lrf402788946 4 年之前
父節點
當前提交
8e16c9285f

+ 19 - 2
app/controller/.answer.js

@@ -1,6 +1,13 @@
 module.exports = {
   create: {
-    requestBody: ["questionnaire_id", "answer", "user_id", 'phone'],
+    requestBody: [
+      "questionnaire_id",
+      "answer",
+      "user_id",
+      "phone",
+      "contacts",
+      "company",
+    ],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +15,14 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["questionnaire_id", "answer", "user_id"],
+    requestBody: [
+      "questionnaire_id",
+      "answer",
+      "user_id",
+      "phone",
+      "contacts",
+      "company",
+    ],
   },
   show: {
     parameters: {
@@ -22,6 +36,9 @@ module.exports = {
         questionnaire_id: "questionnaire_id",
         answer: "answer",
         user_id: "user_id",
+        phone: "phone",
+        contacts: "contacts",
+        company: "company",
         "create_time@start": "create_time@start",
         "create_time@end": "create_time@end",
       },

+ 3 - 2
app/controller/.questionnaire.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["title", "user_id", "questions", "brief"],
+    requestBody: ["title", "user_id", "questions", "brief", "column"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["title", "user_id", "questions", "brief"],
+    requestBody: ["title", "user_id", "questions", "brief", "column"],
   },
   show: {
     parameters: {
@@ -21,6 +21,7 @@ module.exports = {
       query: {
         title: "title",
         user_id: "user_id",
+        column: "column",
         "create_time@start": "create_time@start",
         "create_time@end": "create_time@end",
       },

+ 5 - 0
app/controller/home.js

@@ -7,6 +7,11 @@ class HomeController extends Controller {
     const { ctx } = this;
     ctx.body = 'hi, egg';
   }
+
+  async qrcode() {
+    const data = await this.ctx.service.qrcode.create(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = HomeController;

+ 3 - 0
app/model/answer.js

@@ -8,6 +8,9 @@ const answer = {
   questionnaire_id: { type: ObjectId }, // 问卷id
   answer: { type: Array }, // 答案
   user_id: { type: ObjectId },
+  phone: { type: String },
+  contacts: { type: String },
+  company: { type: String },
   remark: { type: String, maxLength: 200 },
   create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
 };

+ 2 - 0
app/model/questionnaire.js

@@ -9,12 +9,14 @@ const questionnaire = {
   user_id: { type: ObjectId },
   questions: { type: Array, select: false },
   brief: { type: String }, // 简介
+  column: { type: String }, // 简介
   remark: { type: String, maxLength: 200 },
   create_time: { type: String, default: moment(new Date()).format('YYYY-MM-DD HH:mm:ss') },
 };
 const schema = new Schema(questionnaire, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });
 schema.index({ title: 1 });
+schema.index({ column: 1 });
 schema.index({ questions: 1 });
 schema.index({ 'meta.createdAt': 1 });
 schema.plugin(metaPlugin);

+ 1 - 0
app/router.js

@@ -5,6 +5,7 @@
  */
 module.exports = app => {
   const { router, controller } = app;
+  const profix = '/api/question/';
   router.get('/', controller.home.index);
   require('./router/question')(app); // 问题
   require('./router/questionnaire')(app); // 问卷

+ 16 - 16
app/service/answer.js

@@ -12,22 +12,22 @@ class AnswerService extends CrudService {
   }
 
   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 { 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 res = await this.model.create(body);
     return res;
   }

+ 6 - 0
config/config.default.js

@@ -42,6 +42,12 @@ module.exports = appInfo => {
   config.project = {
     live: 'http://127.0.0.1:9101/api/live/v0',
   };
+  config.baseUrl = 'http://broadcast.waityou24.cn';
+  config.wxapi = {
+    appid: 'wx6db5d25b3e7cfc14', // 微信公众号APPID
+    baseUrl: 'http://wx.cc-lotus.info', // 微信网关地址
+  };
+
 
   return {
     ...config,