Datum.php 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\ArticleItem;
  4. use app\common\model\DatumCate;
  5. use app\common\model\DatumComment;
  6. use app\common\model\DatumCommentLike;
  7. use app\common\model\DatumIntro;
  8. use app\common\model\DatumLike;
  9. use app\common\model\DatumUrl;
  10. use app\common\model\PlatformSwitch;
  11. use app\common\model\TopSearch;
  12. use app\common\model\User;
  13. use app\common\model\UserCollect;
  14. use app\common\model\UserDatum;
  15. use app\common\model\UserDownload;
  16. use app\common\model\UserLearn;
  17. use app\common\model\UserLevelRank;
  18. use app\common\model\UserMessage;
  19. use app\common\model\UserSearch;
  20. use app\common\model\UserTrack;
  21. use app\common\service\CheckPower;
  22. use app\common\service\UserSynth;
  23. use library\tools\Data;
  24. use think\Db;
  25. /**
  26. * @title 资料
  27. * @controller Datum
  28. * @group base
  29. */
  30. class Datum extends Base
  31. {
  32. // 需要登录的
  33. protected $need_login = [
  34. 'datumTransmit',
  35. 'datumDownload',
  36. 'datumRead',
  37. 'datumCollect',
  38. 'datumTags',
  39. 'userReferDatum',
  40. 'getMyDatumList',
  41. 'getUserDatumDetail',
  42. 'delUserDatum',
  43. 'getDownloadDatum',
  44. 'getLearnHistory',
  45. 'getDatumCollect',
  46. 'getBoundList',
  47. 'getFollowUpList',
  48. 'secondCommend',
  49. 'praiseMyDatumList',
  50. 'datumComment',
  51. 'delComment',
  52. 'batchesDel',
  53. 'commentTags',
  54. 'unreadChange',
  55. 'getFollowUpMessage',
  56. 'praiseMyComment',
  57. 'getReplyComment',
  58. 'commentMyDatum',
  59. 'getTagsDatum',
  60. 'getTagsComment',
  61. 'getReplyDatum',
  62. 'getCommentDatum',
  63. 'getDatumItemInfo', //1.5新增
  64. 'getDatumDetail', //1.5新增
  65. ];
  66. public function initialize()
  67. {
  68. parent::initialize();
  69. parent::setUid();
  70. $this->source_type= $this->request->header('source_type',1);
  71. }
  72. /**
  73. * @title 资料接口说明
  74. * @desc 资料接口说明
  75. * @author qc
  76. * @url /api/Datum/classIntro
  77. * @method GET
  78. * @return name:1 type:string default:-- desc:单一资料与系列资料区别,type值(1是单一,2是系列),数据:url_arr二维数组数据数量不一样(单一的只有一个,系列的可以是多个)【可以将单一资料看做只有一条记录的系列资料!!!!】
  79. * @return name:2 type:string default:-- desc:单一资料详情的字段(除id)与url_arr数组的第一个同字段名的值相同
  80. * @return name:3 type:string default:-- desc:系列资料详情的字段(除id)与url_arr数组的其中一个同字段名的值相同
  81. * @return name:4 type:string default:-- desc:关于是否的字段(0否,1是)
  82. * @return name:5 type:string default:-- desc:url_id是详情或列表url_arr下的id
  83. */
  84. public function classIntro(){ }
  85. /**
  86. * @title 获取资料目录
  87. * @desc 获取资料目录
  88. * @author qc
  89. * @url /api/Datum/getDatumCate
  90. * @method GET
  91. * @header name:Authorization require:1 desc:Token
  92. * @return name:id type:int default:-- desc:id
  93. * @return name:title type:string default:0 desc:名称
  94. * @return name:datum_list type:array default:0 desc:目录下的资料
  95. * @return name:datum_list.id type:int default:0 desc:资料记录
  96. * @return name:datum_list.title type:int default:0 desc:资料标题
  97. */
  98. public function getDatumCate()
  99. {
  100. $list = DatumCate::field('id,title')->where('is_deleted',0)->where('status',1)->select()->toArray();
  101. foreach ($list as &$v) {
  102. $v['datum_list'] = DatumIntro::field('id,title')
  103. ->where(['datum_cate'=>$v['id'],'status'=>1,'is_deleted'=>0])->select()->toArray();
  104. }
  105. $this->success('ok',['list'=>$list]);
  106. }
  107. /**
  108. * @title 资料推荐
  109. * @desc 资料推荐
  110. * @author qc
  111. * @method GET
  112. * @url /api/Datum/getRecommendList
  113. * @header name:Authorization require:1 desc:Token
  114. * @param name:page type:int default:0 desc:页数
  115. * @param name:page_num type:int default:20 desc:每页数
  116. * @param name:rand_user type:string default:-- desc:随机id(非登录状态必传,page=1时生成(a123),其他页数(a123),一直查询到没有数据)
  117. * @return name:id type:string default:-- desc:资料item_id
  118. * @return name:title type:string default:-- desc:标题
  119. * @return name:datum_id type:string default:-- desc:系列id
  120. * @return name:is_vip type:int default:-- desc:是否是vip(0否,1是)
  121. * @return name:read_num type:int default:-- desc:阅读量
  122. * @return name:down_num type:int default:-- desc:下载量
  123. * @return name:url type:int default:-- desc:资料路径
  124. * @return name:app_name type:string default:-- desc:发布者
  125. * @return name:app_logo type:string default:-- desc:发布者头像
  126. * @return name:create_at type:string default:-- desc:时间
  127. * @return name:is_down type:int default:-- desc:是否能下载(0否1是)
  128. * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
  129. * @return name:pdf_clear type:string default:-- desc:资料未加密路径【is_encrypt=1时用】
  130. * @return name:is_release type:int default:-- desc:是否释放【0否1是】,已释放不需要购买vip
  131. * @return name:release_time type:string default:-- desc:上架时间
  132. */
  133. public function getRecommendList()
  134. {
  135. $user_id = $this->user_id ? $this->user_id : input('rand_user');
  136. if(!$user_id) $this->error('参数错误');
  137. $list = UserSynth::getRecommendList($user_id,'datum',$this->page,$this->page_num);
  138. if($list['code'] != 200) $this->error($list['msg']);
  139. $this->success('ok',$list);
  140. $search_log = UserSearch::getSearchTitle($this->user_id,3);
  141. $search_arr = [];
  142. $where_str = 'b.id > 0';
  143. foreach ($search_log as $t){
  144. $search_arr[] = " b.title like '".'%'.$t."%'" .' ';
  145. $search_arr[] = " b.label like '".'%'.$t."%'" .' ';
  146. }
  147. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  148. $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 ';
  149. $table = 'dd_datum_url';
  150. $order_by_two = 'a.read_num';
  151. $time_str = date("Y-m-d H:i:s");
  152. $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}";
  153. $list = Db::query($sql);
  154. $list = dispose_recommend($list);
  155. array_walk($list,function (&$v,$k){
  156. $v['down_num'] = numTransform($v['down_num']);
  157. $v['read_num'] = numTransform($v['read_num']);
  158. $datum_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
  159. $v['app_name'] = $datum_auth['app_name'];
  160. $v['app_logo'] = $datum_auth['app_logo'];
  161. $v['create_at'] = substr($v['create_at'],0,10);
  162. $v['is_release'] = UserLearn::checkRelease($this->user_id,2,$v['id']);
  163. });
  164. $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 " ;
  165. $total = Db::query($sql2);
  166. $this->success('ok',['list'=>$list,'total_count'=>$total[0]['num'],'page_num'=>$this->page_num]);
  167. }
  168. /**
  169. * @title 获取资料系列列表(平台发布)
  170. * @desc 系列--全部
  171. * @author qc
  172. * @method GET
  173. * @url /api/Datum/getDatumList
  174. * @header name:Authorization require:1 desc:Token
  175. * @param name:title type:string default:-- desc:标题
  176. * @param name:page type:int default:0 desc:页数
  177. * @param name:page_num type:int default:20 desc:每页数
  178. * @param name:sort_type type:int default:1 desc:1默认2时间升序3时间降序
  179. * @return name:id type:int default:-- desc:[请求/api/Datum/getDatumDetail用,请求资料模块其他接口参数:url_id]
  180. * @return name:title type:string default:-- desc:标题列
  181. * @return name:is_over type:int default:-- desc:是否完结(0否,1是)
  182. * @return name:label type:string default:-- desc:标签
  183. * @return name:create_at type:string default:-- desc:时间
  184. * @return name:down_num type:string default:-- desc:下载量
  185. * @return name:is_collect type:int default:-- desc:是否收藏
  186. * @return name:url_arr type:array default:-- desc:资料
  187. * @return name:url_arr.title type:string default:-- desc:资料标题
  188. * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
  189. * @return name:url_arr.url type:string default:-- desc:资料地址
  190. * @return name:url_arr.is_down type:int default:-- desc:是否能下载(0否1是)
  191. * @return name:url_arr.is_encrypt type:int default:-- desc:是否加密(0否1是)
  192. * @return name:url_arr.release_time type:string default:-- desc:上架时间
  193. * @return name:url_arr.pdf_clear type:int default:-- desc:资料未加密路径【is_encrypt=1时用】
  194. */
  195. public function getDatumList()
  196. {
  197. $sel_where = [];
  198. $title = input('get.title');
  199. $type = input('get.type',2);
  200. $is_tj = input('get.is_tj',0);
  201. $sort_type = input('get.sort_type',1);
  202. $sel_where[] = ['is_deleted','=',0];
  203. $sel_where[] = ['status','=',1];
  204. $sel_where[] = ['url_num','>',0];
  205. if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
  206. if($type) $sel_where[] = ['type','=',$type];
  207. $user_id = $this->user_id ? $this->user_id : input('rand_user');
  208. if(!$user_id) $this->error('参数错误');
  209. $list = UserSynth::getRecommendList($user_id,'Intro',$this->page,$this->page_num,$sel_where,input('sort_type',1));
  210. // return json($list);
  211. if($list['code'] != 200) $this->error($list['msg']);
  212. $this->success('ok',$list);
  213. switch ($sort_type) {
  214. case 1:
  215. $order = ['sort'=>'desc','read_num'=>'desc'];
  216. break;
  217. case 2:
  218. $order = ['id'=>'asc','sort'=>'desc'];
  219. break;
  220. case 3:
  221. $order = ['id'=>'desc','sort'=>'desc'];
  222. break;
  223. }
  224. if($title && $this->user_id) UserSearch::saveSearchTitle($this->user_id,$title,3);
  225. $where_str = 'id > 0';
  226. $list = DatumIntro::where($sel_where)->with('urlArr')
  227. ->limit($this->off_set,$this->page_num)
  228. ->where($where_str)
  229. ->order($order)
  230. ->select()->toArray();
  231. array_walk($list,function (&$v,$k){
  232. $v['create_at'] = substr($v['create_at'],0,10);
  233. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['id']);
  234. $v['down_num'] = array_sum(array_column($v['url_arr'],'down_num'));
  235. $v['down_num'] = numTransform($v['down_num']);
  236. $v['datum_url'] = !empty($v['url_arr']) ? $v['url_arr'][0]['url'] : null;
  237. foreach ($v['url_arr'] as &$dv) {
  238. if(in_array($this->source_type,[1])) unset($dv['pdf_clear']);
  239. }
  240. });
  241. $total_num = DatumIntro::where($sel_where)->where($where_str)->count();
  242. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  243. }
  244. /**
  245. * @title 获取资料系列详情(【合集列表】平台)
  246. * @desc 获取资料系列详情
  247. * @author qc
  248. * @method GET
  249. * @url /api/Datum/getDatumDetail
  250. * @header name:Authorization require:1 desc:Token
  251. * @param name:id type:int default:0 desc:资料id
  252. * @param name:sort_type type:int default:1 desc:1正序2倒序
  253. * @return name:title type:string default:-- desc:标题
  254. * @return name:datum_url type:string default:-- desc:资料地址
  255. * @return name:down_num type:string default:-- desc:下载量
  256. * @return name:user_level type:int default:-- desc:会员等级id
  257. * @return name:follow_switch type:int default:-- desc:订阅开关状态【0关闭1开启】
  258. * @return name:is_release type:int default:-- desc:是否释放【0否1是】,已释放不需要购买vip
  259. * @return name:video_id type:int default:-- desc:视频id
  260. * @return name:video_item type:int default:-- desc:item_id
  261. * @return name:goods_id type:int default:-- desc:商品id
  262. * @return name:h5_url type:int default:-- desc:h5的专栏链接
  263. * @return name:user_level type:int default:-- desc:会员等级id
  264. * @return name:url_arr type:array default:-- desc:资料
  265. * @return name:url_arr.id type:int default:-- desc:[请求/api/Datum/getDatumItemInfo用,请求资料模块其他接口参数:url_id]
  266. * @return name:url_arr.title type:string default:-- desc:资料标题
  267. * @return name:url_arr.switch_open type:int default:-- desc:通知开关【0关闭1开启】
  268. * @return name:url_arr.is_vip type:int default:-- desc:是否是vip
  269. * @return name:url_arr.url type:string default:-- desc:资料地址
  270. * @return name:url_arr.is_collect type:int default:-- desc:是否收藏
  271. * @return name:url_arr.collect_num type:int default:-- desc:收藏量
  272. * @return name:url_arr.down_num type:int default:-- desc:下载量
  273. * @return name:url_arr.read_num type:int default:-- desc:阅读量
  274. * @return name:url_arr.is_down type:int default:-- desc:是否能下载【0否1是】
  275. * @return name:url_arr.is_encrypt type:int default:-- desc:是否加密(0否1是)
  276. * @return name:url_arr.pdf_clear type:int default:-- desc:资料未加密路径【is_encrypt=1时用】
  277. * @return name:url_arr.is_recently type:int default:-- desc:是否最近观看【0否1是】
  278. * @return name:url_arr.comment_switch type:int default:-- desc:评论开关【0关闭1开启】
  279. * @return name:url_arr.release_time type:string default:-- desc:上架时间
  280. */
  281. public function getDatumDetail()
  282. {
  283. $sel_where = [];
  284. $sel_where[] = ['id','=',input('get.id')];
  285. $sort_type = input('sort_type',1);
  286. $is_release = UserLearn::checkRelease($this->user_id,2,input('get.id'));
  287. $detail = DatumIntro::where($sel_where)->with(['urlArr'=>function($query)use($sort_type){
  288. // return $query->order('id',$sort_type == 1 ? 'asc' : 'desc');
  289. if($sort_type == 1){
  290. return $query->order('sort asc,id asc');
  291. }else{
  292. return $query->order('sort desc,id desc');
  293. }
  294. }])->find()->toArray();
  295. if((!$is_release && $detail['is_deleted'] == 1) || (!$is_release && $detail['status'] == 0))$this->error('该资料已下线');
  296. if($is_release){
  297. $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();
  298. }
  299. $level_id = UserLevelRank::getUserVip($this->user_id);
  300. $detail['user_level'] = $level_id;
  301. $detail['read_num'] = numTransform(array_sum(array_column($detail['url_arr'],'read_num')));
  302. $detail['down_num'] = numTransform(array_sum(array_column($detail['url_arr'],'down_num')));
  303. $detail['follow_switch'] = PlatformSwitch::checkSwitch($this->user_id,$detail['id'],4);
  304. $detail['is_release'] = UserLearn::checkRelease($this->user_id,2,$detail['id']);
  305. $detail['h5_url'] =$this->request->root(true).'/#/information-collection-list?id='.$detail['id'];
  306. $recently_id = UserTrack::getRecentlyTrack($this->user_id,2,$detail['id']);
  307. foreach ($detail['url_arr'] as &$dv) {
  308. //if($dv['is_vip'] && !$level_id) $dv['url'] = '';
  309. if(in_array($this->source_type,[1])) unset($dv['pdf_clear']);
  310. $dv['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$dv['id'],9);
  311. $dv['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['id'],$dv['id']);
  312. $dv['collect_num'] = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>2,'coll_id'=>$detail['id'],'children_id'=>$dv['id']])->count();
  313. $dv['collect_num'] = numTransform($dv['collect_num']);
  314. $dv['down_num'] = numTransform($dv['down_num']);
  315. $dv['is_recently'] = $dv['id'] == $recently_id ? 1 : 0;
  316. $datum_auth = ArticleItem::getArticleAuth($dv['user_id'],APPNAME,APPLOGO);
  317. $dv['app_name'] = $datum_auth['app_name'];
  318. $dv['app_logo'] = $datum_auth['app_logo'];
  319. }
  320. //DatumIntro::where('id',$detail['id'])->setInc('read_num');
  321. $this->success('ok',['detail'=>$detail]);
  322. }
  323. /**
  324. * @title 获取资料ITEM详情(平台)
  325. * @desc 获取资料ITEM详情
  326. * @author qc
  327. * @method GET
  328. * @url /api/Datum/getDatumItemInfo
  329. * @header name:Authorization require:1 desc:Token
  330. * @param name:url_id type:int default:0 desc:url_id
  331. * @return name:title type:string default:-- desc:资料标题
  332. * @return name:is_vip type:int default:-- desc:是否是vip
  333. * @return name:is_release type:int default:-- desc:是否释放【0否1是】,已释放不需要购买vip
  334. * @return name:cover type:string default:-- desc:封面
  335. * @return name:images type:int default:-- desc:图片
  336. * @return name:content type:int default:-- desc:内容
  337. * @return name:transmit_num type:int default:-- desc:转发量
  338. * @return name:read_num type:int default:-- desc:阅读量
  339. * @return name:collect_num type:int default:-- desc:收藏量
  340. * @return name:down_num type:int default:-- desc:下载量
  341. * @return name:comment_num type:int default:-- desc:评论量
  342. * @return name:is_collect type:int default:-- desc:是否收藏
  343. * @return name:follow_switch type:int default:-- desc:订阅开关状态【0关闭1开启】
  344. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  345. * @return name:praise_num type:int default:-- desc:点赞量
  346. * @return name:is_praise type:int default:-- desc:是否点赞
  347. * @return name:is_down type:int default:-- desc:是否可以下载【0否1是】
  348. * @return name:comment_switch type:int default:-- desc:评论开关【0关闭1开启】
  349. * @return name:app_name type:string default:-- desc:发布者
  350. * @return name:app_logo type:string default:-- desc:发布者头像
  351. * @return name:release_time type:string default:-- desc:上架时间
  352. */
  353. public function getDatumItemInfo()
  354. {
  355. $url_id = input('get.url_id');
  356. $detail = DatumUrl::where('id',$url_id)->find()->toArray();
  357. $is_release = UserLearn::checkRelease($this->user_id,2,$detail['datum_id']);
  358. if($is_release == 0){
  359. if($detail['is_deleted'] == 1 || $detail['status'] == 0) $this->error('该资料已下架');
  360. }
  361. $detail['series_title'] =DatumIntro::where('id',$detail['datum_id'])->value('title');
  362. $detail['follow_switch'] = PlatformSwitch::checkSwitch($this->user_id,$detail['datum_id'],4);
  363. $detail['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$detail['datum_id'],'children_id'=>$detail['id']])->count();
  364. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail['datum_id'],$detail['id']);
  365. $detail['collect_num'] = numTransform($detail['collect_num']);
  366. $detail['down_num'] = numTransform($detail['down_num']);
  367. $detail['read_num'] = numTransform($detail['read_num']);
  368. $detail['transmit_num'] = numTransform($detail['transmit_num']);
  369. $detail['is_release'] = UserLearn::checkRelease($this->user_id,2,$detail['datum_id']);
  370. $detail['comment_num'] = DatumComment::getDatumCommentNum($detail['id']);
  371. $detail['follow_switch'] = PlatformSwitch::checkSwitch($this->user_id,$detail['datum_id'],4);
  372. $detail['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$detail['id'],9);
  373. $detail['praise_num']= DatumLike::where([['url_id','=',$url_id]])->count();
  374. $datum_auth = DatumUrl::getDatumAuth($detail['user_id'],APPNAME,APPLOGO);
  375. $detail['app_name'] = $datum_auth['app_name'];
  376. $detail['app_logo'] = $datum_auth['app_logo'];
  377. $detail['is_praise']= DatumLike::where([['user_id','=',$this->user_id],['url_id','=',$url_id]])->count();
  378. UserTrack::crateTrack($this->user_id,2,$detail['datum_id'],$url_id);
  379. DatumUrl::where('id',$url_id)->setInc('read_num');
  380. DatumIntro::where('id',$detail['datum_id'])->setInc('read_num');
  381. if($this->user_id){
  382. TopSearch::seIncHotNum($url_id,$this->request->controller());
  383. }
  384. $this->success('ok',['detail'=>$detail]);
  385. }
  386. /**
  387. * @title 资料转发(转发数量统计)
  388. * @desc 转发成功后调用
  389. * @author qc
  390. * @method POST
  391. * @url /api/Datum/datumTransmit
  392. * @header name:Authorization require:1 desc:Token
  393. * @param name:datum_id type:int default:-- desc:资料id
  394. *
  395. * @param name:url_id type:int default:-- desc:url_id
  396. */
  397. public function datumTransmit()
  398. {
  399. $datum_id= input('post.datum_id');
  400. $url_id = input('post.url_id',0);
  401. DatumUrl::where('id',$url_id)->setInc('transmit_num');
  402. $this->success('ok');
  403. }
  404. /**
  405. * @title 资料下载(资料下载数量统计)
  406. * @desc 资料下载
  407. * @author qc
  408. * @method POST
  409. * @url /api/Datum/datumDownload
  410. * @header name:Authorization require:1 desc:Token
  411. * @param name:datum_id type:int default:-- desc:资料id
  412. * @param name:url_id type:int default:-- desc:url_id
  413. */
  414. public function datumDownload()
  415. {
  416. $datum_id= input('post.datum_id');
  417. $url_id = input('post.url_id',0);
  418. Data::save('UserDownload',['user_id'=>$this->user_id,'first_id'=>$datum_id,'second_id'=>$url_id]);
  419. DatumUrl::where('id',$url_id)->setInc('down_num');
  420. $this->success('ok');
  421. }
  422. /**
  423. * @title 资料阅读(阅读数量统计)
  424. * @desc 资料阅读
  425. * @author qc
  426. * @method POST
  427. * @url /api/Datum/datumRead
  428. * @header name:Authorization require:1 desc:Token
  429. * @param name:url_id type:int default:-- desc:url_arr的id
  430. */
  431. public function datumRead()
  432. {
  433. $url_id = input('post.url_id',0);
  434. $datum_id = DatumUrl::where('id',$url_id)->value('datum_id');
  435. DatumUrl::where('id',$url_id)->setInc('read_num');
  436. DatumIntro::where('id',$datum_id)->setInc('read_num');
  437. if($this->user_id){
  438. TopSearch::seIncHotNum($url_id,$this->request->controller());
  439. }
  440. $this->success('ok');
  441. }
  442. /**
  443. * @title 资料收藏||取消收藏
  444. * @desc 用户收藏
  445. * @author qc
  446. * @method POST
  447. * @url /api/Datum/datumCollect
  448. * @header name:Authorization require:1 desc:Token
  449. * @param name:datum_id type:int require:1 default:-- desc:记录id[资料id]
  450. * @param name:url_id type:int default:1 desc:url_id
  451. * @return name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  452. */
  453. public function datumCollect()
  454. {
  455. $coll_type = input('post.coll_type',2);
  456. $coll_id = input('post.datum_id',0);
  457. $url_id = input('post.url_id',0);
  458. if(!$coll_id || !$url_id) $this->error('参数错误');
  459. $collect_check = UserCollect::checkCollectByType($this->user_id,$coll_type,$coll_id,$url_id);
  460. if($collect_check) {
  461. UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id,'children_id'=>$url_id])->delete();
  462. $this->success('取消收藏成功',['status'=>0]);
  463. }else{
  464. Data::save('UserCollect', [
  465. 'user_id'=>$this->user_id,
  466. 'coll_type'=>$coll_type,
  467. 'coll_id'=>$coll_id,
  468. 'children_id'=>$url_id,
  469. 'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$coll_id,'children_id'=>$url_id]);
  470. $this->success('收藏成功',['status'=>1]);
  471. }
  472. }
  473. /**
  474. * @title 资料点赞||取消点赞
  475. * @desc 点赞||取消点赞
  476. * @author qc
  477. * @method POST
  478. * @url /api/Datum/datumTags
  479. * @header name:Authorization require:1 desc:Token
  480. * @param name:datum_id type:int default:1 desc:资料系列id
  481. * @param name:url_id type:int default:1 desc:资料url_id
  482. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  483. */
  484. public function datumTags()
  485. {
  486. $datum_id = input('post.datum_id');
  487. $url_id = input('post.url_id');
  488. $ret_val = 0;
  489. $check_tags = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->value('id');
  490. if($check_tags) {
  491. DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id])->delete();
  492. }else{
  493. $p_user_id = DatumUrl::where('id',$url_id)->value('user_id');
  494. $is_read = $p_user_id == $this->user_id ? 1 : 0;
  495. Data::save('DatumLike',
  496. ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id,'is_read'=>$is_read],'user_id',
  497. ['user_id'=>$this->user_id,'datum_id'=>$datum_id,'url_id'=>$url_id]);
  498. $ret_val = 1;
  499. }
  500. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  501. }
  502. /**
  503. * @title 用户提交或修改资料【个人】
  504. * @desc 用户提交或修改资料【个人】
  505. * @author qc
  506. * @method POST
  507. * @url /api/Datum/userReferDatum
  508. * @header name:Authorization require:1 desc:Token
  509. * @param name:id type:int default:-- desc:id(修改时必传)
  510. * @param name:title type:string default:-- desc:标题
  511. * @param name:datum_url type:string default:-- desc:资料地址
  512. * @param name:desc type:string default:-- desc:简介
  513. * @param name:label type:string default:-- desc:资料标签id(多个用逗号隔开)
  514. */
  515. public function userReferDatum()
  516. {
  517. $id = input('post.id',0);
  518. $title = input('post.title');
  519. $desc = input('post.desc');
  520. $datum_url = input('post.datum_url');
  521. $label = input('post.label');
  522. if(!$datum_url) $this->error('请上传资料');
  523. if($id){
  524. $check_status = UserDatum::where('id',$id)->value('status');
  525. if($check_status == 1) $this->error('已审核通过,不允许修改');
  526. }
  527. $data = [
  528. 'title' => $title,
  529. 'user_id' => $this->user_id,
  530. 'desc' => $desc,
  531. 'datum_url' => $datum_url,
  532. 'label' => $label,
  533. 'status' => 0,
  534. 'remark' => '',
  535. ];
  536. if($id) $data['id'] = $id;
  537. if($id){
  538. UserDatum::where('id',$id)->update($data);
  539. }else{
  540. $res= UserDatum::create($data) ;
  541. }
  542. // UserMessage::sendUserMessage($this->user_id,'datum',1,0,0,$id ? $id:$res->id);
  543. $this->success('提交成功,请等待审核',['id'=> $id ? :$res->id]);
  544. }
  545. /**
  546. * @title 我的发布--其他【个人】
  547. * @desc 获取我的资料列表【个人】
  548. * @author qc
  549. * @method GET
  550. * @url /api/Datum/getMyDatumList
  551. * @header name:Authorization require:1 desc:Token
  552. * @param name:title type:string default:-- desc:标题
  553. * @param name:page type:int default:0 desc:页数
  554. * @param name:page_num type:int default:20 desc:每页数
  555. * @return name:title type:string default:-- desc:标题
  556. * @return name:desc type:string default:-- desc:简介
  557. * @return name:datum_url type:string default:-- desc:资料地址
  558. * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
  559. * @return name:remark type:string default:-- desc:审核备注
  560. * @return name:label type:string default:-- desc:标签
  561. */
  562. public function getMyDatumList()
  563. {
  564. $sel_where = [];
  565. $sel_where[] = ['is_deleted','=',0];
  566. $sel_where[] = ['user_id','=',$this->user_id];
  567. $title = input('get.title');
  568. if($title) $sel_where[] = ['title|label','like','%'.$title.'%'];
  569. $list = UserDatum::where($sel_where)
  570. ->field('id,title,desc,datum_url,status,remark,label')
  571. ->order('id desc')
  572. ->limit($this->off_set,$this->page_num)
  573. ->select()->toArray();
  574. $total_num = UserDatum::where($sel_where)->count();
  575. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  576. }
  577. /**
  578. * @title 获取我的资料详情【个人】
  579. * @desc 获取我的资料列表【个人】
  580. * @author qc
  581. * @method GET
  582. * @url /api/Datum/getUserDatumDetail
  583. * @header name:Authorization require:1 desc:Token
  584. * @param name:id type:string default:-- desc:记录id
  585. * @return name:title type:string default:-- desc:标题
  586. * @return name:desc type:string default:-- desc:简介
  587. * @return name:datum_url type:string default:-- desc:资料地址
  588. * @return name:status type:int default:-- desc:0待审核1审核通过2审核未通过
  589. * @return name:remark type:string default:-- desc:审核备注
  590. * @return name:label type:string default:-- desc:标签
  591. * @return name:label_name type:array default:-- desc:标签数组
  592. */
  593. public function getUserDatumDetail()
  594. {
  595. $detail =UserDatum::where('id',input('get.id'))->field('id,title,desc,datum_url,status,remark,label')->find();
  596. if($this->user_id){
  597. $General = new General();
  598. $General->label($detail['label']);
  599. }
  600. if(!$detail) $this->error('资料有误');
  601. $detail['label_name'] =$detail['label'] ? $detail['label_name'] = explode(',',trim($detail['label'],',')) : null;
  602. $this->success('ok',['detail'=>$detail->toArray()]);
  603. }
  604. /**
  605. * @title 用户删除资料记录【个人】
  606. * @desc 用户删除资料记录【个人】
  607. * @author qc
  608. * @method POST
  609. * @url /api/Datum/delUserDatum
  610. * @header name:Authorization require:1 desc:Token
  611. * @param name:id type:int default:-- desc:id
  612. */
  613. public function delUserDatum()
  614. {
  615. UserDatum::where(['user_id'=>$this->user_id,'id'=>input('post.id')])->delete();
  616. $this->success('删除成功');
  617. }
  618. /**
  619. * @title 我的下载
  620. * @desc 获取下载资料列表
  621. * @author qc
  622. * @method GET
  623. * @url /api/Datum/getDownloadDatum
  624. * @header name:Authorization require:1 desc:Token
  625. * @param name:title type:string default:-- desc:标题
  626. * @param name:page type:int default:0 desc:页数
  627. * @param name:page_num type:int default:20 desc:每页数
  628. * @return name:title type:string default:-- desc:标题
  629. * @return name:series_title type:string default:-- desc:系列标题
  630. * @return name:datum_id type:int default:-- desc:资料id
  631. * @return name:url_id type:int default:-- desc:item_id
  632. * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
  633. * @return name:url type:string default:-- desc:资料路径
  634. * @return name:read_num type:string default:-- desc:阅读量
  635. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  636. * @return name:app_name type:string default:-- desc:发布者
  637. * @return name:app_logo type:string default:-- desc:发布者头像
  638. */
  639. public function getDownloadDatum()
  640. {
  641. $sel_where = [];
  642. $title = input('get.title');
  643. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  644. $sel_where[] = ['t.user_id','=',$this->user_id];
  645. $sel_where[] = ['t.type','=',1];
  646. $list = UserDownload::where($sel_where)
  647. ->alias('t')
  648. ->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')
  649. ->leftJoin('DatumUrl i','t.second_id = i.id')
  650. ->leftJoin('DatumIntro x','t.first_id = x.id')
  651. ->order('id desc')
  652. ->limit($this->off_set,$this->page_num)
  653. ->select()->toArray();
  654. foreach ($list as &$v) {
  655. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  656. $datum_auth = DatumUrl::getDatumAuth($v['user_id'],APPNAME,APPLOGO);
  657. $v['app_name'] = $datum_auth['app_name'];
  658. $v['app_logo'] = $datum_auth['app_logo'];
  659. }
  660. $total_num = UserDownload::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.second_id = i.id')->count();
  661. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  662. }
  663. /**
  664. * @title 资料学习历史
  665. * @desc 资料学习历史
  666. * @author qc
  667. * @method GET
  668. * @url /api/Datum/getLearnHistory
  669. * @header name:Authorization require:1 desc:Token
  670. * @param name:title type:string default:-- desc:标题
  671. * @param name:page type:int default:0 desc:页数
  672. * @param name:page_num type:int default:20 desc:每页数
  673. * @return name:title type:string default:-- desc:标题
  674. * @return name:datum_id type:int default:-- desc:资料id
  675. * @return name:url_id type:int default:-- desc:item_id
  676. * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
  677. * @return name:read_num type:int default:-- desc:阅读量
  678. * @return name:url type:string default:-- desc:资料路径
  679. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  680. * @return name:app_name type:string default:-- desc:发布者
  681. * @return name:app_logo type:string default:-- desc:发布者头像
  682. * @return name:is_down type:int default:-- desc:是否能下载(0否1是)
  683. * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
  684. * @return name:pdf_clear type:int default:-- desc:资料未加密路径【is_encrypt=1时用】
  685. */
  686. public function getLearnHistory()
  687. {
  688. $sel_where = [];
  689. $sel_where[] = ['t.user_id','=',$this->user_id];
  690. $sel_where[] = ['t.type','=',2];
  691. $title = input('get.title');
  692. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  693. $list = UserTrack::where($sel_where)
  694. ->alias('t')
  695. ->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')
  696. ->leftJoin('DatumUrl i','t.second_id = i.id')
  697. ->order('update_int desc')
  698. ->limit($this->off_set,$this->page_num)
  699. ->select()->toArray();
  700. foreach ($list as &$v) {
  701. $v['time'] = date("Y-m-d H:i:s",$v['update_int']);
  702. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  703. $datum_auth = DatumUrl::getDatumAuth($v['user_id'],APPNAME,APPLOGO);
  704. $v['app_name'] = $datum_auth['app_name'];
  705. $v['app_logo'] = $datum_auth['app_logo'];
  706. }
  707. $total_num = UserTrack::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.second_id = i.id')->count();
  708. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  709. }
  710. /**
  711. * @title 我的收藏--资料收藏记录
  712. * @desc 资料收藏记录
  713. * @author qc
  714. * @method GET
  715. * @url /api/Datum/getDatumCollect
  716. * @header name:Authorization require:1 desc:Token
  717. * @param name:title type:string default:-- desc:标题
  718. * @param name:page type:int default:0 desc:页数
  719. * @param name:page_num type:int default:20 desc:每页数
  720. * @return name:title type:string default:-- desc:标题
  721. * @return name:series_title type:string default:-- desc:系列标题
  722. * @return name:datum_id type:string default:-- desc:资料id
  723. * @return name:url_id type:string default:-- desc:url_id
  724. * @return name:url type:string default:-- desc:资料路径
  725. * @return name:create_at type:string default:-- desc:时间
  726. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  727. * @return name:app_name type:string default:-- desc:发布者
  728. * @return name:app_logo type:string default:-- desc:发布者头像
  729. * @return name:is_down type:int default:-- desc:是否能下载(0否1是)
  730. * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
  731. * @return name:pdf_clear type:string default:-- desc:资料未加密路径【is_encrypt=1时用】
  732. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  733. * @return name:transmit_num type:int default:-- desc:转发量
  734. * @return name:read_num type:int default:-- desc:阅读量
  735. * @return name:collect_num type:int default:-- desc:收藏量
  736. * @return name:down_num type:int default:-- desc:下载量
  737. * @return name:comment_num type:int default:-- desc:评论量
  738. * @return name:is_collect type:int default:-- desc:是否收藏
  739. * @return name:like_num type:int default:-- desc:点赞数量
  740. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  741. */
  742. public function getDatumCollect()
  743. {
  744. $sel_where = [];
  745. $title = input('get.title');
  746. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  747. $sel_where[] = ['t.user_id','=',$this->user_id];
  748. $sel_where[] = ['t.coll_type','=',2];
  749. $list = UserCollect::where($sel_where)
  750. ->alias('t')
  751. ->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')
  752. ->leftJoin('DatumUrl i','t.children_id = i.id')
  753. ->leftJoin('DatumIntro x','t.coll_id = x.id')
  754. ->order('id desc')
  755. ->limit($this->off_set,$this->page_num)
  756. ->select()->toArray();
  757. array_walk($list,function (&$v){
  758. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['url_id'],9);
  759. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  760. $datum_auth = DatumUrl::getDatumAuth($v['user_id'],APPNAME,APPLOGO);
  761. $v['app_name'] = $datum_auth['app_name'];
  762. $v['app_logo'] = $datum_auth['app_logo'];
  763. $v['down_num'] = numTransform($v['down_num']);
  764. $v['read_num'] = numTransform($v['read_num']);
  765. $v['transmit_num'] = numTransform($v['transmit_num']);
  766. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['datum_id'],$v['url_id']);
  767. $v['collect_num'] = UserCollect::getCollectNum(2,$v['datum_id'],$v['url_id'] );
  768. $v['like_num'] = DatumLike::where('url_id',$v['url_id'])->count();
  769. $v['like_num'] = numTransform($v['like_num']);
  770. $v['is_like'] = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$v['datum_id'],'url_id'=>$v['url_id']])->count();
  771. $v['comment_num'] = DatumComment::getDatumCommentNum($v['url_id']);
  772. });
  773. $total_num =UserCollect::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.children_id = i.id')->count();
  774. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  775. }
  776. /**
  777. * @title 以下接口为二期需求
  778. * @desc 以下接口为二期需求
  779. * @author qc
  780. * @url /api/Datum/secondPhase
  781. * @method
  782. * @return name:1 type:string default:-- desc:以下接口为二期需求
  783. */
  784. public function secondPhase(){}
  785. /**
  786. * @title 我的发布--审核成功【后台资料绑定该会员】
  787. * @desc 后台资料绑定该会员
  788. * @author qc
  789. * @method GET
  790. * @url /api/Datum/getBoundList
  791. * @header name:Authorization require:1 desc:Token
  792. * @param name:title type:string default:-- desc:标题
  793. * @param name:page type:int default:0 desc:页数
  794. * @param name:page_num type:int default:20 desc:每页数
  795. * @return name:id type:string default:-- desc:记录id【url_id】
  796. * @return name:title type:string default:-- desc:标题
  797. * @return name:series_title type:string default:-- desc:系列标题
  798. * @return name:datum_id type:string default:-- desc:资料id
  799. * @return name:create_at type:string default:-- desc:时间
  800. * @return name:url type:string default:-- desc:文件路径
  801. * @return name:is_vip type:int default:-- desc:是否是vip[0否1是]
  802. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  803. * @return name:is_down type:int default:-- desc:是否能下载(0否1是)
  804. * @return name:is_encrypt type:int default:-- desc:是否加密(0否1是)
  805. * @return name:pdf_clear type:string default:-- desc:资料未加密路径【is_encrypt=1时用】
  806. */
  807. public function getBoundList()
  808. {
  809. $sel_where = [];
  810. $title = input('get.title');
  811. $sel_where[] = ['t.user_id','=',$this->user_id];
  812. $sel_where[] = ['t.is_deleted','=',0];
  813. if($title) $sel_where[] = ['t.title|t.label','like','%'.$title.'%'];
  814. $list = DatumUrl::where($sel_where)
  815. ->alias('t')
  816. ->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')
  817. ->order('t.id desc')
  818. ->leftJoin('DatumIntro x','x.id = t.datum_id')
  819. ->limit($this->off_set,$this->page_num)
  820. ->select()->toArray();
  821. foreach ($list as &$v) {
  822. $v['read_num'] = numTransform($v['read_num']);
  823. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['id'],$this->request->controller());
  824. }
  825. $total_num= DatumUrl::where($sel_where) ->alias('t')->count();
  826. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  827. }
  828. /**
  829. * @title 我的订阅--资料
  830. * @desc 我的订阅列表
  831. * @author qc
  832. * @method GET
  833. * @url /api/Datum/getFollowUpList
  834. * @header name:Authorization require:1 desc:Token
  835. * @param name:title type:string default:-- desc:标题
  836. * @param name:page type:int default:0 desc:页数
  837. * @param name:page_num type:int default:20 desc:每页数
  838. * @return name:create_at type:string default:-- desc:追更设置时间
  839. * @return name:datum_id type:int default:-- desc:资料id
  840. * @return name:title type:string default:-- desc:标题
  841. * @return name:recently_title type:int default:-- desc:上次观看title
  842. * @return name:is_deleted type:int default:-- desc:是否删除【0否1是】
  843. * @return name:total_sequel type:int default:-- desc:期数
  844. * @return name:is_recently type:int default:-- desc:是否最近观看【0否1是】
  845. * @return name:recently_id type:int default:-- desc:上次观看记录id
  846. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  847. */
  848. public function getFollowUpList()
  849. {
  850. $sel_where = [];
  851. $sel_where[] = ['p.user_id','=',$this->user_id];
  852. $sel_where[] = ['p.type','=',4];
  853. $sel_where[] = ['p.switch_value','=',1];
  854. $title = input('title');
  855. if($title) $sel_where[] = ['a.title','like','%'.$title.'%'];
  856. $field = 'p.id,p.switch_id as datum_id,p.create_at,a.title,a.is_deleted,total_sequel,a.status ,a.is_deleted';
  857. $list = PlatformSwitch::field($field)
  858. ->alias('p')->leftJoin('DatumIntro a','p.switch_id = a.id')
  859. ->where($sel_where)->limit($this->off_set,$this->page_num)
  860. ->order('p.id desc')->select()->toArray();
  861. array_walk($list,function (&$v){
  862. $v['is_normal'] = $v['status'] == 1 && $v['is_deleted'] == 0 ? 1 : 0;
  863. $recently_id = UserTrack::getRecentlyTrack($this->user_id,2,$v['datum_id']);
  864. $v['is_recently'] = $recently_id ? 1 : 0;
  865. $v['recently_id'] = $recently_id ? $recently_id : 0;
  866. $v['recently_title'] = UserTrack::getRecentlyTitle($this->user_id,2,$v['datum_id']);
  867. });
  868. $total_num = PlatformSwitch::field($field)->alias('p')->leftJoin('DatumIntro a','p.switch_id = a.id')->where($sel_where)->count();
  869. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  870. }
  871. /**
  872. * @title 资料评论
  873. * @desc 资料评论
  874. * @author qc
  875. * @method POST
  876. * @url /api/Datum/datumComment
  877. * @header name:Authorization require:1 desc:Token
  878. * @param name:datum_id type:int default:1 desc:资料系列id
  879. * @param name:url_id type:int default:1 desc:资料id
  880. * @param name:content type:string default:-- desc:内容
  881. * @return name:name type:string default:-- desc:会员名称
  882. * @return name:headimg type:string default:-- desc:会员头像
  883. * @return name:content type:string default:-- desc:内容
  884. */
  885. public function datumComment()
  886. {
  887. $datum_id = input('post.datum_id');
  888. $url_id = input('post.url_id');
  889. $content = input('post.content',0);
  890. if(!$content) $this->error('请输入评论内容');
  891. $comment_switch = DatumUrl::where('id',$url_id)->value('comment_switch');
  892. $send_user = DatumUrl::where('id',$url_id)->value('user_id');
  893. if(!$comment_switch) $this->error('评论功能已关闭');
  894. $res = DatumComment::create([
  895. 'user_id'=>$this->user_id,
  896. 'content'=>$content,
  897. 'datum_id'=>$datum_id,
  898. 'url_id'=>$url_id,
  899. 'is_read' => $send_user == $this->user_id ? 1 : 0,
  900. 'source_read' => $send_user == $this->user_id ? 1 : 0,
  901. ]);
  902. $detail =DatumComment::where('c.id',$res->id)
  903. ->alias('c')
  904. ->field('c.id,c.content,c.create_at,u.name,u.headimg')
  905. ->leftJoin('store_member u','u.id = c.user_id')
  906. ->find()->toArray();
  907. $user_info = $this->userInfo('name');
  908. 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);
  909. $this->success('评论成功',['detail'=>$detail]);
  910. }
  911. /**
  912. * @title 删除评论
  913. * @desc 删除评论
  914. * @author qc
  915. * @method POST
  916. * @url /api/Datum/delComment
  917. * @header name:Authorization require:1 desc:Token
  918. * @param name:id type:int default:1 desc:评论id
  919. */
  920. public function delComment(){
  921. DatumComment::where(['id'=>input('post.id'),'user_id'=>$this->user_id])->update(['is_deleted'=>1]);
  922. $this->success('删除成功');
  923. }
  924. /**
  925. * @title 资料二级评论
  926. * @desc 资料二级评论
  927. * @author qc
  928. * @method POST
  929. * @url /api/Datum/secondCommend
  930. * @header name:Authorization require:1 desc:Token
  931. * @param name:id type:int default:1 desc:评论id
  932. * @param name:content type:string default:-- desc:内容
  933. * @return name:name type:string default:-- desc:会员名称
  934. * @return name:headimg type:string default:-- desc:会员头像
  935. * @return name:content type:string default:-- desc:内容
  936. */
  937. public function secondCommend()
  938. {
  939. $comment = DatumComment::where('id',input('post.id'))->find()->toArray();
  940. $user_info = $this->userInfo('name');
  941. $content = input('post.content');
  942. 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']);
  943. $send_user = DatumUrl::where('id',$comment['url_id'])->value('user_id');
  944. $comment_switch = DatumUrl::where('id',$comment['url_id'])->value('comment_switch');
  945. if(!$comment_switch) $this->error('评论功能已关闭');
  946. $to_user = $comment['user_id'];
  947. 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']);
  948. unset($comment['id']);
  949. unset($comment['create_at']);
  950. unset($comment['to_deleted']);
  951. unset($comment['is_top']);
  952. unset($comment['is_deleted']);
  953. $comment['pid'] = input('post.id');
  954. $comment['user_id'] = $this->user_id;
  955. $comment['content'] = input('post.content');
  956. $comment['lev']++;
  957. $comment['is_read']= $this->user_id == $to_user ? 1 :0 ;
  958. $comment['source_read'] = $this->user_id == $send_user ? 1 :0 ;
  959. if(!$comment['source_id']) $comment['source_id'] = input('post.id');
  960. $res = DatumComment::create($comment);
  961. $detail = DatumComment::where('c.id',$res->id)
  962. ->alias('c')->field('c.id,c.content,c.create_at,u.name,u.headimg')
  963. ->leftJoin('store_member u','u.id = c.user_id')->find()->toArray();
  964. $this->success('评论成功',['detail'=>$detail]);
  965. }
  966. /**
  967. * @title 资料评论列表
  968. * @desc 资料评论列表
  969. * @author qc
  970. * @method GET
  971. * @url /api/Datum/getDatumCommentList
  972. * @header name:Authorization require:1 desc:Token
  973. * @param name:url_id type:int default:-- desc:资料id
  974. * @param name:sort_type type:int default:1 desc:排序1最新2最热
  975. * @param name:page type:int default:-- desc:页数
  976. * @return name:name type:string default:-- desc:会员名称
  977. * @return name:headimg type:string default:-- desc:会员头像
  978. * @return name:content type:string default:-- desc:内容
  979. * @return name:parent type:array default:-- desc:评论上一级(数据同上【一维数组】)
  980. * @return name:children type:array default:-- desc:二级评论(数据同上【二维数组】)
  981. * @return name:like_num type:int default:-- desc:点赞数量
  982. * @return name:is_like type:int default:-- desc:是否点赞(0否1是)
  983. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  984. * @return name:can_delete type:int default:-- desc:是否可以删除(0否1是)
  985. * @return name:total_num type:int default:-- desc:总评论数(仅一级)
  986. */
  987. public function getDatumCommentList()
  988. {
  989. $where = [];
  990. $where[] = ['c.url_id','=',input('get.url_id')];
  991. $where[] = ['c.is_deleted','=',0];
  992. $user_id = $this->user_id;
  993. $sort_type= input('sort_type',1);
  994. switch ($sort_type) {
  995. case 1:
  996. $order = ['is_top'=>'desc','id'=>'desc'];
  997. break;
  998. default:
  999. $order = ['is_top'=>'desc','like_times'=>'desc','id'=>'desc'];
  1000. break;
  1001. }
  1002. $list =DatumComment::where($where)
  1003. ->alias('c')->field('c.*,u.name,u.headimg')
  1004. ->leftJoin('store_member u','u.id = c.user_id')
  1005. ->order($order)->limit($this->off_set,$this->page_num)
  1006. ->select()->toArray();
  1007. array_walk($list,function (&$val,$k)use($user_id){
  1008. $children = DatumComment::where(['c.pid'=>$val['id'],'c.is_deleted'=>0])
  1009. ->alias('c')->field('c.*,u.name,u.headimg')
  1010. ->leftJoin('store_member u','u.id = c.user_id')
  1011. ->order('c.is_top desc,c.id asc')->select()->toArray();
  1012. $val['children'] = $children;
  1013. $val['like_num'] = DatumCommentLike::where('like_id',$val['id'])->count();
  1014. $val['like_num'] = numTransform($val['like_num']);
  1015. $val['is_like'] = DatumCommentLike::where(['like_id'=>$val['id'],'user_id'=>$user_id])->count();
  1016. $parent = DatumComment::where(['c.id'=>$val['pid'],'c.is_deleted'=>0])
  1017. ->alias('c')->field('c.*,u.name,u.headimg')->leftJoin('store_member u','u.id = c.user_id')->find();
  1018. $val['parent'] = $parent ? $parent->toArray() : null;
  1019. $val['parent_comment'] = $val['parent'] ;
  1020. $val['can_delete'] = $val['user_id'] == $this->user_id ? 1 :0;
  1021. });
  1022. $total_num = DatumComment::where($where)->alias('c')->count();
  1023. $this->success('ok',['list'=>$list,'total_num'=>numTransform($total_num),'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1024. }
  1025. /**
  1026. * @title 批量删除||批量取消
  1027. * @desc 删除||取消
  1028. * @author qc
  1029. * @method POST
  1030. * @url /api/Datum/batchesDel
  1031. * @header name:Authorization require:1 desc:Token
  1032. * @param name:id type:string default:1 desc:记录id【多个用逗号隔开=>'1,2'】
  1033. * @param name:type type:string default:1 desc:消息类型【1我的评论,2评论我的,3我的回复,4我的已购,5用户资料删除,6订阅记录,7订阅消息,8我的点赞-资料,9我的点赞-评论,10回复我的,11点赞我的--资料,12点赞我的--评论,13我的收藏,14我的下载,】
  1034. */
  1035. public function batchesDel(){
  1036. $type = input('post.type',1);
  1037. $del_where = [];
  1038. $del_where[] = ['id','in',input('post.id')];
  1039. if(in_array($type,[1,3,4,5,6,7,8,9,13,14])) $del_where[] = ['user_id','=',$this->user_id];
  1040. if(in_array($type,[1,3])) DatumComment::where($del_where)->update(['is_deleted'=>1]);
  1041. if(in_array($type,[2])) DatumComment::where($del_where)->update(['source_deleted'=>1,'source_read'=>1,'is_read'=>1]);
  1042. if(in_array($type,[10])) DatumComment::where($del_where)->update(['to_deleted'=>1,'to_read'=>1]);
  1043. if(in_array($type,[4])) UserLearn::where($del_where)->update(['is_deleted'=>1]);
  1044. if(in_array($type,[5])) UserDatum::where($del_where)->update(['is_deleted'=>1]);
  1045. if(in_array($type,[6])) PlatformSwitch::where($del_where)->delete();
  1046. if(in_array($type,[7])) UserMessage::where($del_where)->update(['is_deleted'=>1]);
  1047. if(in_array($type,[8])) DatumLike::where($del_where)->delete();
  1048. if(in_array($type,[11])) DatumLike::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
  1049. if(in_array($type,[9])) DatumCommentLike::where($del_where)->delete();
  1050. if(in_array($type,[12])) DatumCommentLike::where($del_where)->update(['to_deleted'=>1,'is_read'=>1]);
  1051. if(in_array($type,[13])) UserCollect::where($del_where)->delete();
  1052. if(in_array($type,[14])) UserDownload::where($del_where)->delete();
  1053. $this->success('操作成功');
  1054. }
  1055. /**
  1056. * @title 评论点赞||取消点赞
  1057. * @desc 评论
  1058. * @author qc
  1059. * @method POST
  1060. * @url /api/Datum/commentTags
  1061. * @header name:Authorization require:1 desc:Token
  1062. * @param name:comment_id type:int default:1 desc:评论记录id
  1063. * @return name:tags type:int default:1 desc:0取消成功,1点赞成功
  1064. */
  1065. public function commentTags()
  1066. {
  1067. $comment_id = input('post.comment_id');
  1068. $ret_val = 0;
  1069. $check_tags = DatumCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$comment_id])->value('id');
  1070. if($check_tags) {
  1071. DatumCommentLike::where(['user_id'=>$this->user_id,'like_id'=>$comment_id])->delete();
  1072. // ArticleItem::where('id',$comment_id)->setDec('like_times');
  1073. }else{
  1074. $p_user_id = DatumComment::where('id',$comment_id)->value('user_id');
  1075. $is_read = $p_user_id == $this->user_id ? 1 : 0;
  1076. Data::save('DatumCommentLike',
  1077. ['user_id'=>$this->user_id,'like_id'=>$comment_id,'is_read'=>$is_read],'user_id',
  1078. ['user_id'=>$this->user_id,'like_id'=>$comment_id]);
  1079. $ret_val = 1;
  1080. // ArticleItem::where('id',$comment_id)->setInc('like_times');
  1081. }
  1082. $this->success($ret_val == 1 ?'点赞成功':'取消成功',['tags'=>$ret_val]);
  1083. }
  1084. /**
  1085. * @title 我的订阅---消息
  1086. * @desc 订阅消息
  1087. * @author qc
  1088. * @method GET
  1089. * @url /api/Datum/getFollowUpMessage
  1090. * @header name:Authorization require:1 desc:Token
  1091. *
  1092. * @param name:title type:int default:-- desc:搜索内容
  1093. * @param name:page type:int default:-- desc:页数
  1094. * @param name:page_num type:int default:-- desc:每页数
  1095. *
  1096. * @return name:id type:int default:-- desc:记录id
  1097. * @return name:title type:string default:-- desc:标题
  1098. * @return name:content type:string default:-- desc:内容
  1099. * @return name:create_at type:string default:-- desc:时间
  1100. * @return name:is_read type:int default:-- desc:是否已读【0否1是】
  1101. * @return name:datum_title type:string default:-- desc:系列标题
  1102. * @return name:datum_id type:int default:-- desc:系列id
  1103. * @return name:children_id type:int default:-- desc:详情id
  1104. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1105. */
  1106. public function getFollowUpMessage()
  1107. {
  1108. $title = input('title');
  1109. $list = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'m.module'=>'datum','m.type_id'=>5])
  1110. ->when($title,function ($query)use ($title){
  1111. if($title) $query->where('m.content','like','%'.$title.'%');})
  1112. ->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')
  1113. ->leftJoin('DatumIntro v','v.id= m.relation_id')
  1114. ->limit($this->off_set,$this->page_num)
  1115. ->order(['m.id'=>'desc'])
  1116. ->select()->toArray();
  1117. foreach ($list as &$v) {
  1118. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['children_id'],$this->request->controller());
  1119. }
  1120. $total_num = UserMessage::where(['m.user_id'=>$this->user_id,'m.is_deleted'=>0,'m.module'=>'datum','m.type_id'=>5])
  1121. ->alias('m')->leftJoin('DatumIntro v','v.id= m.relation_id')->count();
  1122. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1123. }
  1124. /**
  1125. * @title 获取角标数量
  1126. * @desc 获取角标数量
  1127. * @author qc
  1128. * @method GET
  1129. * @url /api/Datum/getMarkNum
  1130. * @header name:Authorization require:1 desc:Token
  1131. * @return name:reply_num type:int default:-- desc:未读量--回复我的
  1132. * @return name:comment_num type:int default:-- desc:未读量--评论我的
  1133. * @return name:praise_num type:int default:-- desc:点赞我的【包含视频点赞和评论点赞】
  1134. * @return name:datum_praise_num type:int default:-- desc:-资料点赞
  1135. * @return name:comment_praise_num type:int default:-- desc:评论点赞
  1136. * @return name:follow_num type:int default:-- desc:订阅
  1137. */
  1138. public function getMarkNum()
  1139. {
  1140. // 评论我的
  1141. $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]])
  1142. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1143. ->alias('t')->count();
  1144. // 回复我的
  1145. $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  1146. $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;
  1147. // 点赞我的
  1148. $all_datum = DatumUrl::where('user_id',$this->user_id)->where('is_deleted',0)->column('id');
  1149. $datum_praise_num = DatumLike::where([['is_read','=',0],['url_id','in',$all_datum],['user_id','<>',$this->user_id]])->count();
  1150. $comment_praise_num = DatumCommentLike::where([['is_read','=',0],['like_id','in',$all_comment],['user_id','<>',$this->user_id]])->count();
  1151. $praise_num = $datum_praise_num + $comment_praise_num;
  1152. $follow_num = UserMessage::getUnreadNum($this->user_id,'datum',5);
  1153. $this->success('ok',compact(['reply_num','comment_num','praise_num','datum_praise_num','comment_praise_num','follow_num']));
  1154. }
  1155. /**
  1156. * @title 点赞我的--评论
  1157. * @desc 点赞我的--评论
  1158. * @author qc
  1159. * @method GET
  1160. * @url /api/Datum/praiseMyComment
  1161. * @header name:Authorization require:1 desc:Token
  1162. * @param name:page type:int default:-- desc:页数
  1163. * @param name:page_num type:int default:-- desc:每页数
  1164. *
  1165. * @return name:id type:int default:-- desc:记录id
  1166. * @return name:title type:string default:-- desc:标题
  1167. * @return name:series_title type:string default:-- desc:系列标题
  1168. * @return name:create_at type:string default:-- desc:时间
  1169. * @return name:read_num type:int default:-- desc:播放量
  1170. * @return name:self_name type:string default:-- desc:会员名称[自己的]
  1171. * @return name:user_name type:string default:-- desc:会员名称【别人的】
  1172. * @return name:headimg type:string default:-- desc:会员头像
  1173. * @return name:url type:string default:-- desc:文件路径
  1174. * @return name:like_id type:int default:-- desc:评论id
  1175. * @return name:content type:string default:-- desc:评论内容
  1176. */
  1177. public function praiseMyComment()
  1178. {
  1179. $user_info = $this->userInfo('name,headimg');
  1180. $list = DatumCommentLike::where([['c.user_id','=',$this->user_id],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
  1181. ->alias('l')
  1182. ->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')
  1183. ->leftJoin('StoreMember m','m.id = l.user_id')
  1184. ->leftJoin('DatumComment c','c.id = l.like_id')
  1185. ->leftJoin('DatumUrl v','v.id = c.url_id')
  1186. ->leftJoin('DatumIntro x','x.id = v.datum_id')
  1187. ->order('l.id desc')
  1188. ->limit($this->off_set,$this->page_num)
  1189. ->select()->toArray();
  1190. array_walk($list,function (&$v,$k)use ($user_info){
  1191. $v['self_name'] = $user_info['name'] ;
  1192. $article_auth = ArticleItem::getArticleAuth($v['buid'],APPNAME,APPLOGO);
  1193. $v['app_name'] = $article_auth['app_name'];
  1194. $v['app_logo'] = $article_auth['app_logo'];
  1195. $v['read_num'] = numTransform($v['read_num']);
  1196. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1197. });
  1198. $total_num = DatumCommentLike::where([['c.user_id','=',$this->user_id],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
  1199. ->alias('l')->leftJoin('StoreMember m','m.id = l.user_id')
  1200. ->leftJoin('DatumComment c','c.id = l.like_id')
  1201. ->leftJoin('DatumUrl v','v.id = c.url_id')->count();
  1202. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1203. }
  1204. /**
  1205. * @title 点赞我的--资料
  1206. * @desc 点赞我的--资料
  1207. * @author qc
  1208. * @method GET
  1209. * @url /api/Datum/praiseMyDatumList
  1210. * @header name:Authorization require:1 desc:Token
  1211. * @param name:page type:int default:-- desc:页数
  1212. * @param name:page_num type:int default:-- desc:每页数
  1213. *
  1214. * @return name:id type:int default:-- desc:记录id
  1215. * @return name:title type:string default:-- desc:标题
  1216. * @return name:series_title type:string default:-- desc:系列标题
  1217. * @return name:create_at type:string default:-- desc:时间
  1218. * @return name:read_num type:int default:-- desc:阅读量
  1219. * @return name:user_name type:string default:-- desc:会员名称
  1220. * @return name:headimg type:string default:-- desc:会员头像
  1221. * @return name:url type:string default:-- desc:文件路径
  1222. */
  1223. public function praiseMyDatumList()
  1224. {
  1225. $all_list = DatumUrl::where('user_id',$this->user_id)->where('is_deleted',0)->column('id');
  1226. $user_info = $this->userInfo('name,headimg');
  1227. $list = DatumLike::where([['l.url_id','in',$all_list],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
  1228. ->alias('l')
  1229. ->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')
  1230. ->leftJoin('StoreMember m','m.id = l.user_id')
  1231. ->leftJoin('DatumUrl v','v.id = l.url_id')
  1232. ->leftJoin('DatumIntro x','x.id = v.datum_id')
  1233. ->limit($this->off_set,$this->page_num)
  1234. ->select()->toArray();
  1235. array_walk($list,function (&$v,$k)use ($user_info){
  1236. $v['app_name'] = $user_info['name'] ;
  1237. $v['app_logo'] = $user_info['headimg'];
  1238. $v['read_num'] = numTransform($v['read_num']);
  1239. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1240. });
  1241. $total_num = DatumLike::where([['url_id','in',$all_list],['l.to_deleted','=',0],['l.user_id','<>',$this->user_id]])
  1242. ->alias('l')
  1243. ->leftJoin('StoreMember m','m.id = l.user_id')
  1244. ->leftJoin('DatumUrl v','v.id = l.url_id')
  1245. ->count();
  1246. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1247. }
  1248. /**
  1249. * @title 回复我的【回复我的--回复过我的评论】
  1250. * @desc 回复我的
  1251. * @author qc
  1252. * @method GET
  1253. * @url /api/Datum/getReplyComment
  1254. * @header name:Authorization require:1 desc:Token
  1255. * @param name:title type:string default:-- desc:标题
  1256. * @param name:page type:int default:0 desc:页数
  1257. * @param name:page_num type:int default:20 desc:每页数
  1258. *
  1259. *
  1260. * @return name:title type:string default:-- desc:标题
  1261. * @return name:datum_id type:string default:-- desc:资料系列id
  1262. * @return name:url_id type:string default:-- desc:资料id
  1263. * @return name:url type:string default:-- desc:文件路径
  1264. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  1265. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  1266. * @return name:create_at type:string default:-- desc:时间
  1267. * @return name:is_deleted type:int default:-- desc:0未删除
  1268. * @return name:user_name type:string default:-- desc:用户名【其他会员】
  1269. * @return name:headimg type:string default:-- desc:用户头【其他会员】
  1270. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1271. * @return name:parent_comment type:array default:-- desc:你的评论内容【别人回复的那个评论】
  1272. * @return name:parent_comment.content type:string default:-- desc:内容
  1273. * @return name:parent_comment.name type:string default:-- desc:会员名称
  1274. * @return name:parent_comment.title type:string default:-- desc:资料标题
  1275. * @return name:parent_comment.series_title type:string default:-- desc:系列标题
  1276. * @return name:parent_comment.datum_id type:string default:-- desc:资料系列id
  1277. * @return name:parent_comment.url_id type:string default:-- desc:资料id
  1278. * @return name:parent_comment.is_deleted type:int default:-- desc:0未删除
  1279. */
  1280. public function getReplyComment()
  1281. {
  1282. $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  1283. if(empty($all_comment)) $this->success('ok',['list'=>[]]);
  1284. $sel_where = [];
  1285. $title = input('get.title');
  1286. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  1287. $sel_where[] = ['t.is_deleted','=',0];
  1288. $sel_where[] = ['t.lev','>=',2];
  1289. $sel_where[] = ['t.user_id','<>',$this->user_id];
  1290. $sel_where[] = ['t.to_deleted','=',0];
  1291. $sel_where[] = ['t.pid','in',implode(',',$all_comment)];
  1292. $list = DatumComment::where($sel_where)
  1293. ->alias('t')
  1294. ->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')
  1295. ->leftJoin('store_member u','t.user_id = u.id')
  1296. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1297. ->order('t.is_top desc,t.id desc')
  1298. ->limit($this->off_set,$this->page_num)
  1299. ->select()->toArray();
  1300. foreach ($list as &$v) {
  1301. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1302. $parent_comment = DatumComment::where([['t.id','=',$v['pid']]])
  1303. ->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')
  1304. ->alias('t')
  1305. ->leftJoin('DatumIntro x','t.datum_id = x.id')
  1306. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1307. ->leftJoin('store_member u','t.user_id = u.id')
  1308. ->find()->toArray();
  1309. $parent_comment['read_num'] = numTransform($v['read_num']);
  1310. $datum_auth = ArticleItem::getArticleAuth($parent_comment['user_id'],APPNAME,APPLOGO);
  1311. $parent_comment['app_name'] = $datum_auth['app_name'];
  1312. $parent_comment['app_logo'] = $datum_auth['app_logo'];
  1313. $v['parent_comment'] = $parent_comment;
  1314. }
  1315. $total_num = DatumComment::where($sel_where)->alias('t')->count();
  1316. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1317. }
  1318. /**
  1319. * @title 评论我的【学习服务--评论我的】
  1320. * @desc 评论我的
  1321. * @author qc
  1322. * @method GET
  1323. * @url /api/Datum/commentMyDatum
  1324. * @header name:Authorization require:1 desc:Token
  1325. * @param name:title type:string default:-- desc:标题
  1326. * @param name:page type:int default:0 desc:页数
  1327. * @param name:page_num type:int default:20 desc:每页数
  1328. * @return name:title type:string default:-- desc:标题
  1329. * @return name:series_title type:string default:-- desc:系列标题
  1330. * @return name:datum_id type:string default:-- desc:资料系列id
  1331. * @return name:url_id type:string default:-- desc:资料id
  1332. * @return name:is_read type:int default:-- desc:是否已读(0未读1已读)
  1333. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  1334. * @return name:create_at type:string default:-- desc:时间
  1335. * @return name:url type:string default:-- desc:资料路径
  1336. * @return name:user_name type:string default:-- desc:用户名
  1337. * @return name:headimg type:string default:-- desc:用户头像
  1338. * @return name:read_num type:int default:-- desc:阅读量
  1339. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1340. * @return name:app_name type:string default:-- desc:发布者
  1341. * @return name:app_logo type:string default:-- desc:发布者头像
  1342. */
  1343. public function commentMyDatum()
  1344. {
  1345. $sel_where = [];
  1346. $title = input('get.title');
  1347. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  1348. $sel_where[] = ['t.is_deleted','=',0];
  1349. $sel_where[] = ['i.user_id','=',$this->user_id];
  1350. $sel_where[] = ['t.user_id','<>',$this->user_id];
  1351. $sel_where[] = ['t.source_deleted','=',0];
  1352. $sel_where[] = ['t.pid','=',0];
  1353. $list = DatumComment::where($sel_where)->alias('t')
  1354. ->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')
  1355. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1356. ->leftJoin('DatumIntro x','t.datum_id = x.id')
  1357. ->leftJoin('store_member u','t.user_id = u.id')
  1358. ->order('t.id desc')
  1359. ->limit($this->off_set,$this->page_num)
  1360. ->select()->toArray();
  1361. $user_info = $this->userInfo('name,headimg');
  1362. array_walk($list,function (&$v)use ($user_info){
  1363. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1364. $v['read_num'] = numTransform($v['read_num']);
  1365. $v['app_name'] = $user_info['name'];
  1366. $v['app_logo'] = $user_info['headimg'];
  1367. });
  1368. $total_num= DatumComment::where($sel_where)->alias('t') ->leftJoin('DatumUrl i','t.url_id = i.id')
  1369. ->leftJoin('store_member u','t.user_id = u.id')->count();
  1370. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1371. }
  1372. /**
  1373. * @title 消息已读&&未读变更
  1374. * @desc 消息已读
  1375. * @author qc
  1376. * @method POST
  1377. * @url /api/Datum/unreadChange
  1378. * @header name:Authorization require:1 desc:Token
  1379. * @param name:id type:string default:-- desc:记录id(多个逗号隔开,不传修改全部)
  1380. * @param name:type type:string default:1 desc:消息类型【1评论我的,2回复我的,3订阅消息,4点赞我的--资料,5点赞我的-评论】
  1381. * @param name:is_read type:int default:1 desc:变更类型【0消息变更为未读,1变更为已读】
  1382. *
  1383. */
  1384. public function unreadChange()
  1385. {
  1386. $type = input('post.type',1);
  1387. $id = input('post.id');
  1388. $where = [];
  1389. switch ($type) {
  1390. case 1:
  1391. DatumComment::where([['i.user_id','=',$this->user_id],['t.pid','=',0]])
  1392. ->when($id ,function ($query)use ($id){
  1393. if($id) return $query->where('t.id','in',$id);
  1394. })->leftJoin('DatumUrl i','t.url_id = i.id')
  1395. ->alias('t')
  1396. ->update(['source_read'=>input('post.is_read'),'is_read'=>input('post.is_read')]);
  1397. break;
  1398. case 2:
  1399. $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  1400. DatumComment::where([['t.pid','in',implode(',',$all_comment)]])
  1401. ->when($id ,function ($query)use ($id){
  1402. if($id) return $query->where('t.id','in',$id);
  1403. })->alias('t')->update(['is_read'=>input('post.is_read')]);
  1404. break;
  1405. case 3:
  1406. $where[] = ['user_id','=',$this->user_id];
  1407. if($id) $where[] = ['id','in',$id];
  1408. UserMessage::where($where)->update(['is_read'=>input('post.is_read')]);
  1409. break;
  1410. case 4:
  1411. $all_datum = DatumUrl::where('user_id',$this->user_id)->where('is_deleted',0)->column('id');
  1412. DatumLike::where([['is_read','=',0],['url_id','in',$all_datum]])->update(['is_read'=>1]);
  1413. break;
  1414. case 5:
  1415. $all_comment = DatumComment::where(['user_id'=>$this->user_id,'is_deleted'=>0])->column('id');
  1416. DatumCommentLike::where([['is_read','=',0],['like_id','in',$all_comment]])->update(['is_read'=>1]);
  1417. break;
  1418. }
  1419. $this->success('消息变更成功');
  1420. }
  1421. /**
  1422. * @title 我的点赞--资料
  1423. * @desc 我的点赞
  1424. * @author qc
  1425. * @method GET
  1426. * @url /api/Datum/getTagsDatum
  1427. * @header name:Authorization require:1 desc:Token
  1428. * @param name:title type:string default:-- desc:标题
  1429. * @param name:page type:int default:0 desc:页数
  1430. * @param name:page_num type:int default:20 desc:每页数
  1431. * @return name:title type:string default:-- desc:标题
  1432. * @return name:series_title type:string default:-- desc:系列标题
  1433. * @return name:datum_id type:string default:-- desc:系列id
  1434. * @return name:url_id type:string default:-- desc:资料id
  1435. * @return name:like_num type:string default:-- desc:点赞量
  1436. * @return name:is_like type:string default:-- desc:是否点赞[0否1是]
  1437. * @return name:url type:string default:-- desc:文件路径
  1438. * @return name:is_vip type:int default:-- desc:是否vip[0否1是]
  1439. * @return name:create_at type:string default:-- desc:时间
  1440. * @return name:read_num type:int default:-- desc:阅读量
  1441. * @return name:switch_open type:int default:-- desc:通知开关【0关闭1开启】
  1442. * @return name:app_name type:string default:-- desc:发布方名称
  1443. * @return name:app_logo type:string default:-- desc:发布方头像
  1444. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1445. *
  1446. * @return name:transmit_num type:int default:-- desc:转发量
  1447. * @return name:comment_num type:int default:-- desc:评论量
  1448. * @return name:is_collect type:int default:-- desc:是否收藏
  1449. * @return name:collect_num type:int default:-- desc:收藏量
  1450. */
  1451. public function getTagsDatum()
  1452. {
  1453. $sel_where = [];
  1454. $title = input('get.title');
  1455. if($title) $sel_where[] = ['i.title|i.label','like','%'.$title.'%'];
  1456. $sel_where[] = ['t.user_id','=',$this->user_id];
  1457. $list = DatumLike::where($sel_where)
  1458. ->alias('t')
  1459. ->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')
  1460. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1461. ->leftJoin('DatumIntro x','t.datum_id = x.id')
  1462. ->order('id desc')
  1463. ->limit($this->off_set,$this->page_num)
  1464. ->select()->toArray();
  1465. foreach ($list as &$v) {
  1466. $v['switch_open'] = PlatformSwitch::checkSwitch($this->user_id,$v['url_id'],9);
  1467. $v['like_num'] = DatumLike::where(['datum_id'=>$v['datum_id'],'url_id'=>$v['url_id']])->count();
  1468. $v['like_num'] = numTransform($v['like_num']);
  1469. $v['read_num'] = numTransform($v['read_num']);
  1470. $v['is_like'] = DatumLike::where(['user_id'=>$this->user_id,'datum_id'=>$v['datum_id'],'url_id'=>$v['url_id']])->count();
  1471. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1472. $article_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
  1473. $v['app_name'] = $article_auth['app_name'];
  1474. $v['app_logo'] = $article_auth['app_logo'];
  1475. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['datum_id'],$v['url_id']);
  1476. $v['collect_num'] = UserCollect::getCollectNum(2,$v['datum_id'],$v['url_id']);
  1477. $v['comment_num'] = DatumComment::getDatumCommentNum($v['url_id']);
  1478. }
  1479. $total_num = DatumLike::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.url_id = i.id')->count();
  1480. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1481. }
  1482. /**
  1483. * @title 我的点赞--评论
  1484. * @desc 评论点赞列表
  1485. * @author qc
  1486. * @method GET
  1487. * @url /api/Datum/getTagsComment
  1488. * @header name:Authorization require:1 desc:Token
  1489. * @param name:title type:string default:-- desc:标题
  1490. * @param name:page type:int default:0 desc:页数
  1491. * @param name:page_num type:int default:20 desc:每页数
  1492. * @return name:create_at type:string default:-- desc:时间
  1493. * @return name:user_name type:string default:-- desc:会员名称
  1494. * @return name:headimg type:string default:-- desc:会员头像
  1495. * @return name:content type:string default:-- desc:评论内容
  1496. * @return name:url type:string default:-- desc:资料url
  1497. * @return name:title type:string default:-- desc:标题
  1498. * @return name:series_title type:string default:-- desc:系列标题
  1499. * @return name:read_num type:string default:-- desc:阅读量
  1500. * @return name:app_name type:string default:-- desc:发布者
  1501. * @return name:app_logo type:string default:-- desc:发布者头像
  1502. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1503. */
  1504. public function getTagsComment()
  1505. {
  1506. $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')
  1507. ->alias('l')
  1508. ->where(['l.user_id'=>$this->user_id,'l.type'=>1])
  1509. ->leftJoin('DatumComment c','l.like_id = c.id')
  1510. ->leftJoin('DatumUrl i','i.id = c.url_id')
  1511. ->leftJoin('DatumIntro x','x.id = c.datum_id')
  1512. ->leftJoin('store_member u','u.id = c.user_id')
  1513. ->order('l.id desc')
  1514. ->limit($this->off_set,$this->page_num)
  1515. ->select()->toArray();
  1516. array_walk($list,function (&$v){
  1517. $article_auth = ArticleItem::getArticleAuth($v['buid'],APPNAME,APPLOGO);
  1518. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1519. $v['app_name'] = $article_auth['app_name'];
  1520. $v['app_logo'] = $article_auth['app_logo'];
  1521. });
  1522. $total_num =DatumCommentLike::where(['l.user_id'=>$this->user_id,'l.type'=>1])
  1523. ->alias('l')
  1524. ->leftJoin('DatumComment c','l.like_id = c.id')
  1525. ->leftJoin('DatumUrl i','i.id = c.url_id')
  1526. ->leftJoin('store_member u','u.id = c.user_id')
  1527. ->count();
  1528. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1529. }
  1530. /**
  1531. * @title 我的回复
  1532. * @desc 我的回复
  1533. * @author qc
  1534. * @method GET
  1535. * @url /api/Datum/getReplyDatum
  1536. * @header name:Authorization require:1 desc:Token
  1537. * @param name:title type:string default:-- desc:标题
  1538. * @param name:page type:int default:0 desc:页数
  1539. * @param name:page_num type:int default:20 desc:每页数
  1540. * @return name:title type:string default:-- desc:标题
  1541. * @return name:datum_id type:string default:-- desc:系列id
  1542. * @return name:url_id type:string default:-- desc:资料url_id
  1543. * @return name:url type:string default:-- desc:资料路径
  1544. * @return name:create_at type:string default:-- desc:时间
  1545. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  1546. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  1547. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  1548. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1549. * @return name:parent_comment type:array default:-- desc:上级评论内容【你评论的那个评论】
  1550. * @return name:parent_comment.content type:string default:-- desc:内容
  1551. * @return name:parent_comment.name type:string default:-- desc:会员名称
  1552. * @return name:parent_comment.title type:string default:-- desc:资料标题
  1553. * @return name:parent_comment.serites_title type:string default:-- desc:系列标题
  1554. * @return name:parent_comment.datum_id type:string default:-- desc:系列id
  1555. * @return name:parent_comment.url_id type:string default:-- desc:url_id
  1556. */
  1557. public function getReplyDatum()
  1558. {
  1559. $user_info = $this->userInfo();
  1560. $sel_where = [];
  1561. $title = input('get.title');
  1562. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  1563. $sel_where[] = ['t.user_id','=',$this->user_id];
  1564. $sel_where[] = ['t.is_deleted','=',0];
  1565. $sel_where[] = ['t.lev','>=',2];
  1566. $list = DatumComment::where($sel_where)
  1567. ->alias('t')
  1568. ->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')
  1569. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1570. ->order('t.is_top desc,t.id desc')
  1571. ->limit($this->off_set,$this->page_num)
  1572. ->select()->toArray();
  1573. foreach ($list as &$v) {
  1574. $v['read_num'] = numTransform($v['read_num']);
  1575. $v['user_name'] = $user_info['name'];
  1576. $v['headimg'] = $user_info['headimg'];
  1577. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1578. $parent_comment = DatumComment::where([['t.id','=',$v['pid']]])
  1579. ->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')
  1580. ->alias('t')
  1581. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1582. ->leftJoin('DatumIntro x','t.datum_id = x.id')
  1583. ->leftJoin('store_member u','t.user_id = u.id')
  1584. ->find()->toArray();
  1585. $datum_auth = ArticleItem::getArticleAuth($parent_comment['user_id'],APPNAME,APPLOGO);
  1586. $parent_comment['read_num'] = numTransform($v['read_num']);
  1587. $parent_comment['app_name'] = $datum_auth['app_name'];
  1588. $parent_comment['app_logo'] = $datum_auth['app_logo'];
  1589. $v['app_name'] =$datum_auth['app_name'];
  1590. $v['app_logo'] = $datum_auth['app_logo'];
  1591. $v['parent_comment'] = $parent_comment;
  1592. }
  1593. $total_num = DatumComment::where($sel_where)->alias('t')->leftJoin('DatumUrl i','t.url_id = i.id')->count();
  1594. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num,'user_id'=>$this->user_id]);
  1595. }
  1596. /**
  1597. * @title 我的评论【学习服务--我评论过的资料】
  1598. * @desc 我的评论
  1599. * @author qc
  1600. * @method GET
  1601. * @url /api/Datum/getCommentDatum
  1602. * @header name:Authorization require:1 desc:Token
  1603. * @param name:title type:string default:-- desc:标题
  1604. * @param name:page type:int default:0 desc:页数
  1605. * @param name:page_num type:int default:20 desc:每页数
  1606. * @return name:title type:string default:-- desc:标题
  1607. * @return name:series_title type:string default:-- desc:系列标题
  1608. * @return name:datum_id type:string default:-- desc:系列id
  1609. * @return name:url_id type:string default:-- desc:资料url_id
  1610. * @return name:url type:string default:-- desc:路径
  1611. * @return name:is_top type:int default:-- desc:是否置顶(0否1是)
  1612. * @return name:create_at type:string default:-- desc:时间
  1613. * @return name:user_name type:string default:-- desc:用户名【用户自己的】
  1614. * @return name:headimg type:string default:-- desc:用户头像【用户自己的】
  1615. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1616. * @return name:app_name type:string default:-- desc:发布者
  1617. * @return name:app_logo type:string default:-- desc:发布者头像
  1618. */
  1619. public function getCommentDatum()
  1620. {
  1621. $user_info = $this->userInfo();
  1622. $sel_where = [];
  1623. $title = input('get.title');
  1624. if($title) $sel_where[] = ['i.title|i.label|t.content','like','%'.$title.'%'];
  1625. $sel_where[] = ['t.user_id','=',$this->user_id];
  1626. $sel_where[] = ['t.is_deleted','=',0];
  1627. $sel_where[] = ['t.lev','=',1];
  1628. $sel_where[] = ['t.pid','=',0];
  1629. $list = DatumComment::where($sel_where)
  1630. ->alias('t')
  1631. ->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')
  1632. ->leftJoin('DatumUrl i','t.url_id = i.id')
  1633. ->leftJoin('DatumIntro x','t.datum_id = x.id')
  1634. ->order('t.is_top desc,id desc')
  1635. ->limit($this->off_set,$this->page_num)
  1636. ->select()->toArray();
  1637. foreach ($list as &$v)
  1638. {
  1639. $v['user_name'] = $user_info['name'];
  1640. $v['headimg'] = $user_info['headimg'];
  1641. $v['is_normal'] = CheckPower::checkModulesPower($v['datum_id'],$v['url_id'],$this->request->controller());
  1642. $datum_auth = ArticleItem::getArticleAuth($v['user_id'],APPNAME,APPLOGO);
  1643. $v['app_name'] = $datum_auth['app_name'];
  1644. $v['app_logo'] = $datum_auth['app_logo'];
  1645. }
  1646. $total_num = DatumComment::where($sel_where)->alias('t') ->leftJoin('DatumUrl i','t.url_id = i.id')->count();
  1647. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1648. }
  1649. /**
  1650. * @title 我的已购--已购列表
  1651. * @desc 我的已购--已购列表
  1652. * @author qc
  1653. * @method GET
  1654. * @url /api/Datum/getPurchaseDatum
  1655. * @header name:Authorization require:1 desc:Token
  1656. * @param name:title type:string default:-- desc:标题
  1657. * @param name:page type:int default:0 desc:页数
  1658. * @param name:page_num type:int default:20 desc:每页数
  1659. * @return name:title type:string default:-- desc:标题
  1660. * @return name:datum_id type:string default:-- desc:资料id
  1661. * @return name:item_id type:string default:-- desc:item_id
  1662. * @return name:create_at type:string default:-- desc:时间
  1663. * @return name:total_sequel type:int default:-- desc:期数
  1664. * @return name:is_normal type:int default:-- desc:是否是正常记录(0已删除或是已禁用1可以正常跳转详情)
  1665. * @return name:is_recently type:int default:-- desc:是否最近观看【0否1是】
  1666. * @return name:read_num type:int default:-- desc:阅读量
  1667. * @return name:recently_title type:string default:-- desc:上次观看标题
  1668. */
  1669. public function getPurchaseDatum()
  1670. {
  1671. $sel_where = [];
  1672. $title = input('get.title');
  1673. if($title) $sel_where[] = ['a.title|a.label','like','%'.$title.'%'];
  1674. $sel_where[] = ['t.user_id','=',$this->user_id];
  1675. $sel_where[] = ['t.type','=',2];
  1676. $sel_where[] = ['t.end_int','>',time()];
  1677. $sel_where[] = ['t.is_deleted','=',0];
  1678. $sel_where[] = ['a.is_deleted','=',0];
  1679. $list = UserLearn::where($sel_where)
  1680. ->alias('t')
  1681. ->field('t.id,t.create_at,t.first_id datum_id,t.second_id item_id,a.title,a.total_sequel,a.read_num')
  1682. ->leftJoin('datum_intro a','t.first_id = a.id')
  1683. ->leftJoin('datum_url i','t.second_id = i.id')
  1684. ->order('id desc')
  1685. ->limit($this->off_set,$this->page_num)
  1686. ->select()->toArray();
  1687. array_walk($list,function (&$v){
  1688. $v['is_normal'] = 1;//CheckPower::checkModulesPower($v['article_id'],$v['item_id'],$this->request->controller());
  1689. $recently_id = UserTrack::getRecentlyTrack($this->user_id,2,$v['datum_id']);
  1690. $v['is_recently'] = $recently_id ? 1 : 0;
  1691. $v['recently_title'] = DatumUrl::where('id',$recently_id)->value('title');
  1692. });
  1693. $total_num = UserLearn::where($sel_where)->alias('t') ->leftJoin('datum_url i','t.second_id = i.id')
  1694. ->leftJoin('datum_intro a','t.first_id = a.id')->count();
  1695. $this->success('ok',['list'=>$list,'total_count'=>$total_num,'page_num'=>$this->page_num]);
  1696. }
  1697. }