StoreProductGroup.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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 think\App;
  15. use crmeb\basic\BaseController;
  16. use app\common\repositories\store\product\ProductGroupRepository;
  17. class StoreProductGroup extends BaseController
  18. {
  19. use BindSpreadTrait;
  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. /**
  34. * 获取列表数据
  35. *
  36. * 本函数用于根据请求参数获取对应的商品列表数据。
  37. * 它通过解析页码和每页数量来确定分页信息,从请求中获取过滤条件,然后调用仓库层的方法来获取数据。
  38. * 返回的数据格式化为JSON,用于API响应。
  39. *
  40. * @return \think\response\Json 成功时返回格式化后的数据。
  41. */
  42. public function lst()
  43. {
  44. // 解析并获取当前页码和每页数据数量
  45. [$page, $limit] = $this->getPage();
  46. // 从请求中获取过滤条件,包括激活类型、店铺分类ID、星级和商家ID
  47. $where = $this->request->params([['active_type',1],'store_category_id','star','mer_id']);
  48. // 调用仓库层的方法获取数据,并以JSON格式返回
  49. return app('json')->success($this->repository->getApiList($where,$page, $limit));
  50. }
  51. /**
  52. * 获取资源的详细信息
  53. *
  54. * 本函数通过调用repository中的apiDetail方法,根据提供的ID和用户信息来获取特定资源的详细数据。
  55. * 它封装了数据获取的过程,并通过JSON格式返回成功获取的数据。
  56. *
  57. * @param int $id 资源的唯一标识符,用于定位特定资源
  58. * @return \Illuminate\Http\JsonResponse 成功获取数据时返回的JSON响应,包含资源的详细信息
  59. */
  60. public function detail($id)
  61. {
  62. $this->bindSpread($this->userInfo);
  63. // 调用repository的apiDetail方法,传入资源ID和用户信息,获取资源详细数据
  64. $data = $this->repository->apiDetail($id, $this->userInfo);
  65. // 使用app助手函数获取JSON响应实例,并传入获取的数据,构造成功返回的JSON响应
  66. return app('json')->success($data);
  67. }
  68. /**
  69. * 某个团的详情
  70. * @param $id
  71. * @return \think\response\Json
  72. * @author Qinii
  73. */
  74. public function groupBuying($id)
  75. {
  76. $make = app()->make(ProductGroupBuyingRepository::class);
  77. $data = $make->detail($id,$this->userInfo);
  78. if(!$data) return app('json')->fail('数据丢失');
  79. return app('json')->success($data);
  80. }
  81. /**
  82. * 获取用户数量
  83. *
  84. * 本函数用于查询当前应用中的用户数量。通过分页方式获取数据,以支持数据量较大的情况下的查询效率。
  85. * 不接受任何参数,返回当前应用用户数量的相关数据。
  86. *
  87. * @return \Illuminate\Http\JsonResponse 返回包含用户数量数据的JSON响应。
  88. */
  89. public function userCount()
  90. {
  91. // 解析并获取当前请求的页码和每页数量
  92. [$page, $limit] = $this->getPage();
  93. // 通过依赖注入的方式获取ProductGroupUserRepository实例
  94. // 并调用其getApiList方法获取用户数据列表
  95. $data = app()->make(ProductGroupUserRepository::class)->getApiList([], $page, $limit);
  96. // 使用应用的JSON工具类将获取到的数据封装成JSON响应并返回
  97. return app('json')->success($data);
  98. }
  99. public function category()
  100. {
  101. return app('json')->success($this->repository->getCategory());
  102. }
  103. /**
  104. * 取消参团
  105. * @author Qinii
  106. * @day 1/13/21
  107. */
  108. public function cancel()
  109. {
  110. $data = (int)$this->request->param('group_buying_id');
  111. $make = app()->make(ProductGroupBuyingRepository::class);
  112. $make->cancelGroup($data,$this->userInfo);
  113. return app('json')->success('取消成功,订单金额将会原路退回');
  114. }
  115. }