后台用户设置->增加的补充信息,移动端、会员卡激活添加信息保存失效问题
修复方法如下:
1、文件:app/controller/api/v1/user/UserController.php
方法:edit,修改99行(如有偏差,请对比代码覆盖)如下:
$this->services->saveExtendForm($uid, $extend_info, ['avatar' => $avatar, 'nickname' => $nickname], true);
2、文件:app/services/user/level/UserLevelServices.php
方法:userActivatelevel,修改576行(如有偏差,请对比代码覆盖),如下:
$extend_info = $userServices->handelExtendInfo($data, true) ?: [];
3、文件:app/services/user/UserServices.php
替换方法:
saveExtendForm
public function saveExtendForm(int $uid, array $extend_info, array $update = [], bool $is_all = false)
{
$userInfo = $this->getUserInfo($uid);
if (!$userInfo) {
throw new ValidateException('用户不存在');
}
$extend_info = $this->handelExtendInfo($extend_info, $is_all) ?: [];
if ($extend_info) {
$default = $this->defaultExtendInfo;
$params = array_column($default, 'param');
$sex = $this->sex;
$update['extend_info'] = $extend_info;
foreach ($extend_info as $info) {
if (isset($info['param']) && in_array($info['param'], $params) && isset($info['value']) && $info['value']) {
if ($info['param'] == 'sex') {
$update['sex'] = $sex[$info['value']] ?? 0;
} elseif ($info['param'] == 'birthday') {
$update['birthday'] = strtotime($info['value']);
} else {
$update[$info['param']] = $info['value'];
}
}
}
}
if ($update) $this->dao->update($uid, $update);
return true;
}
4、文件:app/services/user/UserServices.php
替换方法:
handelExtendInfo
public function handelExtendInfo(array $inputExtendInfo, bool $is_all = false)
{
$extendInfo = SystemConfigService::get('user_extend_info', []);
if ($inputExtendInfo && $extendInfo) {
if ($is_all) {//移动端全数据 处理
$inputExtendInfo = array_combine(array_column($inputExtendInfo, 'info'), $inputExtendInfo);
} else {//后台key=>value类型数据
$inputExtendInfo = $inputExtendInfo[0] ?? $inputExtendInfo;
}
foreach ($extendInfo as &$item) {
$value = $is_all ? ($inputExtendInfo[$item['info'] ?? '']['value'] ?? '') : ($inputExtendInfo[$item['info'] ?? ''] ?? '');
if ($value) {
//验证手机号
if ($item['format'] == 'phone') {
if (!check_phone($value)) throw new AdminException($item['tip'] ?? '请填写正确的手机号');
}
//验证邮箱
if ($item['format'] == 'mail') {
if (!check_mail($inputExtendInfo[$item['info']])) throw new AdminException($item['tip'] ?? '请填写正确的邮箱');
}
//验证身份证号
if ($item['format'] == 'id') {
if (!check_card($inputExtendInfo[$item['info']])) throw new AdminException($item['tip'] ?? '请填写正确的身份证号码');
}
}
$item['value'] = $value;
}
}
return $extendInfo;
}
{{item.user_info.nickname ? item.user_info.nickname : item.user_name}}
作者 管理员 企业
{{itemf.name}}
{{itemc.user_info.nickname}}
{{itemc.user_name}}
回复 {{itemc.comment_user_info.nickname}}
{{itemf.name}}