|
@@ -67,21 +67,44 @@ class Index extends Api
|
|
|
//搜索
|
|
|
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,//报名中
|
|
|
];
|
|
|
|
|
|
+ //模糊搜索
|
|
|
+ $wherelike = '';
|
|
|
+ if(!empty($keyword)){
|
|
|
+
|
|
|
+ //搜课程名
|
|
|
+ $wherelike .= "(lesson.name like '%".$keyword."%') or (lesson.name_en like '%".$keyword."%')";
|
|
|
+
|
|
|
+ //搜教练ids
|
|
|
+ $coach_where = [];
|
|
|
+ $coach_where['nickname'] = ['LIKE','%'.$keyword.'%'];
|
|
|
+ $coach_ids = Db::name('coach')->where($coach_where)->column('id');
|
|
|
+ if(!empty($coach_ids))
|
|
|
+ {
|
|
|
+ $wherelike .= ' or ';
|
|
|
+ foreach($coach_ids as $ck => $cv){
|
|
|
+ $wherelike .= "(FIND_IN_SET('".$cv."',slot.coach_ids))";
|
|
|
+
|
|
|
+ if($ck+1 < count($coach_ids)){
|
|
|
+ $wherelike .= " or ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
$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();
|
|
|
+ ->where($where)->where($wherelike)->autopage()
|
|
|
+ //->select(false);echo $list;exit;
|
|
|
+ ->select();
|
|
|
$list = list_domain_image($list,['image']);
|
|
|
$list = $this->list_lang($list,['name']);
|
|
|
|
|
@@ -95,6 +118,9 @@ class Index extends Api
|
|
|
$coach_text .= $coach_list[$coach_id].',';
|
|
|
}
|
|
|
$slot['coach_text'] = substr($coach_text,0,-1);
|
|
|
+
|
|
|
+ //组织时间
|
|
|
+ $slot['slot_time'] = date('m-d',$slot['starttime']).'(周'.date('w',$slot['starttime']).')'.','.date('H:i',$slot['starttime']).'-'.date('H:i',$slot['endtime']);
|
|
|
}
|
|
|
|
|
|
$this->success(1,$list);
|