feat: changeField 支持修改手机号并校验唯一性
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
'use strict';
|
||||
module.exports = {
|
||||
/**
|
||||
* 认证审核
|
||||
* @url admin/system/user/sys/changeStatus 前端调用的url参数地址
|
||||
* 修改用户字段
|
||||
* @url admin/system/user/sys/changeField 前端调用的url参数地址
|
||||
* data 请求参数
|
||||
* @param {String} params1 参数1
|
||||
* @param {String} id 用户ID
|
||||
* @param {String} field 字段名
|
||||
* @param {Any} value 字段值
|
||||
*/
|
||||
main: async (event) => {
|
||||
let {data = {}, userInfo, util, filterResponse, originalParam} = event;
|
||||
@@ -13,8 +15,36 @@ module.exports = {
|
||||
let res = {code: 0, msg: ""};
|
||||
// 业务逻辑开始-----------------------------------------------------------
|
||||
const {id, field, value} = data
|
||||
if (!id || !field) {
|
||||
return {code: -1, msg: "参数错误"};
|
||||
}
|
||||
|
||||
let dataJson = {}
|
||||
dataJson[field] = value
|
||||
|
||||
// 手机号单独校验:格式 + 唯一性,并标记为已验证
|
||||
if (field === 'mobile') {
|
||||
const mobile = (value || '').toString().trim()
|
||||
if (!mobile) {
|
||||
return {code: -1, msg: "手机号不能为空"};
|
||||
}
|
||||
if (!vk.pubfn.test(mobile, 'mobile')) {
|
||||
return {code: -1, msg: "手机号格式不正确"};
|
||||
}
|
||||
const num = await vk.baseDao.count({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
mobile,
|
||||
_id: _.neq(id)
|
||||
}
|
||||
});
|
||||
if (num > 0) {
|
||||
return {code: -1, msg: `手机号【${mobile}】已注册!`};
|
||||
}
|
||||
dataJson.mobile = mobile
|
||||
dataJson.mobile_confirmed = 1
|
||||
}
|
||||
|
||||
await vk.baseDao.updateAndReturn({
|
||||
dbName: 'uni-id-users',
|
||||
whereJson: {
|
||||
|
||||
Reference in New Issue
Block a user