Index.php 1.5 KB

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