|
@@ -11,6 +11,27 @@ class AnswerService extends CrudService {
|
|
|
this.model = this.ctx.model.Answer;
|
|
|
}
|
|
|
|
|
|
+ async create(body) {
|
|
|
+ const { phone, user_id } = 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 res = await this.model.create(body);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
async findOne({ questionnaire_id, user_id }) {
|
|
|
assert(questionnaire_id, '缺少问卷信息');
|
|
|
assert(user_id, '缺少填写人信息');
|