123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- <?php
- namespace app\api\controller;
- use app\common\model\InformationArticle;
- use app\common\model\InformationGoods;
- use app\common\model\NewsCate;
- use app\common\model\NewsChannel;
- use app\common\model\NewsMaterial;
- use app\common\model\NutritionCase;
- use app\common\model\StoreBanner;
- use app\common\model\UserCollect;
- use app\common\model\UserTrack;
- /**
- * @title 资讯(康养百科)
- * @controller Information
- * @group base
- */
- class Information extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 获取分类(共两级)
- * @desc 获取分类
- * @author qc
- * @url /api/Information/getCateTree
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:分类id
- * @return name:logo type:string default:-- desc:图标
- * @return name:title type:string default:0 desc:分类名称
- * @return name:children type:array default:0 desc:下级(数据同上)
- */
- public function getCateTree()
- {
- $list = NewsCate::where(['is_deleted'=>0])->field('id,logo,title,pid,desc')->order('sort desc')->select()->toArray();
- $list = make_tree($list);
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取二级分类
- * @desc 获取二级分类
- * @author qc
- * @url /api/Information/getSecondCate
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:pid type:int default:-- desc:一级分类id
- * @return name:id type:int default:-- desc:分类id
- * @return name:logo type:string default:-- desc:图标
- * @return name:title type:string default:0 desc:分类名称
- * @return name:desc type:string default:0 desc:分类描述
- */
- public function getSecondCate()
- {
- $pid = input('pid');
- $list = NewsCate::where(['is_deleted'=>0,'pid'=>$pid])->field('id,logo,title,pid,desc')->order('sort desc')->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取资讯栏目
- * @desc 获取资讯栏目
- * @author qc
- * @url /api/Information/getNewsChannel
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:title type:string default:-- desc:标题
- * @return name:desc type:string default:-- desc:描述(副标题)
- */
- public function getNewsChannel()
- {
- $list = NewsChannel::field('id,desc,title')->where(['is_deleted'=>0,'status'=>1])->order('sort desc ,id desc')->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取亚健康资讯标签
- * @desc 获取亚健康资讯标签
- * @author qc
- * @url /api/Information/getNutritionCaseList
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:title type:string default:-- desc:标签名
- * @return name:logo type:string default:-- desc:图片
- */
- public function getNutritionCaseList()
- {
- $list = NutritionCase::field('id,title,logo')->where(['status'=>1,'is_deleted'=>0])->order('sort desc ,id desc')->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取亚健康资讯标签详情
- * @desc 获取亚健康资讯标签详情
- * @author qc
- * @url /api/Information/getNutritionCaseDetail
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:-- desc:标签id
- * @return name:title type:string default:-- desc:标签名
- * @return name:intro type:string default:-- desc:详情介绍
- */
- public function getNutritionCaseDetail()
- {
- $id= input('get.id');
- $detail = NutritionCase::where('id',$id)->find()->toArray();
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 随机获取亚健康资讯标签
- * @desc 随机获取
- * @author qc
- * @url /api/Information/getRandNutritionCase
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:4 desc:随机数量
- * @return name:title type:string default:-- desc:标签名
- */
- public function getRandNutritionCase()
- {
- $num = input('get.num',4);
- $list = NutritionCase::field('id,title,logo')->where(['status'=>1,'is_deleted'=>0])->order('sort desc ,id desc')->column('title','id');
- $rand_key = array_rand($list,$num);
- $rand_list = [];
- foreach ($rand_key as $key) {
- $rand_list[] = ['id'=>$key,'title'=>$list[$key]];
- }
- $this->success('ok',['list'=>$rand_list]);
- }
- /**
- * @title 获取资讯专题推荐商品
- * @desc 获取资讯专题推荐商品
- * @author qc
- * @method GET
- * @url /api/Information/getGoodsByNutritionCase
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:资讯id
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数量
- * @return name:id type:string default:-- desc:资讯标签id
- * @return name:news_id type:string default:-- desc:资讯id
- * @return name:goods_set type:array default:-- desc:商品信息
- * @return name:goods_set.name type:string default:-- desc:商品名称
- * @return name:goods_set.desc type:float default:-- desc:商品简介(副标题)
- * @return name:goods_set.cover type:string default:-- desc:商品封面
- * @return name:goods_set.low_price type:float default:-- desc:最低价格
- */
- public function getGoodsByNutritionCase()
- {
- $label_id = input('get.label_id');
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- if($label_id) $sel_where[] = ['label','like','%'.'|'.$label_id.'|'.'%'];
- $new_ids = InformationArticle::where('is_deleted',0)->order('id desc')->limit(0,5)->column('id');
- $goods_ids = InformationGoods::field('goods_id,max(id) id')->where('news_id','in',$new_ids)->group('goods_id')->select()->toArray();
- $list = InformationGoods::with('goodsSet')
- ->where('id','in',array_column($goods_ids,'id'))
- ->limit($this->off_set,$this->page_num)->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取轮播图
- * @desc 获取轮播图
- * @author qc
- * @url /api/Information/getBanner
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:5 desc:查询数量
- * @return name:cover type:srting default:-- desc:图片路径
- * @return name:link type:srting default:-- desc:链接
- */
- public function getBanner()
- {
- $num = input('get.num',5);
- $list = StoreBanner::where(['place'=>2,'is_deleted'=>0])
- ->field('id,cover,link')
- ->limit(0,$num)
- ->order('sort desc ,id desc')
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取资讯列表
- * @desc
- * @author qc
- * @method GET
- * @url /api/Information/getInformationList
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数量
- * @param name:title type:string default:-- desc:标题
- * @param name:type type:int default:0 desc:类型(0全部,1图文,2视频)
- * @param name:channel_id type:int default:0 desc:资讯栏目id
- * @param name:first_classify type:int default:0 desc:一级分类
- * @param name:second_classify type:int default:0 desc:二级分类
- * @param name:is_top type:int default:0 desc:置顶查询传1(置顶文章查询)
- * @param name:label_id type:int default:0 desc:标签id(亚健康资讯)
- * @return name:title type:string default:-- desc:标题
- * @return name:cover type:string default:-- desc:封面
- * @return name:channel_id type:int default:0 desc:资讯栏目id
- * @return name:video_url type:string default:-- desc:视频地址
- * @return name:detail type:string default:-- desc:详情(视频没有这个)
- * @return name:first_classify type:int default:-- desc:一级分类(/api/Information/getCateTree这个接口返回的第一级id)
- * @return name:second_classify type:int default:-- desc:二级分类(/api/Information/getCateTree这个接口返回的第二级id)
- * @return name:type type:string default:-- desc:1图文2视频
- * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:is_collect type:int default:-- desc:是否收藏
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:is_hot type:int default:-- desc:是否热门(0否,1是)
- * @return name:is_new type:int default:-- desc:是否是最新(0否,1是)
- */
- public function getInformationList()
- {
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- $title = input('get.title');
- $type = input('get.type');
- $is_top = input('get.is_top');
- $channel_id = input('get.channel_id');
- $first_classify = input('get.first_classify');
- $second_classify = input('get.second_classify');
- $label_id = input('get.label_id');
- if($title) $sel_where[] = ['title','like','%'.$title.'%'];
- if($type) $sel_where[] = ['type','=',$type];
- if($first_classify) $sel_where[] = ['first_classify','=',$first_classify];
- if($second_classify) $sel_where[] = ['second_classify','=',$second_classify];
- if($is_top) $sel_where[] = ['is_top','=',$is_top];
- if($channel_id) $sel_where[] = ['channel_id','=',$channel_id];
- if($label_id) $sel_where[] = ['label','like','%'.'|'.$label_id.'|'.'%'];
- $new_ids = InformationArticle::order('id desc')->limit(0,3)->column('id');
- $list = InformationArticle::where($sel_where)
- ->order('is_top desc,sort desc ,id desc')
- ->limit($this->off_set,$this->page)->select()->toArray();
- array_walk($list,function (&$v,$k)use ($new_ids){
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$v['id']);
- $v['is_new'] = in_array($v['id'],$new_ids)? 1 :0;
- $v['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$v['id']])->count();
- $v['is_hot'] = $v['collect_num'] > 10000 ? 1:0;
- });
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取资讯详情
- * @desc 获取资讯详情
- * @author qc
- * @method GET
- * @url /api/Information/getInformationDetail
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:资讯id
- * @return name:title type:string default:-- desc:标题
- * @return name:cover type:string default:-- desc:封面
- * @return name:video_url type:string default:-- desc:视频地址
- * @return name:detail type:string default:-- desc:详情(视频没有这个)
- * @return name:first_classify type:int default:-- desc:一级分类
- * @return name:second_classify type:int default:-- desc:二级分类
- * @return name:type type:string default:-- desc:1图文2视频
- * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:is_collect type:int default:-- desc:是否收藏(0否,1是)
- * @return name:collect_num type:int default:-- desc:收藏量
- * @return name:is_hot type:int default:-- desc:是否热门(0否,1是)
- * @return name:label type:int default:-- desc:亚健康标签id串(格式:|id|id|)
- * @return name:label_name type:array default:-- desc:亚健康标签
- * @return name:label_name.title type:array default:-- desc:亚健康标签名
- * @return name:platform_name type:string default:-- desc:平台名称
- */
- public function getInformationDetail()
- {
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- $sel_where[] = ['id','=',input('get.id')];
- if($this->user_id)UserTrack::createTrack($this->user_id,2,input('get.id'));
- $detail = InformationArticle::where($sel_where)
- ->order('is_top desc,sort desc ,id desc')->find();
- if(!$detail)$this->error('该资讯已下线');
- $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,2,$detail->id);
- $detail['collect_num'] = UserCollect::where(['coll_type'=>2,'coll_id'=>$detail->id])->count();
- $detail['is_hot'] = $detail['collect_num'] > 10000 ? 1:0;
- $detail['label_name'] = [];
- if($detail['label']){
- $label_id = explode('|',trim($detail['label'],'|'));
- $detail['label_name'] = NutritionCase::field('id,title')->where('id','in',$label_id)->select()->toArray();
- }
- $detail['platform_name'] = config('text.platform_name');
- InformationArticle::where('id',input('get.id'))->setInc('read_num');//阅读量+1
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取资讯相关商品
- * @desc 获取资讯相关商品
- * @author qc
- * @method GET
- * @url /api/Information/getInformationGoods
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:资讯id
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数量
- * @return name:id type:string default:-- desc:资讯相关商品记录id
- * @return name:news_id type:string default:-- desc:资讯id
- * @return name:goods_set type:array default:-- desc:商品信息
- * @return name:goods_set.name type:string default:-- desc:商品名称
- * @return name:goods_set.desc type:float default:-- desc:商品简介(副标题)
- * @return name:goods_set.cover type:string default:-- desc:商品封面
- * @return name:goods_set.low_price type:float default:-- desc:最低价格
- */
- public function getInformationGoods()
- {
- $id = input('get.id');
- $list = InformationGoods::with('goodsSet')->where(['news_id'=>$id])->limit($this->off_set,$this->page_num)->select();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取资讯素材
- * @desc 获取资讯素材
- * @author qc
- * @method GET
- * @url /api/Information/getNewsMaterial
- * @header name:Authorization require:1 desc:Token
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数量
- * @param name:type type:int default:1 desc:类型(1线上,2线下)
- * @return name:id type:int default:-- desc:素材id
- * @return name:type type:int default:-- desc:类型(1线上,2线下)
- * @return name:title type:string default:-- desc:标题
- * @return name:cover type:string default:-- desc:图片
- */
- public function getNewsMaterial()
- {
- $type = input('get.type',1);
- $list = NewsMaterial::field('id,title,type,cover')->where(['type'=>$type,'is_deleted'=>0,'status'=>1])->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- }
|