lrf 2 tahun lalu
induk
melakukan
c69fc47d56
1 mengubah file dengan 11 tambahan dan 1 penghapusan
  1. 11 1
      app/service/user.js

+ 11 - 1
app/service/user.js

@@ -9,11 +9,21 @@ class UserService extends CrudService {
   constructor(ctx) {
     super(ctx, 'user');
     this.model = this.ctx.model.Race.User;
+    this.baseUserModel = this.ctx.model.Base.User;
   }
 
   async login({ openid }) {
     const num = await this.model.count({ openid });
-    if (num <= 0) return null;
+    if (num <= 0) {
+      // 去找基础库找用户,然后将信息拿来
+      const user = await this.baseUserModel.findOne({ openid });
+      if (!user) throw new BusinessError(ErrorCode.USER_NOT_EXIST, '用户不存在,无法进入比赛系统');
+      const { _id: user_id, type } = user;
+      const obj = { openid, user_id };
+      if (type === '0' || type === '3') obj.type = '0';
+      else obj.type = type;
+      await this.create(obj);
+    }
     const list = await this.query({ openid });
     return _.head(list);
   }