Index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\api\controller;
  3. use app\admin\model\CategoryLangs;
  4. use app\common\controller\Api;
  5. use app\common\model\Category;
  6. /**
  7. * 首页接口
  8. */
  9. class Index extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $loopProduct = \app\admin\model\product\Product::validWhere()->where('loopswitch', 1)->select();
  20. $recommendProduct = \app\admin\model\product\Product::validWhere()->where('recommendswitch', 1)->select();
  21. $newProduct = \app\admin\model\product\Product::validWhere()->where('newswitch', 1)->select();
  22. $cases = \app\admin\model\cases\Cases::validWhere()->where('indexswitch', 1)->select();
  23. $banners = $this->site['banners'];
  24. $this->success('请求成功', compact('banners', 'cases', 'loopProduct', 'newProduct', 'recommendProduct'));
  25. }
  26. public function cates($type = '')
  27. {
  28. $pid = $this->request->get('pid', 0);
  29. $list = Category::getCategoryArray($type, 'normal', $pid);
  30. // var_dump($list);
  31. if ($this->lang)
  32. foreach ($list as &$v) {
  33. $info = CategoryLangs::where('category_id', $v['id'])->where('langlist', $this->lang)->find();
  34. if ($info) {
  35. $v['name'] = $info['name'];
  36. }
  37. }
  38. $this->success('请求成功', $list);
  39. }
  40. }