1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801 |
- <?php
- namespace app\api\controller;
- use app\common\model\ArticleItem;
- use app\common\model\DatumCate;
- use app\common\model\DatumComment;
- use app\common\model\DatumCommentLike;
- use app\common\model\DatumIntro;
- use app\common\model\DatumLike;
- use app\common\model\DatumUrl;
- use app\common\model\PlatformSwitch;
- use app\common\model\TopSearch;
- use app\common\model\User;
- use app\common\model\UserCollect;
- use app\common\model\UserDatum;
- use app\common\model\UserDownload;
- use app\common\model\UserLearn;
- use app\common\model\UserLevelRank;
- use app\common\model\UserMessage;
- use app\common\model\UserSearch;
- use app\common\model\UserTrack;
- use app\common\service\CheckPower;
- use app\common\service\UserSynth;
- use library\tools\Data;
- use think\Db;
- /**
- * @title 资料
- * @controller Datum
- * @group base
- */
- class Datum extends Base
- {
- // 需要登录的
- protected $need_login = [
- 'datumTransmit',
- 'datumDownload',
- 'datumRead',
- 'datumCollect',
- 'datumTags',
- 'userReferDatum',
- 'getMyDatumList',
- 'getUserDatumDetail',
- 'delUserDatum',
- 'getDownloadDatum',
- 'getLearnHistory',
- 'getDatumCollect',
- 'getBoundList',
- 'getFollowUpList',
- 'secondCommend',
- 'praiseMyDatumList',
- 'datumComment',
- 'delComment',
- 'batchesDel',
- 'commentTags',
- 'unreadChange',
- 'getFollowUpMessage',
- 'praiseMyComment',
- 'getReplyComment',
- 'commentMyDatum',
- 'getTagsDatum',
- 'getTagsComment',
- 'getReplyDatum',
- 'getCommentDatum',
- 'getDatumItemInfo', //1.5新增
- 'getDatumDetail', //1.5新增
- ];
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- $this->source_type= $this->request->header('source_type',1);
- }
- /**
- * @title 资料接口说明
- * @desc 资料接口说明
- * @author qc
- * @url /api/Datum/classIntro
- * @method GET
- * @return name:1 type:string default:-- desc:单一资料与系列资料区别,type值(1是单一,2是系列),数据:url_arr二维数组数据数量不一样(单一的只有一个,系列的可以是多个)【可以将单一资料看做只有一条记录的系列资料!!!!】
- * @return name:2 type:string default:-- desc:单一资料详情的字段(除id)与url_arr数组的第一个同字段名的值相同
- * @return name:3 type:string default:-- desc:系列资料详情的字段(除id)与url_arr数组的其中一个同字段名的值相同
- * @return name:4 type:string default:-- desc:关于是否的字段(0否,1是)
- * @return name:5 type:string default:-- desc:url_id是详情或列表url_arr下的id
- */
- public function classIntro(){ }
- /**
- * @title 获取资料目录
- * @desc 获取资料目录
- * @author qc
- * @url /api/Datum/getDatumCate
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:id
- * @return name:title type:string default:0 desc:名称
- * @return name:datum_list type:array default:0 desc:目录下的资料
- * @return name:datum_list.id type:int default:0 desc:资料记录
- * @return name:datum_list.title type:int default:0 desc:资料标题
- */
- public function getDatumCate()
- {
- $list = DatumCate::field('id,title')->where('is_deleted',0)->where('status',1)->select()->toArray();
- foreach ($list as &$v) {
- $v['datum_list'] = DatumIntro::field('id,title')
- ->where(['datum_cate'=>$v['id'],'status'=>1,'is_deleted'=>0])->select()->toArray();
- }
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 资料推荐
- * @desc 资料推荐
- * @author qc
- * @method GET
- * @url /api/Datum/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:id type:string default:-- desc:资料item_id
- * @return name:title type:string default:-- desc:标题
- * @return name:datum_id type:string default:-- desc:系列id
- * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:down_num type:int default:-- desc:下载量
- * @return name:url type:int default:-- desc:资料路径
- * @return name:app_name type:string default:-- desc:发布者
- * @return name:app_logo type:string default:-- desc:发布者头像
- * @return name:create_at type:string default:-- desc:时间
- * @return name:is_down type:int default:-- desc:是否能下载(0否1是)
- * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
- * @return name:pdf_clear type:string default:-- desc:资料未加密路径【is_encrypt=1时用】
- * @return name:is_release type:int default:-- desc:是否释放【0否1是】,已释放不需要购买vip
- * @return name:release_time type:string default:-- desc:上架时间
- */
- public function getRecommendList()
- {
- $user_id = $this->user_id ? $this->user_id : input('rand_user');
- if(!$user_id) $this->error('参数错误');
- $list = UserSynth::getRecommendList($user_id,'datum',$this->page,$this->page_num);
- if($list['code'] != 200) $this->error($list['msg']);
- $this->success('ok',$list);
- $search_log = UserSearch::getSearchTitle($this->user_id,3);
- $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.user_id,a.create_at,a.down_num,a.read_num,a.is_vip,a.datum_id,a.url ,a.is_encrypt,a.pdf_clear,IFNULL(is_recommend,0) is_recommend ';
- $table = 'dd_datum_url';
- $order_by_two = 'a.read_num';
- $time_str = date("Y-m-d H:i:s");
- $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_datum_intro as k ON k.id = a.datum_id WHERE a.status = 1 AND a.is_deleted = 0 AND k.status = 1 AND k.is_deleted = 0 AND a.release_time < '". $time_str ."' 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['down_num'] = numTransform($v['down_num']);
- $v['read_num'] = numTransform($v['read_num']);
- $datum_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $datum_auth['app_name'];
- $v['app_logo'] = $datum_auth['app_logo'];
- $v['create_at'] = substr($v['create_at'],0,10);
- $v['is_release'] = UserLearn::checkRelease($this->user_id,2,$v['id']);
- });
- $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_datum_intro as k ON k.id = a.datum_id WHERE a.status = 1 AND a.is_deleted = 0 AND k.status = 1 AND a.release_time < '". $time_str ."' AND k.is_deleted = 0 " ;
- $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/Datum/getDatumList
- * @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:每页数
- * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
- * @return name:id type:int default:-- desc:[请求/api/Datum/getDatumDetail用,请求资料模块其他接口参数:url_id]
- * @return name:title type:string default:-- desc:标题列
- * @return name:is_over type:int default:-- desc:是否完结(0否,1是)
- * @return name:label type:string default:-- desc:标签
- * @return name:create_at type:string default:-- desc:时间
- * @return name:down_num type:string default:-- desc:下载量
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:url_arr type:array default:-- desc:资料
- * @return name:url_arr.title type:string default:-- desc:资料标题
- * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
- * @return name:url_arr.url type:string default:-- desc:资料地址
- * @return name:url_arr.is_down type:int default:-- desc:是否能下载(0否1是)
- * @return name:url_arr.is_encrypt type:int default:-- desc:是否加密(0否1是)
- * @return name:url_arr.release_time type:string default:-- desc:上架时间
- * @return name:url_arr.pdf_clear type:int default:-- desc:资料未加密路径【is_encrypt=1时用】
- */
- public function getDatumList()
- {
- $sel_where = [];
- $title = input('get.title');
- $type = input('get.type',2);
- $is_tj = input('get.is_tj',0);
- $sort_type = input('get.sort_type',1);
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- $sel_where[] = ['url_num','>',0];
- if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
- if($type) $sel_where[] = ['type','=',$type];
- $user_id = $this->user_id ? $this->user_id : input('rand_user');
- if(!$user_id) $this->error('参数错误');
- $list = UserSynth::getRecommendList($user_id,'Intro',$this->page,$this->page_num,$sel_where,input('sort_type',1));
- // return json($list);
- if($list['code'] != 200) $this->error($list['msg']);
- $this->success('ok',$list);
- switch ($sort_type) {
- case 1:
- $order = ['sort'=>'desc','read_num'=>'desc'];
- break;
- case 2:
- $order = ['id'=>'asc','sort'=>'desc'];
- break;
- case 3:
- $order = ['id'=>'desc','sort'=>'desc'];
- break;
- }
- if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,3);
- $where_str = 'id > 0';
- $list = DatumIntro::where($sel_where)->with('urlArr')
- ->limit($this->off_set,$this->page_num)
- ->where($where_str)
- ->order($order)
- ->select()->toArray();
- array_walk($list,function (&$v,$k){
- $v['create_at'] = substr($v['create_at'],0,10);
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['id']);
- $v['down_num'] = array_sum(array_column($v['url_arr'],'down_num'));
- $v['down_num'] = numTransform($v['down_num']);
- $v['datum_url'] = !empty($v['url_arr']) ? $v['url_arr'][0]['url'] : null;
- foreach ($v['url_arr'] as &$dv) {
- if(in_array($this->source_type,[1])) unset($dv['pdf_clear']);
- }
- });
- $total_num = DatumIntro::where($sel_where)->where($where_str)->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 获取资料系列详情(【合集列表】平台)
- * @desc 获取资料系列详情
- * @author qc
- * @method GET
- * @url /api/Datum/getDatumDetail
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:资料id
- * @param name:sort_type type:int default:1 desc:1正序2倒序
- * @return name:title type:string default:-- desc:标题
- * @return name:datum_url type:string default:-- desc:资料地址
- * @return name:down_num type:string default:-- desc:下载量
- * @return name:user_level type:int default:-- desc:会员等级id
- * @return name:follow_switch type:int default:-- desc:订阅开关状态【0关闭1开启】
- * @return name:is_release type:int default:-- desc:是否释放【0否1是】,已释放不需要购买vip
- * @return name:video_id type:int default:-- desc:视频id
- * @return name:video_item type:int default:-- desc:item_id
- * @return name:goods_id type:int default:-- desc:商品id
- * @return name:h5_url type:int default:-- desc:h5的专栏链接
- * @return name:user_level type:int default:-- desc:会员等级id
- * @return name:url_arr type:array default:-- desc:资料
- * @return name:url_arr.id type:int default:-- desc:[请求/api/Datum/getDatumItemInfo用,请求资料模块其他接口参数:url_id]
- * @return name:url_arr.title type:string default:-- desc:资料标题
- * @return name:url_arr.switch_open type:int default:-- desc:通知开关【0关闭1开启】
- * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
- * @return name:url_arr.url type:string default:-- desc:资料地址
- * @return name:url_arr.is_collect type:int default:-- desc:是否收藏
- * @return name:url_arr.collect_num type:int default:-- desc:收藏量
- * @return name:url_arr.down_num type:int default:-- desc:下载量
- * @return name:url_arr.read_num type:int default:-- desc:阅读量
- * @return name:url_arr.is_down type:int default:-- desc:是否能下载【0否1是】
- * @return name:url_arr.is_encrypt type:int default:-- desc:是否加密(0否1是)
- * @return name:url_arr.pdf_clear type:int default:-- desc:资料未加密路径【is_encrypt=1时用】
- * @return name:url_arr.is_recently type:int default:-- desc:是否最近观看【0否1是】
- * @return name:url_arr.comment_switch type:int default:-- desc:评论开关【0关闭1开启】
- * @return name:url_arr.release_time type:string default:-- desc:上架时间
- */
- public function getDatumDetail()
- {
- $sel_where = [];
- $sel_where[] = ['id','=',input('get.id')];
- $sort_type = input('sort_type',1);
- $is_release = UserLearn::checkRelease($this->user_id,2,input('get.id'));
- $detail = DatumIntro::where($sel_where)->with(['urlArr'=>function($query)use($sort_type){
- // return $query->order('id',$sort_type == 1 ? 'asc' : 'desc');
- if($sort_type == 1){
- return $query->order('sort asc,id asc');
- }else{
- return $query->order('sort desc,id desc');
- }
- }])->find()->toArray();
- if((!$is_release && $detail['is_deleted'] == 1) || (!$is_release && $detail['status'] == 0))$this->error('该资料已下线');
- if($is_release){
- $detail['url_arr'] = DatumUrl::field('id,release_time,datum_id,user_id,title,url,is_encrypt,pdf_clear,sort,is_vip,transmit_num,down_num,read_num,is_down,comment_switch')->where('release_time','< time',date("Y-m-d H:i:s"))->where('is_deleted',0)->where('datum_id',$detail['id'])->select()->toArray();
- }
- $level_id = UserLevelRank::getUserVip($this->user_id);
- $detail['user_level'] = $level_id;
- $detail['read_num'] = numTransform(array_sum(array_column($detail['url_arr'],'read_num')));
- $detail['down_num'] = numTransform(array_sum(array_column($detail['url_arr'],'down_num')));
- $detail['follow_switch'] = PlatformSwitch::checkSwitch($this->user_id,$detail['id'],4);
- $detail['is_release'] = UserLearn::checkRelease($this->user_id,2,$detail['id']);
- $detail['h5_url'] =$this->request->root(true).'/#/information-collection-list?id='.$detail['id'];
- $recently_id = UserTrack::getRecentlyTrack($this->user_id,2,$detail['id']);
- foreach ($detail['url_arr'] as &$dv) {
- //if($dv['is_vip'] && !$level_id) $dv['url'] = '';
- if(in_array($this->source_type,[1])) unset($dv['pdf_clear']);
- $dv['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$dv['id'],9);
- $dv['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['id'],$dv['id']);
- $dv['collect_num'] = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>2,'coll_id'=>$detail['id'],'children_id'=>$dv['id']])->count();
- $dv['collect_num'] = numTransform($dv['collect_num']);
- $dv['down_num'] = numTransform($dv['down_num']);
- $dv['is_recently'] = $dv['id'] == $recently_id ? 1 : 0;
- $datum_auth = ArticleItem::getArticleAuth($dv['user_id'],APPNAME,APPLOGO);
- $dv['app_name'] = $datum_auth['app_name'];
- $dv['app_logo'] = $datum_auth['app_logo'];
- }
- //DatumIntro::where('id',$detail['id'])->setInc('read_num');
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取资料ITEM详情(平台)
- * @desc 获取资料ITEM详情
- * @author qc
- * @method GET
- * @url /api/Datum/getDatumItemInfo
- * @header name:Authorization require:1 desc:Token
- * @param name:url_id type:int default:0 desc:url_id
- * @return name:title type:string default:-- desc:资料标题
- * @return name:is_vip type:int default:-- desc:是否是vip
- * @return name:is_release type:int default:-- desc:是否释放【0否1是】,已释放不需要购买vip
- * @return name:cover type:string default:-- desc:封面
- * @return name:images type:int default:-- desc:图片
- * @return name:content type:int default:-- desc:内容
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:down_num type:int default:-- desc:下载量
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:follow_switch type:int default:-- desc:订阅开关状态【0关闭1开启】
- * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
- * @return name:praise_num type:int default:-- desc:点赞量
- * @return name:is_praise type:int default:-- desc:是否点赞
- * @return name:is_down type:int default:-- desc:是否可以下载【0否1是】
- * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
- * @return name:app_name type:string default:-- desc:发布者
- * @return name:app_logo type:string default:-- desc:发布者头像
- * @return name:release_time type:string default:-- desc:上架时间
- */
- public function getDatumItemInfo()
- {
- $url_id = input('get.url_id');
- $detail = DatumUrl::where('id',$url_id)->find()->toArray();
- $is_release = UserLearn::checkRelease($this->user_id,2,$detail['datum_id']);
- if($is_release == 0){
- if($detail['is_deleted'] == 1 || $detail['status'] == 0) $this->error('该资料已下架');
- }
- $detail['series_title'] =DatumIntro::where('id',$detail['datum_id'])->value('title');
- $detail['follow_switch'] = PlatformSwitch::checkSwitch($this->user_id,$detail['datum_id'],4);
- $detail['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$detail['datum_id'],'children_id'=>$detail['id']])->count();
- $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['datum_id'],$detail['id']);
- $detail['collect_num'] = numTransform($detail['collect_num']);
- $detail['down_num'] = numTransform($detail['down_num']);
- $detail['read_num'] = numTransform($detail['read_num']);
- $detail['transmit_num'] = numTransform($detail['transmit_num']);
- $detail['is_release'] = UserLearn::checkRelease($this->user_id,2,$detail['datum_id']);
- $detail['comment_num'] = DatumComment::getDatumCommentNum($detail['id']);
- $detail['follow_switch'] = PlatformSwitch::checkSwitch($this->user_id,$detail['datum_id'],4);
- $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$detail['id'],9);
- $detail['praise_num']= DatumLike::where([['url_id','=',$url_id]])->count();
- $datum_auth = DatumUrl::getDatumAuth($detail['user_id'],APPNAME,APPLOGO);
- $detail['app_name'] = $datum_auth['app_name'];
- $detail['app_logo'] = $datum_auth['app_logo'];
- $detail['is_praise']= DatumLike::where([['user_id','=',$this->user_id],['url_id','=',$url_id]])->count();
- UserTrack::crateTrack($this->user_id,2,$detail['datum_id'],$url_id);
- DatumUrl::where('id',$url_id)->setInc('read_num');
- DatumIntro::where('id',$detail['datum_id'])->setInc('read_num');
- if($this->user_id){
- TopSearch::seIncHotNum($url_id,$this->request->controller());
- }
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 资料转发(转发数量统计)
- * @desc 转发成功后调用
- * @author qc
- * @method POST
- * @url /api/Datum/datumTransmit
- * @header name:Authorization require:1 desc:Token
- * @param name:datum_id type:int default:-- desc:资料id
- *
- * @param name:url_id type:int default:-- desc:url_id
- */
- public function datumTransmit()
- {
- $datum_id= input('post.datum_id');
- $url_id = input('post.url_id',0);
- DatumUrl::where('id',$url_id)->setInc('transmit_num');
- $this->success('ok');
- }
- /**
- * @title 资料下载(资料下载数量统计)
- * @desc 资料下载
- * @author qc
- * @method POST
- * @url /api/Datum/datumDownload
- * @header name:Authorization require:1 desc:Token
- * @param name:datum_id type:int default:-- desc:资料id
- * @param name:url_id type:int default:-- desc:url_id
- */
- public function datumDownload()
- {
- $datum_id= input('post.datum_id');
- $url_id = input('post.url_id',0);
- Data::save('UserDownload',['user_id'=>$this->user_id,'first_id'=>$datum_id,'second_id'=>$url_id]);
- DatumUrl::where('id',$url_id)->setInc('down_num');
- $this->success('ok');
- }
- /**
- * @title 资料阅读(阅读数量统计)
- * @desc 资料阅读
- * @author qc
- * @method POST
- * @url /api/Datum/datumRead
- * @header name:Authorization require:1 desc:Token
- * @param name:url_id type:int default:-- desc:url_arr的id
- */
- public function datumRead()
- {
- $url_id = input('post.url_id',0);
- $datum_id = DatumUrl::where('id',$url_id)->value('datum_id');
- DatumUrl::where('id',$url_id)->setInc('read_num');
- DatumIntro::where('id',$datum_id)->setInc('read_num');
- if($this->user_id){
- TopSearch::seIncHotNum($url_id,$this->request->controller());
- }
- $this->success('ok');
- }
- /**
- * @title 资料收藏||取消收藏
- * @desc 用户收藏
- * @author qc
- * @method POST
- * @url /api/Datum/datumCollect
- * @header name:Authorization require:1 desc:Token
- * @param name:datum_id type:int require:1 default:-- desc:记录id[资料id]
- * @param name:url_id type:int default:1 desc:url_id
- * @return name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
- */
- public function datumCollect()
- {
- $coll_type = input('post.coll_type',2);
- $coll_id = input('post.datum_id',0);
- $url_id = input('post.url_id',0);
- if(!$coll_id || !$url_id) $this->error('参数错误');
- $collect_check = UserCollect::checkCollectByType($this->user_id,$coll_type,$coll_id,$url_id);
- if($collect_check) {
- UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id,'children_id'=>$url_id])->delete();
- $this->success('取消收藏成功',['status'=>0]);
- }else{
- Data::save('UserCollect', [
- 'user_id'=>$this->user_id,
- 'coll_type'=>$coll_type,
- 'coll_id'=>$coll_id,
- 'children_id'=>$url_id,
- 'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$coll_id,'children_id'=>$url_id]);
- $this->success('收藏成功',['status'=>1]);
- }
- }
- /**
- * @title 资料点赞||取消点赞
- * @desc 点赞||取消点赞
- * @author qc
- * @method POST
- * @url /api/Datum/datumTags
- * @header name:Authorization require:1 desc:Token
- * @param name:datum_id type:int default:1 desc:资料系列id
- * @param name:url_id type:int default:1 desc:资料url_id
- * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
- */
- public function datumTags()
- {
- $datum_id = input('post.datum_id');
- $url_id = input('post.url_id');
- $ret_val = 0;
- $check_tags = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->value('id');
- if($check_tags) {
- DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->delete();
- }else{
- $p_user_id = DatumUrl::where('id',$url_id)->value('user_id');
- $is_read = $p_user_id == $this->user_id ? 1 : 0;
- Data::save('DatumLike',
- ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id,'is_read'=>$is_read],'user_id',
- ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id]);
- $ret_val = 1;
- }
- $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
- }
- /**
- * @title 用户提交或修改资料【个人】
- * @desc 用户提交或修改资料【个人】
- * @author qc
- * @method POST
- * @url /api/Datum/userReferDatum
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:id(修改时必传)
- * @param name:title type:string default:-- desc:标题
- * @param name:datum_url type:string default:-- desc:资料地址
- * @param name:desc type:string default:-- desc:简介
- * @param name:label type:string default:-- desc:资料标签id(多个用逗号隔开)
- */
- public function userReferDatum()
- {
- $id = input('post.id',0);
- $title = input('post.title');
- $desc = input('post.desc');
- $datum_url = input('post.datum_url');
- $label = input('post.label');
- if(!$datum_url) $this->error('请上传资料');
- if($id){
- $check_status = UserDatum::where('id',$id)->value('status');
- if($check_status == 1) $this->error('已审核通过,不允许修改');
- }
- $data = [
- 'title' => $title,
- 'user_id' => $this->user_id,
- 'desc' => $desc,
- 'datum_url' => $datum_url,
- 'label' => $label,
- 'status' => 0,
- 'remark' => '',
- ];
- if($id) $data['id'] = $id;
- if($id){
- UserDatum::where('id',$id)->update($data);
- }else{
- $res= UserDatum::create($data) ;
- }
- // UserMessage::sendUserMessage($this->user_id,'datum',1,0,0,$id ? $id:$res->id);
- $this->success('提交成功,请等待审核',['id'=> $id ? :$res->id]);
- }
- /**
- * @title 我的发布--其他【个人】
- * @desc 获取我的资料列表【个人】
- * @author qc
- * @method GET
- * @url /api/Datum/getMyDatumList
- * @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:desc type:string default:-- desc:简介
- * @return name:datum_url type:string default:-- desc:资料地址
- * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
- * @return name:remark type:string default:-- desc:审核备注
- * @return name:label type:string default:-- desc:标签
- */
- public function getMyDatumList()
- {
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['user_id','=',$this->user_id];
- $title = input('get.title');
- if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
- $list = UserDatum::where($sel_where)
- ->field('id,title,desc,datum_url,status,remark,label')
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $total_num = UserDatum::where($sel_where)->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 获取我的资料详情【个人】
- * @desc 获取我的资料列表【个人】
- * @author qc
- * @method GET
- * @url /api/Datum/getUserDatumDetail
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:string default:-- desc:记录id
- * @return name:title type:string default:-- desc:标题
- * @return name:desc type:string default:-- desc:简介
- * @return name:datum_url type:string default:-- desc:资料地址
- * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
- * @return name:remark type:string default:-- desc:审核备注
- * @return name:label type:string default:-- desc:标签
- * @return name:label_name type:array default:-- desc:标签数组
- */
- public function getUserDatumDetail()
- {
- $detail =UserDatum::where('id',input('get.id'))->field('id,title,desc,datum_url,status,remark,label')->find();
- if($this->user_id){
- $General = new General();
- $General->label($detail['label']);
- }
- if(!$detail) $this->error('资料有误');
- $detail['label_name'] =$detail['label'] ? $detail['label_name'] = explode(',',trim($detail['label'],',')) : null;
- $this->success('ok',['detail'=>$detail->toArray()]);
- }
- /**
- * @title 用户删除资料记录【个人】
- * @desc 用户删除资料记录【个人】
- * @author qc
- * @method POST
- * @url /api/Datum/delUserDatum
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:id
- */
- public function delUserDatum()
- {
- UserDatum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
- $this->success('删除成功');
- }
- /**
- * @title 我的下载
- * @desc 获取下载资料列表
- * @author qc
- * @method GET
- * @url /api/Datum/getDownloadDatum
- * @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:series_title type:string default:-- desc:系列标题
- * @return name:datum_id type:int default:-- desc:资料id
- * @return name:url_id type:int default:-- desc:item_id
- * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
- * @return name:url 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 getDownloadDatum()
- {
- $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 = UserDownload::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.first_id datum_id,t.second_id url_id,i.read_num,i.title,i.is_vip,i.url,i.user_id,x.title series_title')
- ->leftJoin('DatumUrl i','t.second_id = i.id')
- ->leftJoin('DatumIntro x','t.first_id = x.id')
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $datum_auth = DatumUrl::getDatumAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $datum_auth['app_name'];
- $v['app_logo'] = $datum_auth['app_logo'];
- }
- $total_num = UserDownload::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.second_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/Datum/getLearnHistory
- * @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:datum_id type:int default:-- desc:资料id
- * @return name:url_id type:int default:-- desc:item_id
- * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:url 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:is_down type:int default:-- desc:是否能下载(0否1是)
- * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
- * @return name:pdf_clear type:int default:-- desc:资料未加密路径【is_encrypt=1时用】
- */
- public function getLearnHistory()
- {
- $sel_where = [];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.type','=',2];
- $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 datum_id,t.second_id url_id,i.title,i.url,i.is_vip,i.user_id,i.read_num,i.is_down,i.is_encrypt,pdf_clear')
- ->leftJoin('DatumUrl i','t.second_id = i.id')
- ->order('update_int desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $datum_auth = DatumUrl::getDatumAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $datum_auth['app_name'];
- $v['app_logo'] = $datum_auth['app_logo'];
- }
- $total_num = UserTrack::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.second_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/Datum/getDatumCollect
- * @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:series_title type:string default:-- desc:系列标题
- * @return name:datum_id type:string default:-- desc:资料id
- * @return name:url_id type:string default:-- desc:url_id
- * @return name:url type:string default:-- desc:资料路径
- * @return name:create_at 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:is_down type:int default:-- desc:是否能下载(0否1是)
- * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
- * @return name:pdf_clear type:string default:-- desc:资料未加密路径【is_encrypt=1时用】
- * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:down_num type:int default:-- desc:下载量
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:like_num type:int default:-- desc:点赞数量
- * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
- */
- public function getDatumCollect()
- {
- $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','=',2];
- $list = UserCollect::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.coll_id datum_id,t.children_id url_id,i.title,i.url,i.is_vip,i.user_id,i.is_down,i.down_num,i.pdf_clear,i.is_encrypt,i.read_num,i.transmit_num,x.title series_title')
- ->leftJoin('DatumUrl i','t.children_id = i.id')
- ->leftJoin('DatumIntro x','t.coll_id = x.id')
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['url_id'],9);
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $datum_auth = DatumUrl::getDatumAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $datum_auth['app_name'];
- $v['app_logo'] = $datum_auth['app_logo'];
- $v['down_num'] = numTransform($v['down_num']);
- $v['read_num'] = numTransform($v['read_num']);
- $v['transmit_num'] = numTransform($v['transmit_num']);
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['datum_id'],$v['url_id']);
- $v['collect_num'] = UserCollect::getCollectNum(2,$v['datum_id'],$v['url_id'] );
- $v['like_num'] = DatumLike::where('url_id',$v['url_id'])->count();
- $v['like_num'] = numTransform($v['like_num']);
- $v['is_like'] = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$v['datum_id'],'url_id'=>$v['url_id']])->count();
- $v['comment_num'] = DatumComment::getDatumCommentNum($v['url_id']);
- });
- $total_num =UserCollect::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.children_id = i.id')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 以下接口为二期需求
- * @desc 以下接口为二期需求
- * @author qc
- * @url /api/Datum/secondPhase
- * @method
- * @return name:1 type:string default:-- desc:以下接口为二期需求
- */
- public function secondPhase(){}
- /**
- * @title 我的发布--审核成功【后台资料绑定该会员】
- * @desc 后台资料绑定该会员
- * @author qc
- * @method GET
- * @url /api/Datum/getBoundList
- * @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:id type:string default:-- desc:记录id【url_id】
- * @return name:title type:string default:-- desc:标题
- * @return name:series_title type:string default:-- desc:系列标题
- * @return name:datum_id type:string default:-- desc:资料id
- * @return name:create_at type:string default:-- desc:时间
- * @return name:url type:string default:-- desc:文件路径
- * @return name:is_vip type:int default:-- desc:是否是vip[0否1是]
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @return name:is_down type:int default:-- desc:是否能下载(0否1是)
- * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
- * @return name:pdf_clear type:string default:-- desc:资料未加密路径【is_encrypt=1时用】
- */
- public function getBoundList()
- {
- $sel_where = [];
- $title = input('get.title');
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.is_deleted','=',0];
- if($title) $sel_where[] = ['t.title|t.label','like','%'.$title.'%'];
- $list = DatumUrl::where($sel_where)
- ->alias('t')
- ->field('t.id,t.title,t.is_vip,t.url,t.datum_id,t.is_encrypt,t.pdf_clear,t.create_at,t.label,t.is_down,x.title series_title,t.read_num')
- ->order('t.id desc')
- ->leftJoin('DatumIntro x','x.id = t.datum_id')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['read_num'] = numTransform($v['read_num']);
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['id'],$this->request->controller());
- }
- $total_num= DatumUrl::where($sel_where) ->alias('t')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 我的订阅--资料
- * @desc 我的订阅列表
- * @author qc
- * @method GET
- * @url /api/Datum/getFollowUpList
- * @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:create_at type:string default:-- desc:追更设置时间
- * @return name:datum_id type:int default:-- desc:资料id
- * @return name:title type:string default:-- desc:标题
- * @return name:recently_title type:int default:-- desc:上次观看title
- * @return name:is_deleted type:int default:-- desc:是否删除【0否1是】
- * @return name:total_sequel type:int default:-- desc:期数
- * @return name:is_recently type:int default:-- desc:是否最近观看【0否1是】
- * @return name:recently_id type:int default:-- desc:上次观看记录id
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getFollowUpList()
- {
- $sel_where = [];
- $sel_where[] = ['p.user_id','=',$this->user_id];
- $sel_where[] = ['p.type','=',4];
- $sel_where[] = ['p.switch_value','=',1];
- $title = input('title');
- if($title) $sel_where[] = ['a.title','like','%'.$title.'%'];
- $field = 'p.id,p.switch_id as datum_id,p.create_at,a.title,a.is_deleted,total_sequel,a.status ,a.is_deleted';
- $list = PlatformSwitch::field($field)
- ->alias('p')->leftJoin('DatumIntro a','p.switch_id = a.id')
- ->where($sel_where)->limit($this->off_set,$this->page_num)
- ->order('p.id desc')->select()->toArray();
- array_walk($list,function (&$v){
- $v['is_normal'] = $v['status'] == 1 && $v['is_deleted'] == 0 ? 1 : 0;
- $recently_id = UserTrack::getRecentlyTrack($this->user_id,2,$v['datum_id']);
- $v['is_recently'] = $recently_id ? 1 : 0;
- $v['recently_id'] = $recently_id ? $recently_id : 0;
- $v['recently_title'] = UserTrack::getRecentlyTitle($this->user_id,2,$v['datum_id']);
- });
- $total_num = PlatformSwitch::field($field)->alias('p')->leftJoin('DatumIntro a','p.switch_id = a.id')->where($sel_where)->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 资料评论
- * @desc 资料评论
- * @author qc
- * @method POST
- * @url /api/Datum/datumComment
- * @header name:Authorization require:1 desc:Token
- * @param name:datum_id type:int default:1 desc:资料系列id
- * @param name:url_id type:int default:1 desc:资料id
- * @param name:content type:string default:-- desc:内容
- * @return name:name type:string default:-- desc:会员名称
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:content type:string default:-- desc:内容
- */
- public function datumComment()
- {
- $datum_id = input('post.datum_id');
- $url_id = input('post.url_id');
- $content = input('post.content',0);
- if(!$content) $this->error('请输入评论内容');
- $comment_switch = DatumUrl::where('id',$url_id)->value('comment_switch');
- $send_user = DatumUrl::where('id',$url_id)->value('user_id');
- if(!$comment_switch) $this->error('评论功能已关闭');
- $res = DatumComment::create([
- 'user_id'=>$this->user_id,
- 'content'=>$content,
- 'datum_id'=>$datum_id,
- 'url_id'=>$url_id,
- 'is_read' => $send_user == $this->user_id ? 1 : 0,
- 'source_read' => $send_user == $this->user_id ? 1 : 0,
- ]);
- $detail =DatumComment::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($send_user && $this->user_id != $send_user) UserMessage:: sendUserMessage($send_user,'datum',4,0,$this->user_id,$url_id,$content,$url_id,$datum_id);
- $this->success('评论成功',['detail'=>$detail]);
- }
- /**
- * @title 删除评论
- * @desc 删除评论
- * @author qc
- * @method POST
- * @url /api/Datum/delComment
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:评论id
- */
- public function delComment(){
- DatumComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
- $this->success('删除成功');
- }
- /**
- * @title 资料二级评论
- * @desc 资料二级评论
- * @author qc
- * @method POST
- * @url /api/Datum/secondCommend
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:1 desc:评论id
- * @param name:content type:string default:-- desc:内容
- * @return name:name type:string default:-- desc:会员名称
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:content type:string default:-- desc:内容
- */
- public function secondCommend()
- {
- $comment = DatumComment::where('id',input('post.id'))->find()->toArray();
- $user_info = $this->userInfo('name');
- $content = input('post.content');
- if($this->user_id != $comment['user_id'])UserMessage:: sendUserMessage($comment['user_id'],'datum',3,0,$this->user_id,$comment['id'],$content,$comment['url_id'],$comment['datum_id']);
- $send_user = DatumUrl::where('id',$comment['url_id'])->value('user_id');
- $comment_switch = DatumUrl::where('id',$comment['url_id'])->value('comment_switch');
- if(!$comment_switch) $this->error('评论功能已关闭');
- $to_user = $comment['user_id'];
- if($send_user != $this->user_id) UserMessage:: sendUserMessage($send_user,'datum',4,0,$this->user_id,$comment['url_id'],$content,$comment['url_id'],$comment['datum_id']);
- unset($comment['id']);
- unset($comment['create_at']);
- unset($comment['to_deleted']);
- unset($comment['is_top']);
- unset($comment['is_deleted']);
- $comment['pid'] = input('post.id');
- $comment['user_id'] = $this->user_id;
- $comment['content'] = input('post.content');
- $comment['lev']++;
- $comment['is_read']= $this->user_id == $to_user ? 1 :0 ;
- $comment['source_read'] = $this->user_id == $send_user ? 1 :0 ;
- if(!$comment['source_id']) $comment['source_id'] = input('post.id');
- $res = DatumComment::create($comment);
- $detail = DatumComment::where('c.id',$res->id)
- ->alias('c')->field('c.id,c.content,c.create_at,u.name,u.headimg')
- ->leftJoin('store_member u','u.id = c.user_id')->find()->toArray();
- $this->success('评论成功',['detail'=>$detail]);
- }
- /**
- * @title 资料评论列表
- * @desc 资料评论列表
- * @author qc
- * @method GET
- * @url /api/Datum/getDatumCommentList
- * @header name:Authorization require:1 desc:Token
- * @param name:url_id type:int default:-- desc:资料id
- * @param name:sort_type type:int default:1 desc:排序1最新2最热
- * @param name:page 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: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:is_top type:int default:-- desc:是否置顶(0否1是)
- * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
- * @return name:total_num type:int default:-- desc:总评论数(仅一级)
- */
- public function getDatumCommentList()
- {
- $where = [];
- $where[] = ['c.url_id','=',input('get.url_id')];
- $where[] = ['c.is_deleted','=',0];
- $user_id = $this->user_id;
- $sort_type= input('sort_type',1);
- switch ($sort_type) {
- case 1:
- $order = ['is_top'=>'desc','id'=>'desc'];
- break;
- default:
- $order = ['is_top'=>'desc','like_times'=>'desc','id'=>'desc'];
- break;
- }
- $list =DatumComment::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 = DatumComment::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;
- $val['like_num'] = DatumCommentLike::where('like_id',$val['id'])->count();
- $val['like_num'] = numTransform($val['like_num']);
- $val['is_like'] = DatumCommentLike::where(['like_id'=>$val['id'],'user_id'=>$user_id])->count();
- $parent = DatumComment::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'] ;
- $val['can_delete'] = $val['user_id'] == $this->user_id ? 1 :0;
- });
- $total_num = DatumComment::where($where)->alias('c')->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 POST
- * @url /api/Datum/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点赞我的--资料,12点赞我的--评论,13我的收藏,14我的下载,】
- */
- public function batchesDel(){
- $type = input('post.type',1);
- $del_where = [];
- $del_where[] = ['id','in',input('post.id')];
- if(in_array($type,[1,3,4,5,6,7,8,9,13,14])) $del_where[] = ['user_id','=',$this->user_id];
- if(in_array($type,[1,3])) DatumComment::where($del_where)->update(['is_deleted'=>1]);
- if(in_array($type,[2])) DatumComment::where($del_where)->update(['source_deleted'=>1,'source_read'=>1,'is_read'=>1]);
- if(in_array($type,[10])) DatumComment::where($del_where)->update(['to_deleted'=>1,'to_read'=>1]);
- if(in_array($type,[4])) UserLearn::where($del_where)->update(['is_deleted'=>1]);
- if(in_array($type,[5])) UserDatum::where($del_where)->update(['is_deleted'=>1]);
- if(in_array($type,[6])) PlatformSwitch::where($del_where)->delete();
- if(in_array($type,[7])) UserMessage::where($del_where)->update(['is_deleted'=>1]);
- if(in_array($type,[8])) DatumLike::where($del_where)->delete();
- if(in_array($type,[11])) DatumLike::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
- if(in_array($type,[9])) DatumCommentLike::where($del_where)->delete();
- if(in_array($type,[12])) DatumCommentLike::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
- if(in_array($type,[13])) UserCollect::where($del_where)->delete();
- if(in_array($type,[14])) UserDownload::where($del_where)->delete();
- $this->success('操作成功');
- }
- /**
- * @title 评论点赞||取消点赞
- * @desc 评论
- * @author qc
- * @method POST
- * @url /api/Datum/commentTags
- * @header name:Authorization require:1 desc:Token
- * @param name:comment_id type:int default:1 desc:评论记录id
- * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
- */
- public function commentTags()
- {
- $comment_id = input('post.comment_id');
- $ret_val = 0;
- $check_tags = DatumCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$comment_id])->value('id');
- if($check_tags) {
- DatumCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$comment_id])->delete();
- // ArticleItem::where('id',$comment_id)->setDec('like_times');
- }else{
- $p_user_id = DatumComment::where('id',$comment_id)->value('user_id');
- $is_read = $p_user_id == $this->user_id ? 1 : 0;
- Data::save('DatumCommentLike',
- ['user_id'=>$this->user_id,'like_id'=>$comment_id,'is_read'=>$is_read],'user_id',
- ['user_id'=>$this->user_id,'like_id'=>$comment_id]);
- $ret_val = 1;
- // ArticleItem::where('id',$comment_id)->setInc('like_times');
- }
- $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
- }
- /**
- * @title 我的订阅---消息
- * @desc 订阅消息
- * @author qc
- * @method GET
- * @url /api/Datum/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:is_read type:int default:-- desc:是否已读【0否1是】
- * @return name:datum_title type:string default:-- desc:系列标题
- * @return name:datum_id type:int default:-- desc:系列id
- * @return name:children_id type:int default:-- desc:详情id
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- */
- public function getFollowUpMessage()
- {
- $title = input('title');
- $list = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'m.module'=>'datum','m.type_id'=>5])
- ->when($title,function ($query)use ($title){
- if($title) $query->where('m.content','like','%'.$title.'%');})
- ->alias('m')->field('m.id,v.create_at,m.is_read,m.content,m.relation_id datum_id,m.module,v.title datum_title,m.children_id')
- ->leftJoin('DatumIntro v','v.id= m.relation_id')
- ->limit($this->off_set,$this->page_num)
- ->order(['m.id'=>'desc'])
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['children_id'],$this->request->controller());
- }
- $total_num = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'m.module'=>'datum','m.type_id'=>5])
- ->alias('m')->leftJoin('DatumIntro v','v.id= m.relation_id')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 获取角标数量
- * @desc 获取角标数量
- * @author qc
- * @method GET
- * @url /api/Datum/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:praise_num type:int default:-- desc:点赞我的【包含视频点赞和评论点赞】
- * @return name:datum_praise_num type:int default:-- desc:-资料点赞
- * @return name:comment_praise_num type:int default:-- desc:评论点赞
- * @return name:follow_num type:int default:-- desc:订阅
- */
- public function getMarkNum()
- {
- // 评论我的
- $comment_num = DatumComment::where([['t.is_deleted','=',0],['i.user_id','=',$this->user_id],['t.user_id','<>',$this->user_id],['is_read','=',0],['t.pid','=',0]])
- ->leftJoin('DatumUrl i','t.url_id = i.id')
- ->alias('t')->count();
- // 回复我的
- $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- $reply_num = $all_comment ? DatumComment::where([['t.is_deleted','=',0],['t.to_deleted','=',0],['t.user_id','<>',$this->user_id],['t.lev','>=',2],['is_read','=',0],['t.pid','in',implode(',',$all_comment)]])->alias('t')->count() : 0;
- // 点赞我的
- $all_datum = DatumUrl::where('user_id',$this->user_id)->where('is_deleted',0)->column('id');
- $datum_praise_num = DatumLike::where([['is_read','=',0],['url_id','in',$all_datum],['user_id','<>',$this->user_id]])->count();
- $comment_praise_num = DatumCommentLike::where([['is_read','=',0],['like_id','in',$all_comment],['user_id','<>',$this->user_id]])->count();
- $praise_num = $datum_praise_num + $comment_praise_num;
- $follow_num = UserMessage::getUnreadNum($this->user_id,'datum',5);
- $this->success('ok',compact(['reply_num','comment_num','praise_num','datum_praise_num','comment_praise_num','follow_num']));
- }
- /**
- * @title 点赞我的--评论
- * @desc 点赞我的--评论
- * @author qc
- * @method GET
- * @url /api/Datum/praiseMyComment
- * @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:series_title type:string default:-- desc:系列标题
- * @return name:create_at type:string default:-- desc:时间
- * @return name:read_num type:int 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:url type:string default:-- desc:文件路径
- * @return name:like_id type:int default:-- desc:评论id
- * @return name:content type:string default:-- desc:评论内容
- */
- public function praiseMyComment()
- {
- $user_info = $this->userInfo('name,headimg');
- $list = DatumCommentLike::where([['c.user_id','=',$this->user_id],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
- ->alias('l')
- ->field('l.id,l.user_id,l.like_id,m.name user_name,m.headimg,l.create_at,v.url,v.title,v.read_num,c.content,x.title series_title,v.datum_id,c.url_id,v.user_id buid')
- ->leftJoin('StoreMember m','m.id = l.user_id')
- ->leftJoin('DatumComment c','c.id = l.like_id')
- ->leftJoin('DatumUrl v','v.id = c.url_id')
- ->leftJoin('DatumIntro x','x.id = v.datum_id')
- ->order('l.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v,$k)use ($user_info){
- $v['self_name'] = $user_info['name'] ;
- $article_auth = ArticleItem::getArticleAuth($v['buid'],APPNAME,APPLOGO);
- $v['app_name'] = $article_auth['app_name'];
- $v['app_logo'] = $article_auth['app_logo'];
- $v['read_num'] = numTransform($v['read_num']);
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- });
- $total_num = DatumCommentLike::where([['c.user_id','=',$this->user_id],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
- ->alias('l')->leftJoin('StoreMember m','m.id = l.user_id')
- ->leftJoin('DatumComment c','c.id = l.like_id')
- ->leftJoin('DatumUrl v','v.id = c.url_id')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 点赞我的--资料
- * @desc 点赞我的--资料
- * @author qc
- * @method GET
- * @url /api/Datum/praiseMyDatumList
- * @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:series_title type:string default:-- desc:系列标题
- * @return name:create_at type:string default:-- desc:时间
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:user_name type:string default:-- desc:会员名称
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:url type:string default:-- desc:文件路径
- */
- public function praiseMyDatumList()
- {
- $all_list = DatumUrl::where('user_id',$this->user_id)->where('is_deleted',0)->column('id');
- $user_info = $this->userInfo('name,headimg');
- $list = DatumLike::where([['l.url_id','in',$all_list],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
- ->alias('l')
- ->field('l.id,l.user_id,m.name user_name,m.headimg,l.create_at,v.url,v.title,v.read_num,x.title series_title,v.datum_id,l.url_id')
- ->leftJoin('StoreMember m','m.id = l.user_id')
- ->leftJoin('DatumUrl v','v.id = l.url_id')
- ->leftJoin('DatumIntro x','x.id = v.datum_id')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v,$k)use ($user_info){
- $v['app_name'] = $user_info['name'] ;
- $v['app_logo'] = $user_info['headimg'];
- $v['read_num'] = numTransform($v['read_num']);
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- });
- $total_num = DatumLike::where([['url_id','in',$all_list],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
- ->alias('l')
- ->leftJoin('StoreMember m','m.id = l.user_id')
- ->leftJoin('DatumUrl v','v.id = l.url_id')
- ->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 回复我的【回复我的--回复过我的评论】
- * @desc 回复我的
- * @author qc
- * @method GET
- * @url /api/Datum/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:datum_id type:string default:-- desc:资料系列id
- * @return name:url_id type:string default:-- desc:资料id
- * @return name:url 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:is_deleted type:int default:-- desc:0未删除
- * @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.series_title type:string default:-- desc:系列标题
- * @return name:parent_comment.datum_id type:string default:-- desc:资料系列id
- * @return name:parent_comment.url_id type:string default:-- desc:资料id
- * @return name:parent_comment.is_deleted type:int default:-- desc:0未删除
- */
- public function getReplyComment()
- {
- $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- if(empty($all_comment)) $this->success('ok',['list'=>[]]);
- $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.user_id','<>',$this->user_id];
- $sel_where[] = ['t.to_deleted','=',0];
- $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
- $list = DatumComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.is_read,t.datum_id,t.is_top,t.is_deleted,t.url_id,t.create_at,t.lev,t.content,t.pid,u.name user_name,u.headimg,i.url,i.read_num')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->leftJoin('DatumUrl i','t.url_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['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $parent_comment = DatumComment::where([['t.id','=',$v['pid']]])
- ->field('t.id,t.datum_id,t.is_top,t.url_id,t.content,i.title,i.url,t.pid,u.name,t.is_deleted,x.title series_title,i.user_id')
- ->alias('t')
- ->leftJoin('DatumIntro x','t.datum_id = x.id')
- ->leftJoin('DatumUrl i','t.url_id = i.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->find()->toArray();
- $parent_comment['read_num'] = numTransform($v['read_num']);
- $datum_auth = ArticleItem::getArticleAuth($parent_comment['user_id'],APPNAME,APPLOGO);
- $parent_comment['app_name'] = $datum_auth['app_name'];
- $parent_comment['app_logo'] = $datum_auth['app_logo'];
- $v['parent_comment'] = $parent_comment;
- }
- $total_num = DatumComment::where($sel_where)->alias('t')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- /**
- * @title 评论我的【学习服务--评论我的】
- * @desc 评论我的
- * @author qc
- * @method GET
- * @url /api/Datum/commentMyDatum
- * @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:series_title type:string default:-- desc:系列标题
- * @return name:datum_id type:string default:-- desc:资料系列id
- * @return name:url_id type:string default:-- desc:资料id
- * @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:url type:string default:-- desc:资料路径
- * @return name:user_name type:string default:-- desc:用户名
- * @return name:headimg type:string default:-- desc:用户头像
- * @return name:read_num type:int 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 commentMyDatum()
- {
- $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.user_id','<>',$this->user_id];
- $sel_where[] = ['t.source_deleted','=',0];
- $sel_where[] = ['t.pid','=',0];
- $list = DatumComment::where($sel_where)->alias('t')
- ->field('t.id,t.is_read,t.is_top,t.create_at,i.read_num,t.datum_id,t.url_id,t.lev,t.content,i.title,i.url,u.name user_name,u.headimg,x.title series_title')
- ->leftJoin('DatumUrl i','t.url_id = i.id')
- ->leftJoin('DatumIntro x','t.datum_id = x.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->order('t.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $user_info = $this->userInfo('name,headimg');
- array_walk($list,function (&$v)use ($user_info){
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $v['read_num'] = numTransform($v['read_num']);
- $v['app_name'] = $user_info['name'];
- $v['app_logo'] = $user_info['headimg'];
- });
- $total_num= DatumComment::where($sel_where)->alias('t') ->leftJoin('DatumUrl i','t.url_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 POST
- * @url /api/Datum/unreadChange
- * @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点赞我的--资料,5点赞我的-评论】
- * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
- *
- */
- public function unreadChange()
- {
- $type = input('post.type',1);
- $id = input('post.id');
- $where = [];
- switch ($type) {
- case 1:
- DatumComment::where([['i.user_id','=',$this->user_id],['t.pid','=',0]])
- ->when($id ,function ($query)use ($id){
- if($id) return $query->where('t.id','in',$id);
- })->leftJoin('DatumUrl i','t.url_id = i.id')
- ->alias('t')
- ->update(['source_read'=>input('post.is_read'),'is_read'=>input('post.is_read')]);
- break;
- case 2:
- $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- DatumComment::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'=>input('post.is_read')]);
- break;
- case 3:
- $where[] = ['user_id','=',$this->user_id];
- if($id) $where[] = ['id','in',$id];
- UserMessage::where($where)->update(['is_read'=>input('post.is_read')]);
- break;
- case 4:
- $all_datum = DatumUrl::where('user_id',$this->user_id)->where('is_deleted',0)->column('id');
- DatumLike::where([['is_read','=',0],['url_id','in',$all_datum]])->update(['is_read'=>1]);
- break;
- case 5:
- $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
- DatumCommentLike::where([['is_read','=',0],['like_id','in',$all_comment]])->update(['is_read'=>1]);
- break;
- }
- $this->success('消息变更成功');
- }
- /**
- * @title 我的点赞--资料
- * @desc 我的点赞
- * @author qc
- * @method GET
- * @url /api/Datum/getTagsDatum
- * @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:series_title type:string default:-- desc:系列标题
- * @return name:datum_id type:string default:-- desc:系列id
- * @return name:url_id type:string default:-- desc:资料id
- * @return name:like_num type:string default:-- desc:点赞量
- * @return name:is_like type:string default:-- desc:是否点赞[0否1是]
- * @return name:url type:string default:-- desc:文件路径
- * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
- * @return name:create_at type:string default:-- desc:时间
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
- * @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可以正常跳转详情)
- *
- * @return name:transmit_num type:int default:-- desc:转发量
- * @return name:comment_num type:int default:-- desc:评论量
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:collect_num type:int default:-- desc:收藏量
- */
- public function getTagsDatum()
- {
- $sel_where = [];
- $title = input('get.title');
- if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $list = DatumLike::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.datum_id,t.url_id,i.title,i.url,i.is_vip,i.read_num,i.user_id,i.transmit_num,x.title series_title')
- ->leftJoin('DatumUrl i','t.url_id = i.id')
- ->leftJoin('DatumIntro x','t.datum_id = x.id')
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- foreach ($list as &$v) {
- $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['url_id'],9);
- $v['like_num'] = DatumLike::where(['datum_id'=>$v['datum_id'],'url_id'=>$v['url_id']])->count();
- $v['like_num'] = numTransform($v['like_num']);
- $v['read_num'] = numTransform($v['read_num']);
- $v['is_like'] = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$v['datum_id'],'url_id'=>$v['url_id']])->count();
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $article_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $article_auth['app_name'];
- $v['app_logo'] = $article_auth['app_logo'];
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['datum_id'],$v['url_id']);
- $v['collect_num'] = UserCollect::getCollectNum(2,$v['datum_id'],$v['url_id']);
- $v['comment_num'] = DatumComment::getDatumCommentNum($v['url_id']);
- }
- $total_num = DatumLike::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.url_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/Datum/getTagsComment
- * @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:create_at type:string default:-- desc:时间
- * @return name:user_name type:string default:-- desc:会员名称
- * @return name:headimg type:string default:-- desc:会员头像
- * @return name:content type:string default:-- desc:评论内容
- * @return name:url type:string default:-- desc:资料url
- * @return name:title type:string default:-- desc:标题
- * @return name:series_title type:string default:-- desc:系列标题
- * @return name:read_num 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 getTagsComment()
- {
- $list = DatumCommentLike::field('l.*,i.read_num,c.content,i.read_num,i.title,i.url,u.name user_name,u.headimg,i.user_id buid,c.url_id,c.datum_id,x.title series_title')
- ->alias('l')
- ->where(['l.user_id'=>$this->user_id,'l.type'=>1])
- ->leftJoin('DatumComment c','l.like_id = c.id')
- ->leftJoin('DatumUrl i','i.id = c.url_id')
- ->leftJoin('DatumIntro x','x.id = c.datum_id')
- ->leftJoin('store_member u','u.id = c.user_id')
- ->order('l.id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- $article_auth = ArticleItem::getArticleAuth($v['buid'],APPNAME,APPLOGO);
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $v['app_name'] = $article_auth['app_name'];
- $v['app_logo'] = $article_auth['app_logo'];
- });
- $total_num =DatumCommentLike::where(['l.user_id'=>$this->user_id,'l.type'=>1])
- ->alias('l')
- ->leftJoin('DatumComment c','l.like_id = c.id')
- ->leftJoin('DatumUrl i','i.id = c.url_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]);
- }
- /**
- * @title 我的回复
- * @desc 我的回复
- * @author qc
- * @method GET
- * @url /api/Datum/getReplyDatum
- * @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:datum_id type:string default:-- desc:系列id
- * @return name:url_id type:string default:-- desc:资料url_id
- * @return name:url type:string default:-- desc:资料路径
- * @return name:create_at type:string default:-- desc:时间
- * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
- * @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.serites_title type:string default:-- desc:系列标题
- * @return name:parent_comment.datum_id type:string default:-- desc:系列id
- * @return name:parent_comment.url_id type:string default:-- desc:url_id
- */
- public function getReplyDatum()
- {
- $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.lev','>=',2];
- $list = DatumComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.datum_id,t.is_top,t.url_id,t.create_at,t.lev,t.content,i.title,t.pid,i.url,i.read_num')
- ->leftJoin('DatumUrl i','t.url_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['read_num'] = numTransform($v['read_num']);
- $v['user_name'] = $user_info['name'];
- $v['headimg'] = $user_info['headimg'];
- $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $parent_comment = DatumComment::where([['t.id','=',$v['pid']]])
- ->field('t.id,t.datum_id,t.is_top,t.url_id,i.user_id,t.content,i.title,i.url,t.pid,u.name,x.title series_title')
- ->alias('t')
- ->leftJoin('DatumUrl i','t.url_id = i.id')
- ->leftJoin('DatumIntro x','t.datum_id = x.id')
- ->leftJoin('store_member u','t.user_id = u.id')
- ->find()->toArray();
- $datum_auth = ArticleItem::getArticleAuth($parent_comment['user_id'],APPNAME,APPLOGO);
- $parent_comment['read_num'] = numTransform($v['read_num']);
- $parent_comment['app_name'] = $datum_auth['app_name'];
- $parent_comment['app_logo'] = $datum_auth['app_logo'];
- $v['app_name'] =$datum_auth['app_name'];
- $v['app_logo'] = $datum_auth['app_logo'];
- $v['parent_comment'] = $parent_comment;
- }
- $total_num = DatumComment::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.url_id = i.id')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num,'user_id'=>$this->user_id]);
- }
- /**
- * @title 我的评论【学习服务--我评论过的资料】
- * @desc 我的评论
- * @author qc
- * @method GET
- * @url /api/Datum/getCommentDatum
- * @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:series_title type:string default:-- desc:系列标题
- * @return name:datum_id type:string default:-- desc:系列id
- * @return name:url_id type:string default:-- desc:资料url_id
- * @return name:url type:string default:-- desc:路径
- * @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:发布者头像
- */
- public function getCommentDatum()
- {
- $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.lev','=',1];
- $sel_where[] = ['t.pid','=',0];
- $list = DatumComment::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.datum_id,t.url_id,t.is_top,t.lev,t.content,i.title,i.url,i.read_num,x.title series_title,i.user_id')
- ->leftJoin('DatumUrl i','t.url_id = i.id')
- ->leftJoin('DatumIntro x','t.datum_id = x.id')
- ->order('t.is_top desc,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['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
- $datum_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
- $v['app_name'] = $datum_auth['app_name'];
- $v['app_logo'] = $datum_auth['app_logo'];
- }
- $total_num = DatumComment::where($sel_where)->alias('t') ->leftJoin('DatumUrl i','t.url_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/Datum/getPurchaseDatum
- * @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:datum_id type:string default:-- desc:资料id
- * @return name:item_id type:string default:-- desc:item_id
- * @return name:create_at type:string default:-- desc:时间
- * @return name:total_sequel type:int default:-- desc:期数
- * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
- * @return name:is_recently type:int default:-- desc:是否最近观看【0否1是】
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:recently_title type:string default:-- desc:上次观看标题
- */
- public function getPurchaseDatum()
- {
- $sel_where = [];
- $title = input('get.title');
- if($title) $sel_where[] = ['a.title|a.label','like','%'.$title.'%'];
- $sel_where[] = ['t.user_id','=',$this->user_id];
- $sel_where[] = ['t.type','=',2];
- $sel_where[] = ['t.end_int','>',time()];
- $sel_where[] = ['t.is_deleted','=',0];
- $sel_where[] = ['a.is_deleted','=',0];
- $list = UserLearn::where($sel_where)
- ->alias('t')
- ->field('t.id,t.create_at,t.first_id datum_id,t.second_id item_id,a.title,a.total_sequel,a.read_num')
- ->leftJoin('datum_intro a','t.first_id = a.id')
- ->leftJoin('datum_url i','t.second_id = i.id')
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function (&$v){
- $v['is_normal'] = 1;//CheckPower::checkModulesPower($v['article_id'],$v['item_id'],$this->request->controller());
- $recently_id = UserTrack::getRecentlyTrack($this->user_id,2,$v['datum_id']);
- $v['is_recently'] = $recently_id ? 1 : 0;
- $v['recently_title'] = DatumUrl::where('id',$recently_id)->value('title');
- });
- $total_num = UserLearn::where($sel_where)->alias('t') ->leftJoin('datum_url i','t.second_id = i.id')
- ->leftJoin('datum_intro a','t.first_id = a.id')->count();
- $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
- }
- }
|