Education.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. // public function getCourseList()
  56. // {
  57. // $where['audit'] = 1;
  58. // $type1 = input('type', '');
  59. // if ($type1 !== '') {
  60. // $where['type1'] = $type1;
  61. // }
  62. // $grlist = \app\model\api\Education::where($where)
  63. // ->limit(20)
  64. // ->order('od asc,recommend desc,gr_id desc')
  65. // ->select()
  66. // ->toArray();
  67. // foreach ($grlist as &$v) {
  68. // $count = EducationCourse::where('course_status', 1)
  69. // ->where('gr_id', $v['gr_id'])
  70. // ->where('course_audit', 1)
  71. // ->field('count(*) as count,sum(course_play_count) as alll')
  72. // ->find();
  73. // $v['count'] = $count['count'];
  74. // $count['alll'] += $v['times'];
  75. // $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  76. // }
  77. // return app('json')->success(['data' => $grlist]);
  78. // }
  79. private function getCountAndAlll($grlist)
  80. {
  81. foreach ($grlist as &$v) {
  82. $count = EducationCourse::where('course_status', 1)
  83. ->where('gr_id', $v['gr_id'])
  84. ->where('course_audit', 1)
  85. ->field('count(*) as count,sum(course_play_count) as alll')
  86. ->find();
  87. $v['count'] = $count['count'];
  88. $count['alll'] += $v['times'];
  89. $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  90. }
  91. return $grlist;
  92. }
  93. }