|
@@ -11,18 +11,17 @@ class UserService extends Service {
|
|
assert(name, '昵称不存在');
|
|
assert(name, '昵称不存在');
|
|
assert(phone, '电话不存在');
|
|
assert(phone, '电话不存在');
|
|
assert(openid, 'openid不存在');
|
|
assert(openid, 'openid不存在');
|
|
- const filter = {};
|
|
|
|
- const arr = { phone, openid };
|
|
|
|
- for (const e in arr) {
|
|
|
|
- const data = `{ "${e}": "${arr[e]}" }`;
|
|
|
|
- if (arr[e]) {
|
|
|
|
- filter.$or = [];
|
|
|
|
- filter.$or.push(JSON.parse(data));
|
|
|
|
- }
|
|
|
|
|
|
+ let user;
|
|
|
|
+ // 如果手机号与openid同时存在
|
|
|
|
+ user = await this.model.findOne({ phone, openid });
|
|
|
|
+ if (user) {
|
|
|
|
+ return { errcode: -1001, errmsg: '手机号与微信已存在' };
|
|
}
|
|
}
|
|
- const total = await this.model.find({ ...filter });
|
|
|
|
- if (total.length > 0) {
|
|
|
|
- return { errcode: -1001, errmsg: '手机号或微信已存在' };
|
|
|
|
|
|
+ // 如果查询用户只存在手机号
|
|
|
|
+ user = await this.model.findOne({ phone });
|
|
|
|
+ if (user && !user.openid) {
|
|
|
|
+ await this.update({ id: user._id, phone });
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
const res = await this.model.create({ name, thumbnail, phone, stcompanyatus, tab, openid });
|
|
const res = await this.model.create({ name, thumbnail, phone, stcompanyatus, tab, openid });
|