Forum.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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\User;
  8. use app\common\model\UserCollect;
  9. use app\common\model\UserForum;
  10. use app\common\model\UserLevelRank;
  11. use app\common\model\UserMessage;
  12. use app\common\model\UserReport;
  13. use app\common\model\UserSearch;
  14. use app\common\model\UserTrack;
  15. use think\Db;
  16. use library\tools\Data;
  17. use vod\Request\V20170321\GetMediaAuditResultTimelineRequest;
  18. /**
  19. * @title 论坛
  20. * @controller Forum
  21. * @group base
  22. */
  23. class Forum extends Base
  24. {
  25. // 需要登录的
  26. protected $need_login = [];
  27. public function initialize(){
  28. parent::initialize();
  29. parent::checkLogin();
  30. if(!$this->user_id) parent::setUid();
  31. }
  32. /**
  33. * @title 获取论坛列表
  34. * @desc 获取论坛列表
  35. * @author qc
  36. * @method GET
  37. * @url /api/Forum/getForumList
  38. * @header name:Authorization require:1 desc:Token
  39. * @param name:is_tj type:int default:0 desc:是否推荐0否1是
  40. * @param name:title type:string default:-- desc:标题
  41. * @param name:page type:int default:0 desc:页数
  42. * @param name:page_num type:int default:20 desc:每页数
  43. * @param name:sort_type type:int default:1 desc:排序1默认2时间升序3时间降序
  44. * @return name:title type:string default:-- desc:标题
  45. * @return name:content type:string default:0 desc:内容
  46. * @return name:level type:int default:-- desc:vip等级id
  47. * @return name:label type:string default:-- desc:标签
  48. * @return name:name type:string default:-- desc:发布用户
  49. * @return name:headimg type:string default:-- desc:发布用户头像
  50. * @return name:browse_num type:int default:-- desc:浏览量
  51. * @return name:reply_num type:int default:-- desc:回答量
  52. * @return name:unread_num type:int default:-- desc:未读量
  53. */
  54. public function getForumList()
  55. {
  56. $sel_where = [];
  57. $title = input('get.title');
  58. $label = input('get.label');
  59. $is_tj = input('get.is_tj');
  60. $sort_type = input('get.sort_type',1);
  61. $sel_where[] = ['f.is_deleted','=',0];
  62. if($title) $sel_where[] = ['f.title|f.label','like','%'.$title.'%'];
  63. if($label) $sel_where[] = ['f.label','like','%'.$label.'%'];
  64. $app_name = sysconf('app_name');
  65. $app_logo = sysconf('app_logo');
  66. switch ($sort_type) {
  67. case 1:
  68. $order = ['sort'=>'desc','id'=>'desc'];
  69. break;
  70. case 2:
  71. $order = ['id'=>'asc','sort'=>'desc'];
  72. break;
  73. case 3:
  74. $order = ['id'=>'desc','sort'=>'desc'];
  75. break;
  76. }
  77. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,6);
  78. $user_level = UserLevelRank::getUserVip($this->user_id);
  79. $max_level = 0;
  80. if($user_level == 0){
  81. $where_str = ' f.level <= 1';
  82. $max_level = 1;
  83. }else{
  84. $where_str = ' f.level <= '.$user_level;
  85. $max_level = $user_level;
  86. }
  87. if($is_tj) {
  88. $search_log = UserSearch::getSearchTitle($this->user_id,6);
  89. $search_arr = [];
  90. foreach ($search_log as $t){
  91. $search_arr[] = " f.title like '".'%'.$t."%'" .' ';
  92. $search_arr[] = " f.label like '".'%'.$t."%'" .' ';
  93. }
  94. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  95. }
  96. if($is_tj){
  97. $search_log = UserSearch::getSearchTitle($this->user_id,6);
  98. $search_arr = [];
  99. $where_str = 'b.id > 0';
  100. foreach ($search_log as $t){
  101. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  102. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  103. }
  104. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  105. $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';
  106. $table = 'dd_user_forum';
  107. $order_by_two = 'id';
  108. $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 AND a.level <= $max_level ORDER BY is_recommend DESC , $order_by_two desc LIMIT {$this->off_set},{$this->page_num}";
  109. $list = Db::query($sql);
  110. array_walk($list,function (&$v,$k) {
  111. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  112. $reply_num = ForumReply::field('count(DISTINCT user_id) reply_num' )->where(['forum_id'=>$v['id']])->select()->toArray();
  113. $v['reply_num'] = array_sum(array_column($reply_num,'reply_num'));
  114. });
  115. }else{
  116. $list = UserForum::where($sel_where)
  117. ->alias('f')
  118. ->field('f.id,f.title,f.content,f.label,f.level,f.browse_num,f.sort,f.create_at,u.name,u.headimg, IFNULL( (SELECT count(DISTINCT r.user_id) FROM dd_forum_reply as r WHERE f.id=r.forum_id),0 ) as reply_num')
  119. ->leftJoin('store_member u','u.id = f.user_id')
  120. ->where($where_str)
  121. ->limit($this->off_set,$this->page_num)
  122. ->order($order)
  123. ->select()->toArray();
  124. array_walk($list,function (&$v,$k) use ($app_name,$app_logo){
  125. $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
  126. if(!$v['name']) $v['name'] = $app_name;
  127. if(!$v['headimg']) $v['headimg'] = $app_logo;
  128. });
  129. }
  130. $num = UserForum::where('is_read',0)->count();
  131. if(!empty($list)) {
  132. $ids_arr = array_column($list,'id');
  133. UserForum::where('id','in',implode(',',$ids_arr))->where('is_read',0)->update(['is_read'=>1]);
  134. UserForum::where('id','in',implode(',',$ids_arr))->setInc('browse_num');
  135. }
  136. $this->success('ok',['list'=>$list,'unread_num'=>$num]);
  137. }
  138. /**
  139. * @title 获取论坛未读数量
  140. * @desc 获取论坛未读数量
  141. * @author qc
  142. * @method GET
  143. * @url /api/Forum/getUnreadNum
  144. * @header name:Authorization require:1 desc:Token
  145. * @return name:unread_num type:int default:-- desc:未读量
  146. */
  147. public function getUnreadNum()
  148. {
  149. $num = UserForum::where('is_read',0)->where('is_deleted',0)->count();
  150. $this->success('ok',['unread_num'=>$num]);
  151. }
  152. /**
  153. * @title 获取论坛详情
  154. * @desc 获取论坛详情
  155. * @author qc
  156. * @method GET
  157. * @url /api/Forum/getForumInfo
  158. * @header name:Authorization require:1 desc:Token
  159. * @param name:id type:string default:-- desc:论坛记录id
  160. * @return name:title type:string default:-- desc:标题
  161. * @return name:content type:string default:0 desc:内容
  162. * @return name:level type:int default:-- desc:vip等级id
  163. * @return name:label type:string default:-- desc:标签
  164. * @return name:label_name type:array default:-- desc:标签
  165. * @return name:name type:string default:-- desc:发布用户
  166. * @return name:headimg type:string default:-- desc:发布用户头像
  167. * @return name:browse_num type:int default:-- desc:浏览量
  168. * @return name:is_collect type:int default:-- desc:是否关注【0否1是】
  169. * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
  170. * @return name:comment_num type:int default:-- desc:评论数量
  171. * @return name:replay_num type:int default:-- desc:回复数量
  172. */
  173. public function getForumInfo(){
  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,f.content,f.label,f.level,f.browse_num,is_read,f.create_at,u.name,u.headimg,IFNULL( (SELECT count(DISTINCT r.user_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']) $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,5,$detail['id']);
  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. UserForum::where('id',$id)->setInc('browse_num');// 增加浏览量
  194. if(!$detail['is_read'])UserForum::where('id',$detail['id'])->update(['is_read'=>1]);
  195. UserTrack::crateTrack($this->user_id,5,input('get.id'),0);
  196. $this->success('ok',['detail'=>$detail]);
  197. }
  198. /**
  199. * @title 关注||取消关注
  200. * @desc 关注||取消关注
  201. * @author qc
  202. * @method POST
  203. * @url /api/Forum/forumCollect
  204. * @header name:Authorization require:1 desc:Token
  205. * @param name:id type:int require:1 default:-- desc:论坛id
  206. * @param name:status type:int default:0 desc:收藏状态(0取消关注【未关注】,1关注)
  207. */
  208. public function forumCollect()
  209. {
  210. $coll_status = UserCollect::plateCollect($this->user_id,5,input('post.id',0),0);
  211. $coll_status ? $this->success('关注成功',['status'=>1]) : $this->success('取消关注成功',['status'=>0]);
  212. }
  213. /**
  214. * @title 开启||关闭通知开关
  215. * @desc 开启||关闭通知开关
  216. * @author qc
  217. * @method POST
  218. * @url /api/Forum/forumSwitch
  219. * @header name:Authorization require:1 desc:Token
  220. * @param name:id type:int require:1 default:-- desc:论坛id
  221. */
  222. public function forumSwitch()
  223. {
  224. $switch_status = PlatformSwitch::userSwitch($this->user_id,5,input('post.id',0));
  225. $switch_status ? $this->success('开启成功',['status'=>1]) : $this->success('关闭成功',['status'=>0]);
  226. }
  227. /**
  228. * @title 论坛回复
  229. * @desc 论坛回复
  230. * @author qc
  231. * @method POST
  232. * @url /api/Forum/replyForum
  233. * @header name:Authorization require:1 desc:Token
  234. * @param name:id type:int default:-- desc:论坛id
  235. * @param name:content type:string default:-- desc:内容
  236. * @return name:name type:string default:-- desc:会员名称
  237. * @return name:headimg type:string default:-- desc:会员头像
  238. * @return name:content type:string default:-- desc:内容
  239. */
  240. public function replyForum()
  241. {
  242. $id = input('post.id');
  243. $content = input('post.content');
  244. if(!$content) $this->error('请上传内容');
  245. $issue_user = UserForum::where('id',$id)->value('user_id');
  246. $res = ForumReply::create(['user_id'=>$this->user_id,'content'=>$content,'issue_user'=>$issue_user,'forum_id'=>$id]);
  247. $detail = ForumReply::where('c.id',$res->id)
  248. ->alias('c')
  249. ->field('c.id,c.content,c.create_at,u.name,u.headimg')
  250. ->leftJoin('store_member u','u.id = c.user_id')
  251. ->find()->toArray();
  252. $user_info = $this->userInfo('name');
  253. UserMessage:: sendUserMessage($issue_user,'forum',5,0,$this->user_id,$id,$user_info['name'].'回复了您的提问');
  254. $this->success('回复成功',['detail'=>$detail]);
  255. }
  256. /**
  257. * @title 论坛回复列表
  258. * @desc 论坛回复列表
  259. * @author qc
  260. * @method GET
  261. * @url /api/Forum/getReplyList
  262. * @header name:Authorization require:1 desc:Token
  263. * @param name:forum_id type:int default:0 desc:论坛记录id
  264. * @param name:page type:int default:0 desc:页数
  265. * @param name:page_num type:int default:20 desc:每页数
  266. * @return name:id type:int default:-- desc:论坛回复id
  267. * @return name:content type:string default:-- desc:内容
  268. * @return name:name type:string default:-- desc:会员
  269. * @return name:headimg type:string default:-- desc:会员头像
  270. * @return name:like_num type:int default:-- desc:点赞数量
  271. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  272. * @return name:children type:array default:-- desc:评论列表【所有的都查了】
  273. * @return name:children.content type:string default:-- desc:评论内容
  274. * @return name:children.create_at type:string default:-- desc:评论时间
  275. * @return name:children.name type:string default:-- desc:会员
  276. * @return name:children.headimg type:string default:-- desc:会员头像
  277. * @return name:children.like_num type:int default:-- desc:点赞数量
  278. * @return name:children.is_like type:int default:-- desc:是否点赞(0否1是)
  279. * @return name:children.children_num type:int default:-- desc:评论数量
  280. * @return name:total_num type:int default: desc:总数
  281. */
  282. public function getReplyList()
  283. {
  284. $where = [];
  285. $where[] = ['r.forum_id','=',input('get.forum_id')];
  286. $where[] = ['r.is_deleted','=',0];
  287. $list = ForumReply::where($where)
  288. ->alias('r')
  289. ->field('r.id,r.content,r.create_at,u.name,u.headimg')
  290. ->leftJoin('store_member u','r.user_id = u.id')
  291. ->limit($this->off_set,$this->page_num)
  292. ->order('r.id desc')
  293. ->select()->toArray();
  294. $total_num = ForumReply::where($where)->alias('r')->count();
  295. array_walk($list,function (&$val,$k){
  296. $val['like_num'] = PlatformLike::getPraiseNum($val['id'],3);
  297. $val['is_like'] = PlatformLike::checkTags($this->user_id,$val['id'],3);
  298. $children = ForumReplyComment::where(['c.reply_id'=>$val['id'],'c.is_deleted'=>0])
  299. ->alias('c')
  300. ->field('c.id,c.create_at,c.content,u.name,u.headimg')
  301. ->leftJoin('store_member u','u.id = c.user_id')
  302. ->order('c.id desc')
  303. ->select()->toArray();
  304. foreach ($children as &$c) {
  305. $c['like_num'] = PlatformLike::getPraiseNum($c['id'], 8);
  306. $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
  307. }
  308. $val['children'] = $children ? $children : null;
  309. $val['children_num'] = count($children);
  310. });
  311. $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
  312. }
  313. /**
  314. * @title 论坛回复的评论列表
  315. * @desc 论坛回复的评论列表
  316. * @author qc
  317. * @method GET
  318. * @url /api/Forum/getReplyCommentList
  319. * @header name:Authorization require:1 desc:Token
  320. * @param name:reply_id type:int default:0 desc:论坛回复记录id
  321. * @param name:page type:int default:0 desc:页数
  322. * @param name:page_num type:int default:20 desc:每页数
  323. * @return name:content type:string default:-- desc:评论内容
  324. * @return name:create_at type:string default:-- desc:评论时间
  325. * @return name:name type:string default:-- desc:会员
  326. * @return name:headimg type:string default:-- desc:会员头像
  327. * @return name:like_num type:int default:-- desc:点赞数量
  328. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  329. * @return name:total_num type:int default: desc:总数
  330. */
  331. public function getReplyCommentList()
  332. {
  333. $reply_id = input('reply_id');
  334. $list = ForumReplyComment::where(['c.reply_id'=>$reply_id,'c.is_deleted'=>0])
  335. ->alias('c')
  336. ->field('c.id,c.create_at,c.content,u.name,u.headimg')
  337. ->leftJoin('store_member u','u.id = c.user_id')
  338. ->order('c.id desc')
  339. ->select()->toArray();
  340. foreach ($list as &$c){
  341. $c['like_num'] = PlatformLike::getPraiseNum($c['id'], 8);
  342. $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
  343. }
  344. $total_num = ForumReplyComment::where(['c.reply_id'=>$reply_id,'c.is_deleted'=>0])->alias('c')->count();
  345. $this->success('ok',compact(['list','total_num']));
  346. }
  347. /**
  348. * @title 论坛二级评论
  349. * @desc 论坛二级评论
  350. * @author qc
  351. * @method POST
  352. * @url /api/Forum/forumSecondComment
  353. * @header name:Authorization require:1 desc:Token
  354. * @param name:id type:int default:1 desc:评论id
  355. * @param name:content type:string default:-- desc:内容
  356. * @return name:name type:string default:-- desc:会员名称
  357. * @return name:headimg type:string default:-- desc:会员头像
  358. * @return name:content type:string default:-- desc:内容
  359. */
  360. public function forumSecondComment()
  361. {
  362. $comment = ForumReplyComment::where('id',input('post.id'))->find()->toArray();
  363. $user_info = $this->userInfo('name');
  364. UserMessage:: sendUserMessage($comment['user_id'],'forum',4,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
  365. unset($comment['id']);
  366. unset($comment['create_at']);
  367. $comment['pid'] = input('post.id');
  368. $comment['user_id'] = $this->user_id;
  369. $comment['content'] = input('post.content');
  370. $comment['lev']++;
  371. if(!$comment['source_id']) $comment['source_id'] = input('post.id');
  372. $res = ForumReplyComment::create($comment);
  373. $detail = ForumReplyComment::where('p.id',$res->id)
  374. ->alias('p')
  375. ->field('p.id,p.content,p.create_at,u.name,u.headimg')
  376. ->leftJoin('store_member u','u.id = p.user_id')
  377. ->find()->toArray();
  378. $this->success('评论成功',['detail'=>$detail]);
  379. }
  380. /**
  381. * @title 论坛回复点赞||取消点赞
  382. * @desc 论坛回复点赞||取消点赞
  383. * @author qc
  384. * @method POST
  385. * @url /api/Forum/forumTags
  386. * @header name:Authorization require:1 desc:Token
  387. * @param name:like_id type:int default:1 desc:论坛回复的id
  388. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  389. */
  390. public function forumTags()
  391. {
  392. $ret_val= PlatformLike::userTags($this->user_id,input('post.like_id'),3);
  393. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  394. }
  395. /**
  396. * @title 对论坛回复的评论进行点赞||取消点赞
  397. * @desc 论坛回复的评论点赞||取消点赞
  398. * @author qc
  399. * @method POST
  400. * @url /api/Forum/forumCommentTags
  401. * @header name:Authorization require:1 desc:Token
  402. * @param name:like_id type:int default:1 desc:论坛回复的评论id
  403. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  404. */
  405. public function forumCommentTags()
  406. {
  407. $ret_val= PlatformLike::userTags($this->user_id,input('post.like_id'),8);
  408. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  409. }
  410. /**
  411. * @title 对论坛回复进行评论
  412. * @desc 对论坛回复进行评论
  413. * @author qc
  414. * @method POST
  415. * @url /api/Forum/commentReply
  416. * @header name:Authorization require:1 desc:Token
  417. * @param name:reply_id type:int default:-- desc:回复的id
  418. * @param name:content type:string default:-- desc:内容
  419. * @return name:name type:string default:-- desc:会员名称
  420. * @return name:headimg type:string default:-- desc:会员头像
  421. * @return name:content type:string default:-- desc:内容
  422. * @return name:create_at type:string default:-- desc:时间
  423. */
  424. public function commentReply()
  425. {
  426. $reply_id = input('post.reply_id');
  427. $content = input('post.content');
  428. if(!$content) $this->error('请输入评论内容');
  429. $reply_info = ForumReply::where('id',$reply_id)->find()->toArray();
  430. //if($reply_info['user_id'] == $this->user_id) $this->error('无法评论自己的回答');
  431. $user_info = $this->userInfo('name,headimg');
  432. UserMessage:: sendUserMessage($reply_info['user_id'],'forum',3,0,$this->user_id,$reply_id,$user_info['name'].'评论了您的回复');
  433. $res = ForumReplyComment::create(['user_id'=>$this->user_id,'content'=>$content,'forum_id'=>$reply_info['forum_id'],'reply_id'=>$reply_id]);
  434. $detail = ForumReplyComment::where('c.id',$res->id)
  435. ->alias('c')
  436. ->field('c.id,c.content,c.create_at,u.name,u.headimg')
  437. ->leftJoin('store_member u','u.id = c.user_id')
  438. ->find()->toArray();
  439. $this->success('评论成功',['detail'=>$detail]);
  440. }
  441. /**
  442. * @title 用户发布论坛
  443. * @desc 用户发布论坛
  444. * @author qc
  445. * @method POST
  446. * @url /api/Forum/userReferForum
  447. * @header name:Authorization require:1 desc:Token
  448. * @param name:title type:string default:-- desc:标题
  449. * @param name:content type:string default:-- desc:内容
  450. * @param name:label type:string default:-- desc:论坛标签(多个用逗号隔开)
  451. * @param name:images type:string default:-- desc:(多个用|隔开)
  452. */
  453. public function userReferForum()
  454. {
  455. $title = input('post.title');
  456. $content = input('post.content');
  457. $label = input('post.label');
  458. $images = input('post.images');
  459. if(!$title || !$content || !$label) $this->error('参数错误');
  460. $data = [
  461. 'title' => $title,
  462. 'user_id' => $this->user_id,
  463. 'content' => $content,
  464. 'label' => $label,
  465. 'images' => $images,
  466. 'level' => UserLevelRank::getUserVip($this->user_id),
  467. ];
  468. $res = UserForum::create($data);
  469. UserMessage::sendUserMessage($this->user_id,'forum',1,0,0,$res->id);
  470. $this->success('发布成功');
  471. }
  472. /**
  473. * @title 用户删除论坛记录
  474. * @desc 用户删除论坛记录
  475. * @author qc
  476. * @method POST
  477. * @url /api/Forum/delForum
  478. * @header name:Authorization require:1 desc:Token
  479. * @param name:id type:int default:-- desc:id
  480. */
  481. public function delForum(){
  482. UserForum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
  483. $this->success('删除成功');
  484. }
  485. /**
  486. * @title 我的提问
  487. * @desc 我的提问
  488. * @author qc
  489. * @method GET
  490. * @url /api/Forum/getUserForumList
  491. * @header name:Authorization require:1 desc:Token
  492. * @param name:title type:string default:-- desc:标题
  493. * @param name:page type:int default:-- desc:页数
  494. * @param name:page_num type:int default:-- desc:每页数量
  495. * @return name:title type:string default:-- desc:标题
  496. * @return name:content type:string default:0 desc:内容
  497. * @return name:level type:int default:-- desc:vip等级id
  498. * @return name:label type:string default:-- desc:标签
  499. * @return name:name type:string default:-- desc:发布用户
  500. * @return name:headimg type:string default:-- desc:发布用户头像
  501. * @return name:browse_num type:int default:-- desc:浏览量
  502. * @return name:reply_num type:int default:-- desc:回答量
  503. */
  504. public function getUserForumList()
  505. {
  506. $sel_where = [];
  507. $sel_where[] = ['f.is_deleted','=',0];
  508. $sel_where[] = ['f.user_id','=',$this->user_id];
  509. if($title = input('get.title')) $sel_where[] = ['f.title|f.label','like','%'.$title.'%'];
  510. $list = UserForum::where($sel_where)
  511. ->alias('f')
  512. ->field('f.id,f.title,f.content,f.level,f.browse_num,f.create_at,u.name,u.headimg, IFNULL( (SELECT count(DISTINCT r.user_id) FROM dd_forum_reply as r WHERE f.id=r.forum_id ),0 ) as reply_num')
  513. ->leftJoin('store_member u','u.id = f.user_id')
  514. ->limit($this->off_set,$this->page_num)
  515. ->order( 'id desc' )
  516. ->select()->toArray();
  517. $this->success('ok',['list'=>$list,'user_info'=>$this->userInfo(['name','headimg'])]);
  518. }
  519. /**
  520. * @title 我的回答【列表】--论坛问题
  521. * @desc 我的回答【列表】
  522. * @author qc
  523. * @method GET
  524. * @url /api/Forum/myReplyList
  525. * @header name:Authorization require:1 desc:Token
  526. * @param name:title type:string default:-- desc:关键字
  527. * @param name:page type:int default:-- desc:页数
  528. * @param name:page_num type:int default:-- desc:每页数量
  529. * @return name:title type:string default:-- desc:标题[论坛]
  530. * @return name:content type:string default:0 desc:内容
  531. * @return name:name type:string default:-- desc:用户
  532. * @return name:headimg type:string default:-- desc:用户头像
  533. * @return name:create_at type:string default:-- desc:时间
  534. */
  535. public function myReplyList()
  536. {
  537. $where = [];
  538. $where[] = ['r.user_id','=',$this->user_id];
  539. $where[] = ['r.is_deleted','=',0];
  540. if($title = input('title'))$where[] = ['r.content','like','%'.$title.'%'];
  541. $list = ForumReply::where($where)
  542. ->alias('r')
  543. ->field('r.id,r.content,r.create_at,f.title,u.name ,u.headimg')
  544. ->leftJoin('user_forum f','r.forum_id = f.id')
  545. ->leftJoin('store_member u','r.user_id = u.id')
  546. ->limit($this->off_set,$this->page_num)
  547. ->order('r.id desc')
  548. ->select()->toArray();
  549. $total_num = ForumReply::where($where)->alias('r')->count();
  550. $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
  551. }
  552. /**
  553. * @title 我的评论
  554. * @desc 我的评论
  555. * @author qc
  556. * @method GET
  557. * @url /api/Forum/myDiscuss
  558. * @header name:Authorization require:1 desc:Token
  559. * @param name:title type:string default:-- desc:关键字
  560. * @param name:page type:int default:-- desc:页数
  561. * @param name:page_num type:int default:-- desc:每页数量
  562. * @return name:create_at type:string default:-- desc:时间
  563. * @return name:title type:string default:-- desc:论坛标题
  564. * @return name:content type:string default:0 desc:评论内容
  565. * @return name:reply_content type:string default:0 desc:回复内容
  566. * @return name:name type:string default:-- desc:回复的用户
  567. * @return name:headimg type:string default:-- desc:回复的头像
  568. */
  569. public function myDiscuss()
  570. {
  571. $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content')->alias('c')
  572. ->where(['c.user_id'=>$this->user_id,'c.is_deleted'=>0])
  573. ->leftJoin('forum_reply r','c.reply_id = r.id')
  574. ->leftJoin('store_member m','m.id = r.user_id')
  575. ->leftJoin('user_forum f','f.id = c.forum_id')
  576. ->order('c.id desc')
  577. ->limit($this->off_set,$this->page_num)
  578. ->select()->toArray();
  579. $this->success('ok',['list'=>$list]);
  580. }
  581. /**
  582. * @title 回答我的
  583. * @desc 回答我的
  584. * @author qc
  585. * @method GET
  586. * @url /api/Forum/replyToMyForum
  587. * @header name:Authorization require:1 desc:Token
  588. * @param name:title type:string default:-- desc:关键字
  589. * @param name:page type:int default:-- desc:页数
  590. * @param name:page_num type:int default:-- desc:每页数量
  591. * @return name:title type:string default:-- desc:标题[论坛]
  592. * @return name:content type:string default:0 desc:内容
  593. * @return name:name type:string default:-- desc:用户
  594. * @return name:headimg type:string default:-- desc:用户头像
  595. * @return name:create_at type:string default:-- desc:时间
  596. */
  597. public function replyToMyForum()
  598. {
  599. $where = [];
  600. $where[] = ['r.issue_user','=',$this->user_id];
  601. $where[] = ['r.is_deleted','=',0];
  602. if($title = input('title'))$where[] = ['r.content','like','%'.$title.'%'];
  603. $list = ForumReply::where($where)
  604. ->alias('r')
  605. ->field('r.id,r.content,r.create_at,f.title,u.name ,u.headimg')
  606. ->leftJoin('user_forum f','r.forum_id = f.id')
  607. ->leftJoin('store_member u','r.user_id = u.id')
  608. ->limit($this->off_set,$this->page_num)
  609. ->order('r.id desc')
  610. ->select()->toArray();
  611. $total_num = ForumReply::where($where)->alias('r')->count();
  612. $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
  613. }
  614. /**
  615. * @title 评论我的
  616. * @desc 评论我的
  617. * @author qc
  618. * @method GET
  619. * @url /api/Forum/commentOnMyReply
  620. * @header name:Authorization require:1 desc:Token
  621. * @param name:title type:string default:-- desc:关键字
  622. * @param name:page type:int default:-- desc:页数
  623. * @param name:page_num type:int default:-- desc:每页数量
  624. * @return name:create_at type:string default:-- desc:时间
  625. * @return name:title type:string default:-- desc:论坛标题
  626. * @return name:content type:string default:0 desc:评论内容
  627. * @return name:reply_content type:string default:0 desc:回复内容
  628. * @return name:name type:string default:-- desc:评论用户
  629. * @return name:headimg type:string default:-- desc:评论用户头像
  630. */
  631. public function commentOnMyReply()
  632. {
  633. $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content')->alias('c')
  634. ->where(['r.user_id'=>$this->user_id,'r.is_deleted'=>0])
  635. ->leftJoin('forum_reply r','c.reply_id = r.id')
  636. ->leftJoin('store_member m','m.id = c.user_id')
  637. ->leftJoin('user_forum f','f.id = c.forum_id')
  638. ->order('c.id desc')
  639. ->limit($this->off_set,$this->page_num)
  640. ->select()->toArray();
  641. $this->success('ok',['list'=>$list]);
  642. }
  643. /**
  644. * @title 用户举报
  645. * @desc 用户举报
  646. * @author qc
  647. * @url /api/Forum/forumReport
  648. * @method POST
  649. * @header name:Authorization require:1 desc:Token
  650. * @param name:report_id type:int default:-- desc:举报内容的id
  651. * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
  652. */
  653. public function forumReport()
  654. {
  655. $report_id= input('post.report_id');
  656. $case_ids= input('post.case_ids');
  657. if(!$report_id) $this->error('请现在举报内容');
  658. if(!$case_ids) $this->error('请选择举报原因');
  659. UserReport::report($this->user_id,6,$report_id,$case_ids);
  660. $this->success('举报成功');
  661. }
  662. /**
  663. * @title 转发(转发数量统计)
  664. * @desc 转发成功后调用
  665. * @author qc
  666. * @method POST
  667. * @url /api/Forum/forumTransmit
  668. * @header name:Authorization require:1 desc:Token
  669. * @param name:forum_id type:int default:-- desc:论坛问题id
  670. */
  671. public function forumTransmit()
  672. {
  673. $forum_id = input('post.forum_id');
  674. UserForum::where('id',$forum_id)->setInc('transmit_num');
  675. $this->success('转发成功');
  676. }
  677. /**
  678. * @title 回复我的【回复我的--回复过我的评论】
  679. * @desc 回复我的
  680. * @author qc
  681. * @method GET
  682. * @url /api/Forum/getReplyComment
  683. * @header name:Authorization require:1 desc:Token
  684. * @param name:title type:string default:-- desc:标题
  685. * @param name:page type:int default:0 desc:页数
  686. * @param name:page_num type:int default:20 desc:每页数
  687. * @return name:title type:string default:-- desc:标题
  688. *
  689. * @return name:title type:string default:-- desc:论坛标题
  690. * @return name:create_at type:string default:-- desc:时间
  691. * @return name:user_name type:string default:-- desc:用户名【其他会员】
  692. * @return name:headimg type:string default:-- desc:用户头像【其他会员】
  693. * @return name:content type:string default:-- desc:回复内容
  694. * @return name:parent_comment type:array default:-- desc:你的评论内容
  695. * @return name:parent_comment.content type:string default:-- desc:内容
  696. * @return name:parent_comment.name type:string default:-- desc:你的会员名称
  697. * @return name:parent_comment.headimg type:string default:-- desc:你的头像
  698. * @return name:parent_comment.title type:string default:-- desc:论坛标题
  699. * @return name:parent_comment.forum_id type:string default:-- desc:论坛id
  700. */
  701. public function getReplyComment()
  702. {
  703. // 所有我评论的回答
  704. $all_comment = ForumReplyComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  705. if(empty($all_comment)) $this->success('ok',['list'=>null]);
  706. $sel_where = [];
  707. $title = input('get.title');
  708. if($title) $sel_where[] = ['i.title','like','%'.$title.'%'];
  709. $sel_where[] = ['t.is_deleted','=',0];
  710. $sel_where[] = ['t.lev','>=',2];
  711. $sel_where[] = ['t.user_id','<>',$this->user_id];
  712. $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
  713. $list = ForumReplyComment::where($sel_where)
  714. ->alias('t')
  715. ->field('t.id,t.create_at,t.content,t.pid,forum_id,u.name user_name,u.headimg,i.title')
  716. ->leftJoin('store_member u','t.user_id = u.id')
  717. ->leftJoin('UserForum i','t.forum_id = i.id')
  718. ->order('t.id desc')
  719. ->limit($this->off_set,$this->page_num)
  720. ->select()->toArray();
  721. foreach ($list as &$v) {
  722. $parent_comment = ForumReplyComment::where([['t.id','=',$v['pid']]])
  723. ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg')
  724. ->alias('t')
  725. ->leftJoin('UserForum i','t.forum_id = i.id')
  726. ->leftJoin('store_member u','t.user_id = u.id')
  727. ->find()->toArray();
  728. $v['parent_comment'] = $parent_comment;
  729. }
  730. $this->success('ok',['list'=>$list]);
  731. }
  732. /**
  733. * @title 我的回复【我的回复--我回复过的评论】
  734. * @desc 我的回复
  735. * @author qc
  736. * @method GET
  737. * @url /api/Forum/getReplyForum
  738. * @header name:Authorization require:1 desc:Token
  739. * @param name:title type:string default:-- desc:标题
  740. * @param name:page type:int default:0 desc:页数
  741. * @param name:page_num type:int default:20 desc:每页数
  742. * @return name:title type:string default:-- desc:论坛标题
  743. * @return name:create_at type:string default:-- desc:时间
  744. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  745. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  746. * @return name:content type:string default:-- desc:回复内容
  747. * @return name:parent_comment type:array default:-- desc:上级评论内容【你回复的那个】
  748. * @return name:parent_comment.content type:string default:-- desc:内容
  749. * @return name:parent_comment.name type:string default:-- desc:会员名称【别人的】
  750. * @return name:parent_comment.headimg type:string default:-- desc:会员头像【别人的】
  751. * @return name:parent_comment.title type:string default:-- desc:论坛标题
  752. * @return name:parent_comment.forum_id type:string default:-- desc:论坛id
  753. */
  754. public function getReplyForum()
  755. {
  756. $user_info = $this->userInfo();
  757. $sel_where = [];
  758. $title = input('get.title');
  759. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  760. $sel_where[] = ['t.user_id','=',$this->user_id];
  761. $sel_where[] = ['t.is_deleted','=',0];
  762. $sel_where[] = ['t.lev','>=',2];
  763. $list = ForumReplyComment::where($sel_where)
  764. ->alias('t')
  765. ->field('t.id,t.create_at,t.content,t.pid,forum_id,i.title')
  766. ->leftJoin('UserForum i','t.forum_id = i.id')
  767. ->order('t.id desc')
  768. ->limit($this->off_set,$this->page_num)
  769. ->select()->toArray();
  770. foreach ($list as &$v) {
  771. $v['user_name'] = $user_info['name'];
  772. $v['headimg'] = $user_info['headimg'];
  773. $parent_comment = ForumReplyComment::where([['t.id','=',$v['pid']]])
  774. ->field('t.id,t.create_at,t.content,t.pid,forum_id,u.name,u.headimg,i.title')
  775. ->alias('t')
  776. ->leftJoin('UserForum i','t.forum_id = i.id')
  777. ->leftJoin('store_member u','t.user_id = u.id')
  778. ->find()->toArray();
  779. $v['parent_comment'] = $parent_comment;
  780. }
  781. $this->success('ok',['list'=>$list]);
  782. }
  783. }