liuyu 4 years ago
parent
commit
7e7e94bd51
5 changed files with 36 additions and 3 deletions
  1. 5 3
      app/controller/.room.js
  2. 5 0
      app/controller/room.js
  3. 2 0
      app/model/room.js
  4. 1 0
      app/router.js
  5. 23 0
      app/service/room.js

+ 5 - 3
app/controller/.room.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert","stream_id","ishis","file_id"],
+    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert","stream_id","ishis","file_id","queid","isque"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert","stream_id","ishis","file_id"],
+    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts","isadvert","stream_id","ishis","file_id","queid","isque"],
   },
   show: {
     parameters: {
@@ -29,7 +29,9 @@ module.exports = {
         starttime: "starttime",
         endtime: "endtime",
         stream_id: "stream_id",
-        ishis: "ishis"
+        ishis: "ishis",
+        queid: "queid",
+        isque: "isque"
       },
     },
     service: "query",

+ 5 - 0
app/controller/room.js

@@ -152,6 +152,11 @@ class RoomController extends Controller {
     });
     this.ctx.ok({ });
   }
+
+  async roomquest() {
+    const data = await this.service.roomquest(this.ctx.request.body);
+    this.ctx.ok({ data });
+  }
 }
 
 module.exports = CrudController(RoomController, meta);

+ 2 - 0
app/model/room.js

@@ -27,6 +27,8 @@ const RoomSchema = {
   status: { type: String, required: false, maxLength: 64, default: '0' }, // 状态0、开启1、关闭
   isadvert: { type: Boolean, required: false, default: false }, // 是否有广告位0、开启1、关闭
   adverts: { type: [ AdvertInfo ], required: false, select: true }, // 广告位
+  queid: { type: String, required: false, maxLength: 200 }, // 问卷id
+  isque: { type: String, required: false, maxLength: 64, default: '0' }, // 状态0、无1、有
 };
 
 const schema = new Schema(RoomSchema, { toJSON: { virtuals: true } });

+ 1 - 0
app/router.js

@@ -26,6 +26,7 @@ module.exports = app => {
   router.post('/api/onlive/room/startrecord', controller.room.startrecord);
   router.resources('room', '/api/onlive/room', controller.room); // index、create、show、destroy
   router.post('room', '/api/onlive/room/update/:id', controller.room.update);
+  router.post('/api/onlive/room/roomquest', controller.room.roomquest);
 
   // 聊天表设置路由
   router.resources('chat', '/api/onlive/chat', controller.chat); // index、create、show、destroy

+ 23 - 0
app/service/room.js

@@ -81,6 +81,29 @@ class RoomService extends CrudService {
     return res;
   }
 
+  async roomquest(data) {
+    const res = await this.model.findById(data.roomid);
+    if (!res) {
+      throw new BusinessError(ErrorCode.DATA_NOT_EXIST);
+    }
+    res.queid = data.queid;
+    res.isque = '1';
+    const result = await res.save();
+    if (result) {
+      const { mq } = this.ctx;
+      if (mq) {
+        const exchange = 'quest_publish' + res.id;
+        const parm = {
+          durable: true,
+          headers: {
+            userid: res.id,
+          } };
+        await mq.fanout(exchange, res.id, JSON.stringify(res), parm);
+      }
+    }
+    return result;
+  }
+
 }
 
 module.exports = RoomService;