@@ -93,9 +93,18 @@ class UserService extends CrudService {
stud.openid = openid;
stud.isComming = '1';
await stud.save();
+ // 再次检查是否有该用户,需要用uid查
+ const have_user = await this.model.findOne({ uid: stud.id });
const newdata = { name: stud.name, mobile: stud.phone, type: '4', uid: stud.id, openid, unionid };
- newdata.passwd = { secret: '12345678' };
- user = await this.model.create(newdata);
+ if (have_user) {
+ if (stud.name) have_user.name = stud.name;
+ if (stud.phone) have_user.mobile = stud.phone;
+ if (stud.id) have_user.uid = stud.id;
+ user = await have_user.save();
+ } else {
+ newdata.passwd = { secret: '12345678' };
+ user = await this.model.create(newdata);
+ }
}
return user;