123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831 |
- <?php
- namespace app\api\controller;
- use app\common\model\ForumReply;
- use app\common\model\ForumReplyComment;
- use app\common\model\PlatformLike;
- use app\common\model\PlatformSwitch;
- use app\common\model\User;
- use app\common\model\UserCollect;
- use app\common\model\UserForum;
- use app\common\model\UserLevelRank;
- use app\common\model\UserMessage;
- use app\common\model\UserReport;
- use app\common\model\UserSearch;
- use app\common\model\UserTrack;
- use think\Db;
- use library\tools\Data;
- use vod\Request\V20170321\GetMediaAuditResultTimelineRequest;
- /**
- * @title 论坛
- * @controller Forum
- * @group base
- */
- class Forum extends Base
- {
- // 需要登录的
- protected $need_login = [];
- public function initialize(){
- parent::initialize();
- parent::checkLogin();
- if(!$this->user_id) parent::setUid();
- }
- /**
- * @title 获取论坛列表
- * @desc 获取论坛列表
- * @author qc
- * @method GET
- * @url /api/Forum/getForumList
- * @header name:Authorization require:1 desc:Token
- * @param name:is_tj type:int default:0 desc:是否推荐0否1是
- * @param name:title type:string default:-- desc:标题
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @param name:sort_type type:int default:1 desc:排序1默认2时间升序3时间降序
- * @return name:title type:string default:-- desc:标题
- * @return name:content type:string default:0 desc:内容
- * @return name:level type:int default:-- desc:vip等级id
- * @return name:label type:string default:-- desc:标签
- * @return name:name type:string default:-- desc:发布用户
- * @return name:headimg type:string default:-- desc:发布用户头像
- * @return name:browse_num type:int default:-- desc:浏览量
- * @return name:reply_num type:int default:-- desc:回答量
- * @return name:unread_num type:int default:-- desc:未读量
- */
- public function getForumList()
- {
- $sel_where = [];
- $title = input('get.title');
- $label = input('get.label');
- $is_tj = input('get.is_tj');
- $sort_type = input('get.sort_type',1);
- $sel_where[] = ['f.is_deleted','=',0];
- if($title) $sel_where[] = ['f.title|f.label','like','%'.$title.'%'];
- if($label) $sel_where[] = ['f.label','like','%'.$label.'%'];
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- switch ($sort_type) {
- case 1:
- $order = ['sort'=>'desc','id'=>'desc'];
- break;
- case 2:
- $order = ['id'=>'asc','sort'=>'desc'];
- break;
- case 3:
- $order = ['id'=>'desc','sort'=>'desc'];
- break;
- }
- if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,6);
- $user_level = UserLevelRank::getUserVip($this->user_id);
- $max_level = 0;
- if($user_level == 0){
- $where_str = ' f.level <= 1';
- $max_level = 1;
- }else{
- $where_str = ' f.level <= '.$user_level;
- $max_level = $user_level;
- }
- if($is_tj) {
- $search_log = UserSearch::getSearchTitle($this->user_id,6);
- $search_arr = [];
- foreach ($search_log as $t){
- $search_arr[] = " f.title like '".'%'.$t."%'" .' ';
- $search_arr[] = " f.label like '".'%'.$t."%'" .' ';
- }
- if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
- }
- if($is_tj){
- $search_log = UserSearch::getSearchTitle($this->user_id,6);
- $search_arr = [];
- $where_str = 'b.id > 0';
- foreach ($search_log as $t){
- $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
- $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
- }
- if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
- $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';
- $table = 'dd_user_forum';
- $order_by_two = 'id';
- $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}";
- $list = Db::query($sql);
- array_walk($list,function (&$v,$k) {
- $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
- $reply_num = ForumReply::field('count(DISTINCT user_id) reply_num' )->where(['forum_id'=>$v['id']])->select()->toArray();
- $v['reply_num'] = array_sum(array_column($reply_num,'reply_num'));
- });
- }else{
- $list = UserForum::where($sel_where)
- ->alias('f')
- ->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')
- ->leftJoin('store_member u','u.id = f.user_id')
- ->where($where_str)
- ->limit($this->off_set,$this->page_num)
- ->order($order)
- ->select()->toArray();
- array_walk($list,function (&$v,$k) use ($app_name,$app_logo){
- $v['label_name'] = $v['label'] ? explode(',',trim($v['label'],',')): null;
- if(!$v['name']) $v['name'] = $app_name;
- if(!$v['headimg']) $v['headimg'] = $app_logo;
- });
- }
- $num = UserForum::where('is_read',0)->count();
- if(!empty($list)) {
- $ids_arr = array_column($list,'id');
- UserForum::where('id','in',implode(',',$ids_arr))->where('is_read',0)->update(['is_read'=>1]);
- UserForum::where('id','in',implode(',',$ids_arr))->setInc('browse_num');
- }
- $this->success('ok',['list'=>$list,'unread_num'=>$num]);
- }
- /**
- * @title 获取论坛未读数量
- * @desc 获取论坛未读数量
- * @author qc
- * @method GET
- * @url /api/Forum/getUnreadNum
- * @header name:Authorization require:1 desc:Token
- * @return name:unread_num type:int default:-- desc:未读量
- */
- public function getUnreadNum()
- {
- $num = UserForum::where('is_read',0)->where('is_deleted',0)->count();
- $this->success('ok',['unread_num'=>$num]);
- }
- /**
- * @title 获取论坛详情
- * @desc 获取论坛详情
- * @author qc
- * @method GET
- * @url /api/Forum/getForumInfo
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:string default:-- desc:论坛记录id
- * @return name:title type:string default:-- desc:标题
- * @return name:content type:string default:0 desc:内容
- * @return name:level type:int default:-- desc:vip等级id
- * @return name:label type:string default:-- desc:标签
- * @return name:label_name type:array default:-- desc:标签
- * @return name:name type:string default:-- desc:发布用户
- * @return name:headimg type:string default:-- desc:发布用户头像
- * @return name:browse_num type:int default:-- desc:浏览量
- * @return name:is_collect type:int default:-- desc:是否关注【0否1是】
- * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
- * @return name:comment_num type:int default:-- desc:评论数量
- * @return name:replay_num type:int default:-- desc:回复数量
- */
- public function getForumInfo(){
- $id = input('get.id');
- $user_level = UserLevelRank::getUserVip($this->user_id);
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- $detail = UserForum::where('f.id',$id)
- ->alias('f')
- ->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')
- ->leftJoin('store_member u','u.id = f.user_id')
- ->find()->toArray();
- if($detail['is_deleted']) $this->error('改论坛已删除');
- if($user_level > 0 && $detail['level'] > $user_level) $this->error('用户等级不足');
- if($user_level == 0 && $detail['level'] > 1) $this->error('用户等级不足');
- $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,5,$detail['id']);
- $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,5,$detail['id']);
- $detail['label_name'] = $detail['label'] ? explode(',',trim($detail['label'],',')): null;
- if(!$detail['name']) $detail['name'] = $app_name;
- if(!$detail['headimg']) $detail['headimg'] = $app_logo;
- $detail['comment_num'] = ForumReplyComment::where(['is_deleted'=>0,'forum_id'=>$detail['id']])->count();
- $detail['replay_num'] = ForumReply::where(['is_deleted'=>0,'forum_id'=>$detail['id']])->count();
- UserForum::where('id',$id)->setInc('browse_num');// 增加浏览量
- if(!$detail['is_read'])UserForum::where('id',$detail['id'])->update(['is_read'=>1]);
- UserTrack::crateTrack($this->user_id,5,input('get.id'),0);
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 关注||取消关注
- * @desc 关注||取消关注
- * @author qc
- * @method POST
- * @url /api/Forum/forumCollect
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:-- desc:论坛id
- * @param name:status type:int default:0 desc:收藏状态(0取消关注【未关注】,1关注)
- */
- public function forumCollect()
- {
- $coll_status = UserCollect::plateCollect($this->user_id,5,input('post.id',0),0);
- $coll_status ? $this->success('关注成功',['status'=>1]) : $this->success('取消关注成功',['status'=>0]);
- }
- /**
- * @title 开启||关闭通知开关
- * @desc 开启||关闭通知开关
- * @author qc
- * @method POST
- * @url /api/Forum/forumSwitch
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:-- desc:论坛id
- */
- public function forumSwitch()
- {
- $switch_status = PlatformSwitch::userSwitch($this->user_id,5,input('post.id',0));
- $switch_status ? $this->success('开启成功',['status'=>1]) : $this->success('关闭成功',['status'=>0]);
- }
- /**
- * @title 论坛回复
- * @desc 论坛回复
- * @author qc
- * @method POST
- * @url /api/Forum/replyForum
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:论坛id
- * @param name:content type:string default:-- desc:内容
- * @return name:name type:string default:-- desc:会员名称
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:content type:string default:-- desc:内容
- */
- public function replyForum()
- {
- $id = input('post.id');
- $content = input('post.content');
- if(!$content) $this->error('请上传内容');
- $issue_user = UserForum::where('id',$id)->value('user_id');
- $res = ForumReply::create(['user_id'=>$this->user_id,'content'=>$content,'issue_user'=>$issue_user,'forum_id'=>$id]);
- $detail = ForumReply::where('c.id',$res->id)
- ->alias('c')
- ->field('c.id,c.content,c.create_at,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->find()->toArray();
- $user_info = $this->userInfo('name');
- UserMessage:: sendUserMessage($issue_user,'forum',5,0,$this->user_id,$id,$user_info['name'].'回复了您的提问');
- $this->success('回复成功',['detail'=>$detail]);
- }
- /**
- * @title 论坛回复列表
- * @desc 论坛回复列表
- * @author qc
- * @method GET
- * @url /api/Forum/getReplyList
- * @header name:Authorization require:1 desc:Token
- * @param name:forum_id type:int default:0 desc:论坛记录id
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:id type:int default:-- desc:论坛回复id
- * @return name:content type:string default:-- desc:内容
- * @return name:name type:string default:-- desc:会员
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:like_num type:int default:-- desc:点赞数量
- * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
- * @return name:children type:array default:-- desc:评论列表【所有的都查了】
- * @return name:children.content type:string default:-- desc:评论内容
- * @return name:children.create_at type:string default:-- desc:评论时间
- * @return name:children.name type:string default:-- desc:会员
- * @return name:children.headimg type:string default:-- desc:会员头像
- * @return name:children.like_num type:int default:-- desc:点赞数量
- * @return name:children.is_like type:int default:-- desc:是否点赞(0否1是)
- * @return name:children.children_num type:int default:-- desc:评论数量
- * @return name:total_num type:int default: desc:总数
- */
- public function getReplyList()
- {
- $where = [];
- $where[] = ['r.forum_id','=',input('get.forum_id')];
- $where[] = ['r.is_deleted','=',0];
- $list = ForumReply::where($where)
- ->alias('r')
- ->field('r.id,r.content,r.create_at,u.name,u.headimg')
- ->leftJoin('store_member u','r.user_id = u.id')
- ->limit($this->off_set,$this->page_num)
- ->order('r.id desc')
- ->select()->toArray();
- $total_num = ForumReply::where($where)->alias('r')->count();
- array_walk($list,function (&$val,$k){
- $val['like_num'] = PlatformLike::getPraiseNum($val['id'],3);
- $val['is_like'] = PlatformLike::checkTags($this->user_id,$val['id'],3);
- $children = ForumReplyComment::where(['c.reply_id'=>$val['id'],'c.is_deleted'=>0])
- ->alias('c')
- ->field('c.id,c.create_at,c.content,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->order('c.id desc')
- ->select()->toArray();
- foreach ($children as &$c) {
- $c['like_num'] = PlatformLike::getPraiseNum($c['id'], 8);
- $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
- }
- $val['children'] = $children ? $children : null;
- $val['children_num'] = count($children);
- });
- $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
- }
- /**
- * @title 论坛回复的评论列表
- * @desc 论坛回复的评论列表
- * @author qc
- * @method GET
- * @url /api/Forum/getReplyCommentList
- * @header name:Authorization require:1 desc:Token
- * @param name:reply_id type:int default:0 desc:论坛回复记录id
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:content type:string default:-- desc:评论内容
- * @return name:create_at type:string default:-- desc:评论时间
- * @return name:name type:string default:-- desc:会员
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:like_num type:int default:-- desc:点赞数量
- * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
- * @return name:total_num type:int default: desc:总数
- */
- public function getReplyCommentList()
- {
- $reply_id = input('reply_id');
- $list = ForumReplyComment::where(['c.reply_id'=>$reply_id,'c.is_deleted'=>0])
- ->alias('c')
- ->field('c.id,c.create_at,c.content,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->order('c.id desc')
- ->select()->toArray();
- foreach ($list as &$c){
- $c['like_num'] = PlatformLike::getPraiseNum($c['id'], 8);
- $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
- }
- $total_num = ForumReplyComment::where(['c.reply_id'=>$reply_id,'c.is_deleted'=>0])->alias('c')->count();
- $this->success('ok',compact(['list','total_num']));
- }
- /**
- * @title 论坛二级评论
- * @desc 论坛二级评论
- * @author qc
- * @method POST
- * @url /api/Forum/forumSecondComment
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:评论id
- * @param name:content type:string default:-- desc:内容
- * @return name:name type:string default:-- desc:会员名称
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:content type:string default:-- desc:内容
- */
- public function forumSecondComment()
- {
- $comment = ForumReplyComment::where('id',input('post.id'))->find()->toArray();
- $user_info = $this->userInfo('name');
- UserMessage:: sendUserMessage($comment['user_id'],'forum',4,0,$this->user_id,$comment['id'],$user_info['name'].'回复了您的评论');
- unset($comment['id']);
- unset($comment['create_at']);
- $comment['pid'] = input('post.id');
- $comment['user_id'] = $this->user_id;
- $comment['content'] = input('post.content');
- $comment['lev']++;
- if(!$comment['source_id']) $comment['source_id'] = input('post.id');
- $res = ForumReplyComment::create($comment);
- $detail = ForumReplyComment::where('p.id',$res->id)
- ->alias('p')
- ->field('p.id,p.content,p.create_at,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = p.user_id')
- ->find()->toArray();
- $this->success('评论成功',['detail'=>$detail]);
- }
- /**
- * @title 论坛回复点赞||取消点赞
- * @desc 论坛回复点赞||取消点赞
- * @author qc
- * @method POST
- * @url /api/Forum/forumTags
- * @header name:Authorization require:1 desc:Token
- * @param name:like_id type:int default:1 desc:论坛回复的id
- * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
- */
- public function forumTags()
- {
- $ret_val= PlatformLike::userTags($this->user_id,input('post.like_id'),3);
- $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
- }
- /**
- * @title 对论坛回复的评论进行点赞||取消点赞
- * @desc 论坛回复的评论点赞||取消点赞
- * @author qc
- * @method POST
- * @url /api/Forum/forumCommentTags
- * @header name:Authorization require:1 desc:Token
- * @param name:like_id type:int default:1 desc:论坛回复的评论id
- * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
- */
- public function forumCommentTags()
- {
- $ret_val= PlatformLike::userTags($this->user_id,input('post.like_id'),8);
- $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
- }
- /**
- * @title 对论坛回复进行评论
- * @desc 对论坛回复进行评论
- * @author qc
- * @method POST
- * @url /api/Forum/commentReply
- * @header name:Authorization require:1 desc:Token
- * @param name:reply_id type:int default:-- desc:回复的id
- * @param name:content type:string default:-- desc:内容
- * @return name:name type:string default:-- desc:会员名称
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:content type:string default:-- desc:内容
- * @return name:create_at type:string default:-- desc:时间
- */
- public function commentReply()
- {
- $reply_id = input('post.reply_id');
- $content = input('post.content');
- if(!$content) $this->error('请输入评论内容');
- $reply_info = ForumReply::where('id',$reply_id)->find()->toArray();
- //if($reply_info['user_id'] == $this->user_id) $this->error('无法评论自己的回答');
- $user_info = $this->userInfo('name,headimg');
- UserMessage:: sendUserMessage($reply_info['user_id'],'forum',3,0,$this->user_id,$reply_id,$user_info['name'].'评论了您的回复');
- $res = ForumReplyComment::create(['user_id'=>$this->user_id,'content'=>$content,'forum_id'=>$reply_info['forum_id'],'reply_id'=>$reply_id]);
- $detail = ForumReplyComment::where('c.id',$res->id)
- ->alias('c')
- ->field('c.id,c.content,c.create_at,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->find()->toArray();
- $this->success('评论成功',['detail'=>$detail]);
- }
- /**
- * @title 用户发布论坛
- * @desc 用户发布论坛
- * @author qc
- * @method POST
- * @url /api/Forum/userReferForum
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:标题
- * @param name:content type:string default:-- desc:内容
- * @param name:label type:string default:-- desc:论坛标签(多个用逗号隔开)
- * @param name:images type:string default:-- desc:(多个用|隔开)
- */
- public function userReferForum()
- {
- $title = input('post.title');
- $content = input('post.content');
- $label = input('post.label');
- $images = input('post.images');
- if(!$title || !$content || !$label) $this->error('参数错误');
- $data = [
- 'title' => $title,
- 'user_id' => $this->user_id,
- 'content' => $content,
- 'label' => $label,
- 'images' => $images,
- 'level' => UserLevelRank::getUserVip($this->user_id),
- ];
- $res = UserForum::create($data);
- UserMessage::sendUserMessage($this->user_id,'forum',1,0,0,$res->id);
- $this->success('发布成功');
- }
- /**
- * @title 用户删除论坛记录
- * @desc 用户删除论坛记录
- * @author qc
- * @method POST
- * @url /api/Forum/delForum
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:id
- */
- public function delForum(){
- UserForum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
- $this->success('删除成功');
- }
- /**
- * @title 我的提问
- * @desc 我的提问
- * @author qc
- * @method GET
- * @url /api/Forum/getUserForumList
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:标题
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数量
- * @return name:title type:string default:-- desc:标题
- * @return name:content type:string default:0 desc:内容
- * @return name:level type:int default:-- desc:vip等级id
- * @return name:label type:string default:-- desc:标签
- * @return name:name type:string default:-- desc:发布用户
- * @return name:headimg type:string default:-- desc:发布用户头像
- * @return name:browse_num type:int default:-- desc:浏览量
- * @return name:reply_num type:int default:-- desc:回答量
- */
- public function getUserForumList()
- {
- $sel_where = [];
- $sel_where[] = ['f.is_deleted','=',0];
- $sel_where[] = ['f.user_id','=',$this->user_id];
- if($title = input('get.title')) $sel_where[] = ['f.title|f.label','like','%'.$title.'%'];
- $list = UserForum::where($sel_where)
- ->alias('f')
- ->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')
- ->leftJoin('store_member u','u.id = f.user_id')
- ->limit($this->off_set,$this->page_num)
- ->order( 'id desc' )
- ->select()->toArray();
- $this->success('ok',['list'=>$list,'user_info'=>$this->userInfo(['name','headimg'])]);
- }
- /**
- * @title 我的回答【列表】--论坛问题
- * @desc 我的回答【列表】
- * @author qc
- * @method GET
- * @url /api/Forum/myReplyList
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:关键字
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数量
- * @return name:title type:string default:-- desc:标题[论坛]
- * @return name:content type:string default:0 desc:内容
- * @return name:name type:string default:-- desc:用户
- * @return name:headimg type:string default:-- desc:用户头像
- * @return name:create_at type:string default:-- desc:时间
- */
- public function myReplyList()
- {
- $where = [];
- $where[] = ['r.user_id','=',$this->user_id];
- $where[] = ['r.is_deleted','=',0];
- if($title = input('title'))$where[] = ['r.content','like','%'.$title.'%'];
- $list = ForumReply::where($where)
- ->alias('r')
- ->field('r.id,r.content,r.create_at,f.title,u.name ,u.headimg')
- ->leftJoin('user_forum f','r.forum_id = f.id')
- ->leftJoin('store_member u','r.user_id = u.id')
- ->limit($this->off_set,$this->page_num)
- ->order('r.id desc')
- ->select()->toArray();
- $total_num = ForumReply::where($where)->alias('r')->count();
- $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
- }
- /**
- * @title 我的评论
- * @desc 我的评论
- * @author qc
- * @method GET
- * @url /api/Forum/myDiscuss
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:关键字
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数量
- * @return name:create_at type:string default:-- desc:时间
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:content type:string default:0 desc:评论内容
- * @return name:reply_content type:string default:0 desc:回复内容
- * @return name:name type:string default:-- desc:回复的用户
- * @return name:headimg type:string default:-- desc:回复的头像
- */
- public function myDiscuss()
- {
- $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content')->alias('c')
- ->where(['c.user_id'=>$this->user_id,'c.is_deleted'=>0])
- ->leftJoin('forum_reply r','c.reply_id = r.id')
- ->leftJoin('store_member m','m.id = r.user_id')
- ->leftJoin('user_forum f','f.id = c.forum_id')
- ->order('c.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 回答我的
- * @desc 回答我的
- * @author qc
- * @method GET
- * @url /api/Forum/replyToMyForum
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:关键字
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数量
- * @return name:title type:string default:-- desc:标题[论坛]
- * @return name:content type:string default:0 desc:内容
- * @return name:name type:string default:-- desc:用户
- * @return name:headimg type:string default:-- desc:用户头像
- * @return name:create_at type:string default:-- desc:时间
- */
- public function replyToMyForum()
- {
- $where = [];
- $where[] = ['r.issue_user','=',$this->user_id];
- $where[] = ['r.is_deleted','=',0];
- if($title = input('title'))$where[] = ['r.content','like','%'.$title.'%'];
- $list = ForumReply::where($where)
- ->alias('r')
- ->field('r.id,r.content,r.create_at,f.title,u.name ,u.headimg')
- ->leftJoin('user_forum f','r.forum_id = f.id')
- ->leftJoin('store_member u','r.user_id = u.id')
- ->limit($this->off_set,$this->page_num)
- ->order('r.id desc')
- ->select()->toArray();
- $total_num = ForumReply::where($where)->alias('r')->count();
- $this->success('ok',['list'=>$list,'total_num'=>$total_num]);
- }
- /**
- * @title 评论我的
- * @desc 评论我的
- * @author qc
- * @method GET
- * @url /api/Forum/commentOnMyReply
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:关键字
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数量
- * @return name:create_at type:string default:-- desc:时间
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:content type:string default:0 desc:评论内容
- * @return name:reply_content type:string default:0 desc:回复内容
- * @return name:name type:string default:-- desc:评论用户
- * @return name:headimg type:string default:-- desc:评论用户头像
- */
- public function commentOnMyReply()
- {
- $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content')->alias('c')
- ->where(['r.user_id'=>$this->user_id,'r.is_deleted'=>0])
- ->leftJoin('forum_reply r','c.reply_id = r.id')
- ->leftJoin('store_member m','m.id = c.user_id')
- ->leftJoin('user_forum f','f.id = c.forum_id')
- ->order('c.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 用户举报
- * @desc 用户举报
- * @author qc
- * @url /api/Forum/forumReport
- * @method POST
- * @header name:Authorization require:1 desc:Token
- * @param name:report_id type:int default:-- desc:举报内容的id
- * @param name:case_ids type:string default:-- desc:举报类目id串(逗号隔开)
- */
- public function forumReport()
- {
- $report_id= input('post.report_id');
- $case_ids= input('post.case_ids');
- if(!$report_id) $this->error('请现在举报内容');
- if(!$case_ids) $this->error('请选择举报原因');
- UserReport::report($this->user_id,6,$report_id,$case_ids);
- $this->success('举报成功');
- }
- /**
- * @title 转发(转发数量统计)
- * @desc 转发成功后调用
- * @author qc
- * @method POST
- * @url /api/Forum/forumTransmit
- * @header name:Authorization require:1 desc:Token
- * @param name:forum_id type:int default:-- desc:论坛问题id
- */
- public function forumTransmit()
- {
- $forum_id = input('post.forum_id');
- UserForum::where('id',$forum_id)->setInc('transmit_num');
- $this->success('转发成功');
- }
- /**
- * @title 回复我的【回复我的--回复过我的评论】
- * @desc 回复我的
- * @author qc
- * @method GET
- * @url /api/Forum/getReplyComment
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:标题
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:title type:string default:-- desc:标题
- *
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:create_at type:string default:-- desc:时间
- * @return name:user_name type:string default:-- desc:用户名【其他会员】
- * @return name:headimg type:string default:-- desc:用户头像【其他会员】
- * @return name:content type:string default:-- desc:回复内容
- * @return name:parent_comment type:array default:-- desc:你的评论内容
- * @return name:parent_comment.content type:string default:-- desc:内容
- * @return name:parent_comment.name type:string default:-- desc:你的会员名称
- * @return name:parent_comment.headimg type:string default:-- desc:你的头像
- * @return name:parent_comment.title type:string default:-- desc:论坛标题
- * @return name:parent_comment.forum_id type:string default:-- desc:论坛id
- */
- public function getReplyComment()
- {
- // 所有我评论的回答
- $all_comment = ForumReplyComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- if(empty($all_comment)) $this->success('ok',['list'=>null]);
- $sel_where = [];
- $title = input('get.title');
- if($title) $sel_where[] = ['i.title','like','%'.$title.'%'];
- $sel_where[] = ['t.is_deleted','=',0];
- $sel_where[] = ['t.lev','>=',2];
- $sel_where[] = ['t.user_id','<>',$this->user_id];
- $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
- $list = ForumReplyComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.content,t.pid,forum_id,u.name user_name,u.headimg,i.title')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->leftJoin('UserForum i','t.forum_id = i.id')
- ->order('t.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $parent_comment = ForumReplyComment::where([['t.id','=',$v['pid']]])
- ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg')
- ->alias('t')
- ->leftJoin('UserForum i','t.forum_id = i.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->find()->toArray();
- $v['parent_comment'] = $parent_comment;
- }
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 我的回复【我的回复--我回复过的评论】
- * @desc 我的回复
- * @author qc
- * @method GET
- * @url /api/Forum/getReplyForum
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:标题
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:title type:string default:-- desc:论坛标题
- * @return name:create_at type:string default:-- desc:时间
- * @return name:user_name type:string default:-- desc:用户名【用户自己的】
- * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
- * @return name:content type:string default:-- desc:回复内容
- * @return name:parent_comment type:array default:-- desc:上级评论内容【你回复的那个】
- * @return name:parent_comment.content type:string default:-- desc:内容
- * @return name:parent_comment.name type:string default:-- desc:会员名称【别人的】
- * @return name:parent_comment.headimg type:string default:-- desc:会员头像【别人的】
- * @return name:parent_comment.title type:string default:-- desc:论坛标题
- * @return name:parent_comment.forum_id type:string default:-- desc:论坛id
- */
- public function getReplyForum()
- {
- $user_info = $this->userInfo();
- $sel_where = [];
- $title = input('get.title');
- if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.is_deleted','=',0];
- $sel_where[] = ['t.lev','>=',2];
- $list = ForumReplyComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.content,t.pid,forum_id,i.title')
- ->leftJoin('UserForum i','t.forum_id = i.id')
- ->order('t.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['user_name'] = $user_info['name'];
- $v['headimg'] = $user_info['headimg'];
- $parent_comment = ForumReplyComment::where([['t.id','=',$v['pid']]])
- ->field('t.id,t.create_at,t.content,t.pid,forum_id,u.name,u.headimg,i.title')
- ->alias('t')
- ->leftJoin('UserForum i','t.forum_id = i.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->find()->toArray();
- $v['parent_comment'] = $parent_comment;
- }
- $this->success('ok',['list'=>$list]);
- }
- }
|