feat(admin,front): 新增师傅资料修改功能,支持头像和接单手机号

- 新增 master/saveProfile 接口用于保存师傅资料
- 新增前端页面入口,允许已认证师傅修改头像和手机号
- 新增头像验证逻辑,确保头像属于当前用户且不超过10MB
- 新增 masterProfilePayload 工具函数验证手机号格式
- 优化会员中心账号页面,新增头像上传和展示功能
- 修复头像URL处理逻辑,支持CDN地址转换
这个提交包含在:
2026-11-20 11:10:34 +08:00
父节点 3d86db0bf4
当前提交 07f3349dd0
共有 15 个文件被更改,包括 1211 次插入 和 18 次删除

查看文件

@@ -171,7 +171,7 @@ class Auth extends Base
'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'] ?: '',
'avatar' => !empty($user['avatar']) ? (strpos((string)$user['avatar'], 'http') === 0 ? $user['avatar'] : cdnurl($user['avatar'], true)) : '',
'balance' => (float)$user['money'],
'coupon_count' => (int)$couponCount,
'unread_count' => (int)$unread,
@@ -190,7 +190,8 @@ class Auth extends Base
public function saveAccount()
{
$uid = $this->uid();
$userType = trim((string)$this->request->post('user_type', 'personal'));
$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';
}
@@ -240,9 +241,14 @@ class Auth extends Base
}
$userUpdate['mobile'] = $mobile;
}
$avatar = trim((string)$this->request->post('avatar', ''));
if ($avatar !== '') {
$this->validateAvatar($avatar);
$userUpdate['avatar'] = $avatar;
}
Db::name('user')->where('id', $uid)->update($userUpdate);
if ($userType === 'merchant' && $merchantRel && $merchantRel['role'] === 'owner') {
if ($userType === 'merchant' && $merchantRel && $merchantRel['role'] === 'owner' && $this->request->has('company_name', 'post')) {
$existMerchant = $merchantRel['merchant'];
$curUser = Db::name('user')->where('id', $uid)->find();
$merchantSave = [

查看文件

@@ -35,6 +35,17 @@ class Base extends Api
return (int)$this->auth->id;
}
/** 验证新头像属于当前账号,且是符合限制的图片附件。 */
protected function validateAvatar($url)
{
$attachment = Db::name('attachment')->where('user_id', $this->uid())
->where('category', 'avatar')->where('url', $url)->find();
if (!$attachment || (int)$attachment['filesize'] > 10 * 1024 * 1024
|| !in_array(strtolower((string)$attachment['mimetype']), ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/bmp'], true)) {
$this->error('头像无效,请重新上传不超过10MB的图片');
}
}
/**
* 师傅档案
*/

查看文件

@@ -263,7 +263,7 @@ class Master extends Base
'idcard_front_raw' => (string)($master['idcard_front'] ?? ''),
'idcard_back_raw' => (string)($master['idcard_back'] ?? ''),
'cert_images' => (string)($master['cert_images'] ?? ''),
'avatar' => $master['avatar'],
'avatar' => !empty($master['avatar']) ? (strpos((string)$master['avatar'], 'http') === 0 ? $master['avatar'] : cdnurl($master['avatar'], true)) : '',
'city' => $master['city'],
'lng' => (string)($master['lng'] ?? ''),
'lat' => (string)($master['lat'] ?? ''),
@@ -286,6 +286,27 @@ class Master extends Base
]);
}
/** 保存已认证师傅的普通资料,不修改实名审核信息。 */
public function saveProfile()
{
$master = $this->masterInfo();
if (!$master || $master['verify_status'] !== 'pass') {
$this->error('仅已认证师傅可修改资料');
}
$mobile = trim((string)$this->request->post('mobile', ''));
if (!preg_match('/^1\d{10}$/', $mobile)) {
$this->error('请输入正确的接单手机号');
}
$update = ['mobile' => $mobile, 'updatetime' => time()];
$avatar = trim((string)$this->request->post('avatar', ''));
if ($avatar !== '') {
$this->validateAvatar($avatar);
$update['avatar'] = $avatar;
}
Db::name('master')->where('id', (int)$master['id'])->where('user_id', $this->uid())->update($update);
$this->success('保存成功');
}
/**
* 接单开关
* @ApiMethod (POST)