Datum.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\ArticleItem;
  4. use app\common\model\DatumCate;
  5. use app\common\model\DatumIntro;
  6. use app\common\model\DatumLike;
  7. use app\common\model\DatumUrl;
  8. use app\common\model\PlatformSwitch;
  9. use app\common\model\User;
  10. use app\common\model\UserCollect;
  11. use app\common\model\UserDatum;
  12. use app\common\model\UserDownload;
  13. use app\common\model\UserLevelRank;
  14. use app\common\model\UserMessage;
  15. use app\common\model\UserSearch;
  16. use app\common\model\UserTrack;
  17. use app\common\service\CheckPower;
  18. use library\tools\Data;
  19. use think\Db;
  20. /**
  21. * @title 资料
  22. * @controller Datum
  23. * @group base
  24. */
  25. class Datum extends Base
  26. {
  27. // 需要登录的
  28. protected $need_login = [
  29. 'datumTransmit',
  30. 'datumDownload',
  31. 'datumRead',
  32. 'datumCollect',
  33. 'datumTags',
  34. 'userReferDatum',
  35. 'getMyDatumList',
  36. 'getUserDatumDetail',
  37. 'delUserDatum',
  38. 'getDownloadDatum',
  39. 'getLearnHistory',
  40. 'getDatumCollect',
  41. 'getBoundList',
  42. 'getFollowUpList',
  43. ];
  44. public function initialize()
  45. {
  46. parent::initialize();
  47. parent::setUid();
  48. }
  49. /**
  50. * @title 资料接口说明
  51. * @desc 资料接口说明
  52. * @author qc
  53. * @url /api/Datum/classIntro
  54. * @method GET
  55. * @return name:1 type:string default:-- desc:单一资料与系列资料区别,type值(1是单一,2是系列),数据:url_arr二维数组数据数量不一样(单一的只有一个,系列的可以是多个)【可以将单一资料看做只有一条记录的系列资料!!!!】
  56. * @return name:2 type:string default:-- desc:单一资料详情的字段(除id)与url_arr数组的第一个同字段名的值相同
  57. * @return name:3 type:string default:-- desc:系列资料详情的字段(除id)与url_arr数组的其中一个同字段名的值相同
  58. * @return name:4 type:string default:-- desc:关于是否的字段(0否,1是)
  59. * @return name:5 type:string default:-- desc:url_id是详情或列表url_arr下的id
  60. */
  61. public function classIntro(){ }
  62. /**
  63. * @title 获取资料目录
  64. * @desc 获取资料目录
  65. * @author qc
  66. * @url /api/Datum/getDatumCate
  67. * @method GET
  68. * @header name:Authorization require:1 desc:Token
  69. * @return name:id type:int default:-- desc:id
  70. * @return name:title type:string default:0 desc:名称
  71. * @return name:datum_list type:array default:0 desc:目录下的资料
  72. * @return name:datum_list.id type:int default:0 desc:资料记录
  73. * @return name:datum_list.title type:int default:0 desc:资料标题
  74. */
  75. public function getDatumCate()
  76. {
  77. $list = DatumCate::field('id,title')->where('is_deleted',0)->where('status',1)->select()->toArray();
  78. foreach ($list as &$v) {
  79. $v['datum_list'] = DatumIntro::field('id,title')
  80. ->where(['datum_cate'=>$v['id'],'status'=>1,'is_deleted'=>0])->select()->toArray();
  81. }
  82. $this->success('ok',['list'=>$list]);
  83. }
  84. /**
  85. * @title 资料推荐
  86. * @desc 资料推荐
  87. * @author qc
  88. * @method GET
  89. * @url /api/Datum/getRecommendList
  90. * @header name:Authorization require:1 desc:Token
  91. * @param name:page type:int default:0 desc:页数
  92. * @param name:page_num type:int default:20 desc:每页数
  93. * @return name:id type:string default:-- desc:资料item_id
  94. * @return name:title type:string default:-- desc:标题
  95. * @return name:datum_id type:string default:-- desc:系列id
  96. * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
  97. * @return name:read_num type:int default:-- desc:阅读量
  98. * @return name:down_num type:int default:-- desc:下载量
  99. * @return name:url type:int default:-- desc:资料路径
  100. */
  101. public function getRecommendList()
  102. {
  103. $search_log = UserSearch::getSearchTitle($this->user_id,3);
  104. $search_arr = [];
  105. $where_str = 'b.id > 0';
  106. foreach ($search_log as $t){
  107. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  108. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  109. }
  110. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  111. $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 ';
  112. $table = 'dd_datum_url';
  113. $order_by_two = 'a.read_num';
  114. $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}";
  115. $list = Db::query($sql);
  116. $list = dispose_recommend($list);
  117. array_walk($list,function (&$v,$k){
  118. $v['down_num'] = numTransform($v['down_num']);
  119. $v['read_num'] = numTransform($v['read_num']);
  120. });
  121. $this->success('ok',['list'=>$list,'sql'=>$sql]);
  122. }
  123. /**
  124. * @title 获取资料列表(平台发布)
  125. * @desc 获取资料列表
  126. * @author qc
  127. * @method GET
  128. * @url /api/Datum/getDatumList
  129. * @header name:Authorization require:1 desc:Token
  130. * @param name:type type:int default:0 desc:类型1单个2系列
  131. * @param name:is_tj type:int default:0 desc:是否推荐0否1是
  132. * @param name:title type:string default:-- desc:标题
  133. * @param name:page type:int default:0 desc:页数
  134. * @param name:page_num type:int default:20 desc:每页数
  135. * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
  136. * @return name:id type:int default:-- desc:[请求/api/Datum/getDatumDetail用,请求资料模块其他接口参数:url_id]
  137. * @return name:title type:string default:-- desc:标题
  138. * @return name:type type:int default:0 desc:类型1单个2系列
  139. * @return name:datum_url type:string default:-- desc:资料地址
  140. * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
  141. * @return name:is_over type:int default:-- desc:是否完结(0否,1是)
  142. * @return name:label type:string default:-- desc:标签
  143. * @return name:is_collect type:int default:-- desc:是否收藏
  144. * @return name:url_arr type:array default:-- desc:资料
  145. * @return name:url_arr.title type:string default:-- desc:资料标题
  146. * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
  147. * @return name:url_arr.url type:string default:-- desc:资料地址
  148. */
  149. public function getDatumList()
  150. {
  151. $sel_where = [];
  152. $title = input('get.title');
  153. $type = input('get.type',0);
  154. $is_tj = input('get.is_tj',0);
  155. $sort_type = input('get.sort_type',1);
  156. $sel_where[] = ['is_deleted','=',0];
  157. $sel_where[] = ['status','=',1];
  158. $sel_where[] = ['url_num','>',0];
  159. if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
  160. if($type) $sel_where[] = ['type','=',$type];
  161. switch ($sort_type) {
  162. case 1:
  163. $order = ['sort'=>'desc','read_num'=>'desc'];
  164. break;
  165. case 2:
  166. $order = ['id'=>'asc','sort'=>'desc'];
  167. break;
  168. case 3:
  169. $order = ['id'=>'desc','sort'=>'desc'];
  170. break;
  171. }
  172. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,3);
  173. $where_str = 'id > 0';
  174. if($is_tj) {
  175. $search_log = UserSearch::getSearchTitle($this->user_id,3);
  176. $search_arr = [];
  177. foreach ($search_log as $t){
  178. $search_arr[] = " title like '".'%'.$t."%'" .' ';
  179. }
  180. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  181. }
  182. $list = DatumIntro::where($sel_where)->with('urlArr')
  183. ->limit($this->off_set,$this->page_num)
  184. ->where($where_str)
  185. ->order($order)
  186. ->select()->toArray();
  187. array_walk($list,function (&$v,$k){
  188. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['id']);
  189. $v['down_num'] = array_sum(array_column($v['url_arr'],'down_num'));
  190. $v['down_num'] = numTransform($v['down_num']);
  191. });
  192. $this->success('ok',['list'=>$list]);
  193. }
  194. /**
  195. * @title 获取资料详情(平台)
  196. * @desc 获取资料详情
  197. * @author qc
  198. * @method GET
  199. * @url /api/Datum/getDatumDetail
  200. * @header name:Authorization require:1 desc:Token
  201. * @param name:id type:int default:0 desc:资料id
  202. * @return name:title type:string default:-- desc:标题
  203. * @return name:datum_url type:string default:-- desc:资料地址
  204. * @return name:down_num type:string default:-- desc:下载量
  205. * @return name:url_arr type:array default:-- desc:资料
  206. * @return name:url_arr.id type:int default:-- desc:[请求/api/Datum/getDatumItemInfo用,请求资料模块其他接口参数:url_id]
  207. * @return name:url_arr.title type:string default:-- desc:资料标题
  208. * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
  209. * @return name:url_arr.url type:string default:-- desc:资料地址
  210. * @return name:url_arr.is_collect type:int default:-- desc:是否收藏
  211. * @return name:url_arr.collect_num type:int default:-- desc:收藏量
  212. * @return name:url_arr.down_num type:int default:-- desc:下载量
  213. */
  214. public function getDatumDetail()
  215. {
  216. $sel_where = [];
  217. $sel_where[] = ['id','=',input('get.id')];
  218. $detail = DatumIntro::where($sel_where)->with('urlArr')->find()->toArray();
  219. if($detail['is_deleted'] == 1 || $detail['status'] == 0)$this->error('该资料已下线');
  220. $level_id = UserLevelRank::getUserVip($this->user_id);
  221. $detail['read_num'] = numTransform(array_sum(array_column($detail['url_arr'],'read_num')));
  222. $detail['down_num'] = numTransform(array_sum(array_column($detail['url_arr'],'down_num')));
  223. foreach ($detail['url_arr'] as &$dv) {
  224. if($dv['is_vip'] && !$level_id) $dv['url'] = '';
  225. $dv['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['id'],$dv['id']);
  226. $dv['collect_num'] = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>1,'coll_id'=>$detail['id'],'children_id'=>$dv['id']])->count();
  227. $dv['collect_num'] = numTransform($dv['collect_num']);
  228. $dv['down_num'] = numTransform($dv['down_num']);
  229. }
  230. $this->success('ok',['detail'=>$detail]);
  231. }
  232. /**
  233. * @title 获取资料ITEM详情(平台)
  234. * @desc 获取资料ITEM详情
  235. * @author qc
  236. * @method GET
  237. * @url /api/Datum/getDatumItemInfo
  238. * @header name:Authorization require:1 desc:Token
  239. * @param name:url_id type:int default:0 desc:url_id
  240. * @return name:title type:string default:-- desc:资料标题
  241. * @return name:is_vip type:int default:-- desc:是否是vip
  242. * @return name:cover type:string default:-- desc:封面
  243. * @return name:images type:int default:-- desc:图片
  244. * @return name:content type:int default:-- desc:内容
  245. * @return name:transmit_num type:int default:-- desc:转发量
  246. * @return name:read_num type:int default:-- desc:阅读量
  247. * @return name:collect_num type:int default:-- desc:收藏量
  248. * @return name:down_num type:int default:-- desc:下载量
  249. * @return name:is_collect type:int default:-- desc:是否收藏
  250. */
  251. public function getDatumItemInfo()
  252. {
  253. $url_id = input('get.url_id');
  254. $detail = DatumUrl::where('id',$url_id)->find()->toArray();
  255. if($detail['is_deleted'] == 1 || $detail['status'] == 0) $this->error('该资料已下架');
  256. $detail['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$detail['datum_id'],'children_id'=>$detail['id']])->count();
  257. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['datum_id'],$detail['id']);
  258. $detail['collect_num'] = numTransform($detail['collect_num']);
  259. $detail['down_num'] = numTransform($detail['down_num']);
  260. $detail['read_num'] = numTransform($detail['read_num']);
  261. $detail['transmit_num'] = numTransform($detail['transmit_num']);
  262. UserTrack::crateTrack($this->user_id,2,$detail['datum_id'],$url_id);
  263. $this->success('ok',['detail'=>$detail]);
  264. }
  265. /**
  266. * @title 资料转发(转发数量统计)
  267. * @desc 转发成功后调用
  268. * @author qc
  269. * @method POST
  270. * @url /api/Datum/datumTransmit
  271. * @header name:Authorization require:1 desc:Token
  272. * @param name:datum_id type:int default:-- desc:资料id
  273. * @param name:url_id type:int default:-- desc:url_id
  274. */
  275. public function datumTransmit()
  276. {
  277. $datum_id= input('post.datum_id');
  278. $url_id = input('post.url_id',0);
  279. DatumUrl::where('id',$url_id)->setInc('transmit_num');
  280. $this->success('ok');
  281. }
  282. /**
  283. * @title 资料下载(资料下载数量统计)
  284. * @desc 资料下载
  285. * @author qc
  286. * @method POST
  287. * @url /api/Datum/datumDownload
  288. * @header name:Authorization require:1 desc:Token
  289. * @param name:datum_id type:int default:-- desc:资料id
  290. * @param name:url_id type:int default:-- desc:url_id
  291. */
  292. public function datumDownload()
  293. {
  294. $datum_id= input('post.datum_id');
  295. $url_id = input('post.url_id',0);
  296. Data::save('UserDownload',['user_id'=>$this->user_id,'first_id'=>$datum_id,'second_id'=>$url_id]);
  297. DatumUrl::where('id',$url_id)->setInc('down_num');
  298. $this->success('ok');
  299. }
  300. /**
  301. * @title 资料阅读(阅读数量统计)
  302. * @desc 资料阅读
  303. * @author qc
  304. * @method POST
  305. * @url /api/Datum/datumRead
  306. * @header name:Authorization require:1 desc:Token
  307. * @param name:url_id type:int default:-- desc:url_arr的id
  308. */
  309. public function datumRead()
  310. {
  311. $url_id = input('post.url_id',0);
  312. $datum_id = DatumUrl::where('id',$url_id)->value('datum_id');
  313. DatumUrl::where('id',$url_id)->setInc('read_num');
  314. DatumIntro::where('id',$datum_id)->setInc('read_num');
  315. $this->success('ok');
  316. }
  317. /**
  318. * @title 资料收藏||取消收藏
  319. * @desc 用户收藏
  320. * @author qc
  321. * @method POST
  322. * @url /api/Datum/datumCollect
  323. * @header name:Authorization require:1 desc:Token
  324. * @param name:datum_id type:int require:1 default:-- desc:记录id[资料id]
  325. * @param name:url_id type:int default:1 desc:url_id
  326. * @return name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  327. */
  328. public function datumCollect()
  329. {
  330. $coll_type = input('post.coll_type',2);
  331. $coll_id = input('post.datum_id',0);
  332. $url_id = input('post.url_id',0);
  333. if(!$coll_id || !$url_id) $this->error('参数错误');
  334. $collect_check = UserCollect::checkCollectByType($this->user_id,$coll_type,$coll_id,$url_id);
  335. if($collect_check) {
  336. UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id,'children_id'=>$url_id])->delete();
  337. $this->success('取消收藏成功',['status'=>0]);
  338. }else{
  339. Data::save('UserCollect', [
  340. 'user_id'=>$this->user_id,
  341. 'coll_type'=>$coll_type,
  342. 'coll_id'=>$coll_id,
  343. 'children_id'=>$url_id,
  344. 'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$coll_id,'children_id'=>$url_id]);
  345. $this->success('收藏成功',['status'=>1]);
  346. }
  347. }
  348. /**
  349. * @title 资料点赞||取消点赞
  350. * @desc 点赞||取消点赞
  351. * @author qc
  352. * @method POST
  353. * @url /api/Datum/datumTags
  354. * @header name:Authorization require:1 desc:Token
  355. * @param name:datum_id type:int default:1 desc:资料id
  356. * @param name:url_id type:int default:1 desc:url_id
  357. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  358. */
  359. public function datumTags()
  360. {
  361. $datum_id = input('post.datum_id');
  362. $url_id = input('post.url_id');
  363. $ret_val = 0;
  364. $check_tags = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->value('id');
  365. if($check_tags) {
  366. DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->delete();
  367. }else{
  368. Data::save('DatumLike',
  369. ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id],'user_id',
  370. ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id]);
  371. $ret_val = 1;
  372. }
  373. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  374. }
  375. /**
  376. * @title 用户提交或修改资料【个人】
  377. * @desc 用户提交或修改资料【个人】
  378. * @author qc
  379. * @method POST
  380. * @url /api/Datum/userReferDatum
  381. * @header name:Authorization require:1 desc:Token
  382. * @param name:id type:int default:-- desc:id(修改时必传)
  383. * @param name:title type:string default:-- desc:标题
  384. * @param name:datum_url type:string default:-- desc:资料地址
  385. * @param name:desc type:string default:-- desc:简介
  386. * @param name:label type:string default:-- desc:资料标签id(多个用逗号隔开)
  387. */
  388. public function userReferDatum()
  389. {
  390. $id = input('post.id',0);
  391. $title = input('post.title');
  392. $desc = input('post.desc');
  393. $datum_url = input('post.datum_url');
  394. $label = input('post.label');
  395. if(!$datum_url) $this->error('请上传资料');
  396. if($id){
  397. $check_status = UserDatum::where('id',$id)->value('status');
  398. if($check_status == 1) $this->error('已审核通过,不允许修改');
  399. }
  400. $data = [
  401. 'title' => $title,
  402. 'user_id' => $this->user_id,
  403. 'desc' => $desc,
  404. 'datum_url' => $datum_url,
  405. 'label' => $label,
  406. 'status' => 0,
  407. 'remark' => '',
  408. ];
  409. if($id) $data['id'] = $id;
  410. if($id){
  411. UserDatum::where('id',$id)->update($data);
  412. }else{
  413. $res= UserDatum::create($data) ;
  414. }
  415. UserMessage::sendUserMessage($this->user_id,'datum',1,0,0,$id ? $id:$res->id);
  416. $this->success('提交成功,请等待审核',['id'=> $id ? :$res->id]);
  417. }
  418. /**
  419. * @title 获取我的资料列表【个人】
  420. * @desc 获取我的资料列表【个人】
  421. * @author qc
  422. * @method GET
  423. * @url /api/Datum/getMyDatumList
  424. * @header name:Authorization require:1 desc:Token
  425. * @param name:title type:string default:-- desc:标题
  426. * @param name:page type:int default:0 desc:页数
  427. * @param name:page_num type:int default:20 desc:每页数
  428. * @return name:title type:string default:-- desc:标题
  429. * @return name:desc type:string default:-- desc:简介
  430. * @return name:datum_url type:string default:-- desc:资料地址
  431. * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
  432. * @return name:remark type:string default:-- desc:审核备注
  433. * @return name:label type:string default:-- desc:标签
  434. */
  435. public function getMyDatumList()
  436. {
  437. $sel_where = [];
  438. $sel_where[] = ['is_deleted','=',0];
  439. $sel_where[] = ['user_id','=',$this->user_id];
  440. $title = input('get.title');
  441. if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
  442. $list = UserDatum::where($sel_where)
  443. ->field('id,title,desc,datum_url,status,remark,label')
  444. ->order('id desc')
  445. ->limit($this->off_set,$this->page_num)
  446. ->select()->toArray();
  447. $this->success('ok',['list'=>$list]);
  448. }
  449. /**
  450. * @title 获取我的资料详情【个人】
  451. * @desc 获取我的资料列表【个人】
  452. * @author qc
  453. * @method GET
  454. * @url /api/Datum/getUserDatumDetail
  455. * @header name:Authorization require:1 desc:Token
  456. * @param name:id type:string default:-- desc:记录id
  457. * @return name:title type:string default:-- desc:标题
  458. * @return name:desc type:string default:-- desc:简介
  459. * @return name:datum_url type:string default:-- desc:资料地址
  460. * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
  461. * @return name:remark type:string default:-- desc:审核备注
  462. * @return name:label type:string default:-- desc:标签
  463. * @return name:label_name type:array default:-- desc:标签数组
  464. */
  465. public function getUserDatumDetail()
  466. {
  467. $detail =UserDatum::where('id',input('get.id'))->field('id,title,desc,datum_url,status,remark,label')->find();
  468. if(!$detail) $this->error('资料有误');
  469. $detail['label_name'] =$detail['label'] ? $detail['label_name'] = explode(',',trim($detail['label'],',')) : null;
  470. $this->success('ok',['detail'=>$detail->toArray()]);
  471. }
  472. /**
  473. * @title 用户删除资料记录【个人】
  474. * @desc 用户删除资料记录【个人】
  475. * @author qc
  476. * @method POST
  477. * @url /api/Datum/delUserDatum
  478. * @header name:Authorization require:1 desc:Token
  479. * @param name:id type:int default:-- desc:id
  480. */
  481. public function delUserDatum()
  482. {
  483. UserDatum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
  484. $this->success('删除成功');
  485. }
  486. /**
  487. * @title 获取下载资料列表
  488. * @desc 获取下载资料列表
  489. * @author qc
  490. * @method GET
  491. * @url /api/Datum/getDownloadDatum
  492. * @header name:Authorization require:1 desc:Token
  493. * @param name:title type:string default:-- desc:标题
  494. * @param name:page type:int default:0 desc:页数
  495. * @param name:page_num type:int default:20 desc:每页数
  496. * @return name:title type:string default:-- desc:标题
  497. * @return name:datum_id type:int default:-- desc:资料id
  498. * @return name:url_id type:int default:-- desc:item_id
  499. * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
  500. * @return name:url type:string default:-- desc:资料路径
  501. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  502. */
  503. public function getDownloadDatum()
  504. {
  505. $sel_where = [];
  506. $title = input('get.title');
  507. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  508. $sel_where[] = ['t.user_id','=',$this->user_id];
  509. $sel_where[] = ['t.type','=',1];
  510. $list = UserDownload::where($sel_where)
  511. ->alias('t')
  512. ->field('t.id,t.create_at,t.first_id datum_id,t.second_id url_id,i.title,i.is_vip,i.url')
  513. ->leftJoin('DatumUrl i','t.second_id = i.id')
  514. ->order('id desc')
  515. ->limit($this->off_set,$this->page_num)
  516. ->select()->toArray();
  517. foreach ($list as &$v) {
  518. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  519. }
  520. $this->success('ok',['list'=>$list]);
  521. }
  522. /**
  523. * @title 资料学习历史
  524. * @desc 资料学习历史
  525. * @author qc
  526. * @method GET
  527. * @url /api/Datum/getLearnHistory
  528. * @header name:Authorization require:1 desc:Token
  529. * @param name:title type:string default:-- desc:标题
  530. * @param name:page type:int default:0 desc:页数
  531. * @param name:page_num type:int default:20 desc:每页数
  532. * @return name:title type:string default:-- desc:标题
  533. * @return name:datum_id type:int default:-- desc:资料id
  534. * @return name:url_id type:int default:-- desc:item_id
  535. * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
  536. * @return name:url type:string default:-- desc:资料路径
  537. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  538. */
  539. public function getLearnHistory()
  540. {
  541. $sel_where = [];
  542. $sel_where[] = ['t.user_id','=',$this->user_id];
  543. $sel_where[] = ['t.type','=',2];
  544. $title = input('get.title');
  545. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  546. $list = UserTrack::where($sel_where)
  547. ->alias('t')
  548. ->field('t.id,t.update_int,t.first_id datum_id,t.second_id url_id,i.title,i.url,i.is_vip')
  549. ->leftJoin('DatumUrl i','t.second_id = i.id')
  550. ->order('update_int desc')
  551. ->limit($this->off_set,$this->page_num)
  552. ->select()->toArray();
  553. foreach ($list as &$v) {
  554. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  555. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  556. }
  557. $this->success('ok',['list'=>$list]);
  558. }
  559. /**
  560. * @title 资料收藏记录
  561. * @desc 图文收藏记录
  562. * @author qc
  563. * @method GET
  564. * @url /api/Datum/getDatumCollect
  565. * @header name:Authorization require:1 desc:Token
  566. * @param name:title type:string default:-- desc:标题
  567. * @param name:page type:int default:0 desc:页数
  568. * @param name:page_num type:int default:20 desc:每页数
  569. * @return name:title type:string default:-- desc:标题
  570. * @return name:datum_id type:string default:-- desc:资料id
  571. * @return name:url_id type:string default:-- desc:url_id
  572. * @return name:url type:string default:-- desc:资料路径
  573. * @return name:create_at type:string default:-- desc:时间
  574. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  575. */
  576. public function getDatumCollect()
  577. {
  578. $sel_where = [];
  579. $title = input('get.title');
  580. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  581. $sel_where[] = ['t.user_id','=',$this->user_id];
  582. $sel_where[] = ['t.coll_type','=',2];
  583. $list = UserCollect::where($sel_where)
  584. ->alias('t')
  585. ->field('t.id,t.create_at,t.coll_id datum_id,t.children_id url_id,i.title,i.url,i.is_vip')
  586. ->leftJoin('DatumUrl i','t.children_id = i.id')
  587. ->order('id desc')
  588. ->limit($this->off_set,$this->page_num)
  589. ->select()->toArray();
  590. array_walk($list,function (&$v){
  591. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  592. });
  593. $this->success('ok',['list'=>$list]);
  594. }
  595. /**
  596. * @title 以下接口为二期需求
  597. * @desc 以下接口为二期需求
  598. * @author qc
  599. * @url /api/Datum/secondPhase
  600. * @method
  601. * @return name:1 type:string default:-- desc:以下接口为二期需求
  602. */
  603. public function secondPhase(){}
  604. /**
  605. * @title 我的绑定【后台资料绑定该会员】
  606. * @desc 后台资料绑定该会员
  607. * @author qc
  608. * @method GET
  609. * @url /api/Datum/getBoundList
  610. * @header name:Authorization require:1 desc:Token
  611. * @param name:title type:string default:-- desc:标题
  612. * @param name:page type:int default:0 desc:页数
  613. * @param name:page_num type:int default:20 desc:每页数
  614. * @return name:id type:string default:-- desc:记录id【url_id】
  615. * @return name:title type:string default:-- desc:标题
  616. * @return name:datum_id type:string default:-- desc:资料id
  617. * @return name:create_at type:string default:-- desc:时间
  618. * @return name:url type:string default:-- desc:文件路径
  619. * @return name:is_vip type:int default:-- desc:是否是vip[0否1是]
  620. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  621. */
  622. public function getBoundList()
  623. {
  624. $sel_where = [];
  625. $title = input('get.title');
  626. $sel_where[] = ['user_id','=',$this->user_id];
  627. $sel_where[] = ['is_deleted','=',0];
  628. if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
  629. $list = DatumUrl::where($sel_where)
  630. ->alias('t')
  631. ->field('id,title,is_vip,url,datum_id,create_at,label')
  632. ->order('id desc')
  633. ->limit($this->off_set,$this->page_num)
  634. ->select()->toArray();
  635. foreach ($list as &$v) {
  636. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['id'],$this->request->controller());
  637. }
  638. $this->success('ok',['list'=>$list]);
  639. }
  640. /**
  641. * @title 我的追更列表
  642. * @desc 我的追更列表
  643. * @author qc
  644. * @method GET
  645. * @url /api/Datum/getFollowUpList
  646. * @header name:Authorization require:1 desc:Token
  647. * @param name:title type:string default:-- desc:标题
  648. * @param name:page type:int default:0 desc:页数
  649. * @param name:page_num type:int default:20 desc:每页数
  650. * @return name:create_at type:string default:-- desc:追更设置时间
  651. * @return name:recruit_id type:int default:-- desc:资料id
  652. * @return name:title type:string default:-- desc:标题
  653. */
  654. public function getFollowUpList()
  655. {
  656. $sel_where = [];
  657. $sel_where[] = ['p.user_id','=',$this->user_id];
  658. $sel_where[] = ['p.type','=',6];
  659. $sel_where[] = ['p.switch_id','=',1];
  660. $field = 'p.id,p.switch_id as article_id,p.create_at,a.title';
  661. $list = PlatformSwitch::field($field)
  662. ->alias('p')
  663. ->leftJoin('DatumUrl a','p.switch_id = a.id')
  664. ->where($sel_where)
  665. ->limit($this->off_set,$this->page_num)
  666. ->order('p.id desc')
  667. ->select()->toArray();
  668. $this->success('ok',['list'=>$list]);
  669. }
  670. }