StoreSpu.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\controller\api\store\product;
  3. use app\common\repositories\user\UserHistoryRepository;
  4. use think\App;
  5. use ln\basic\BaseController;
  6. use app\common\repositories\store\product\SpuRepository;
  7. class StoreSpu extends BaseController
  8. {
  9. protected $userInfo;
  10. protected $repository;
  11. public function __construct(App $app, SpuRepository $repository)
  12. {
  13. parent::__construct($app);
  14. $this->repository = $repository;
  15. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  16. }
  17. /**
  18. * TODO 商品搜索列表
  19. * @return mixed
  20. * @author Qinii
  21. * @day 12/24/20
  22. */
  23. public function lst()
  24. {
  25. [$page, $limit] = $this->getPage();
  26. $where = $this->request->params([
  27. 'keyword', 'cate_id', 'cate_pid', 'order', 'price_on', 'price_off', 'brand_id', 'pid','mer_cate_id','product_type','action', 'common'
  28. ]);
  29. $where['is_gift_bag'] = 0;
  30. $where['order'] = $where['order'] ? $where['order'] : 'star';
  31. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  32. return app('json')->success($data);
  33. }
  34. /**
  35. * TODO 商户的商品搜索列表
  36. * @param $id
  37. * @return mixed
  38. * @author Qinii
  39. * @day 12/24/20
  40. */
  41. public function merProductLst($id)
  42. {
  43. [$page, $limit] = $this->getPage();
  44. $where = $this->request->params([
  45. 'keyword', 'cate_id','order', 'price_on', 'price_off', 'brand_id', 'pid','mer_cate_id','product_type','action','common'
  46. ]);
  47. $where['mer_id'] = $id;
  48. $where['is_gift_bag'] = 0;
  49. $where['order'] = $where['order'] ? $where['order'] : 'sort';
  50. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  51. return app('json')->success($data);
  52. }
  53. /**
  54. * TODO 推荐列表
  55. * @return mixed
  56. * @author Qinii
  57. * @day 12/24/20
  58. */
  59. public function recommend()
  60. {
  61. [$page, $limit] = $this->getPage();
  62. $where = $this->request->params(['common']);
  63. $where['order'] = 'sales';
  64. $where['is_gift_bag'] = 0;
  65. if (!is_null( $this->userInfo)) {
  66. $cateId= app()->make(UserHistoryRepository::class)->getRecommend($this->userInfo->uid);
  67. if($cateId && count($cateId) > 5) $where['cate_id'] = $cateId;
  68. }
  69. $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo);
  70. return app('json')->success($data);
  71. }
  72. /**
  73. * TODO 热门列表
  74. * @return mixed
  75. * @author Qinii
  76. * @day 12/24/20
  77. */
  78. public function hot($type)
  79. {
  80. [$page, $limit] = $this->getPage();
  81. $where = $this->request->params(['common']);
  82. $where['hot_type'] = $type;
  83. $where['is_gift_bag'] = 0;
  84. $where['order'] = 'star';
  85. $data = $this->repository->getApiSearch($where, $page, $limit, null);
  86. return app('json')->success($data);
  87. }
  88. /**
  89. * TODO 礼包列表
  90. * @return mixed
  91. * @author Qinii
  92. * @day 12/24/20
  93. */
  94. public function bag()
  95. {
  96. [$page, $limit] = $this->getPage();
  97. $where['is_gift_bag'] = 1;
  98. $where['order'] = 'rank';
  99. $data = $this->repository->getApiSearch($where, $page, $limit,null);
  100. return app('json')->success($data);
  101. }
  102. /**
  103. * TODO 礼包推荐列表
  104. * @return mixed
  105. * @author Qinii
  106. * @day 12/24/20
  107. */
  108. public function bagRecommend()
  109. {
  110. [$page, $limit] = $this->getPage();
  111. $where['is_gift_bag'] = 1;
  112. $where['hot_type'] = 'best';
  113. $data = $this->repository->getApiSearch($where, $page, $limit,null);
  114. return app('json')->success($data);
  115. }
  116. /**
  117. * TODO 活动分类
  118. * @param $type
  119. * @return \think\response\Json
  120. * @author Qinii
  121. * @day 1/12/21
  122. */
  123. public function activeCategory($type)
  124. {
  125. $data = $this->repository->getActiveCaategory($type);
  126. return app('json')->success($data);
  127. }
  128. }