Education.php 9.8 KB

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