Education.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. return app('json')->success($result);
  34. }
  35. /**
  36. * 获取轮播列表
  37. * @return mixed
  38. */
  39. public function recommend()
  40. {
  41. $EducationModel = new \app\model\api\Education();
  42. $where = [
  43. 'audit' => 1,
  44. 'recommend' => 1,
  45. ];
  46. $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
  47. $result = ['recommendList' => $recommendList];
  48. return app('json')->success($result);
  49. }
  50. /**
  51. * 获取课程组列表
  52. * @return mixed
  53. */
  54. public function getCourseList()
  55. {
  56. $where['audit'] = 1;
  57. $type1 = input('type', '');
  58. if ($type1 !== '') {
  59. $where['type1'] = $type1;
  60. }
  61. $grlist = \app\model\api\Education::where($where)
  62. ->limit(20)
  63. ->order('od asc,recommend desc,gr_id desc')
  64. ->select()
  65. ->toArray();
  66. foreach ($grlist as &$v) {
  67. $count = EducationCourse::where('course_status', 1)
  68. ->where('gr_id', $v['gr_id'])
  69. ->where('course_audit', 1)
  70. ->field('count(*) as count,sum(course_play_count) as alll')
  71. ->find();
  72. $v['count'] = $count['count'];
  73. $count['alll'] += $v['times'];
  74. $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  75. }
  76. return app('json')->success(['data' => $grlist]);
  77. }
  78. }