瀏覽代碼

搜索接口

lizhen_gitee 1 年之前
父節點
當前提交
b4b2c1dcf6
共有 1 個文件被更改,包括 36 次插入0 次删除
  1. 36 0
      application/api/controller/Index.php

+ 36 - 0
application/api/controller/Index.php

@@ -51,4 +51,40 @@ class Index extends Api
         $this->success(1,$result);
 
     }
+
+    //搜索
+    public function search(){
+        $keyword = input('keyword','','trim');
+        if(empty($keyword)){
+            $this->error();
+        }
+
+        //搜课时表
+        $where = [
+            'lesson.name|lesson.name_en' => ['LIKE','%'.$keyword.'%'],
+            'slot.starttime' => ['gt',time()],//未开始
+            'slot.status' => 0,//报名中
+        ];
+
+        $list  = Db::name('lesson_slot')->alias('slot')
+            ->field('slot.*,lesson.name,lesson.name_en,lesson.image,lesson.price')
+            ->join('lesson','slot.lesson_id = lesson.id','LEFT')
+            ->where($where)->autopage()->select();
+        $list  = list_domain_image($list,['image']);
+        $list  = $this->list_lang($list,['name']);
+
+        //准备教练数据
+        $coach_list = Db::name('coach')->column('id,nickname');
+        foreach($list as $key => &$slot){
+            //放入教练
+            $coach_text = '';
+            $coach_ids = explode(',',$slot['coach_ids']);
+            foreach($coach_ids as $coach_id){
+                $coach_text .= $coach_list[$coach_id].',';
+            }
+            $slot['coach_text'] = substr($coach_text,0,-1);
+        }
+
+        $this->success(1,$list);
+    }
 }