success('请求成功'); } /** * 获取教材级别 * * api/books/getBooksLevel */ public function getBooksLevel(){ $BooksLevel = new BooksLevel(); $list = $BooksLevel->where('is_deleted',1)->where('status',0)->order('sort desc,id desc')->select(); $this->success('操作成功',$list); } /** * 获取教学层次 * * api/books/getBooksArrangement */ public function getBooksArrangement(){ $BooksArrangement = new BooksArrangement(); $list = $BooksArrangement->where('is_deleted',1)->where('status',0)->order('sort desc,id desc')->select(); $this->success('操作成功',$list); } /** * 获取专业类型 * * api/books/getBooksSpeciality */ public function getBooksSpeciality(){ $BooksSpeciality = new BooksSpeciality(); $list = $BooksSpeciality->where('is_deleted',1)->where('status',0)->order('sort desc,id desc')->select(); $this->success('操作成功',$list); } /** * 教材列表 * * api/books/getBooksList */ public function getBooksList(){ $data = input(); $where = []; $BookModel = new BookModel(); if(!isset($data['page']) || $data['page'] == '' || $data['page'] == null){ $page = 1; }else{ $page = $data['page']; } if(!isset($data['limit']) || $data['limit'] == '' || $data['limit'] == null){ $limit = 20; }else{ $limit = $data['limit']; } //教材级别 if(isset($data['level_id']) && $data['level_id'] && $data['level_id']!= '' && $data['level_id'] != null){ $where['level_id'] = $data['level_id']; } //教学层次 if(isset($data['arrangement_id']) && $data['arrangement_id'] && $data['arrangement_id']!= '' && $data['arrangement_id'] != null){ $where['arrangement_id'] = $data['arrangement_id']; } //专业类型 if(isset($data['speciality_id']) && $data['speciality_id'] && $data['speciality_id']!= '' && $data['speciality_id'] != null){ $where['speciality_id'] = $data['speciality_id']; } //教材类型 0纸质书 1电子书 if(isset($data['book_type']) && $data['book_type']!= '' && $data['book_type'] != null){ $where['book_type'] = $data['book_type']; } //是否新书推荐 0是 1否 if(isset($data['is_new_recommend']) && $data['is_new_recommend']!= '' && $data['is_new_recommend'] != null){ $where['is_new_recommend'] = $data['is_new_recommend']; } //是否获奖教材 0是 1否 if(isset($data['is_awards']) && $data['is_awards']!= '' && $data['is_awards'] != null){ $where['is_awards'] = $data['is_awards']; } //关键字 if ( isset($data['keywords']) && $data['keywords'] != '' && $data['keywords'] != null){ $where['title'] = ['like','%'.$data['keywords'].'%']; } $where['is_deleted'] = 1; $list = $BookModel->where($where)->order('id desc')->field('id,title,image,book_type,is_new_recommend,author,is_awards,price,entity_price,createtime,updatetime,level_id,arrangement_id,speciality_id,series_id,is_series')->paginate([ 'list_rows'=> $limit, 'page' => $page, ]); $lists = $list->toArray(); foreach ($lists['data'] as $key => &$item){ $lists['data'][$key]['is_free'] = 1; if($item['price'] <= 0){ $lists['data'][$key]['is_free'] = 0; } } $this->success('操作成功',$lists); } /** * 教材详情 * * api/books/getBookInfo */ public function getBookInfo(){ $data = input(); $BookModel = new BookModel(); $BooksLevel = new BooksLevel(); $BooksArrangement = new BooksArrangement(); $BooksSpeciality = new BooksSpeciality(); if(!isset($data['id']) || !$data['id']){ $this->error('参数错误'); } $id = $data['id']; $list = $BookModel->where('id',$id)->where('is_deleted',1)->with(['courseware_file','resource_file','package_file','specimen_file','ebook_file','level','arrangement','speciality'])->find(); $list['is_certificate'] = 1; $list['is_pay'] = 1; $list['is_free'] = 1; $list['cer'] = null; if($list['price'] <= 0){ $list['is_free'] = 0; } //判断是否可查看所有课程 if($this->auth->isLogin()){ $Certificate = new Certificate(); $UserGoods = new UserGoods(); $uid = $this->auth->id; $cer = $Certificate->where('user_id',$uid) ->where('goods_id',$id) ->where('status',1) ->where('is_expire',1) ->where('free_end_time','>',date("Y-m-d H:i:s")) ->where('is_deleted',1)->find(); if($cer){ $list['is_certificate'] = 0; $list['cer'] = $cer; } $good = $UserGoods->where('user_id',$uid)->where('goods_type',0)->where('goods_id',$id)->find(); if($good){ $list['is_pay'] = 0; } } $list['banner'] = explode(',',$list['banner']); if(!$list){ $this->error('教材不存在或已删除'); } $this->success('操作成功',$list); } /** * 获取系列相关教材 * * api/books/getSeriesBooks */ public function getSeriesBooks(){ $data = input(); $BookModel = new BookModel(); if(!isset($data['series_id']) || !$data['series_id']){ $this->error('参数错误'); } $series_id = $data['series_id']; $list = $BookModel->where('series_id',$series_id) ->where('is_deleted',1) ->where('is_series',0) ->field('id,title,image,book_type,is_new_recommend,author,is_awards,price,entity_price,createtime,updatetime,level_id,arrangement_id,speciality_id,series_id,is_series') ->select(); $lists = $list; $listss = []; if($this->auth->isLogin()) { $uid = $this->auth->id; foreach ($lists as $k => $v) { $UserGoods = new UserGoods(); $Certificate = new Certificate(); $good = $UserGoods->where('user_id', $uid)->where('goods_type', 0)->where('goods_id', $v['id'])->find(); //体验卡 $cer = $Certificate->where('user_id',$uid) ->where('goods_id',$v['id']) ->where('status',1) ->where('is_expire',1) ->where('free_end_time','>',date("Y-m-d H:i:s")) ->where('is_deleted',1)->find(); if($cer){ $list[$k]['is_certificate'] = 0; $list[$k]['free_end_time'] = $cer['free_end_time']; }else{ $list[$k]['is_certificate'] = 1; //免费/付费 $list[$k]['is_free'] = 1; if($v['price'] <= 0){ $list[$k]['is_free'] = 0; } } if (!$good) { $listss[] = $v; // unset($lists[$k]); } } }else{ $listss = $lists; } $this->success('操作成功',$listss); } /** * 投稿 * * api/books/addContribute */ public function addContribute(){ $data = input(); $uid = $this->auth->id; $data['user_id'] = $uid; $Contribute = new Contribute(); $save = $Contribute->save($data); if($save){ $this->success('操作成功'); }else{ $this->success('操作失败'); } } /** * 样书申请 * * api/books/addContribute */ public function addSampleApply(){ $data = input(); $uid = $this->auth->id; $data['user_id'] = $uid; $SampleApply = new SampleApply(); $save = $SampleApply->save($data); if($save){ $this->success('操作成功'); }else{ $this->success('操作失败'); } } }