Merchant.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\operate\OperateLogRepository;
  16. use app\common\repositories\system\serve\ServeOrderRepository;
  17. use app\common\repositories\user\UserBillRepository;
  18. use app\validate\merchant\MerchantTakeValidate;
  19. use crmeb\basic\BaseController;
  20. use app\common\repositories\system\merchant\MerchantRepository;
  21. use app\validate\merchant\MerchantUpdateValidate;
  22. use crmeb\jobs\ChangeMerchantStatusJob;
  23. use crmeb\services\ImageWaterMarkService;
  24. use crmeb\services\UploadService;
  25. use think\App;
  26. use think\facade\Queue;
  27. /**
  28. * Class Merchant
  29. * @package app\controller\merchant\system
  30. * @author xaboy
  31. * @day 2020/6/25
  32. */
  33. class Merchant extends BaseController
  34. {
  35. /**
  36. * @var MerchantRepository
  37. */
  38. protected $repository;
  39. /**
  40. * Merchant constructor.
  41. * @param App $app
  42. * @param MerchantRepository $repository
  43. */
  44. public function __construct(App $app, MerchantRepository $repository)
  45. {
  46. parent::__construct($app);
  47. $this->repository = $repository;
  48. }
  49. /**
  50. * 更新表单
  51. *
  52. * @return \Illuminate\Http\JsonResponse
  53. */
  54. public function updateForm()
  55. {
  56. // 调用 formToData 方法将表单转换为数据并返回成功响应
  57. return app('json')->success(formToData($this->repository->merchantForm($this->request->merchant()->toArray())));
  58. }
  59. /**
  60. * 更新商家信息
  61. *
  62. * @param MerchantUpdateValidate $validate 商家更新验证器
  63. * @param MerchantTakeValidate $takeValidate 商家配送验证器
  64. * @param MerchantTakeRepository $repository 商家配送仓库
  65. * @return \think\response\Json
  66. */
  67. public function update(MerchantUpdateValidate $validate, MerchantTakeValidate $takeValidate, MerchantTakeRepository $repository)
  68. {
  69. $type = $this->request->param('type', 1);
  70. // 获取当前登录的商家信息
  71. $merchant = $this->request->merchant();
  72. // 如果 type 为 2,则表示更新商家配送信息
  73. if ($type == 2) {
  74. // 获取请求参数中的指定字段
  75. $data = $this->request->params([
  76. 'mer_info',
  77. 'mer_certificate',
  78. 'service_phone',
  79. 'mer_avatar',
  80. 'mer_banner',
  81. 'mer_state',
  82. 'mini_banner',
  83. 'mer_keyword',
  84. 'mer_address',
  85. 'long',
  86. 'lat',
  87. ['delivery_way', [2]],
  88. ['services_type', 0],
  89. ]);
  90. // 对获取到的数据进行验证
  91. $validate->check($data);
  92. // 判断系统配置中的 sys_bases_status 是否为 0,如果是,则将 $sys_bases_status 设为 0,否则设为 1
  93. $sys_bases_status = systemConfig('sys_bases_status') === '0' ? 0 : 1;
  94. // 如果 $sys_bases_status 为 true,并且 $data['mer_certificate'] 为空,则返回错误信息
  95. if ($sys_bases_status && empty($data['mer_certificate']))
  96. return app('json')->fail('店铺资质不可为空');
  97. // 调用 ConfigValueRepository 类的 setFormData 方法,将 $data['mer_certificate'] 和 $data['services_type'] 存储到数据库中
  98. app()->make(ConfigValueRepository::class)->setFormData([
  99. 'mer_certificate' => $data['mer_certificate'],
  100. 'services_type' => $data['services_type']
  101. ], $this->request->merId());
  102. // 删除 $data 数组中的 mer_certificate 和 services_type 两个元素
  103. unset($data['mer_certificate'], $data['services_type']);
  104. foreach ($data['delivery_way'] as $datum) {
  105. if ($datum == 1) {
  106. $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']);
  107. $takeValidate->check($takeData);
  108. $repository->set($this->request->merId(), $takeData);
  109. break;
  110. }
  111. }
  112. $delivery_way = implode(',', $data['delivery_way']);
  113. if (count((array)$data['delivery_way']) == 1 && $data['delivery_way'] != $merchant->delivery_way) {
  114. app()->make(ProductRepository::class)->getSearch([])
  115. ->where('mer_id', $merchant->mer_id)
  116. ->update(['delivery_way' => $delivery_way]);
  117. }
  118. $data['delivery_way'] = $delivery_way;
  119. } else {
  120. $data = $this->request->params(['mer_state']);
  121. if ($merchant->is_margin == 1 && $data['mer_state'] == 1)
  122. return app('json')->fail('开启店铺前请先支付保证金');
  123. if ($data['mer_state'] && !$merchant->sub_mchid && systemConfig('open_wx_combine'))
  124. return app('json')->fail('开启店铺前请先完成微信子商户入驻');
  125. }
  126. $merchant->save($data);
  127. // 商户编辑记录日志
  128. event('create_operate_log', [
  129. 'category' => OperateLogRepository::MERCHANT_EDIT_AUDIT_STATUS,
  130. 'data' => [
  131. 'merchant' => $merchant,
  132. 'admin_info' => $this->request->adminInfo(),
  133. 'update_infos' => ['status' => $data['mer_state']]
  134. ],
  135. ]);
  136. Queue::push(ChangeMerchantStatusJob::class, $this->request->merId());
  137. return app('json')->success('修改成功');
  138. }
  139. /**
  140. * 获取商户信息详情
  141. * @return mixed
  142. * @author xaboy
  143. * @day 2020/7/21
  144. */
  145. public function info(MerchantTakeRepository $repository)
  146. {
  147. $merchant = $this->request->merchant();
  148. $adminInfo = $this->request->adminInfo();
  149. $append = ['merchantCategory', 'merchantType', 'mer_certificate','margin_remind_status'];
  150. if ($merchant->is_margin == -10)
  151. $append[] = 'refundMarginOrder';
  152. $data = $merchant->append($append)->hidden(['mark', 'reg_admin_id', 'sort'])->toArray();
  153. $delivery = $repository->get($this->request->merId()) + systemConfig(['tx_map_key']);
  154. $data = array_merge($data,$delivery);
  155. $data['sys_bases_status'] = systemConfig('sys_bases_status') === '0' ? 0 : 1;
  156. $data['services_type'] = (int)merchantConfig((int)$merchant->mer_id,'services_type');
  157. $data['customer_corpId'] = merchantConfig((int)$merchant->mer_id,'customer_corpId');
  158. $data['customer_url'] = merchantConfig((int)$merchant->mer_id,'customer_url');
  159. $data['mer_account'] = $adminInfo['account'];
  160. return app('json')->success($data);
  161. }
  162. /**
  163. * 获取商家提现信息
  164. *
  165. * @param MerchantTakeRepository $repository 商家提现仓库
  166. * @return mixed
  167. */
  168. public function takeInfo(MerchantTakeRepository $repository)
  169. {
  170. // 获取商家ID
  171. $merId = $this->request->merId();
  172. // 调用仓库的get方法获取商家提现信息并加上系统配置中的tx_map_key
  173. return app('json')->success($repository->get($merId) + systemConfig(['tx_map_key']));
  174. }
  175. /**
  176. * 设置商家提现信息
  177. *
  178. * @param MerchantTakeValidate $validate 商家提现验证器
  179. * @param MerchantTakeRepository $repository 商家提现仓库
  180. * @return mixed
  181. */
  182. public function take(MerchantTakeValidate $validate, MerchantTakeRepository $repository)
  183. {
  184. $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']);
  185. // 验证商家提现信息
  186. $validate->check($data);
  187. // 调用仓库的set方法设置商家提现信息
  188. $repository->set($this->request->merId(), $data);
  189. // 返回设置成功的消息
  190. return app('json')->success('设置成功');
  191. }
  192. /**
  193. * 获取边距二维码
  194. *
  195. * @return \think\response\Json
  196. */
  197. public function getMarginQrCode()
  198. {
  199. // 设置支付类型为1
  200. $data['pay_type'] = 1;
  201. $data['type'] = $this->request->param('type', 10);
  202. // 调用 ServeOrderRepository 类的 QrCode 方法生成二维码
  203. $res = app()->make(ServeOrderRepository::class)->QrCode($this->request->merId(), 'margin', $data);
  204. // 返回生成的二维码
  205. return app('json')->success($res);
  206. }
  207. /**
  208. * 获取边距列表
  209. *
  210. * @return \think\response\Json
  211. */
  212. public function getMarginLst()
  213. {
  214. // 获取分页参数
  215. [$page, $limit] = $this->getPage();
  216. // 设置查询条件
  217. $where = [
  218. 'mer_id' => $this->request->merId(),
  219. 'category' => 'mer_margin'
  220. ];
  221. // 调用 UserBillRepository 类的 getLst 方法获取列表数据
  222. $data = app()->make(UserBillRepository::class)->getLst($where, $page, $limit);
  223. // 返回列表数据
  224. return app('json')->success($data);
  225. }
  226. }