12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301 |
- <?php
- namespace app\api\controller;
- use app\common\model\ArticleItem;
- use app\common\model\DatumUrl;
- use app\common\model\PlatformSwitch;
- use app\common\model\PressComment;
- use app\common\model\PlatformLike;
- use app\common\model\TopSearch;
- use app\common\model\User;
- use app\common\model\UserCollect;
- use app\common\model\UserMessage;
- use app\common\model\UserReport;
- use app\common\model\UserSearch;
- use app\common\model\UserTrack;
- use app\common\model\VideoUrl;
- use app\common\service\CheckPower;
- use app\common\service\UserSynth;
- use library\tools\Data;
- use think\Db;
- /**
- * @title 新闻
- * @controller Press
- * @group base
- */
- class Press extends Base
- {
- // 需要登录的
- protected $need_login = [
- 'pressCollect',
- 'pressTransmit',
- 'pressReport',
- 'pressRead',
- 'PressTags',
- 'pressCommentTags',
- 'pressComment',
- 'pressSecondComment',
- 'getReplyComment',
- 'commentMyPress',
- 'getMyPressComment',
- 'getReplyPress',
- 'getPressCollect',
- 'getTagsPress',
- 'delComment',
- 'praiseMyPress',
- 'unreadChange',
- ];
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 新闻接口说明
- * @desc 新闻接口说明
- * @author qc
- * @url /api/Press/classIntro
- * @method GET
- * @return name:1 type:string default:-- desc:该模块没有视频!!
- */
- public function classIntro(){}
- /**
- * @title 新闻推荐
- * @desc 新闻推荐
- * @author qc
- * @method GET
- * @url /api/Press/getRecommendList
- * @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:images type:string default:-- desc:图片多张|隔开
- * @return name:images_arr type:array default:-- desc:图片多张[数组]
- * @return name:content type:string default:-- desc:详情
- * @return name:create_at type:string default:-- desc:时间
- * @return name:read_num type:int default:-- desc:阅读
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:praise_num type:int default:-- desc:点赞量
- * @return name:is_praise type:int default:-- desc:是否点赞
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- * @return name:release_time type:string default:-- desc:上架时间
- * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
- */
- public function getRecommendList()
- {
- $user_id = $this->user_id ? $this->user_id : input('rand_user');
- if(!$user_id) $this->error('参数错误');
- $list = UserSynth::getRecommendList($user_id,'press',$this->page,$this->page_num);
- if($list['code'] != 200) $this->error($list['msg']);
- $this->success('ok',$list);
- $search_log = UserSearch::getSearchTitle($this->user_id,4);
- $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.label,a.images,a.read_num,a.transmit_num,a.user_id,a.create_at,IFNULL(is_recommend,0) is_recommend ';
- $table = 'dd_press';
- $order_by_two = 'a.read_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 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){
- $v['read_num'] = numTransform($v['read_num']);
- $v['transmit_num'] = numTransform($v['transmit_num']);
- $v['label_name'] = $v['label']? explode(',',trim($v['label'],',')) : null;
- $v['images_arr'] = $v['images']? explode('|',trim($v['images'],'|')):null;
- $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $info_auth['app_name'];
- $v['app_logo'] = $info_auth['app_logo'];
- $v['comment_num'] = PressComment::getCommentNum($v['id']);
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['id']);
- $v['collect_num'] = UserCollect::getCollectNum(4,$v['id']);
- $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['id'],1);
- $v['praise_num'] = PlatformLike::getPraiseNum($v['id'],1);
- });
- $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 WHERE a.is_deleted = 0 AND a.status = 1 ORDER BY is_recommend DESC , $order_by_two desc ";
- $total = Db::query($sql2);
- $this->success('ok',['list'=>$list,'total_count'=>$total[0]['num'],'page_num'=>$this->page_num]);
- }
- /**
- * @title 获取新闻列表
- * @desc 获取新闻列表
- * @author qc
- * @method GET
- * @url /api/Press/getPressList
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:标题
- * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
- * @param name:page type:int default:0 desc:页数
- * @param name:page_num type:int default:20 desc:每页数
- * @return name:images type:string default:-- desc:图片多张|隔开
- * @return name:images_arr type:array default:-- desc:图片多张[数组]
- * @return name:content type:string default:-- desc:详情
- * @return name:create_at type:string default:-- desc:时间
- * @return name:read_num type:int default:-- desc:阅读
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:praise_num type:int default:-- desc:点赞量
- * @return name:is_praise type:int default:-- desc:是否点赞
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:release_time type:string default:-- desc:上架时间
- */
- public function getPressList(){
- $title = input('get.title');
- $sort_type = input('get.sort_type',1);
- switch ($sort_type) {
- case 1:
- $order = ['sort'=>'desc','read_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,4);
- $list = \app\common\model\Press::where(['is_deleted'=>0])
- ->field('id,images,title,content,read_num,create_at,transmit_num,user_id,release_time')
- ->when($title,function ($query)use($title){
- if($title) $query->where('title|label','like','%'.$title.'%');
- })->order($order)->limit($this->off_set,$this->page_num)->select()->toArray();
- foreach ($list as &$v) {
- $v['comment_num'] = PressComment::getCommentNum($v['id']);
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['id']);
- $v['collect_num'] = UserCollect::getCollectNum(4,$v['id']);
- $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['id'],1);
- $v['praise_num'] = PlatformLike::getPraiseNum($v['id'],1);
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $info_auth = \app\common\model\Press::getInfoAuth($this->user_id,APPNAME,APPLOGO);
- $v['app_name'] = $info_auth['app_name'];
- $v['app_logo'] = $info_auth['app_logo'];
- }
- $total_num = \app\common\model\Press::where(['is_deleted'=>0])
- ->field('id,images,title,content,read_num,create_at,transmit_num')
- ->when($title,function ($query)use($title){
- if($title) $query->where('title|label','like','%'.$title.'%');
- })->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 获取新闻详情
- * @desc 获取新闻详情
- * @author qc
- * @method GET
- * @url /api/Press/getPressDetail
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:新闻id
- * @return name:title type:string default:-- desc:标题
- * @return name:images type:string default:-- desc:图片多张|隔开
- * @return name:images_arr type:array default:-- desc:图片多张[数组]
- * @return name:content type:string default:-- desc:详情
- * @return name:create_at type:string default:-- desc:时间
- * @return name:read_num type:int default:-- desc:阅读
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:praise_num type:int default:-- desc:点赞量
- * @return name:is_praise type:int default:-- desc:是否点赞
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
- * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
- * @return name:goods_id type:int default:-- desc:供应商商品id
- * @return name:goods_jump type:int default:-- desc:供应商商品id否能跳转【0不能跳转,1能跳转】
- * @return name:release_time type:string default:-- desc:上架时间
- *
- * @return name:video_id type:int default:-- desc:视频系列id
- * @return name:video_item type:int default:-- desc:关联视频详情id【video_arr.id】
- * @return name:video_jump type:int default:-- desc:关联视频是否能跳转【0不能跳转,1能跳转,验证是否vip】
- *
- * @return name:article_id type:int default:-- desc:图文系列id
- * @return name:article_item type:int default:-- desc:关联图文详情id【item_list.id】
- * @return name:article_jump type:int default:-- desc:关联图文是否能跳转【0不能跳转,1能跳转,验证是否vip】
- * @return name:datum_id type:int default:-- desc:资料id--ppt【系列id】
- * @return name:datum_item type:int default:-- desc:资料id--ppt【系列下的其中一个】
- * @return name:datum_jump type:int default:-- desc:关联资料是否能跳转【0不能跳转,1能跳转,验证是否vip】
- */
- public function getPressDetail()
- {
- $sel_where[] = ['id','=',input('get.id')];
- $detail = \app\common\model\Press::field('id,images,supplier_id,goods_id,title,release_time,content,read_num,create_at,transmit_num,user_id,is_deleted,status,video_id,video_item,article_id,article_item,datum_id,datum_item')->where($sel_where)->find()->toArray();
- if($detail['is_deleted'] == 1 || $detail['status'] == 0) $this->error('该新闻已下架');
- $detail['comment_num'] = PressComment::where(['first_id'=>$detail['id'],'type'=>1,'is_deleted'=>0])->count();
- $detail['comment_num'] = numTransform($detail['comment_num']);
- $detail['transmit_num'] = numTransform($detail['transmit_num']);
- $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$detail['id']);
- $detail['collect_num'] = UserCollect::getCollectNum(4,$detail['id']);
- $detail['is_praise'] = PlatformLike::checkTags($this->user_id,$detail['id'],1);
- $detail['praise_num'] = PlatformLike::getPraiseNum($detail['id'],1);
- $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$detail['id'],10);
- $detail['article_jump'] = ArticleItem::checkVip($detail['article_item'],$this->user_id);
- $detail['video_jump'] = VideoUrl::checkVip($detail['video_item'],$this->user_id);
- $detail['datum_jump'] = DatumUrl::checkVip($detail['datum_item'],$this->user_id);
- $detail['goods_jump'] = CheckPower::checkModulesPower($detail['goods_id'], 0, 'supplier');
- $app_name = sysconf('app_name');
- $app_logo = sysconf('app_logo');
- if(!$detail['user_id']){
- $detail['app_name'] = $app_name;
- $detail['app_logo'] = $app_logo;
- }else{
- $user_info = User::where('id',$detail['user_id'])->field('name,headimg')->find();
- $detail['app_name'] = $user_info ? $user_info->name : '';
- $detail['app_logo'] = $user_info ? $user_info->headimg : '';
- }
- // \app\common\model\Press::where('id',$detail['id'])->setInc('read_num');
- UserTrack::crateTrack($this->user_id,4,input('get.id'),0);
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取新闻评论列表
- * @desc 获取新闻评论列表
- * @author qc
- * @method GET
- * @url /api/Press/getPressCommentList
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:新闻id
- * @param name:sort_type type:int default:1 desc:排序规则1时间2热点
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int 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是)
- * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
- * @return name:children type:array 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 getPressCommentList()
- {
- $where = [];
- $where[] = ['c.first_id','=',input('get.id')];
- $where[] = ['c.is_deleted','=',0];
- $where[] = ['c.type','=',1];
- $user_id = $this->user_id;
- $sort_type= input('sort_type',1);
- switch ($sort_type) {
- case 1:
- $order = ['c.is_top'=>'desc','c.id'=>'desc'];
- break;
- default:
- $order = ['c.is_top'=>'desc','c.like_times'=>'desc'];
- break;
- }
- $list =PressComment::where($where)
- ->alias('c')
- ->field('c.*,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->order($order)
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$val,$k)use($user_id){
- $children = PressComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
- ->alias('c')->field('c.*,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->order('c.is_top desc,c.id asc')
- ->select()->toArray();
- $val['children'] = $children ? $children : null;
- $val['like_num'] = PlatformLike::getPraiseNum($val['id'],2);
- $val['is_like'] = PlatformLike::checkTags($user_id,$val['id'],2);
- $parent = PressComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
- ->alias('c')->field('c.*,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->find();
- $val['parent'] = $parent ? $parent->toArray() : null;
- $val['parent_comment'] = $val['parent'] ;
- });
- $total_num = PressComment::where($where) ->leftJoin('store_member u','u.id = c.user_id')->alias('c')->count();
- $this->success('ok',['list'=>$list,'total_num'=>numTransform($total_num),'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 以下接口调用验证登录【需要header传Authorization】
- * @desc 以下接口调用验证登录
- * @author qc
- * @method
- * @url /api/Press/needLogin()
- */
- public function needLogin(){}
- /**
- * @title 删除评论
- * @desc 删除评论
- * @author qc
- * @method POST
- * @url /api/Press/delComment
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:评论id
- */
- public function delComment(){
- PressComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
- $this->success('删除成功');
- }
- /**
- * @title 收藏||取消收藏
- * @desc 用户收藏
- * @author qc
- * @method POST
- * @url /api/Press/pressCollect
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int require:1 default:-- desc:新闻id
- * @return name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
- */
- public function pressCollect(){
- $coll_status = UserCollect::plateCollect($this->user_id,4,input('post.id',0));
- $coll_status ? $this->success('收藏成功',['status'=>1]) : $this->success('取消收藏成功',['status'=>0]);
- }
- /**
- * @title 新闻转发(转发数量统计)
- * @desc 转发成功后调用
- * @author qc
- * @method POST
- * @url /api/Press/pressTransmit
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:新闻id
- */
- public function pressTransmit()
- {
- $press_id = input('post.id',0);
- \app\common\model\Press::where('id',$press_id)->setInc('transmit_num');
- $this->success('ok');
- }
- /**
- * @title 新闻举报
- * @desc 新闻举报
- * @author qc
- * @url /api/Press/pressReport
- * @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 pressReport()
- {
- $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,7,$report_id,$case_ids);
- $this->success('举报成功');
- }
- /**
- * @title 新闻阅读(阅读数量统计)
- * @desc 新闻阅读
- * @author qc
- * @method POST
- * @url /api/Press/pressRead
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:新闻id
- */
- public function pressRead()
- {
- $press_id = input('post.id',0);
- \app\common\model\Press::where('id',$press_id)->setInc('read_num');
- if($this->user_id){
- TopSearch::seIncHotNum($press_id,$this->request->controller());
- }
- $this->success('ok');
- }
- /**
- * @title 新闻点赞||取消点赞
- * @desc 点赞||取消点赞
- * @author qc
- * @method POST
- * @url /api/Press/PressTags
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:新闻id
- * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
- */
- public function pressTags()
- {
- $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),1);
- $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
- }
- /**
- * @title 新闻评论点赞||取消点赞
- * @desc 新闻评论点赞
- * @author qc
- * @method POST
- * @url /api/Press/pressCommentTags
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:评论id
- * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
- */
- public function pressCommentTags()
- {
- $ret_val = PlatformLike::userTags($this->user_id,input('post.id'),2);
- if($ret_val == 1){
- PressComment::where('id',input('post.id'))->setInc('like_times');
- }else{
- PressComment::where('id',input('post.id'))->setDec('like_times');
- }
- $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
- }
- /**
- * @title 新闻评论
- * @desc 新闻评论
- * @author qc
- * @method POST
- * @url /api/Press/pressComment
- * @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:create_at type:string default:-- desc:时间
- */
- public function pressComment()
- {
- $id = input('post.id');
- $content = input('post.content',0);
- if(!$content) $this->error('请输入评论内容');
- $comment_info = \app\common\model\Press::where('id',$id)->find()->toArray();
- if(!$comment_info['comment_switch']) $this->error('评论功能已关闭');
- $res = PressComment::create(['user_id'=>$this->user_id,'content'=>$content,'first_id'=>$id,'type'=>1]);
- $detail =PressComment::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();
- if($comment_info['user_id'] && $this->user_id != $comment_info['user_id'])UserMessage:: sendUserMessage($comment_info['user_id'],'press',2,0,$this->user_id,$detail['id'],$content);
- $this->success('评论成功',['detail'=>$detail]);
- }
- /**
- * @title 新闻二级评论
- * @desc 新闻二级评论
- * @author qc
- * @method POST
- * @url /api/Press/pressSecondComment
- * @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 pressSecondComment()
- {
- $comment = PressComment::where('id',input('post.id'))->find()->toArray();
- $user_info = $this->userInfo('name');
- if($comment['user_id'] != $this->user_id)UserMessage::sendUserMessage($comment['user_id'],'press',1,0,$this->user_id,$comment['id'],input('post.content'));
- 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 = PressComment::create($comment);
- $detail = PressComment::where('p.id',$res->id)
- ->alias('p')
- ->field('p.id,p.content,p.is_top,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 GET
- * @url /api/Press/getMarkNum
- * @header name:Authorization require:1 desc:Token
- * @return name:reply_num type:int default:-- desc:未读量--回复我的
- * @return name:comment_num type:int default:-- desc:未读量--评论我的
- * @return name:total_num type:int default:-- desc:总数【reply_num+comment_num】
- * @return name:praise_press type:int default:-- desc:点赞我的--新闻
- * @return name:praise_comment type:int default:-- desc:点赞我的--评论
- * @return name:praise_num type:int default:-- desc:点赞我的--新闻+评论
- */
- public function getMarkNum()
- {
- // 评论我的
- $comment_num = PressComment::where([['t.is_deleted','=',0],['t.pid','=',0],['i.user_id','=',$this->user_id],['is_read','=',0],['t.user_id','<>',$this->user_id]])
- ->leftJoin('Press i','t.first_id = i.id')
- ->alias('t')->count();
- // 回复我的
- $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- $reply_num = PressComment::where([['t.is_deleted','=',0],['t.lev','>=',2],['is_read','=',0],['t.pid','in',implode(',',$all_comment)],['t.user_id','<>',$this->user_id]])->alias('t')->count();
- $total_num = $comment_num + $reply_num ;
- $praise_press = PlatformLike::where([['p.type', '=', 1],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p') ->leftJoin('Press f', 'f.id = p.like_id')->count();
- $praise_comment = PlatformLike::where([['p.type', '=', 2],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0],['p.user_id','<>',$this->user_id]])->alias('p')->leftJoin('PressComment c', 'c.id = p.like_id')->count();
- $praise_num = $praise_press + $praise_comment;
- $this->success('ok',compact(['reply_num','comment_num','total_num','praise_num','praise_press','praise_comment']));
- }
- /**
- * @title 消息已读&&未读变更
- * @desc 支持批量选择
- * @author qc
- * @method POST
- * @url /api/Press/unreadChange
- * eadChange
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:string default:-- desc:记录id(多个逗号隔开,不传修改全部])
- * @param name:type type:string default:1 desc:消息类型【1评论我的,2回复我的,3点赞我的--新闻,4点赞我的-评论】
- * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
- */
- public function unreadChange()
- {
- $type = input('post.type',1);
- $id = input('post.id');
- $is_read = input('post.is_read',0);
- $where = [];
- switch ($type)
- {
- case 1:
- PressComment::where([['i.user_id','=',$this->user_id]])
- ->when($id ,function ($query)use ($id){
- if($id) return $query->where('t.id','in',$id);
- })->leftJoin('Press i','t.first_id = i.id')
- ->alias('t') ->update(['source_read'=>$is_read,'t.is_read'=>$is_read]);
- break;
- case 2:
- $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- PressComment::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:
- $ids = PlatformLike::where([['p.type', '=', 1],['f.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p') ->leftJoin('Press f', 'f.id = p.like_id')->column('p.id');
- PlatformLike::where('id','in' ,$ids)->update(['is_read'=>1]);
- break;
- case 4:
- $ids2 = PlatformLike::where([['p.type', '=', 2],['c.user_id', '=', $this->user_id],['p.to_deleted', '=', 0],['p.is_read','=',0]])->alias('p')->leftJoin('PressComment c', 'c.id = p.like_id')->column('p.id');
- PlatformLike::where('id','in' ,$ids2)->update(['is_read'=>1]);
- break;
- }
- // PressComment::where('id',input('post.id'))->update(['is_read'=>1]);
- $this->success('消息变更成功');
- }
- /**
- * @title 回复我的【回复我的--回复过我的评论】
- * @desc 回复我的
- * @author qc
- * @method GET
- * @url /api/Press/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:cover type:string default:-- desc:封面
- * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
- * @return name:images_arr type:array default:-- desc:图片【多张】
- * @return name:create_at type:string default:-- desc:时间
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- * @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: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.title type:string default:-- desc:标题
- * @return name:parent_comment.press_id type:string default:-- desc:新闻id
- * @return name:parent_comment.app_name type:string default:-- desc:发布方名称
- * @return name:parent_comment.app_logo type:string default:-- desc:发布方头像
- * @return name:parent_comment.read_num type:string default:-- desc:阅读量
- */
- public function getReplyComment()
- {
- $all_comment = PressComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- if(empty($all_comment)) $this->success('ok',['list'=>null,'total_count'=>0,'page_num'=>$this->page_num]);
- $sel_where = [];
- $title = input('get.title');
- if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
- $sel_where[] = ['t.is_deleted','=',0];
- $sel_where[] = ['t.lev','>=',2];
- $sel_where[] = ['t.to_deleted','=',0];
- $sel_where[] = ['t.user_id','<>',$this->user_id];
- $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
- $list = PressComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.is_top,t.is_read,t.create_at,t.first_id press_id,t.lev,t.content,t.pid,u.name user_name,u.headimg,i.cover,i.images,i.read_num')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->leftJoin('Press i','t.first_id = i.id')
- ->order('t.is_top desc,t.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['self_name'] = $this->user_info['name'];
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
- ->field('t.id,t.first_id press_id,t.is_top,t.content,i.title,i.cover,t.pid,u.name,i.user_id,i.read_num')
- ->alias('t')
- ->leftJoin('Press i','t.first_id = i.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->find()->toArray();
- $parent_comment['images_arr'] =$v['images_arr'];
- $parent_comment['read_num'] = numTransform($v['read_num']);
- $info_auth = \app\common\model\Press::getInfoAuth($parent_comment['user_id'],APPNAME,APPLOGO);
- $parent_comment['app_name'] = $info_auth['app_name'];
- $parent_comment['app_logo'] = $info_auth['app_logo'];
- $v['parent_comment'] = $parent_comment;
- }
- $total_num = PressComment::where($sel_where)->alias('t')->leftJoin('store_member u','t.user_id = u.id')->leftJoin('Press i','t.first_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/Press/commentMyPress
- * @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:press_id type:string default:-- desc:新闻id
- * @return name:cover 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: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:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- * @return name:content type:string default:-- desc:评论内容
- * @return name:read_num type:string default:-- desc:阅读量
- */
- public function commentMyPress()
- {
- $sel_where = [];
- $title = input('get.title');
- if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
- $sel_where[] = ['t.is_deleted','=',0];
- $sel_where[] = ['i.user_id','=',$this->user_id];
- $sel_where[] = ['t.pid','=',0];
- $sel_where[] = ['t.to_deleted','=',0];
- $sel_where[] = ['t.user_id','<>',$this->user_id];
- $list = PressComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.is_read,t.is_top,t.create_at,t.first_id press_id,t.content,i.images,i.title,i.cover,u.name user_name,u.headimg,i.read_num')
- ->leftJoin('Press i','t.first_id = i.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->order('t.is_top desc,t.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $user_info = $this->userInfo();
- array_walk($list,function (&$v)use ($user_info){
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $v['app_name'] = $user_info['name'];
- $v['app_logo'] = $user_info['headimg'];
- $v['read_num'] = numTransform($v['read_num']);
- });
- $total_num = PressComment::where($sel_where)->alias('t') ->leftJoin('Press i','t.first_id = i.id')
- ->leftJoin('store_member u','t.user_id = u.id')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 我的评论
- * @desc 我的评论
- * @author qc
- * @method GET
- * @url /api/Press/getMyPressComment
- * @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:press_id type:string default:-- desc:新闻id
- * @return name:cover type:string default:-- desc:封面
- * @return name:images_arr type:array 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:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getMyPressComment()
- {
- $where = [];
- $where[] = ['t.is_deleted','=',0];
- $where[] = ['t.type','=',1];
- $where[] = ['t.user_id','=',$this->user_id];
- $where[] = ['t.pid','=',0];
- $title = input('get.title');
- if($title) $where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
- $list = PressComment::where($where)
- ->alias('t')
- ->field('t.id,t.is_top,t.create_at,t.first_id press_id,i.images,t.content,i.title,i.cover,u.name user_name,u.headimg,i.read_num,i.user_id iuid')
- ->leftJoin('Press i','t.first_id = i.id')
- ->leftJoin('store_member u','u.id = t.user_id')
- ->order('t.is_top desc,id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
- $v['read_num'] = numTransform($v['read_num']);
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- // $parent_comment = PressComment::where($where)
- // ->alias('t')
- // ->field('t.id,t.is_top,t.create_at,t.first_id press_id,i.images,t.content,i.title,i.cover,u.name user_name,u.headimg,i.read_num,i.user_id')
- // ->leftJoin('Press i','t.first_id = i.id')
- // ->leftJoin('store_member u','u.id = t.user_id')
- // ->order('t.is_top desc,id desc')
- // ->limit($this->off_set,$this->page_num)
- // ->find()->toArray();
- $info_auth = \app\common\model\Press::getInfoAuth($v['iuid'],APPNAME,APPLOGO);
- $v['app_name'] = $info_auth['app_name'];
- $v['app_logo'] = $info_auth['app_logo'];
- }
- $total_num = PressComment::where($where)
- ->alias('t') ->leftJoin('Press i','t.first_id = i.id')
- ->leftJoin('store_member u','u.id = t.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/Press/getReplyPress
- * @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:press_id type:int default:-- desc:新闻id
- * @return name:cover type:string default:-- desc:封面
- * @return name:images_arr type:array default:-- desc:图片多张[数组]
- * @return name:create_at type:string default:-- desc:时间
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @return name:user_name type:string default:-- desc:用户名【用户自己的】
- * @return name:headimg 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.title type:string default:-- desc:新闻标题
- * @return name:parent_comment.press_id type:string default:-- desc:新闻id
- * @return name:parent_comment.app_name type:string default:-- desc:发布方名称
- * @return name:parent_comment.app_logo type:string default:-- desc:发布方头像
- * @return name:parent_comment.read_num type:string default:-- desc:阅读量
- */
- public function getReplyPress()
- {
- $user_info = $this->userInfo();
- $sel_where = [];
- $title = input('get.title');
- if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.is_deleted','=',0];
- $sel_where[] = ['t.source_deleted','=',0];
- $sel_where[] = ['t.lev','>=',2];
- $list = PressComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.is_top,t.create_at,t.first_id press_id,t.lev,t.content,t.pid,i.title,i.cover,images,read_num')
- ->leftJoin('Press i','t.first_id = i.id')
- ->order('t.is_top,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'];
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $parent_comment = PressComment::where([['t.id','=',$v['pid']]])
- ->field('t.id,t.is_top,t.first_id press_id,t.content,i.title,i.cover,i.images,t.pid,u.name,i.read_num,i.user_id')
- ->alias('t')
- ->leftJoin('Press i','t.first_id = i.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->find()->toArray();
- $parent_comment['read_num'] = numTransform($v['read_num']);
- $parent_comment['images_arr'] = $parent_comment['images'] ? explode('|',$parent_comment['images']) : null;
- $info_auth = \app\common\model\Press::getInfoAuth($parent_comment['user_id'],APPNAME,APPLOGO);
- $parent_comment['app_name'] = $info_auth['app_name'];
- $parent_comment['app_logo'] = $info_auth['app_logo'];
- $v['parent_comment'] = $parent_comment;
- }
- $total_num = PressComment::where($sel_where)->alias('t')->leftJoin('Press i','t.first_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/Press/getPressCollect
- * @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:press_id type:string default:-- desc:新闻id
- * @return name:cover type:string default:-- desc:封面
- * @return name:create_at type:string default:-- desc:时间
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:praise_num type:int default:-- desc:点赞量
- * @return name:is_praise type:int default:-- desc:是否点赞
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getPressCollect()
- {
- $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.coll_type','=',4];
- $list = UserCollect::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.coll_id press_id,i.title,images,i.user_id,i.transmit_num,i.read_num')
- ->leftJoin('Press i','t.coll_id = i.id')
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $v['comment_num'] = PressComment::getCommentNum($v['press_id']);
- $v['collect_num'] = UserCollect::getCollectNum(4,$v['press_id']);
- $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['press_id'],1);
- $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);
- $v['transmit_num'] =numTransform($v['transmit_num']);
- $v['read_num'] =numTransform($v['read_num']);
- $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);
- $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['press_id'],10);
- $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $info_auth['app_name'];
- $v['app_logo'] = $info_auth['app_logo'];
- }
- $total_num = UserCollect::where($sel_where)->alias('t')
- ->leftJoin('Press 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/Press/getTagsPress
- * @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:press_id type:string default:-- desc:新闻id
- * @return name:cover type:string default:-- desc:封面
- * @return name:create_at type:string default:-- desc:时间
- *
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:praise_num type:int default:-- desc:点赞量
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getTagsPress()
- {
- $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.type','=',1];
- $list = PlatformLike::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.like_id press_id,i.title,i.cover,images,transmit_num,i.read_num,comment_switch,i.user_id')
- ->leftJoin('Press i','t.like_id = i.id')
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['transmit_num'] = numTransform($v['transmit_num']);
- $v['read_num'] = numTransform($v['read_num']);
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $v['comment_num'] = PressComment::getCommentNum($v['press_id']);
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,4,$v['press_id']);
- $v['collect_num'] = UserCollect::getCollectNum(4,$v['press_id']);
- $v['is_praise'] = PlatformLike::checkTags($this->user_id,$v['press_id'],1);
- $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
- $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $info_auth['app_name'];
- $v['app_logo'] = $info_auth['app_logo'];
- }
- $total_num = PlatformLike::where($sel_where)->alias('t')->leftJoin('Press i','t.like_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/Press/getPressTrack
- * @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:press_id type:string default:-- desc:新闻id
- * @return name:images_arr type:array default:-- desc:封面
- * @return name:cover type:string default:-- desc:封面
- * @return name:create_at type:string default:-- desc:时间
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getPressTrack()
- {
- $sel_where = [];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.type','=',4];
- $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,t.first_id press_id,i.title,i.cover,i.images,i.read_num,i.user_id')
- ->leftJoin('Press i','t.first_id = i.id')
- ->order('update_int desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['cover'] = $v['images_arr'] ? $v['images_arr'][0] : null;
- $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
- $v['read_num'] = numTransform($v['read_num']);
- $info_auth = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $info_auth['app_name'];
- $v['app_logo'] = $info_auth['app_logo'];
- /* $v['comment_num'] = PressComment::where(['first_id'=>$v['press_id'],'type'=>1,'is_deleted'=>0])->count();
- $v['collect_num'] = UserCollect::getCollectNum(4,$v['press_id']);
- $v['praise_num'] = PlatformLike::getPraiseNum($v['press_id'],1);*/
- }
- $total_num = UserTrack::where($sel_where)->alias('t')->leftJoin('Press i','t.first_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/Press/praiseMyPress
- * @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:create_at type:string default:-- desc:时间
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:images type:string default:-- desc:图片多张|隔开
- * @return name:images_arr type:array 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:like_id type:string default:-- desc:新闻id
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- */
- public function praiseMyPress()
- {
- $user_info = $this->userInfo('name,headimg');
- $sel_where = [];
- $sel_where[] = ['p.type', '=', 1];
- $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.images,f.read_num,f.content')
- ->alias('p')
- ->leftJoin('Press 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) use ($user_info){
- $v['is_normal'] = CheckPower::checkModulesPower($v['like_id'], 0, $this->request->controller());
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['app_name'] = $user_info['name'];
- $v['app_logo'] = $user_info['headimg'];
- $v['read_num'] = numTransform($v['read_num']);
- });
- $total_num = PlatformLike::where($sel_where)->alias('p')->leftJoin('Press 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/Press/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:press_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:self_name type:string default:-- desc:用户名称【自己的】
- * @return name:content type:string default:-- desc:评论内容
- * @return name:press_content type:string default:-- desc:新闻内容
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:images type:string default:-- desc:图片多张|隔开
- * @return name:images_arr type:array default:-- desc:图片多张[数组]
- * @return name:comment_normal type:int default:-- desc:评论是否正常
- */
- public function praiseCommentList()
- {
- $user_info = $this->userInfo('name,headimg');
- $list = PlatformLike::where([['l.type','=',2],['c.user_id','=',$this->user_id],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
- ->alias('l')
- ->field('l.id,l.user_id,m.name user_name,m.headimg,c.is_deleted,c.to_deleted,c.source_deleted,l.create_at,v.images,c.first_id press_id,v.user_id buid,v.title,v.read_num,c.content,v.content press_content,v.comment_switch')
- ->leftJoin('StoreMember m','m.id = l.user_id')
- ->leftJoin('PressComment c','c.id = l.like_id')
- ->leftJoin('Press v','v.id = c.first_id')
- ->order('l.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v,$k)use ($user_info){
- $info_auth = \app\common\model\Press::getInfoAuth($v['buid'],APPNAME,APPLOGO);
- $v['app_name'] = $info_auth['app_name'];
- $v['app_logo'] = $info_auth['app_logo'];
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $v['read_num'] = numTransform($v['read_num']);
- $v['self_name'] = $user_info['name'];
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['comment_normal'] = $v['to_deleted'] || $v['is_deleted'] || $v['source_deleted'] ? 0 : 1;
- });
- $total_num = PlatformLike::where([['l.type','=',2],['c.user_id','=',$this->user_id],['l.to_deleted','=',0]])->alias('l') ->leftJoin('StoreMember m','m.id = l.user_id')
- ->leftJoin('PressComment c','c.id = l.like_id')
- ->leftJoin('Press v','v.id = c.first_id')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 批量删除||批量取消
- * @desc 删除||取消
- * @author qc
- * @method POST
- * @url /api/Press/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我的回复】
- */
- 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,'is_read'=>1]);
- if(in_array($type,[2])) PressComment::where($del_where)->where(['user_id'=>$this->user_id])->update(['is_deleted'=>1]);
- if(in_array($type,[3,4])) PressComment::where($del_where)->update(['to_deleted'=>1,'is_read'=>1,'source_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',4)->delete();
- if(in_array($type,[7])) PressComment::where($del_where)->where('user_id',$this->user_id)->update(['source_deleted'=>1]);
- $this->success('删除成功');
- }
- /**
- * @title 我的发布
- * @desc 我的发布
- * @author qc
- * @method GET
- * @url /api/Press/getMyPressList
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:-- desc:页数
- * @param name:page_num type:int default:-- desc:每页数
- * @param name:title type:string default:-- 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:label_name type:array default:-- desc:标签
- * @return name:images_arr type:array default:-- desc:图片
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getMyPressList()
- {
- $where = [];
- $where[] = ['user_id','=',$this->user_id];
- $where[] = ['is_deleted','=',0];
- $where[] = ['status','=',1];
- $title = input('get.title');
- if ($title) $where[] = ['name', 'like', '%' . $title . '%'];
- $list = \app\common\model\Press::field('id,title,label,create_at,images')->where($where)->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['images_arr'] = $v['images'] ? explode('|',$v['images']) : null;
- $v['label_name'] = $v['label'] ? explode(',', trim($v['label'], ',')) : null;
- $v['is_normal'] = CheckPower::checkModulesPower($v['id'],0,$this->request->controller());
- });
- $total_num =\app\common\model\Press::where($where)->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- /**
- * @title 我的点赞--评论
- * @desc 评论点赞列表
- * @author qc
- * @method GETapi/Press/getTagsComment
- * @url /
- * @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:create_at type:string default:-- desc:时间
- * @return name:self_name type:string default:-- desc:会员名称【自己的】
- * @return name:self_headimg type:string default:-- desc:会员头像【自己的】
- * @return name:comment_user type:string default:-- desc:会员名称【评论人】
- * @return name:images type:string default:-- desc:图片多张|隔开
- * @return name:images_arr type:array default:-- desc:图片多张[数组]
- * @return name:content type:string default:-- desc:评论内容
- * @return name:cover type:string default:-- desc:封面
- * @return name:title type:string default:-- desc:标题
- * @return name:read_num type:string default:-- desc:浏览量
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @return name:app_name type:string default:-- desc:发布方名称
- * @return name:app_logo type:string default:-- desc:发布方头像
- */
- public function getTagsComment()
- {
- $list = PlatformLike::field('l.id,c.content,g.read_num,g.images,g.cover,u.name comment_user,g.user_id,l.create_at,g.title,g.id press_id,c.user_id cuid,l.like_id')
- ->alias('l')
- ->where(['l.user_id'=>$this->user_id,'l.type'=>2])
- ->where('c.user_id','<>',$this->user_id)
- ->leftJoin('PressComment c','l.like_id = c.id')
- ->leftJoin('Press g','g.id = c.first_id')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->order('l.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $user_info = $this->userInfo();
- foreach ($list as &$v) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['press_id'],0,$this->request->controller());
- $auth_info = \app\common\model\Press::getInfoAuth($v['user_id'],APPNAME,APPLOGO);
- $user_infos = User::where('id',$v['cuid'])->field('name,headimg')->find();
- $v['app_name'] = $auth_info['app_name'];
- $v['app_logo'] = $auth_info['app_logo'];
- $v['read_num'] = numTransform($v['read_num']);
- $v['self_name'] = $user_info['name'];
- $v['self_headimg'] = $user_info['headimg'];
- $v['images_arr'] = $v['images']? explode('|',trim($v['images'],'|')):null;
- //返回一下headimg和user_name,类似视频图文资料
- //我的点赞评论
- $v['user_name'] = $user_infos['name'];
- $v['headimg'] = $user_infos['headimg'];
- }
- $total_num =PlatformLike::alias('l')
- ->where(['l.user_id'=>$this->user_id,'l.type'=>2])
- ->where('c.user_id','<>',$this->user_id)
- ->leftJoin('PressComment c','l.like_id = c.id')
- ->leftJoin('Press g','g.id = c.first_id')
- ->leftJoin('store_member u','u.id = c.user_id')->count();
- $this->success('ok', ['list' => $list, 'total_count' => $total_num, 'page_num' => $this->page_num]);
- }
- }
|