Information.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\InformationArticle;
  4. use app\common\model\InformationGoods;
  5. use app\common\model\NewsCate;
  6. use app\common\model\NewsChannel;
  7. use app\common\model\NewsMaterial;
  8. use app\common\model\NutritionCase;
  9. use app\common\model\StoreBanner;
  10. use app\common\model\UserCollect;
  11. use app\common\model\UserTrack;
  12. /**
  13. * @title 资讯(康养百科)
  14. * @controller Information
  15. * @group base
  16. */
  17. class Information extends Base
  18. {
  19. public function initialize()
  20. {
  21. parent::initialize();
  22. parent::setUid();
  23. }
  24. /**
  25. * @title 获取分类(共两级)
  26. * @desc 获取分类
  27. * @author qc
  28. * @url /api/Information/getCateTree
  29. * @method GET
  30. * @header name:Authorization require:1 desc:Token
  31. * @return name:id type:int default:-- desc:分类id
  32. * @return name:logo type:string default:-- desc:图标
  33. * @return name:title type:string default:0 desc:分类名称
  34. * @return name:children type:array default:0 desc:下级(数据同上)
  35. */
  36. public function getCateTree()
  37. {
  38. $list = NewsCate::where(['is_deleted'=>0])->field('id,logo,title,pid,desc')->order('sort desc')->select()->toArray();
  39. $list = make_tree($list);
  40. $this->success('ok',['list'=>$list]);
  41. }
  42. /**
  43. * @title 获取二级分类
  44. * @desc 获取二级分类
  45. * @author qc
  46. * @url /api/Information/getSecondCate
  47. * @method GET
  48. * @header name:Authorization require:1 desc:Token
  49. * @param name:pid type:int default:-- desc:一级分类id
  50. * @return name:id type:int default:-- desc:分类id
  51. * @return name:logo type:string default:-- desc:图标
  52. * @return name:title type:string default:0 desc:分类名称
  53. * @return name:desc type:string default:0 desc:分类描述
  54. */
  55. public function getSecondCate()
  56. {
  57. $pid = input('pid');
  58. $list = NewsCate::where(['is_deleted'=>0,'pid'=>$pid])->field('id,logo,title,pid,desc')->order('sort desc')->select()->toArray();
  59. $this->success('ok',['list'=>$list]);
  60. }
  61. /**
  62. * @title 获取资讯栏目
  63. * @desc 获取资讯栏目
  64. * @author qc
  65. * @url /api/Information/getNewsChannel
  66. * @method GET
  67. * @header name:Authorization require:1 desc:Token
  68. * @return name:title type:string default:-- desc:标题
  69. * @return name:desc type:string default:-- desc:描述(副标题)
  70. */
  71. public function getNewsChannel()
  72. {
  73. $list = NewsChannel::field('id,desc,title')->where(['is_deleted'=>0,'status'=>1])->order('sort desc ,id desc')->select()->toArray();
  74. $this->success('ok',['list'=>$list]);
  75. }
  76. /**
  77. * @title 获取亚健康资讯标签
  78. * @desc 获取亚健康资讯标签
  79. * @author qc
  80. * @url /api/Information/getNutritionCaseList
  81. * @method GET
  82. * @header name:Authorization require:1 desc:Token
  83. * @return name:title type:string default:-- desc:标签名
  84. * @return name:logo type:string default:-- desc:图片
  85. */
  86. public function getNutritionCaseList()
  87. {
  88. $list = NutritionCase::field('id,title,logo')->where(['status'=>1,'is_deleted'=>0])->order('sort desc ,id desc')->select()->toArray();
  89. $this->success('ok',['list'=>$list]);
  90. }
  91. /**
  92. * @title 获取亚健康资讯标签详情
  93. * @desc 获取亚健康资讯标签详情
  94. * @author qc
  95. * @url /api/Information/getNutritionCaseDetail
  96. * @method GET
  97. * @header name:Authorization require:1 desc:Token
  98. * @param name:id type:int default:-- desc:标签id
  99. * @return name:title type:string default:-- desc:标签名
  100. * @return name:intro type:string default:-- desc:详情介绍
  101. */
  102. public function getNutritionCaseDetail()
  103. {
  104. $id= input('get.id');
  105. $detail = NutritionCase::where('id',$id)->find()->toArray();
  106. $this->success('ok',['detail'=>$detail]);
  107. }
  108. /**
  109. * @title 随机获取亚健康资讯标签
  110. * @desc 随机获取
  111. * @author qc
  112. * @url /api/Information/getRandNutritionCase
  113. * @method GET
  114. * @header name:Authorization require:1 desc:Token
  115. * @param name:num type:int default:4 desc:随机数量
  116. * @return name:title type:string default:-- desc:标签名
  117. */
  118. public function getRandNutritionCase()
  119. {
  120. $num = input('get.num',4);
  121. $list = NutritionCase::field('id,title,logo')->where(['status'=>1,'is_deleted'=>0])->order('sort desc ,id desc')->column('title','id');
  122. $rand_key = array_rand($list,$num);
  123. $rand_list = [];
  124. foreach ($rand_key as $key) {
  125. $rand_list[] = ['id'=>$key,'title'=>$list[$key]];
  126. }
  127. $this->success('ok',['list'=>$rand_list]);
  128. }
  129. /**
  130. * @title 获取资讯专题推荐商品
  131. * @desc 获取资讯专题推荐商品
  132. * @author qc
  133. * @method GET
  134. * @url /api/Information/getGoodsByNutritionCase
  135. * @header name:Authorization require:1 desc:Token
  136. * @param name:id type:int default:0 desc:资讯id
  137. * @param name:page type:int default:1 desc:页数
  138. * @param name:page_num type:int default:20 desc:每页数量
  139. * @return name:id type:string default:-- desc:资讯标签id
  140. * @return name:news_id type:string default:-- desc:资讯id
  141. * @return name:goods_set type:array default:-- desc:商品信息
  142. * @return name:goods_set.name type:string default:-- desc:商品名称
  143. * @return name:goods_set.desc type:float default:-- desc:商品简介(副标题)
  144. * @return name:goods_set.cover type:string default:-- desc:商品封面
  145. * @return name:goods_set.low_price type:float default:-- desc:最低价格
  146. */
  147. public function getGoodsByNutritionCase()
  148. {
  149. $label_id = input('get.label_id');
  150. $sel_where = [];
  151. $sel_where[] = ['is_deleted','=',0];
  152. $sel_where[] = ['status','=',1];
  153. if($label_id) $sel_where[] = ['label','like','%'.'|'.$label_id.'|'.'%'];
  154. $new_ids = InformationArticle::where('is_deleted',0)->order('id desc')->limit(0,5)->column('id');
  155. $goods_ids = InformationGoods::field('goods_id,max(id) id')->where('news_id','in',$new_ids)->group('goods_id')->select()->toArray();
  156. $list = InformationGoods::with('goodsSet')
  157. ->where('id','in',array_column($goods_ids,'id'))
  158. ->limit($this->off_set,$this->page_num)->select()->toArray();
  159. $this->success('ok',['list'=>$list]);
  160. }
  161. /**
  162. * @title 获取轮播图
  163. * @desc 获取轮播图
  164. * @author qc
  165. * @url /api/Information/getBanner
  166. * @method GET
  167. * @header name:Authorization require:1 desc:Token
  168. * @param name:num type:int default:5 desc:查询数量
  169. * @return name:cover type:srting default:-- desc:图片路径
  170. * @return name:link type:srting default:-- desc:链接
  171. */
  172. public function getBanner()
  173. {
  174. $num = input('get.num',5);
  175. $list = StoreBanner::where(['place'=>2,'is_deleted'=>0])
  176. ->field('id,cover,link')
  177. ->limit(0,$num)
  178. ->order('sort desc ,id desc')
  179. ->select()->toArray();
  180. $this->success('ok',['list'=>$list]);
  181. }
  182. /**
  183. * @title 获取资讯列表
  184. * @desc
  185. * @author qc
  186. * @method GET
  187. * @url /api/Information/getInformationList
  188. * @header name:Authorization require:1 desc:Token
  189. * @param name:page type:int default:1 desc:页数
  190. * @param name:page_num type:int default:20 desc:每页数量
  191. * @param name:title type:string default:-- desc:标题
  192. * @param name:type type:int default:0 desc:类型(0全部,1图文,2视频)
  193. * @param name:channel_id type:int default:0 desc:资讯栏目id
  194. * @param name:first_classify type:int default:0 desc:一级分类
  195. * @param name:second_classify type:int default:0 desc:二级分类
  196. * @param name:is_top type:int default:0 desc:置顶查询传1(置顶文章查询)
  197. * @param name:label_id type:int default:0 desc:标签id(亚健康资讯)
  198. * @return name:title type:string default:-- desc:标题
  199. * @return name:cover type:string default:-- desc:封面
  200. * @return name:channel_id type:int default:0 desc:资讯栏目id
  201. * @return name:video_url type:string default:-- desc:视频地址
  202. * @return name:detail type:string default:-- desc:详情(视频没有这个)
  203. * @return name:first_classify type:int default:-- desc:一级分类(/api/Information/getCateTree这个接口返回的第一级id)
  204. * @return name:second_classify type:int default:-- desc:二级分类(/api/Information/getCateTree这个接口返回的第二级id)
  205. * @return name:type type:string default:-- desc:1图文2视频
  206. * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
  207. * @return name:read_num type:int default:-- desc:阅读量
  208. * @return name:is_collect type:int default:-- desc:是否收藏
  209. * @return name:collect_num type:int default:-- desc:收藏量
  210. * @return name:is_hot type:int default:-- desc:是否热门(0否,1是)
  211. * @return name:is_new type:int default:-- desc:是否是最新(0否,1是)
  212. */
  213. public function getInformationList()
  214. {
  215. $sel_where = [];
  216. $sel_where[] = ['is_deleted','=',0];
  217. $sel_where[] = ['status','=',1];
  218. $title = input('get.title');
  219. $type = input('get.type');
  220. $is_top = input('get.is_top');
  221. $channel_id = input('get.channel_id');
  222. $first_classify = input('get.first_classify');
  223. $second_classify = input('get.second_classify');
  224. $label_id = input('get.label_id');
  225. if($title) $sel_where[] = ['title','like','%'.$title.'%'];
  226. if($type) $sel_where[] = ['type','=',$type];
  227. if($first_classify) $sel_where[] = ['first_classify','=',$first_classify];
  228. if($second_classify) $sel_where[] = ['second_classify','=',$second_classify];
  229. if($is_top) $sel_where[] = ['is_top','=',$is_top];
  230. if($channel_id) $sel_where[] = ['channel_id','=',$channel_id];
  231. if($label_id) $sel_where[] = ['label','like','%'.'|'.$label_id.'|'.'%'];
  232. $new_ids = InformationArticle::order('id desc')->limit(0,3)->column('id');
  233. $list = InformationArticle::where($sel_where)
  234. ->order('is_top desc,sort desc ,id desc')
  235. ->limit($this->off_set,$this->page)->select()->toArray();
  236. array_walk($list,function (&$v,$k)use ($new_ids){
  237. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['id']);
  238. $v['is_new'] = in_array($v['id'],$new_ids)? 1 :0;
  239. $v['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$v['id']])->count();
  240. $v['is_hot'] = $v['collect_num'] > 10000 ? 1:0;
  241. });
  242. $this->success('ok',['list'=>$list]);
  243. }
  244. /**
  245. * @title 获取资讯详情
  246. * @desc 获取资讯详情
  247. * @author qc
  248. * @method GET
  249. * @url /api/Information/getInformationDetail
  250. * @header name:Authorization require:1 desc:Token
  251. * @param name:id type:int default:0 desc:资讯id
  252. * @return name:title type:string default:-- desc:标题
  253. * @return name:cover type:string default:-- desc:封面
  254. * @return name:video_url type:string default:-- desc:视频地址
  255. * @return name:detail type:string default:-- desc:详情(视频没有这个)
  256. * @return name:first_classify type:int default:-- desc:一级分类
  257. * @return name:second_classify type:int default:-- desc:二级分类
  258. * @return name:type type:string default:-- desc:1图文2视频
  259. * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
  260. * @return name:read_num type:int default:-- desc:阅读量
  261. * @return name:is_collect type:int default:-- desc:是否收藏(0否,1是)
  262. * @return name:collect_num type:int default:-- desc:收藏量
  263. * @return name:is_hot type:int default:-- desc:是否热门(0否,1是)
  264. * @return name:label type:int default:-- desc:亚健康标签id串(格式:|id|id|)
  265. * @return name:label_name type:array default:-- desc:亚健康标签
  266. * @return name:label_name.title type:array default:-- desc:亚健康标签名
  267. * @return name:platform_name type:string default:-- desc:平台名称
  268. */
  269. public function getInformationDetail()
  270. {
  271. $sel_where = [];
  272. $sel_where[] = ['is_deleted','=',0];
  273. $sel_where[] = ['status','=',1];
  274. $sel_where[] = ['id','=',input('get.id')];
  275. if($this->user_id)UserTrack::createTrack($this->user_id,2,input('get.id'));
  276. $detail = InformationArticle::where($sel_where)
  277. ->order('is_top desc,sort desc ,id desc')->find();
  278. if(!$detail)$this->error('该资讯已下线');
  279. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail->id);
  280. $detail['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$detail->id])->count();
  281. $detail['is_hot'] = $detail['collect_num'] > 10000 ? 1:0;
  282. $detail['label_name'] = [];
  283. if($detail['label']){
  284. $label_id = explode('|',trim($detail['label'],'|'));
  285. $detail['label_name'] = NutritionCase::field('id,title')->where('id','in',$label_id)->select()->toArray();
  286. }
  287. $detail['platform_name'] = config('text.platform_name');
  288. InformationArticle::where('id',input('get.id'))->setInc('read_num');//阅读量+1
  289. $this->success('ok',['detail'=>$detail]);
  290. }
  291. /**
  292. * @title 获取资讯相关商品
  293. * @desc 获取资讯相关商品
  294. * @author qc
  295. * @method GET
  296. * @url /api/Information/getInformationGoods
  297. * @header name:Authorization require:1 desc:Token
  298. * @param name:id type:int default:0 desc:资讯id
  299. * @param name:page type:int default:1 desc:页数
  300. * @param name:page_num type:int default:20 desc:每页数量
  301. * @return name:id type:string default:-- desc:资讯相关商品记录id
  302. * @return name:news_id type:string default:-- desc:资讯id
  303. * @return name:goods_set type:array default:-- desc:商品信息
  304. * @return name:goods_set.name type:string default:-- desc:商品名称
  305. * @return name:goods_set.desc type:float default:-- desc:商品简介(副标题)
  306. * @return name:goods_set.cover type:string default:-- desc:商品封面
  307. * @return name:goods_set.low_price type:float default:-- desc:最低价格
  308. */
  309. public function getInformationGoods()
  310. {
  311. $id = input('get.id');
  312. $list = InformationGoods::with('goodsSet')->where(['news_id'=>$id])->limit($this->off_set,$this->page_num)->select();
  313. $this->success('ok',['list'=>$list]);
  314. }
  315. /**
  316. * @title 获取资讯素材
  317. * @desc 获取资讯素材
  318. * @author qc
  319. * @method GET
  320. * @url /api/Information/getNewsMaterial
  321. * @header name:Authorization require:1 desc:Token
  322. * @param name:page type:int default:1 desc:页数
  323. * @param name:page_num type:int default:20 desc:每页数量
  324. * @param name:type type:int default:1 desc:类型(1线上,2线下)
  325. * @return name:id type:int default:-- desc:素材id
  326. * @return name:type type:int default:-- desc:类型(1线上,2线下)
  327. * @return name:title type:string default:-- desc:标题
  328. * @return name:cover type:string default:-- desc:图片
  329. */
  330. public function getNewsMaterial()
  331. {
  332. $type = input('get.type',1);
  333. $list = NewsMaterial::field('id,title,type,cover')->where(['type'=>$type,'is_deleted'=>0,'status'=>1])->select()->toArray();
  334. $this->success('ok',['list'=>$list]);
  335. }
  336. }