Education.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. if (!$course) {
  51. return app('json')->fail('课程不存在');
  52. }
  53. $course = $course->toArray();
  54. $education = \app\model\api\Education::where('gr_id', $course['gr_id'])
  55. ->where('audit', 1)
  56. ->find();
  57. if (!$education) {
  58. return app('json')->fail('课程不存在或未通过审核');
  59. }
  60. $education = $education->toArray();
  61. $course['edu_name'] = $education['name'];
  62. $course['edu_logo'] = $education['logo'];
  63. $course['edu_type1'] = $education['type1'];
  64. $course['edu_type2'] = $education['type2'];
  65. return app('json')->success($course);
  66. }
  67. /**
  68. * 获取轮播列表
  69. * @return mixed
  70. */
  71. public function recommend()
  72. {
  73. $EducationModel = new \app\model\api\Education();
  74. $where = [
  75. 'audit' => 1,
  76. 'recommend' => 1,
  77. ];
  78. $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
  79. $result = ['recommendList' => $recommendList];
  80. return app('json')->success($result);
  81. }
  82. /**
  83. * 获取课程组列表
  84. * @return mixed
  85. */
  86. private function getCountAndAlll($grlist)
  87. {
  88. foreach ($grlist as &$v) {
  89. $count = EducationCourse::where('course_status', 1)
  90. ->where('gr_id', $v['gr_id'])
  91. ->where('course_audit', 1)
  92. ->field('count(*) as count,sum(course_play_count) as alll')
  93. ->find();
  94. $v['count'] = $count['count'];
  95. $count['alll'] += $v['times'];
  96. $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  97. }
  98. return $grlist;
  99. }
  100. }