123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- declare(strict_types=1);
- namespace app\mobile\controller;
- use think\facade\Request;
- use app\model\Employee;
- use app\model\Lecturer as LecturerModel;
- use app\model\TrainClass;
- use app\model\ActivityCollor;
- class Lecturer extends Base
- {
- /**
- * 大咖讲师列表
- */
- public function list()
- {
- $where = [
- ['root_id','=',0],
- ['del','=',0]
- ];
- $param = Request::only(['page'=>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]);
- }
- }
|