更新:调整商家认证接口为1个统一的接口

master
zwesy 2021-12-02 10:49:50 +08:00
parent 8caf23c5b1
commit 407a7bf21d
3 changed files with 17 additions and 130 deletions

View File

@ -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, '服务器繁忙!商户认证申请提交失败!');
}
}
}

View File

@ -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");

View File

@ -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'],
];
}