1,'limit'=>10,'keyword'=>'']); $keyword = $param['keyword']; if($keyword) $where[] = ['name','like','%'.$keyword.'%']; $res = LecturerModel::with(['company'=>function($query){ $query->bind(['lecturer_company_name'=>'name']); }])->where($where)->page((int)$param['page'],(int)$param['limit'])->select(); $count = LecturerModel::where($where)->count(); foreach ($res as $key => $value) { $res[$key]['view_count'] = 0; } return json(['code'=>0,'data'=>$res,'count'=>$count]); } /** * 讲师详情 */ public function read($id) { $where = [ ['root_id','=',0], ['id','=',$id] ]; $info = LecturerModel::with(['company'=>function($query){ $query->bind(['lecturer_company_name'=>'name']); }])->where($where)->findOrEmpty(); if($info->isEmpty()) return json(['code'=>0,'data'=>[]]); //观看人次 $where1 = [ ['lecturer_id','=',$id] ]; $info->view_count = TrainClass::where($where1)->count(); $info->is_collor = !ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',2]])->findOrEmpty()->isEmpty(); return json(['code'=>0,'data'=>$info]); } /** * 讲师收藏 */ public function collor($id) { $check = LecturerModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty(); if($check->isEmpty()) return json(['code'=>1,'data'=>'收藏失败','msg'=>'收藏失败']); $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',2]])->findOrEmpty(); if ($res->isEmpty()) { ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time(),'type'=>2]); return json(['code'=>0,'data'=>'收藏成功','msg'=>'收藏成功']); }else{ ActivityCollor::where([['aid','=',$id],['employee_id','=',$this->employeeId],['type','=',2]])->delete(); return json(['code'=>0,'data'=>'取消收藏','msg'=>'取消收藏']); } } /** * 讲师详情页,讲师课程列表 */ public function trainList() { $param = Request::only(['page'=>1,'limit'=>10,'id'=>0]); $where = [ ['lecturer_id','=',$param['id']], ['root_id','=',0], ['publish','=',1], ['del','=',0] ]; $list = TrainClass::where($where)->field('title,introduce,id,course_id,root_id')->page((int)$param['page'],(int)$param['limit'])->select()->toArray(); foreach ($list as $key => $value) { $list[$key]['course_count'] = $value['course_id'] ? count(explode(',',$value['course_id'])) : 0; } $count = TrainClass::where($where)->count(); return json(['code'=>0,'data'=>$list,'count'=>$count]); } /** * 大咖讲师详情页 其他讲师相关推荐 */ public function recommendList() { $param = Request::only(['page'=>1,'limit'=>10,'id'=>0]); $where = [ ['root_id','=',0], ['del','=',0], ['id','<>',$param['id']] ]; $res = LecturerModel::with(['company'=>function($query){ $query->bind(['lecturer_company_name'=>'name']); }])->where($where)->page((int)$param['page'],(int)$param['limit'])->select(); return json(['code'=>0,'data'=>$res]); } }