UserMerchant.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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\merchant\user;
  12. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  13. use app\common\repositories\store\order\StoreOrderRepository;
  14. use app\common\repositories\user\UserLabelRepository;
  15. use app\common\repositories\user\UserMerchantRepository;
  16. use crmeb\basic\BaseController;
  17. use FormBuilder\Exception\FormBuilderException;
  18. use think\App;
  19. use think\db\exception\DataNotFoundException;
  20. use think\db\exception\DbException;
  21. use think\db\exception\ModelNotFoundException;
  22. /**
  23. * Class UserMerchant
  24. * @package app\controller\merchant\user
  25. * @author xaboy
  26. * @day 2020/10/20
  27. */
  28. class UserMerchant extends BaseController
  29. {
  30. /**
  31. * @var UserMerchantRepository
  32. */
  33. protected $repository;
  34. /**
  35. * UserMerchant constructor.
  36. * @param App $app
  37. * @param UserMerchantRepository $repository
  38. */
  39. public function __construct(App $app, UserMerchantRepository $repository)
  40. {
  41. parent::__construct($app);
  42. $this->repository = $repository;
  43. }
  44. /**
  45. * @return \think\response\Json
  46. * @author xaboy
  47. * @day 2020/10/20
  48. */
  49. public function getList()
  50. {
  51. $where = $this->request->params(['nickname', 'sex', 'is_promoter', 'user_time_type', 'user_time', 'pay_count', 'label_id', 'user_type']);
  52. [$page, $limit] = $this->getPage();
  53. $where['mer_id'] = $this->request->merId();
  54. return app('json')->success($this->repository->getList($where, $page, $limit));
  55. }
  56. /**
  57. * @param $id
  58. * @return mixed
  59. * @throws DataNotFoundException
  60. * @throws DbException
  61. * @throws FormBuilderException
  62. * @throws ModelNotFoundException
  63. * @author xaboy
  64. * @day 2020-05-08
  65. */
  66. public function changeLabelForm($id)
  67. {
  68. if (!$this->repository->exists($id))
  69. return app('json')->fail('数据不存在');
  70. return app('json')->success(formToData($this->repository->changeLabelForm($this->request->merId(), $id)));
  71. }
  72. /**
  73. * @param $id
  74. * @param UserLabelRepository $labelRepository
  75. * @return mixed
  76. * @throws DbException
  77. * @author xaboy
  78. * @day 2020-05-08
  79. */
  80. public function changeLabel($id, UserLabelRepository $labelRepository)
  81. {
  82. $label_id = (array)$this->request->param('label_id', []);
  83. if (!$this->repository->exists($id))
  84. return app('json')->fail('数据不存在');
  85. $merId = $this->request->merId();
  86. $label_id = $labelRepository->intersection((array)$label_id, $merId, 0);
  87. $label_id = array_unique(array_merge($label_id, $this->repository->get($id)->authLabel));
  88. $label_id = implode(',', $label_id);
  89. $this->repository->update($id, compact('label_id'));
  90. return app('json')->success('修改成功');
  91. }
  92. public function order($uid)
  93. {
  94. [$page, $limit] = $this->getPage();
  95. $data = app()->make(StoreOrderRepository::class)->userMerList($uid, $this->request->merId(), $page, $limit);
  96. return app('json')->success($data);
  97. }
  98. public function coupon($uid)
  99. {
  100. [$page, $limit] = $this->getPage();
  101. $data = app()->make(StoreCouponUserRepository::class)->userList(['mer_id' => $this->request->merId(), 'uid' => (int)$uid], $page, $limit);
  102. return app('json')->success($data);
  103. }
  104. }