liuyu 4 年之前
父节点
当前提交
a9237b79c2

+ 37 - 0
app/controller/.lookrecord.js

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: ["roomid", "roomname", "userid","username","createtime","type"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["roomid", "roomname", "userid","username","createtime","type"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        roomid: "roomid",
+        roomname: "roomname",
+        userid: "userid",
+        username: "username",
+        type: "type",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

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

@@ -1,6 +1,6 @@
 module.exports = {
   create: {
-    requestBody: ["roomid", "roomname", "userid","username","phone","switchrole"],
+    requestBody: ["roomid", "roomname", "userid","username","phone","switchrole","isxf","createtime"],
   },
   destroy: {
     params: ["!id"],
@@ -8,7 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: ["roomid", "roomname", "userid","username","phone","switchrole"],
+    requestBody: ["roomid", "roomname", "userid","username","phone","switchrole","isxf","createtime"],
   },
   show: {
     parameters: {

+ 18 - 0
app/controller/lookrecord.js

@@ -0,0 +1,18 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.lookrecord.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 管理
+class LookrecordController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.lookuser;
+  }
+
+}
+
+module.exports = CrudController(LookrecordController, meta);

+ 21 - 0
app/model/lookrecord.js

@@ -0,0 +1,21 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+const LookrecordSchema = {
+  roomid: { type: String, required: false, maxLength: 200 }, // 房间名称
+  roomname: { type: String, required: false, maxLength: 200 }, // 房间号
+  userid: { type: String, required: false, maxLength: 200 }, // 观看用户id
+  username: { type: String, required: false, maxLength: 200 }, // 观看用户名称
+  createtime: { type: String, required: false, maxLength: 200 }, // 创建时间
+  type: { type: String, required: false, maxLength: 200 }, // 0、进入 1、退出
+};
+
+const schema = new Schema(LookrecordSchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Lookrecord', schema, 'lookrecord');
+};

+ 2 - 0
app/model/lookuser.js

@@ -9,6 +9,8 @@ const LookuserSchema = {
   username: { type: String, required: false, maxLength: 200 }, // 观看用户名称
   phone: { type: String, required: false, maxLength: 200 }, // 手机号
   switchrole: { type: String, required: false }, // 直播身份  ‘anchor’ 主播  ‘audience’ 观众
+  createtime: { type: String, required: false, maxLength: 200 }, // 创建时间
+  isxf: { type: String, required: false, maxLength: 200 }, // 申请学分
 };
 
 const schema = new Schema(LookuserSchema, { toJSON: { virtuals: true } });

+ 4 - 0
app/router.js

@@ -36,6 +36,10 @@ module.exports = app => {
   router.get('/api/onlive/lookuser/swichrole', controller.lookuser.swichrole);
   router.resources('lookuser', '/api/onlive/lookuser', controller.lookuser); // index、create、show、destroy
   router.post('lookuser', '/api/onlive/lookuser/update/:id', controller.lookuser.update);
+  router.post('/api/onlive/lookuser/updatexf', controller.lookuser.updatexf);
+
+  router.resources('lookrecord', '/api/onlive/lookrecord', controller.lookrecord); // index、create、show、destroy
+  router.post('lookrecord', '/api/onlive/lookrecord/update/:id', controller.lookrecord.update);
 
   // 用户登录
   router.post('/api/onlive/login', controller.login.login);

+ 24 - 0
app/service/lookrecord.js

@@ -0,0 +1,24 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const moment = require('moment');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class LookrecordService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'lookuser');
+    this.model = this.ctx.model.Lookrecord;
+  }
+
+  async create(data) {
+    data.createtime = moment().format('YYYY-MM-DD HH:mm:ss');
+    const res = await this.model.create(data);
+    return res;
+  }
+}
+
+module.exports = LookrecordService;

+ 6 - 0
app/service/lookuser.js

@@ -3,6 +3,7 @@
 
 const assert = require('assert');
 const _ = require('lodash');
+const moment = require('moment');
 const { ObjectId } = require('mongoose').Types;
 const { CrudService } = require('naf-framework-mongoose/lib/service');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
@@ -11,14 +12,19 @@ class LookuserService extends CrudService {
   constructor(ctx) {
     super(ctx, 'lookuser');
     this.model = this.ctx.model.Lookuser;
+    this.rmodel = this.ctx.model.Lookrecord;
   }
 
   async create(data) {
     const { roomname, userid } = data;
     const lookuser = await this.model.findOne({ roomname, userid });
+    const time = moment().format('YYYY-MM-DD HH:mm:ss');
     if (!lookuser) {
+      data.createtime = time;
       await this.model.create(data);
     }
+    const newdata = { roomid: data.roomid, roomname: data.roomname, userid, username: data.username, createtime: time, type: '0' };
+    await this.rmodel.create(newdata);
   }
 
   async update({ id }, data) {