Press.php 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\ArticleItem;
  4. use app\common\model\DatumUrl;
  5. use app\common\model\PlatformSwitch;
  6. use app\common\model\PressComment;
  7. use app\common\model\PlatformLike;
  8. use app\common\model\TopSearch;
  9. use app\common\model\User;
  10. use app\common\model\UserCollect;
  11. use app\common\model\UserMessage;
  12. use app\common\model\UserReport;
  13. use app\common\model\UserSearch;
  14. use app\common\model\UserTrack;
  15. use app\common\model\VideoUrl;
  16. use app\common\service\CheckPower;
  17. use app\common\service\UserSynth;
  18. use library\tools\Data;
  19. use think\Db;
  20. /**
  21. * @title 新闻
  22. * @controller Press
  23. * @group base
  24. */
  25. class Press extends Base
  26. {
  27. // 需要登录的
  28. protected $need_login = [
  29. 'pressCollect',
  30. 'pressTransmit',
  31. 'pressReport',
  32. 'pressRead',
  33. 'PressTags',
  34. 'pressCommentTags',
  35. 'pressComment',
  36. 'pressSecondComment',
  37. 'getReplyComment',
  38. 'commentMyPress',
  39. 'getMyPressComment',
  40. 'getReplyPress',
  41. 'getPressCollect',
  42. 'getTagsPress',
  43. 'delComment',
  44. 'praiseMyPress',
  45. 'unreadChange',
  46. ];
  47. public function initialize()
  48. {
  49. parent::initialize();
  50. parent::setUid();
  51. }
  52. /**
  53. * @title 新闻接口说明
  54. * @desc 新闻接口说明
  55. * @author qc
  56. * @url /api/Press/classIntro
  57. * @method GET
  58. * @return name:1 type:string default:-- desc:该模块没有视频!!
  59. */
  60. public function classIntro(){}
  61. /**
  62. * @title 新闻推荐
  63. * @desc 新闻推荐
  64. * @author qc
  65. * @method GET
  66. * @url /api/Press/getRecommendList
  67. * @header name:Authorization require:1 desc:Token
  68. * @param name:page type:int default:0 desc:页数
  69. * @param name:page_num type:int default:20 desc:每页数
  70. * @param name:rand_user type:string default:-- desc:随机id(非登录状态必传,page=1时生成(a123),其他页数(a123),一直查询到没有数据)
  71. * @return name:images type:string default:-- desc:图片多张|隔开
  72. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  73. * @return name:content type:string default:-- desc:详情
  74. * @return name:create_at type:string default:-- desc:时间
  75. * @return name:read_num type:int default:-- desc:阅读
  76. * @return name:is_collect type:int default:-- desc:是否收藏
  77. * @return name:transmit_num type:int default:-- desc:转发量
  78. * @return name:collect_num type:int default:-- desc:收藏量
  79. * @return name:praise_num type:int default:-- desc:点赞量
  80. * @return name:is_praise type:int default:-- desc:是否点赞
  81. * @return name:comment_num type:int default:-- desc:评论量
  82. * @return name:app_name type:string default:-- desc:发布方名称
  83. * @return name:app_logo type:string default:-- desc:发布方头像
  84. * @return name:release_time type:string default:-- desc:上架时间
  85. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  86. */
  87. public function getRecommendList()
  88. {
  89. $user_id = $this->user_id ? $this->user_id : input('rand_user');
  90. if(!$user_id) $this->error('参数错误');
  91. $list = UserSynth::getRecommendList($user_id,'press',$this->page,$this->page_num);
  92. if($list['code'] != 200) $this->error($list['msg']);
  93. $this->success('ok',$list);
  94. $search_log = UserSearch::getSearchTitle($this->user_id,4);
  95. $search_arr = [];
  96. $where_str = 'b.id > 0';
  97. foreach ($search_log as $t){
  98. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  99. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  100. }
  101. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  102. $field = 'a.id,a.title,a.label,a.images,a.read_num,a.transmit_num,a.user_id,a.create_at,IFNULL(is_recommend,0) is_recommend ';
  103. $table = 'dd_press';
  104. $order_by_two = 'a.read_num';
  105. $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 WHERE a.is_deleted = 0 AND a.status = 1 ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
  106. $list = Db::query($sql);
  107. $list = dispose_recommend($list);
  108. array_walk($list,function (&$v,$k){
  109. $v['read_num'] = numTransform($v['read_num']);
  110. $v['transmit_num'] = numTransform($v['transmit_num']);
  111. $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
  112. $v['images_arr'] = $v['images']? explode('|',trim($v['images'],'|')):null;
  113. $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
  114. $v['app_name'] = $info_auth['app_name'];
  115. $v['app_logo'] = $info_auth['app_logo'];
  116. $v['comment_num'] = PressComment::getCommentNum($v['id']);
  117. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['id']);
  118. $v['collect_num'] = UserCollect::getCollectNum(4,$v['id']);
  119. $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['id'],1);
  120. $v['praise_num'] = PlatformLike::getPraiseNum($v['id'],1);
  121. });
  122. $sql2 = "SELECT count(a.id) num 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 WHERE a.is_deleted = 0 AND a.status = 1 ORDER BY is_recommend DESC , $order_by_two desc ";
  123. $total = Db::query($sql2);
  124. $this->success('ok',['list'=>$list,'total_count'=>$total[0]['num'],'page_num'=>$this->page_num]);
  125. }
  126. /**
  127. * @title 获取新闻列表
  128. * @desc 获取新闻列表
  129. * @author qc
  130. * @method GET
  131. * @url /api/Press/getPressList
  132. * @header name:Authorization require:1 desc:Token
  133. * @param name:title type:string default:-- desc:标题
  134. * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
  135. * @param name:page type:int default:0 desc:页数
  136. * @param name:page_num type:int default:20 desc:每页数
  137. * @return name:images type:string default:-- desc:图片多张|隔开
  138. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  139. * @return name:content type:string default:-- desc:详情
  140. * @return name:create_at type:string default:-- desc:时间
  141. * @return name:read_num type:int default:-- desc:阅读
  142. * @return name:is_collect type:int default:-- desc:是否收藏
  143. * @return name:transmit_num type:int default:-- desc:转发量
  144. * @return name:collect_num type:int default:-- desc:收藏量
  145. * @return name:praise_num type:int default:-- desc:点赞量
  146. * @return name:is_praise type:int default:-- desc:是否点赞
  147. * @return name:comment_num type:int default:-- desc:评论量
  148. * @return name:app_name type:string default:-- desc:发布方名称
  149. * @return name:release_time type:string default:-- desc:上架时间
  150. */
  151. public function getPressList(){
  152. $title = input('get.title');
  153. $sort_type = input('get.sort_type',1);
  154. switch ($sort_type) {
  155. case 1:
  156. $order = ['sort'=>'desc','read_num'=>'desc','id'=>'asc'];
  157. break;
  158. case 2:
  159. $order = ['id'=>'asc','sort'=>'desc'];
  160. break;
  161. case 3:
  162. $order = ['id'=>'desc','sort'=>'desc'];
  163. break;
  164. }
  165. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,4);
  166. $list = \app\common\model\Press::where(['is_deleted'=>0])
  167. ->field('id,images,title,content,read_num,create_at,transmit_num,user_id,release_time')
  168. ->when($title,function ($query)use($title){
  169. if($title) $query->where('title|label','like','%'.$title.'%');
  170. })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
  171. foreach ($list as &$v) {
  172. $v['comment_num'] = PressComment::getCommentNum($v['id']);
  173. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['id']);
  174. $v['collect_num'] = UserCollect::getCollectNum(4,$v['id']);
  175. $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['id'],1);
  176. $v['praise_num'] = PlatformLike::getPraiseNum($v['id'],1);
  177. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  178. $info_auth = \app\common\model\Press::getInfoAuth($this->user_id,APPNAME,APPLOGO);
  179. $v['app_name'] = $info_auth['app_name'];
  180. $v['app_logo'] = $info_auth['app_logo'];
  181. }
  182. $total_num = \app\common\model\Press::where(['is_deleted'=>0])
  183. ->field('id,images,title,content,read_num,create_at,transmit_num')
  184. ->when($title,function ($query)use($title){
  185. if($title) $query->where('title|label','like','%'.$title.'%');
  186. })->count();
  187. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  188. }
  189. /**
  190. * @title 获取新闻详情
  191. * @desc 获取新闻详情
  192. * @author qc
  193. * @method GET
  194. * @url /api/Press/getPressDetail
  195. * @header name:Authorization require:1 desc:Token
  196. * @param name:id type:int default:0 desc:新闻id
  197. * @return name:title type:string default:-- desc:标题
  198. * @return name:images type:string default:-- desc:图片多张|隔开
  199. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  200. * @return name:content type:string default:-- desc:详情
  201. * @return name:create_at type:string default:-- desc:时间
  202. * @return name:read_num type:int default:-- desc:阅读
  203. * @return name:is_collect type:int default:-- desc:是否收藏
  204. * @return name:transmit_num type:int default:-- desc:转发量
  205. * @return name:collect_num type:int default:-- desc:收藏量
  206. * @return name:praise_num type:int default:-- desc:点赞量
  207. * @return name:is_praise type:int default:-- desc:是否点赞
  208. * @return name:comment_num type:int default:-- desc:评论量
  209. * @return name:app_name type:string default:-- desc:发布方名称
  210. * @return name:app_logo type:string default:-- desc:发布方头像
  211. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  212. * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
  213. * @return name:goods_id type:int default:-- desc:供应商商品id
  214. * @return name:goods_jump type:int default:-- desc:供应商商品id否能跳转【0不能跳转,1能跳转】
  215. * @return name:release_time type:string default:-- desc:上架时间
  216. *
  217. * @return name:video_id type:int default:-- desc:视频系列id
  218. * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
  219. * @return name:video_jump type:int default:-- desc:关联视频是否能跳转【0不能跳转,1能跳转,验证是否vip】
  220. *
  221. * @return name:article_id type:int default:-- desc:图文系列id
  222. * @return name:article_item type:int default:-- desc:关联图文详情id【item_list.id】
  223. * @return name:article_jump type:int default:-- desc:关联图文是否能跳转【0不能跳转,1能跳转,验证是否vip】
  224. * @return name:datum_id type:int default:-- desc:资料id--ppt【系列id】
  225. * @return name:datum_item type:int default:-- desc:资料id--ppt【系列下的其中一个】
  226. * @return name:datum_jump type:int default:-- desc:关联资料是否能跳转【0不能跳转,1能跳转,验证是否vip】
  227. */
  228. public function getPressDetail()
  229. {
  230. $sel_where[] = ['id','=',input('get.id')];
  231. $detail = \app\common\model\Press::field('id,images,supplier_id,goods_id,title,release_time,content,read_num,create_at,transmit_num,user_id,is_deleted,status,video_id,video_item,article_id,article_item,datum_id,datum_item')->where($sel_where)->find()->toArray();
  232. if($detail['is_deleted'] == 1 || $detail['status'] == 0) $this->error('该新闻已下架');
  233. $detail['comment_num'] = PressComment::where(['first_id'=>$detail['id'],'type'=>1,'is_deleted'=>0])->count();
  234. $detail['comment_num'] = numTransform($detail['comment_num']);
  235. $detail['transmit_num'] = numTransform($detail['transmit_num']);
  236. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$detail['id']);
  237. $detail['collect_num'] = UserCollect::getCollectNum(4,$detail['id']);
  238. $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],1);
  239. $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],1);
  240. $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$detail['id'],10);
  241. $detail['article_jump'] = ArticleItem::checkVip($detail['article_item'],$this->user_id);
  242. $detail['video_jump'] = VideoUrl::checkVip($detail['video_item'],$this->user_id);
  243. $detail['datum_jump'] = DatumUrl::checkVip($detail['datum_item'],$this->user_id);
  244. $detail['goods_jump'] = CheckPower::checkModulesPower($detail['goods_id'], 0, 'supplier');
  245. $app_name = sysconf('app_name');
  246. $app_logo = sysconf('app_logo');
  247. if(!$detail['user_id']){
  248. $detail['app_name'] = $app_name;
  249. $detail['app_logo'] = $app_logo;
  250. }else{
  251. $user_info = User::where('id',$detail['user_id'])->field('name,headimg')->find();
  252. $detail['app_name'] = $user_info ? $user_info->name : '';
  253. $detail['app_logo'] = $user_info ? $user_info->headimg : '';
  254. }
  255. // \app\common\model\Press::where('id',$detail['id'])->setInc('read_num');
  256. UserTrack::crateTrack($this->user_id,4,input('get.id'),0);
  257. $this->success('ok',['detail'=>$detail]);
  258. }
  259. /**
  260. * @title 获取新闻评论列表
  261. * @desc 获取新闻评论列表
  262. * @author qc
  263. * @method GET
  264. * @url /api/Press/getPressCommentList
  265. * @header name:Authorization require:1 desc:Token
  266. * @param name:id type:int default:-- desc:新闻id
  267. * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
  268. * @param name:page type:int default:-- desc:页数
  269. * @param name:page_num type:int default:-- desc:每页数量
  270. * @return name:name type:string default:-- desc:会员名称
  271. * @return name:headimg type:string default:-- desc:会员头像
  272. * @return name:content type:string default:-- desc:内容
  273. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  274. * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
  275. * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
  276. * @return name:like_num type:int default:-- desc:点赞数量
  277. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  278. * @return name:total_num type:int default:-- desc:总评论数(仅一级)
  279. */
  280. public function getPressCommentList()
  281. {
  282. $where = [];
  283. $where[] = ['c.first_id','=',input('get.id')];
  284. $where[] = ['c.is_deleted','=',0];
  285. $where[] = ['c.type','=',1];
  286. $user_id = $this->user_id;
  287. $sort_type= input('sort_type',1);
  288. switch ($sort_type) {
  289. case 1:
  290. $order = ['c.is_top'=>'desc','c.id'=>'desc'];
  291. break;
  292. default:
  293. $order = ['c.is_top'=>'desc','c.like_times'=>'desc'];
  294. break;
  295. }
  296. $list =PressComment::where($where)
  297. ->alias('c')
  298. ->field('c.*,u.name,u.headimg')
  299. ->leftJoin('store_member u','u.id = c.user_id')
  300. ->order($order)
  301. ->limit($this->off_set,$this->page_num)
  302. ->select()->toArray();
  303. array_walk($list,function (&$val,$k)use($user_id){
  304. $children = PressComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
  305. ->alias('c')->field('c.*,u.name,u.headimg')
  306. ->leftJoin('store_member u','u.id = c.user_id')
  307. ->order('c.is_top desc,c.id asc')
  308. ->select()->toArray();
  309. $val['children'] = $children ? $children : null;
  310. $val['like_num'] = PlatformLike::getPraiseNum($val['id'],2);
  311. $val['is_like'] = PlatformLike::checkTags($user_id,$val['id'],2);
  312. $parent = PressComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
  313. ->alias('c')->field('c.*,u.name,u.headimg')
  314. ->leftJoin('store_member u','u.id = c.user_id')
  315. ->find();
  316. $val['parent'] = $parent ? $parent->toArray() : null;
  317. $val['parent_comment'] = $val['parent'] ;
  318. });
  319. $total_num = PressComment::where($where) ->leftJoin('store_member u','u.id = c.user_id')->alias('c')->count();
  320. $this->success('ok',['list'=>$list,'total_num'=>numTransform($total_num),'total_count'=>$total_num,'page_num'=>$this->page_num]);
  321. }
  322. /**
  323. * @title 以下接口调用验证登录【需要header传Authorization】
  324. * @desc 以下接口调用验证登录
  325. * @author qc
  326. * @method
  327. * @url /api/Press/needLogin()
  328. */
  329. public function needLogin(){}
  330. /**
  331. * @title 删除评论
  332. * @desc 删除评论
  333. * @author qc
  334. * @method POST
  335. * @url /api/Press/delComment
  336. * @header name:Authorization require:1 desc:Token
  337. * @param name:id type:int default:1 desc:评论id
  338. */
  339. public function delComment(){
  340. PressComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
  341. $this->success('删除成功');
  342. }
  343. /**
  344. * @title 收藏||取消收藏
  345. * @desc 用户收藏
  346. * @author qc
  347. * @method POST
  348. * @url /api/Press/pressCollect
  349. * @header name:Authorization require:1 desc:Token
  350. * @param name:id type:int require:1 default:-- desc:新闻id
  351. * @return name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  352. */
  353. public function pressCollect(){
  354. $coll_status = UserCollect::plateCollect($this->user_id,4,input('post.id',0));
  355. $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]);
  356. }
  357. /**
  358. * @title 新闻转发(转发数量统计)
  359. * @desc 转发成功后调用
  360. * @author qc
  361. * @method POST
  362. * @url /api/Press/pressTransmit
  363. * @header name:Authorization require:1 desc:Token
  364. * @param name:id type:int default:-- desc:新闻id
  365. */
  366. public function pressTransmit()
  367. {
  368. $press_id = input('post.id',0);
  369. \app\common\model\Press::where('id',$press_id)->setInc('transmit_num');
  370. $this->success('ok');
  371. }
  372. /**
  373. * @title 新闻举报
  374. * @desc 新闻举报
  375. * @author qc
  376. * @url /api/Press/pressReport
  377. * @method POST
  378. * @header name:Authorization require:1 desc:Token
  379. * @param name:report_id type:int default:-- desc:举报内容的id
  380. * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
  381. */
  382. public function pressReport()
  383. {
  384. $report_id= input('post.report_id');
  385. $case_ids= input('post.case_ids');
  386. if(!$report_id) $this->error('请现在举报内容');
  387. if(!$case_ids) $this->error('请选择举报原因');
  388. UserReport::report($this->user_id,7,$report_id,$case_ids);
  389. $this->success('举报成功');
  390. }
  391. /**
  392. * @title 新闻阅读(阅读数量统计)
  393. * @desc 新闻阅读
  394. * @author qc
  395. * @method POST
  396. * @url /api/Press/pressRead
  397. * @header name:Authorization require:1 desc:Token
  398. * @param name:id type:int default:-- desc:新闻id
  399. */
  400. public function pressRead()
  401. {
  402. $press_id = input('post.id',0);
  403. \app\common\model\Press::where('id',$press_id)->setInc('read_num');
  404. if($this->user_id){
  405. TopSearch::seIncHotNum($press_id,$this->request->controller());
  406. }
  407. $this->success('ok');
  408. }
  409. /**
  410. * @title 新闻点赞||取消点赞
  411. * @desc 点赞||取消点赞
  412. * @author qc
  413. * @method POST
  414. * @url /api/Press/PressTags
  415. * @header name:Authorization require:1 desc:Token
  416. * @param name:id type:int default:1 desc:新闻id
  417. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  418. */
  419. public function pressTags()
  420. {
  421. $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),1);
  422. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  423. }
  424. /**
  425. * @title 新闻评论点赞||取消点赞
  426. * @desc 新闻评论点赞
  427. * @author qc
  428. * @method POST
  429. * @url /api/Press/pressCommentTags
  430. * @header name:Authorization require:1 desc:Token
  431. * @param name:id type:int default:1 desc:评论id
  432. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  433. */
  434. public function pressCommentTags()
  435. {
  436. $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),2);
  437. if($ret_val == 1){
  438. PressComment::where('id',input('post.id'))->setInc('like_times');
  439. }else{
  440. PressComment::where('id',input('post.id'))->setDec('like_times');
  441. }
  442. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  443. }
  444. /**
  445. * @title 新闻评论
  446. * @desc 新闻评论
  447. * @author qc
  448. * @method POST
  449. * @url /api/Press/pressComment
  450. * @header name:Authorization require:1 desc:Token
  451. * @param name:id type:int default:1 desc:新闻id
  452. * @param name:content type:string default:-- desc:内容
  453. * @return name:name type:string default:-- desc:会员名称
  454. * @return name:headimg type:string default:-- desc:会员头像
  455. * @return name:content type:string default:-- desc:内容
  456. * @return name:create_at type:string default:-- desc:时间
  457. */
  458. public function pressComment()
  459. {
  460. $id = input('post.id');
  461. $content = input('post.content',0);
  462. if(!$content) $this->error('请输入评论内容');
  463. $comment_info = \app\common\model\Press::where('id',$id)->find()->toArray();
  464. if(!$comment_info['comment_switch']) $this->error('评论功能已关闭');
  465. $res = PressComment::create(['user_id'=>$this->user_id,'content'=>$content,'first_id'=>$id,'type'=>1]);
  466. $detail =PressComment::where('p.id',$res->id)
  467. ->alias('p')
  468. ->field('p.id,p.content,p.create_at,u.name,u.headimg')
  469. ->leftJoin('store_member u','u.id = p.user_id')
  470. ->find()->toArray();
  471. if($comment_info['user_id'] && $this->user_id != $comment_info['user_id'])UserMessage:: sendUserMessage($comment_info['user_id'],'press',2,0,$this->user_id,$detail['id'],$content);
  472. $this->success('评论成功',['detail'=>$detail]);
  473. }
  474. /**
  475. * @title 新闻二级评论
  476. * @desc 新闻二级评论
  477. * @author qc
  478. * @method POST
  479. * @url /api/Press/pressSecondComment
  480. * @header name:Authorization require:1 desc:Token
  481. * @param name:id type:int default:1 desc:评论id
  482. * @param name:content type:string default:-- desc:内容
  483. * @return name:name type:string default:-- desc:会员名称
  484. * @return name:headimg type:string default:-- desc:会员头像
  485. * @return name:content type:string default:-- desc:内容
  486. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  487. */
  488. public function pressSecondComment()
  489. {
  490. $comment = PressComment::where('id',input('post.id'))->find()->toArray();
  491. $user_info = $this->userInfo('name');
  492. if($comment['user_id'] != $this->user_id)UserMessage::sendUserMessage($comment['user_id'],'press',1,0,$this->user_id,$comment['id'],input('post.content'));
  493. unset($comment['id']);
  494. unset($comment['create_at']);
  495. $comment['pid'] = input('post.id');
  496. $comment['user_id'] = $this->user_id;
  497. $comment['content'] = input('post.content');
  498. $comment['lev']++;
  499. if(!$comment['source_id']) $comment['source_id'] = input('post.id');
  500. $res = PressComment::create($comment);
  501. $detail = PressComment::where('p.id',$res->id)
  502. ->alias('p')
  503. ->field('p.id,p.content,p.is_top,p.create_at,u.name,u.headimg')
  504. ->leftJoin('store_member u','u.id = p.user_id')
  505. ->find()->toArray();
  506. $this->success('评论成功',['detail'=>$detail]);
  507. }
  508. /**
  509. * @title 获取角标数量
  510. * @desc 获取角标数量
  511. * @author qc
  512. * @method GET
  513. * @url /api/Press/getMarkNum
  514. * @header name:Authorization require:1 desc:Token
  515. * @return name:reply_num type:int default:-- desc:未读量--回复我的
  516. * @return name:comment_num type:int default:-- desc:未读量--评论我的
  517. * @return name:total_num type:int default:-- desc:总数【reply_num+comment_num】
  518. * @return name:praise_press type:int default:-- desc:点赞我的--新闻
  519. * @return name:praise_comment type:int default:-- desc:点赞我的--评论
  520. * @return name:praise_num type:int default:-- desc:点赞我的--新闻+评论
  521. */
  522. public function getMarkNum()
  523. {
  524. // 评论我的
  525. $comment_num = PressComment::where([['t.is_deleted','=',0],['t.pid','=',0],['i.user_id','=',$this->user_id],['is_read','=',0],['t.user_id','<>',$this->user_id]])
  526. ->leftJoin('Press i','t.first_id = i.id')
  527. ->alias('t')->count();
  528. // 回复我的
  529. $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  530. $reply_num = PressComment::where([['t.is_deleted','=',0],['t.lev','>=',2],['is_read','=',0],['t.pid','in',implode(',',$all_comment)],['t.user_id','<>',$this->user_id]])->alias('t')->count();
  531. $total_num = $comment_num + $reply_num ;
  532. $praise_press = PlatformLike::where([['p.type', '=', 1],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p') ->leftJoin('Press f', 'f.id = p.like_id')->count();
  533. $praise_comment = PlatformLike::where([['p.type', '=', 2],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p')->leftJoin('PressComment c', 'c.id = p.like_id')->count();
  534. $praise_num = $praise_press + $praise_comment;
  535. $this->success('ok',compact(['reply_num','comment_num','total_num','praise_num','praise_press','praise_comment']));
  536. }
  537. /**
  538. * @title 消息已读&&未读变更
  539. * @desc 支持批量选择
  540. * @author qc
  541. * @method POST
  542. * @url /api/Press/unreadChange
  543. * eadChange
  544. * @header name:Authorization require:1 desc:Token
  545. * @param name:id type:string default:-- desc:记录id(多个逗号隔开,不传修改全部])
  546. * @param name:type type:string default:1 desc:消息类型【1评论我的,2回复我的,3点赞我的--新闻,4点赞我的-评论】
  547. * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
  548. */
  549. public function unreadChange()
  550. {
  551. $type = input('post.type',1);
  552. $id = input('post.id');
  553. $is_read = input('post.is_read',0);
  554. $where = [];
  555. switch ($type)
  556. {
  557. case 1:
  558. PressComment::where([['i.user_id','=',$this->user_id]])
  559. ->when($id ,function ($query)use ($id){
  560. if($id) return $query->where('t.id','in',$id);
  561. })->leftJoin('Press i','t.first_id = i.id')
  562. ->alias('t') ->update(['source_read'=>$is_read,'t.is_read'=>$is_read]);
  563. break;
  564. case 2:
  565. $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  566. PressComment::where([['t.pid','in',implode(',',$all_comment)]])
  567. ->when($id ,function ($query)use ($id){
  568. if($id) return $query->where('t.id','in',$id);
  569. })->alias('t')->update(['is_read'=>$is_read]);
  570. break;
  571. case 3:
  572. $ids = PlatformLike::where([['p.type', '=', 1],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p') ->leftJoin('Press f', 'f.id = p.like_id')->column('p.id');
  573. PlatformLike::where('id','in' ,$ids)->update(['is_read'=>1]);
  574. break;
  575. case 4:
  576. $ids2 = PlatformLike::where([['p.type', '=', 2],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('PressComment c', 'c.id = p.like_id')->column('p.id');
  577. PlatformLike::where('id','in' ,$ids2)->update(['is_read'=>1]);
  578. break;
  579. }
  580. // PressComment::where('id',input('post.id'))->update(['is_read'=>1]);
  581. $this->success('消息变更成功');
  582. }
  583. /**
  584. * @title 回复我的【回复我的--回复过我的评论】
  585. * @desc 回复我的
  586. * @author qc
  587. * @method GET
  588. * @url /api/Press/getReplyComment
  589. * @header name:Authorization require:1 desc:Token
  590. * @param name:title type:string default:-- desc:标题
  591. * @param name:page type:int default:0 desc:页数
  592. * @param name:page_num type:int default:20 desc:每页数
  593. * @return name:title type:string default:-- desc:标题
  594. * @return name:cover type:string default:-- desc:封面
  595. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  596. * @return name:images_arr type:array default:-- desc:图片【多张】
  597. * @return name:create_at type:string default:-- desc:时间
  598. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  599. * @return name:self_name type:string default:-- desc:用户名称【自己的】
  600. * @return name:user_name type:string default:-- desc:用户名【其他会员】
  601. * @return name:headimg type:string default:-- desc:用户头【其他会员】
  602. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  603. * @return name:parent_comment type:array default:-- desc:你的评论内容【别人回复的那个评论】
  604. * @return name:parent_comment.content type:string default:-- desc:内容
  605. * @return name:parent_comment.name type:string default:-- desc:会员名称
  606. * @return name:parent_comment.title type:string default:-- desc:标题
  607. * @return name:parent_comment.press_id type:string default:-- desc:新闻id
  608. * @return name:parent_comment.app_name type:string default:-- desc:发布方名称
  609. * @return name:parent_comment.app_logo type:string default:-- desc:发布方头像
  610. * @return name:parent_comment.read_num type:string default:-- desc:阅读量
  611. */
  612. public function getReplyComment()
  613. {
  614. $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  615. if(empty($all_comment)) $this->success('ok',['list'=>null,'total_count'=>0,'page_num'=>$this->page_num]);
  616. $sel_where = [];
  617. $title = input('get.title');
  618. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  619. $sel_where[] = ['t.is_deleted','=',0];
  620. $sel_where[] = ['t.lev','>=',2];
  621. $sel_where[] = ['t.to_deleted','=',0];
  622. $sel_where[] = ['t.user_id','<>',$this->user_id];
  623. $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
  624. $list = PressComment::where($sel_where)
  625. ->alias('t')
  626. ->field('t.id,t.is_top,t.is_read,t.create_at,t.first_id press_id,t.lev,t.content,t.pid,u.name user_name,u.headimg,i.cover,i.images,i.read_num')
  627. ->leftJoin('store_member u','t.user_id = u.id')
  628. ->leftJoin('Press i','t.first_id = i.id')
  629. ->order('t.is_top desc,t.id desc')
  630. ->limit($this->off_set,$this->page_num)
  631. ->select()->toArray();
  632. foreach ($list as &$v) {
  633. $v['self_name'] = $this->user_info['name'];
  634. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  635. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  636. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  637. $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
  638. ->field('t.id,t.first_id press_id,t.is_top,t.content,i.title,i.cover,t.pid,u.name,i.user_id,i.read_num')
  639. ->alias('t')
  640. ->leftJoin('Press i','t.first_id = i.id')
  641. ->leftJoin('store_member u','t.user_id = u.id')
  642. ->find()->toArray();
  643. $parent_comment['images_arr'] =$v['images_arr'];
  644. $parent_comment['read_num'] = numTransform($v['read_num']);
  645. $info_auth = \app\common\model\Press::getInfoAuth($parent_comment['user_id'],APPNAME,APPLOGO);
  646. $parent_comment['app_name'] = $info_auth['app_name'];
  647. $parent_comment['app_logo'] = $info_auth['app_logo'];
  648. $v['parent_comment'] = $parent_comment;
  649. }
  650. $total_num = PressComment::where($sel_where)->alias('t')->leftJoin('store_member u','t.user_id = u.id')->leftJoin('Press i','t.first_id = i.id')->count();
  651. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  652. }
  653. /**
  654. * @title 评论我的
  655. * @desc 评论我的
  656. * @author qc
  657. * @method GET
  658. * @url /api/Press/commentMyPress
  659. * @header name:Authorization require:1 desc:Token
  660. * @param name:title type:string default:-- desc:标题
  661. * @param name:page type:int default:-- desc:页数
  662. * @param name:page_num type:int default:-- desc:每页数
  663. *
  664. * @return name:title type:string default:-- desc:标题
  665. * @return name:press_id type:string default:-- desc:新闻id
  666. * @return name:cover type:string default:-- desc:封面
  667. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  668. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  669. * @return name:create_at type:string default:-- desc:时间
  670. * @return name:user_name type:string default:-- desc:用户名
  671. * @return name:headimg type:string default:-- desc:用户头像
  672. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  673. * @return name:app_name type:string default:-- desc:发布方名称
  674. * @return name:app_logo type:string default:-- desc:发布方头像
  675. * @return name:content type:string default:-- desc:评论内容
  676. * @return name:read_num type:string default:-- desc:阅读量
  677. */
  678. public function commentMyPress()
  679. {
  680. $sel_where = [];
  681. $title = input('get.title');
  682. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  683. $sel_where[] = ['t.is_deleted','=',0];
  684. $sel_where[] = ['i.user_id','=',$this->user_id];
  685. $sel_where[] = ['t.pid','=',0];
  686. $sel_where[] = ['t.to_deleted','=',0];
  687. $sel_where[] = ['t.user_id','<>',$this->user_id];
  688. $list = PressComment::where($sel_where)
  689. ->alias('t')
  690. ->field('t.id,t.is_read,t.is_top,t.create_at,t.first_id press_id,t.content,i.images,i.title,i.cover,u.name user_name,u.headimg,i.read_num')
  691. ->leftJoin('Press i','t.first_id = i.id')
  692. ->leftJoin('store_member u','t.user_id = u.id')
  693. ->order('t.is_top desc,t.id desc')
  694. ->limit($this->off_set,$this->page_num)
  695. ->select()->toArray();
  696. $user_info = $this->userInfo();
  697. array_walk($list,function (&$v)use ($user_info){
  698. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  699. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  700. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  701. $v['app_name'] = $user_info['name'];
  702. $v['app_logo'] = $user_info['headimg'];
  703. $v['read_num'] = numTransform($v['read_num']);
  704. });
  705. $total_num = PressComment::where($sel_where)->alias('t') ->leftJoin('Press i','t.first_id = i.id')
  706. ->leftJoin('store_member u','t.user_id = u.id')->count();
  707. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  708. }
  709. /**
  710. * @title 我的评论
  711. * @desc 我的评论
  712. * @author qc
  713. * @method GET
  714. * @url /api/Press/getMyPressComment
  715. * @header name:Authorization require:1 desc:Token
  716. * @param name:title type:string default:-- desc:标题
  717. * @param name:page type:int default:-- desc:页数
  718. * @param name:page_num type:int default:-- desc:每页数
  719. *
  720. * @return name:title type:string default:-- desc:标题
  721. * @return name:press_id type:string default:-- desc:新闻id
  722. * @return name:cover type:string default:-- desc:封面
  723. * @return name:images_arr type:array default:-- desc:封面
  724. * @return name:create_at type:string default:-- desc:时间
  725. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  726. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  727. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  728. */
  729. public function getMyPressComment()
  730. {
  731. $where = [];
  732. $where[] = ['t.is_deleted','=',0];
  733. $where[] = ['t.type','=',1];
  734. $where[] = ['t.user_id','=',$this->user_id];
  735. $where[] = ['t.pid','=',0];
  736. $title = input('get.title');
  737. if($title) $where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  738. $list = PressComment::where($where)
  739. ->alias('t')
  740. ->field('t.id,t.is_top,t.create_at,t.first_id press_id,i.images,t.content,i.title,i.cover,u.name user_name,u.headimg,i.read_num,i.user_id iuid')
  741. ->leftJoin('Press i','t.first_id = i.id')
  742. ->leftJoin('store_member u','u.id = t.user_id')
  743. ->order('t.is_top desc,id desc')
  744. ->limit($this->off_set,$this->page_num)
  745. ->select()->toArray();
  746. foreach ($list as &$v) {
  747. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  748. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  749. $v['read_num'] = numTransform($v['read_num']);
  750. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  751. // $parent_comment = PressComment::where($where)
  752. // ->alias('t')
  753. // ->field('t.id,t.is_top,t.create_at,t.first_id press_id,i.images,t.content,i.title,i.cover,u.name user_name,u.headimg,i.read_num,i.user_id')
  754. // ->leftJoin('Press i','t.first_id = i.id')
  755. // ->leftJoin('store_member u','u.id = t.user_id')
  756. // ->order('t.is_top desc,id desc')
  757. // ->limit($this->off_set,$this->page_num)
  758. // ->find()->toArray();
  759. $info_auth = \app\common\model\Press::getInfoAuth($v['iuid'],APPNAME,APPLOGO);
  760. $v['app_name'] = $info_auth['app_name'];
  761. $v['app_logo'] = $info_auth['app_logo'];
  762. }
  763. $total_num = PressComment::where($where)
  764. ->alias('t') ->leftJoin('Press i','t.first_id = i.id')
  765. ->leftJoin('store_member u','u.id = t.user_id')->count();
  766. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  767. }
  768. /**
  769. * @title 我的回复【我的回复--我回复过的评论】
  770. * @desc 我的回复
  771. * @author qc
  772. * @method GET
  773. * @url /api/Press/getReplyPress
  774. * @header name:Authorization require:1 desc:Token
  775. * @param name:title type:string default:-- desc:标题
  776. * @param name:page type:int default:0 desc:页数
  777. * @param name:page_num type:int default:20 desc:每页数
  778. * @return name:title type:string default:-- desc:标题
  779. * @return name:press_id type:int default:-- desc:新闻id
  780. * @return name:cover type:string default:-- desc:封面
  781. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  782. * @return name:create_at type:string default:-- desc:时间
  783. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  784. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  785. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  786. * @return name:parent_comment type:array default:-- desc:上级评论内容【你评论的那个评论】
  787. * @return name:parent_comment.content type:string default:-- desc:内容
  788. * @return name:parent_comment.name type:string default:-- desc:会员名称
  789. * @return name:parent_comment.title type:string default:-- desc:新闻标题
  790. * @return name:parent_comment.press_id type:string default:-- desc:新闻id
  791. * @return name:parent_comment.app_name type:string default:-- desc:发布方名称
  792. * @return name:parent_comment.app_logo type:string default:-- desc:发布方头像
  793. * @return name:parent_comment.read_num type:string default:-- desc:阅读量
  794. */
  795. public function getReplyPress()
  796. {
  797. $user_info = $this->userInfo();
  798. $sel_where = [];
  799. $title = input('get.title');
  800. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  801. $sel_where[] = ['t.user_id','=',$this->user_id];
  802. $sel_where[] = ['t.is_deleted','=',0];
  803. $sel_where[] = ['t.source_deleted','=',0];
  804. $sel_where[] = ['t.lev','>=',2];
  805. $list = PressComment::where($sel_where)
  806. ->alias('t')
  807. ->field('t.id,t.is_top,t.create_at,t.first_id press_id,t.lev,t.content,t.pid,i.title,i.cover,images,read_num')
  808. ->leftJoin('Press i','t.first_id = i.id')
  809. ->order('t.is_top,t.id desc')
  810. ->limit($this->off_set,$this->page_num)
  811. ->select()->toArray();
  812. foreach ($list as &$v) {
  813. $v['user_name'] = $user_info['name'];
  814. $v['headimg'] = $user_info['headimg'];
  815. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  816. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  817. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  818. $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
  819. ->field('t.id,t.is_top,t.first_id press_id,t.content,i.title,i.cover,i.images,t.pid,u.name,i.read_num,i.user_id')
  820. ->alias('t')
  821. ->leftJoin('Press i','t.first_id = i.id')
  822. ->leftJoin('store_member u','t.user_id = u.id')
  823. ->find()->toArray();
  824. $parent_comment['read_num'] = numTransform($v['read_num']);
  825. $parent_comment['images_arr'] = $parent_comment['images'] ? explode('|',$parent_comment['images']) : null;
  826. $info_auth = \app\common\model\Press::getInfoAuth($parent_comment['user_id'],APPNAME,APPLOGO);
  827. $parent_comment['app_name'] = $info_auth['app_name'];
  828. $parent_comment['app_logo'] = $info_auth['app_logo'];
  829. $v['parent_comment'] = $parent_comment;
  830. }
  831. $total_num = PressComment::where($sel_where)->alias('t')->leftJoin('Press i','t.first_id = i.id')->count();
  832. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  833. }
  834. /**
  835. * @title 我的收藏【新闻】
  836. * @desc 我的收藏
  837. * @author qc
  838. * @method GET
  839. * @url /api/Press/getPressCollect
  840. * @header name:Authorization require:1 desc:Token
  841. * @param name:title type:string default:-- desc:标题
  842. * @param name:page type:int default:-- desc:页数
  843. * @param name:page_num type:int default:-- desc:每页数
  844. *
  845. * @return name:title type:string default:-- desc:标题
  846. * @return name:press_id type:string default:-- desc:新闻id
  847. * @return name:cover type:string default:-- desc:封面
  848. * @return name:create_at type:string default:-- desc:时间
  849. * @return name:read_num type:int default:-- desc:阅读量
  850. * @return name:transmit_num type:int default:-- desc:转发量
  851. * @return name:collect_num type:int default:-- desc:收藏量
  852. * @return name:praise_num type:int default:-- desc:点赞量
  853. * @return name:is_praise type:int default:-- desc:是否点赞
  854. * @return name:comment_num type:int default:-- desc:评论量
  855. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  856. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  857. */
  858. public function getPressCollect()
  859. {
  860. $sel_where = [];
  861. $title = input('get.title');
  862. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  863. $sel_where[] = ['t.user_id','=',$this->user_id];
  864. $sel_where[] = ['t.coll_type','=',4];
  865. $list = UserCollect::where($sel_where)
  866. ->alias('t')
  867. ->field('t.id,t.create_at,t.coll_id press_id,i.title,images,i.user_id,i.transmit_num,i.read_num')
  868. ->leftJoin('Press i','t.coll_id = i.id')
  869. ->order('id desc')
  870. ->limit($this->off_set,$this->page_num)
  871. ->select()->toArray();
  872. foreach ($list as &$v) {
  873. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  874. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  875. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  876. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  877. $v['comment_num'] = PressComment::getCommentNum($v['press_id']);
  878. $v['collect_num'] = UserCollect::getCollectNum(4,$v['press_id']);
  879. $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['press_id'],1);
  880. $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);
  881. $v['transmit_num'] =numTransform($v['transmit_num']);
  882. $v['read_num'] =numTransform($v['read_num']);
  883. $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);
  884. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['press_id'],10);
  885. $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
  886. $v['app_name'] = $info_auth['app_name'];
  887. $v['app_logo'] = $info_auth['app_logo'];
  888. }
  889. $total_num = UserCollect::where($sel_where)->alias('t')
  890. ->leftJoin('Press i','t.coll_id = i.id')->count();
  891. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  892. }
  893. /**
  894. * @title 我的点赞--新闻
  895. * @desc 我的点赞
  896. * @author qc
  897. * @method GET
  898. * @url /api/Press/getTagsPress
  899. * @header name:Authorization require:1 desc:Token
  900. * @param name:title type:string default:-- desc:标题
  901. * @param name:page type:int default:-- desc:页数
  902. * @param name:page_num type:int default:-- desc:每页数
  903. *
  904. * @return name:title type:string default:-- desc:标题
  905. * @return name:press_id type:string default:-- desc:新闻id
  906. * @return name:cover type:string default:-- desc:封面
  907. * @return name:create_at type:string default:-- desc:时间
  908. *
  909. * @return name:is_collect type:int default:-- desc:是否收藏
  910. * @return name:transmit_num type:int default:-- desc:转发量
  911. * @return name:collect_num type:int default:-- desc:收藏量
  912. * @return name:praise_num type:int default:-- desc:点赞量
  913. * @return name:comment_num type:int default:-- desc:评论量
  914. * @return name:app_name type:string default:-- desc:发布方名称
  915. * @return name:app_logo type:string default:-- desc:发布方头像
  916. * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
  917. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  918. */
  919. public function getTagsPress()
  920. {
  921. $sel_where = [];
  922. $title = input('get.title');
  923. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  924. $sel_where[] = ['t.user_id','=',$this->user_id];
  925. $sel_where[] = ['t.type','=',1];
  926. $list = PlatformLike::where($sel_where)
  927. ->alias('t')
  928. ->field('t.id,t.create_at,t.like_id press_id,i.title,i.cover,images,transmit_num,i.read_num,comment_switch,i.user_id')
  929. ->leftJoin('Press i','t.like_id = i.id')
  930. ->order('id desc')
  931. ->limit($this->off_set,$this->page_num)
  932. ->select()->toArray();
  933. foreach ($list as &$v) {
  934. $v['transmit_num'] = numTransform($v['transmit_num']);
  935. $v['read_num'] = numTransform($v['read_num']);
  936. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  937. $v['comment_num'] = PressComment::getCommentNum($v['press_id']);
  938. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['press_id']);
  939. $v['collect_num'] = UserCollect::getCollectNum(4,$v['press_id']);
  940. $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['press_id'],1);
  941. $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);
  942. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  943. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  944. $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
  945. $v['app_name'] = $info_auth['app_name'];
  946. $v['app_logo'] = $info_auth['app_logo'];
  947. }
  948. $total_num = PlatformLike::where($sel_where)->alias('t')->leftJoin('Press i','t.like_id = i.id')->count();
  949. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  950. }
  951. /**
  952. * @title 我的浏览历史【新闻】
  953. * @desc 我的浏览历史
  954. * @author qc
  955. * @method GET
  956. * @url /api/Press/getPressTrack
  957. * @header name:Authorization require:1 desc:Token
  958. * @param name:title type:string default:-- desc:标题
  959. * @param name:page type:int default:-- desc:页数
  960. * @param name:page_num type:int default:-- desc:每页数
  961. *
  962. * @return name:title type:string default:-- desc:标题
  963. * @return name:press_id type:string default:-- desc:新闻id
  964. * @return name:images_arr type:array default:-- desc:封面
  965. * @return name:cover type:string default:-- desc:封面
  966. * @return name:create_at type:string default:-- desc:时间
  967. * @return name:app_name type:string default:-- desc:发布方名称
  968. * @return name:app_logo type:string default:-- desc:发布方头像
  969. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  970. */
  971. public function getPressTrack()
  972. {
  973. $sel_where = [];
  974. $sel_where[] = ['t.user_id','=',$this->user_id];
  975. $sel_where[] = ['t.type','=',4];
  976. $title = input('get.title');
  977. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  978. $list = UserTrack::where($sel_where)
  979. ->alias('t')
  980. ->field('t.id,t.update_int,t.first_id press_id,i.title,i.cover,i.images,i.read_num,i.user_id')
  981. ->leftJoin('Press i','t.first_id = i.id')
  982. ->order('update_int desc')
  983. ->limit($this->off_set,$this->page_num)
  984. ->select()->toArray();
  985. foreach ($list as &$v) {
  986. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  987. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  988. $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
  989. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  990. $v['read_num'] = numTransform($v['read_num']);
  991. $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
  992. $v['app_name'] = $info_auth['app_name'];
  993. $v['app_logo'] = $info_auth['app_logo'];
  994. /* $v['comment_num'] = PressComment::where(['first_id'=>$v['press_id'],'type'=>1,'is_deleted'=>0])->count();
  995. $v['collect_num'] = UserCollect::getCollectNum(4,$v['press_id']);
  996. $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);*/
  997. }
  998. $total_num = UserTrack::where($sel_where)->alias('t')->leftJoin('Press i','t.first_id = i.id')->count();
  999. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1000. }
  1001. /**
  1002. * @title 点赞我的--新闻
  1003. * @desc 点赞我的--新闻
  1004. * @author qc
  1005. * @method GET
  1006. * @url /api/Press/praiseMyPress
  1007. * @header name:Authorization require:1 desc:Token
  1008. * @param name:page type:int default:-- desc:页数
  1009. * @param name:page_num type:int default:-- desc:每页数
  1010. * @return name:id type:int default:-- desc:记录id
  1011. * @return name:title type:string default:-- desc:标题
  1012. * @return name:create_at type:string default:-- desc:时间
  1013. * @return name:read_num type:int default:-- desc:阅读量
  1014. * @return name:images type:string default:-- desc:图片多张|隔开
  1015. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  1016. * @return name:user_name type:string default:-- desc:会员名称
  1017. * @return name:headimg type:string default:-- desc:会员头像
  1018. * @return name:content type:string default:-- desc:详情
  1019. * @return name:like_id type:string default:-- desc:新闻id
  1020. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1021. * @return name:app_name type:string default:-- desc:发布方名称
  1022. * @return name:app_logo type:string default:-- desc:发布方头像
  1023. */
  1024. public function praiseMyPress()
  1025. {
  1026. $user_info = $this->userInfo('name,headimg');
  1027. $sel_where = [];
  1028. $sel_where[] = ['p.type', '=', 1];
  1029. $sel_where[] = ['f.user_id', '=', $this->user_id];
  1030. $sel_where[] = ['p.user_id', '<>', $this->user_id];
  1031. $sel_where[] = ['p.to_deleted', '=', 0];
  1032. $list = PlatformLike::where($sel_where)
  1033. ->field('p.*,f.title,u.name user_name,u.headimg,f.images,f.read_num,f.content')
  1034. ->alias('p')
  1035. ->leftJoin('Press f', 'f.id = p.like_id')
  1036. ->leftJoin('StoreMember u', 'u.id = p.user_id')
  1037. ->limit($this->off_set,$this->page_num)
  1038. ->select()->toArray();
  1039. array_walk($list, function (&$v) use ($user_info){
  1040. $v['is_normal'] = CheckPower::checkModulesPower($v['like_id'], 0, $this->request->controller());
  1041. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  1042. $v['app_name'] = $user_info['name'];
  1043. $v['app_logo'] = $user_info['headimg'];
  1044. $v['read_num'] = numTransform($v['read_num']);
  1045. });
  1046. $total_num = PlatformLike::where($sel_where)->alias('p')->leftJoin('Press f', 'f.id = p.like_id')->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
  1047. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1048. }
  1049. /**
  1050. * @title 点赞我的--评论
  1051. * @desc 点赞我的
  1052. * @author qc
  1053. * @method GET
  1054. * @url /api/Press/praiseCommentList
  1055. * @header name:Authorization require:1 desc:Token
  1056. * @param name:page type:int default:-- desc:页数
  1057. * @param name:page_num type:int default:-- desc:每页数
  1058. * @return name:id type:int default:-- desc:记录id
  1059. * @return name:press_id type:int default:-- desc:新闻id
  1060. * @return name:title type:string default:-- desc:新闻标题
  1061. * @return name:create_at type:string default:-- desc:时间
  1062. * @return name:user_name type:string default:-- desc:会员名称【点赞人的】
  1063. * @return name:headimg type:string default:-- desc:会员头像【点赞人的】
  1064. * @return name:self_name type:string default:-- desc:用户名称【自己的】
  1065. * @return name:content type:string default:-- desc:评论内容
  1066. * @return name:press_content type:string default:-- desc:新闻内容
  1067. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1068. * @return name:app_name type:string default:-- desc:发布方名称
  1069. * @return name:app_logo type:string default:-- desc:发布方头像
  1070. * @return name:read_num type:int default:-- desc:阅读量
  1071. * @return name:images type:string default:-- desc:图片多张|隔开
  1072. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  1073. * @return name:comment_normal type:int default:-- desc:评论是否正常
  1074. */
  1075. public function praiseCommentList()
  1076. {
  1077. $user_info = $this->userInfo('name,headimg');
  1078. $list = PlatformLike::where([['l.type','=',2],['c.user_id','=',$this->user_id],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
  1079. ->alias('l')
  1080. ->field('l.id,l.user_id,m.name user_name,m.headimg,c.is_deleted,c.to_deleted,c.source_deleted,l.create_at,v.images,c.first_id press_id,v.user_id buid,v.title,v.read_num,c.content,v.content press_content,v.comment_switch')
  1081. ->leftJoin('StoreMember m','m.id = l.user_id')
  1082. ->leftJoin('PressComment c','c.id = l.like_id')
  1083. ->leftJoin('Press v','v.id = c.first_id')
  1084. ->order('l.id desc')
  1085. ->limit($this->off_set,$this->page_num)
  1086. ->select()->toArray();
  1087. array_walk($list,function (&$v,$k)use ($user_info){
  1088. $info_auth = \app\common\model\Press::getInfoAuth($v['buid'],APPNAME,APPLOGO);
  1089. $v['app_name'] = $info_auth['app_name'];
  1090. $v['app_logo'] = $info_auth['app_logo'];
  1091. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  1092. $v['read_num'] = numTransform($v['read_num']);
  1093. $v['self_name'] = $user_info['name'];
  1094. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  1095. $v['comment_normal'] = $v['to_deleted'] || $v['is_deleted'] || $v['source_deleted'] ? 0 : 1;
  1096. });
  1097. $total_num = PlatformLike::where([['l.type','=',2],['c.user_id','=',$this->user_id],['l.to_deleted','=',0]])->alias('l') ->leftJoin('StoreMember m','m.id = l.user_id')
  1098. ->leftJoin('PressComment c','c.id = l.like_id')
  1099. ->leftJoin('Press v','v.id = c.first_id')->count();
  1100. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1101. }
  1102. /**
  1103. * @title 批量删除||批量取消
  1104. * @desc 删除||取消
  1105. * @author qc
  1106. * @method POST
  1107. * @url /api/Press/batchesDel
  1108. * @header name:Authorization require:1 desc:Token
  1109. * @param name:id type:string default:1 desc:记录id【多个用逗号隔开=>'1,2'】
  1110. * @param name:type type:string default:1 desc:消息类型【1点赞我的,2我的评论,3回复我的,4评论我的,5我的点赞,6我的收藏,7我的回复】
  1111. */
  1112. public function batchesDel()
  1113. {
  1114. $type = input('post.type',1);
  1115. $id = input('post.id');
  1116. if(!$id) $this->error('请选择要删除的记录');
  1117. $del_where = [];
  1118. $del_where[] = ['id','in',$id];
  1119. if(in_array($type,[1])) PlatformLike::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
  1120. if(in_array($type,[2])) PressComment::where($del_where)->where(['user_id'=>$this->user_id])->update(['is_deleted'=>1]);
  1121. if(in_array($type,[3,4])) PressComment::where($del_where)->update(['to_deleted'=>1,'is_read'=>1,'source_read'=>1]);
  1122. if(in_array($type,[5])) PlatformLike::where($del_where)->where('user_id',$this->user_id)->delete();
  1123. if(in_array($type,[6])) UserCollect::where($del_where)->where('user_id',$this->user_id)->where('coll_type',4)->delete();
  1124. if(in_array($type,[7])) PressComment::where($del_where)->where('user_id',$this->user_id)->update(['source_deleted'=>1]);
  1125. $this->success('删除成功');
  1126. }
  1127. /**
  1128. * @title 我的发布
  1129. * @desc 我的发布
  1130. * @author qc
  1131. * @method GET
  1132. * @url /api/Press/getMyPressList
  1133. * @header name:Authorization require:1 desc:Token
  1134. * @param name:page type:int default:-- desc:页数
  1135. * @param name:page_num type:int default:-- desc:每页数
  1136. * @param name:title type:string default:-- desc:关键词
  1137. * @return name:id type:int default:-- desc:新闻id
  1138. * @return name:title type:string default:-- desc:标题
  1139. * @return name:create_at type:string default:-- desc:时间
  1140. * @return name:label_name type:array default:-- desc:标签
  1141. * @return name:images_arr type:array default:-- desc:图片
  1142. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1143. */
  1144. public function getMyPressList()
  1145. {
  1146. $where = [];
  1147. $where[] = ['user_id','=',$this->user_id];
  1148. $where[] = ['is_deleted','=',0];
  1149. $where[] = ['status','=',1];
  1150. $title = input('get.title');
  1151. if ($title) $where[] = ['name', 'like', '%' . $title . '%'];
  1152. $list = \app\common\model\Press::field('id,title,label,create_at,images')->where($where)->limit($this->off_set,$this->page_num)
  1153. ->select()->toArray();
  1154. array_walk($list,function (&$v){
  1155. $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
  1156. $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
  1157. $v['is_normal'] = CheckPower::checkModulesPower($v['id'],0,$this->request->controller());
  1158. });
  1159. $total_num =\app\common\model\Press::where($where)->count();
  1160. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1161. }
  1162. /**
  1163. * @title 我的点赞--评论
  1164. * @desc 评论点赞列表
  1165. * @author qc
  1166. * @method GETapi/Press/getTagsComment
  1167. * @url /
  1168. * @header name:Authorization require:1 desc:Token
  1169. * @param name:page type:int default:0 desc:页数
  1170. * @param name:page_num type:int default:20 desc:每页数
  1171. * @return name:create_at type:string default:-- desc:时间
  1172. * @return name:self_name type:string default:-- desc:会员名称【自己的】
  1173. * @return name:self_headimg type:string default:-- desc:会员头像【自己的】
  1174. * @return name:comment_user type:string default:-- desc:会员名称【评论人】
  1175. * @return name:images type:string default:-- desc:图片多张|隔开
  1176. * @return name:images_arr type:array default:-- desc:图片多张[数组]
  1177. * @return name:content type:string default:-- desc:评论内容
  1178. * @return name:cover type:string default:-- desc:封面
  1179. * @return name:title type:string default:-- desc:标题
  1180. * @return name:read_num type:string default:-- desc:浏览量
  1181. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1182. * @return name:app_name type:string default:-- desc:发布方名称
  1183. * @return name:app_logo type:string default:-- desc:发布方头像
  1184. */
  1185. public function getTagsComment()
  1186. {
  1187. $list = PlatformLike::field('l.id,c.content,g.read_num,g.images,g.cover,u.name comment_user,g.user_id,l.create_at,g.title,g.id press_id,c.user_id cuid,l.like_id')
  1188. ->alias('l')
  1189. ->where(['l.user_id'=>$this->user_id,'l.type'=>2])
  1190. ->where('c.user_id','<>',$this->user_id)
  1191. ->leftJoin('PressComment c','l.like_id = c.id')
  1192. ->leftJoin('Press g','g.id = c.first_id')
  1193. ->leftJoin('store_member u','u.id = c.user_id')
  1194. ->order('l.id desc')
  1195. ->limit($this->off_set,$this->page_num)
  1196. ->select()->toArray();
  1197. $user_info = $this->userInfo();
  1198. foreach ($list as &$v) {
  1199. $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
  1200. $auth_info = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
  1201. $user_infos = User::where('id',$v['cuid'])->field('name,headimg')->find();
  1202. $v['app_name'] = $auth_info['app_name'];
  1203. $v['app_logo'] = $auth_info['app_logo'];
  1204. $v['read_num'] = numTransform($v['read_num']);
  1205. $v['self_name'] = $user_info['name'];
  1206. $v['self_headimg'] = $user_info['headimg'];
  1207. $v['images_arr'] = $v['images']? explode('|',trim($v['images'],'|')):null;
  1208. //返回一下headimg和user_name,类似视频图文资料
  1209. //我的点赞评论
  1210. $v['user_name'] = $user_infos['name'];
  1211. $v['headimg'] = $user_infos['headimg'];
  1212. }
  1213. $total_num =PlatformLike::alias('l')
  1214. ->where(['l.user_id'=>$this->user_id,'l.type'=>2])
  1215. ->where('c.user_id','<>',$this->user_id)
  1216. ->leftJoin('PressComment c','l.like_id = c.id')
  1217. ->leftJoin('Press g','g.id = c.first_id')
  1218. ->leftJoin('store_member u','u.id = c.user_id')->count();
  1219. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1220. }
  1221. }