feat: 重构后台服务字典与商品独立定价体系及前后端交互优化

这个提交包含在:
2026-11-10 11:01:05 +08:00
父节点 3ebd795cbb
当前提交 e2b0044b64
共有 66 个文件被更改,包括 6628 次插入 和 2137 次删除

查看文件

@@ -126,7 +126,7 @@ class Auth extends Base
protected function profileData()
{
$uid = $this->uid();
$user = Db::name('user')->field('id,nickname,mobile,avatar,money,score,createtime')->where('id', $uid)->find();
$user = Db::name('user')->field('id,nickname,mobile,email,avatar,money,score,user_type,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();
@@ -156,6 +156,9 @@ class Auth extends Base
$merchantInfo = [
'id' => (int)$merchant['id'],
'name' => $merchant['name'],
'legal_person' => isset($merchant['legal_person']) ? (string)$merchant['legal_person'] : '',
'legal_mobile' => isset($merchant['legal_mobile']) ? (string)$merchant['legal_mobile'] : '',
'tech_mobile' => isset($merchant['tech_mobile']) ? (string)$merchant['tech_mobile'] : '',
'verify_status' => $merchant['verify_status'],
'audit_msg' => $merchant['audit_msg'],
'settle_type' => $merchant['settle_type'],
@@ -165,21 +168,112 @@ class Auth extends Base
];
}
$userType = (!empty($user['user_type']) && $user['user_type'] === 'merchant') || ($merchant && $merchant['verify_status'] === 'pass')
? 'merchant'
: 'personal';
return [
'id' => (int)$user['id'],
'nickname' => $user['nickname'] ?: ('用户' . substr((string)$user['mobile'], -4)),
'mobile' => $user['mobile'],
'avatar' => $user['avatar'] ?: '',
'balance' => (float)$user['money'],
'coupon_count' => (int)$couponCount,
'unread_count' => (int)$unread,
'is_master' => $master ? true : false,
'master' => $masterInfo,
'is_merchant' => $merchant ? true : false,
'merchant' => $merchantInfo,
'id' => (int)$user['id'],
'nickname' => $user['nickname'] ?: ('用户' . substr((string)$user['mobile'], -4)),
'mobile' => $user['mobile'],
'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'] : '',
'avatar' => $user['avatar'] ?: '',
'balance' => (float)$user['money'],
'coupon_count' => (int)$couponCount,
'unread_count' => (int)$unread,
'is_master' => $master ? true : false,
'master' => $masterInfo,
'is_merchant' => $merchant ? true : false,
'merchant' => $merchantInfo,
];
}
/**
* 保存账号信息(对标奇兵到家「账号信息」页:支持 家庭/个人 与 商家 两种用户类型)
* @ApiMethod (POST)
*/
public function saveAccount()
{
$uid = $this->uid();
$userType = trim((string)$this->request->post('user_type', 'personal'));
if (!in_array($userType, ['personal', 'merchant'], true)) {
$userType = 'personal';
}
$nickname = trim((string)$this->request->post('nickname', ''));
$mobile = trim((string)$this->request->post('mobile', ''));
$contactAddress = trim((string)$this->request->post('contact_address', ''));
$email = trim((string)$this->request->post('email', ''));
$companyName = trim((string)$this->request->post('company_name', ''));
$legalPerson = trim((string)$this->request->post('legal_person', ''));
$legalMobile = trim((string)$this->request->post('legal_mobile', ''));
$techMobile = trim((string)$this->request->post('tech_mobile', ''));
if ($nickname === '') {
$this->error('请输入用户昵称');
}
if ($legalPerson !== '' && preg_match('/\d/', $legalPerson)) {
$this->error('法人姓名不支持数字输入');
}
if ($legalMobile !== '' && !preg_match('/^1\d{10}$/', $legalMobile)) {
$this->error('法人手机号格式不正确');
}
if ($techMobile !== '' && !preg_match('/^1\d{10}$/', $techMobile)) {
$this->error('技术手机号格式不正确');
}
if ($email !== '' && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$this->error('电子邮箱格式不正确');
}
$userUpdate = [
'nickname' => $nickname,
'user_type' => $userType,
'contact_address' => $contactAddress,
'email' => $email,
'updatetime' => time(),
];
if ($mobile !== '' && preg_match('/^1\d{10}$/', $mobile)) {
$conflict = Db::name('user')->where('mobile', $mobile)->where('id', '<>', $uid)->find();
if ($conflict) {
$this->error('该联系号码已被其他账号绑定');
}
$userUpdate['mobile'] = $mobile;
}
Db::name('user')->where('id', $uid)->update($userUpdate);
if ($userType === 'merchant') {
$existMerchant = Db::name('merchant')->where('user_id', $uid)->find();
$curUser = Db::name('user')->where('id', $uid)->find();
$merchantSave = [
'name' => $companyName !== '' ? $companyName : ($existMerchant ? $existMerchant['name'] : $nickname),
'legal_person' => $legalPerson,
'legal_mobile' => $legalMobile,
'tech_mobile' => $techMobile,
'contact' => $nickname,
'mobile' => $curUser ? (string)$curUser['mobile'] : '',
'address' => $contactAddress,
'email' => $email,
'updatetime' => time(),
];
if ($existMerchant) {
Db::name('merchant')->where('id', $existMerchant['id'])->update($merchantSave);
} else {
$merchantSave['user_id'] = $uid;
$merchantSave['license_no'] = '';
$merchantSave['verify_status'] = 'pass';
$merchantSave['createtime'] = time();
Db::name('merchant')->insert($merchantSave);
}
}
$this->success('保存成功', ['userinfo' => $this->profileData()]);
}
/**
* 微信授权登录(小程序 uni.login 拿到的 code)
* @ApiMethod (POST)