1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783 |
- <?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\TopSearch;
- 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 app\common\service\CheckPower;
- use app\common\service\UserSynth;
- use think\Db;
- use library\tools\Data;
- use vod\Request\V20170321\GetMediaAuditResultTimelineRequest;
- /**
- * @title 问答
- * @controller Forum
- * @group base
- */
- class Forum extends Base
- {
- // 需要登录的
- protected $need_login = [
- 'forumCollect',
- 'forumSwitch',
- 'replyForum',
- 'commentReply',
- 'forumSecondComment',
- 'forumTags',
- 'userReferForum',
- 'getUserForumList',
- 'myReplyList',
- 'myDiscuss',
- 'unreadChange',
- 'replyToMyForum',
- 'commentOnMyForum',
- 'commentOnMyReply',
- 'forumReport',
- 'forumTransmit',
- 'getReplyComment',
- 'getReplyForum',
- 'praiseForumList',
- 'praiseReplyList',
- 'praiseCommentList',
- 'batchesDel',
- 'getForumTrack',
- 'getTagsForum',
- 'getTagsReply',
- 'getTagsComment',
- 'getCollectList',
- ];
- public function initialize()
- {
- parent::initialize();
- 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:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @param name:rand_user type:string default:-- desc:随机id(非登录状态必传,page=1时生成(a123),其他页数(a123),一直查询到没有数据)
- * @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:reply_num type:int default:-- desc:回答量
- * @return name:open_vip type:int default:-- desc:是否需要开通vip[0不需要1需要]
- * @return name:release_time type:string default:-- desc:上架时间
- *
- */
- public function getForumList()
- {
- $user_id = $this->user_id ? $this->user_id : input('rand_user');
- if(!$user_id) $this->error('参数错误');
- $list = UserSynth::getRecommendList($user_id,'forum',$this->page,$this->page_num);
- if($list['code'] != 200) $this->error($list['msg']);
- $this->success('ok',$list);
- $sel_where = [];
- $title = input('get.title');
- $label = input('get.label');
- $sort_type = input('get.sort_type', 1);
- $sel_where[] = ['f.is_deleted', '=', 0];
- $sel_where[] = ['f.status', '=', 1];
- 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', 'browse_num' => 'desc', 'id' => 'asc'];
- 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 = $user_level ? $user_level : 1;
- $search_log = UserSearch::getSearchTitle($this->user_id, 6);
- $search_arr = [];
- foreach ($search_log as $t) {
- $search_arr[] = " b.title like '" . '%' . $t . "%'" . ' ';
- $search_arr[] = " b.label like '" . '%' . $t . "%'" . ' ';
- }
- $where_str = 'b.id > 0';
- 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 = 'a.browse_num';
- $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}";
- $list = Db::query($sql);
- $list = dispose_recommend($list);
- array_walk($list, function (&$v, $k) use ($app_name, $app_logo,$user_level) {
- $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
- $reply_num = ForumReply::where(['forum_id' => $v['id']])->where('is_deleted', 0)->count();
- $v['reply_num'] = numTransform($reply_num);
- $v['browse_num'] = numTransform($v['browse_num']);
- if (!$v['name']) $v['name'] = $app_name;
- if (!$v['headimg']) $v['headimg'] = $app_logo;
- $v['open_vip'] = !$user_level && $v['level'] ? 1 : 0;
- });
- $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 ";
- $total = Db::query($sql2);
- $total_num = $total[0]['num'];
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_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:images type:string default:0 desc:图片【多张|隔开】
- * @return name:images_arr type:array default:null desc:图片【多张】
- * @return name:collect_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:回复数量
- * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
- * @return name:like_num type:int default:-- desc:点赞数量
- * @return name:release_time type:string 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,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')
- ->leftJoin('store_member u', 'u.id = f.user_id')
- ->find()->toArray();
- if ($detail['is_deleted'] || $detail['status'] == 0) $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, $detail['id'], 1);
- $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();
- $detail['comment_num'] = numTransform($detail['comment_num']);
- $detail['replay_num'] = numTransform($detail['replay_num']);
- $detail['browse_num'] = numTransform($detail['browse_num']);
- $collect_num = UserCollect::getCollectNum(5,$detail['id']);
- $detail['collect_num'] = numTransform($collect_num);
- $detail['images_arr'] = $detail['images'] ? explode('|', $detail['images']) : null;
- $detail['is_like'] = PlatformLike::checkTags($this->user_id, $detail['id'], 10);
- $detail['like_num'] = PlatformLike::getPraiseNum($detail['id'], 10);
- UserForum::where('id', $id)->setInc('browse_num');// 增加浏览量
- if($this->user_id){
- TopSearch::seIncHotNum($id,$this->request->controller());
- }
- if($detail['content'] != null && $detail['content'] != ''){
- $detail['content'] = "<div style='font-family:微软雅黑;'>".$detail['content']."</div>";
- }
- 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 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_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
- * @return name:comment_num type:int default:-- desc:评论数量
- * @return name:new_comment type:array default:-- desc:最新两条评论【数据结构:评论列表【问题&&答案】/api/Forum/getReplyCommentList一样】
- * @return name:hot_comment type:array default:-- desc:最热两条评论【数据结构:评论列表【问题&&答案】/api/Forum/getReplyCommentList一样】
- * @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.is_top,r.content,r.create_at,r.user_id,u.name,u.headimg,forum_id,f.level')
- ->leftJoin('store_member u', 'r.user_id = u.id')
- ->leftJoin('UserForum f', 'r.forum_id = f.id')
- ->limit($this->off_set, $this->page_num)
- ->order('r.is_top,r.id desc')
- ->select()->toArray();
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- $total_num = ForumReply::where($where)->alias('r')->count();
- array_walk($list, function (&$val, $k) use ($app_name, $app_logo) {
- $val['like_num'] = PlatformLike::getPraiseNum($val['id'], 3);
- $val['is_like'] = PlatformLike::checkTags($this->user_id, $val['id'], 3);
- $val['can_delete'] = $val['user_id'] == $this->user_id ? 1 :0;
- if (!$val['user_id']) $val['name'] = $app_name;
- if (!$val['user_id']) $val['headimg'] = $app_logo;
- $sel_where = [];
- $sel_where[] = ['c.forum_id','=',$val['forum_id']];
- $sel_where[] = ['c.is_deleted','=',0];
- $sel_where[] = ['c.reply_id','=',$val['id']];
- $val['comment_num'] = ForumReplyComment::where($sel_where)->alias('c')->count();
- // 最新两条评论
- $new_comment = ForumReplyComment::where($sel_where)->alias('c')
- ->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')
- ->leftJoin('store_member u', 'u.id = c.user_id')
- ->order( ['c.is_top'=>'desc','c.id'=>'desc'])->limit(0,2)
- ->select()->toArray();
- foreach ($new_comment as &$c) {
- $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
- $parent_comment = ForumReplyComment::where([['t.id', '=', $c['pid']]])
- ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.is_deleted')
- ->alias('t')->leftJoin('UserForum i', 't.forum_id = i.id')->leftJoin('store_member u', 't.user_id = u.id')
- ->find();
- $c['parent_comment'] = $parent_comment ? $parent_comment->toArray() : null;
- }
- // 最热两条
- $hot_comment = ForumReplyComment::where($sel_where)->alias('c')
- ->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')
- ->leftJoin('store_member u', 'u.id = c.user_id')
- ->order(['c.is_top'=>'desc','like_num'=>'desc','c.id'=>'desc'])->limit(0,2)
- ->select()->toArray();
- foreach ($hot_comment as &$c) {
- $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
- $parent_comment = ForumReplyComment::where([['t.id', '=', $c['pid']]])
- ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.is_deleted')
- ->alias('t')->leftJoin('UserForum i', 't.forum_id = i.id')->leftJoin('store_member u', 't.user_id = u.id')
- ->find();
- $c['parent_comment'] = $parent_comment ? $parent_comment->toArray() : null;
- }
- $val['new_comment'] = $new_comment;
- $val['hot_comment'] = $hot_comment;
- });
- $this->success('ok', ['list' => $list, 'total_num' => numTransform($total_num), 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 回答详情
- * @desc 回答详情
- * @author qc
- * @method GET
- * @url /api/Forum/getReplyInfo
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:回答记录id
- * @return name:id type:int default:-- desc:问答回复id
- * @return name:forum_id type:int default:-- desc:问题id
- * @return name:forum_title type:int default:-- desc:问题标题
- * @return name:level type:int default:-- desc:问答VIP等级
- * @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:user_id type:int default:-- desc:回答人id
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
- * @return name:serial_number type:int default:-- desc:第几个回答的
- * @return name:next_id type:int default:-- desc:下一个回答的id
- */
- public function getReplyInfo()
- {
- $id = input('get.id');
- $info = ForumReply::where('r.id',$id)
- ->alias('r')
- ->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')
- ->leftJoin('store_member u', 'r.user_id = u.id')
- ->leftJoin('UserForum f', 'f.id = r.forum_id')
- ->find()->toArray();
- if($info['is_deleted']) $this->error('该答案已删除');
- $info['like_num'] = PlatformLike::getPraiseNum($info['id'], 3);
- $info['is_like'] = PlatformLike::checkTags($this->user_id, $info['id'], 3);
- $info['serial_number'] = ForumReply::where([['id','<=',$id],['forum_id','=',$info['forum_id']]])->count();
- $info['next_id'] = ForumReply::where([['id','>',$id],['forum_id','=',$info['forum_id']],['is_deleted','=',0]])->min('id');
- $info['forum_title'] = UserForum::where('id',$info['forum_id'])->value('title');
- $this->success('ok',['detail'=>$info]);
- }
- /**
- * @title 评论列表【问题&&答案】
- * @desc 评论列表
- * @author qc
- * @method GET
- * @url /api/Forum/getReplyCommentList
- * @header name:Authorization require:1 desc:Token
- * @param name:forum_id type:int default:0 desc:问题id
- * @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:每页数
- * @param name:sort_type type:int default:1 desc:排序1最新2最热
- * @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:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
- * @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
- * @return name:parent_comment.is_deleted type:int default:-- desc:是否删除【0否,1,2删除】
- */
- public function getReplyCommentList()
- {
- $forum_id = input('forum_id');
- $reply_id = input('reply_id',0);
- $sort_type = input('get.sort_type',1);
- $sel_where = [];
- $sel_where[] = ['c.forum_id','=',$forum_id];
- $sel_where[] = ['c.is_deleted','=',0];
- $sel_where[] = ['c.reply_id','=',$reply_id];
- switch ($sort_type) {
- case 1:
- $order = ['c.is_top'=>'desc','c.id'=>'desc'];
- break;
- case 2:
- $order = ['c.is_top'=>'desc','like_num'=>'desc','c.id'=>'desc'];
- break;
- }
- $list = ForumReplyComment::where($sel_where)->alias('c')
- ->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')
- ->leftJoin('store_member u', 'u.id = c.user_id')
- ->order($order)
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- foreach ($list as &$c) {
- $c['is_like'] = PlatformLike::checkTags($this->user_id, $c['id'], 8);
- $c['can_delete'] = $c['user_id'] == $this->user_id ? 1 :0;
- $parent_comment = ForumReplyComment::where([['t.id', '=', $c['pid']]])
- ->field('t.id,t.forum_id,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.is_deleted')
- ->alias('t')
- ->leftJoin('UserForum i', 't.forum_id = i.id')
- ->leftJoin('store_member u', 't.user_id = u.id')
- ->find();
- $c['parent_comment'] = $parent_comment ? $parent_comment->toArray() : null;
- }
- $total_num =ForumReplyComment::where($sel_where)->alias('c')->leftJoin('store_member u', 'u.id = c.user_id')->count();
- $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @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, input('post.id', 0), 1);
- $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('请输入内容');
- $forum_info = UserForum::where('id', $id)->find()->toArray();
- if (!$forum_info['comment_switch']) $this->error('评论功能已关闭');
- $issue_user = $forum_info['user_id'];
- $res = ForumReply::create([
- 'user_id' => $this->user_id,
- 'content' => $content,
- 'issue_user' => $issue_user,
- 'forum_id' => $id,
- 'is_read' => $this->user_id == $issue_user ? 1 : 0,
- ]);
- $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');
- if($issue_user != $this->user_id) UserMessage:: sendUserMessage($issue_user, 'forum', 5, 0, $this->user_id, $id, $content);
- // 有新的回答时给关注问题的会员推送
- UserForum:: sendCollectMsg($id,$res->id);
- UserForum::where('id',$id)->setInc('r_num',1);
- $this->success('回复成功', ['detail' => $detail]);
- }
- /**
- * @title 一级评论【问题&&答案】
- * @desc 一级评论
- * @author qc
- * @method POST
- * @url /api/Forum/commentReply
- * @header name:Authorization require:1 desc:Token
- * @param name:forum_id type:int require:1 default:-- desc:问题的id
- * @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()
- {
- $forum_id = input('post.forum_id');
- $reply_id = input('post.reply_id', 0);
- $content = input('post.content');
- if (!$content) $this->error('请输入评论内容');
- if(intval($reply_id)) $reply_info = ForumReply::where('id', $reply_id)->find()->toArray();
- $forum_info = UserForum::where('id', $forum_id)->find()->toArray();
- if (!$forum_info['comment_switch']) $this->error('评论功能已关闭');
- $user_info = $this->userInfo('name,headimg');
- 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);
- 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);
- $res = ForumReplyComment::create([
- 'user_id' => $this->user_id,
- 'content' => $content,
- 'forum_id' => $forum_id,
- 'reply_id' => $reply_id,
- 'is_read' => !empty($reply_info) && $reply_info['user_id'] == $this->user_id ? 1 : 0,
- 'source_read' => $forum_info['user_id'] == $this->user_id ? 1 : 0,
- ]);
- $detail = ForumReplyComment::where('c.id', $res->id)
- ->alias('c')
- ->field('c.id,c.is_top,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/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:内容
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- */
- public function forumSecondComment()
- {
- $comment = ForumReplyComment::where('id', input('post.id'))->find()->toArray();
- $forum_info = UserForum::where('id', $comment['forum_id'])->find()->toArray();
- if (!$forum_info['comment_switch']) $this->error('评论功能已关闭');
- $user_info = $this->userInfo('name');
- // if( $comment['reply_id']) $reply_info = ForumReply::where('id', $comment['reply_id'])->find()->toArray();
- if ($comment['user_id'] != $this->user_id ) UserMessage:: sendUserMessage($comment['user_id'], 'forum', 4, 0, $this->user_id, $comment['id'], input('post.content'));
- unset($comment['id']);
- unset($comment['create_at']);
- unset($comment['to_deleted']);
- unset($comment['is_top']);
- unset($comment['is_deleted']);
- $comment['is_read'] = !empty($comment) && $this->user_id == $comment['user_id'] ? 1 : 0;
- $comment['source_read'] = $this->user_id == $forum_info['user_id'] ? 1 : 0;
- $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.is_top,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:type type:int default:3 desc:类型(3答案,8评论【不用区分】,10问题)
- * @param name:like_id type:int default:1 desc:记录id
- * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
- */
- public function forumTags()
- {
- if (!in_array(input('type', 3), [3, 8, 10])) $this->error('类型错误');
- $ret_val = PlatformLike::userTags($this->user_id, input('post.like_id'), input('type', 3));
- $this->success('操作成功', ['tags' => $ret_val]);
- }
- /**
- * @title 用户发布或编辑问答
- * @desc 用户发布问答
- * @author qc
- * @method POST
- * @url /api/Forum/userReferForum
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:string default:-- desc:详情id【编辑必传】
- * @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()
- {
- $id = input('post.id');
- $title = input('post.title');
- $content = input('post.content');
- $label = input('post.label');
- $images = input('post.images');
- if (!$title || !$label) $this->error('参数错误');
- if (!$content) $content = '';
- $data = [
- 'title' => $title,
- 'user_id' => $this->user_id,
- 'content' => $content,
- 'label' => $label,
- 'images' => $images,
- 'level' => 0,//UserLevelRank::getUserVip($this->user_id),
- ];
- if($id){
- UserForum::where('id',$id)->update($data);
- UserForum::esAdd($id);
- \app\common\model\TopSearch::saveData($id,'forum');
- }else{
- $res = UserForum::create($data);
- UserForum::esAdd($res->id);
- \app\common\model\TopSearch::saveData($res->id,'forum');
- }
- //UserMessage::sendUserMessage($this->user_id, 'forum', 1, 0, 0, $res->id);
- $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: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:reply_num type:int default:-- desc:回答量
- * @return name:is_deleted type:int default:-- desc:0正常2后台下架
- * @return name:is_normal type:int default:-- desc:是否能正常跳转
- */
- public function getUserForumList()
- {
- $sel_where = [];
- $sel_where[] = ['f.is_deleted', '<>', 1];
- $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.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')
- ->leftJoin('store_member u', 'u.id = f.user_id')
- ->limit($this->off_set, $this->page_num)
- ->order('id desc')
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['browse_num'] = numTransform($v['browse_num']);
- $v['reply_num'] = numTransform($v['reply_num']);
- $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
- $v['is_normal'] = CheckPower::checkModulesPower($v['id'], 0, $this->request->controller());
- });
- $total_num = UserForum::where($sel_where)->alias('f')->leftJoin('store_member u', 'u.id = f.user_id')->count();
- $this->success('ok', ['list' => $list, 'user_info' => $this->userInfo(['name', 'headimg']), 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @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:browse_num type:int default:-- desc:问答浏览量
- * @return name:reply_num type:int default:-- desc:问答回答数量
- * @return name:like_num type:int 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:时间
- * @return name:is_normal type:int default:-- desc:是否能正常跳转
- * @return name:level type:int default:-- desc:问答VIP等级
- */
- 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.forum_id,r.create_at,f.title,u.name ,u.headimg,f.browse_num,f.level')
- ->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();
- array_walk($list, function (&$v) {
- $v['reply_num'] = ForumReply::where('forum_id', $v['forum_id'])->where('is_deleted', 0)->count();
- $v['reply_num'] = numTransform($v['reply_num']);
- $v['like_num'] = PlatformLike::getPraiseNum($v['forum_id'], 3);
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- });
- $total_num = ForumReply::where($where)->alias('r')->count();
- $this->success('ok', ['list' => $list, 'total_num' => numTransform($total_num), 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 我的评论
- * @desc 我的评论
- * @author qc
- * @method GET
- * @url /api/Forum/myDiscuss
- * @header name:Authorization require:1 desc:Token
- * @param name:type type:int default:1 desc:1问题2回答
- * @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:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:headimg type:string default:-- desc:用户头像
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function myDiscuss()
- {
- $where = [];
- $type = input('get.type',1);
- $where[] = ['c.user_id', '=', $this->user_id];
- $where[] = ['c.is_deleted', '=', 0];
- if ($title = input('title')) $where[] = ['c.content', 'like', '%' . $title . '%'];
- $where[] = ['c.user_id', '=', $this->user_id];
- // $where[] = $type == 1 ? ['f.user_id', '<>', $this->user_id]:['r.user_id', '<>', $this->user_id];
- $where[] = ['c.pid', '=', 0];
- $where[] = ['c.reply_id',$type == 1 ? '=' :'>',0];
- $where[] = ['c.is_deleted', '=', 0];
- $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content,f.level,r.user_id reply_user')->alias('c')
- ->where($where)
- ->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.is_top desc,c.id desc')
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- $user_info = $this->userInfo();
- array_walk($list, function (&$v)use ($user_info) {
- $v['name'] = $user_info['name'];
- $v['headimg'] = $user_info['headimg'];
- if($v['reply_id']) {
- $v['show_title'] = $v['reply_content'];
- unset($v['reply_content']);
- $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
- }else{
- $v['show_title'] = $v['title'];
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- }
- });
- $total_num = ForumReplyComment::where($where)
- ->alias('c')
- ->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')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 获取角标数量
- * @desc 获取角标数量
- * @author qc
- * @method GET
- * @url /api/Forum/getMarkNum
- * @header name:Authorization require:1 desc:Token
- * @return name:answer_num type:int default:-- desc:回答我的
- * @return name:reply_num type:int default:-- desc:回复我的【总数量】
- * @return name:reply_forum type:int default:-- desc:回复我的【问题】
- * @return name:reply_answer type:int default:-- desc:回复我的【答案】
- * @return name:comment_num type:int default:-- desc:评论我的【总数量】
- * @return name:forum_comment type:int default:-- desc:评论我的【评论问题】
- * @return name:reply_comment type:int default:-- desc:评论我的【评论答案】
- * @return name:follow_num type:int default:-- desc:关注量
- * @return name:praise_forum type:int default:-- desc:点赞问题
- * @return name:praise_reply type:int default:-- desc:点赞回答
- * @return name:praise_comment type:int default:-- desc:点赞评论
- * @return name:total_num type:int default:-- desc:总数
- */
- public function getMarkNum()
- {
- //回答我的
- $answer_num = ForumReply::where([['r.issue_user', '=', $this->user_id], ['r.is_deleted', '=', 0], ['r.is_read', '=', 0]])
- ->alias('r')->leftJoin('user_forum f', 'r.forum_id = f.id')->count();
- // 回复我的
- $all_comment = ForumReplyComment::where(['user_id' => $this->user_id, 'is_deleted' => 0])->column('id');
- if(count($all_comment) < 1){
- $reply_forum = 0;
- $reply_answer = 0;
- }else{
- $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();
- $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();
- }
- $reply_num = $reply_forum +$reply_answer;
- // 评论我的问题
- /* $where[] = ['f.user_id', '=', $this->user_id];
- $where[] = ['f.is_deleted', '=', 0];
- $where[] = ['c.is_deleted', '=', 0];
- $where[] = ['c.user_id', '<>', $this->user_id];
- $where[] = ['c.reply_id', '=', 0];
- $where[] = ['c.to_deleted', '=', 0];
- $where[] = ['c.pid','=',0];*/
- $forum_comment = ForumReplyComment::alias('c')
- ->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])
- ->where('c.user_id','<>',$this->user_id)
- ->leftJoin('UserForum r', 'c.forum_id = r.id')
- ->count();
- // 评论我的回答
- $reply_comment = ForumReplyComment::alias('c')
- ->where(['r.user_id' => $this->user_id, 'r.is_deleted' => 0, 'c.is_read' => 0,'c.pid'=>0])
- ->leftJoin('forum_reply r', 'c.reply_id = r.id')
- ->count();
- $comment_num = $forum_comment +$reply_comment;
- $follow_num = UserMessage::getUnreadNum($this->user_id,'forum',6);
- $total_num = $answer_num + $reply_num + $comment_num +$follow_num;
- //
- $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')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
- $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')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
- $praise_comment = PlatformLike::where([['p.type', '=', 8],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
- ->leftJoin('UserForum f', 'f.id = c.forum_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
- $this->success('ok', compact([
- 'answer_num',
- 'reply_num',
- 'comment_num',
- 'forum_comment',
- 'reply_comment',
- 'reply_answer',
- 'reply_forum',
- 'follow_num',
- 'praise_forum',
- 'praise_reply',
- 'praise_comment',
- 'total_num',
- ]));
- }
- /**
- * @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:id type:string default:-- desc:回答记录id
- * @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:时间
- * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
- * @return name:forum_id type:int default:-- desc:问答id
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function replyToMyForum()
- {
- $where = [];
- $where[] = ['r.issue_user', '=', $this->user_id];
- $where[] = ['r.user_id', '<>', $this->user_id];
- $where[] = ['r.is_deleted', '=', 0];
- $where[] = ['r.to_deleted', '=', 0];
- $where[] = ['f.user_id', '=', $this->user_id];// 过滤回答自己的问答
- if ($title = input('title')) $where[] = ['r.content', 'like', '%' . $title . '%'];
- $list = ForumReply::where($where)
- ->alias('r')
- ->field('r.id,r.is_read,r.content,r.create_at,f.title,u.name,r.forum_id ,u.headimg,f.level')
- ->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();
- array_walk($list, function (&$v) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- });
- $total_num = ForumReply::where($where)->leftJoin('user_forum f', 'r.forum_id = f.id')
- ->leftJoin('store_member u', 'r.user_id = u.id')->alias('r')->count();
- $this->success('ok', ['list' => $list, 'total_num' => numTransform($total_num), 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 评论我的--问题
- * @desc 评论我的
- * @author qc
- * @method GET
- * @url /api/Forum/commentOnMyForum
- * @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:评论用户头像
- * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function commentOnMyForum()
- {
- $where = [];
- $where[] = ['f.user_id', '=', $this->user_id];
- $where[] = ['f.is_deleted', '=', 0];
- $where[] = ['c.is_deleted', '=', 0];
- $where[] = ['c.user_id', '<>', $this->user_id];
- $where[] = ['c.reply_id', '=', 0];
- $where[] = ['c.to_deleted', '=', 0];
- $where[] = ['c.pid','=',0];
- if ($title = input('title')) $where[] = ['f.title', 'like', '%' . $title . '%'];
- $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title')->alias('c')
- ->where($where)
- ->leftJoin('store_member m', 'm.id = c.user_id')
- ->leftJoin('user_forum f', 'f.id = c.forum_id')
- ->order('c.is_top desc,c.id desc')
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- array_walk($list, function (&$v) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- });
- $total_num = ForumReplyComment::where($where)
- ->alias('c')
- ->leftJoin('store_member m', 'm.id = c.user_id')
- ->leftJoin('user_forum f', 'f.id = c.forum_id')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_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:评论用户头像
- * @return name:self_name type:string default:-- desc:自己昵称
- * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function commentOnMyReply()
- {
- $where = [];
- $where[] = ['r.user_id', '=', $this->user_id];
- $where[] = ['r.is_deleted', '=', 0];
- $where[] = ['c.user_id', '<>', $this->user_id];
- $where[] = ['c.reply_id', '>', 0];
- $where[] = ['c.to_deleted', '=', 0];
- $where[] = ['c.pid','=',0];
- if ($title = input('title')) $where[] = ['f.title', 'like', '%' . $title . '%'];
- $list = ForumReplyComment::field('c.*,m.name,m.headimg,f.title,r.content reply_content,f.level')->alias('c')
- ->where($where)
- ->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.is_top desc,c.id desc')
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- array_walk($list, function (&$v) {
- $v['self_name'] = $this->user_info['name'];
- $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
- });
- $total_num = ForumReplyComment::where($where)
- ->alias('c')
- ->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')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @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:type type:int default:1 desc:1问题2回答
- * @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:title type:string default:-- desc:问题标题
- * @return name:create_at type:string default:-- desc:时间
- * @return name:is_deleted type:int default:-- desc:回复内容是被删除【0否】
- * @return name:user_name type:string default:-- desc:用户名【其他会员】
- * @return name:headimg type:string default:-- desc:用户头像【其他会员】
- * @return name:content type:string default:-- desc:回复内容
- * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:parent_comment type:array default:-- desc:你的评论内容【阴影部分】
- * @return name:parent_comment.content type:string default:-- desc:内容
- * @return name:parent_comment.is_normal type:int default:-- desc:问题或答案能否跳转(0已删除或是已禁用1可以正常跳转详情)
- * @return name:parent_comment.is_deleted type:int default:-- desc:被评论的内容是否删除
- * @return name:parent_comment.name type:string default:-- desc:你的会员名称
- * @return name:parent_comment.headimg type:string default:-- desc:你的头像
- * @return name:parent_comment.forum_id type:int default:-- desc:问答id
- * @return name:parent_comment.show_title type:string default:-- desc:展示的问题标题或答案内容
- * @return name:parent_comment.is_deleted type:int default:-- desc:是否删除【0否,1,2删除】
- * @return name:parent_comment.reply_user type:int default:-- desc:回答人id
- * @return name:parent_comment.reply_id type:int default:-- desc:答案id【值为0是问题类型,大于0是答案类型】
- */
- 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');
- $type = input('get.type',1);
- if ($title) $sel_where[] = ['t.content', 'like', '%' . $title . '%'];
- // $sel_where[] = ['t.is_deleted', '=', 0];
- $sel_where[] = ['t.to_deleted', '=', 0];
- $sel_where[] = ['t.user_id','<>',$this->user_id];
- $sel_where[] = ['t.pid', 'in', implode(',', $all_comment)];
- $sel_where[] = ['t.reply_id',$type == 1 ? '=' : '>',0];
- $list = ForumReplyComment::where($sel_where)
- ->alias('t')
- ->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')
- ->leftJoin('store_member u', 't.user_id = u.id')
- ->leftJoin('UserForum i', 't.forum_id = i.id')
- ->order('t.is_top desc,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.is_top,t.forum_id,t.is_deleted,t.create_at,t.content,i.title,t.pid,u.name,u.headimg,t.reply_id')
- ->alias('t')->leftJoin('UserForum i', 't.forum_id = i.id')
- ->leftJoin('store_member u', 't.user_id = u.id')
- ->find()->toArray();
- $parent_comment['show_title'] = $v['title'];
- if($parent_comment['reply_id']) {
- $reply_info = ForumReply::where('id', $parent_comment['reply_id'])->find()->toArray();
- $parent_comment['reply_user'] = $reply_info['user_id'];
- $parent_comment['show_title'] = ForumReply::where('id',$parent_comment['reply_id'])->value('content');
- $parent_comment['is_normal'] =CheckPower::checkModulesPower($parent_comment['reply_id'], 0, 'reply');
- }else{
- $parent_comment['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- $parent_comment['show_title'] = $parent_comment['show_title'];
- }
- $v['parent_comment'] = $parent_comment;
- }
- $total_num = ForumReplyComment::where($sel_where)->alias('t')->leftJoin('store_member u', 't.user_id = u.id')
- ->leftJoin('UserForum i', 't.forum_id = i.id')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @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:type type:int default:1 desc:1问题2回答
- * @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:level type:int default:-- desc:VIP等级
- * @return name:user_name type:string default:-- desc:用户名【用户自己的】
- * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
- * @return name:content type:string default:-- desc:回复内容
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @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
- * @return name:parent_comment.is_deleted type:int default:-- desc:是否删除【0否,1,2删除】
- * @return name:parent_comment.show_title type:string default:-- desc:展示的问题标题或答案内容
- * @return name:parent_comment.reply_id type:int default:-- desc:答案id【值为0是问题类型,大于0是答案类型】
- *
- */
- public function getReplyForum()
- {
- $sel_where = [];
- $title = input('get.title');
- $type = input('get.type',1);
- if ($title) $sel_where[] = ['i.title|i.label', 'like', '%' . $title . '%'];
- $sel_where[] = ['t.user_id', '=', $this->user_id];
- $sel_where[] = ['c.user_id', '<>', $this->user_id];
- $sel_where[] = ['t.is_deleted', '=', 0];
- $sel_where[] = ['t.lev', '>=', 2];
- $sel_where[] = ['t.reply_id',$type == 1 ? '=' :'>',0];
- $list = ForumReplyComment::where($sel_where)
- ->alias('t')
- ->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')
- ->leftJoin('UserForum i', 't.forum_id = i.id')
- ->leftJoin('ForumReplyComment c', 'c.id = t.pid')
- ->order('t.id desc')
- ->limit($this->off_set, $this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['user_name'] = $this->user_info['name'];
- $v['headimg'] = $this->user_info['headimg'];
- $parent_comment = ForumReplyComment::where([['t.id', '=', $v['pid']]])
- ->field('t.id,t.is_top,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();
- if($v['reply_id']) {
- $reply_info = ForumReply::where('id', $v['reply_id'])->find()->toArray();
- $parent_comment['reply_user'] = $reply_info['user_id'];
- $parent_comment['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
- $parent_comment['show_title'] = ForumReply::where('id',$v['reply_id'])->value('content');
- }else{
- $parent_comment['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- $parent_comment['show_title'] = $parent_comment['title'];
- }
- $v['parent_comment'] = $parent_comment;
- }
- $total_num = ForumReplyComment::where($sel_where)->alias('t') ->leftJoin('UserForum i', 't.forum_id = i.id')
- ->leftJoin('ForumReplyComment c', 'c.id = t.pid')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- *
- * @title 点赞我的--问题
- * @desc 点赞我的
- * @author qc
- * @method GET
- * @url /api/Forum/praiseForumList
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数
- * @return name:id type:int default:-- desc:记录id
- * @return name:like_id type:int default:-- desc:问题id
- * @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:level type:int default:-- desc:VIP等级
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function praiseForumList()
- {
- $sel_where = [];
- $sel_where[] = ['p.type', '=', 10];
- $sel_where[] = ['f.user_id', '=', $this->user_id];
- $sel_where[] = ['p.user_id', '<>', $this->user_id];
- $sel_where[] = ['p.to_deleted', '=', 0];
- $list = PlatformLike::where($sel_where)
- ->field('p.*,f.title,u.name user_name,u.headimg,f.level')
- ->alias('p')
- ->leftJoin('UserForum f', 'f.id = p.like_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list, function (&$v) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['like_id'], 0, $this->request->controller());
- });
- $total_num = PlatformLike::where($sel_where)->alias('p')
- ->leftJoin('UserForum f', 'f.id = p.like_id')->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 点赞我的--答案
- * @desc 点赞我的
- * @author qc
- * @method GET
- * @url /api/Forum/praiseReplyList
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数
- * @return name:id type:int default:-- desc:记录id
- * @return name:content type:string default:-- desc:答案
- * @return name:level type:int default:-- desc:VIP等级
- * @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:is_normal type:int default:-- desc:是否是正常记录
- */
- public function praiseReplyList()
- {
- $sel_where = [];
- $sel_where[] = ['p.type', '=', 3];
- $sel_where[] = ['f.user_id', '=', $this->user_id];
- $sel_where[] = ['p.user_id', '<>', $this->user_id];
- $sel_where[] = ['p.to_deleted', '=', 0];
- /* PlatformLike::where($sel_where)->alias('p')->leftJoin('ForumReply f', 'f.id = p.like_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->update(['p.is_read'=>1]);*/
- $list = PlatformLike::where($sel_where)
- ->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')
- ->alias('p')
- ->leftJoin('ForumReply f', 'f.id = p.like_id')
- ->leftJoin('UserForum m', 'm.id = f.forum_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')
- ->limit($this->off_set,$this->page_num)
- ->order('p.id desc')
- ->select()->toArray();
- array_walk($list, function (&$v) {
- $v['is_normal'] = $v['to_deleted'] || $v['is_deleted'] ? 0 : 1;
- });
- $total_num = PlatformLike::where($sel_where)->alias('p')
- ->leftJoin('ForumReply f', 'f.id = p.like_id')->leftJoin('StoreMember u', 'u.id = p.user_id')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 点赞我的--评论
- * @desc 点赞我的
- * @author qc
- * @method GET
- * @url /api/Forum/praiseCommentList
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数
- * @return name:id type:int default:-- desc:记录id
- * @return name:title type:string default:-- desc:问题||答案内容
- * @return name:forum_id type:string default:-- desc:问题id
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:type type:int default:-- desc:1问题2答案
- * @return name:reply_id type:string default:-- desc:答案id(问题类型值为0)
- * @return name:reply_user type:string default:-- desc:回答会员id
- * @return name:content type:string default:-- desc:评论内容
- * @return name:create_at type:string default:-- desc:时间
- * @return name:self_name type:string default:-- desc:用户名称【自己的】
- * @return name:user_name type:string default:-- desc:会员名称【点赞人的】
- * @return name:headimg type:string default:-- desc:会员头像【点赞人的】
- * @return name:comment_normal type:int default:-- desc:评论是否正常
- * @return name:aim_normal type:int default:-- desc:问题或答案是否正常
- */
- public function praiseCommentList()
- {
- $sel_where = [];
- $sel_where[] = ['p.type', '=', 8];
- $sel_where[] = ['c.user_id', '=', $this->user_id];
- $sel_where[] = ['p.user_id', '<>', $this->user_id];
- $sel_where[] = ['p.to_deleted', '=', 0];
- /* PlatformLike::where($sel_where)->alias('p') ->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
- ->leftJoin('UserForum f', 'f.id = c.forum_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->update(['p.is_read'=>1]);*/
- $list = PlatformLike::where($sel_where)
- ->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')
- ->alias('p')
- ->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
- ->leftJoin('UserForum f', 'f.id = c.forum_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')
- ->limit($this->off_set,$this->page_num)
- ->order('p.create_at desc')
- ->select()->toArray();
- $self_name = User::where('id', $this->user_id)->value('name');
- array_walk($list, function (&$v) use ($self_name) {
- $v['type'] = $v['reply_id'] ? 2 : 1;
- $v['comment_normal'] = $v['to_deleted'] || $v['is_deleted'] || $v['source_deleted'] ? 0 : 1;
- if ($v['reply_id']) {
- $reply_info = ForumReply::where('id', $v['reply_id'])->find()->toArray();
- $v['reply_user'] = $reply_info['user_id'];
- $v['title'] = $reply_info['content'];
- $v['aim_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
- } else {
- $v['aim_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- }
- $v['self_name'] = $self_name;
- });
- $total_num = PlatformLike::where($sel_where)->alias('p')
- ->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
- ->leftJoin('UserForum f', 'f.id = c.forum_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')
- ->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 批量删除||批量取消
- * @desc 删除||取消
- * @author qc
- * @method POST
- * @url /api/Forum/batchesDel
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:string default:1 desc:记录id【多个用逗号隔开=>'1,2'】
- * @param name:type type:string default:1 desc:消息类型【1点赞我的,2回答我的,3回复我的,4评论我的,5我的点赞,6我的关注,7我的回答,8我的回复,9我的评论,10我的提问,11追番消息】
- */
- public function batchesDel()
- {
- $type = input('post.type',1);
- $id = input('post.id');
- if(!$id) $this->error('请选择要删除的记录');
- $del_where = [];
- $del_where[] = ['id','in',$id];
- if(in_array($type,[1])) PlatformLike::where($del_where)->update(['to_deleted'=>1]);
- if(in_array($type,[2])) ForumReply::where($del_where)->where(['issue_user'=>$this->user_id])->update(['to_deleted'=>1,'is_deleted'=>1,'is_read'=>1]);
- if(in_array($type,[2])){
- $reply = Db::name('forum_reply')->where($del_where)->where('issue_user',$this->user_id)->field('id,forum_id')->find();
- $count = Db::name('forum_reply')->where($del_where)->where('issue_user',$this->user_id)->count();
- UserForum::where('id',$reply['forum_id'])->setDec('r_num',$count);
- }
- if(in_array($type,[3,4])) ForumReplyComment::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
- if(in_array($type,[5])) PlatformLike::where($del_where)->where('user_id',$this->user_id)->delete();
- if(in_array($type,[6])) UserCollect::where($del_where)->where('user_id',$this->user_id)->where('coll_type',5)->delete();
- if(in_array($type,[7])) ForumReply::where($del_where)->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
- if(in_array($type,[7])){
- $reply = Db::name('forum_reply')->where($del_where)->where('user_id',$this->user_id)->field('id,forum_id')->find();
- $count = Db::name('forum_reply')->where($del_where)->where('user_id',$this->user_id)->count();
- UserForum::where('id',$reply['forum_id'])->setDec('r_num',$count);
- }
- if(in_array($type,[8,9])) ForumReplyComment::where($del_where)->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
- if(in_array($type,[10])){
- UserForum::where($del_where)->where('user_id',$this->user_id)->update(['is_deleted'=>1]);
- \app\common\model\TopSearch::saveData($id,'forum');
- UserForum::esAdd(input('id'));
- }
- if(in_array($type,[11])) UserMessage::where($del_where)->update(['is_deleted'=>1]);
- $this->success('操作成功');
- }
- /**
- * @title 消息已读&&未读变更
- * @desc 消息已读
- * @author qc
- * @method POST
- * @url /api/Forum/unreadChange
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:string default:-- desc:记录id(不传改全部的)
- * @param name:type type:int default:-- desc:1回答我的,2回复我的,3评论我的--问题,4评论我的--回答,5追番消息,6点赞我的--问题,7点赞我的--回答,8点赞我的--评论
- * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
- */
- public function unreadChange()
- {
- $type = input('post.type');
- $id = input('post.id');
- $is_read = input('post.is_read');
- switch ($type) {
- case 1:
- 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]);
- break;
- case 2 :
- $all_comment = ForumReplyComment::where(['user_id' => $this->user_id, 'is_deleted' => 0])->column('id');
- ForumReplyComment::where([['t.pid','in',implode(',',$all_comment)]])->when($id ,function ($query)use ($id){
- if($id) return $query->where('t.id','in',$id);})->alias('t')->update(['is_read'=>$is_read]);
- break;
- case 3:
- ForumReplyComment::alias('c')->where(['r.user_id' => $this->user_id,'c.reply_id'=>'0'])
- ->when($id ,function ($query)use ($id){
- if($id) return $query->where('c.id','in',$id);})
- ->leftJoin('UserForum r', 'c.forum_id = r.id')
- ->update(['c.is_read'=>$is_read]);
- break;
- case 4:
- ForumReplyComment::alias('c')->where('r.user_id' ,'=', $this->user_id)->where('reply_id','>',0)
- ->when($id ,function ($query)use ($id){
- if($id) return $query->where('c.id','in',$id);})
- ->leftJoin('ForumReply r', 'c.reply_id = r.id')
- ->update(['c.is_read'=>$is_read]);
- break;
- case 5:
- $where[] = ['user_id','=',$this->user_id];
- if($id) $where[] = ['id','in',$id];
- UserMessage::where($where)->update(['is_read'=>input('post.is_read')]);
- break;
- case 6:
- $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')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->column('p.id');
- PlatformLike::where('id','in' ,$ids )->update(['is_read'=>1]);
- break;
- case 7:
- $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')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->column('p.id');
- PlatformLike::where('id','in' ,$ids )->update(['is_read'=>1]);
- break;
- case 8:
- $ids = PlatformLike::where([['p.type', '=', 8],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('ForumReplyComment c', 'c.id = p.like_id')
- ->leftJoin('UserForum f', 'f.id = c.forum_id')
- ->leftJoin('StoreMember u', 'u.id = p.user_id')->column('p.id');
- PlatformLike::where('id','in' ,$ids )->update(['is_read'=>1]);
- break;
- }
- $this->success('操作成功');
- }
- /**
- * @title 浏览历史
- * @desc 浏览历史
- * @author qc
- * @method GET
- * @url /api/Forum/getForumTrack
- * @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:level type:int default:-- desc:vip等级id
- * @return name:content type:string default:0 desc:内容
- * @return name:create_at 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:comment_num type:int default:-- desc:评论量
- * @return name:reply_num type:int default:-- desc:回答量
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getForumTrack()
- {
- $sel_where = [];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.type','=',5];
- $title = input('get.title');
- if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
- $list = UserTrack::where($sel_where)
- ->alias('t')
- ->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')
- ->leftJoin('UserForum i','t.first_id = i.id')
- ->leftJoin('dd_store_member m','m.id = i.user_id')
- ->order('update_int desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- if(!$v['name']) $v['name'] = APPNAME;
- if(!$v['headimg']) $v['headimg'] = APPLOGO;
- $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
- $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- $v['reply_num'] = ForumReply::where(['forum_id' => $v['forum_id']])->where('is_deleted', 0)->count();
- });
- $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();
- $this->success('ok',['list'=>$list ,'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 我的点赞--问题
- * @desc 我的点赞
- * @author qc
- * @method GET
- * @url /api/Forum/getTagsForum
- * @header name:Authorization require:1 desc:Token
- * @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:level type:int default:-- desc:会员等级[0否]
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:like_num type:int default:-- desc:点赞量
- * @return name:user_name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像
- * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
- * @return name:is_normal type:int default:-- desc:是否能正常跳转
- * @return name:forum_id type:int default:-- desc:问题id
- */
- public function getTagsForum()
- {
- $list = PlatformLike::where([['l.user_id','=',$this->user_id],['l.type','=',10]])
- ->field('l.*,b.title,b.id forum_id,u.name user_name,u.headimg,b.level,b.content')
- ->alias('l')
- ->leftJoin('UserForum b','l.like_id = b.id')
- ->leftJoin('dd_store_member u','b.user_id = u.id')
- ->limit($this->off_set,$this->page_num)
- ->order('l.id desc')
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id, $v['forum_id'], 1);
- if(!$v['user_name']) $v['user_name']= $this->user_info['name'];
- if(!$v['headimg']) $v['headimg']= $this->user_info['headimg'];
- $comment_num = ForumReplyComment::where(['is_deleted' => 0, 'forum_id' => $v['forum_id'],'reply_id'=>0])->count();
- $v['comment_num'] = numTransform($comment_num);
- $v['like_num'] = PlatformLike::getPraiseNum($v['forum_id'],10);
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- });
- $total_num = PlatformLike::where([['user_id','=',$this->user_id],['type','=',10]])->count();
- $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 我的点赞--答案
- * @desc 我的点赞
- * @author qc
- * @method GET
- * @url /api/Forum/getTagsReply
- * @header name:Authorization require:1 desc:Token
- * @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:content type:string default:-- desc:答案内容
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:like_num type:int default:-- desc:点赞量
- * @return name:user_name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像
- * @return name:is_normal type:int default:-- desc:是否能正常跳转
- * @return name:forum_normal type:int default:-- desc:问答状态【0下架或删除,1正常】
- * @return name:reply_id type:int default:-- desc:答案id
- * @return name:forum_id type:int default:-- desc:问题id
- * @return name:level type:int default:-- desc:VIP等级
- * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
- */
- public function getTagsReply()
- {
- $list = PlatformLike::where([['l.user_id','=',$this->user_id],['b.user_id','<>',$this->user_id],['l.type','=',3]])
- ->field('l.*,b.id reply_id,u.name user_name,u.headimg,b.content,b.forum_id,m.level')
- ->alias('l')
- ->leftJoin('ForumReply b','l.like_id = b.id')
- ->leftJoin('UserForum m','m.id = b.forum_id')
- ->leftJoin('dd_store_member u','b.user_id = u.id')
- ->limit($this->off_set,$this->page_num)
- ->order('l.id desc')
- ->select()->toArray();
- array_walk($list,function (&$v){
- $comment_num = ForumReplyComment::where(['is_deleted' => 0,'reply_id'=>$v['reply_id']])->count();
- $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id, $v['forum_id'], 1);
- $v['comment_num'] = numTransform($comment_num);
- $v['like_num'] = PlatformLike::getPraiseNum($v['like_id'],3);
- $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
- $v['forum_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, 'forum');
- });
- $total_num = PlatformLike::where([['user_id','=',$this->user_id],['type','=',3]])->count();
- $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 我的点赞--评论
- * @desc 我的点赞
- * @author qc
- * @method GET
- * @url /api/Forum/getTagsComment
- * @header name:Authorization require:1 desc:Token
- * @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:content type:string default:-- desc:评论内容
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:like_num type:int default:-- desc:点赞量
- * @return name:user_name type:string default:-- desc:昵称
- * @return name:headimg type:string default:-- desc:头像
- * @return name:is_normal type:int default:-- desc:是否能正常跳转
- * @return name:reply_id type:int default:-- desc:答案id[等于0是问题,大于0是答案]
- * @return name:show_title type:string default:-- desc:展示的问题标题或答案内容
- * @return name:switch_open type:int default:-- desc:开关是否开启【0否1是】
- *
- */
- public function getTagsComment()
- {
- $list = PlatformLike::where([['l.user_id','=',$this->user_id],['b.user_id','<>',$this->user_id],['l.type','=',8]])
- ->field('l.*,b.id comment_id,u.name user_name,u.headimg,b.content,b.is_deleted,b.forum_id,b.reply_id')
- ->alias('l')
- ->leftJoin('ForumReplyComment b','l.like_id = b.id')
- ->leftJoin('dd_store_member u','b.user_id = u.id')
- ->order('l.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- $comment_num = ForumReplyComment::where(['is_deleted' => 0, 'forum_id'=>$v['forum_id'], 'reply_id'=>$v['reply_id']])->count();
- $v['comment_num'] = numTransform($comment_num);
- $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id, $v['forum_id'], 1);
- $v['like_num'] = PlatformLike::getPraiseNum($v['like_id'],8);
- $v['level'] = UserForum::where('id',$v['forum_id'])->value('level');
- if($v['reply_id']) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['reply_id'], 0, 'reply');
- $v['show_title'] = ForumReply::where('id',$v['reply_id'])->value('content');
- }else{
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- $v['show_title'] = UserForum::where('id',$v['forum_id'])->value('title');
- }
- });
- $total_num = PlatformLike::where([['l.user_id','=',$this->user_id],['l.type','=',8]])->alias('l')
- ->leftJoin('ForumReplyComment b','l.like_id = b.id')->count();
- $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 我的关注--问题
- * @desc 我的关注
- * @author qc
- * @method GET
- * @url /api/Forum/getCollectList
- * @header name:Authorization require:1 desc:Token
- * @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:reply_num type:int default:-- desc:回答量
- * @return name:browse_num type:int default:-- desc:浏览量
- * @return name:is_normal type:int default:-- desc:是否能正常跳转
- * @return name:forum_id type:int default:-- desc:问题id
- * @return name:level type:int default:-- desc:VIP等级
- */
- public function getCollectList()
- {
- $sel_where = [];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.coll_type','=',5];
- $list = UserCollect::where($sel_where)
- ->alias('t')
- ->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')
- ->leftJoin('UserForum i','t.coll_id = i.id')
- ->order('t.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- $v['browse_num'] = numTransform($v['browse_num']);
- $v['reply_num'] = ForumReply::where(['forum_id' => $v['forum_id']])->where('is_deleted', 0)->count();
- });
- $total_num = UserCollect::where($sel_where)
- ->alias('t') ->leftJoin('UserForum i','t.coll_id = i.id')->count();
- $this->success('ok', ['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 追番消息
- * @desc 追番消息
- * @author qc
- * @method GET
- * @url /api/Forum/getFollowUpMessage
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:int default:-- desc:搜索内容
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数
- *
- * @return name:id type:int default:-- desc:记录id
- * @return name:title type:string default:-- desc:标题
- * @return name:content type:string default:-- desc:内容
- * @return name:create_at type:string default:-- desc:时间
- * @return name:relation_id type:int default:-- desc:答案id
- * @return name:forum_id type:int default:-- desc:问题id
- * @return name:is_read type:int default:-- desc:是否已读【0否1是】
- * @return name:is_normal type:int default:-- desc:是否能正常跳转
- */
- public function getFollowUpMessage()
- {
- $title = input('title');
- $list = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'m.module'=>'forum','m.type_id'=>6])
- ->alias('m')
- ->when($title,function ($query)use ($title){
- if($title) $query->where('m.content','like','%'.$title.'%');})
- ->field('m.id,m.create_at,m.is_read,m.content,m.relation_id,m.module,m.children_id')
- ->limit($this->off_set,$this->page_num)
- ->order(['m.id'=>'desc'])
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['create_at'] = substr($v['create_at'],0,10);
- $v['forum_id'] = ForumReply::where('id',$v['relation_id'])->value('forum_id');
- $v['is_normal'] = CheckPower::checkModulesPower($v['forum_id'], 0, $this->request->controller());
- });
- $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();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- }
|