|
@@ -15,17 +15,27 @@ class Achieve_applyService extends CrudService {
|
|
|
}
|
|
|
|
|
|
async create(body) {
|
|
|
-
|
|
|
+
|
|
|
const { user_id, basic } = body;
|
|
|
let res;
|
|
|
if (!user_id) {
|
|
|
const { phone, email, contacts, addr } = basic;
|
|
|
- const personalData = { name: contacts, phone, email, addr };
|
|
|
- personalData.password = '123456';
|
|
|
- personalData.code = 'CGPJXTYW';
|
|
|
- personalData.status = '1';
|
|
|
- const user = await this.httpUtil.cpost('/users/personal', 'live', personalData);
|
|
|
- if (!user) throw new BusinessError(ErrorCode.SERVICE_FAULT, '用户创建失败!');
|
|
|
+
|
|
|
+ const users = await this.httpUtil.cget('/users/personal', 'live', { phone });
|
|
|
+ let user;
|
|
|
+ if (users.length <= 0) {
|
|
|
+
|
|
|
+ const personalData = { name: contacts, phone, email, addr };
|
|
|
+ personalData.password = '123456';
|
|
|
+ personalData.code = 'CGPJXTYW';
|
|
|
+ personalData.status = '1';
|
|
|
+ user = await this.httpUtil.cpost('/users/personal', 'live', personalData);
|
|
|
+ if (!user) throw new BusinessError(ErrorCode.SERVICE_FAULT, '用户创建失败!');
|
|
|
+ } else {
|
|
|
+
|
|
|
+ user = _.head(users);
|
|
|
+ }
|
|
|
+
|
|
|
body.user_id = user._id;
|
|
|
res = await this.model.create(body);
|
|
|
} else {
|