MerchantApplyments.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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\validate\merchant\MerchantApplymentsValidate;
  13. use think\App;
  14. use think\facade\Config;
  15. use think\facade\Queue;
  16. use crmeb\basic\BaseController;
  17. use app\common\repositories\system\merchant\MerchantApplymentsRepository;
  18. class MerchantApplyments 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, MerchantApplymentsRepository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. }
  34. /**
  35. * 创建申请
  36. * @param MerchantApplymentsValidate $validate
  37. * @return \think\response\Json
  38. * @author Qinii
  39. * @day 6/22/21
  40. */
  41. public function create(MerchantApplymentsValidate $validate)
  42. {
  43. if(!systemConfig('open_wx_sub_mch')) return app('json')->fail('未开启子商户入驻');
  44. $data = $this->checkParams($validate);
  45. $this->repository->create($data,$this->request->merId());
  46. return app('json')->success('申请提交成功');
  47. }
  48. /**
  49. * 获取商家详情
  50. *
  51. * @return \think\response\Json
  52. */
  53. public function detail()
  54. {
  55. // 获取商家ID
  56. $merId = $this->request->merId();
  57. // 调用仓库方法获取商家详情
  58. $data = $this->repository->detail($merId);
  59. // 添加开通微信子商户配置项
  60. $data['open_wx_sub_mch'] = systemConfig('open_wx_sub_mch');
  61. // 返回JSON格式的成功响应
  62. return app('json')->success($data);
  63. }
  64. public function update($id, MerchantApplymentsValidate $validate)
  65. {
  66. if (!systemConfig('open_wx_sub_mch')) return app('json')->fail('未开启子商户入驻');
  67. // 校验参数
  68. $data = $this->checkParams($validate);
  69. // 删除ID字段
  70. unset($data['id']);
  71. $this->repository->edit($id, $data);
  72. return app('json')->success('编辑提交成功');
  73. }
  74. /**
  75. * 查询商家状态
  76. *
  77. * @return \think\response\Json
  78. */
  79. public function check()
  80. {
  81. $mer_id = $this->request->merId();
  82. // 调用仓库方法查询商家状态
  83. $this->repository->check($mer_id);
  84. return app('json')->success('查询状态已更新');
  85. }
  86. /**
  87. * 上传图片
  88. * @param string $field 上传图片的字段名
  89. * @return \think\response\Json
  90. */
  91. public function uploadImage($field)
  92. {
  93. // 获取上传的文件
  94. $file = $this->request->file($field);
  95. // 获取水印参数
  96. $water = $this->request->param('water');
  97. // 如果没有上传文件则返回错误信息
  98. if (!$file) return app('json')->fail('请上传图片');
  99. // 如果上传的是数组则只取第一个元素
  100. $file = is_array($file) ? $file[0] : $file;
  101. // 验证上传的文件是否符合要求
  102. validate(["$field|图片" => [
  103. 'fileSize' => config('upload.filesize'),
  104. 'fileExt' => 'jpg,jpeg,png,bmp,gif',
  105. 'fileMime' => 'image/jpeg,image/png,image/gif',
  106. function ($file) {
  107. $ext = $file->extension();
  108. if ($ext != strtolower($file->extension())) {
  109. return '图片后缀必须为小写';
  110. }
  111. return true;
  112. }
  113. ]])->check([$field => $file]);
  114. // 调用仓库的上传图片方法
  115. $res = $this->repository->uploadImage($field, $water);
  116. // 返回上传结果
  117. return app('json')->success($res);
  118. }
  119. /**
  120. * 校验参数
  121. * @param MerchantApplymentsValidate $validate 验证器实例
  122. * @return array 校验通过的参数数组
  123. */
  124. public function checkParams(MerchantApplymentsValidate $validate)
  125. {
  126. //'organization_cert_info',
  127. // 获取需要校验的参数
  128. $data = $this->request->params([
  129. 'organization_type', 'business_license_info', 'id_doc_type', 'id_card_info', 'id_doc_info', 'need_account_info', 'account_info', 'contact_info', 'sales_scene_info', 'merchant_shortname', 'qualifications', 'business_addition_pics', 'business_addition_desc'
  130. ]);
  131. // 根据不同的身份证类型删除对应的参数
  132. if ($data['id_doc_type'] == 1) {
  133. unset($data['id_doc_info']);
  134. } else {
  135. unset($data['id_card_info']);
  136. }
  137. // 如果机构类型为2401或2500则删除商业营业执照和组织机构代码证
  138. if (in_array($data['organization_type'], ['2401', '2500'])) {
  139. unset($data['business_license_info']);
  140. // unset($data['organization_cert_info']);
  141. }
  142. // if(isset($data['organization_cert_info']) && !is_array($data['organization_cert_info'])) unset($data['organization_cert_info']);
  143. if (isset($data['qualifications']) && !$data['qualifications']) unset($data['qualifications']);
  144. if (isset($data['business_addition_pics']) && !$data['business_addition_pics']) unset($data['business_addition_pics']);
  145. if ($data['organization_type'] !== 2 && isset($data['id_card_info']['id_card_address'])) {
  146. unset($data['id_card_info']['id_card_address']);
  147. }
  148. $validate->check($data);
  149. return $data;
  150. }
  151. }