StoreProductGroup.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\ProductGroupBuyingRepository;
  13. use app\common\repositories\store\product\ProductGroupUserRepository;
  14. use crmeb\jobs\ChangeSpuStatusJob;
  15. use think\App;
  16. use crmeb\basic\BaseController;
  17. use app\common\repositories\store\product\ProductGroupRepository;
  18. class StoreProductGroup extends BaseController
  19. {
  20. protected $repository;
  21. protected $userInfo;
  22. /**
  23. * StoreProductPresell constructor.
  24. * @param App $app
  25. * @param repository $repository
  26. */
  27. public function __construct(App $app, ProductGroupRepository $repository)
  28. {
  29. parent::__construct($app);
  30. $this->repository = $repository;
  31. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  32. }
  33. public function lst()
  34. {
  35. [$page, $limit] = $this->getPage();
  36. $where = $this->request->params([['active_type',1],'store_category_id','star']);
  37. return app('json')->success($this->repository->getApiList($where,$page, $limit));
  38. }
  39. public function detail($id)
  40. {
  41. $data = $this->repository->apiDetail($id);
  42. if(!$data){
  43. queue(ChangeSpuStatusJob::class,['id' => $id,'product_type' => 4]);
  44. return app('json')->fail('商品已下架');
  45. }
  46. return app('json')->success($data);
  47. }
  48. public function groupBuying($id)
  49. {
  50. $make = app()->make(ProductGroupBuyingRepository::class);
  51. $data = $make->detail($id,$this->userInfo);
  52. if(!$data) return app('json')->fail('数据丢失');
  53. return app('json')->success($data);
  54. }
  55. public function userCount()
  56. {
  57. [$page, $limit] = $this->getPage();
  58. $data = app()->make(ProductGroupUserRepository::class)->getApiList([],$page,$limit);
  59. return app('json')->success($data);
  60. }
  61. public function category()
  62. {
  63. return app('json')->success($this->repository->getCategory());
  64. }
  65. /**
  66. * TODO 取消参团
  67. * @author Qinii
  68. * @day 1/13/21
  69. */
  70. public function cancel()
  71. {
  72. $data = (int)$this->request->param('group_buying_id');
  73. $make = app()->make(ProductGroupBuyingRepository::class);
  74. $make->cancelGroup($data,$this->userInfo);
  75. return app('json')->success('取消成功,订单金额将会原路退回');
  76. }
  77. }