liuyu 4 years ago
parent
commit
4ff5e3b58b
3 changed files with 27 additions and 0 deletions
  1. 5 0
      app/controller/room.js
  2. 1 0
      app/router.js
  3. 21 0
      app/service/room.js

+ 5 - 0
app/controller/room.js

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

+ 1 - 0
app/router.js

@@ -31,6 +31,7 @@ module.exports = app => {
   router.post('/api/onlive/room/updateanchor', controller.room.updateanchor);
   router.post('/api/onlive/room/updateshmai', controller.room.updateshmai);
   router.post('/api/onlive/room/switchzjr', controller.room.switchzjr);
+  router.post('/api/onlive/room/switchzb', controller.room.switchzb);
 
   // 聊天表设置路由
   router.resources('chat', '/api/onlive/chat', controller.chat); // index、create、show、destroy

+ 21 - 0
app/service/room.js

@@ -176,6 +176,27 @@ class RoomService extends CrudService {
     }
     return resmodel;
   }
+
+  async switchzb({ id }) {
+    const resmodel = await this.model.findById(id);
+    if (resmodel) {
+      resmodel.switchzjr = '';
+      const result = await resmodel.save();
+      if (result) {
+        const { mq } = this.ctx;
+        if (mq) {
+          const exchange = 'switch_zb_' + id;
+          const parm = {
+            durable: true,
+            headers: {
+              userid: result.id,
+            } };
+          await mq.fanout(exchange, result.id, JSON.stringify(result), parm);
+        }
+      }
+    }
+    return resmodel;
+  }
 }
 
 module.exports = RoomService;