StoreProductAssistSet.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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\ProductAssistSetRepository;
  13. use app\common\repositories\store\product\ProductAssistUserRepository;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. class StoreProductAssistSet extends BaseController
  17. {
  18. protected $repository;
  19. protected $userInfo;
  20. /**
  21. * StoreProductPresell constructor.
  22. * @param App $app
  23. * @param repository $repository
  24. */
  25. public function __construct(App $app, ProductAssistSetRepository $repository)
  26. {
  27. parent::__construct($app);
  28. $this->repository = $repository;
  29. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  30. }
  31. /**
  32. * 个人助力列表
  33. * @return mixed
  34. * @author Qinii
  35. * @day 2020-11-25
  36. */
  37. public function lst()
  38. {
  39. [$page, $limit] = $this->getPage();
  40. $where['uid'] = $this->request->uid();
  41. return app('json')->success($this->repository->getApiList($where,$page, $limit));
  42. }
  43. /**
  44. * 根据ID获取详细信息
  45. *
  46. * 本函数旨在根据提供的ID和类型参数,从仓库中获取特定资源的详细信息。
  47. * 它首先从请求中获取类型参数,并验证其是否为预期的值(1或2)。
  48. * 如果类型参数无效,函数将返回一个错误响应。
  49. * 如果类型参数有效,函数将调用仓库中的detail方法来获取信息,并返回成功响应包含获取的数据。
  50. *
  51. * @param int $id 资源的唯一标识符
  52. * @return \think\Response 返回一个JSON格式的响应,包含成功获取的数据或错误信息
  53. */
  54. public function detail($id)
  55. {
  56. // 从请求中获取类型参数,并设置默认值为1
  57. $type = $this->request->param('type', 1);
  58. // 验证类型参数是否有效(是否为1或2)
  59. if (!in_array($type, [1, 2])) {
  60. // 如果类型参数无效,返回一个错误的JSON响应
  61. return app('json')->fail('类型参数错误');
  62. }
  63. // 调用仓库的detail方法来获取指定ID和类型的资源信息
  64. $data = $this->repository->detail($id, $this->userInfo, $type);
  65. // 返回一个成功的JSON响应,包含获取的资源信息
  66. return app('json')->success($data);
  67. }
  68. /**
  69. * 发起助力
  70. * @param $id
  71. * @return mixed
  72. * @author Qinii
  73. * @day 2020-10-28
  74. */
  75. public function create($id)
  76. {
  77. // if($this->userInfo->user_type == 'wechat' && !$this->userInfo->subscribe){
  78. // return app('json')->fail('请先关注公众号');
  79. // }
  80. $data = $this->repository->create($id,$this->request->uid());
  81. return app('json')->success($data);
  82. }
  83. /**
  84. * 帮好友助力
  85. * @param $id
  86. * @return mixed
  87. * @author Qinii
  88. * @day 2020-10-28
  89. */
  90. public function set($id)
  91. {
  92. $this->repository->set($id,$this->userInfo);
  93. return app('json')->success('助力成功');
  94. }
  95. /**
  96. * 删除辅助设置项
  97. *
  98. * 本函数用于逻辑删除一个辅助设置项。所谓逻辑删除,是指并不真正从数据库中移除记录,
  99. * 而是通过将记录的状态字段设置为特定值(这里为-1)来标记该记录为已删除。
  100. * 这种做法通常用于处理数据安全和可恢复性方面的需求。
  101. *
  102. * @param int $id 辅助设置项的唯一标识ID
  103. * @return json 返回一个JSON格式的响应,包含操作的结果信息
  104. */
  105. public function delete($id)
  106. {
  107. // 根据ID和当前用户的UID查询辅助设置项信息
  108. $res = $this->repository->getWhere(['product_assist_set_id' => $id,'uid' => $this->request->uid()]);
  109. // 如果查询结果为空,则返回错误信息
  110. if(!$res)return app('json')->fail('信息错误');
  111. // 更新辅助设置项的状态为已删除(-1)
  112. $this->repository->update($id,['status' => -1]);
  113. // 返回成功信息
  114. return app('json')->success('取消成功');
  115. }
  116. /**
  117. * 助力列表
  118. * @param $id
  119. * @param ProductAssistUserRepository $repository
  120. * @return mixed
  121. * @author Qinii
  122. * @day 2020-10-28
  123. */
  124. public function userList($id,ProductAssistUserRepository $repository)
  125. {
  126. [$page, $limit] = $this->getPage();
  127. $where['product_assist_set_id'] = $id;
  128. if(!$this->repository->get($id)) return app('json')->fail('数据丢失');
  129. return app('json')->success($repository->userList($where,$page, $limit));
  130. }
  131. /**
  132. * 分享数量增加函数
  133. *
  134. * 本函数用于处理分享数量的增加操作。它通过调用repository中的方法来实现分享计数的增加,
  135. * 并返回一个表示操作成功的JSON响应。
  136. *
  137. * @param int $id 共享内容的唯一标识符。这个标识符用于确定要增加分享计数的具体内容。
  138. * @return \Illuminate\Http\JsonResponse 返回一个表示操作成功的JSON响应。
  139. */
  140. public function shareNum($id)
  141. {
  142. // 增加分享计数。这里$repository被视为一个依赖注入的对象,通过调用其incNum方法来增加指定$id的分享计数。
  143. $this->repository->incNum(1,$id);
  144. // 返回一个表示操作成功的JSON响应。这里使用了app('json')来获取一个JSON响应助手实例,并调用其success方法返回成功消息。
  145. return app('json')->success('oks');
  146. }
  147. }