Datum.php 25 KB

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