Forum.php 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\ForumReply;
  4. use app\common\model\ForumReplyComment;
  5. use app\common\model\PlatformLike;
  6. use app\common\model\PlatformSwitch;
  7. use app\common\model\TopSearch;
  8. use app\common\model\User;
  9. use app\common\model\UserCollect;
  10. use app\common\model\UserForum;
  11. use app\common\model\UserLevelRank;
  12. use app\common\model\UserMessage;
  13. use app\common\model\UserReport;
  14. use app\common\model\UserSearch;
  15. use app\common\model\UserTrack;
  16. use app\common\service\CheckPower;
  17. use app\common\service\UserSynth;
  18. use think\Db;
  19. use library\tools\Data;
  20. use vod\Request\V20170321\GetMediaAuditResultTimelineRequest;
  21. /**
  22. * @title 问答
  23. * @controller Forum
  24. * @group base
  25. */
  26. class Forum extends Base
  27. {
  28. // 需要登录的
  29. protected $need_login = [
  30. 'forumCollect',
  31. 'forumSwitch',
  32. 'replyForum',
  33. 'commentReply',
  34. 'forumSecondComment',
  35. 'forumTags',
  36. 'userReferForum',
  37. 'getUserForumList',
  38. 'myReplyList',
  39. 'myDiscuss',
  40. 'unreadChange',
  41. 'replyToMyForum',
  42. 'commentOnMyForum',
  43. 'commentOnMyReply',
  44. 'forumReport',
  45. 'forumTransmit',
  46. 'getReplyComment',
  47. 'getReplyForum',
  48. 'praiseForumList',
  49. 'praiseReplyList',
  50. 'praiseCommentList',
  51. 'batchesDel',
  52. 'getForumTrack',
  53. 'getTagsForum',
  54. 'getTagsReply',
  55. 'getTagsComment',
  56. 'getCollectList',
  57. ];
  58. public function initialize()
  59. {
  60. parent::initialize();
  61. if (!$this->user_id) parent::setUid();
  62. }
  63. /**
  64. * @title 获取问题列表
  65. * @desc 获取问题列表
  66. * @author qc
  67. * @method GET
  68. * @url /api/Forum/getForumList
  69. * @header name:Authorization require:1 desc:Token
  70. * @param name:page type:int default:0 desc:页数
  71. * @param name:page_num type:int default:20 desc:每页数
  72. * @param name:rand_user type:string default:-- desc:随机id(非登录状态必传,page=1时生成(a123),其他页数(a123),一直查询到没有数据)
  73. * @return name:title type:string default:-- desc:标题
  74. * @return name:content type:string default:0 desc:内容
  75. * @return name:level type:int default:-- desc:vip等级id
  76. * @return name:label type:string default:-- desc:标签
  77. * @return name:label_name type:array default:-- desc:标签
  78. * @return name:name type:string default:-- desc:发布用户
  79. * @return name:headimg type:string default:-- desc:发布用户头像
  80. * @return name:browse_num type:int default:-- desc:浏览量
  81. * @return name:reply_num type:int default:-- desc:回答量
  82. * @return name:open_vip type:int default:-- desc:是否需要开通vip[0不需要1需要]
  83. * @return name:release_time type:string default:-- desc:上架时间
  84. *
  85. */
  86. public function getForumList()
  87. {
  88. $user_id = $this->user_id ? $this->user_id : input('rand_user');
  89. if(!$user_id) $this->error('参数错误');
  90. $list = UserSynth::getRecommendList($user_id,'forum',$this->page,$this->page_num);
  91. if($list['code'] != 200) $this->error($list['msg']);
  92. $this->success('ok',$list);
  93. $sel_where = [];
  94. $title = input('get.title');
  95. $label = input('get.label');
  96. $sort_type = input('get.sort_type', 1);
  97. $sel_where[] = ['f.is_deleted', '=', 0];
  98. $sel_where[] = ['f.status', '=', 1];
  99. if ($title) $sel_where[] = ['f.title|f.label', 'like', '%' . $title . '%'];
  100. if ($label) $sel_where[] = ['f.label', 'like', '%' . $label . '%'];
  101. $app_name = sysconf('app_name');
  102. $app_logo = sysconf('app_logo');
  103. switch ($sort_type) {
  104. case 1:
  105. $order = ['sort' => 'desc', 'browse_num' => 'desc', 'id' => 'asc'];
  106. break;
  107. case 2:
  108. $order = ['id' => 'asc', 'sort' => 'desc'];
  109. break;
  110. case 3:
  111. $order = ['id' => 'desc', 'sort' => 'desc'];
  112. break;
  113. }
  114. if ($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id, $title, 6);
  115. $user_level = UserLevelRank::getUserVip($this->user_id);
  116. $max_level = $user_level ? $user_level : 1;
  117. $search_log = UserSearch::getSearchTitle($this->user_id, 6);
  118. $search_arr = [];
  119. foreach ($search_log as $t) {
  120. $search_arr[] = " b.title like '" . '%' . $t . "%'" . ' ';
  121. $search_arr[] = " b.label like '" . '%' . $t . "%'" . ' ';
  122. }
  123. $where_str = 'b.id > 0';
  124. if (!empty($search_arr)) $where_str = implode(' OR ', $search_arr);
  125. $field = ' a.id,a.title,a.content,a.label,a.level,a.browse_num,a.sort,a.create_at,IFNULL(is_recommend,0) is_recommend, u.name,u.headimg';
  126. $table = 'dd_user_forum';
  127. $order_by_two = 'a.browse_num';
  128. $sql = "SELECT $field FROM " . $table . " a LEFT JOIN ( SELECT id,IF(id,1,1) is_recommend FROM $table b WHERE ( $where_str )) AS c ON c.id = a.id LEFT JOIN dd_store_member as u ON a.user_id =u.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}";
  129. $list = Db::query($sql);
  130. $list = dispose_recommend($list);
  131. array_walk($list, function (&$v, $k) use ($app_name, $app_logo,$user_level) {
  132. $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
  133. $reply_num = ForumReply::where(['forum_id' => $v['id']])->where('is_deleted', 0)->count();
  134. $v['reply_num'] = numTransform($reply_num);
  135. $v['browse_num'] = numTransform($v['browse_num']);
  136. if (!$v['name']) $v['name'] = $app_name;
  137. if (!$v['headimg']) $v['headimg'] = $app_logo;
  138. $v['open_vip'] = !$user_level && $v['level'] ? 1 : 0;
  139. });
  140. $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 LEFT JOIN dd_store_member as u ON a.user_id =u.id WHERE a.is_deleted = 0 AND a.status =1 ";
  141. $total = Db::query($sql2);
  142. $total_num = $total[0]['num'];
  143. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  144. }
  145. /**
  146. * @title 获取问题详情
  147. * @desc 获取问题详情
  148. * @author qc
  149. * @method GET
  150. * @url /api/Forum/getForumInfo
  151. * @header name:Authorization require:1 desc:Token
  152. * @param name:id type:string default:-- desc:问题记录id
  153. * @return name:title type:string default:-- desc:标题
  154. * @return name:content type:string default:0 desc:内容
  155. * @return name:level type:int default:-- desc:vip等级id
  156. * @return name:label type:string default:-- desc:标签
  157. * @return name:label_name type:array default:-- desc:标签
  158. * @return name:name type:string default:-- desc:发布用户
  159. * @return name:headimg type:string default:-- desc:发布用户头像
  160. * @return name:browse_num type:int default:-- desc:浏览量
  161. * @return name:images type:string default:0 desc:图片【多张|隔开】
  162. * @return name:images_arr type:array default:null desc:图片【多张】
  163. * @return name:collect_num type:int default:-- desc:关注量
  164. * @return name:is_collect type:int default:-- desc:是否关注【0否1是】
  165. * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
  166. * @return name:comment_num type:int default:-- desc:评论数量
  167. * @return name:replay_num type:int default:-- desc:回复数量
  168. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  169. * @return name:like_num type:int default:-- desc:点赞数量
  170. * @return name:release_time type:string default:-- desc:上架时间
  171. */
  172. public function getForumInfo()
  173. {
  174. $id = input('get.id');
  175. $user_level = UserLevelRank::getUserVip($this->user_id);
  176. $app_name = sysconf('app_name');
  177. $app_logo = sysconf('app_logo');
  178. $detail = UserForum::where('f.id', $id)
  179. ->alias('f')
  180. ->field('f.id,f.title,f.is_deleted,release_time,f.content,f.label,f.images,f.level,f.browse_num,f.status,is_read,f.create_at,u.name,u.headimg,IFNULL( (SELECT count(r.id) FROM dd_forum_reply as r WHERE f.id=r.forum_id ),0 ) as reply_num')
  181. ->leftJoin('store_member u', 'u.id = f.user_id')
  182. ->find()->toArray();
  183. if ($detail['is_deleted'] || $detail['status'] == 0) $this->error('该问答已删除');
  184. // if ($user_level > 0 && $detail['level'] > $user_level) $this->error('用户等级不足');
  185. //if ($user_level == 0 && $detail['level'] > 1) $this->error('用户等级不足');
  186. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id, 5, $detail['id']);
  187. $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id, $detail['id'], 1);
  188. $detail['label_name'] = $detail['label'] ? explode(',', trim($detail['label'], ',')) : null;
  189. if (!$detail['name']) $detail['name'] = $app_name;
  190. if (!$detail['headimg']) $detail['headimg'] = $app_logo;
  191. $detail['comment_num'] = ForumReplyComment::where(['is_deleted' => 0, 'forum_id' => $detail['id']])->count();
  192. $detail['replay_num'] = ForumReply::where(['is_deleted' => 0, 'forum_id' => $detail['id']])->count();
  193. $detail['comment_num'] = numTransform($detail['comment_num']);
  194. $detail['replay_num'] = numTransform($detail['replay_num']);
  195. $detail['browse_num'] = numTransform($detail['browse_num']);
  196. $collect_num = UserCollect::getCollectNum(5,$detail['id']);
  197. $detail['collect_num'] = numTransform($collect_num);
  198. $detail['images_arr'] = $detail['images'] ? explode('|', $detail['images']) : null;
  199. $detail['is_like'] = PlatformLike::checkTags($this->user_id, $detail['id'], 10);
  200. $detail['like_num'] = PlatformLike::getPraiseNum($detail['id'], 10);
  201. UserForum::where('id', $id)->setInc('browse_num');// 增加浏览量
  202. if($this->user_id){
  203. TopSearch::seIncHotNum($id,$this->request->controller());
  204. }
  205. if($detail['content'] != null && $detail['content'] != ''){
  206. $detail['content'] = "<div style='font-family:微软雅黑;'>".$detail['content']."</div>";
  207. }
  208. if (!$detail['is_read']) UserForum::where('id', $detail['id'])->update(['is_read' => 1]);
  209. UserTrack::crateTrack($this->user_id, 5, input('get.id'), 0);
  210. $this->success('ok', ['detail' => $detail]);
  211. }
  212. /**
  213. * @title 问题回答列表
  214. * @desc 问题回答列表
  215. * @author qc
  216. * @method GET
  217. * @url /api/Forum/getReplyList
  218. * @header name:Authorization require:1 desc:Token
  219. * @param name:forum_id type:int default:0 desc:问答记录id
  220. * @param name:page type:int default:0 desc:页数
  221. * @param name:page_num type:int default:20 desc:每页数
  222. * @return name:id type:int default:-- desc:问答回复id
  223. * @return name:content type:string default:-- desc:内容
  224. * @return name:name type:string default:-- desc:会员
  225. * @return name:headimg type:string default:-- desc:会员头像
  226. * @return name:like_num type:int default:-- desc:点赞数量
  227. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  228. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  229. * @return name:level type:int default:-- desc:VIP等级
  230. * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
  231. * @return name:comment_num type:int default:-- desc:评论数量
  232. * @return name:new_comment type:array default:-- desc:最新两条评论【数据结构:评论列表【问题&&答案】/api/Forum/getReplyCommentList一样】
  233. * @return name:hot_comment type:array default:-- desc:最热两条评论【数据结构:评论列表【问题&&答案】/api/Forum/getReplyCommentList一样】
  234. * @return name:total_num type:int default: desc:总数
  235. */
  236. public function getReplyList()
  237. {
  238. $where = [];
  239. $where[] = ['r.forum_id', '=', input('get.forum_id')];
  240. $where[] = ['r.is_deleted', '=', 0];
  241. $list = ForumReply::where($where)
  242. ->alias('r')
  243. ->field('r.id,r.is_top,r.content,r.create_at,r.user_id,u.name,u.headimg,forum_id,f.level')
  244. ->leftJoin('store_member u', 'r.user_id = u.id')
  245. ->leftJoin('UserForum f', 'r.forum_id = f.id')
  246. ->limit($this->off_set, $this->page_num)
  247. ->order('r.is_top,r.id desc')
  248. ->select()->toArray();
  249. $app_name = sysconf('app_name');
  250. $app_logo = sysconf('app_logo');
  251. $total_num = ForumReply::where($where)->alias('r')->count();
  252. array_walk($list, function (&$val, $k) use ($app_name, $app_logo) {
  253. $val['like_num'] = PlatformLike::getPraiseNum($val['id'], 3);
  254. $val['is_like'] = PlatformLike::checkTags($this->user_id, $val['id'], 3);
  255. $val['can_delete'] = $val['user_id'] == $this->user_id ? 1 :0;
  256. if (!$val['user_id']) $val['name'] = $app_name;
  257. if (!$val['user_id']) $val['headimg'] = $app_logo;
  258. $sel_where = [];
  259. $sel_where[] = ['c.forum_id','=',$val['forum_id']];
  260. $sel_where[] = ['c.is_deleted','=',0];
  261. $sel_where[] = ['c.reply_id','=',$val['id']];
  262. $val['comment_num'] = ForumReplyComment::where($sel_where)->alias('c')->count();
  263. // 最新两条评论
  264. $new_comment = ForumReplyComment::where($sel_where)->alias('c')
  265. ->field('c.id,c.is_top,c.user_id,c.forum_id,c.reply_id,c.create_at,c.pid,c.content,u.name,u.headimg, IFNULL( (SELECT count(id) FROM dd_platform_like as r WHERE c.id=r.like_id AND r.type = 8),0 ) as like_num')
  266. ->leftJoin('store_member u', 'u.id = c.user_id')
  267. ->order( ['c.is_top'=>'desc','c.id'=>'desc'])->limit(0,2)
  268. ->select()->toArray();
  269. foreach ($new_comment as &$c) {
  270. $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
  271. $parent_comment = ForumReplyComment::where([['t.id', '=', $c['pid']]])
  272. ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.is_deleted')
  273. ->alias('t')->leftJoin('UserForum i', 't.forum_id = i.id')->leftJoin('store_member u', 't.user_id = u.id')
  274. ->find();
  275. $c['parent_comment'] = $parent_comment ? $parent_comment->toArray() : null;
  276. }
  277. // 最热两条
  278. $hot_comment = ForumReplyComment::where($sel_where)->alias('c')
  279. ->field('c.id,c.is_top,c.user_id,c.forum_id,c.reply_id,c.create_at,c.pid,c.content,u.name,u.headimg, IFNULL( (SELECT count(id) FROM dd_platform_like as r WHERE c.id=r.like_id AND r.type = 8),0 ) as like_num')
  280. ->leftJoin('store_member u', 'u.id = c.user_id')
  281. ->order(['c.is_top'=>'desc','like_num'=>'desc','c.id'=>'desc'])->limit(0,2)
  282. ->select()->toArray();
  283. foreach ($hot_comment as &$c) {
  284. $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
  285. $parent_comment = ForumReplyComment::where([['t.id', '=', $c['pid']]])
  286. ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.is_deleted')
  287. ->alias('t')->leftJoin('UserForum i', 't.forum_id = i.id')->leftJoin('store_member u', 't.user_id = u.id')
  288. ->find();
  289. $c['parent_comment'] = $parent_comment ? $parent_comment->toArray() : null;
  290. }
  291. $val['new_comment'] = $new_comment;
  292. $val['hot_comment'] = $hot_comment;
  293. });
  294. $this->success('ok', ['list' => $list, 'total_num' => numTransform($total_num), 'total_count' => $total_num, 'page_num' => $this->page_num]);
  295. }
  296. /**
  297. * @title 回答详情
  298. * @desc 回答详情
  299. * @author qc
  300. * @method GET
  301. * @url /api/Forum/getReplyInfo
  302. * @header name:Authorization require:1 desc:Token
  303. * @param name:id type:int default:1 desc:回答记录id
  304. * @return name:id type:int default:-- desc:问答回复id
  305. * @return name:forum_id type:int default:-- desc:问题id
  306. * @return name:forum_title type:int default:-- desc:问题标题
  307. * @return name:level type:int default:-- desc:问答VIP等级
  308. * @return name:content type:string default:-- desc:内容
  309. * @return name:name type:string default:-- desc:会员
  310. * @return name:headimg type:string default:-- desc:会员头像
  311. * @return name:like_num type:int default:-- desc:点赞数量
  312. * @return name:user_id type:int default:-- desc:回答人id
  313. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  314. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  315. * @return name:serial_number type:int default:-- desc:第几个回答的
  316. * @return name:next_id type:int default:-- desc:下一个回答的id
  317. */
  318. public function getReplyInfo()
  319. {
  320. $id = input('get.id');
  321. $info = ForumReply::where('r.id',$id)
  322. ->alias('r')
  323. ->field('r.id,r.is_top,r.forum_id,r.content,r.create_at,r.user_id,u.name,u.headimg,r.is_deleted,f.level')
  324. ->leftJoin('store_member u', 'r.user_id = u.id')
  325. ->leftJoin('UserForum f', 'f.id = r.forum_id')
  326. ->find()->toArray();
  327. if($info['is_deleted']) $this->error('该答案已删除');
  328. $info['like_num'] = PlatformLike::getPraiseNum($info['id'], 3);
  329. $info['is_like'] = PlatformLike::checkTags($this->user_id, $info['id'], 3);
  330. $info['serial_number'] = ForumReply::where([['id','<=',$id],['forum_id','=',$info['forum_id']]])->count();
  331. $info['next_id'] = ForumReply::where([['id','>',$id],['forum_id','=',$info['forum_id']],['is_deleted','=',0]])->min('id');
  332. $info['forum_title'] = UserForum::where('id',$info['forum_id'])->value('title');
  333. $this->success('ok',['detail'=>$info]);
  334. }
  335. /**
  336. * @title 评论列表【问题&&答案】
  337. * @desc 评论列表
  338. * @author qc
  339. * @method GET
  340. * @url /api/Forum/getReplyCommentList
  341. * @header name:Authorization require:1 desc:Token
  342. * @param name:forum_id type:int default:0 desc:问题id
  343. * @param name:reply_id type:int default:0 desc:回答记录id【不传获取问题的评论,传值获取答案的评论】
  344. * @param name:page type:int default:0 desc:页数
  345. * @param name:page_num type:int default:20 desc:每页数
  346. * @param name:sort_type type:int default:1 desc:排序1最新2最热
  347. * @return name:content type:string default:-- desc:评论内容
  348. * @return name:create_at type:string default:-- desc:评论时间
  349. * @return name:name type:string default:-- desc:会员
  350. * @return name:headimg type:string default:-- desc:会员头像
  351. * @return name:like_num type:int default:-- desc:点赞数量
  352. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  353. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  354. * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
  355. * @return name:parent_comment type:array default:-- desc:被回复的评论内容
  356. * @return name:parent_comment.content type:string default:-- desc:内容
  357. * @return name:parent_comment.name type:string default:-- desc:名称
  358. * @return name:parent_comment.headimg type:string default:-- desc:头像
  359. * @return name:parent_comment.title type:string default:-- desc:问答标题
  360. * @return name:parent_comment.forum_id type:string default:-- desc:问答id
  361. * @return name:parent_comment.is_deleted type:int default:-- desc:是否删除【0否,1,2删除】
  362. */
  363. public function getReplyCommentList()
  364. {
  365. $forum_id = input('forum_id');
  366. $reply_id = input('reply_id',0);
  367. $sort_type = input('get.sort_type',1);
  368. $sel_where = [];
  369. $sel_where[] = ['c.forum_id','=',$forum_id];
  370. $sel_where[] = ['c.is_deleted','=',0];
  371. $sel_where[] = ['c.reply_id','=',$reply_id];
  372. switch ($sort_type) {
  373. case 1:
  374. $order = ['c.is_top'=>'desc','c.id'=>'desc'];
  375. break;
  376. case 2:
  377. $order = ['c.is_top'=>'desc','like_num'=>'desc','c.id'=>'desc'];
  378. break;
  379. }
  380. $list = ForumReplyComment::where($sel_where)->alias('c')
  381. ->field('c.id,c.is_top,c.forum_id,c.user_id,c.reply_id,c.create_at,c.pid,c.content,u.name,u.headimg, IFNULL( (SELECT count(id) FROM dd_platform_like as r WHERE c.id=r.like_id AND r.type = 8),0 ) as like_num')
  382. ->leftJoin('store_member u', 'u.id = c.user_id')
  383. ->order($order)
  384. ->limit($this->off_set, $this->page_num)
  385. ->select()->toArray();
  386. foreach ($list as &$c) {
  387. $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
  388. $c['can_delete'] = $c['user_id'] == $this->user_id ? 1 :0;
  389. $parent_comment = ForumReplyComment::where([['t.id', '=', $c['pid']]])
  390. ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.is_deleted')
  391. ->alias('t')
  392. ->leftJoin('UserForum i', 't.forum_id = i.id')
  393. ->leftJoin('store_member u', 't.user_id = u.id')
  394. ->find();
  395. $c['parent_comment'] = $parent_comment ? $parent_comment->toArray() : null;
  396. }
  397. $total_num =ForumReplyComment::where($sel_where)->alias('c')->leftJoin('store_member u', 'u.id = c.user_id')->count();
  398. $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  399. }
  400. /**
  401. * @title 关注||取消关注
  402. * @desc 关注||取消关注
  403. * @author qc
  404. * @method POST
  405. * @url /api/Forum/forumCollect
  406. * @header name:Authorization require:1 desc:Token
  407. * @param name:id type:int require:1 default:-- desc:问答id
  408. * @param name:status type:int default:0 desc:收藏状态(0取消关注【未关注】,1关注)
  409. */
  410. public function forumCollect()
  411. {
  412. $coll_status = UserCollect::plateCollect($this->user_id, 5, input('post.id', 0), 0);
  413. $coll_status ? $this->success('操作成功', ['status' => 1]) : $this->success('操作成功', ['status' => 0]);
  414. }
  415. /**
  416. * @title 开启||关闭通知开关
  417. * @desc 开启||关闭通知开关
  418. * @author qc
  419. * @method POST
  420. * @url /api/Forum/forumSwitch
  421. * @header name:Authorization require:1 desc:Token*
  422. * @param name:id type:int require:1 default:-- desc:问答id
  423. */
  424. public function forumSwitch()
  425. {
  426. $switch_status = PlatformSwitch::userSwitch($this->user_id, input('post.id', 0), 1);
  427. $switch_status ? $this->success('操作成功', ['status' => 1]) : $this->success('操作成功', ['status' => 0]);
  428. }
  429. /**
  430. * @title 问题回答【对问题进行回答】
  431. * @desc 问题回答
  432. * @author qc
  433. * @method POST
  434. * @url /api/Forum/replyForum
  435. * @header name:Authorization require:1 desc:Token
  436. * @param name:id type:int default:-- desc:问答id
  437. * @param name:content type:string default:-- desc:内容
  438. * @return name:name type:string default:-- desc:会员名称
  439. * @return name:headimg type:string default:-- desc:会员头像
  440. * @return name:content type:string default:-- desc:内容
  441. */
  442. public function replyForum()
  443. {
  444. $id = input('post.id');
  445. $content = input('post.content');
  446. if (!$content) $this->error('请输入内容');
  447. $forum_info = UserForum::where('id', $id)->find()->toArray();
  448. if (!$forum_info['comment_switch']) $this->error('评论功能已关闭');
  449. $issue_user = $forum_info['user_id'];
  450. $res = ForumReply::create([
  451. 'user_id' => $this->user_id,
  452. 'content' => $content,
  453. 'issue_user' => $issue_user,
  454. 'forum_id' => $id,
  455. 'is_read' => $this->user_id == $issue_user ? 1 : 0,
  456. ]);
  457. $detail = ForumReply::where('c.id', $res->id)
  458. ->alias('c')
  459. ->field('c.id,c.content,c.create_at,u.name,u.headimg')
  460. ->leftJoin('store_member u', 'u.id = c.user_id')
  461. ->find()->toArray();
  462. $user_info = $this->userInfo('name');
  463. if($issue_user != $this->user_id) UserMessage:: sendUserMessage($issue_user, 'forum', 5, 0, $this->user_id, $id, $content);
  464. // 有新的回答时给关注问题的会员推送
  465. UserForum:: sendCollectMsg($id,$res->id);
  466. UserForum::where('id',$id)->setInc('r_num',1);
  467. $this->success('回复成功', ['detail' => $detail]);
  468. }
  469. /**
  470. * @title 一级评论【问题&&答案】
  471. * @desc 一级评论
  472. * @author qc
  473. * @method POST
  474. * @url /api/Forum/commentReply
  475. * @header name:Authorization require:1 desc:Token
  476. * @param name:forum_id type:int require:1 default:-- desc:问题的id
  477. * @param name:reply_id type:int default:-- desc:答案的id【不传是对问题的评论,传值是对答案的评论】
  478. * @param name:content type:string default:-- desc:内容
  479. * @return name:name type:string default:-- desc:会员名称
  480. * @return name:headimg type:string default:-- desc:会员头像
  481. * @return name:content type:string default:-- desc:内容
  482. * @return name:create_at type:string default:-- desc:时间
  483. */
  484. public function commentReply()
  485. {
  486. $forum_id = input('post.forum_id');
  487. $reply_id = input('post.reply_id', 0);
  488. $content = input('post.content');
  489. if (!$content) $this->error('请输入评论内容');
  490. if(intval($reply_id)) $reply_info = ForumReply::where('id', $reply_id)->find()->toArray();
  491. $forum_info = UserForum::where('id', $forum_id)->find()->toArray();
  492. if (!$forum_info['comment_switch']) $this->error('评论功能已关闭');
  493. $user_info = $this->userInfo('name,headimg');
  494. if (intval($reply_id) && $reply_info['user_id'] != $this->user_id ) UserMessage:: sendUserMessage($reply_info['user_id'], 'forum', 3, 0, $this->user_id, $reply_id, $content);
  495. if (!intval($reply_id) && $forum_info['user_id'] && $forum_info['user_id'] != $this->user_id) UserMessage:: sendUserMessage($forum_info['user_id'], 'forum',7, 0, $this->user_id, $reply_id, $content);
  496. $res = ForumReplyComment::create([
  497. 'user_id' => $this->user_id,
  498. 'content' => $content,
  499. 'forum_id' => $forum_id,
  500. 'reply_id' => $reply_id,
  501. 'is_read' => !empty($reply_info) && $reply_info['user_id'] == $this->user_id ? 1 : 0,
  502. 'source_read' => $forum_info['user_id'] == $this->user_id ? 1 : 0,
  503. ]);
  504. $detail = ForumReplyComment::where('c.id', $res->id)
  505. ->alias('c')
  506. ->field('c.id,c.is_top,c.content,c.create_at,u.name,u.headimg')
  507. ->leftJoin('store_member u', 'u.id = c.user_id')
  508. ->find()->toArray();
  509. $this->success('评论成功', ['detail' => $detail]);
  510. }
  511. /**
  512. * @title 二级评论【问题&&答案】
  513. * @desc 二级评论
  514. * @author qc
  515. * @method POST
  516. * @url /api/Forum/forumSecondComment
  517. * @header name:Authorization require:1 desc:Token
  518. * @param name:id type:int default:1 desc:评论id
  519. * @param name:content type:string default:-- desc:内容
  520. * @return name:name type:string default:-- desc:会员名称
  521. * @return name:headimg type:string default:-- desc:会员头像
  522. * @return name:content type:string default:-- desc:内容
  523. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  524. */
  525. public function forumSecondComment()
  526. {
  527. $comment = ForumReplyComment::where('id', input('post.id'))->find()->toArray();
  528. $forum_info = UserForum::where('id', $comment['forum_id'])->find()->toArray();
  529. if (!$forum_info['comment_switch']) $this->error('评论功能已关闭');
  530. $user_info = $this->userInfo('name');
  531. // if( $comment['reply_id']) $reply_info = ForumReply::where('id', $comment['reply_id'])->find()->toArray();
  532. if ($comment['user_id'] != $this->user_id ) UserMessage:: sendUserMessage($comment['user_id'], 'forum', 4, 0, $this->user_id, $comment['id'], input('post.content'));
  533. unset($comment['id']);
  534. unset($comment['create_at']);
  535. unset($comment['to_deleted']);
  536. unset($comment['is_top']);
  537. unset($comment['is_deleted']);
  538. $comment['is_read'] = !empty($comment) && $this->user_id == $comment['user_id'] ? 1 : 0;
  539. $comment['source_read'] = $this->user_id == $forum_info['user_id'] ? 1 : 0;
  540. $comment['pid'] = input('post.id');
  541. $comment['user_id'] = $this->user_id;
  542. $comment['content'] = input('post.content');
  543. $comment['lev']++;
  544. if (!$comment['source_id']) $comment['source_id'] = input('post.id');
  545. $res = ForumReplyComment::create($comment);
  546. $detail = ForumReplyComment::where('p.id', $res->id)
  547. ->alias('p')
  548. ->field('p.id,p.is_top,p.content,p.create_at,u.name,u.headimg')
  549. ->leftJoin('store_member u', 'u.id = p.user_id')
  550. ->find()->toArray();
  551. $this->success('评论成功', ['detail' => $detail]);
  552. }
  553. /**
  554. * @title 点赞||取消点赞
  555. * @desc 点赞||取消点赞
  556. * @author qc
  557. * @method POST
  558. * @url /api/Forum/forumTags
  559. * @header name:Authorization require:1 desc:Token
  560. * @param name:type type:int default:3 desc:类型(3答案,8评论【不用区分】,10问题)
  561. * @param name:like_id type:int default:1 desc:记录id
  562. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  563. */
  564. public function forumTags()
  565. {
  566. if (!in_array(input('type', 3), [3, 8, 10])) $this->error('类型错误');
  567. $ret_val = PlatformLike::userTags($this->user_id, input('post.like_id'), input('type', 3));
  568. $this->success('操作成功', ['tags' => $ret_val]);
  569. }
  570. /**
  571. * @title 用户发布或编辑问答
  572. * @desc 用户发布问答
  573. * @author qc
  574. * @method POST
  575. * @url /api/Forum/userReferForum
  576. * @header name:Authorization require:1 desc:Token
  577. * @param name:id type:string default:-- desc:详情id【编辑必传】
  578. * @param name:title type:string default:-- desc:标题
  579. * @param name:content type:string default:-- desc:内容
  580. * @param name:label type:string default:-- desc:问答标签(多个用逗号隔开)
  581. * @param name:images type:string default:-- desc:(多个用|隔开)
  582. */
  583. public function userReferForum()
  584. {
  585. $id = input('post.id');
  586. $title = input('post.title');
  587. $content = input('post.content');
  588. $label = input('post.label');
  589. $images = input('post.images');
  590. if (!$title || !$label) $this->error('参数错误');
  591. if (!$content) $content = '';
  592. $data = [
  593. 'title' => $title,
  594. 'user_id' => $this->user_id,
  595. 'content' => $content,
  596. 'label' => $label,
  597. 'images' => $images,
  598. 'level' => 0,//UserLevelRank::getUserVip($this->user_id),
  599. ];
  600. if($id){
  601. UserForum::where('id',$id)->update($data);
  602. UserForum::esAdd($id);
  603. \app\common\model\TopSearch::saveData($id,'forum');
  604. }else{
  605. $res = UserForum::create($data);
  606. UserForum::esAdd($res->id);
  607. \app\common\model\TopSearch::saveData($res->id,'forum');
  608. }
  609. //UserMessage::sendUserMessage($this->user_id, 'forum', 1, 0, 0, $res->id);
  610. $this->success('发布成功');
  611. }
  612. /**
  613. * @title 我的提问
  614. * @desc 我的提问
  615. * @author qc
  616. * @method GET
  617. * @url /api/Forum/getUserForumList
  618. * @header name:Authorization require:1 desc:Token
  619. * @param name:title type:string default:-- desc:标题
  620. * @param name:page type:int default:-- desc:页数
  621. * @param name:page_num type:int default:-- desc:每页数量
  622. * @return name:title type:string default:-- desc:标题
  623. * @return name:content type:string default:0 desc:内容
  624. * @return name:level type:int default:-- desc:vip等级id
  625. * @return name:label type:string default:-- desc:标签
  626. * @return name:label_name type:array default:-- desc:标签
  627. * @return name:name type:string default:-- desc:发布用户
  628. * @return name:headimg type:string default:-- desc:发布用户头像
  629. * @return name:browse_num type:int default:-- desc:浏览量
  630. * @return name:reply_num type:int default:-- desc:回答量
  631. * @return name:is_deleted type:int default:-- desc:0正常2后台下架
  632. * @return name:is_normal type:int default:-- desc:是否能正常跳转
  633. */
  634. public function getUserForumList()
  635. {
  636. $sel_where = [];
  637. $sel_where[] = ['f.is_deleted', '<>', 1];
  638. $sel_where[] = ['f.user_id', '=', $this->user_id];
  639. if ($title = input('get.title')) $sel_where[] = ['f.title|f.label', 'like', '%' . $title . '%'];
  640. $list = UserForum::where($sel_where)
  641. ->alias('f')
  642. ->field('f.id,f.title,f.content,f.level,f.label,f.browse_num,f.create_at,u.name,u.headimg, IFNULL( (SELECT count(r.id) FROM dd_forum_reply as r WHERE f.id=r.forum_id ),0 ) as reply_num')
  643. ->leftJoin('store_member u', 'u.id = f.user_id')
  644. ->limit($this->off_set, $this->page_num)
  645. ->order('id desc')
  646. ->select()->toArray();
  647. array_walk($list,function (&$v){
  648. $v['browse_num'] = numTransform($v['browse_num']);
  649. $v['reply_num'] = numTransform($v['reply_num']);
  650. $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
  651. $v['is_normal'] = CheckPower::checkModulesPower($v['id'], 0, $this->request->controller());
  652. });
  653. $total_num = UserForum::where($sel_where)->alias('f')->leftJoin('store_member u', 'u.id = f.user_id')->count();
  654. $this->success('ok', ['list' => $list, 'user_info' => $this->userInfo(['name', 'headimg']), 'total_count' => $total_num, 'page_num' => $this->page_num]);
  655. }
  656. /**
  657. * @title 我的回答
  658. * @desc 我的回答
  659. * @author qc
  660. * @method GET
  661. * @url /api/Forum/myReplyList
  662. * @header name:Authorization require:1 desc:Token
  663. * @param name:title type:string default:-- desc:关键字
  664. * @param name:page type:int default:-- desc:页数
  665. * @param name:page_num type:int default:-- desc:每页数量
  666. * @return name:title type:string default:-- desc:标题[问答]
  667. * @return name:browse_num type:int default:-- desc:问答浏览量
  668. * @return name:reply_num type:int default:-- desc:问答回答数量
  669. * @return name:like_num type:int default:-- desc:问答点赞量
  670. * @return name:content type:string default:0 desc:内容
  671. * @return name:name type:string default:-- desc:用户
  672. * @return name:headimg type:string default:-- desc:用户头像
  673. * @return name:create_at type:string default:-- desc:时间
  674. * @return name:is_normal type:int default:-- desc:是否能正常跳转
  675. * @return name:level type:int default:-- desc:问答VIP等级
  676. */
  677. public function myReplyList()
  678. {
  679. $where = [];
  680. $where[] = ['r.user_id', '=', $this->user_id];
  681. $where[] = ['r.is_deleted', '=', 0];
  682. if ($title = input('title')) $where[] = ['r.content', 'like', '%' . $title . '%'];
  683. $list = ForumReply::where($where)
  684. ->alias('r')
  685. ->field('r.id,r.content,r.forum_id,r.create_at,f.title,u.name ,u.headimg,f.browse_num,f.level')
  686. ->leftJoin('user_forum f', 'r.forum_id = f.id')
  687. ->leftJoin('store_member u', 'r.user_id = u.id')
  688. ->limit($this->off_set, $this->page_num)
  689. ->order('r.id desc')
  690. ->select()->toArray();
  691. array_walk($list, function (&$v) {
  692. $v['reply_num'] = ForumReply::where('forum_id', $v['forum_id'])->where('is_deleted', 0)->count();
  693. $v['reply_num'] = numTransform($v['reply_num']);
  694. $v['like_num'] = PlatformLike::getPraiseNum($v['forum_id'], 3);
  695. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  696. });
  697. $total_num = ForumReply::where($where)->alias('r')->count();
  698. $this->success('ok', ['list' => $list, 'total_num' => numTransform($total_num), 'total_count' => $total_num, 'page_num' => $this->page_num]);
  699. }
  700. /**
  701. * @title 我的评论
  702. * @desc 我的评论
  703. * @author qc
  704. * @method GET
  705. * @url /api/Forum/myDiscuss
  706. * @header name:Authorization require:1 desc:Token
  707. * @param name:type type:int default:1 desc:1问题2回答
  708. * @param name:title type:string default:-- desc:关键字
  709. * @param name:page type:int default:-- desc:页数
  710. * @param name:page_num type:int default:-- desc:每页数量
  711. * @return name:create_at type:string default:-- desc:时间
  712. * @return name:title type:string default:-- desc:问答标题
  713. * @return name:content type:string default:0 desc:评论内容
  714. * @return name:reply_content type:string default:0 desc:内容
  715. * @return name:name type:string default:-- desc:用户名
  716. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  717. * @return name:headimg type:string default:-- desc:用户头像
  718. * @return name:level type:int default:-- desc:VIP等级
  719. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  720. */
  721. public function myDiscuss()
  722. {
  723. $where = [];
  724. $type = input('get.type',1);
  725. $where[] = ['c.user_id', '=', $this->user_id];
  726. $where[] = ['c.is_deleted', '=', 0];
  727. if ($title = input('title')) $where[] = ['c.content', 'like', '%' . $title . '%'];
  728. $where[] = ['c.user_id', '=', $this->user_id];
  729. // $where[] = $type == 1 ? ['f.user_id', '<>', $this->user_id]:['r.user_id', '<>', $this->user_id];
  730. $where[] = ['c.pid', '=', 0];
  731. $where[] = ['c.reply_id',$type == 1 ? '=' :'>',0];
  732. $where[] = ['c.is_deleted', '=', 0];
  733. $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content,f.level,r.user_id reply_user')->alias('c')
  734. ->where($where)
  735. ->leftJoin('forum_reply r', 'c.reply_id = r.id')
  736. ->leftJoin('store_member m', 'm.id = r.user_id')
  737. ->leftJoin('user_forum f', 'f.id = c.forum_id')
  738. ->order('c.is_top desc,c.id desc')
  739. ->limit($this->off_set, $this->page_num)
  740. ->select()->toArray();
  741. $user_info = $this->userInfo();
  742. array_walk($list, function (&$v)use ($user_info) {
  743. $v['name'] = $user_info['name'];
  744. $v['headimg'] = $user_info['headimg'];
  745. if($v['reply_id']) {
  746. $v['show_title'] = $v['reply_content'];
  747. unset($v['reply_content']);
  748. $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
  749. }else{
  750. $v['show_title'] = $v['title'];
  751. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  752. }
  753. });
  754. $total_num = ForumReplyComment::where($where)
  755. ->alias('c')
  756. ->leftJoin('forum_reply r', 'c.reply_id = r.id')
  757. ->leftJoin('store_member m', 'm.id = r.user_id')
  758. ->leftJoin('user_forum f', 'f.id = c.forum_id')->count();
  759. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  760. }
  761. /**
  762. * @title 获取角标数量
  763. * @desc 获取角标数量
  764. * @author qc
  765. * @method GET
  766. * @url /api/Forum/getMarkNum
  767. * @header name:Authorization require:1 desc:Token
  768. * @return name:answer_num type:int default:-- desc:回答我的
  769. * @return name:reply_num type:int default:-- desc:回复我的【总数量】
  770. * @return name:reply_forum type:int default:-- desc:回复我的【问题】
  771. * @return name:reply_answer type:int default:-- desc:回复我的【答案】
  772. * @return name:comment_num type:int default:-- desc:评论我的【总数量】
  773. * @return name:forum_comment type:int default:-- desc:评论我的【评论问题】
  774. * @return name:reply_comment type:int default:-- desc:评论我的【评论答案】
  775. * @return name:follow_num type:int default:-- desc:关注量
  776. * @return name:praise_forum type:int default:-- desc:点赞问题
  777. * @return name:praise_reply type:int default:-- desc:点赞回答
  778. * @return name:praise_comment type:int default:-- desc:点赞评论
  779. * @return name:total_num type:int default:-- desc:总数
  780. */
  781. public function getMarkNum()
  782. {
  783. //回答我的
  784. $answer_num = ForumReply::where([['r.issue_user', '=', $this->user_id], ['r.is_deleted', '=', 0], ['r.is_read', '=', 0]])
  785. ->alias('r')->leftJoin('user_forum f', 'r.forum_id = f.id')->count();
  786. // 回复我的
  787. $all_comment = ForumReplyComment::where(['user_id' => $this->user_id, 'is_deleted' => 0])->column('id');
  788. if(count($all_comment) < 1){
  789. $reply_forum = 0;
  790. $reply_answer = 0;
  791. }else{
  792. $reply_forum = ForumReplyComment::where([['t.is_deleted', '=', 0], ['t.user_id', '<>', $this->user_id], ['t.reply_id', '=', 0], ['t.is_read', '=', 0], ['t.pid', 'in', implode(',', $all_comment)]])->alias('t')->count();
  793. $reply_answer = ForumReplyComment::where([['t.is_deleted', '=', 0], ['t.user_id', '<>', $this->user_id], ['t.reply_id', '>', 0], ['t.is_read', '=', 0], ['t.pid', 'in', implode(',', $all_comment)]])->alias('t')->count();
  794. }
  795. $reply_num = $reply_forum +$reply_answer;
  796. // 评论我的问题
  797. /* $where[] = ['f.user_id', '=', $this->user_id];
  798. $where[] = ['f.is_deleted', '=', 0];
  799. $where[] = ['c.is_deleted', '=', 0];
  800. $where[] = ['c.user_id', '<>', $this->user_id];
  801. $where[] = ['c.reply_id', '=', 0];
  802. $where[] = ['c.to_deleted', '=', 0];
  803. $where[] = ['c.pid','=',0];*/
  804. $forum_comment = ForumReplyComment::alias('c')
  805. ->where(['r.user_id' => $this->user_id, 'r.is_deleted' => 0, 'c.is_read' => 0,'c.reply_id'=>0,'c.pid'=>0,'c.to_deleted'=>0])
  806. ->where('c.user_id','<>',$this->user_id)
  807. ->leftJoin('UserForum r', 'c.forum_id = r.id')
  808. ->count();
  809. // 评论我的回答
  810. $reply_comment = ForumReplyComment::alias('c')
  811. ->where(['r.user_id' => $this->user_id, 'r.is_deleted' => 0, 'c.is_read' => 0,'c.pid'=>0])
  812. ->leftJoin('forum_reply r', 'c.reply_id = r.id')
  813. ->count();
  814. $comment_num = $forum_comment +$reply_comment;
  815. $follow_num = UserMessage::getUnreadNum($this->user_id,'forum',6);
  816. $total_num = $answer_num + $reply_num + $comment_num +$follow_num;
  817. //
  818. $praise_forum = PlatformLike::where([['p.type', '=', 10],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p') ->leftJoin('UserForum f', 'f.id = p.like_id')
  819. ->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
  820. $praise_reply = PlatformLike::where([['p.type', '=', 3],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('ForumReply f', 'f.id = p.like_id')
  821. ->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
  822. $praise_comment = PlatformLike::where([['p.type', '=', 8],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
  823. ->leftJoin('UserForum f', 'f.id = c.forum_id')
  824. ->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
  825. $this->success('ok', compact([
  826. 'answer_num',
  827. 'reply_num',
  828. 'comment_num',
  829. 'forum_comment',
  830. 'reply_comment',
  831. 'reply_answer',
  832. 'reply_forum',
  833. 'follow_num',
  834. 'praise_forum',
  835. 'praise_reply',
  836. 'praise_comment',
  837. 'total_num',
  838. ]));
  839. }
  840. /**
  841. * @title 回答我的
  842. * @desc 回答我的
  843. * @author qc
  844. * @method GET
  845. * @url /api/Forum/replyToMyForum
  846. * @header name:Authorization require:1 desc:Token
  847. * @param name:title type:string default:-- desc:关键字
  848. * @param name:page type:int default:-- desc:页数
  849. * @param name:page_num type:int default:-- desc:每页数量
  850. * @return name:id type:string default:-- desc:回答记录id
  851. * @return name:title type:string default:-- desc:标题[问答]
  852. * @return name:content type:string default:0 desc:评论内容
  853. * @return name:name type:string default:-- desc:用户
  854. * @return name:headimg type:string default:-- desc:用户头像
  855. * @return name:create_at type:string default:-- desc:时间
  856. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  857. * @return name:forum_id type:int default:-- desc:问答id
  858. * @return name:level type:int default:-- desc:VIP等级
  859. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  860. */
  861. public function replyToMyForum()
  862. {
  863. $where = [];
  864. $where[] = ['r.issue_user', '=', $this->user_id];
  865. $where[] = ['r.user_id', '<>', $this->user_id];
  866. $where[] = ['r.is_deleted', '=', 0];
  867. $where[] = ['r.to_deleted', '=', 0];
  868. $where[] = ['f.user_id', '=', $this->user_id];// 过滤回答自己的问答
  869. if ($title = input('title')) $where[] = ['r.content', 'like', '%' . $title . '%'];
  870. $list = ForumReply::where($where)
  871. ->alias('r')
  872. ->field('r.id,r.is_read,r.content,r.create_at,f.title,u.name,r.forum_id ,u.headimg,f.level')
  873. ->leftJoin('user_forum f', 'r.forum_id = f.id')
  874. ->leftJoin('store_member u', 'r.user_id = u.id')
  875. ->limit($this->off_set, $this->page_num)
  876. ->order('r.id desc')
  877. ->select()->toArray();
  878. array_walk($list, function (&$v) {
  879. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  880. });
  881. $total_num = ForumReply::where($where)->leftJoin('user_forum f', 'r.forum_id = f.id')
  882. ->leftJoin('store_member u', 'r.user_id = u.id')->alias('r')->count();
  883. $this->success('ok', ['list' => $list, 'total_num' => numTransform($total_num), 'total_count' => $total_num, 'page_num' => $this->page_num]);
  884. }
  885. /**
  886. * @title 评论我的--问题
  887. * @desc 评论我的
  888. * @author qc
  889. * @method GET
  890. * @url /api/Forum/commentOnMyForum
  891. * @header name:Authorization require:1 desc:Token
  892. * @param name:title type:string default:-- desc:关键字
  893. * @param name:page type:int default:-- desc:页数
  894. * @param name:page_num type:int default:-- desc:每页数量
  895. * @return name:create_at type:string default:-- desc:时间
  896. * @return name:title type:string default:-- desc:问答标题
  897. * @return name:content type:string default:0 desc:评论内容
  898. * @return name:reply_content type:string default:0 desc:回复内容
  899. * @return name:name type:string default:-- desc:评论用户
  900. * @return name:headimg type:string default:-- desc:评论用户头像
  901. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  902. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  903. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  904. */
  905. public function commentOnMyForum()
  906. {
  907. $where = [];
  908. $where[] = ['f.user_id', '=', $this->user_id];
  909. $where[] = ['f.is_deleted', '=', 0];
  910. $where[] = ['c.is_deleted', '=', 0];
  911. $where[] = ['c.user_id', '<>', $this->user_id];
  912. $where[] = ['c.reply_id', '=', 0];
  913. $where[] = ['c.to_deleted', '=', 0];
  914. $where[] = ['c.pid','=',0];
  915. if ($title = input('title')) $where[] = ['f.title', 'like', '%' . $title . '%'];
  916. $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title')->alias('c')
  917. ->where($where)
  918. ->leftJoin('store_member m', 'm.id = c.user_id')
  919. ->leftJoin('user_forum f', 'f.id = c.forum_id')
  920. ->order('c.is_top desc,c.id desc')
  921. ->limit($this->off_set, $this->page_num)
  922. ->select()->toArray();
  923. array_walk($list, function (&$v) {
  924. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  925. });
  926. $total_num = ForumReplyComment::where($where)
  927. ->alias('c')
  928. ->leftJoin('store_member m', 'm.id = c.user_id')
  929. ->leftJoin('user_forum f', 'f.id = c.forum_id')->count();
  930. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  931. }
  932. /**
  933. * @title 评论我的--回答
  934. * @desc 评论我的
  935. * @author qc
  936. * @method GET
  937. * @url /api/Forum/commentOnMyReply
  938. * @header name:Authorization require:1 desc:Token
  939. * @param name:title type:string default:-- desc:关键字
  940. * @param name:page type:int default:-- desc:页数
  941. * @param name:page_num type:int default:-- desc:每页数量
  942. * @return name:create_at type:string default:-- desc:时间
  943. * @return name:title type:string default:-- desc:问答标题
  944. * @return name:content type:string default:0 desc:评论内容
  945. * @return name:reply_content type:string default:0 desc:回复内容
  946. * @return name:name type:string default:-- desc:评论用户
  947. * @return name:headimg type:string default:-- desc:评论用户头像
  948. * @return name:self_name type:string default:-- desc:自己昵称
  949. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  950. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  951. * @return name:level type:int default:-- desc:VIP等级
  952. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  953. */
  954. public function commentOnMyReply()
  955. {
  956. $where = [];
  957. $where[] = ['r.user_id', '=', $this->user_id];
  958. $where[] = ['r.is_deleted', '=', 0];
  959. $where[] = ['c.user_id', '<>', $this->user_id];
  960. $where[] = ['c.reply_id', '>', 0];
  961. $where[] = ['c.to_deleted', '=', 0];
  962. $where[] = ['c.pid','=',0];
  963. if ($title = input('title')) $where[] = ['f.title', 'like', '%' . $title . '%'];
  964. $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content,f.level')->alias('c')
  965. ->where($where)
  966. ->leftJoin('forum_reply r', 'c.reply_id = r.id')
  967. ->leftJoin('store_member m', 'm.id = c.user_id')
  968. ->leftJoin('user_forum f', 'f.id = c.forum_id')
  969. ->order('c.is_top desc,c.id desc')
  970. ->limit($this->off_set, $this->page_num)
  971. ->select()->toArray();
  972. array_walk($list, function (&$v) {
  973. $v['self_name'] = $this->user_info['name'];
  974. $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
  975. });
  976. $total_num = ForumReplyComment::where($where)
  977. ->alias('c')
  978. ->leftJoin('forum_reply r', 'c.reply_id = r.id')
  979. ->leftJoin('store_member m', 'm.id = c.user_id')
  980. ->leftJoin('user_forum f', 'f.id = c.forum_id')->count();
  981. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  982. }
  983. /**
  984. * @title 用户举报
  985. * @desc 用户举报
  986. * @author qc
  987. * @url /api/Forum/forumReport
  988. * @method POST
  989. * @header name:Authorization require:1 desc:Token
  990. * @param name:report_id type:int default:-- desc:举报内容的id
  991. * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
  992. */
  993. public function forumReport()
  994. {
  995. $report_id = input('post.report_id');
  996. $case_ids = input('post.case_ids');
  997. if (!$report_id) $this->error('请现在举报内容');
  998. if (!$case_ids) $this->error('请选择举报原因');
  999. UserReport::report($this->user_id, 6, $report_id, $case_ids);
  1000. $this->success('举报成功');
  1001. }
  1002. /**
  1003. * @title 转发(转发数量统计)
  1004. * @desc 转发成功后调用
  1005. * @author qc
  1006. * @method POST
  1007. * @url /api/Forum/forumTransmit
  1008. * @header name:Authorization require:1 desc:Token
  1009. * @param name:forum_id type:int default:-- desc:问答问题id
  1010. */
  1011. public function forumTransmit()
  1012. {
  1013. $forum_id = input('post.forum_id');
  1014. UserForum::where('id', $forum_id)->setInc('transmit_num');
  1015. $this->success('转发成功');
  1016. }
  1017. /**
  1018. * @title 回复我的【回复过我的评论】
  1019. * @desc 回复我的
  1020. * @author qc
  1021. * @method GET
  1022. * @url /api/Forum/getReplyComment
  1023. * @header name:Authorization require:1 desc:Token
  1024. * @param name:title type:string default:-- desc:查询内容
  1025. * @param name:type type:int default:1 desc:1问题2回答
  1026. * @param name:page type:int default:0 desc:页数
  1027. * @param name:page_num type:int default:20 desc:每页数
  1028. * @return name:id type:int default:-- desc:记录id
  1029. * @return name:title type:string default:-- desc:问题标题
  1030. * @return name:create_at type:string default:-- desc:时间
  1031. * @return name:is_deleted type:int default:-- desc:回复内容是被删除【0否】
  1032. * @return name:user_name type:string default:-- desc:用户名【其他会员】
  1033. * @return name:headimg type:string default:-- desc:用户头像【其他会员】
  1034. * @return name:content type:string default:-- desc:回复内容
  1035. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  1036. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  1037. * @return name:level type:int default:-- desc:VIP等级
  1038. * @return name:parent_comment type:array default:-- desc:你的评论内容【阴影部分】
  1039. * @return name:parent_comment.content type:string default:-- desc:内容
  1040. * @return name:parent_comment.is_normal type:int default:-- desc:问题或答案能否跳转(0已删除或是已禁用1可以正常跳转详情)
  1041. * @return name:parent_comment.is_deleted type:int default:-- desc:被评论的内容是否删除
  1042. * @return name:parent_comment.name type:string default:-- desc:你的会员名称
  1043. * @return name:parent_comment.headimg type:string default:-- desc:你的头像
  1044. * @return name:parent_comment.forum_id type:int default:-- desc:问答id
  1045. * @return name:parent_comment.show_title type:string default:-- desc:展示的问题标题或答案内容
  1046. * @return name:parent_comment.is_deleted type:int default:-- desc:是否删除【0否,1,2删除】
  1047. * @return name:parent_comment.reply_user type:int default:-- desc:回答人id
  1048. * @return name:parent_comment.reply_id type:int default:-- desc:答案id【值为0是问题类型,大于0是答案类型】
  1049. */
  1050. public function getReplyComment()
  1051. {
  1052. // 所有我评论的回答
  1053. $all_comment = ForumReplyComment::where(['user_id'=> $this->user_id, 'is_deleted' => 0])->column('id');
  1054. if (empty($all_comment)) $this->success('ok', ['list' => null]);
  1055. $sel_where = [];
  1056. $title = input('get.title');
  1057. $type = input('get.type',1);
  1058. if ($title) $sel_where[] = ['t.content', 'like', '%' . $title . '%'];
  1059. // $sel_where[] = ['t.is_deleted', '=', 0];
  1060. $sel_where[] = ['t.to_deleted', '=', 0];
  1061. $sel_where[] = ['t.user_id','<>',$this->user_id];
  1062. $sel_where[] = ['t.pid', 'in', implode(',', $all_comment)];
  1063. $sel_where[] = ['t.reply_id',$type == 1 ? '=' : '>',0];
  1064. $list = ForumReplyComment::where($sel_where)
  1065. ->alias('t')
  1066. ->field('t.id,t.is_top,t.create_at,t.is_read,t.content,t.is_deleted,t.pid,forum_id,u.name user_name,u.headimg,i.title,t.reply_id,i.level')
  1067. ->leftJoin('store_member u', 't.user_id = u.id')
  1068. ->leftJoin('UserForum i', 't.forum_id = i.id')
  1069. ->order('t.is_top desc,t.id desc')
  1070. ->limit($this->off_set, $this->page_num)
  1071. ->select()->toArray();
  1072. foreach ($list as &$v) {
  1073. $parent_comment = ForumReplyComment::where([['t.id', '=', $v['pid']]])
  1074. ->field('t.id,t.is_top,t.forum_id,t.is_deleted,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.reply_id')
  1075. ->alias('t')->leftJoin('UserForum i', 't.forum_id = i.id')
  1076. ->leftJoin('store_member u', 't.user_id = u.id')
  1077. ->find()->toArray();
  1078. $parent_comment['show_title'] = $v['title'];
  1079. if($parent_comment['reply_id']) {
  1080. $reply_info = ForumReply::where('id', $parent_comment['reply_id'])->find()->toArray();
  1081. $parent_comment['reply_user'] = $reply_info['user_id'];
  1082. $parent_comment['show_title'] = ForumReply::where('id',$parent_comment['reply_id'])->value('content');
  1083. $parent_comment['is_normal'] =CheckPower::checkModulesPower($parent_comment['reply_id'], 0, 'reply');
  1084. }else{
  1085. $parent_comment['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1086. $parent_comment['show_title'] = $parent_comment['show_title'];
  1087. }
  1088. $v['parent_comment'] = $parent_comment;
  1089. }
  1090. $total_num = ForumReplyComment::where($sel_where)->alias('t')->leftJoin('store_member u', 't.user_id = u.id')
  1091. ->leftJoin('UserForum i', 't.forum_id = i.id')->count();
  1092. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1093. }
  1094. /**
  1095. * @title 我的回复【我的回复--我回复过的评论】
  1096. * @desc 我的回复
  1097. * @author qc
  1098. * @method GET
  1099. * @url /api/Forum/getReplyForum
  1100. * @header name:Authorization require:1 desc:Token
  1101. * @param name:title type:string default:-- desc:标题
  1102. * @param name:type type:int default:1 desc:1问题2回答
  1103. * @param name:page type:int default:0 desc:页数
  1104. * @param name:page_num type:int default:20 desc:每页数
  1105. * @return name:title type:string default:-- desc:问答标题
  1106. * @return name:create_at type:string default:-- desc:时间
  1107. * @return name:level type:int default:-- desc:VIP等级
  1108. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  1109. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  1110. * @return name:content type:string default:-- desc:回复内容
  1111. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  1112. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1113. * @return name:parent_comment type:array default:-- desc:上级评论内容【阴影部分--你回复的那个】
  1114. * @return name:parent_comment.content type:string default:-- desc:内容
  1115. * @return name:parent_comment.name type:string default:-- desc:会员名称【别人的】
  1116. * @return name:parent_comment.headimg type:string default:-- desc:会员头像【别人的】
  1117. * @return name:parent_comment.title type:string default:-- desc:问答标题
  1118. * @return name:parent_comment.forum_id type:string default:-- desc:问答id
  1119. * @return name:parent_comment.is_deleted type:int default:-- desc:是否删除【0否,1,2删除】
  1120. * @return name:parent_comment.show_title type:string default:-- desc:展示的问题标题或答案内容
  1121. * @return name:parent_comment.reply_id type:int default:-- desc:答案id【值为0是问题类型,大于0是答案类型】
  1122. *
  1123. */
  1124. public function getReplyForum()
  1125. {
  1126. $sel_where = [];
  1127. $title = input('get.title');
  1128. $type = input('get.type',1);
  1129. if ($title) $sel_where[] = ['i.title|i.label', 'like', '%' . $title . '%'];
  1130. $sel_where[] = ['t.user_id', '=', $this->user_id];
  1131. $sel_where[] = ['c.user_id', '<>', $this->user_id];
  1132. $sel_where[] = ['t.is_deleted', '=', 0];
  1133. $sel_where[] = ['t.lev', '>=', 2];
  1134. $sel_where[] = ['t.reply_id',$type == 1 ? '=' :'>',0];
  1135. $list = ForumReplyComment::where($sel_where)
  1136. ->alias('t')
  1137. ->field('t.id,t.is_top,t.create_at,t.content,t.pid,t.forum_id,i.title,t.reply_id,t.is_deleted,i.level')
  1138. ->leftJoin('UserForum i', 't.forum_id = i.id')
  1139. ->leftJoin('ForumReplyComment c', 'c.id = t.pid')
  1140. ->order('t.id desc')
  1141. ->limit($this->off_set, $this->page_num)
  1142. ->select()->toArray();
  1143. foreach ($list as &$v) {
  1144. $v['user_name'] = $this->user_info['name'];
  1145. $v['headimg'] = $this->user_info['headimg'];
  1146. $parent_comment = ForumReplyComment::where([['t.id', '=', $v['pid']]])
  1147. ->field('t.id,t.is_top,t.create_at,t.content,t.pid,forum_id,u.name,u.headimg,i.title')
  1148. ->alias('t')
  1149. ->leftJoin('UserForum i', 't.forum_id = i.id')
  1150. ->leftJoin('store_member u', 't.user_id = u.id')
  1151. ->find()->toArray();
  1152. if($v['reply_id']) {
  1153. $reply_info = ForumReply::where('id', $v['reply_id'])->find()->toArray();
  1154. $parent_comment['reply_user'] = $reply_info['user_id'];
  1155. $parent_comment['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
  1156. $parent_comment['show_title'] = ForumReply::where('id',$v['reply_id'])->value('content');
  1157. }else{
  1158. $parent_comment['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1159. $parent_comment['show_title'] = $parent_comment['title'];
  1160. }
  1161. $v['parent_comment'] = $parent_comment;
  1162. }
  1163. $total_num = ForumReplyComment::where($sel_where)->alias('t') ->leftJoin('UserForum i', 't.forum_id = i.id')
  1164. ->leftJoin('ForumReplyComment c', 'c.id = t.pid')->count();
  1165. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1166. }
  1167. /**
  1168. *
  1169. * @title 点赞我的--问题
  1170. * @desc 点赞我的
  1171. * @author qc
  1172. * @method GET
  1173. * @url /api/Forum/praiseForumList
  1174. * @header name:Authorization require:1 desc:Token
  1175. * @param name:page type:int default:-- desc:页数
  1176. * @param name:page_num type:int default:-- desc:每页数
  1177. * @return name:id type:int default:-- desc:记录id
  1178. * @return name:like_id type:int default:-- desc:问题id
  1179. * @return name:title type:string default:-- desc:问题
  1180. * @return name:create_at type:string default:-- desc:时间
  1181. * @return name:user_name type:string default:-- desc:会员名称
  1182. * @return name:headimg type:string default:-- desc:会员头像
  1183. * @return name:level type:int default:-- desc:VIP等级
  1184. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1185. */
  1186. public function praiseForumList()
  1187. {
  1188. $sel_where = [];
  1189. $sel_where[] = ['p.type', '=', 10];
  1190. $sel_where[] = ['f.user_id', '=', $this->user_id];
  1191. $sel_where[] = ['p.user_id', '<>', $this->user_id];
  1192. $sel_where[] = ['p.to_deleted', '=', 0];
  1193. $list = PlatformLike::where($sel_where)
  1194. ->field('p.*,f.title,u.name user_name,u.headimg,f.level')
  1195. ->alias('p')
  1196. ->leftJoin('UserForum f', 'f.id = p.like_id')
  1197. ->leftJoin('StoreMember u', 'u.id = p.user_id')
  1198. ->limit($this->off_set,$this->page_num)
  1199. ->select()->toArray();
  1200. array_walk($list, function (&$v) {
  1201. $v['is_normal'] = CheckPower::checkModulesPower($v['like_id'], 0, $this->request->controller());
  1202. });
  1203. $total_num = PlatformLike::where($sel_where)->alias('p')
  1204. ->leftJoin('UserForum f', 'f.id = p.like_id')->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
  1205. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1206. }
  1207. /**
  1208. * @title 点赞我的--答案
  1209. * @desc 点赞我的
  1210. * @author qc
  1211. * @method GET
  1212. * @url /api/Forum/praiseReplyList
  1213. * @header name:Authorization require:1 desc:Token
  1214. * @param name:page type:int default:-- desc:页数
  1215. * @param name:page_num type:int default:-- desc:每页数
  1216. * @return name:id type:int default:-- desc:记录id
  1217. * @return name:content type:string default:-- desc:答案
  1218. * @return name:level type:int default:-- desc:VIP等级
  1219. * @return name:create_at type:string default:-- desc:时间
  1220. * @return name:user_name type:string default:-- desc:会员名称
  1221. * @return name:headimg type:string default:-- desc:会员头像
  1222. * @return name:is_normal type:int default:-- desc:是否是正常记录
  1223. */
  1224. public function praiseReplyList()
  1225. {
  1226. $sel_where = [];
  1227. $sel_where[] = ['p.type', '=', 3];
  1228. $sel_where[] = ['f.user_id', '=', $this->user_id];
  1229. $sel_where[] = ['p.user_id', '<>', $this->user_id];
  1230. $sel_where[] = ['p.to_deleted', '=', 0];
  1231. /* PlatformLike::where($sel_where)->alias('p')->leftJoin('ForumReply f', 'f.id = p.like_id')
  1232. ->leftJoin('StoreMember u', 'u.id = p.user_id')->update(['p.is_read'=>1]);*/
  1233. $list = PlatformLike::where($sel_where)
  1234. ->field('p.*,f.content,f.is_deleted,f.to_deleted,u.name user_name,u.headimg,m.level,f.forum_id,f.id reply_id')
  1235. ->alias('p')
  1236. ->leftJoin('ForumReply f', 'f.id = p.like_id')
  1237. ->leftJoin('UserForum m', 'm.id = f.forum_id')
  1238. ->leftJoin('StoreMember u', 'u.id = p.user_id')
  1239. ->limit($this->off_set,$this->page_num)
  1240. ->order('p.id desc')
  1241. ->select()->toArray();
  1242. array_walk($list, function (&$v) {
  1243. $v['is_normal'] = $v['to_deleted'] || $v['is_deleted'] ? 0 : 1;
  1244. });
  1245. $total_num = PlatformLike::where($sel_where)->alias('p')
  1246. ->leftJoin('ForumReply f', 'f.id = p.like_id')->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
  1247. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1248. }
  1249. /**
  1250. * @title 点赞我的--评论
  1251. * @desc 点赞我的
  1252. * @author qc
  1253. * @method GET
  1254. * @url /api/Forum/praiseCommentList
  1255. * @header name:Authorization require:1 desc:Token
  1256. * @param name:page type:int default:-- desc:页数
  1257. * @param name:page_num type:int default:-- desc:每页数
  1258. * @return name:id type:int default:-- desc:记录id
  1259. * @return name:title type:string default:-- desc:问题||答案内容
  1260. * @return name:forum_id type:string default:-- desc:问题id
  1261. * @return name:level type:int default:-- desc:VIP等级
  1262. * @return name:type type:int default:-- desc:1问题2答案
  1263. * @return name:reply_id type:string default:-- desc:答案id(问题类型值为0)
  1264. * @return name:reply_user type:string default:-- desc:回答会员id
  1265. * @return name:content type:string default:-- desc:评论内容
  1266. * @return name:create_at type:string default:-- desc:时间
  1267. * @return name:self_name type:string default:-- desc:用户名称【自己的】
  1268. * @return name:user_name type:string default:-- desc:会员名称【点赞人的】
  1269. * @return name:headimg type:string default:-- desc:会员头像【点赞人的】
  1270. * @return name:comment_normal type:int default:-- desc:评论是否正常
  1271. * @return name:aim_normal type:int default:-- desc:问题或答案是否正常
  1272. */
  1273. public function praiseCommentList()
  1274. {
  1275. $sel_where = [];
  1276. $sel_where[] = ['p.type', '=', 8];
  1277. $sel_where[] = ['c.user_id', '=', $this->user_id];
  1278. $sel_where[] = ['p.user_id', '<>', $this->user_id];
  1279. $sel_where[] = ['p.to_deleted', '=', 0];
  1280. /* PlatformLike::where($sel_where)->alias('p') ->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
  1281. ->leftJoin('UserForum f', 'f.id = c.forum_id')
  1282. ->leftJoin('StoreMember u', 'u.id = p.user_id')->update(['p.is_read'=>1]);*/
  1283. $list = PlatformLike::where($sel_where)
  1284. ->field('p.*,c.content,c.is_deleted,c.forum_id,c.to_deleted,c.source_deleted,u.name user_name,u.headimg,f.title,c.reply_id,f.level,f.user_id forum_user')
  1285. ->alias('p')
  1286. ->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
  1287. ->leftJoin('UserForum f', 'f.id = c.forum_id')
  1288. ->leftJoin('StoreMember u', 'u.id = p.user_id')
  1289. ->limit($this->off_set,$this->page_num)
  1290. ->order('p.create_at desc')
  1291. ->select()->toArray();
  1292. $self_name = User::where('id', $this->user_id)->value('name');
  1293. array_walk($list, function (&$v) use ($self_name) {
  1294. $v['type'] = $v['reply_id'] ? 2 : 1;
  1295. $v['comment_normal'] = $v['to_deleted'] || $v['is_deleted'] || $v['source_deleted'] ? 0 : 1;
  1296. if ($v['reply_id']) {
  1297. $reply_info = ForumReply::where('id', $v['reply_id'])->find()->toArray();
  1298. $v['reply_user'] = $reply_info['user_id'];
  1299. $v['title'] = $reply_info['content'];
  1300. $v['aim_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
  1301. } else {
  1302. $v['aim_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1303. }
  1304. $v['self_name'] = $self_name;
  1305. });
  1306. $total_num = PlatformLike::where($sel_where)->alias('p')
  1307. ->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
  1308. ->leftJoin('UserForum f', 'f.id = c.forum_id')
  1309. ->leftJoin('StoreMember u', 'u.id = p.user_id')
  1310. ->count();
  1311. $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
  1312. }
  1313. /**
  1314. * @title 批量删除||批量取消
  1315. * @desc 删除||取消
  1316. * @author qc
  1317. * @method POST
  1318. * @url /api/Forum/batchesDel
  1319. * @header name:Authorization require:1 desc:Token
  1320. * @param name:id type:string default:1 desc:记录id【多个用逗号隔开=>'1,2'】
  1321. * @param name:type type:string default:1 desc:消息类型【1点赞我的,2回答我的,3回复我的,4评论我的,5我的点赞,6我的关注,7我的回答,8我的回复,9我的评论,10我的提问,11追番消息】
  1322. */
  1323. public function batchesDel()
  1324. {
  1325. $type = input('post.type',1);
  1326. $id = input('post.id');
  1327. if(!$id) $this->error('请选择要删除的记录');
  1328. $del_where = [];
  1329. $del_where[] = ['id','in',$id];
  1330. if(in_array($type,[1])) PlatformLike::where($del_where)->update(['to_deleted'=>1]);
  1331. if(in_array($type,[2])) ForumReply::where($del_where)->where(['issue_user'=>$this->user_id])->update(['to_deleted'=>1,'is_deleted'=>1,'is_read'=>1]);
  1332. if(in_array($type,[2])){
  1333. $reply = Db::name('forum_reply')->where($del_where)->where('issue_user',$this->user_id)->field('id,forum_id')->find();
  1334. $count = Db::name('forum_reply')->where($del_where)->where('issue_user',$this->user_id)->count();
  1335. UserForum::where('id',$reply['forum_id'])->setDec('r_num',$count);
  1336. }
  1337. if(in_array($type,[3,4])) ForumReplyComment::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
  1338. if(in_array($type,[5])) PlatformLike::where($del_where)->where('user_id',$this->user_id)->delete();
  1339. if(in_array($type,[6])) UserCollect::where($del_where)->where('user_id',$this->user_id)->where('coll_type',5)->delete();
  1340. if(in_array($type,[7])) ForumReply::where($del_where)->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
  1341. if(in_array($type,[7])){
  1342. $reply = Db::name('forum_reply')->where($del_where)->where('user_id',$this->user_id)->field('id,forum_id')->find();
  1343. $count = Db::name('forum_reply')->where($del_where)->where('user_id',$this->user_id)->count();
  1344. UserForum::where('id',$reply['forum_id'])->setDec('r_num',$count);
  1345. }
  1346. if(in_array($type,[8,9])) ForumReplyComment::where($del_where)->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
  1347. if(in_array($type,[10])){
  1348. UserForum::where($del_where)->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
  1349. \app\common\model\TopSearch::saveData($id,'forum');
  1350. UserForum::esAdd(input('id'));
  1351. }
  1352. if(in_array($type,[11])) UserMessage::where($del_where)->update(['is_deleted'=>1]);
  1353. $this->success('操作成功');
  1354. }
  1355. /**
  1356. * @title 消息已读&&未读变更
  1357. * @desc 消息已读
  1358. * @author qc
  1359. * @method POST
  1360. * @url /api/Forum/unreadChange
  1361. * @header name:Authorization require:1 desc:Token
  1362. * @param name:id type:string default:-- desc:记录id(不传改全部的)
  1363. * @param name:type type:int default:-- desc:1回答我的,2回复我的,3评论我的--问题,4评论我的--回答,5追番消息,6点赞我的--问题,7点赞我的--回答,8点赞我的--评论
  1364. * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
  1365. */
  1366. public function unreadChange()
  1367. {
  1368. $type = input('post.type');
  1369. $id = input('post.id');
  1370. $is_read = input('post.is_read');
  1371. switch ($type) {
  1372. case 1:
  1373. ForumReply::where(['issue_user'=>$this->user_id])->when($id,function ($query)use ($id){if ($id) return $query->where('id','in',$id);})->update(['is_read'=>$is_read]);
  1374. break;
  1375. case 2 :
  1376. $all_comment = ForumReplyComment::where(['user_id' => $this->user_id, 'is_deleted' => 0])->column('id');
  1377. ForumReplyComment::where([['t.pid','in',implode(',',$all_comment)]])->when($id ,function ($query)use ($id){
  1378. if($id) return $query->where('t.id','in',$id);})->alias('t')->update(['is_read'=>$is_read]);
  1379. break;
  1380. case 3:
  1381. ForumReplyComment::alias('c')->where(['r.user_id' => $this->user_id,'c.reply_id'=>'0'])
  1382. ->when($id ,function ($query)use ($id){
  1383. if($id) return $query->where('c.id','in',$id);})
  1384. ->leftJoin('UserForum r', 'c.forum_id = r.id')
  1385. ->update(['c.is_read'=>$is_read]);
  1386. break;
  1387. case 4:
  1388. ForumReplyComment::alias('c')->where('r.user_id' ,'=', $this->user_id)->where('reply_id','>',0)
  1389. ->when($id ,function ($query)use ($id){
  1390. if($id) return $query->where('c.id','in',$id);})
  1391. ->leftJoin('ForumReply r', 'c.reply_id = r.id')
  1392. ->update(['c.is_read'=>$is_read]);
  1393. break;
  1394. case 5:
  1395. $where[] = ['user_id','=',$this->user_id];
  1396. if($id) $where[] = ['id','in',$id];
  1397. UserMessage::where($where)->update(['is_read'=>input('post.is_read')]);
  1398. break;
  1399. case 6:
  1400. $ids = PlatformLike::where([['p.type', '=', 10],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p') ->leftJoin('UserForum f', 'f.id = p.like_id')
  1401. ->leftJoin('StoreMember u', 'u.id = p.user_id')->column('p.id');
  1402. PlatformLike::where('id','in' ,$ids )->update(['is_read'=>1]);
  1403. break;
  1404. case 7:
  1405. $ids = PlatformLike::where([['p.type', '=', 3],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('ForumReply f', 'f.id = p.like_id')
  1406. ->leftJoin('StoreMember u', 'u.id = p.user_id')->column('p.id');
  1407. PlatformLike::where('id','in' ,$ids )->update(['is_read'=>1]);
  1408. break;
  1409. case 8:
  1410. $ids = PlatformLike::where([['p.type', '=', 8],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
  1411. ->leftJoin('UserForum f', 'f.id = c.forum_id')
  1412. ->leftJoin('StoreMember u', 'u.id = p.user_id')->column('p.id');
  1413. PlatformLike::where('id','in' ,$ids )->update(['is_read'=>1]);
  1414. break;
  1415. }
  1416. $this->success('操作成功');
  1417. }
  1418. /**
  1419. * @title 浏览历史
  1420. * @desc 浏览历史
  1421. * @author qc
  1422. * @method GET
  1423. * @url /api/Forum/getForumTrack
  1424. * @header name:Authorization require:1 desc:Token
  1425. * @param name:title type:string default:-- desc:搜索内容
  1426. * @param name:page type:int default:0 desc:页数
  1427. * @param name:page_num type:int default:20 desc:每页数
  1428. * @return name:title type:string default:-- desc:问题标题
  1429. * @return name:level type:int default:-- desc:vip等级id
  1430. * @return name:content type:string default:0 desc:内容
  1431. * @return name:create_at type:string default:-- desc:时间
  1432. * @return name:label_name type:array default:-- desc:标签
  1433. * @return name:name type:string default:-- desc:发布用户
  1434. * @return name:headimg type:string default:-- desc:发布用户头像
  1435. * @return name:browse_num type:int default:-- desc:浏览量
  1436. * @return name:comment_num type:int default:-- desc:评论量
  1437. * @return name:reply_num type:int default:-- desc:回答量
  1438. * @return name:level type:int default:-- desc:VIP等级
  1439. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1440. */
  1441. public function getForumTrack()
  1442. {
  1443. $sel_where = [];
  1444. $sel_where[] = ['t.user_id','=',$this->user_id];
  1445. $sel_where[] = ['t.type','=',5];
  1446. $title = input('get.title');
  1447. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  1448. $list = UserTrack::where($sel_where)
  1449. ->alias('t')
  1450. ->field('t.id,t.update_int,i.level,i.label,i.content,t.first_id forum_id,m.name,m.headimg,i.title,i.browse_num,i.user_id,IFNULL( (SELECT count(r.id) FROM dd_forum_reply_comment as r WHERE t.first_id= r.forum_id AND r.is_deleted = 0 ),0 ) as comment_num')
  1451. ->leftJoin('UserForum i','t.first_id = i.id')
  1452. ->leftJoin('dd_store_member m','m.id = i.user_id')
  1453. ->order('update_int desc')
  1454. ->limit($this->off_set,$this->page_num)
  1455. ->select()->toArray();
  1456. array_walk($list,function (&$v){
  1457. if(!$v['name']) $v['name'] = APPNAME;
  1458. if(!$v['headimg']) $v['headimg'] = APPLOGO;
  1459. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  1460. $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
  1461. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1462. $v['reply_num'] = ForumReply::where(['forum_id' => $v['forum_id']])->where('is_deleted', 0)->count();
  1463. });
  1464. $total_num = UserTrack::where($sel_where)->alias('t')->leftJoin('UserForum i','t.first_id = i.id')->leftJoin('dd_store_member m','m.id = i.user_id')->count();
  1465. $this->success('ok',['list'=>$list ,'total_count' => $total_num, 'page_num' => $this->page_num]);
  1466. }
  1467. /**
  1468. * @title 我的点赞--问题
  1469. * @desc 我的点赞
  1470. * @author qc
  1471. * @method GET
  1472. * @url /api/Forum/getTagsForum
  1473. * @header name:Authorization require:1 desc:Token
  1474. * @param name:page type:int default:0 desc:页数
  1475. * @param name:page_num type:int default:20 desc:每页数
  1476. * @return name:title type:string default:-- desc:标题
  1477. * @return name:create_at type:string default:-- desc:时间
  1478. * @return name:level type:int default:-- desc:会员等级[0否]
  1479. * @return name:comment_num type:int default:-- desc:评论量
  1480. * @return name:like_num type:int default:-- desc:点赞量
  1481. * @return name:user_name type:string default:-- desc:昵称
  1482. * @return name:headimg type:string default:-- desc:头像
  1483. * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
  1484. * @return name:is_normal type:int default:-- desc:是否能正常跳转
  1485. * @return name:forum_id type:int default:-- desc:问题id
  1486. */
  1487. public function getTagsForum()
  1488. {
  1489. $list = PlatformLike::where([['l.user_id','=',$this->user_id],['l.type','=',10]])
  1490. ->field('l.*,b.title,b.id forum_id,u.name user_name,u.headimg,b.level,b.content')
  1491. ->alias('l')
  1492. ->leftJoin('UserForum b','l.like_id = b.id')
  1493. ->leftJoin('dd_store_member u','b.user_id = u.id')
  1494. ->limit($this->off_set,$this->page_num)
  1495. ->order('l.id desc')
  1496. ->select()->toArray();
  1497. array_walk($list,function (&$v){
  1498. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id, $v['forum_id'], 1);
  1499. if(!$v['user_name']) $v['user_name']= $this->user_info['name'];
  1500. if(!$v['headimg']) $v['headimg']= $this->user_info['headimg'];
  1501. $comment_num = ForumReplyComment::where(['is_deleted' => 0, 'forum_id' => $v['forum_id'],'reply_id'=>0])->count();
  1502. $v['comment_num'] = numTransform($comment_num);
  1503. $v['like_num'] = PlatformLike::getPraiseNum($v['forum_id'],10);
  1504. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1505. });
  1506. $total_num = PlatformLike::where([['user_id','=',$this->user_id],['type','=',10]])->count();
  1507. $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1508. }
  1509. /**
  1510. * @title 我的点赞--答案
  1511. * @desc 我的点赞
  1512. * @author qc
  1513. * @method GET
  1514. * @url /api/Forum/getTagsReply
  1515. * @header name:Authorization require:1 desc:Token
  1516. * @param name:page type:int default:0 desc:页数
  1517. * @param name:page_num type:int default:20 desc:每页数
  1518. * @return name:title type:string default:-- desc:标题
  1519. * @return name:create_at type:string default:-- desc:时间
  1520. * @return name:content type:string default:-- desc:答案内容
  1521. * @return name:comment_num type:int default:-- desc:评论量
  1522. * @return name:like_num type:int default:-- desc:点赞量
  1523. * @return name:user_name type:string default:-- desc:昵称
  1524. * @return name:headimg type:string default:-- desc:头像
  1525. * @return name:is_normal type:int default:-- desc:是否能正常跳转
  1526. * @return name:forum_normal type:int default:-- desc:问答状态【0下架或删除,1正常】
  1527. * @return name:reply_id type:int default:-- desc:答案id
  1528. * @return name:forum_id type:int default:-- desc:问题id
  1529. * @return name:level type:int default:-- desc:VIP等级
  1530. * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
  1531. */
  1532. public function getTagsReply()
  1533. {
  1534. $list = PlatformLike::where([['l.user_id','=',$this->user_id],['b.user_id','<>',$this->user_id],['l.type','=',3]])
  1535. ->field('l.*,b.id reply_id,u.name user_name,u.headimg,b.content,b.forum_id,m.level')
  1536. ->alias('l')
  1537. ->leftJoin('ForumReply b','l.like_id = b.id')
  1538. ->leftJoin('UserForum m','m.id = b.forum_id')
  1539. ->leftJoin('dd_store_member u','b.user_id = u.id')
  1540. ->limit($this->off_set,$this->page_num)
  1541. ->order('l.id desc')
  1542. ->select()->toArray();
  1543. array_walk($list,function (&$v){
  1544. $comment_num = ForumReplyComment::where(['is_deleted' => 0,'reply_id'=>$v['reply_id']])->count();
  1545. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id, $v['forum_id'], 1);
  1546. $v['comment_num'] = numTransform($comment_num);
  1547. $v['like_num'] = PlatformLike::getPraiseNum($v['like_id'],3);
  1548. $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
  1549. $v['forum_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, 'forum');
  1550. });
  1551. $total_num = PlatformLike::where([['user_id','=',$this->user_id],['type','=',3]])->count();
  1552. $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1553. }
  1554. /**
  1555. * @title 我的点赞--评论
  1556. * @desc 我的点赞
  1557. * @author qc
  1558. * @method GET
  1559. * @url /api/Forum/getTagsComment
  1560. * @header name:Authorization require:1 desc:Token
  1561. * @param name:page type:int default:0 desc:页数
  1562. * @param name:page_num type:int default:20 desc:每页数
  1563. * @return name:title type:string default:-- desc:标题
  1564. * @return name:create_at type:string default:-- desc:时间
  1565. * @return name:content type:string default:-- desc:评论内容
  1566. * @return name:comment_num type:int default:-- desc:评论量
  1567. * @return name:like_num type:int default:-- desc:点赞量
  1568. * @return name:user_name type:string default:-- desc:昵称
  1569. * @return name:headimg type:string default:-- desc:头像
  1570. * @return name:is_normal type:int default:-- desc:是否能正常跳转
  1571. * @return name:reply_id type:int default:-- desc:答案id[等于0是问题,大于0是答案]
  1572. * @return name:show_title type:string default:-- desc:展示的问题标题或答案内容
  1573. * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
  1574. *
  1575. */
  1576. public function getTagsComment()
  1577. {
  1578. $list = PlatformLike::where([['l.user_id','=',$this->user_id],['b.user_id','<>',$this->user_id],['l.type','=',8]])
  1579. ->field('l.*,b.id comment_id,u.name user_name,u.headimg,b.content,b.is_deleted,b.forum_id,b.reply_id')
  1580. ->alias('l')
  1581. ->leftJoin('ForumReplyComment b','l.like_id = b.id')
  1582. ->leftJoin('dd_store_member u','b.user_id = u.id')
  1583. ->order('l.id desc')
  1584. ->limit($this->off_set,$this->page_num)
  1585. ->select()->toArray();
  1586. array_walk($list,function (&$v){
  1587. $comment_num = ForumReplyComment::where(['is_deleted' => 0, 'forum_id'=>$v['forum_id'], 'reply_id'=>$v['reply_id']])->count();
  1588. $v['comment_num'] = numTransform($comment_num);
  1589. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id, $v['forum_id'], 1);
  1590. $v['like_num'] = PlatformLike::getPraiseNum($v['like_id'],8);
  1591. $v['level'] = UserForum::where('id',$v['forum_id'])->value('level');
  1592. if($v['reply_id']) {
  1593. $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
  1594. $v['show_title'] = ForumReply::where('id',$v['reply_id'])->value('content');
  1595. }else{
  1596. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1597. $v['show_title'] = UserForum::where('id',$v['forum_id'])->value('title');
  1598. }
  1599. });
  1600. $total_num = PlatformLike::where([['l.user_id','=',$this->user_id],['l.type','=',8]])->alias('l')
  1601. ->leftJoin('ForumReplyComment b','l.like_id = b.id')->count();
  1602. $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1603. }
  1604. /**
  1605. * @title 我的关注--问题
  1606. * @desc 我的关注
  1607. * @author qc
  1608. * @method GET
  1609. * @url /api/Forum/getCollectList
  1610. * @header name:Authorization require:1 desc:Token
  1611. * @param name:page type:int default:0 desc:页数
  1612. * @param name:page_num type:int default:20 desc:每页数
  1613. * @return name:title type:string default:-- desc:标题
  1614. * @return name:create_at type:string default:-- desc:时间
  1615. * @return name:reply_num type:int default:-- desc:回答量
  1616. * @return name:browse_num type:int default:-- desc:浏览量
  1617. * @return name:is_normal type:int default:-- desc:是否能正常跳转
  1618. * @return name:forum_id type:int default:-- desc:问题id
  1619. * @return name:level type:int default:-- desc:VIP等级
  1620. */
  1621. public function getCollectList()
  1622. {
  1623. $sel_where = [];
  1624. $sel_where[] = ['t.user_id','=',$this->user_id];
  1625. $sel_where[] = ['t.coll_type','=',5];
  1626. $list = UserCollect::where($sel_where)
  1627. ->alias('t')
  1628. ->field('t.id,t.create_at,t.coll_id forum_id ,i.level,i.title,i.browse_num,IFNULL( (SELECT count(r.id) FROM dd_forum_reply as r WHERE t.coll_id= r.forum_id AND r.is_deleted = 0 ),0 ) as comment_num')
  1629. ->leftJoin('UserForum i','t.coll_id = i.id')
  1630. ->order('t.id desc')
  1631. ->limit($this->off_set,$this->page_num)
  1632. ->select()->toArray();
  1633. array_walk($list,function (&$v){
  1634. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1635. $v['browse_num'] = numTransform($v['browse_num']);
  1636. $v['reply_num'] = ForumReply::where(['forum_id' => $v['forum_id']])->where('is_deleted', 0)->count();
  1637. });
  1638. $total_num = UserCollect::where($sel_where)
  1639. ->alias('t') ->leftJoin('UserForum i','t.coll_id = i.id')->count();
  1640. $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1641. }
  1642. /**
  1643. * @title 追番消息
  1644. * @desc 追番消息
  1645. * @author qc
  1646. * @method GET
  1647. * @url /api/Forum/getFollowUpMessage
  1648. * @header name:Authorization require:1 desc:Token
  1649. * @param name:title type:int default:-- desc:搜索内容
  1650. * @param name:page type:int default:-- desc:页数
  1651. * @param name:page_num type:int default:-- desc:每页数
  1652. *
  1653. * @return name:id type:int default:-- desc:记录id
  1654. * @return name:title type:string default:-- desc:标题
  1655. * @return name:content type:string default:-- desc:内容
  1656. * @return name:create_at type:string default:-- desc:时间
  1657. * @return name:relation_id type:int default:-- desc:答案id
  1658. * @return name:forum_id type:int default:-- desc:问题id
  1659. * @return name:is_read type:int default:-- desc:是否已读【0否1是】
  1660. * @return name:is_normal type:int default:-- desc:是否能正常跳转
  1661. */
  1662. public function getFollowUpMessage()
  1663. {
  1664. $title = input('title');
  1665. $list = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'m.module'=>'forum','m.type_id'=>6])
  1666. ->alias('m')
  1667. ->when($title,function ($query)use ($title){
  1668. if($title) $query->where('m.content','like','%'.$title.'%');})
  1669. ->field('m.id,m.create_at,m.is_read,m.content,m.relation_id,m.module,m.children_id')
  1670. ->limit($this->off_set,$this->page_num)
  1671. ->order(['m.id'=>'desc'])
  1672. ->select()->toArray();
  1673. array_walk($list,function (&$v){
  1674. $v['create_at'] = substr($v['create_at'],0,10);
  1675. $v['forum_id'] = ForumReply::where('id',$v['relation_id'])->value('forum_id');
  1676. $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
  1677. });
  1678. $total_num = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'m.module'=>'forum','m.type_id'=>6])->alias('m')->leftJoin('VideoIntro v','v.id= m.relation_id')->count();
  1679. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1680. }
  1681. }