StoreProduct.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\store\product;
  12. use app\common\repositories\store\product\SpuRepository;
  13. use app\common\repositories\system\groupData\GroupDataRepository;
  14. use app\common\repositories\user\UserMerchantRepository;
  15. use crmeb\jobs\ChangeSpuStatusJob;
  16. use think\App;
  17. use crmeb\basic\BaseController;
  18. use app\common\repositories\store\product\ProductRepository as repository;
  19. class StoreProduct extends BaseController
  20. {
  21. /**
  22. * @var repository
  23. */
  24. protected $repository;
  25. protected $userInfo;
  26. /**
  27. * StoreProduct constructor.
  28. * @param App $app
  29. * @param repository $repository
  30. */
  31. public function __construct(App $app, repository $repository)
  32. {
  33. parent::__construct($app);
  34. $this->repository = $repository;
  35. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  36. }
  37. /**
  38. * @Author:Qinii
  39. * @Date: 2020/5/28
  40. * @return mixede
  41. */
  42. public function lst()
  43. {
  44. [$page, $limit] = $this->getPage();
  45. $where = $this->request->params(['keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid','star']);
  46. $data = $this->repository->getApiSearch(null, $where, $page, $limit, $this->userInfo);
  47. return app('json')->success($data);
  48. }
  49. /**
  50. * @Author:Qinii
  51. * @Date: 2020/5/30
  52. * @param $id
  53. * @return mixed
  54. */
  55. public function detail($id)
  56. {
  57. $data = $this->repository->detail($id, $this->userInfo);
  58. if (!$data){
  59. queue(ChangeSpuStatusJob::class,['id' => $id,'product_type' => 0]);
  60. return app('json')->fail('商品已下架');
  61. }
  62. if ($this->request->isLogin()) {
  63. app()->make(UserMerchantRepository::class)->updateLastTime($this->request->uid(), $data->mer_id);
  64. }
  65. return app('json')->success($data);
  66. }
  67. /**
  68. * @Author:Qinii
  69. * @Date: 2020/5/30
  70. * @return mixed
  71. */
  72. public function recommendList()
  73. {
  74. [$page, $limit] = $this->getPage();
  75. return app('json')->success($this->repository->recommend($this->userInfo, null, $page, $limit));
  76. }
  77. public function qrcode($id)
  78. {
  79. $param = $this->request->params(['type',['product_type',0]]);
  80. if (!$product = $this->repository->existsProduct($id, $param['product_type']))
  81. return app('json')->fail('商品不存在');
  82. if ($param['type'] == 'routine'){
  83. $url = $this->repository->routineQrCode($id,$param['product_type'],$this->request->userInfo());
  84. }else{
  85. $url = $this->repository->wxQrCode($id,$param['product_type'],$this->request->userInfo());
  86. }
  87. if (!$url) return app('json')->fail('二维码生成失败');
  88. return app('json')->success(compact('url'));
  89. }
  90. public function getBagList()
  91. {
  92. if(!systemConfig('extension_status')) return app('json')->fail('活动未开启');
  93. [$page, $limit] = $this->getPage();
  94. $where = $this->repository->bagShow();
  95. return app('json')->success($this->repository->getBagList($where, $page, $limit));
  96. }
  97. public function getBagrecomm()
  98. {
  99. $where = $this->repository->bagShow();
  100. $where['is_best'] = 1;
  101. return app('json')->success($this->repository->selectWhere($where)->append(['merchant']));
  102. }
  103. public function getBagExplain()
  104. {
  105. if(!systemConfig('extension_status')) return app('json')->fail('活动未开启');
  106. $data = [
  107. 'explain' => systemConfig('promoter_explain'),
  108. 'data' => app()->make(GroupDataRepository::class)->groupData('promoter_config', 0),
  109. ];
  110. return app('json')->success($data);
  111. }
  112. public function hot($type)
  113. {
  114. [$page, $limit] = $this->getPage();
  115. return app('json')->success($this->repository->getApiSearch(null, ['hot_type' => $type, 'is_gift_bag' => 0, 'is_used' => 1], $page, $limit, $this->userInfo));
  116. }
  117. }