Education.php 10 KB

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