|
@@ -35,8 +35,26 @@ class UserService extends CrudService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- // 学生注册
|
|
|
+ // 学校注册
|
|
|
async register(data) {
|
|
|
+ const { code, mobile, passwd, name } = data;
|
|
|
+ assert(code && mobile && name && passwd, '缺少部分信息项');
|
|
|
+ const user = await this.model.findOne({ mobile });
|
|
|
+ if (user) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_EXISTED);
|
|
|
+ }
|
|
|
+ const sch = await this.schModel.findOne({ code });
|
|
|
+ if (!sch) {
|
|
|
+ throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
|
|
|
+ }
|
|
|
+ const newdata = { name, mobile, type: '2', uid: sch.id };
|
|
|
+ newdata.passwd = { secret: passwd };
|
|
|
+ const res = await this.model.create(newdata);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 学生绑定
|
|
|
+ async bind(data) {
|
|
|
const { openid, id_number, mobile, passwd } = data;
|
|
|
assert(openid && id_number && mobile, '缺少部分信息项');
|
|
|
let user = await this.model.findOne({ mobile });
|
|
@@ -55,7 +73,7 @@ class UserService extends CrudService {
|
|
|
await stud.save();
|
|
|
const newdata = { name: stud.name, mobile: stud.phone, type: '4', uid: stud.id, openid };
|
|
|
newdata.passwd = { secret: '12345678' };
|
|
|
- user = await this.umodel.create(newdata);
|
|
|
+ user = await this.model.create(newdata);
|
|
|
}
|
|
|
return user;
|
|
|
}
|