where('is_deleted',0)->select()->toArray(); foreach ($list as &$v) { $v['datum_list'] = DatumIntro::field('id,title')->where(['datum_cate'=>$v['id']])->select()->toArray(); } $this->success('ok',['list'=>$list]); } /** * @title 资料推荐 * @desc 资料推荐 * @author qc * @method GET * @url /api/Datum/getRecommendList * @header name:Authorization require:1 desc:Token * @param name:page type:int default:0 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @return name:id type:string default:-- desc:资料item_id * @return name:title type:string default:-- desc:标题 * @return name:datum_id type:string default:-- desc:系列id * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是) * @return name:read_num type:int default:-- desc:阅读量 * @return name:down_num type:int default:-- desc:下载量 * @return name:url type:int default:-- desc:资料路径 */ public function getRecommendList() { $search_log = UserSearch::getSearchTitle($this->user_id,3); $search_arr = []; $where_str = 'b.id > 0'; foreach ($search_log as $t){ $search_arr[] = " b.title like '".'%'.$t."%'" .' '; $search_arr[] = " b.label like '".'%'.$t."%'" .' '; } if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr); $field = ' a.id,a.title,a.user_id,a.down_num,a.read_num,a.is_vip,a.datum_id,a.url ,IFNULL(is_recommend,0) is_recommend '; $table = 'dd_datum_url'; $order_by_two = 'a.read_num'; $sql = "SELECT $field FROM " .$table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id LEFT JOIN dd_datum_intro as k ON k.id = a.datum_id WHERE a.status = 1 AND a.is_deleted = 0 AND k.status = 1 AND k.is_deleted = 0 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}"; $list = Db::query($sql); array_walk($list,function (&$v,$k){ }); $this->success('ok',['list'=>$list,'sql'=>$sql]); } /** * @title 获取资料列表(平台发布) * @desc 获取资料列表 * @author qc * @method GET * @url /api/Datum/getDatumList * @header name:Authorization require:1 desc:Token * @param name:type type:int default:0 desc:类型1单个2系列 * @param name:is_tj type:int default:0 desc:是否推荐0否1是 * @param name:title type:string default:-- desc:标题 * @param name:page type:int default:0 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序 * @return name:id type:int default:-- desc:[请求/api/Datum/getDatumDetail用,请求资料模块其他接口参数:url_id] * @return name:title type:string default:-- desc:标题 * @return name:type type:int default:0 desc:类型1单个2系列 * @return name:datum_url type:string default:-- desc:资料地址 * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是) * @return name:is_over type:int default:-- desc:是否完结(0否,1是) * @return name:label type:string default:-- desc:标签 * @return name:is_collect type:int default:-- desc:是否收藏 * @return name:url_arr type:array default:-- desc:资料 * @return name:url_arr.title type:string default:-- desc:资料标题 * @return name:url_arr.is_vip type:int default:-- desc:是否是vip * @return name:url_arr.url type:string default:-- desc:资料地址 */ public function getDatumList() { $sel_where = []; $title = input('get.title'); $type = input('get.type',0); $is_tj = input('get.is_tj',0); $sort_type = input('get.sort_type',1); $sel_where[] = ['is_deleted','=',0]; $sel_where[] = ['status','=',1]; $sel_where[] = ['url_num','>',0]; if($title) $sel_where[] = ['title|label','like','%'.$title.'%']; if($type) $sel_where[] = ['type','=',$type]; switch ($sort_type) { case 1: $order = ['sort'=>'desc','id'=>'desc']; break; case 2: $order = ['id'=>'asc','sort'=>'desc']; break; case 3: $order = ['id'=>'desc','sort'=>'desc']; break; } if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,3); $where_str = 'id > 0'; if($is_tj) { $search_log = UserSearch::getSearchTitle($this->user_id,3); $search_arr = []; foreach ($search_log as $t){ $search_arr[] = " title like '".'%'.$t."%'" .' '; } if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr); } $list = DatumIntro::where($sel_where)->with('urlArr') ->limit($this->off_set,$this->page_num) ->where($where_str) ->order($order) ->select()->toArray(); array_walk($list,function (&$v,$k){ $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['id']); $v['down_num'] = array_sum(array_column($v['url_arr'],'down_num')); }); $this->success('ok',['list'=>$list]); } /** * @title 获取资料详情(平台) * @desc 获取资料详情 * @author qc * @method GET * @url /api/Datum/getDatumDetail * @header name:Authorization require:1 desc:Token * @param name:id type:int default:0 desc:资料id * @return name:title type:string default:-- desc:标题 * @return name:datum_url type:string default:-- desc:资料地址 * @return name:down_num type:string default:-- desc:下载量 * @return name:url_arr type:array default:-- desc:资料 * @return name:url_arr.id type:int default:-- desc:[请求/api/Datum/getDatumItemInfo用,请求资料模块其他接口参数:url_id] * @return name:url_arr.title type:string default:-- desc:资料标题 * @return name:url_arr.is_vip type:int default:-- desc:是否是vip * @return name:url_arr.url type:string default:-- desc:资料地址 * @return name:url_arr.is_collect type:int default:-- desc:是否收藏 * @return name:url_arr.collect_num type:int default:-- desc:收藏量 * @return name:url_arr.down_num type:int default:-- desc:下载量 */ public function getDatumDetail() { $sel_where = []; $sel_where[] = ['id','=',input('get.id')]; $detail = DatumIntro::where($sel_where)->with('urlArr')->find()->toArray(); if($detail['is_deleted'] == 1 || $detail['status'] == 0)$this->error('该资料已下线'); $level_id = UserLevelRank::getUserVip($this->user_id); foreach ($detail['url_arr'] as &$dv) { if($dv['is_vip'] && !$level_id) $dv['url'] = ''; $dv['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['id'],$dv['id']); $dv['collect_num'] = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>1,'coll_id'=>$detail['id'],'children_id'=>$dv['id']])->count(); } $detail['read_num'] = array_sum(array_column($detail['url_arr'],'read_num')); $detail['down_num'] = array_sum(array_column($detail['url_arr'],'down_num')); $this->success('ok',['detail'=>$detail]); } /** * @title 获取资料ITEM详情(平台) * @desc 获取资料ITEM详情 * @author qc * @method GET * @url /api/Datum/getDatumItemInfo * @header name:Authorization require:1 desc:Token * @param name:url_id type:int default:0 desc:url_id * @return name:title type:string default:-- desc:资料标题 * @return name:is_vip type:int default:-- desc:是否是vip * @return name:cover type:string default:-- desc:封面 * @return name:images type:int default:-- desc:图片 * @return name:content type:int default:-- desc:内容 * @return name:transmit_num type:int default:-- desc:转发量 * @return name:read_num type:int default:-- desc:阅读量 * @return name:collect_num type:int default:-- desc:收藏量 * @return name:down_num type:int default:-- desc:下载量 * @return name:is_collect type:int default:-- desc:是否收藏 */ public function getDatumItemInfo() { $url_id = input('get.url_id'); $detail = DatumUrl::where('id',$url_id)->find()->toArray(); $detail['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$detail['datum_id'],'children_id'=>$detail['id']])->count(); $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['datum_id'],$detail['id']); UserTrack::crateTrack($this->user_id,2,$detail['datum_id'],$url_id); $this->success('ok',['detail'=>$detail]); } /** * @title 资料转发(转发数量统计) * @desc 转发成功后调用 * @author qc * @method POST * @url /api/Datum/datumTransmit * @header name:Authorization require:1 desc:Token * @param name:datum_id type:int default:-- desc:资料id * @param name:url_id type:int default:-- desc:url_id */ public function datumTransmit() { $datum_id= input('post.datum_id'); $url_id = input('post.url_id',0); DatumUrl::where('id',$url_id)->setInc('transmit_num'); $this->success('ok'); } /** * @title 资料下载(资料下载数量统计) * @desc 资料下载 * @author qc * @method POST * @url /api/Datum/datumDownload * @header name:Authorization require:1 desc:Token * @param name:datum_id type:int default:-- desc:资料id * @param name:url_id type:int default:-- desc:url_id */ public function datumDownload() { $datum_id= input('post.datum_id'); $url_id = input('post.url_id',0); Data::save('UserDownload',['user_id'=>$this->user_id,'first_id'=>$datum_id,'second_id'=>$url_id]); DatumUrl::where('id',$url_id)->setInc('down_num'); $this->success('ok'); } /** * @title 资料阅读(阅读数量统计) * @desc 资料阅读 * @author qc * @method POST * @url /api/Datum/datumRead * @header name:Authorization require:1 desc:Token * @param name:url_id type:int default:-- desc:url_arr的id */ public function datumRead() { $url_id = input('post.url_id',0); DatumUrl::where('id',$url_id)->setInc('read_num'); $this->success('ok'); } /** * @title 资料收藏||取消收藏 * @desc 用户收藏 * @author qc * @method POST * @url /api/Datum/datumCollect * @header name:Authorization require:1 desc:Token * @param name:datum_id type:int require:1 default:-- desc:记录id[资料id] * @param name:url_id type:int default:1 desc:url_id * @return name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏) */ public function datumCollect() { $coll_type = input('post.coll_type',2); $coll_id = input('post.datum_id',0); $url_id = input('post.url_id',0); if(!$coll_id || !$url_id) $this->error('参数错误'); $collect_check = UserCollect::checkCollectByType($this->user_id,$coll_type,$coll_id,$url_id); if($collect_check) { UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id,'children_id'=>$url_id])->delete(); $this->success('取消收藏成功',['status'=>0]); }else{ Data::save('UserCollect', [ 'user_id'=>$this->user_id, 'coll_type'=>$coll_type, 'coll_id'=>$coll_id, 'children_id'=>$url_id, 'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$coll_id,'children_id'=>$url_id]); $this->success('收藏成功',['status'=>1]); } } /** * @title 资料点赞||取消点赞 * @desc 点赞||取消点赞 * @author qc * @method POST * @url /api/Datum/datumTags * @header name:Authorization require:1 desc:Token * @param name:datum_id type:int default:1 desc:资料id * @param name:url_id type:int default:1 desc:url_id * @return name:tags type:int default:1 desc:0取消成功,1点赞成功 */ public function datumTags() { $datum_id = input('post.datum_id'); $url_id = input('post.url_id'); $ret_val = 0; $check_tags = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->value('id'); if($check_tags) { DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->delete(); }else{ Data::save('DatumLike', ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id],'user_id', ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id]); $ret_val = 1; } $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]); } /** * @title 用户提交或修改资料【个人】 * @desc 用户提交或修改资料【个人】 * @author qc * @method POST * @url /api/Datum/userReferDatum * @header name:Authorization require:1 desc:Token * @param name:id type:int default:-- desc:id(修改时必传) * @param name:title type:string default:-- desc:标题 * @param name:datum_url type:string default:-- desc:资料地址 * @param name:desc type:string default:-- desc:简介 * @param name:label type:string default:-- desc:资料标签id(多个用逗号隔开) */ public function userReferDatum() { $id = input('post.id',0); $title = input('post.title'); $desc = input('post.desc'); $datum_url = input('post.datum_url'); $label = input('post.label'); if(!$datum_url) $this->error('请上传资料'); if($id){ $check_status = UserDatum::where('id',$id)->value('status'); if($check_status == 1) $this->error('已审核通过,不允许修改'); } $data = [ 'title' => $title, 'user_id' => $this->user_id, 'desc' => $desc, 'datum_url' => $datum_url, 'label' => $label, 'status' => 0, 'remark' => '', ]; if($id) $data['id'] = $id; if($id){ UserDatum::where('id',$id)->update($data); }else{ $res= UserDatum::create($data) ; } UserMessage::sendUserMessage($this->user_id,'datum',1,0,0,$id ? $id:$res->id); $this->success('提交成功,请等待审核',['id'=> $id ? :$res->id]); } /** * @title 获取我的资料列表【个人】 * @desc 获取我的资料列表【个人】 * @author qc * @method GET * @url /api/Datum/getMyDatumList * @header name:Authorization require:1 desc:Token * @param name:title type:string default:-- desc:标题 * @param name:page type:int default:0 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @return name:title type:string default:-- desc:标题 * @return name:desc type:string default:-- desc:简介 * @return name:datum_url type:string default:-- desc:资料地址 * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过 * @return name:remark type:string default:-- desc:审核备注 * @return name:label type:string default:-- desc:标签 */ public function getMyDatumList() { $sel_where = []; $sel_where[] = ['is_deleted','=',0]; $sel_where[] = ['user_id','=',$this->user_id]; $title = input('get.title'); if($title) $sel_where[] = ['title|label','like','%'.$title.'%']; $list = UserDatum::where($sel_where) ->field('id,title,desc,datum_url,status,remark,label') ->order('id desc') ->limit($this->off_set,$this->page_num) ->select()->toArray(); $this->success('ok',['list'=>$list]); } /** * @title 获取我的资料详情【个人】 * @desc 获取我的资料列表【个人】 * @author qc * @method GET * @url /api/Datum/getUserDatumDetail * @header name:Authorization require:1 desc:Token * @param name:id type:string default:-- desc:记录id * @return name:title type:string default:-- desc:标题 * @return name:desc type:string default:-- desc:简介 * @return name:datum_url type:string default:-- desc:资料地址 * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过 * @return name:remark type:string default:-- desc:审核备注 * @return name:label type:string default:-- desc:标签 * @return name:label_name type:array default:-- desc:标签数组 */ public function getUserDatumDetail() { $detail =UserDatum::where('id',input('get.id'))->field('id,title,desc,datum_url,status,remark,label')->find(); if(!$detail) $this->error('资料有误'); $detail['label_name'] =$detail['label'] ? $detail['label_name'] = explode(',',trim($detail['label'],',')) : null; $this->success('ok',['detail'=>$detail->toArray()]); } /** * @title 用户删除资料记录【个人】 * @desc 用户删除资料记录【个人】 * @author qc * @method POST * @url /api/Datum/delUserDatum * @header name:Authorization require:1 desc:Token * @param name:id type:int default:-- desc:id */ public function delUserDatum() { UserDatum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete(); $this->success('删除成功'); } /** * @title 获取下载资料列表 * @desc 获取下载资料列表 * @author qc * @method GET * @url /api/Datum/getDownloadDatum * @header name:Authorization require:1 desc:Token * @param name:title type:string default:-- desc:标题 * @param name:page type:int default:0 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @return name:title type:string default:-- desc:标题 * @return name:datum_id type:int default:-- desc:资料id * @return name:url_id type:int default:-- desc:item_id * @return name:is_vip type:int default:-- desc:是否vip[0否1是] * @return name:url type:string default:-- desc:资料路径 */ public function getDownloadDatum() { $sel_where = []; $title = input('get.title'); if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%']; $sel_where[] = ['t.user_id','=',$this->user_id]; $sel_where[] = ['t.type','=',1]; $list = UserDownload::where($sel_where) ->alias('t') ->field('t.id,t.create_at,t.first_id datum_id,t.second_id url_id,i.title,i.is_vip,i.url') ->leftJoin('DatumUrl i','t.second_id = i.id') ->order('id desc') ->limit($this->off_set,$this->page_num) ->select()->toArray(); $this->success('ok',['list'=>$list]); } /** * @title 资料学习历史 * @desc 资料学习历史 * @author qc * @method GET * @url /api/Datum/getLearnHistory * @header name:Authorization require:1 desc:Token * @param name:title type:string default:-- desc:标题 * @param name:page type:int default:0 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @return name:title type:string default:-- desc:标题 * @return name:datum_id type:int default:-- desc:资料id * @return name:url_id type:int default:-- desc:item_id * @return name:is_vip type:int default:-- desc:是否vip[0否1是] * @return name:url type:string default:-- desc:资料路径 */ public function getLearnHistory() { $sel_where = []; $sel_where[] = ['t.user_id','=',$this->user_id]; $sel_where[] = ['t.type','=',2]; $title = input('get.title'); if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%']; $list = UserTrack::where($sel_where) ->alias('t') ->field('t.id,t.update_int,t.first_id datum_id,t.second_id url_id,i.title,i.url,i.is_vip') ->leftJoin('DatumUrl i','t.second_id = i.id') ->order('update_int desc') ->limit($this->off_set,$this->page_num) ->select()->toArray(); foreach ($list as &$v) { $v['time'] = date("Y-m-d H:i:s",$v['update_int']); } $this->success('ok',['list'=>$list]); } /** * @title 资料收藏记录 * @desc 图文收藏记录 * @author qc * @method GET * @url /api/Datum/getDatumCollect * @header name:Authorization require:1 desc:Token * @param name:title type:string default:-- desc:标题 * @param name:page type:int default:0 desc:页数 * @param name:page_num type:int default:20 desc:每页数 * @return name:title type:string default:-- desc:标题 * @return name:datum_id type:string default:-- desc:资料id * @return name:url_id type:string default:-- desc:url_id * @return name:url type:string default:-- desc:资料路径 * @return name:create_at type:string default:-- desc:时间 */ public function getDatumCollect() { $sel_where = []; $title = input('get.title'); if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%']; $sel_where[] = ['t.user_id','=',$this->user_id]; $sel_where[] = ['t.coll_type','=',2]; $list = UserCollect::where($sel_where) ->alias('t') ->field('t.id,t.create_at,t.coll_id datum_id,t.children_id url_id,i.title,i.url,i.is_vip') ->leftJoin('DatumUrl i','t.children_id = i.id') ->order('id desc') ->limit($this->off_set,$this->page_num) ->select()->toArray(); $this->success('ok',['list'=>$list]); } }