Nutrition.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\NewsCate;
  4. use app\common\model\StoreBanner;
  5. use think\Db;
  6. /**
  7. * @title 康养百科(废弃)
  8. * @controller Nutrition
  9. * @group base
  10. */
  11. class Nutrition extends Base
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. parent::setUid();
  17. }
  18. /**
  19. * @title 获取营养百科资讯分类
  20. * @desc 获取营养百科资讯分类
  21. * @author qc
  22. * @url /api/Nutrition/getNewsCate
  23. * @method GET
  24. * @header name:Authorization require:1 desc:Token
  25. * @return name:logo type:string default:-- desc:log
  26. * @return name:title type:string default:-- desc:名称
  27. * @return name:pid type:string default:-- desc:上级id
  28. * @return name:child_ren type:array default:-- desc:二级分类
  29. */
  30. public function getNewsCate(){
  31. $list = NewsCate::getCates();
  32. $this->success('ok',['list'=>$list]);
  33. }
  34. /**
  35. * @title 获取下级分类
  36. * @desc 获取下级分类
  37. * @author qc
  38. * @url /api/Nutrition/getChildrenCate
  39. * @method GET
  40. * @header name:Authorization require:1 desc:Token
  41. * @param name:cate_id type:int default:-- desc:上级id
  42. * @return name:logo type:string default:-- desc:log
  43. * @return name:title type:string default:-- desc:名称
  44. * @return name:pid type:string default:-- desc:上级id
  45. * @return name:child_ren type:array default:-- desc:二级分类
  46. */
  47. public function getChildrenCate()
  48. {
  49. $cate_id = input('cate_id');
  50. $list = NewsCate::where(['pid'=>$cate_id,'is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select();
  51. $this->success('ok',['list'=>$list ? $list->toArray():[]]);
  52. }
  53. /**
  54. * @title 获取百科轮播图
  55. * @desc 获取百科轮播图
  56. * @author qc
  57. * @url /api/Nutrition/getNutritionBanner
  58. * @method GET
  59. * @header name:Authorization require:1 desc:Token
  60. * @return name:cover type:string default:-- desc:图片
  61. * @return name:link type:string default:-- desc:链接
  62. * @return name:child_ren type:array default:-- desc:二级分类
  63. */
  64. public function getNutritionBanner()
  65. {
  66. $list = StoreBanner::where(['place'=>2,'is_deleted'=>0])
  67. ->field('id,cover,link')->order('sort desc')->limit(0,5)->select();
  68. $this->success('ok',['list'=>$list? $list->toArray():[]]);
  69. }
  70. /**
  71. * @title 获取百科推荐case
  72. * @desc 获取百科推荐case
  73. * @author qc
  74. * @url /api/Nutrition/getNutritionCase
  75. * @method GET
  76. * @header name:Authorization require:1 desc:Token
  77. * @param name:num type:int default:0 desc:随机查询数量(0查询全部)
  78. * @return name:id type:int default:-- desc:id
  79. * @return name:title type:string default:-- desc:标题
  80. */
  81. public function getNutritionCase()
  82. {
  83. $num = input('get.num',0);
  84. $list = Db::name('nutrition_case')->where(['status'=>1])->field('id,title')->select();
  85. if(!$list) $this->success('ok',['list'=>[]]);
  86. if(!$num || $num > $list) $this->success('ok',['list'=>$list->toArray()]);
  87. $rand_key = array_rand(array_keys($list),$num);
  88. $list = $list->toArray();
  89. $ret = [];
  90. array_map(function ($val)use(&$ret,$list){
  91. $ret[] = $list[$val];
  92. },$rand_key);
  93. $this->success('ok',['list'=>$ret]);
  94. }
  95. }