select(); foreach ($list as $k=>&$v){ $a = DataBestKnowledge::mk()->where('class_id',$v['id'])->where('audit',2)->where('is_del',1)->count('id'); if(!$a){ unset($list[$k]); } } $this->success('成功',$list); } /** * @Title("提交发布信息") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=1,default="",desc="token") * @Param("title",type="string",require=1,default="",desc="标题") * @Param("content",type="string",require=1,default="",desc="内容") * @Param("imgs",type="string",require=0,default="",desc="图片,多个以英文逗号隔开") * @Param("video",type="string",require=0,default="",desc="视频") * @Param("file",type="string",require=0,default="",desc="文件,多个以英文逗号隔开") * @Param("amount",type="decimal",require=0,default="0",desc="收费金额") * @Param("class_id",type="int",require=0,default="0",desc="分类ID") * @Param("id",type="string",require=0,default="",desc="审核失败,修改,则必传之前提交的ID") */ public function subinfo() { $user = $this->getUser(); if (!$user['is_auth']) $this->error('未实名认证,无法发布'); $is_pool = DataPoolTalent::mk()->where('uuid',$this->uuid)->where('audit',2)->count(); if (!$is_pool) $this->error('请先加入人才库'); $data = $this->_vali([ 'uuid.default'=>$this->uuid, 'title.require'=>'标题必须', 'content.require'=>'内容必填', 'imgs.default'=>'', 'video.default'=>'', 'file.default'=>'', 'type.default'=>'2', 'amount.default'=>'0', 'class_id.require'=>'分类必须' ]); if (!isAmount($data['amount'])) $this->error('金额错误'); $id = input('id'); empty($id) ? : $data['update_at']=date('Y-m-d H:i:s'); !empty($id) ? (DataBestKnowledge::mk()->where('uuid',$this->uuid)->where('id',$id)->value('audit') == 3 ? $data['audit'] =1 : '') : ''; if (empty($id) ? DataBestKnowledge::mk()->insert($data) : DataBestKnowledge::mk()->where('id',$id)->update($data)){ $this->success('提交成功'); } $this->error('提交失败'); } /** * @Title("百知文库列表") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=0,default="",desc="token") * @Param("page",type="int",require=0,default="1",desc="第几页") * @Param("keyword",type="string",require=0,default="",desc="关键词") * @Param("class_id",type="string",require=0,default="",desc="分类ID") */ public function knowlist(){ $keyword = input('keyword'); $class_id = input('class_id'); $list = DataBestKnowledge::mk() ->where('audit',2) ->where('is_del',1) ->when($keyword,function ($query) use ($keyword){ $query->whereLike('title|content','%'.$keyword.'%'); }) ->when($class_id,function ($query) use ($class_id){ $query->where('class_id',$class_id); }) ->with(['user'=>function($query){ $query->field('id,nickname,headimg,is_auth,is_vip'); },'classTo']) ->order('create_at','desc') ->paginate(); $this->success('成功',$list); } /** * @Title("百知文库列表") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=0,default="",desc="token") * @Param("page",type="int",require=0,default="1",desc="第几页") * @Param("keyword",type="string",require=0,default="",desc="关键词") * @Param("class_id",type="string",require=0,default="",desc="分类ID") * @Param ("exad",desc="之前加载的列表中所有的广告ID,用,隔开",default="") */ public function knowlist2(){ $page=input('page/d')?:1; $keyword = input('keyword'); $exad=input('exad'); $class_id = input('class_id'); list($limit,$adNum,$splitNum)=$this->getLimit(); $list = DataBestKnowledge::mk() ->where('audit',2) ->where('is_del',1) ->when($keyword,function ($query) use ($keyword){ $query->whereLike('title|content','%'.$keyword.'%'); }) ->when($class_id,function ($query) use ($class_id){ $query->where('class_id',$class_id); }) ->with(['user'=>function($query){ $query->field('id,nickname,headimg,is_auth,is_vip'); },'classTo']) ->order('create_at','desc') ->paginate($limit); $xwArr=$list->chunk($splitNum); if($list->isEmpty()){ $this->success('',$list); } $ads=DataBestKnowledgeAd::show() ->order('sort','desc') ->when($exad,function (Query $query)use ($exad){ $query->whereNotIn('id',$exad); }) ->limit($adNum) ->select(); $newList=[]; foreach ($xwArr as $key=>$xwOne){ $ad=$ads[$key]??null; foreach ($xwOne as $one){ $one['ctype']=1; $newList[]=$one; } if($ad && count($xwOne)>=$splitNum){ $ad['ctype']=2; $newList[]=$ad; } } $this->success('成功',[ 'total'=>$list->total(), 'per_page'=>$limit, 'current_page'=>$page, 'last_page'=>$list->lastPage(), 'data'=>$newList ]); } protected function getLimit(){ $splitNum=sysconf('config_xw.split_num2')?:3; $min=15; $limit=1; while ($limit*$splitNum<$min){ $limit++; } return [$limit*$splitNum,$limit,$splitNum]; } /** * @Title("百知文库详情页") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=0,default="",desc="token") * @Param("id",type="int",require=0,default="1",desc="id") * * @Returned("is_collect",desc="是否收藏1:已收藏0:未收藏") */ public function knowdetail(){ $id = input('id'); $uuid = $this->uuid; $detail = DataBestKnowledge::mk() ->where('audit',2) ->with(['user'=>function($query){ $query->field('id,nickname,headimg,is_auth,is_vip'); }]) ->where('is_del',1) ->where('id',$id) ->findOrFail(); $detail['is_collect'] = !empty($uuid) ? (DataCollectionLog::mk()->where('link_id',$id)->where('uuid',$uuid)->where('type',2)->count() ? 1 : 0) : 0; $this->success('成功',$detail); } /** * @Title("广告详情页") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=0,default="",desc="token") * @Param("id",type="int",require=0,default="1",desc="id") * */ public function ad_detail(){ $id = input('id'); $detail = DataBestKnowledgeAd::mk() ->where('status',1) ->where('id',$id) ->findOrFail(); $this->success('成功',$detail); } /** * @Title("百知文库收藏/取消收藏") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=1,default="",desc="token") * @Param("id",type="string",require=1,default="",desc="主键ID") * @Param("category",type="string",require=1,default="",desc="1:收藏2:取消收藏") */ public function cocanclecollection(){ $data = $this->_vali([ 'id.require'=>'id必须', 'category.require|in:1,2'=>'category有误' ]); switch ($data['category']){ case 1: DataCollectionLog::Show(2,$this->uuid,$data['id'])->count() ? $this->error('已收藏过') : ''; if (DataCollectionLog::mk()->insert(['uuid'=>$this->uuid,'type'=>2,'link_id'=>$data['id']])){ $this->success('收藏成功'); } $this->error('收藏失败'); break; case 2: DataCollectionLog::Show(2,$this->uuid,$data['id'])->count() ? : $this->error('未收藏'); if (DataCollectionLog::mk()->where('uuid',$this->uuid)->where('type',2)->where('link_id',$data['id'])->delete()){ $this->success('取消成功'); } $this->error('取消失败'); break; } } /** * @Title("百知文库分享") * @Method("post") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=1,default="",desc="token") * @Param("id",type="string",require=1,default="",desc="主键ID") */ public function knowshare(){ $data = $this->_vali([ 'id.require'=>'id必须' ]); if (DataShareLog::mk()->insert(['uuid'=>$this->uuid,'type'=>2,'link_id'=>$data['id']])){ $this->success('分享成功'); } $this->error('分享失败'); } /** * @Title ("上传视频限制时长") * @Method ("get") * @Header("api-name",type="string",require=1,default="",desc="访问类型") * @Header("api-token",type="string",require=1,default="",desc="token") * @Returned("data",desc="限制时长") */ public function knowvideo(){ $data = SystemConfig('know_config.video')?:[]; if(!$data)$this->error('配置错误'); $this->success('成功',$data); } }