StoreProduct.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. namespace app\controller\api\store\product;
  3. use app\common\repositories\store\GuaranteeTemplateRepository;
  4. use app\common\repositories\store\product\SpuRepository;
  5. use app\common\repositories\system\groupData\GroupDataRepository;
  6. use app\common\repositories\user\UserMerchantRepository;
  7. use ln\jobs\ChangeSpuStatusJob;
  8. use think\App;
  9. use ln\basic\BaseController;
  10. use app\common\repositories\store\product\ProductRepository as repository;
  11. use think\facade\Cache;
  12. class StoreProduct extends BaseController
  13. {
  14. /**
  15. * @var repository
  16. */
  17. protected $repository;
  18. protected $userInfo;
  19. /**
  20. * StoreProduct constructor.
  21. * @param App $app
  22. * @param repository $repository
  23. */
  24. public function __construct(App $app, repository $repository)
  25. {
  26. parent::__construct($app);
  27. $this->repository = $repository;
  28. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  29. }
  30. /**
  31. * @Author:Qinii
  32. * @Date: 2020/5/28
  33. * @return mixede
  34. */
  35. public function lst()
  36. {
  37. [$page, $limit] = $this->getPage();
  38. $where = $this->request->params(['keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid','star']);
  39. $data = $this->repository->getApiSearch(null, $where, $page, $limit, $this->userInfo);
  40. return app('json')->success($data);
  41. }
  42. /**
  43. * @Author:Qinii
  44. * @Date: 2020/5/30
  45. * @param $id
  46. * @return mixed
  47. */
  48. public function detail($id)
  49. {
  50. $data = $this->repository->detail($id, $this->userInfo);
  51. if (!$data){
  52. queue(ChangeSpuStatusJob::class,['id' => $id,'product_type' => 0]);
  53. return app('json')->fail('商品已下架');
  54. }
  55. if ($this->request->isLogin()) {
  56. app()->make(UserMerchantRepository::class)->updateLastTime($this->request->uid(), $data->mer_id);
  57. }
  58. return app('json')->success($data);
  59. }
  60. /**
  61. * @Author:Qinii
  62. * @Date: 2020/5/30
  63. * @return mixed
  64. */
  65. public function recommendList()
  66. {
  67. [$page, $limit] = $this->getPage();
  68. return app('json')->success($this->repository->recommend($this->userInfo, null, $page, $limit));
  69. }
  70. public function qrcode($id)
  71. {
  72. $id = (int)$id;
  73. $param = $this->request->params(['type', ['product_type', 0]]);
  74. $param['product_type'] = (int)$param['product_type'];
  75. if (!$id || !$product = $this->repository->existsProduct($id, $param['product_type']))
  76. return app('json')->fail('商品不存在');
  77. if ($param['type'] == 'routine') {
  78. $url = $this->repository->routineQrCode($id, $param['product_type'], $this->request->userInfo());
  79. }else{
  80. $url = $this->repository->wxQrCode($id, $param['product_type'], $this->request->userInfo());
  81. }
  82. if (!$url) return app('json')->fail('二维码生成失败');
  83. return app('json')->success(compact('url'));
  84. }
  85. public function getBagList()
  86. {
  87. if(!systemConfig('extension_status')) return app('json')->fail('活动未开启');
  88. [$page, $limit] = $this->getPage();
  89. $where = $this->repository->bagShow();
  90. return app('json')->success($this->repository->getBagList($where, $page, $limit));
  91. }
  92. public function getBagrecomm()
  93. {
  94. $where = $this->repository->bagShow();
  95. $where['is_best'] = 1;
  96. return app('json')->success($this->repository->selectWhere($where)->append(['merchant']));
  97. }
  98. public function getBagExplain()
  99. {
  100. if(!systemConfig('extension_status')) return app('json')->fail('活动未开启');
  101. $data = [
  102. 'explain' => systemConfig('promoter_explain'),
  103. 'data' => app()->make(GroupDataRepository::class)->groupData('promoter_config', 0),
  104. ];
  105. return app('json')->success($data);
  106. }
  107. public function hot($type)
  108. {
  109. [$page, $limit] = $this->getPage();
  110. return app('json')->success($this->repository->getApiSearch(null, ['hot_type' => $type, 'is_gift_bag' => 0, 'is_used' => 1], $page, $limit, $this->userInfo));
  111. }
  112. public function guaranteeTemplate($id)
  113. {
  114. $where = [
  115. 'guarantee_template_id' => $id,
  116. 'status' => 1,
  117. ];
  118. $data = $this->repository->GuaranteeTemplate($where);
  119. return app('json')->success($data);
  120. }
  121. public function setIncreaseTake()
  122. {
  123. $product_id = $this->request->param('product_id');
  124. $unique = $this->request->param('unique');
  125. $type = $this->request->param('type');
  126. if($type == 1 && !$this->userInfo['phone']) return app('json')->fail('请先绑定手机号');
  127. $this->repository->increaseTake($this->request->uid(),$unique,$type,$product_id);
  128. return app('json')->success('订阅成功');
  129. }
  130. /**
  131. * TODO
  132. * @return \think\response\Json
  133. * @author Qinii
  134. * @day 6/15/21
  135. */
  136. public function preview()
  137. {
  138. $param = $this->request->params(['key','id','product_type']);
  139. $data = [];
  140. if($param['key']){
  141. $data = Cache::get($param['key']);
  142. Cache::delete($param['key']);
  143. }elseif($param['id']){
  144. $data = $this->repository->getPreview($param);
  145. }
  146. if(!$data) return app('json')->fail('数据不存在');
  147. return app('json')->success($data);
  148. }
  149. }