123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\api\controller;
- use app\common\model\NewsCate;
- use app\common\model\StoreBanner;
- use think\Db;
- /**
- * @title 康养百科(废弃)
- * @controller Nutrition
- * @group base
- */
- class Nutrition extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 获取营养百科资讯分类
- * @desc 获取营养百科资讯分类
- * @author qc
- * @url /api/Nutrition/getNewsCate
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:logo type:string default:-- desc:log
- * @return name:title type:string default:-- desc:名称
- * @return name:pid type:string default:-- desc:上级id
- * @return name:child_ren type:array default:-- desc:二级分类
- */
- public function getNewsCate(){
- $list = NewsCate::getCates();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取下级分类
- * @desc 获取下级分类
- * @author qc
- * @url /api/Nutrition/getChildrenCate
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:cate_id type:int default:-- desc:上级id
- * @return name:logo type:string default:-- desc:log
- * @return name:title type:string default:-- desc:名称
- * @return name:pid type:string default:-- desc:上级id
- * @return name:child_ren type:array default:-- desc:二级分类
- */
- public function getChildrenCate()
- {
- $cate_id = input('cate_id');
- $list = NewsCate::where(['pid'=>$cate_id,'is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select();
- $this->success('ok',['list'=>$list ? $list->toArray():[]]);
- }
- /**
- * @title 获取百科轮播图
- * @desc 获取百科轮播图
- * @author qc
- * @url /api/Nutrition/getNutritionBanner
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:cover type:string default:-- desc:图片
- * @return name:link type:string default:-- desc:链接
- * @return name:child_ren type:array default:-- desc:二级分类
- */
- public function getNutritionBanner()
- {
- $list = StoreBanner::where(['place'=>2,'is_deleted'=>0])
- ->field('id,cover,link')->order('sort desc')->limit(0,5)->select();
- $this->success('ok',['list'=>$list? $list->toArray():[]]);
- }
- /**
- * @title 获取百科推荐case
- * @desc 获取百科推荐case
- * @author qc
- * @url /api/Nutrition/getNutritionCase
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:0 desc:随机查询数量(0查询全部)
- * @return name:id type:int default:-- desc:id
- * @return name:title type:string default:-- desc:标题
- */
- public function getNutritionCase()
- {
- $num = input('get.num',0);
- $list = Db::name('nutrition_case')->where(['status'=>1])->field('id,title')->select();
- if(!$list) $this->success('ok',['list'=>[]]);
- if(!$num || $num > $list) $this->success('ok',['list'=>$list->toArray()]);
- $rand_key = array_rand(array_keys($list),$num);
- $list = $list->toArray();
- $ret = [];
- array_map(function ($val)use(&$ret,$list){
- $ret[] = $list[$val];
- },$rand_key);
- $this->success('ok',['list'=>$ret]);
- }
- }
|