Merchant.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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\system;
  12. use app\common\repositories\store\MerchantTakeRepository;
  13. use app\common\repositories\store\product\ProductRepository;
  14. use app\common\repositories\system\config\ConfigValueRepository;
  15. use app\common\repositories\system\serve\ServeOrderRepository;
  16. use app\common\repositories\user\UserBillRepository;
  17. use app\validate\merchant\MerchantTakeValidate;
  18. use crmeb\basic\BaseController;
  19. use app\common\repositories\system\merchant\MerchantRepository;
  20. use app\validate\merchant\MerchantUpdateValidate;
  21. use crmeb\jobs\ChangeMerchantStatusJob;
  22. use think\App;
  23. use think\facade\Queue;
  24. /**
  25. * Class Merchant
  26. * @package app\controller\merchant\system
  27. * @author xaboy
  28. * @day 2020/6/25
  29. */
  30. class Merchant extends BaseController
  31. {
  32. /**
  33. * @var MerchantRepository
  34. */
  35. protected $repository;
  36. /**
  37. * Merchant constructor.
  38. * @param App $app
  39. * @param MerchantRepository $repository
  40. */
  41. public function __construct(App $app, MerchantRepository $repository)
  42. {
  43. parent::__construct($app);
  44. $this->repository = $repository;
  45. }
  46. /**
  47. * @return mixed
  48. * @throws \FormBuilder\Exception\FormBuilderException
  49. * @author xaboy
  50. * @day 2020/6/25
  51. */
  52. public function updateForm()
  53. {
  54. return app('json')->success(formToData($this->repository->merchantForm($this->request->merchant()->toArray())));
  55. }
  56. /**
  57. * @param MerchantUpdateValidate $validate
  58. * @return mixed
  59. * @author xaboy
  60. * @day 2020/6/25
  61. */
  62. public function update(MerchantUpdateValidate $validate, MerchantTakeValidate $takeValidate, MerchantTakeRepository $repository)
  63. {
  64. $type = $this->request->param('type',1);
  65. $merchant = $this->request->merchant();
  66. if ($type == 2) {
  67. $data = $this->request->params([
  68. 'mer_info',
  69. 'mer_certificate',
  70. 'service_phone',
  71. 'mer_avatar',
  72. 'mer_banner',
  73. 'mer_state',
  74. 'mini_banner',
  75. 'mer_keyword',
  76. 'mer_address',
  77. 'long',
  78. 'lat',
  79. ['delivery_way',[2]],
  80. ]);
  81. $validate->check($data);
  82. $sys_bases_status = systemConfig('sys_bases_status') === '0' ? 0 : 1;
  83. if ($sys_bases_status && empty($data['mer_certificate']))
  84. return app('json')->fail('店铺资质不可为空');
  85. app()->make(ConfigValueRepository::class)->setFormData([
  86. 'mer_certificate' => $data['mer_certificate']
  87. ], $this->request->merId());
  88. unset($data['mer_certificate']);
  89. foreach ($data['delivery_way'] as $datum) {
  90. if ($datum == 1) {
  91. $takeData = $this->request->params(['mer_take_status', 'mer_take_name', 'mer_take_phone', 'mer_take_address', 'mer_take_location', 'mer_take_day', 'mer_take_time']);
  92. $takeValidate->check($takeData);
  93. $repository->set($this->request->merId(), $takeData);
  94. break;
  95. }
  96. }
  97. $delivery_way = implode(',',$data['delivery_way']);
  98. if (count($data['delivery_way']) == 1 && $data['delivery_way'] != $merchant->delivery_way) {
  99. app()->make(ProductRepository::class)->getSearch([])
  100. ->where('mer_id',$merchant->mer_id)
  101. ->update(['delivery_way' => $delivery_way]);
  102. }
  103. $data['delivery_way'] = $delivery_way;
  104. } else {
  105. $data = $this->request->params(['mer_state']);
  106. if ($merchant->is_margin == 1 && $data['mer_state'] == 1)
  107. return app('json')->fail('开启店铺前请先支付保证金');
  108. if ($data['mer_state'] && !$merchant->sub_mchid && systemConfig('open_wx_combine'))
  109. return app('json')->fail('开启店铺前请先完成微信子商户入驻');
  110. }
  111. $merchant->save($data);
  112. Queue::push(ChangeMerchantStatusJob::class, $this->request->merId());
  113. return app('json')->success('修改成功');
  114. }
  115. /**
  116. * @return mixed
  117. * @author xaboy
  118. * @day 2020/7/21
  119. */
  120. public function info(MerchantTakeRepository $repository)
  121. {
  122. $merchant = $this->request->merchant();
  123. $append = ['merchantCategory', 'merchantType', 'mer_certificate'];
  124. if ($merchant->is_margin == -10)
  125. $append[] = 'refundMarginOrder';
  126. $data = $merchant->append($append)->hidden(['mark', 'reg_admin_id', 'sort'])->toArray();
  127. $delivery = $repository->get($this->request->merId()) + systemConfig(['tx_map_key']);
  128. $data = array_merge($data,$delivery);
  129. $data['sys_bases_status'] = systemConfig('sys_bases_status') === '0' ? 0 : 1;
  130. return app('json')->success($data);
  131. }
  132. /**
  133. * @param MerchantTakeRepository $repository
  134. * @return mixed
  135. * @author xaboy
  136. * @day 2020/8/1
  137. */
  138. public function takeInfo(MerchantTakeRepository $repository)
  139. {
  140. $merId = $this->request->merId();
  141. return app('json')->success($repository->get($merId) + systemConfig(['tx_map_key']));
  142. }
  143. /**
  144. * @param MerchantTakeValidate $validate
  145. * @param MerchantTakeRepository $repository
  146. * @return mixed
  147. * @author xaboy
  148. * @day 2020/8/1
  149. */
  150. public function take(MerchantTakeValidate $validate, MerchantTakeRepository $repository)
  151. {
  152. $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']);
  153. $validate->check($data);
  154. $repository->set($this->request->merId(), $data);
  155. return app('json')->success('设置成功');
  156. }
  157. public function getMarginQrCode()
  158. {
  159. $data['pay_type'] = 1;
  160. $res = app()->make(ServeOrderRepository::class)->QrCode($this->request->merId(), 'margin', $data);
  161. return app('json')->success($res);
  162. }
  163. public function getMarginLst()
  164. {
  165. [$page, $limit] = $this->getPage();
  166. $where = [
  167. 'mer_id' => $this->request->merId(),
  168. 'category' => 'mer_margin'
  169. ];
  170. $data = app()->make(UserBillRepository::class)->getLst($where, $page, $limit);
  171. return app('json')->success($data);
  172. }
  173. }