| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- namespace app\api\controller;
- use Alipay\EasySDK\Kernel\Base;
- use app\model\api\ContractRecord as UserContractRecordModel;
- use app\model\api\EducationCourse;
- use library\services\UtilService;
- use think\facade\Db;
- class Education
- {
- /**
- * 课程列表页面
- * @return \think\response\Json
- */
- public function index()
- {
- $EducationModel = new \app\model\api\Education();
- $where["audit"] = 1;
- $type1 = input("type1", "");
- if ($type1 !== "") {
- $where["type1"] = $type1;
- } else {
- $type1 = 2;
- }
- if ($type1 == 0) {
- $where["type1"] = 0;
- } elseif ($type1 == 1) {
- $where["type1"] = 1;
- }
- $page = input('page/d', 1);
- $pageSize = input('pageSize/d', 20);
- $grlist = $EducationModel->where($where)
- ->order("od asc,recommend desc,gr_id desc")
- ->paginate($pageSize, false, ['page' => $page]);
- $result = ['grlist' => $grlist->items(), 'total' => $grlist->total()];
- $result['grlist'] = $this->getCountAndAlll($result['grlist']);
- return app('json')->success($result);
- }
- /**
- * 获取轮播列表
- * @return mixed
- */
- public function recommend()
- {
- $EducationModel = new \app\model\api\Education();
- $where = [
- 'audit' => 1,
- 'recommend' => 1,
- ];
- $recommendList = $EducationModel->getEducationGrList($where, 9, "od asc,recommend desc,gr_id desc");
- $result = ['recommendList' => $recommendList];
- return app('json')->success($result);
- }
- /**
- * 获取课程组列表
- * @return mixed
- */
- private function getCountAndAlll($grlist)
- {
- foreach ($grlist as &$v) {
- $count = EducationCourse::where('course_status', 1)
- ->where('gr_id', $v['gr_id'])
- ->where('course_audit', 1)
- ->field('count(*) as count,sum(course_play_count) as alll')
- ->find();
- $v['count'] = $count['count'];
- $count['alll'] += $v['times'];
- $v['alll'] = $count['alll'] ? $count['alll'] : 0;
- }
- return $grlist;
- }
- /**
- * 获取课程列表
- * @param $gr_id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getCourseList($gr_id)
- {
- $courseList = EducationCourse::where('course_status', 1)
- ->where('gr_id', $gr_id)
- ->where('course_audit', 1)
- ->select();
- return json([
- 'code' => 200,
- 'msg' => 'ok',
- 'data' => $courseList
- ]);
- }
- /**
- * 合约列表
- * @param \app\Request $request
- * @return mixed
- */
- public function getContractList(\think\Request $request)
- {
- // $pageSize = 50;
- // $post = UtilService::getMore([
- // ['page',1],
- // ['pageSize',50],
- // ['nickname',''],
- //// ['uid',''],
- // ['parent_uid',''],
- // ['mobile',''],
- // ['status',''],
- // ['time',[]],
- // ],$request);
- //// $post['uid']=$request->user["uid"];
- // $data = (new UserModel)->getDataList($post,"*",1);
- // return app('json')->success([
- // 'list' => $data["list"],
- // 'pageCount' => $data["totalCount"],
- // 'pageSize' => $data["pageSize"],
- // 'page' => $data["page"],
- // ]);
- $post = UtilService::getMore([
- ['page', 1],
- ['pageSize', 50],
- ['status',-2] //1未签约 2已签约 3已解约
- ], $request);
- $post["pageSize"] = $post["pageSize"]>50 ? 50 : (int)$post["pageSize"];
- $post["page"] = $post["page"]<=0 ? 1 : (int)$post["page"];
- $where=[];
- $where[]=["uid","=",$request->user["uid"]];
- $totalCount = (new UserContractRecordModel)->where($where)->count();
- if ($post["status"]!=-2){
- $where[]=['status','=',$post["status"]];
- }
- $data=null;
- if($totalCount>0){
- $data = (new UserContractRecordModel)
- // ->field("")
- // ->alias("ut")
- // ->join("show_template t", "t.id = show_template_id","left")
- ->where($where)
- ->order("is_default", "desc")
- ->order("id", "desc")
- ->page($post["page"], $post["pageSize"])
- ->select();
- foreach($data as $k=>$v){
- $data[$k]["is_use"] = 1;//是否已经购买或者可以使用
- switch ($data[$k]["status"]){
- case 0:
- $data[$k]["status_name"] = "未签约";
- break;
- case 1:
- $data[$k]["status_name"] = "已签约";
- break;
- case -1:
- $data[$k]["status_name"] = "已解约";
- break;
- }
- }
- }
- $data = empty($data)?[]:$data;
- return app('json')->success(["list" => $data, "pageSize" => $post["pageSize"],"page"=>$post["page"],"totalCount"=>$totalCount]);
- }
- }
|