Education.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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\ContractTemplate as ContractTemplateModel;
  6. use app\model\api\EducationCourse;
  7. use library\services\UtilService;
  8. use think\facade\Db;
  9. class Education
  10. {
  11. /**
  12. * 课程列表页面
  13. * @return \think\response\Json
  14. */
  15. public function index()
  16. {
  17. $EducationModel = new \app\model\api\Education();
  18. $where["audit"] = 1;
  19. $type1 = input("type1", "");
  20. if ($type1 !== "") {
  21. $where["type1"] = $type1;
  22. } else {
  23. $type1 = 2;
  24. }
  25. if ($type1 == 0) {
  26. $where["type1"] = 0;
  27. } elseif ($type1 == 1) {
  28. $where["type1"] = 1;
  29. }
  30. $page = input('page/d', 1);
  31. $pageSize = input('pageSize/d', 20);
  32. $grlist = $EducationModel->where($where)
  33. ->order("od asc,recommend desc,gr_id desc")
  34. ->paginate($pageSize, false, ['page' => $page]);
  35. $result = ['grlist' => $grlist->items(), 'total' => $grlist->total()];
  36. $result['grlist'] = $this->getCountAndAlll($result['grlist']);
  37. return app('json')->success($result);
  38. }
  39. /**
  40. * 获取轮播列表
  41. * @return mixed
  42. */
  43. public function recommend()
  44. {
  45. $EducationModel = new \app\model\api\Education();
  46. $where = [
  47. 'audit' => 1,
  48. 'recommend' => 1,
  49. ];
  50. $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
  51. $result = ['recommendList' => $recommendList];
  52. return app('json')->success($result);
  53. }
  54. /**
  55. * 获取课程组列表
  56. * @return mixed
  57. */
  58. private function getCountAndAlll($grlist)
  59. {
  60. foreach ($grlist as &$v) {
  61. $count = EducationCourse::where('course_status', 1)
  62. ->where('gr_id', $v['gr_id'])
  63. ->where('course_audit', 1)
  64. ->field('count(*) as count,sum(course_play_count) as alll')
  65. ->find();
  66. $v['count'] = $count['count'];
  67. $count['alll'] += $v['times'];
  68. $v['alll'] = $count['alll'] ? $count['alll'] : 0;
  69. }
  70. return $grlist;
  71. }
  72. /**
  73. * 获取课程列表
  74. * @param $gr_id
  75. * @return mixed
  76. * @throws \think\db\exception\DataNotFoundException
  77. * @throws \think\db\exception\DbException
  78. * @throws \think\db\exception\ModelNotFoundException
  79. */
  80. public function getCourseList($gr_id)
  81. {
  82. $courseList = EducationCourse::where('course_status', 1)
  83. ->where('gr_id', $gr_id)
  84. ->where('course_audit', 1)
  85. ->select();
  86. return json([
  87. 'code' => 200,
  88. 'msg' => 'ok',
  89. 'data' => $courseList
  90. ]);
  91. }
  92. /**
  93. * 合约列表
  94. * @param \app\Request $request
  95. * @return mixed
  96. */
  97. public function getContractList(\think\Request $request)
  98. {
  99. // $pageSize = 50;
  100. // $post = UtilService::getMore([
  101. // ['page',1],
  102. // ['pageSize',50],
  103. // ['nickname',''],
  104. //// ['uid',''],
  105. // ['parent_uid',''],
  106. // ['mobile',''],
  107. // ['status',''],
  108. // ['time',[]],
  109. // ],$request);
  110. //// $post['uid']=$request->user["uid"];
  111. // $data = (new UserModel)->getDataList($post,"*",1);
  112. // return app('json')->success([
  113. // 'list' => $data["list"],
  114. // 'pageCount' => $data["totalCount"],
  115. // 'pageSize' => $data["pageSize"],
  116. // 'page' => $data["page"],
  117. // ]);
  118. $post = UtilService::getMore([
  119. ['page', 1],
  120. ['pageSize', 50],
  121. ['status',-2] //1未签约 2已签约 3已解约
  122. ], $request);
  123. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  124. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  125. $where=[];
  126. $where[]=["uid","=",$request->user["uid"]];
  127. $totalCount = (new UserContractRecordModel)->where($where)->count();
  128. if ($post["status"]!=-2){
  129. $where[]=['status','=',$post["status"]];
  130. }
  131. $data=null;
  132. if($totalCount>0){
  133. $data = (new UserContractRecordModel)
  134. // ->field("")
  135. // ->alias("ut")
  136. // ->join("show_template t", "t.id = show_template_id","left")
  137. ->where($where)
  138. ->order("is_default", "desc")
  139. ->order("id", "desc")
  140. ->page($post["page"], $post["pageSize"])
  141. ->select();
  142. foreach($data as $k=>$v){
  143. $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
  144. switch ($data[$k]["status"]){
  145. case 0:
  146. $data[$k]["status_name"] = "未签约";
  147. break;
  148. case 1:
  149. $data[$k]["status_name"] = "已签约";
  150. break;
  151. case -1:
  152. $data[$k]["status_name"] = "已解约";
  153. break;
  154. }
  155. }
  156. }
  157. $data = empty($data)?[]:$data;
  158. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
  159. }
  160. /**
  161. * 合约模版列表
  162. * @param \app\Request $request
  163. * @return mixed
  164. */
  165. public function getContractTemplateList(\think\Request $request)
  166. {
  167. $post = UtilService::getMore([
  168. ['page', 1],
  169. ['pageSize', 50],
  170. // ['status',-2] //1未签约 2已签约 3已解约
  171. ], $request);
  172. $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
  173. $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
  174. $where=[];
  175. $where[]=["is_show","=",1];
  176. $totalCount = (new ContractTemplateModel)->where($where)->count();
  177. // if ($post["status"]!=-2){
  178. // $where[]=['status','=',$post["status"]];
  179. // }
  180. $data=null;
  181. if($totalCount>0){
  182. $data = (new ContractTemplateModel)
  183. ->where($where)
  184. ->field('id,title,is_show,imgs,admin_time,time')
  185. ->order("id", "desc")
  186. ->page($post["page"], $post["pageSize"])
  187. ->select();
  188. foreach($data as $k=>$v){
  189. $data[$k]["imgs"] = getImageAr($v["imgs"]);
  190. $data[$k]["img"] = empty($data[$k]["imgs"]) ? "" : $data[$k]["imgs"][0];
  191. $data[$k]["time"] = date("Y-m-d H:i:s",$v["time"]);
  192. $data[$k]["admin_time"] = date("Y-m-d H:i:s",$v["admin_time"]);
  193. }
  194. }
  195. $data = empty($data)?[]:$data;
  196. return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
  197. }
  198. /**
  199. * 合约模版详情
  200. * @param \app\Request $request
  201. * @return mixed
  202. */
  203. public function getContractTemplatInfo(\think\Request $request)
  204. {
  205. $post = UtilService::getMore([
  206. ['id', ''],
  207. ], $request);
  208. $where=[];
  209. $where[]=["is_show","=",1];
  210. $where[]=["id","=",$post['id']];
  211. $totalCount = (new ContractTemplateModel)->where($where)->count();
  212. $data=null;
  213. if($totalCount>0){
  214. $data = (new ContractTemplateModel)
  215. ->where($where)
  216. ->order("id", "desc")
  217. ->page($post["page"], $post["pageSize"])
  218. ->select();
  219. // $data['id'] = $oData['id'];
  220. $data['imgs'] = getImageAr($data["imgs"]);
  221. $data['content'] = json_decode($data['content']);
  222. $data['time'] = date("Y-m-d H:i:s", $data["time"]);
  223. $data['admin_time'] = date("Y-m-d H:i:s", $data["admin_time"]);
  224. }
  225. $data = empty($data)?[]:$data;
  226. return app('json')->success($data);
  227. }
  228. }