UserMerchant.php 3.3 KB

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