diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index 3d859e62..dcb9c582 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -46,6 +46,13 @@ class MerchantIntention extends BaseController return app('json')->fail('未开启商户入驻'); } if ($this->userInfo) $data['uid'] = $this->userInfo->uid; + if ($this->userInfo->phone && ($this->userInfo->phone != $data['phone'] ?? '')) { + throw new ValidateException('联系电话和注册手机不一致'); + } + $intentionInfo = Db::name('merchant_intention')->where('social_credit_code', $data['social_credit_code'])->where('status', '<>', 2)->find(); + if ($intentionInfo) { + throw new ValidateException('此统一社会信用代码已申请商户'); + } $merInfo = Db::name('merchant')->where('uid', $this->userInfo->uid)->where('status', 1)->find(); if ($merInfo) { throw new ValidateException('该用户已存在商户,不可申请'); @@ -69,7 +76,7 @@ class MerchantIntention extends BaseController ]); $areaInfo = Db::name('geo_area')->where('area_code', $data['area_id'] ?? '')->find(); $sendData = [ - 'company_name' => $data['mer_name'], + 'company_name' => $data['company_name'] ?? '', 'organization_code' => $data['social_credit_code'] ?? '', 'master_name' => $data['name'], 'master_phone' => $data['phone'], @@ -77,6 +84,7 @@ class MerchantIntention extends BaseController 'city' => $areaInfo['city_code'] ?? '', 'area' => $data['area_id'] ?? '', 'street' => $data['street_id'] ?? '', + 'address' => $data['address'] ?? '', 'mer_intention_id' => $intention->mer_intention_id ]; $res = $this->sendMerIntentionApply($sendData); @@ -118,15 +126,32 @@ class MerchantIntention extends BaseController public function update($id) { - if (!$this->repository->getWhere(['mer_intention_id' => (int)$id, 'uid' => $this->userInfo->uid, 'is_del' => 0])) + $merIntentionInfo = $this->repository->getWhere(['mer_intention_id' => (int)$id, 'uid' => $this->userInfo->uid, 'is_del' => 0]); + if (!$merIntentionInfo) return app('json')->fail('数据不存在'); + if ($merIntentionInfo['status']) { + return app('json')->fail('已审核数据不能修改'); + } $data = $this->checkParams(); if (!systemConfig('mer_intention_open')) { return app('json')->fail('未开启商户入驻'); } + if ($this->userInfo->phone && ($this->userInfo->phone != $data['phone'] ?? '')) { + throw new ValidateException('联系电话和注册手机不一致'); + } + $intentionInfo = Db::name('merchant_intention')->where('social_credit_code', $data['social_credit_code'])->where('status', '<>', 2)->find(); + if ($intentionInfo) { + throw new ValidateException('此统一社会信用代码已申请商户'); + } if (!empty($data['mer_phone'])) { unset($data['mer_phone']); } + $make = app()->make(MerchantRepository::class); + if ($make->fieldExists('mer_name', $data['mer_name'])) + throw new ValidateException('商户名称已存在,不可申请'); + $adminRepository = app()->make(MerchantAdminRepository::class); + if ($adminRepository->fieldExists('account', $data['phone'])) + throw new ValidateException('手机号已是管理员,不可申请'); $data['create_time'] = date('Y-m-d H:i:s', time()); $this->repository->updateIntention((int)$id, $data); SwooleTaskService::admin('notice', [ @@ -139,7 +164,7 @@ class MerchantIntention extends BaseController ]); $areaInfo = Db::name('geo_area')->where('area_code', $data['area_id'] ?? '')->find(); $sendData = [ - 'company_name' => $data['mer_name'], + 'company_name' => $data['company_name'] ?? '', 'organization_code' => $data['social_credit_code'] ?? '', 'master_name' => $data['name'], 'master_phone' => $data['phone'], @@ -147,6 +172,7 @@ class MerchantIntention extends BaseController 'city' => $areaInfo['city_code'] ?? '', 'area' => $data['area_id'] ?? '', 'street' => $data['street_id'] ?? '', + 'address' => $data['address'] ?? '', 'mer_intention_id' => $id ]; $res = $this->sendMerIntentionApply($sendData); @@ -179,7 +205,9 @@ class MerchantIntention extends BaseController { $data = $this->request->params([ 'phone', - 'mer_name', + 'mer_name', + 'company_name', + 'address', 'name', 'code', 'images',