Education.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\api\controller;
  3. use Alipay\EasySDK\Kernel\Base;
  4. use app\model\api\EducationCourse;
  5. use think\facade\Db;
  6. class Education
  7. {
  8. /**
  9. * 课程列表页面
  10. * @return \think\response\Json
  11. */
  12. public function index()
  13. {
  14. $EducationModel = new \app\model\api\Education();
  15. $where["audit"] = 1;
  16. $type1 = input("type1", "");
  17. if ($type1 !== "") {
  18. $where["type1"] = $type1;
  19. } else {
  20. $type1 = 2;
  21. }
  22. if ($type1 == 0) {
  23. $where["type1"] = 0;
  24. } elseif ($type1 == 1) {
  25. $where["type1"] = 1;
  26. }
  27. $page = input('page/d', 1);
  28. $pageSize = input('pageSize/d', 20);
  29. $grlist = $EducationModel->where($where)
  30. ->order("od asc,recommend desc,gr_id desc")
  31. ->paginate($pageSize, false, ['page' => $page]);
  32. $result = ['grlist' => $grlist->items(), 'total' => $grlist->total()];
  33. $result['grlist'] = $this->getCountAndAlll($result['grlist']);
  34. return app('json')->success($result);
  35. }
  36. /**
  37. * 获取轮播列表
  38. * @return mixed
  39. */
  40. public function recommend()
  41. {
  42. $EducationModel = new \app\model\api\Education();
  43. $where = [
  44. 'audit' => 1,
  45. 'recommend' => 1,
  46. ];
  47. $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
  48. $result = ['recommendList' => $recommendList];
  49. return app('json')->success($result);
  50. }
  51. /**
  52. * 获取课程组列表
  53. * @return mixed
  54. */
  55. private function getCountAndAlll($grlist)
  56. {
  57. foreach ($grlist as &$v) {
  58. $count = EducationCourse::where('course_status', 1)
  59. ->where('gr_id', $v['gr_id'])
  60. ->where('course_audit', 1)
  61. ->field('count(*) as count,sum(course_play_count) as alll')
  62. ->find();
  63. $v['count'] = $count['count'];
  64. $count['alll'] += $v['times'];
  65. $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  66. }
  67. return $grlist;
  68. }
  69. /**
  70. * 获取课程列表
  71. * @param $gr_id
  72. * @return mixed
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public function getCourseList($gr_id)
  78. {
  79. $courseList = EducationCourse::where('course_status', 1)
  80. ->where('gr_id', $gr_id)
  81. ->where('course_audit', 1)
  82. ->select();
  83. return json([
  84. 'code' => 200,
  85. 'msg' => 'ok',
  86. 'data' => $courseList
  87. ]);
  88. }
  89. }