Press.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\PressComment;
  4. use app\common\model\PlatformLike;
  5. use app\common\model\User;
  6. use app\common\model\UserCollect;
  7. use app\common\model\UserMessage;
  8. use app\common\model\UserReport;
  9. use app\common\model\UserSearch;
  10. use app\common\model\UserTrack;
  11. use library\tools\Data;
  12. /**
  13. * @title 新闻
  14. * @controller Press
  15. * @group base
  16. */
  17. class Press extends Base
  18. {
  19. // 需要登录的
  20. protected $need_login = ['pressCollect','pressTransmit','pressRead','PressTags','pressComment','pressCommend','delComment'];
  21. public function initialize()
  22. {
  23. parent::initialize();
  24. parent::setUid();
  25. }
  26. /**
  27. * @title 新闻接口说明
  28. * @desc 新闻接口说明
  29. * @author qc
  30. * @url /api/Press/classIntro
  31. * @method GET
  32. * @return name:1 type:string default:-- desc:该模块没有视频!!
  33. */
  34. public function classIntro(){}
  35. /**
  36. * @title 获取新闻列表
  37. * @desc 获取新闻列表
  38. * @author qc
  39. * @method GET
  40. * @url /api/Press/getPressList
  41. * @header name:Authorization require:1 desc:Token
  42. * @param name:title type:string default:-- desc:标题
  43. * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
  44. * @param name:page type:int default:0 desc:页数
  45. * @param name:page_num type:int default:20 desc:每页数
  46. * @return name:title type:string default:-- desc:标题
  47. * @return name:images type:string default:-- desc:图片多张|隔开
  48. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  49. * @return name:content type:string default:-- desc:详情
  50. * @return name:create_at type:string default:-- desc:时间
  51. * @return name:read_num type:int default:-- desc:阅读
  52. * @return name:is_collect type:int default:-- desc:是否收藏
  53. * @return name:transmit_num type:int default:-- desc:转发量
  54. * @return name:collect_num type:int default:-- desc:收藏量
  55. * @return name:praise_num type:int default:-- desc:点赞量
  56. * @return name:is_praise type:int default:-- desc:是否点赞
  57. * @return name:comment_num type:int default:-- desc:评论量
  58. */
  59. public function getPressList(){
  60. $title = input('get.title');
  61. $sort_type = input('get.sort_type',1);
  62. switch ($sort_type) {
  63. case 1:
  64. $order = ['sort'=>'desc','id'=>'desc'];
  65. break;
  66. case 2:
  67. $order = ['id'=>'asc','sort'=>'desc'];
  68. break;
  69. case 3:
  70. $order = ['id'=>'desc','sort'=>'desc'];
  71. break;
  72. }
  73. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,4);
  74. $list = \app\common\model\Press::where(['is_deleted'=>0])
  75. ->field('id,images,title,content,read_num,create_at,transmit_num')
  76. ->when($title,function ($query)use($title){
  77. if($title) $query->where('title|label','like','%'.$title.'%');
  78. })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
  79. foreach ($list as &$v) {
  80. $v['comment_num'] = PressComment::where(['first_id'=>$v['id'],'type'=>1,'is_deleted'=>0])->count();
  81. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['id']);
  82. $v['collect_num'] = UserCollect::getCollectNum(4,$v['id']);
  83. $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['id'],1);
  84. $v['praise_num'] = PlatformLike::getPraiseNum($v['id'],1);
  85. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  86. }
  87. $this->success('ok',['list'=>$list]);
  88. }
  89. /**
  90. * @title 获取新闻详情
  91. * @desc 获取新闻详情
  92. * @author qc
  93. * @method GET
  94. * @url /api/Press/getPressDetail
  95. * @header name:Authorization require:1 desc:Token
  96. * @param name:id type:int default:0 desc:新闻id
  97. * @return name:title type:string default:-- desc:标题
  98. * @return name:images type:string default:-- desc:图片多张|隔开
  99. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  100. * @return name:content type:string default:-- desc:详情
  101. * @return name:create_at type:string default:-- desc:时间
  102. * @return name:read_num type:int default:-- desc:阅读
  103. * @return name:is_collect type:int default:-- desc:是否收藏
  104. * @return name:transmit_num type:int default:-- desc:转发量
  105. * @return name:collect_num type:int default:-- desc:收藏量
  106. * @return name:praise_num type:int default:-- desc:点赞量
  107. * @return name:is_praise type:int default:-- desc:是否点赞
  108. * @return name:comment_num type:int default:-- desc:评论量
  109. * @return name:app_name type:string default:-- desc:发布方名称
  110. * @return name:app_logo type:string default:-- desc:发布方头像
  111. */
  112. public function getPressDetail()
  113. {
  114. $sel_where[] = ['id','=',input('get.id')];
  115. $detail = \app\common\model\Press::field('id,images,title,content,read_num,create_at,transmit_num,user_id')->where($sel_where)->find()->toArray();
  116. $detail['comment_num'] = PressComment::where(['first_id'=>$detail['id'],'type'=>1,'is_deleted'=>0])->count();
  117. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$detail['id']);
  118. $detail['collect_num'] = UserCollect::getCollectNum(4,$detail['id']);
  119. $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],1);
  120. $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],1);
  121. $app_name = sysconf('app_name');
  122. $app_logo = sysconf('app_logo');
  123. if(!$detail['user_id']){
  124. $detail['app_name'] = $app_name;
  125. $detail['app_logo'] = $app_logo;
  126. }else{
  127. $user_info = User::where('id',$detail['user_id'])->field('name,headimg')->find();
  128. $detail['app_name'] = $user_info ? $user_info->name : '';
  129. $detail['app_logo'] = $user_info ? $user_info->headimg : '';
  130. }
  131. UserTrack::crateTrack($this->user_id,4,input('get.id'),0);
  132. $this->success('ok',['detail'=>$detail]);
  133. }
  134. /**
  135. * @title 获取新闻评论列表
  136. * @desc 获取新闻评论列表
  137. * @author qc
  138. * @method GET
  139. * @url /api/Press/getPressCommentList
  140. * @header name:Authorization require:1 desc:Token
  141. * @param name:id type:int default:-- desc:新闻id
  142. * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
  143. * @param name:page type:int default:-- desc:页数
  144. * @param name:page_num type:int default:-- desc:每页数量
  145. * @return name:name type:string default:-- desc:会员名称
  146. * @return name:headimg type:string default:-- desc:会员头像
  147. * @return name:content type:string default:-- desc:内容
  148. * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
  149. * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
  150. * @return name:like_num type:int default:-- desc:点赞数量
  151. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  152. * @return name:total_num type:int default:-- desc:总评论数(仅一级)
  153. */
  154. public function getPressCommentList()
  155. {
  156. $where = [];
  157. $where[] = ['c.first_id','=',input('get.id')];
  158. $where[] = ['c.is_deleted','=',0];
  159. $where[] = ['c.type','=',1];
  160. $user_id = $this->user_id;
  161. $sort_type= input('sort_type',1);
  162. switch ($sort_type) {
  163. case 1:
  164. $order = ['c.id'=>'desc'];
  165. break;
  166. default:
  167. $order = ['c.like_times'=>'desc'];
  168. break;
  169. }
  170. $list =PressComment::where($where)
  171. ->alias('c')
  172. ->field('c.*,u.name,u.headimg')
  173. ->leftJoin('store_member u','u.id = c.user_id')
  174. ->order($order)
  175. ->limit($this->off_set,$this->page_num)
  176. ->select()->toArray();
  177. array_walk($list,function (&$val,$k)use($user_id){
  178. $children = PressComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
  179. ->alias('c')->field('c.*,u.name,u.headimg')
  180. ->leftJoin('store_member u','u.id = c.user_id')
  181. ->order('c.id asc')
  182. ->select()->toArray();
  183. $val['children'] = $children ? $children : null;
  184. $val['like_num'] = PlatformLike::getPraiseNum($val['id'],2);
  185. $val['is_like'] = PlatformLike::checkTags($user_id,$val['id'],2);
  186. $parent = PressComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
  187. ->alias('c')->field('c.*,u.name,u.headimg')
  188. ->leftJoin('store_member u','u.id = c.user_id')
  189. ->find();
  190. $val['parent'] = $parent ? $parent->toArray() : null;
  191. });
  192. $total_num = PressComment::where($where)->alias('c')->count();
  193. $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
  194. }
  195. /**
  196. * @title 删除评论
  197. * @desc 删除评论
  198. * @author qc
  199. * @method POST
  200. * @url /api/Press/delComment
  201. * @header name:Authorization require:1 desc:Token
  202. * @param name:id type:int default:1 desc:评论id
  203. */
  204. public function delComment(){
  205. PressComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
  206. $this->success('删除成功');
  207. }
  208. /**
  209. * @title 以下接口调用验证登录【需要header传Authorization】
  210. * @desc 以下接口调用验证登录
  211. * @author qc
  212. * @method
  213. * @url /api/Press/needLogin()
  214. */
  215. public function needLogin(){}
  216. /**
  217. * @title 收藏||取消收藏
  218. * @desc 用户收藏
  219. * @author qc
  220. * @method POST
  221. * @url /api/Press/pressCollect
  222. * @header name:Authorization require:1 desc:Token
  223. * @param name:id type:int require:1 default:-- desc:新闻id
  224. * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  225. */
  226. public function pressCollect(){
  227. $coll_status = UserCollect::plateCollect($this->user_id,4,input('post.id',0));
  228. $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]);
  229. }
  230. /**
  231. * @title 新闻转发(转发数量统计)
  232. * @desc 转发成功后调用
  233. * @author qc
  234. * @method POST
  235. * @url /api/Press/pressTransmit
  236. * @header name:Authorization require:1 desc:Token
  237. * @param name:id type:int default:-- desc:新闻id
  238. */
  239. public function pressTransmit()
  240. {
  241. $press_id = input('post.id',0);
  242. \app\common\model\Press::where('id',$press_id)->setInc('transmit_num');
  243. $this->success('ok');
  244. }
  245. /**
  246. * @title 新闻举报
  247. * @desc 新闻举报
  248. * @author qc
  249. * @url /api/Press/pressReport
  250. * @method POST
  251. * @header name:Authorization require:1 desc:Token
  252. * @param name:report_id type:int default:-- desc:举报内容的id
  253. * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
  254. */
  255. public function pressReport()
  256. {
  257. $report_id= input('post.report_id');
  258. $case_ids= input('post.case_ids');
  259. if(!$report_id) $this->error('请现在举报内容');
  260. if(!$case_ids) $this->error('请选择举报原因');
  261. UserReport::report($this->user_id,7,$report_id,$case_ids);
  262. $this->success('举报成功');
  263. }
  264. /**
  265. * @title 新闻阅读(阅读数量统计)
  266. * @desc 新闻阅读
  267. * @author qc
  268. * @method POST
  269. * @url /api/Press/pressRead
  270. * @header name:Authorization require:1 desc:Token
  271. * @param name:id type:int default:-- desc:新闻id
  272. */
  273. public function pressRead()
  274. {
  275. $press_id = input('post.id',0);
  276. \app\common\model\Press::where('id',$press_id)->setInc('read_num');
  277. $this->success('ok');
  278. }
  279. /**
  280. * @title 新闻点赞||取消点赞
  281. * @desc 点赞||取消点赞
  282. * @author qc
  283. * @method POST
  284. * @url /api/Press/PressTags
  285. * @header name:Authorization require:1 desc:Token
  286. * @param name:id type:int default:1 desc:新闻id
  287. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  288. */
  289. public function pressTags()
  290. {
  291. $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),1);
  292. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  293. }
  294. /**
  295. * @title 新闻评论点赞||取消点赞
  296. * @desc 新闻评论点赞
  297. * @author qc
  298. * @method POST
  299. * @url /api/Press/pressCommentTags
  300. * @header name:Authorization require:1 desc:Token
  301. * @param name:id type:int default:1 desc:评论id
  302. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  303. */
  304. public function pressCommentTags()
  305. {
  306. $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),2);
  307. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  308. }
  309. /**
  310. * @title 新闻评论
  311. * @desc 新闻评论
  312. * @author qc
  313. * @method POST
  314. * @url /api/Press/pressComment
  315. * @header name:Authorization require:1 desc:Token
  316. * @param name:id type:int default:1 desc:新闻id
  317. * @param name:content type:string default:-- desc:内容
  318. * @return name:name type:string default:-- desc:会员名称
  319. * @return name:headimg type:string default:-- desc:会员头像
  320. * @return name:content type:string default:-- desc:内容
  321. * @return name:create_at type:string default:-- desc:时间
  322. */
  323. public function pressComment()
  324. {
  325. $id = input('post.id');
  326. $content = input('post.content',0);
  327. if(!$content) $this->error('请输入评论内容');
  328. $res = PressComment::create(['user_id'=>$this->user_id,'content'=>$content,'first_id'=>$id,'type'=>1]);
  329. $detail =PressComment::where('p.id',$res->id)
  330. ->alias('p')
  331. ->field('p.id,p.content,p.create_at,u.name,u.headimg')
  332. ->leftJoin('store_member u','u.id = p.user_id')
  333. ->find()->toArray();
  334. $this->success('评论成功',['detail'=>$detail]);
  335. }
  336. /**
  337. * @title 新闻二级评论
  338. * @desc 新闻二级评论
  339. * @author qc
  340. * @method POST
  341. * @url /api/Press/pressSecondComment
  342. * @header name:Authorization require:1 desc:Token
  343. * @param name:id type:int default:1 desc:评论id
  344. * @param name:content type:string default:-- desc:内容
  345. * @return name:name type:string default:-- desc:会员名称
  346. * @return name:headimg type:string default:-- desc:会员头像
  347. * @return name:content type:string default:-- desc:内容
  348. */
  349. public function pressSecondComment()
  350. {
  351. $comment = PressComment::where('id',input('post.id'))->find()->toArray();
  352. $user_info = $this->userInfo('name');
  353. UserMessage:: sendUserMessage($comment['user_id'],'press',1,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
  354. unset($comment['id']);
  355. unset($comment['create_at']);
  356. $comment['pid'] = input('post.id');
  357. $comment['user_id'] = $this->user_id;
  358. $comment['content'] = input('post.content');
  359. $comment['lev']++;
  360. if(!$comment['source_id']) $comment['source_id'] = input('post.id');
  361. $res = PressComment::create($comment);
  362. $detail = PressComment::where('p.id',$res->id)
  363. ->alias('p')
  364. ->field('p.id,p.content,p.create_at,u.name,u.headimg')
  365. ->leftJoin('store_member u','u.id = p.user_id')
  366. ->find()->toArray();
  367. $this->success('评论成功',['detail'=>$detail]);
  368. }
  369. /**
  370. * @title 回复我的【回复我的--回复过我的评论】
  371. * @desc 回复我的
  372. * @author qc
  373. * @method GET
  374. * @url /api/Press/getReplyComment
  375. * @header name:Authorization require:1 desc:Token
  376. * @param name:title type:string default:-- desc:标题
  377. * @param name:page type:int default:0 desc:页数
  378. * @param name:page_num type:int default:20 desc:每页数
  379. * @return name:title type:string default:-- desc:标题
  380. * @return name:cover type:string default:-- desc:封面
  381. * @return name:iamges_arr type:array default:-- desc:图片【多张】
  382. * @return name:create_at type:string default:-- desc:时间
  383. * @return name:user_name type:string default:-- desc:用户名【其他会员】
  384. * @return name:headimg type:string default:-- desc:用户头【其他会员】
  385. * @return name:parent_comment type:array default:-- desc:你的评论内容【别人回复的那个评论】
  386. * @return name:parent_comment.content type:string default:-- desc:内容
  387. * @return name:parent_comment.name type:string default:-- desc:会员名称
  388. * @return name:parent_comment.title type:string default:-- desc:标题
  389. * @return name:parent_comment.press_id type:string default:-- desc:新闻id
  390. */
  391. public function getReplyComment()
  392. {
  393. $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  394. if(empty($all_comment)) $this->success('ok',['list'=>null]);
  395. $sel_where = [];
  396. $title = input('get.title');
  397. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  398. $sel_where[] = ['t.is_deleted','=',0];
  399. $sel_where[] = ['t.lev','>=',2];
  400. $sel_where[] = ['t.user_id','<>',$this->user_id];
  401. $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
  402. $list = PressComment::where($sel_where)
  403. ->alias('t')
  404. ->field('t.id,t.create_at,t.lev,t.content,t.pid,u.name user_name,u.headimg,i.cover,i.images')
  405. ->leftJoin('store_member u','t.user_id = u.id')
  406. ->leftJoin('Press i','t.first_id = i.id')
  407. ->order('t.id desc')
  408. ->limit($this->off_set,$this->page_num)
  409. ->select()->toArray();
  410. foreach ($list as &$v) {
  411. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  412. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  413. $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
  414. ->field('t.id,t.first_id press_id,t.content,i.title,i.cover,t.pid,u.name')
  415. ->alias('t')
  416. ->leftJoin('Press i','t.first_id = i.id')
  417. ->leftJoin('store_member u','t.user_id = u.id')
  418. ->find()->toArray();
  419. $v['parent_comment'] = $parent_comment;
  420. }
  421. $this->success('ok',['list'=>$list]);
  422. }
  423. /**
  424. * @title 评论我的
  425. * @desc 评论我的
  426. * @author qc
  427. * @method GET
  428. * @url /api/Press/commentMyPress
  429. * @header name:Authorization require:1 desc:Token
  430. * @param name:title type:string default:-- desc:标题
  431. * @param name:page type:int default:-- desc:页数
  432. * @param name:page_num type:int default:-- desc:每页数
  433. *
  434. * @return name:title type:string default:-- desc:标题
  435. * @return name:press_id type:string default:-- desc:新闻id
  436. * @return name:cover type:string default:-- desc:封面
  437. * @return name:create_at type:string default:-- desc:时间
  438. * @return name:user_name type:string default:-- desc:用户名
  439. * @return name:headimg type:string default:-- desc:用户头像
  440. */
  441. public function commentMyPress()
  442. {
  443. $sel_where = [];
  444. $title = input('get.title');
  445. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  446. $sel_where[] = ['t.is_deleted','=',0];
  447. $sel_where[] = ['i.user_id','=',$this->user_id];
  448. $list = PressComment::where($sel_where)
  449. ->alias('t')
  450. ->field('t.id,t.create_at,t.first_id press_id,t.content,i.title,i.cover,u.name user_name,u.headimg')
  451. ->leftJoin('Press i','t.first_id = i.id')
  452. ->leftJoin('store_member u','t.user_id = u.id')
  453. ->order('t.id desc')
  454. ->limit($this->off_set,$this->page_num)
  455. ->select()->toArray();
  456. $this->success('ok',['list'=>$list]);
  457. }
  458. /**
  459. * @title 我的评论
  460. * @desc 我的评论
  461. * @author qc
  462. * @method GET
  463. * @url /api/Press/getMyPressComment
  464. * @header name:Authorization require:1 desc:Token
  465. * @param name:title type:string default:-- desc:标题
  466. * @param name:page type:int default:-- desc:页数
  467. * @param name:page_num type:int default:-- desc:每页数
  468. *
  469. * @return name:title type:string default:-- desc:标题
  470. * @return name:press_id type:string default:-- desc:新闻id
  471. * @return name:cover type:string default:-- desc:封面
  472. * @return name:images_arr type:array default:-- desc:封面
  473. * @return name:create_at type:string default:-- desc:时间
  474. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  475. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  476. */
  477. public function getMyPressComment()
  478. {
  479. $where = [];
  480. $where[] = ['t.is_deleted','=',0];
  481. $where[] = ['t.type','=',1];
  482. $where[] = ['t.user_id','=',$this->user_id];
  483. $list = PressComment::where($where)
  484. ->alias('t')
  485. ->field('t.id,t.create_at,t.first_id press_id,i.images,t.content,i.title,i.cover,u.name user_name,u.headimg')
  486. ->leftJoin('Press i','t.first_id = i.id')
  487. ->leftJoin('store_member u','u.id = t.user_id')
  488. ->order('id desc')
  489. ->limit($this->off_set,$this->page_num)
  490. ->select()->toArray();
  491. foreach ($list as &$v) {
  492. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  493. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  494. }
  495. $this->success('ok',['list'=>$list]);
  496. }
  497. /**
  498. * @title 我的回复【我的回复--我回复过的评论】
  499. * @desc 我的评论
  500. * @author qc
  501. * @method GET
  502. * @url /api/Press/getReplyPress
  503. * @header name:Authorization require:1 desc:Token
  504. * @param name:title type:string default:-- desc:标题
  505. * @param name:page type:int default:0 desc:页数
  506. * @param name:page_num type:int default:20 desc:每页数
  507. * @return name:title type:string default:-- desc:标题
  508. * @return name:press_id type:int default:-- desc:新闻id
  509. * @return name:cover type:string default:-- desc:封面
  510. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  511. * @return name:create_at type:string default:-- desc:时间
  512. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  513. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  514. * @return name:parent_comment type:array default:-- desc:上级评论内容【你评论的那个评论】
  515. * @return name:parent_comment.content type:string default:-- desc:内容
  516. * @return name:parent_comment.name type:string default:-- desc:会员名称
  517. * @return name:parent_comment.title type:string default:-- desc:新闻标题
  518. * @return name:parent_comment.press_id type:string default:-- desc:新闻id
  519. */
  520. public function getReplyPress()
  521. {
  522. $user_info = $this->userInfo();
  523. $sel_where = [];
  524. $title = input('get.title');
  525. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  526. $sel_where[] = ['t.user_id','=',$this->user_id];
  527. $sel_where[] = ['t.is_deleted','=',0];
  528. $sel_where[] = ['t.lev','>=',2];
  529. $list = PressComment::where($sel_where)
  530. ->alias('t')
  531. ->field('t.id,t.create_at,t.first_id press_id,t.lev,t.content,t.pid,i.title,i.cover,images')
  532. ->leftJoin('Press i','t.first_id = i.id')
  533. ->order('t.id desc')
  534. ->limit($this->off_set,$this->page_num)
  535. ->select()->toArray();
  536. foreach ($list as &$v) {
  537. $v['user_name'] = $user_info['name'];
  538. $v['headimg'] = $user_info['headimg'];
  539. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  540. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  541. $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
  542. ->field('t.id,t.first_id press_id,t.content,i.title,i.cover,i.images,t.pid,u.name')
  543. ->alias('t')
  544. ->leftJoin('Press i','t.first_id = i.id')
  545. ->leftJoin('store_member u','t.user_id = u.id')
  546. ->find()->toArray();
  547. $parent_comment['images_arr'] = $parent_comment['images'] ? explode('|',$parent_comment['images']) : null;
  548. $v['parent_comment'] = $parent_comment;
  549. }
  550. $this->success('ok',['list'=>$list]);
  551. }
  552. /**
  553. * @title 我的收藏【新闻】
  554. * @desc 我的收藏
  555. * @author qc
  556. * @method GET
  557. * @url /api/Press/getPressCollect
  558. * @header name:Authorization require:1 desc:Token
  559. * @param name:title type:string default:-- desc:标题
  560. * @param name:page type:int default:-- desc:页数
  561. * @param name:page_num type:int default:-- desc:每页数
  562. *
  563. * @return name:title type:string default:-- desc:标题
  564. * @return name:press_id type:string default:-- desc:新闻id
  565. * @return name:cover type:string default:-- desc:封面
  566. * @return name:create_at type:string default:-- desc:时间
  567. */
  568. public function getPressCollect()
  569. {
  570. $sel_where = [];
  571. $title = input('get.title');
  572. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  573. $sel_where[] = ['t.user_id','=',$this->user_id];
  574. $sel_where[] = ['t.coll_type','=',4];
  575. $list = UserCollect::where($sel_where)
  576. ->alias('t')
  577. ->field('t.id,t.create_at,t.coll_id press_id,i.title,i.cover,images')
  578. ->leftJoin('Press i','t.coll_id = i.id')
  579. ->order('id desc')
  580. ->limit($this->off_set,$this->page_num)
  581. ->select()->toArray();
  582. foreach ($list as &$v) {
  583. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  584. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  585. }
  586. $this->success('ok',['list'=>$list]);
  587. }
  588. /**
  589. * @title 我的点赞列表【新闻】
  590. * @desc 我的点赞
  591. * @author qc
  592. * @method GET
  593. * @url /api/Press/getTagsPress
  594. * @header name:Authorization require:1 desc:Token
  595. * @param name:title type:string default:-- desc:标题
  596. * @param name:page type:int default:-- desc:页数
  597. * @param name:page_num type:int default:-- desc:每页数
  598. *
  599. * @return name:title type:string default:-- desc:标题
  600. * @return name:press_id type:string default:-- desc:新闻id
  601. * @return name:cover type:string default:-- desc:封面
  602. * @return name:create_at type:string default:-- desc:时间
  603. */
  604. public function getTagsPress()
  605. {
  606. $sel_where = [];
  607. $title = input('get.title');
  608. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  609. $sel_where[] = ['t.user_id','=',$this->user_id];
  610. $sel_where[] = ['t.type','=',1];
  611. $list = PlatformLike::where($sel_where)
  612. ->alias('t')
  613. ->field('t.id,t.create_at,t.like_id press_id,i.title,i.cover,images')
  614. ->leftJoin('Press i','t.like_id = i.id')
  615. ->order('id desc')
  616. ->limit($this->off_set,$this->page_num)
  617. ->select()->toArray();
  618. foreach ($list as &$v) {
  619. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  620. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  621. }
  622. $this->success('ok',['list'=>$list]);
  623. }
  624. /**
  625. * @title 我的浏览历史【新闻】
  626. * @desc 我的浏览历史
  627. * @author qc
  628. * @method GET
  629. * @url /api/Press/getPressTrack
  630. * @header name:Authorization require:1 desc:Token
  631. * @param name:title type:string default:-- desc:标题
  632. * @param name:page type:int default:-- desc:页数
  633. * @param name:page_num type:int default:-- desc:每页数
  634. *
  635. * @return name:title type:string default:-- desc:标题
  636. * @return name:press_id type:string default:-- desc:新闻id
  637. * @return name:cover type:string default:-- desc:封面
  638. * @return name:create_at type:string default:-- desc:时间
  639. */
  640. public function getPressTrack()
  641. {
  642. $sel_where = [];
  643. $sel_where[] = ['t.user_id','=',$this->user_id];
  644. $sel_where[] = ['t.type','=',4];
  645. $title = input('get.title');
  646. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  647. $list = UserTrack::where($sel_where)
  648. ->alias('t')
  649. ->field('t.id,t.update_int,t.first_id press_id,i.title,i.cover,i.images')
  650. ->leftJoin('Press i','t.first_id = i.id')
  651. ->order('update_int desc')
  652. ->limit($this->off_set,$this->page_num)
  653. ->select()->toArray();
  654. foreach ($list as &$v) {
  655. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  656. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  657. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  658. }
  659. $this->success('ok',['list'=>$list]);
  660. }
  661. }