Forum.php 89 KB

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