feat: 新增账号安全模块及资质校验功能
- 新增账号安全页面及支付密码验证组件 - 新增用户类型选择流程及商家资质管理 - 新增订单资质校验逻辑,师傅需满足订单证书要求 - 新增企业资质认证相关数据库表及接口 - 优化用户列表展示,区分个人与商家用户类型
这个提交包含在:
@@ -43,6 +43,9 @@ class Auth extends Base
|
||||
|
||||
if (!$user) {
|
||||
// 若数据库中无此手机号:直连数据库插入注册新会员
|
||||
if (!preg_match('/^\S{6,30}$/', $password)) {
|
||||
$this->error('登录密码须为6至30位非空字符');
|
||||
}
|
||||
$ret = $this->auth->register($mobile, $password, '', $mobile, []);
|
||||
if (!$ret) {
|
||||
$this->error($this->auth->getError() ?: '注册登录失败');
|
||||
@@ -54,9 +57,10 @@ class Auth extends Base
|
||||
if (empty($user['password'])) {
|
||||
$this->error('该账号尚未设置登录密码,请使用微信一键登录后设置密码');
|
||||
}
|
||||
$encryptPassword = $this->auth->getEncryptPassword($password, $user['salt']);
|
||||
if ($user['password'] !== $encryptPassword) {
|
||||
$this->error('手机号或密码不正确');
|
||||
try {
|
||||
\app\common\library\AccountSecurity::verify((int)$user['id'], 'login', $password);
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage() === '密码不正确' ? '手机号或密码不正确' : $e->getMessage());
|
||||
}
|
||||
$this->auth->direct($user['id']);
|
||||
}
|
||||
@@ -83,7 +87,7 @@ class Auth extends Base
|
||||
protected function profileData()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$user = Db::name('user')->field('id,nickname,mobile,email,avatar,money,score,user_type,contact_address,createtime')->where('id', $uid)->find();
|
||||
$user = Db::name('user')->field('id,nickname,mobile,email,avatar,money,score,user_type,identity_selected,company_name,company_legal_person,company_legal_mobile,company_tech_mobile,contact_address,createtime')->where('id', $uid)->find();
|
||||
$master = Db::name('master')->where('user_id', $uid)->find();
|
||||
|
||||
$couponCount = Db::name('user_coupon')->where('user_id', $uid)->where('status', 'unused')->count();
|
||||
@@ -152,13 +156,7 @@ class Auth extends Base
|
||||
'pending_verify' => $getCnt(7),
|
||||
];
|
||||
|
||||
if ($merchantRole === 'member' && $merchant && $merchant['verify_status'] === 'pass') {
|
||||
$userType = 'merchant';
|
||||
} elseif (!empty($user['user_type']) && in_array($user['user_type'], ['personal', 'merchant'], true)) {
|
||||
$userType = $user['user_type'];
|
||||
} else {
|
||||
$userType = ($merchant && $merchant['verify_status'] === 'pass') ? 'merchant' : 'personal';
|
||||
}
|
||||
$userType = in_array($user['user_type'], ['personal', 'merchant'], true) ? $user['user_type'] : 'personal';
|
||||
|
||||
return [
|
||||
'id' => (int)$user['id'],
|
||||
@@ -167,10 +165,11 @@ class Auth extends Base
|
||||
'email' => !empty($user['email']) ? (string)$user['email'] : ($merchant && !empty($merchant['email']) ? (string)$merchant['email'] : ''),
|
||||
'contact_address' => !empty($user['contact_address']) ? (string)$user['contact_address'] : ($merchant ? (string)($merchant['province'] . $merchant['city'] . $merchant['district'] . $merchant['address']) : ''),
|
||||
'user_type' => $userType,
|
||||
'company_name' => $merchant ? (string)$merchant['name'] : '',
|
||||
'legal_person' => $merchant && isset($merchant['legal_person']) ? (string)$merchant['legal_person'] : '',
|
||||
'legal_mobile' => $merchant && isset($merchant['legal_mobile']) ? (string)$merchant['legal_mobile'] : '',
|
||||
'tech_mobile' => $merchant && isset($merchant['tech_mobile']) ? (string)$merchant['tech_mobile'] : '',
|
||||
'identity_selected' => (bool)$user['identity_selected'],
|
||||
'company_name' => $user['company_name'] !== '' ? $user['company_name'] : ($merchant ? (string)$merchant['name'] : ''),
|
||||
'legal_person' => $user['company_legal_person'] !== '' ? $user['company_legal_person'] : ($merchant ? (string)($merchant['legal_person'] ?? '') : ''),
|
||||
'legal_mobile' => $user['company_legal_mobile'] !== '' ? $user['company_legal_mobile'] : ($merchant ? (string)($merchant['legal_mobile'] ?? '') : ''),
|
||||
'tech_mobile' => $user['company_tech_mobile'] !== '' ? $user['company_tech_mobile'] : ($merchant ? (string)($merchant['tech_mobile'] ?? '') : ''),
|
||||
'avatar' => !empty($user['avatar']) ? (strpos((string)$user['avatar'], 'http') === 0 ? $user['avatar'] : cdnurl($user['avatar'], true)) : '',
|
||||
'balance' => (float)$user['money'],
|
||||
'coupon_count' => (int)$couponCount,
|
||||
@@ -190,10 +189,14 @@ class Auth extends Base
|
||||
public function saveAccount()
|
||||
{
|
||||
$uid = $this->uid();
|
||||
$currentUserType = Db::name('user')->where('id', $uid)->value('user_type');
|
||||
$userType = trim((string)$this->request->post('user_type', $currentUserType ?: 'personal'));
|
||||
if (!in_array($userType, ['personal', 'merchant'], true)) {
|
||||
$userType = 'personal';
|
||||
$currentUser = Db::name('user')->where('id', $uid)->find();
|
||||
$userType = (string)$currentUser['user_type'];
|
||||
$requestedType = $this->request->post('user_type', null);
|
||||
if ($requestedType !== null && $requestedType !== $userType) {
|
||||
$this->error('用户类型确定后不可自行修改');
|
||||
}
|
||||
if (empty($currentUser['identity_selected'])) {
|
||||
$this->error('请先选择用户类型');
|
||||
}
|
||||
$nickname = trim((string)$this->request->post('nickname', ''));
|
||||
$mobile = trim((string)$this->request->post('mobile', ''));
|
||||
@@ -221,19 +224,18 @@ class Auth extends Base
|
||||
}
|
||||
|
||||
$merchantRel = $this->merchantOf($uid);
|
||||
if ($userType === 'merchant') {
|
||||
if (!$merchantRel || ($merchantRel['merchant']['verify_status'] ?? '') !== 'pass') {
|
||||
$this->error('请先提交企业入驻申请并通过审核后再启用商家账号');
|
||||
}
|
||||
}
|
||||
|
||||
$userUpdate = [
|
||||
'nickname' => $nickname,
|
||||
'user_type' => $userType,
|
||||
'contact_address' => $contactAddress,
|
||||
'email' => $email,
|
||||
'updatetime' => time(),
|
||||
];
|
||||
if ($userType === 'merchant') {
|
||||
foreach (['company_name' => $companyName, 'company_legal_person' => $legalPerson, 'company_legal_mobile' => $legalMobile, 'company_tech_mobile' => $techMobile] as $field => $value) {
|
||||
$requestField = ['company_name' => 'company_name', 'company_legal_person' => 'legal_person', 'company_legal_mobile' => 'legal_mobile', 'company_tech_mobile' => 'tech_mobile'][$field];
|
||||
if ($this->request->has($requestField, 'post')) $userUpdate[$field] = $value;
|
||||
}
|
||||
}
|
||||
if ($mobile !== '' && preg_match('/^1\d{10}$/', $mobile)) {
|
||||
$conflict = Db::name('user')->where('mobile', $mobile)->where('id', '<>', $uid)->find();
|
||||
if ($conflict) {
|
||||
@@ -268,6 +270,22 @@ class Auth extends Base
|
||||
$this->success('保存成功', ['userinfo' => $this->profileData()]);
|
||||
}
|
||||
|
||||
/** 首次登录选择用户类型,原子更新防止重复选择。 */
|
||||
public function selectIdentity()
|
||||
{
|
||||
$type = trim((string)$this->request->post('user_type', ''));
|
||||
if (!in_array($type, ['personal', 'merchant'], true)) {
|
||||
$this->error('请选择个人用户或商家用户');
|
||||
}
|
||||
$updated = Db::name('user')->where('id', $this->uid())->where('identity_selected', 0)->update([
|
||||
'user_type' => $type, 'identity_selected' => 1, 'updatetime' => time(),
|
||||
]);
|
||||
if (!$updated) {
|
||||
$this->error('用户类型确定后不可自行修改');
|
||||
}
|
||||
$this->success('选择成功', ['userinfo' => $this->profileData()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信授权登录(小程序 uni.login 拿到的 code)
|
||||
* @ApiMethod (POST)
|
||||
|
||||
在新工单中引用
屏蔽一个用户