StoreProductAssistSet.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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\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. * TODO 个人助力列表
  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. public function detail($id)
  44. {
  45. $data = $this->repository->detail($id,$this->userInfo);
  46. return app('json')->success($data);
  47. }
  48. /**
  49. * TODO 发起助力
  50. * @param $id
  51. * @return mixed
  52. * @author Qinii
  53. * @day 2020-10-28
  54. */
  55. public function create($id)
  56. {
  57. // if($this->userInfo->user_type == 'wechat' && !$this->userInfo->subscribe){
  58. // return app('json')->fail('请先关注公众号');
  59. // }
  60. $data = $this->repository->create($id,$this->request->uid());
  61. return app('json')->success($data);
  62. }
  63. /**
  64. * TODO 帮好友助力
  65. * @param $id
  66. * @return mixed
  67. * @author Qinii
  68. * @day 2020-10-28
  69. */
  70. public function set($id)
  71. {
  72. $this->repository->set($id,$this->userInfo);
  73. return app('json')->success('助力成功');
  74. }
  75. public function delete($id)
  76. {
  77. $res = $this->repository->getWhere(['product_assist_set_id' => $id,'uid' => $this->request->uid(),'is_del' => 0]);
  78. if(!$res)return app('json')->fail('信息错误');
  79. $this->repository->update($id,['is_del' => 1]);
  80. return app('json')->success('取消成功');
  81. }
  82. /**
  83. * TODO 助力列表
  84. * @param $id
  85. * @param ProductAssistUserRepository $repository
  86. * @return mixed
  87. * @author Qinii
  88. * @day 2020-10-28
  89. */
  90. public function userList($id,ProductAssistUserRepository $repository)
  91. {
  92. [$page, $limit] = $this->getPage();
  93. $where['product_assist_set_id'] = $id;
  94. if(!$this->repository->get($id)) return app('json')->fail('数据丢失');
  95. return app('json')->success($repository->userList($where,$page, $limit));
  96. }
  97. public function shareNum($id)
  98. {
  99. $this->repository->incNum(1,$id);
  100. return app('json')->success('oks');
  101. }
  102. }