liuyu 4 лет назад
Родитель
Сommit
f020b4182b
6 измененных файлов с 23 добавлено и 5 удалено
  1. 2 2
      app/controller/.room.js
  2. 5 0
      app/controller/lookuser.js
  3. 8 0
      app/model/room.js
  4. 1 0
      app/router.js
  5. 5 1
      app/service/lookuser.js
  6. 2 2
      app/service/room.js

+ 2 - 2
app/controller/.room.js

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime"],
+    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime"],
+    requestBody: ["title","name", "type", "filedir", "url", "anchorid","username","status","content","starttime","endtime","adverts"],
   },
   show: {
     parameters: {

+ 5 - 0
app/controller/lookuser.js

@@ -13,6 +13,11 @@ class LookuserController extends Controller {
     this.service = this.ctx.service.lookuser;
   }
 
+  async roomcount() {
+    const data = await this.service.roomcount(this.ctx.query);
+    this.ctx.ok({ ...data });
+  }
+
 }
 
 module.exports = CrudController(LookuserController, meta);

+ 8 - 0
app/model/room.js

@@ -2,6 +2,13 @@
 const Schema = require('mongoose').Schema;
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
+// 房间广告位
+const AdvertInfo = {
+  title: { type: String, required: false }, // 广告标题
+  imgdir: { type: String, required: false }, // 图片地址
+  imgurl: { type: String, required: false }, // 图片链接地址
+};
+
 const RoomSchema = {
   name: { type: String, required: false, maxLength: 200 }, // 房间名称
   title: { type: String, required: false, maxLength: 200 }, // 标题
@@ -14,6 +21,7 @@ const RoomSchema = {
   starttime: { type: String, required: false }, // 开始时间
   endtime: { type: String, required: false }, // 结束时间
   status: { type: String, required: false, maxLength: 64, default: '0' }, // 状态0、开启1、关闭
+  adverts: { type: [ AdvertInfo ], required: false, select: true }, // 广告位
 };
 
 const schema = new Schema(RoomSchema, { toJSON: { virtuals: true } });

+ 1 - 0
app/router.js

@@ -32,6 +32,7 @@ module.exports = app => {
   router.post('roomuser', '/api/onlive/roomuser/update/:id', controller.roomuser.update);
 
   // 观看用户表设置路由
+  router.get('/api/onlive/lookuser/roomcount', controller.lookuser.roomcount);
   router.resources('lookuser', '/api/onlive/lookuser', controller.lookuser); // index、create、show、destroy
   router.post('lookuser', '/api/onlive/lookuser/update/:id', controller.lookuser.update);
 

+ 5 - 1
app/service/lookuser.js

@@ -21,7 +21,11 @@ class LookuserService extends CrudService {
     }
   }
 
-
+  async roomcount(data) {
+    const { roomname } = data;
+    const total = await this.model.count({ roomname });
+    return { total };
+  }
 }
 
 module.exports = LookuserService;

+ 2 - 2
app/service/room.js

@@ -9,7 +9,7 @@ const { BusinessError, ErrorCode } = require('naf-core').Error;
 
 class RoomService extends CrudService {
   constructor(ctx) {
-    super(ctx, "room");
+    super(ctx, 'room');
     this.model = this.ctx.model.Room;
     this.rumodel = this.ctx.model.Roomuser;
     this.lookmodel = this.ctx.model.Lookuser;
@@ -19,7 +19,7 @@ class RoomService extends CrudService {
     const { name } = data;
     const room_ = await this.model.findOne({ name });
     if (room_) {
-      throw new BusinessError("此房间已经存在,请重新输入");
+      throw new BusinessError('此房间已经存在,请重新输入');
     }
     const roomuser = await this.rumodel.findById(data.anchorid);
     if (!roomuser) {