Lecturer.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\mobile\controller;
  4. use think\facade\Request;
  5. use app\model\Employee;
  6. use app\model\Lecturer as LecturerModel;
  7. use app\model\TrainClass;
  8. use app\model\ActivityCollor;
  9. class Lecturer extends Base
  10. {
  11. /**
  12. * 大咖讲师列表
  13. */
  14. public function list()
  15. {
  16. $where = [
  17. ['root_id','=',0],
  18. ['del','=',0]
  19. ];
  20. $param = Request::only(['page'=>1,'limit'=>10,'keyword'=>'']);
  21. $keyword = $param['keyword'];
  22. if($keyword) $where[] = ['name','like','%'.$keyword.'%'];
  23. $res = LecturerModel::with(['company'=>function($query){
  24. $query->bind(['lecturer_company_name'=>'name']);
  25. }])->where($where)->page((int)$param['page'],(int)$param['limit'])->select();
  26. $count = LecturerModel::where($where)->count();
  27. foreach ($res as $key => $value) {
  28. $res[$key]['view_count'] = 0;
  29. }
  30. return json(['code'=>0,'data'=>$res,'count'=>$count]);
  31. }
  32. /**
  33. * 讲师详情
  34. */
  35. public function read($id)
  36. {
  37. $where = [
  38. ['root_id','=',0],
  39. ['id','=',$id]
  40. ];
  41. $info = LecturerModel::with(['company'=>function($query){
  42. $query->bind(['lecturer_company_name'=>'name']);
  43. }])->where($where)->findOrEmpty();
  44. if($info->isEmpty()) return json(['code'=>0,'data'=>[]]);
  45. //观看人次
  46. $where1 = [
  47. ['lecturer_id','=',$id]
  48. ];
  49. $info->view_count = TrainClass::where($where1)->count();
  50. $info->is_collor = !ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',2]])->findOrEmpty()->isEmpty();
  51. return json(['code'=>0,'data'=>$info]);
  52. }
  53. /**
  54. * 讲师收藏
  55. */
  56. public function collor($id)
  57. {
  58. $check = LecturerModel::where([['root_id','=',0],['id','=',$id]])->findOrEmpty();
  59. if($check->isEmpty()) return json(['code'=>1,'data'=>'收藏失败','msg'=>'收藏失败']);
  60. $res = ActivityCollor::where([['employee_id','=',$this->employeeId],['aid','=',$id],['type','=',2]])->findOrEmpty();
  61. if ($res->isEmpty()) {
  62. ActivityCollor::insertGetId(['employee_id'=>$this->employeeId,'aid'=>$id,'addtime'=>time(),'type'=>2]);
  63. return json(['code'=>0,'data'=>'收藏成功','msg'=>'收藏成功']);
  64. }else{
  65. ActivityCollor::where([['aid','=',$id],['employee_id','=',$this->employeeId],['type','=',2]])->delete();
  66. return json(['code'=>0,'data'=>'取消收藏','msg'=>'取消收藏']);
  67. }
  68. }
  69. /**
  70. * 讲师详情页,讲师课程列表
  71. */
  72. public function trainList()
  73. {
  74. $param = Request::only(['page'=>1,'limit'=>10,'id'=>0]);
  75. $where = [
  76. ['lecturer_id','=',$param['id']],
  77. ['root_id','=',0],
  78. ['publish','=',1],
  79. ['del','=',0]
  80. ];
  81. $list = TrainClass::where($where)->field('title,introduce,id,course_id,root_id')->page((int)$param['page'],(int)$param['limit'])->select()->toArray();
  82. foreach ($list as $key => $value) {
  83. $list[$key]['course_count'] = $value['course_id'] ? count(explode(',',$value['course_id'])) : 0;
  84. }
  85. $count = TrainClass::where($where)->count();
  86. return json(['code'=>0,'data'=>$list,'count'=>$count]);
  87. }
  88. /**
  89. * 大咖讲师详情页 其他讲师相关推荐
  90. */
  91. public function recommendList()
  92. {
  93. $param = Request::only(['page'=>1,'limit'=>10,'id'=>0]);
  94. $where = [
  95. ['root_id','=',0],
  96. ['del','=',0],
  97. ['id','<>',$param['id']]
  98. ];
  99. $res = LecturerModel::with(['company'=>function($query){
  100. $query->bind(['lecturer_company_name'=>'name']);
  101. }])->where($where)->page((int)$param['page'],(int)$param['limit'])->select();
  102. return json(['code'=>0,'data'=>$res]);
  103. }
  104. }