Education.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\api\controller;
  3. use Alipay\EasySDK\Kernel\Base;
  4. use app\model\api\ContractRecord as UserContractRecordModel;
  5. use app\model\api\EducationCourse;
  6. use library\services\UtilService;
  7. use think\facade\Db;
  8. class Education
  9. {
  10. /**
  11. * 课程列表页面
  12. * @return \think\response\Json
  13. */
  14. public function index()
  15. {
  16. $EducationModel = new \app\model\api\Education();
  17. $where["audit"] = 1;
  18. $type1 = input("type1", "");
  19. if ($type1 !== "") {
  20. $where["type1"] = $type1;
  21. } else {
  22. $type1 = 2;
  23. }
  24. if ($type1 == 0) {
  25. $where["type1"] = 0;
  26. } elseif ($type1 == 1) {
  27. $where["type1"] = 1;
  28. }
  29. $page = input('page/d', 1);
  30. $pageSize = input('pageSize/d', 20);
  31. $grlist = $EducationModel->where($where)
  32. ->order("od asc,recommend desc,gr_id desc")
  33. ->paginate($pageSize, false, ['page' => $page]);
  34. $result = ['grlist' => $grlist->items(), 'total' => $grlist->total()];
  35. $result['grlist'] = $this->getCountAndAlll($result['grlist']);
  36. return app('json')->success($result);
  37. }
  38. /**
  39. * 获取轮播列表
  40. * @return mixed
  41. */
  42. public function recommend()
  43. {
  44. $EducationModel = new \app\model\api\Education();
  45. $where = [
  46. 'audit' => 1,
  47. 'recommend' => 1,
  48. ];
  49. $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
  50. $result = ['recommendList' => $recommendList];
  51. return app('json')->success($result);
  52. }
  53. /**
  54. * 获取课程组列表
  55. * @return mixed
  56. */
  57. private function getCountAndAlll($grlist)
  58. {
  59. foreach ($grlist as &$v) {
  60. $count = EducationCourse::where('course_status', 1)
  61. ->where('gr_id', $v['gr_id'])
  62. ->where('course_audit', 1)
  63. ->field('count(*) as count,sum(course_play_count) as alll')
  64. ->find();
  65. $v['count'] = $count['count'];
  66. $count['alll'] += $v['times'];
  67. $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  68. }
  69. return $grlist;
  70. }
  71. /**
  72. * 获取课程列表
  73. * @param $gr_id
  74. * @return mixed
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. */
  79. public function getCourseList($gr_id)
  80. {
  81. $courseList = EducationCourse::where('course_status', 1)
  82. ->where('gr_id', $gr_id)
  83. ->where('course_audit', 1)
  84. ->select();
  85. return json([
  86. 'code' => 200,
  87. 'msg' => 'ok',
  88. 'data' => $courseList
  89. ]);
  90. }
  91. /**
  92. * 合约列表
  93. * @param \app\Request $request
  94. * @return mixed
  95. */
  96. public function getContractList(\think\Request $request)
  97. {
  98. // $pageSize = 50;
  99. // $post = UtilService::getMore([
  100. // ['page',1],
  101. // ['pageSize',50],
  102. // ['nickname',''],
  103. //// ['uid',''],
  104. // ['parent_uid',''],
  105. // ['mobile',''],
  106. // ['status',''],
  107. // ['time',[]],
  108. // ],$request);
  109. //// $post['uid']=$request->user["uid"];
  110. // $data = (new UserModel)->getDataList($post,"*",1);
  111. // return app('json')->success([
  112. // 'list' => $data["list"],
  113. // 'pageCount' => $data["totalCount"],
  114. // 'pageSize' => $data["pageSize"],
  115. // 'page' => $data["page"],
  116. // ]);
  117. $post = UtilService::getMore([
  118. ['page', 1],
  119. ['pageSize', 50],
  120. ['status',-2] //1未签约 2已签约 3已解约
  121. ], $request);
  122. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  123. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  124. $where=[];
  125. $where[]=["uid","=",$request->user["uid"]];
  126. $totalCount = (new UserContractRecordModel)->where($where)->count();
  127. if ($post["status"]!=-2){
  128. $where[]=['status','=',$post["status"]];
  129. }
  130. $data=null;
  131. if($totalCount>0){
  132. $data = (new UserContractRecordModel)
  133. // ->field("")
  134. // ->alias("ut")
  135. // ->join("show_template t", "t.id = show_template_id","left")
  136. ->where($where)
  137. ->order("is_default", "desc")
  138. ->order("id", "desc")
  139. ->page($post["page"], $post["pageSize"])
  140. ->select();
  141. foreach($data as $k=>$v){
  142. $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
  143. switch ($data[$k]["status"]){
  144. case 0:
  145. $data[$k]["status_name"] = "未签约";
  146. break;
  147. case 1:
  148. $data[$k]["status_name"] = "已签约";
  149. break;
  150. case -1:
  151. $data[$k]["status_name"] = "已解约";
  152. break;
  153. }
  154. }
  155. }
  156. $data = empty($data)?[]:$data;
  157. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
  158. }
  159. }