|
@@ -12,22 +12,22 @@ class AnswerService extends CrudService {
|
|
|
}
|
|
|
|
|
|
async create(body) {
|
|
|
- // const { phone, contacts, company } = body;
|
|
|
- // if (!user_id && phone) {
|
|
|
- // // 没有用户id,但是有电话,需要注册
|
|
|
- // // 查询用户
|
|
|
- // let user = await this.ctx.service.util.httpUtil.cpost('/spm', 'live', { model: 'personal', method: 'findOne', query: { phone } }, { method: 'useModel' });
|
|
|
- // if (user) {
|
|
|
- // body.user_id = user._id;
|
|
|
- // delete body.phone;
|
|
|
- // } else {
|
|
|
- // user = await this.ctx.service.util.httpUtil.cpost('/spm', 'live', { service: 'users.personal', method: 'create', body: { phone, name: '个人', code: 'WJDCXTJG', password: '123456', status: '1' } }, { method: 'useService' });
|
|
|
- // if (user) {
|
|
|
- // body.user_id = user._id;
|
|
|
- // delete body.phone;
|
|
|
- // } else throw new BusinessError(ErrorCode.SERVICE_FAULT, '创建用户失败');
|
|
|
- // }
|
|
|
- // }
|
|
|
+ const { phone, user_id, create_user = true } = body;
|
|
|
+ if (!user_id && phone && create_user) {
|
|
|
+ // 没有用户id,但是有电话,且需要注册
|
|
|
+ // 查询用户
|
|
|
+ let user = await this.ctx.service.util.httpUtil.cpost('/spm', 'live', { model: 'personal', method: 'findOne', query: { phone } }, { method: 'useModel' });
|
|
|
+ if (user) {
|
|
|
+ body.user_id = user._id;
|
|
|
+ delete body.phone;
|
|
|
+ } else {
|
|
|
+ user = await this.ctx.service.util.httpUtil.cpost('/spm', 'live', { service: 'users.personal', method: 'create', body: { phone, name: '个人', code: 'WJDCXT', password: '123456', status: '1' } }, { method: 'useService' });
|
|
|
+ if (user) {
|
|
|
+ body.user_id = user._id;
|
|
|
+ delete body.phone;
|
|
|
+ } else throw new BusinessError(ErrorCode.SERVICE_FAULT, '创建用户失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
const res = await this.model.create(body);
|
|
|
return res;
|
|
|
}
|