BestKnowledge.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. namespace app\data\controller\api\auth;
  3. use app\data\controller\api\Auth;
  4. use app\data\model\DataBestKnowledge;
  5. use app\data\model\DataBestKnowledgeAd;
  6. use app\data\model\DataClassification;
  7. use app\data\model\DataCollectionLog;
  8. use app\data\model\DataPoolTalent;
  9. use app\data\model\DataShareLog;
  10. use app\data\model\DataTeachingKnowledge;
  11. use app\data\model\DataXwAd;
  12. use hg\apidoc\annotation\Desc;
  13. use think\admin\model\SystemConfig;
  14. use think\admin\Storage;
  15. use think\db\Query;
  16. use think\exception\HttpResponseException;
  17. use think\admin\Controller;
  18. use hg\apidoc\annotation\Title;
  19. use hg\apidoc\annotation\Method;
  20. use hg\apidoc\annotation\Param;
  21. use hg\apidoc\annotation\Header;
  22. use hg\apidoc\annotation\Returned;
  23. use think\facade\Validate;
  24. /**
  25. * @Title("百知文库")
  26. */
  27. class BestKnowledge extends Auth
  28. {
  29. protected $noNeedLogin=['classification','knowlist','knowdetail','knowlist2'];
  30. /**
  31. * @Title("分类列表")
  32. * @Method("post")
  33. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  34. * @Header("api-token",type="string",require=0,default="",desc="token")
  35. */
  36. public function classification(){
  37. $list = DataClassification::Show(1)->select();
  38. foreach ($list as $k=>&$v){
  39. $a = DataBestKnowledge::mk()->where('class_id',$v['id'])->where('audit',2)->where('is_del',1)->count('id');
  40. if(!$a){
  41. unset($list[$k]);
  42. }
  43. }
  44. $this->success('成功',$list);
  45. }
  46. /**
  47. * @Title("提交发布信息")
  48. * @Method("post")
  49. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  50. * @Header("api-token",type="string",require=1,default="",desc="token")
  51. * @Param("title",type="string",require=1,default="",desc="标题")
  52. * @Param("content",type="string",require=1,default="",desc="内容")
  53. * @Param("imgs",type="string",require=0,default="",desc="图片,多个以英文逗号隔开")
  54. * @Param("video",type="string",require=0,default="",desc="视频")
  55. * @Param("file",type="string",require=0,default="",desc="文件,多个以英文逗号隔开")
  56. * @Param("amount",type="decimal",require=0,default="0",desc="收费金额")
  57. * @Param("class_id",type="int",require=0,default="0",desc="分类ID")
  58. * @Param("id",type="string",require=0,default="",desc="审核失败,修改,则必传之前提交的ID")
  59. */
  60. public function subinfo()
  61. {
  62. $user = $this->getUser();
  63. if (!$user['is_auth']) $this->error('未实名认证,无法发布');
  64. $is_pool = DataPoolTalent::mk()->where('uuid',$this->uuid)->where('audit',2)->count();
  65. if (!$is_pool) $this->error('请先加入人才库');
  66. $data = $this->_vali([
  67. 'uuid.default'=>$this->uuid,
  68. 'title.require'=>'标题必须',
  69. 'content.require'=>'内容必填',
  70. 'imgs.default'=>'',
  71. 'video.default'=>'',
  72. 'file.default'=>'',
  73. 'type.default'=>'2',
  74. 'amount.default'=>'0',
  75. 'class_id.require'=>'分类必须'
  76. ]);
  77. if (!isAmount($data['amount'])) $this->error('金额错误');
  78. $id = input('id');
  79. empty($id) ? : $data['update_at']=date('Y-m-d H:i:s');
  80. !empty($id) ? (DataBestKnowledge::mk()->where('uuid',$this->uuid)->where('id',$id)->value('audit') == 3 ? $data['audit'] =1 : '') : '';
  81. if (empty($id) ? DataBestKnowledge::mk()->insert($data) : DataBestKnowledge::mk()->where('id',$id)->update($data)){
  82. $this->success('提交成功');
  83. }
  84. $this->error('提交失败');
  85. }
  86. /**
  87. * @Title("百知文库列表")
  88. * @Method("post")
  89. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  90. * @Header("api-token",type="string",require=0,default="",desc="token")
  91. * @Param("page",type="int",require=0,default="1",desc="第几页")
  92. * @Param("keyword",type="string",require=0,default="",desc="关键词")
  93. * @Param("class_id",type="string",require=0,default="",desc="分类ID")
  94. */
  95. public function knowlist(){
  96. $keyword = input('keyword');
  97. $class_id = input('class_id');
  98. $list = DataBestKnowledge::mk()
  99. ->where('audit',2)
  100. ->where('is_del',1)
  101. ->when($keyword,function ($query) use ($keyword){
  102. $query->whereLike('title|content','%'.$keyword.'%');
  103. })
  104. ->when($class_id,function ($query) use ($class_id){
  105. $query->where('class_id',$class_id);
  106. })
  107. ->with(['user'=>function($query){
  108. $query->field('id,nickname,headimg,is_auth,is_vip');
  109. },'classTo'])
  110. ->order('create_at','desc')
  111. ->paginate();
  112. $this->success('成功',$list);
  113. }
  114. /**
  115. * @Title("百知文库列表")
  116. * @Method("post")
  117. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  118. * @Header("api-token",type="string",require=0,default="",desc="token")
  119. * @Param("page",type="int",require=0,default="1",desc="第几页")
  120. * @Param("keyword",type="string",require=0,default="",desc="关键词")
  121. * @Param("class_id",type="string",require=0,default="",desc="分类ID")
  122. * @Param ("exad",desc="之前加载的列表中所有的广告ID,用,隔开",default="")
  123. */
  124. public function knowlist2(){
  125. $page=input('page/d')?:1;
  126. $keyword = input('keyword');
  127. $exad=input('exad');
  128. $class_id = input('class_id');
  129. list($limit,$adNum,$splitNum)=$this->getLimit();
  130. $list = DataBestKnowledge::mk()
  131. ->where('audit',2)
  132. ->where('is_del',1)
  133. ->when($keyword,function ($query) use ($keyword){
  134. $query->whereLike('title|content','%'.$keyword.'%');
  135. })
  136. ->when($class_id,function ($query) use ($class_id){
  137. $query->where('class_id',$class_id);
  138. })
  139. ->with(['user'=>function($query){
  140. $query->field('id,nickname,headimg,is_auth,is_vip');
  141. },'classTo'])
  142. ->order('create_at','desc')
  143. ->paginate($limit);
  144. $xwArr=$list->chunk($splitNum);
  145. if($list->isEmpty()){
  146. $this->success('',$list);
  147. }
  148. $ads=DataBestKnowledgeAd::show()
  149. ->order('sort','desc')
  150. ->when($exad,function (Query $query)use ($exad){
  151. $query->whereNotIn('id',$exad);
  152. })
  153. ->limit($adNum)
  154. ->select();
  155. $newList=[];
  156. foreach ($xwArr as $key=>$xwOne){
  157. $ad=$ads[$key]??null;
  158. foreach ($xwOne as $one){
  159. $one['ctype']=1;
  160. $newList[]=$one;
  161. }
  162. if($ad && count($xwOne)>=$splitNum){
  163. $ad['ctype']=2;
  164. $newList[]=$ad;
  165. }
  166. }
  167. $this->success('成功',[
  168. 'total'=>$list->total(),
  169. 'per_page'=>$limit,
  170. 'current_page'=>$page,
  171. 'last_page'=>$list->lastPage(),
  172. 'data'=>$newList
  173. ]);
  174. }
  175. protected function getLimit(){
  176. $splitNum=sysconf('config_xw.split_num2')?:3;
  177. $min=15;
  178. $limit=1;
  179. while ($limit*$splitNum<$min){
  180. $limit++;
  181. }
  182. return [$limit*$splitNum,$limit,$splitNum];
  183. }
  184. /**
  185. * @Title("百知文库详情页")
  186. * @Method("post")
  187. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  188. * @Header("api-token",type="string",require=0,default="",desc="token")
  189. * @Param("id",type="int",require=0,default="1",desc="id")
  190. *
  191. * @Returned("is_collect",desc="是否收藏1:已收藏0:未收藏")
  192. */
  193. public function knowdetail(){
  194. $id = input('id');
  195. $uuid = $this->uuid;
  196. $detail = DataBestKnowledge::mk()
  197. ->where('audit',2)
  198. ->with(['user'=>function($query){
  199. $query->field('id,nickname,headimg,is_auth,is_vip');
  200. }])
  201. ->where('is_del',1)
  202. ->where('id',$id)
  203. ->findOrFail();
  204. $detail['is_collect'] = !empty($uuid) ? (DataCollectionLog::mk()->where('link_id',$id)->where('uuid',$uuid)->where('type',2)->count() ? 1 : 0) : 0;
  205. $this->success('成功',$detail);
  206. }
  207. /**
  208. * @Title("广告详情页")
  209. * @Method("post")
  210. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  211. * @Header("api-token",type="string",require=0,default="",desc="token")
  212. * @Param("id",type="int",require=0,default="1",desc="id")
  213. *
  214. */
  215. public function ad_detail(){
  216. $id = input('id');
  217. $detail = DataBestKnowledgeAd::mk()
  218. ->where('status',1)
  219. ->where('id',$id)
  220. ->findOrFail();
  221. $this->success('成功',$detail);
  222. }
  223. /**
  224. * @Title("百知文库收藏/取消收藏")
  225. * @Method("post")
  226. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  227. * @Header("api-token",type="string",require=1,default="",desc="token")
  228. * @Param("id",type="string",require=1,default="",desc="主键ID")
  229. * @Param("category",type="string",require=1,default="",desc="1:收藏2:取消收藏")
  230. */
  231. public function cocanclecollection(){
  232. $data = $this->_vali([
  233. 'id.require'=>'id必须',
  234. 'category.require|in:1,2'=>'category有误'
  235. ]);
  236. switch ($data['category']){
  237. case 1:
  238. DataCollectionLog::Show(2,$this->uuid,$data['id'])->count() ? $this->error('已收藏过') : '';
  239. if (DataCollectionLog::mk()->insert(['uuid'=>$this->uuid,'type'=>2,'link_id'=>$data['id']])){
  240. $this->success('收藏成功');
  241. }
  242. $this->error('收藏失败');
  243. break;
  244. case 2:
  245. DataCollectionLog::Show(2,$this->uuid,$data['id'])->count() ? : $this->error('未收藏');
  246. if (DataCollectionLog::mk()->where('uuid',$this->uuid)->where('type',2)->where('link_id',$data['id'])->delete()){
  247. $this->success('取消成功');
  248. }
  249. $this->error('取消失败');
  250. break;
  251. }
  252. }
  253. /**
  254. * @Title("百知文库分享")
  255. * @Method("post")
  256. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  257. * @Header("api-token",type="string",require=1,default="",desc="token")
  258. * @Param("id",type="string",require=1,default="",desc="主键ID")
  259. */
  260. public function knowshare(){
  261. $data = $this->_vali([
  262. 'id.require'=>'id必须'
  263. ]);
  264. if (DataShareLog::mk()->insert(['uuid'=>$this->uuid,'type'=>2,'link_id'=>$data['id']])){
  265. $this->success('分享成功');
  266. }
  267. $this->error('分享失败');
  268. }
  269. /**
  270. * @Title ("上传视频限制时长")
  271. * @Method ("get")
  272. * @Header("api-name",type="string",require=1,default="",desc="访问类型")
  273. * @Header("api-token",type="string",require=1,default="",desc="token")
  274. * @Returned("data",desc="限制时长")
  275. */
  276. public function knowvideo(){
  277. $data = SystemConfig('know_config.video')?:[];
  278. if(!$data)$this->error('配置错误');
  279. $this->success('成功',$data);
  280. }
  281. }