lrf402788946 4 jaren geleden
bovenliggende
commit
94448e3578
1 gewijzigde bestanden met toevoegingen van 11 en 2 verwijderingen
  1. 11 2
      app/service/user.js

+ 11 - 2
app/service/user.js

@@ -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;
   }