diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 8c7f5351..2df4e11b 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -207,6 +207,7 @@ class Auth extends BaseController // 判断是否是商户,并且有没有完善信息 // 这里有点小问题以后要修改 $store_service = Db::name('store_service')->where('uid', $data['uid'])->find(); + if ($store_service) { $mer_arr = Db::name('merchant')->where('mer_id', $store_service['mer_id'])->where('is_del', 0)->field('type_id,mer_avatar,mer_banner,mer_info,category_id,service_phone,mer_address,uid,mer_name,create_time,update_time')->find(); if ($mer_arr && $mer_arr['mer_avatar'] != '' && $mer_arr['mer_banner'] != '' && $mer_arr['mer_info'] && $mer_arr['service_phone'] != '' && $mer_arr['mer_address'] != '') { @@ -215,7 +216,7 @@ class Auth extends BaseController $data['mer_info'] = $mer_arr; $typCode = Db::name('merchant_type')->where('mer_type_id', $mer_arr['type_id'] ?? 0)->value('type_code'); $data['mer_info']['type_code'] = $typCode; - if ($mer_arr['create_time'] == $mer_arr['update_time']) { + if (($mer_arr['create_time'] ?? '') == ($mer_arr['update_time'] ?? '')) { $data['mer_info']['setup_status'] = 0; } else { $data['mer_info']['setup_status'] = 1; @@ -1354,7 +1355,8 @@ class Auth extends BaseController //同步商户状态信息 public function merchantStatus($id) { - Log::info("接收到同步商户状态HOST:" . request()->url()); + Log::info("接收到同步商户状态HOST:" . request()->host() . request()->url()); + Log::info("接收到同步商户状态数据:" . json_encode(request()->param())); $repository = app()->make(MerchantIntentionRepository::class); if (!$repository->getWhereCount(['mer_intention_id' => $id, 'is_del' => 0])) return app('json')->fail('数据不存在'); diff --git a/app/controller/api/store/merchant/MerchantIntention.php b/app/controller/api/store/merchant/MerchantIntention.php index a96f5685..7dc1d59f 100644 --- a/app/controller/api/store/merchant/MerchantIntention.php +++ b/app/controller/api/store/merchant/MerchantIntention.php @@ -46,6 +46,14 @@ class MerchantIntention extends BaseController return app('json')->fail('未开启商户入驻'); } if ($this->userInfo) $data['uid'] = $this->userInfo->uid; + if (($this->userInfo->phone ?? false) && ($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('该用户已存在商户,不可申请'); @@ -68,16 +76,16 @@ class MerchantIntention extends BaseController ] ]); $areaInfo = Db::name('geo_area')->where('area_code', $data['area_id'] ?? '')->find(); - $cityId = Db::name('geo_city')->where('city_code', $areaInfo['city_code'] ?? '')->value('city_id', 0); - $streetId = Db::name('geo_street')->where('street_code', $data['street_id'] ?? '')->value('street_id', 0); $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'], - 'city' => $cityId, - 'area' => $areaInfo['area_id'] ?? 0, - 'street' => $streetId, + 'images' => !empty($data['images'])?json_encode($data['images']):'', + '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); @@ -119,15 +127,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 ?? false) && ($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', [ @@ -138,6 +163,23 @@ class MerchantIntention extends BaseController 'id' => $id ] ]); + $areaInfo = Db::name('geo_area')->where('area_code', $data['area_id'] ?? '')->find(); + $sendData = [ + 'company_name' => $data['company_name'] ?? '', + 'organization_code' => $data['social_credit_code'] ?? '', + 'master_name' => $data['name'], + 'master_phone' => $data['phone'], + 'images' => !empty($data['images'])?json_encode($data['images']):'', + 'city' => $areaInfo['city_code'] ?? '', + 'area' => $data['area_id'] ?? '', + 'street' => $data['street_id'] ?? '', + 'address' => $data['address'] ?? '', + 'mer_intention_id' => $id + ]; + $res = $this->sendMerIntentionApply($sendData); + if (!$res) { + throw new ValidateException('申请商户入驻任务失败,请联系平台'); + } return app('json')->success('修改成功'); } @@ -164,7 +206,9 @@ class MerchantIntention extends BaseController { $data = $this->request->params([ 'phone', - 'mer_name', + 'mer_name', + 'company_name', + 'address', 'name', 'code', 'images',