From 407a7bf21d0be117b470179d84a7b674cf9c76f6 Mon Sep 17 00:00:00 2001 From: zwesy Date: Thu, 2 Dec 2021 10:49:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=95=86=E5=AE=B6=E8=AE=A4=E8=AF=81=E6=8E=A5=E5=8F=A3=E4=B8=BA?= =?UTF-8?q?1=E4=B8=AA=E7=BB=9F=E4=B8=80=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/Business.php | 124 ++++-------------------------- app/model/Business.php | 13 +--- app/validate/BusinessValidate.php | 10 +-- 3 files changed, 17 insertions(+), 130 deletions(-) diff --git a/app/controller/api/Business.php b/app/controller/api/Business.php index 3712ab1..df2527c 100644 --- a/app/controller/api/Business.php +++ b/app/controller/api/Business.php @@ -18,14 +18,11 @@ use app\model\Business as BusinessModel; class Business extends Base { /** - * 商家注册 - * - * 方式1:注册为自然商家 - * 由系统后台工作人员审核 + * 商家认证注册 * * 重新编辑注册则覆盖之前的审核信息,并重新进行审核 */ - public function registerByNormal() + public function registerBusiness() { $params = [ 'type'=> $this->request->param('type/d', 0), @@ -41,6 +38,7 @@ class Business extends Base 'county'=> $this->request->param('county', ''), 'business_address' => $this->request->param('business_address', ''), 'business_circle_id' => $this->request->param('business_circle_id/d', 0), + 'agency_code' => $this->request->param('agency_code', ''), ]; $accountId = $this->request->user['user_id'] ?? 0; @@ -57,7 +55,7 @@ class Business extends Base throw new ValidateException('无效请求!'); } - if (!$validate->scene('registerByNormal')->check($params)) { + if (!$validate->scene('apiRegister')->check($params)) { throw new ValidateException($validate->getError()); } @@ -74,6 +72,15 @@ class Business extends Base $params['business_circle'] = $businessCircle['name']; } + if (!empty($params['agency_code'])) { + $agencyBusiness = $busRepo->findOneByWhere(['code'=> $params['agency_code'], 'is_agency'=> self::BOOL_TRUE, 'state' => BusinessModel::state_on]); + if (empty($agencyBusiness) || $agencyBusiness['is_delete'] == self::BOOL_TRUE) { + throw new ValidateException('没有相关的代理商记录!'); + } elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) { + throw new ValidateException('该代理商已被封禁!'); + } + } + $business = null; if (isset($account['business_code']) && !empty($account['business_code'])) { $business = $busRepo->findOneByWhere(['code'=> $account['business_code']]); @@ -115,110 +122,5 @@ class Business extends Base } } - /** - * 商家注册 - * - * 方式2:注册为平台代理商下的商家 - * 由平台代理商工作人员审核 - * - * 重新编辑注册则覆盖之前的审核信息,并重新进行审核 - */ - public function registerByAgency() - { - $params = [ - 'type'=> $this->request->param('type/d', 0), - 'business_name'=> $this->request->param('business_name', ''), - 'business_subtitle'=> $this->request->param('business_subtitle', ''), - 'business_license'=> $this->request->param('business_license', ''), - 'contact_name'=> $this->request->param('contact_name', ''), - 'contact_phone'=> $this->request->param('contact_phone', ''), - 'lat'=> $this->request->param('lat', ''), - 'lng'=> $this->request->param('lng', ''), - 'province'=> $this->request->param('province', ''), - 'city'=> $this->request->param('city', ''), - 'county'=> $this->request->param('county', ''), - 'business_address' => $this->request->param('business_address', ''), - 'business_circle_id' => $this->request->param('business_circle_id/d', 0), - 'agency_code' => $this->request->param('agency_code', ''), - ]; - - $accountId = $this->request->user['user_id'] ?? 0; - - try { - $validate = new BusinessValidate(); - $busRepo = BusinessRepository::getInstance(); - $dicRepo = DictionaryRepository::getInstance(); - $accountRepo = AccountRepository::getInstance(); - - $account = $accountRepo->findById($accountId); - if (empty($account)) { - throw new ValidateException('无效请求!'); - } - - if (!$validate->scene('registerByAgency')->check($params)) { - throw new ValidateException($validate->getError()); - } - - $businessCategory = $dicRepo->findBusinessTypeById($params['type']); - if (empty($businessCategory)) { - throw new ValidateException('请选择正确的商家分类信息!'); - } - - if ($params['business_circle_id'] > 0) { - $businessCircle = $dicRepo->findBusinessCircleById($params['business_circle_id']); - if (empty($businessCircle)) { - throw new ValidateException('请选择正确的商圈信息!'); - } - $params['business_circle'] = $businessCircle['name']; - } - - $agencyBusiness = $busRepo->findOneByWhere(['code'=> $params['agency_code'], 'is_agency'=> self::BOOL_TRUE, 'state' => BusinessModel::state_on]); - if (empty($agencyBusiness) || $agencyBusiness['is_delete'] == self::BOOL_TRUE) { - throw new ValidateException('没有相关的平台商记录!'); - } elseif ($agencyBusiness['enable'] == self::BOOL_TRUE) { - throw new ValidateException('该平台商已被封禁!'); - } - - $business = null; - if (isset($account['business_code']) && !empty($account['business_code'])) { - $business = $busRepo->findOneByWhere(['code'=> $account['business_code']]); - } - - $params['create_time'] = date('Y-m-d H:i:s'); - $params['is_delete'] = 0; - $params['state'] = BusinessModel::state_reviewing; - $params['enable'] = 0; - $params['type_name'] = $businessCategory['name']; - - if ($business) { - if ($business['state'] == BusinessModel::state_reviewing) { - throw new ValidateException('商户认证审批中,请勿重复提交!'); - } - - // 更新审批信息,重新审批 - $params['update_time'] = date('Y-m-d H:i:s'); - $business = $business->save($params); - - } else { - // 添加审批记录 - $businessCode = createUuid(); - $params['code'] = $businessCode; - $business = $busRepo->create($params); - if (!$business) { - throw new RepositoryException('服务器繁忙!商户认证申请提交失败!'); - } - - $account->save(['business_code' => $businessCode]); - } - - $result = $busRepo->formatFrontBusinessInfo($business->toArray(), [2]); - return $this->json(0, 'success', $result); - } catch (ValidateException $e) { - return $this->json(4001, $e->getError()); - } catch (RepositoryException | \Exception $e) { - return $this->json(5001, '服务器繁忙!商户认证申请提交失败!'); - } - } - } \ No newline at end of file diff --git a/app/model/Business.php b/app/model/Business.php index e3707cf..c9a57ac 100644 --- a/app/model/Business.php +++ b/app/model/Business.php @@ -11,7 +11,7 @@ class Business extends Base const state_off = 2; /** - * @remarks 代理商、平台代理商、渠道商等词组均描述的是平台商,因此文案统一为【平台商】 + * @remarks 代理商、平台商、平台代理商、渠道商等词组均描述的是代理商,因此文案统一为【代理商】 */ public function category() @@ -19,20 +19,11 @@ class Business extends Base return $this->hasOne(Category::class, 'id',"type"); } - /** - * 关联的平台商 - * - * @return HasOne - */ - public function agency(): HasOne - { - return $this->hasOne(Business::class, 'agency_code', "code"); - } - public function account() { return $this->hasOne(Account::class, 'business_code',"code"); } + public function agency() { return $this->hasOne(self::class,"code","agency_code"); diff --git a/app/validate/BusinessValidate.php b/app/validate/BusinessValidate.php index ca97dfb..f5661d7 100644 --- a/app/validate/BusinessValidate.php +++ b/app/validate/BusinessValidate.php @@ -25,7 +25,6 @@ class BusinessValidate extends Validate 'background|商家背景图' => 'max:250', 'business_circle_id' => 'egt:0', - 'agency_code' => 'require|length:32', ]; protected $message = [ @@ -38,18 +37,13 @@ class BusinessValidate extends Validate 'lng.between' => '地址定位信息错误,请重新定位!', 'business_circle_id.egt' => '请选择所属商圈!', - 'agency_code.require' => '请选择需要加入的商家!', - 'agency_code.length' => '加入的商家参数错误!', ]; protected $scene = [ // 认证商家 - 'registerByNormal' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone', + 'apiRegister' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone', 'lat', 'lng', 'province', 'city', 'county', 'business_address', 'business_circle_id'], - // 加入平台代理商 - 'registerByAgency' => ['type', 'business_name', 'business_subtitle', 'business_license', 'contact_name', 'contact_phone', - 'lat', 'lng', 'province', 'city', 'county', 'business_address', 'business_circle_id', 'agency_code'], // 商家编辑可编辑资料(基本信息修改需要审核通过后才能变更) - 'apiEdit' => ['lat', 'lng', 'province', 'city', 'county', 'business_address', 'characteristic', 'background', 'business_circle_id'], + 'apiEdit' => ['lat', 'lng', 'province', 'city', 'county', 'business_address', 'characteristic', 'background', 'business_circle_id'], ]; } \ No newline at end of file