Education.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. // * @param $gr_id
  39. // * @return mixed
  40. // * @throws \think\db\exception\DataNotFoundException
  41. // * @throws \think\db\exception\DbException
  42. // * @throws \think\db\exception\ModelNotFoundException
  43. // */
  44. // public function getCourseDetail($gr_id)
  45. // {
  46. // $course = EducationCourse::where('gr_id', $gr_id)
  47. // ->where('course_status', 1)
  48. // ->where('course_audit', 1)
  49. // ->find();
  50. //
  51. // if (!$course) {
  52. // return app('json')->fail('课程不存在');
  53. // }
  54. //
  55. // $course = $course->toArray();
  56. //
  57. // $education = \app\model\api\Education::where('gr_id', $course['gr_id'])
  58. // ->where('audit', 1)
  59. // ->find();
  60. //
  61. // if (!$education) {
  62. // return app('json')->fail('课程不存在或未通过审核');
  63. // }
  64. //
  65. // $education = $education->toArray();
  66. //
  67. // $course['edu_name'] = $education['name'];
  68. // $course['edu_logo'] = $education['logo'];
  69. // $course['edu_type1'] = $education['type1'];
  70. // $course['edu_type2'] = $education['type2'];
  71. //
  72. // return app('json')->success($course);
  73. // }
  74. /**
  75. * 获取轮播列表
  76. * @return mixed
  77. */
  78. public function recommend()
  79. {
  80. $EducationModel = new \app\model\api\Education();
  81. $where = [
  82. 'audit' => 1,
  83. 'recommend' => 1,
  84. ];
  85. $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
  86. $result = ['recommendList' => $recommendList];
  87. return app('json')->success($result);
  88. }
  89. /**
  90. * 获取课程组列表
  91. * @return mixed
  92. */
  93. private function getCountAndAlll($grlist)
  94. {
  95. foreach ($grlist as &$v) {
  96. $count = EducationCourse::where('course_status', 1)
  97. ->where('gr_id', $v['gr_id'])
  98. ->where('course_audit', 1)
  99. ->field('count(*) as count,sum(course_play_count) as alll')
  100. ->find();
  101. $v['count'] = $count['count'];
  102. $count['alll'] += $v['times'];
  103. $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  104. }
  105. return $grlist;
  106. }
  107. /**
  108. * 获取课程详细信息
  109. * @param $gr_id
  110. * @return array
  111. * @throws \think\db\exception\DataNotFoundException
  112. * @throws \think\db\exception\DbException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. */
  115. public function getCourseInfo($gr_id) {
  116. $courses = DB::table('table_education_course')
  117. ->where('course_status', 1)
  118. ->whereIn('gr_id', (array) $gr_id)
  119. ->where('course_audit', 1)
  120. ->select()
  121. ->toArray();
  122. $course_list = [];
  123. foreach ($courses as $course) {
  124. $course_info = [
  125. 'course_id' => $course->id,
  126. 'course_name' => $course->course_name,
  127. 'course_cover' => $course->course_cover,
  128. // 其他课程相关信息
  129. ];
  130. $course_list[] = $course_info;
  131. }
  132. $count_and_all = $this->getCountAndAlll($gr_id);
  133. $result = [
  134. 'course_list' => $course_list,
  135. 'count' => $count_and_all[0]['count'],
  136. 'alll' => $count_and_all[0]['alll']
  137. ];
  138. return $result;
  139. }
  140. }