Index.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use addons\unishop\model\Product as productModel;
  6. /**
  7. * 首页接口
  8. */
  9. class Index extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. */
  16. public function index()
  17. {
  18. //一行标签
  19. $tag = Db::name('index_server')->order('id desc')->select();
  20. $tag = list_domain_image($tag,['image']);
  21. //多个头条
  22. $sys = Db::name('index_sys')->order('id desc')->select();
  23. //默认不弹窗,登录了但是没有地址,就弹窗
  24. $add_address = 0;
  25. if($this->auth->isLogin()){
  26. $address = Db::name('unishop_address')->where('user_id',$this->auth->id)->find();
  27. if(empty($address)){
  28. $add_address = 1;
  29. }
  30. }
  31. //首页弹窗商品
  32. $index_show_product = null;
  33. $map = [
  34. 'id' => config('site.index_show_product'),
  35. 'switch' => 1,
  36. 'deletetime' => null,
  37. ];
  38. $productModel = new productModel();
  39. $index_show_product = $productModel->field('id,image,title')->where($map)->find();
  40. $index_show_product = info_domain_image($index_show_product,['image']);
  41. $result = [
  42. 'tag' => $tag,
  43. 'sys' => $sys,
  44. 'index_add_address' => $add_address, //首页是否添加地址
  45. 'index_show_product' => $index_show_product,//首页弹窗商品
  46. ];
  47. $this->success(1, $result);
  48. }
  49. }