Index.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. //登录之后,首页商品一天只弹一次
  42. if($this->auth->isLogin()){
  43. $key = date('Y-m-d').'-'.$this->auth->id;
  44. if(cache($key) == 1){
  45. $index_show_product = null;
  46. }else{
  47. cache($key,1,86400);
  48. }
  49. }
  50. //
  51. $result = [
  52. 'tag' => $tag,
  53. 'sys' => $sys,
  54. 'index_add_address' => $add_address, //首页是否添加地址
  55. 'index_show_product' => $index_show_product,//首页弹窗商品
  56. ];
  57. $this->success(1, $result);
  58. }
  59. public function test(){
  60. $key = date('Y-m-d').'-'.$this->auth->id;
  61. dump(cache($key));
  62. }
  63. public function clean(){
  64. $key = date('Y-m-d').'-'.$this->auth->id;
  65. cache($key,null);
  66. }
  67. }