|
@@ -15,42 +15,32 @@ class ExpertuserService extends CrudService {
|
|
|
}
|
|
|
|
|
|
async create(data) {
|
|
|
- const { name, password, role } = data;
|
|
|
+ const { name, password, role, phone } = data;
|
|
|
assert(name, '用户名不能为空');
|
|
|
assert(password, '密码不能为空');
|
|
|
- const { phone } = data;
|
|
|
const has_phone = await this.model.findOne({ phone, role });
|
|
|
if (has_phone) {
|
|
|
- throw new BusinessError('此身份的手机号已被注册,请更换手机号');
|
|
|
+ throw new BusinessError('此身份手机号已被注册,请更换手机号');
|
|
|
}
|
|
|
- const newdata = data;
|
|
|
- newdata.password = { secret: password };
|
|
|
- const res = await this.model.create(newdata);
|
|
|
+ data.password = { secret: password };
|
|
|
+ const res = await this.model.create(data);
|
|
|
if (res) {
|
|
|
- const url = this.ctx.app.config.axios.auth.baseUrl;
|
|
|
const newdata = {
|
|
|
name,
|
|
|
phone: data.phone,
|
|
|
- passwd: password,
|
|
|
+ passwd: data.password,
|
|
|
uid: res.id,
|
|
|
role: data.role,
|
|
|
pid: data.pid,
|
|
|
deptname: data.deptname,
|
|
|
code: data.code,
|
|
|
};
|
|
|
- const user = await this.ctx.curl(url, {
|
|
|
- method: 'post',
|
|
|
- headers: {
|
|
|
- 'content-type': 'application/json',
|
|
|
- },
|
|
|
- dataType: 'json',
|
|
|
- data: JSON.stringify(newdata),
|
|
|
- });
|
|
|
- if (user.data.errcode === 0) {
|
|
|
- const result = await this.model.findById(res.id);
|
|
|
- result.userid = user.data.data.id;
|
|
|
- result.save();
|
|
|
+ const auth_user = await this.umodel.findOne({ phone, role });
|
|
|
+ if (auth_user) {
|
|
|
+ throw new BusinessError('此身份手机号已被注册,请更换手机号');
|
|
|
}
|
|
|
+ const authres = await this.umodel.create(newdata);
|
|
|
+ return authres;
|
|
|
}
|
|
|
return res;
|
|
|
}
|