lrf402788946 4 years ago
parent
commit
f170a2731d

+ 7 - 32
app/controller/.channel.js

@@ -1,18 +1,6 @@
 module.exports = {
   create: {
-    requestBody: [
-      "!user_id",
-      "title",
-      "desc",
-      "province",
-      "place",
-      "sponsor",
-      "organizer",
-      "image_path",
-      "videodata",
-      "orgin",
-      "create_time",
-    ],
+    requestBody: ["!user_id", "title", "desc", "type", "orgin", "create_time"],
   },
   destroy: {
     params: ["!id"],
@@ -20,19 +8,7 @@ module.exports = {
   },
   update: {
     params: ["!id"],
-    requestBody: [
-      "!user_id",
-      "title",
-      "desc",
-      "province",
-      "place",
-      "sponsor",
-      "organizer",
-      "image_path",
-      "videodata",
-      "orgin",
-      "create_time",
-    ],
+    requestBody: ["!user_id", "title", "desc", "type", "orgin", "create_time"],
   },
   show: {
     parameters: {
@@ -46,12 +22,7 @@ module.exports = {
         user_id: "user_id",
         title: "title",
         desc: "desc",
-        province: "province",
-        place: "place",
-        sponsor: "sponsor",
-        organizer: "organizer",
-        image_path: "image_path",
-        videodata: "videodata",
+        type: "type",
         orgin: "orgin",
         create_time: "create_time",
       },
@@ -64,4 +35,8 @@ module.exports = {
       count: true,
     },
   },
+  login: {
+    requestBody: ["!room_id", "passwd"],
+    service: 'login'
+  },
 };

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

@@ -0,0 +1,37 @@
+module.exports = {
+  create: {
+    requestBody: ["!user_id", "title", "start_time", "end_time", "file_path"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["!user_id", "title", "start_time", "end_time", "file_path"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        user_id: "user_id",
+        title: "title",
+        start_time: "start_time",
+        end_time: "end_time",
+        file_path: "file_path",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 16 - 0
app/controller/channelVideo.js

@@ -0,0 +1,16 @@
+'use strict';
+
+const _ = require('lodash');
+const meta = require('./.channel.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 科技频道录像
+class ChannelVideoController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.channelVideo;
+  }
+}
+
+module.exports = CrudController(ChannelVideoController, meta);

+ 5 - 14
app/model/channel.js

@@ -1,27 +1,18 @@
 'use strict';
 const Schema = require('mongoose').Schema;
+const moment = require('moment');
 const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 const { Secret } = require('naf-framework-mongoose/lib/model/schema');
-// 产品图片表
-const videos = new Schema({
-  name: { type: String, required: false, maxLength: 200 }, // 视频标题
-  start_time: { type: String, required: false, maxLength: 200 }, // 开始时间
-  end_time: { type: String, required: false, maxLength: 200 }, // 结束时间
-  url: { type: String, required: false, maxLength: 500 }, // 视频路径
-});
 
 const Channel = {
   user_id: { type: String, required: false, maxLength: 200 }, // 创建人id
   title: { type: String, required: false, maxLength: 200 }, // 标题
-  province: { type: String, required: false }, // 省
-  place: { type: String, required: false }, // 市
   orgin: { type: String, required: false, maxLength: 200 }, // 来源
-  sponsor: { type: String, required: false, maxLength: 200 }, // 主办方
-  organizer: { type: String, required: false, maxLength: 200 }, // 承办方
+  type: { type: String, required: false, maxLength: 200 }, // 类别
+  room_id: { type: String, required: false, maxLength: 200 }, // 房间id,服务生成,从2001开始
+  passwd: { type: Secret, required: false, maxLength: 200, select: false }, // 密码,房间号
   desc: { type: String, maxLength: 1000 }, // 简介
-  create_time: { type: String, required: false, maxLength: 200 }, // 创建时间
-  image_path: { type: String, required: false }, // 图片路径
-  videodata: { type: [ videos ], default: [] }, // vip用户
+  create_time: { type: String, required: false, maxLength: 200, default: moment().format('YYYY-MM-DD HH:ss') }, // 创建时间
 };
 const schema = new Schema(Channel, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });

+ 19 - 0
app/model/channelVideo.js

@@ -0,0 +1,19 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+const ChannelVideo = {
+  user_id: { type: String, required: false, maxLength: 200 }, // 所属人id,关联channel
+  title: { type: String, required: false, maxLength: 200 }, // 标题
+  start_time: { type: String, required: false, maxLength: 200 }, // 开始时间
+  end_time: { type: String, required: false, maxLength: 200 }, // 结束时间
+  file_path: { type: String, required: false, maxLength: 200 }, // 视频路径
+};
+const schema = new Schema(ChannelVideo, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('ChannelVideo', schema, 'channelVideo');
+};

+ 4 - 0
app/router.js

@@ -101,5 +101,9 @@ module.exports = app => {
   // 科技在线频道
   router.resources('channel', '/api/live/channel', controller.channel); // index、create、show、destroy
   router.post('channel', '/api/live/channel/update/:id', controller.channel.update);
+  router.post('channel', '/api/live/channel/login', controller.channel.login);
+  // 科技频道录像
+  router.resources('channelVideo', '/api/live/channelvideo', controller.channelVideo); // index、create、show、destroy
+  router.post('channelVideo', '/api/live/channelvideo/update/:id', controller.channelVideo.update);
 
 };

+ 38 - 0
app/service/channel.js

@@ -12,6 +12,44 @@ class ChannelService extends CrudService {
     super(ctx, 'channel');
     this.model = this.ctx.model.Channel;
   }
+  async create(data) {
+    const { user_id, title, orgin, type } = data;
+    assert(user_id, '缺少创建人信息');
+    assert(title, '缺少标题');
+    assert(orgin, '缺少来源');
+    assert(type, '缺少类别');
+    const last = await this.model.findOne().sort({ room_id: -1 });
+    if (last) {
+      const { room_id } = last;
+      if (parseInt(room_id)) data.room_id = `${parseInt(room_id) + 1}`;
+      else data.room_id = `${room_id}1`;
+    } else {
+      data.room_id = '2001';
+    }
+    data.passwd = { secret: data.room_id };
+    let res = await this.model.create(data);
+    if (res) {
+      res = JSON.parse(JSON.stringify(res));
+      res.passwd = data.room_id;
+      console.log(res);
+    }
+    return res;
+  }
+
+  async login(data) {
+    const { room_id, passwd } = data;
+    assert(room_id, '请填写房间号');
+    assert(passwd, '请填写密码');
+    let channel = await this.model.findOne({ room_id }, '+passwd');
+    if (!channel) throw new BusinessError(ErrorCode.USER_NOT_EXIST, '房间号不存在');
+    const secret = _.get(channel, 'passwd.secret');
+    if (!secret) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '房间号密码缺失');
+    if (passwd === secret) {
+      channel = JSON.parse(JSON.stringify(channel));
+      channel = _.omit(channel, [ 'passwd' ]);
+      return channel;
+    } throw new BusinessError(ErrorCode.BAD_PASSWORD, '密码错误');
+  }
 }
 
 module.exports = ChannelService;

+ 18 - 0
app/service/channelVideo.js

@@ -0,0 +1,18 @@
+'use strict';
+
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+
+class ChannelVideoService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'channelvideo');
+    this.model = this.ctx.model.ChannelVideo;
+  }
+
+}
+
+module.exports = ChannelVideoService;