|
@@ -35,6 +35,31 @@ class UserService extends CrudService {
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 学生注册
|
|
|
|
+ async register(data) {
|
|
|
|
+ const { openid, id_number, mobile, passwd } = data;
|
|
|
|
+ assert(openid && id_number && mobile, '缺少部分信息项');
|
|
|
|
+ let user = await this.model.findOne({ mobile });
|
|
|
|
+ if (user) {
|
|
|
|
+ if (user.passwd.secret !== passwd) {
|
|
|
|
+ throw new BusinessError(ErrorCode.BAD_PASSWORD);
|
|
|
|
+ }
|
|
|
|
+ user.openid = openid;
|
|
|
|
+ await user.save();
|
|
|
|
+ } else {
|
|
|
|
+ const stud = await this.stuModel.findOne({ id_number });
|
|
|
|
+ if (!stud) {
|
|
|
|
+ throw new BusinessError(ErrorCode.USER_NOT_EXIST);
|
|
|
|
+ }
|
|
|
|
+ stud.openid = openid;
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
|
|
+
|
|
// 通过openid查询用户信息
|
|
// 通过openid查询用户信息
|
|
async findByOpenid(openid) {
|
|
async findByOpenid(openid) {
|
|
// 通过openid查询用户信息
|
|
// 通过openid查询用户信息
|