Merchant.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace app\controller\merchant\system;
  3. use app\common\repositories\store\MerchantTakeRepository;
  4. use app\common\repositories\system\config\ConfigValueRepository;
  5. use app\validate\merchant\MerchantTakeValidate;
  6. use ln\basic\BaseController;
  7. use app\common\repositories\system\merchant\MerchantRepository;
  8. use app\validate\merchant\MerchantUpdateValidate;
  9. use ln\jobs\ChangeMerchantStatusJob;
  10. use think\App;
  11. use think\facade\Queue;
  12. /**
  13. * Class Merchant
  14. * @package app\controller\merchant\system
  15. * @author zfy
  16. * @day 2020/6/25
  17. */
  18. class Merchant extends BaseController
  19. {
  20. /**
  21. * @var MerchantRepository
  22. */
  23. protected $repository;
  24. /**
  25. * Merchant constructor.
  26. * @param App $app
  27. * @param MerchantRepository $repository
  28. */
  29. public function __construct(App $app, MerchantRepository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. }
  34. /**
  35. * @return mixed
  36. * @throws \FormBuilder\Exception\FormBuilderException
  37. * @author zfy
  38. * @day 2020/6/25
  39. */
  40. public function updateForm()
  41. {
  42. return app('json')->success(formToData($this->repository->merchantForm($this->request->merchant()->toArray())));
  43. }
  44. /**
  45. * @param MerchantUpdateValidate $validate
  46. * @return mixed
  47. * @author zfy
  48. * @day 2020/6/25
  49. */
  50. public function update(MerchantUpdateValidate $validate)
  51. {
  52. $data = $this->request->params(['mer_info', 'mer_certificate', 'service_phone', 'mer_avatar', 'mer_banner', 'mer_state', 'mini_banner', 'mer_keyword', 'mer_address', 'long', 'lat']);
  53. $validate->check($data);
  54. app()->make(ConfigValueRepository::class)->setFormData([
  55. 'mer_certificate' => $data['mer_certificate']
  56. ], $this->request->merId());
  57. unset($data['mer_certificate']);
  58. $merchant = $this->request->merchant();
  59. if ($data['mer_state'] && !$merchant->sub_mchid && systemConfig('open_wx_combine')) {
  60. return app('json')->fail('开启店铺前请先完成微信子商户入驻');
  61. }
  62. $merchant->save($data);
  63. Queue::push(ChangeMerchantStatusJob::class, $this->request->merId());
  64. return app('json')->success('修改成功');
  65. }
  66. /**
  67. * @return mixed
  68. * @author zfy
  69. * @day 2020/7/21
  70. */
  71. public function info()
  72. {
  73. $merchant = $this->request->merchant();
  74. return app('json')->success($merchant->append(['merchantCategory', 'merchantType', 'mer_certificate'])->hidden(['mark', 'reg_admin_id', 'sort'])->toArray());
  75. }
  76. /**
  77. * @param MerchantTakeRepository $repository
  78. * @return mixed
  79. * @author zfy
  80. * @day 2020/8/1
  81. */
  82. public function takeInfo(MerchantTakeRepository $repository)
  83. {
  84. $merId = $this->request->merId();
  85. return app('json')->success($repository->get($merId) + systemConfig(['tx_map_key']));
  86. }
  87. /**
  88. * @param MerchantTakeValidate $validate
  89. * @param MerchantTakeRepository $repository
  90. * @return mixed
  91. * @author zfy
  92. * @day 2020/8/1
  93. */
  94. public function take(MerchantTakeValidate $validate, MerchantTakeRepository $repository)
  95. {
  96. $data = $this->request->params(['mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
  97. $validate->check($data);
  98. $repository->set($this->request->merId(), $data);
  99. return app('json')->success('设置成功');
  100. }
  101. }