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;
- class Information extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
-
- 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]);
- }
-
- 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]);
- }
-
- 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]);
- }
-
- 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]);
- }
-
- public function getNutritionCaseDetail()
- {
- $id= input('get.id');
- $detail = NutritionCase::where('id',$id)->find()->toArray();
- $this->success('ok',['detail'=>$detail]);
- }
-
- 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]);
- }
-
- 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]);
- }
-
- 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]);
- }
-
- 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]);
- }
-
- 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');
- $this->success('ok',['detail'=>$detail]);
- }
-
- 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]);
- }
-
- 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]);
- }
- }
|