Browse Source

Merge branch 'master' of http://git.cc-lotus.info/service-platform/service-live

liuyu 5 years ago
parent
commit
c6bfb544da

+ 41 - 0
app/controller/.dock.js

@@ -0,0 +1,41 @@
+module.exports = {
+  create: {
+    requestBody: ["title", "desc"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["title", "desc"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: ["title", "desc"],
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+  apply:{
+    params: ["!id"],
+    requestBody:['user_id','user_name','buyer', 'goodsList', 'contact', 'contact_tel', 'email', 'company'],
+    service: 'apply',
+  },
+  check:{
+    params: ["!id","!dock_id"],
+    requestBody:['status'],
+    service:'check',
+  }
+};

+ 16 - 0
app/controller/dock.js

@@ -0,0 +1,16 @@
+'use strict';
+
+// const _ = require('lodash');
+const meta = require('./.dock.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 公共聊天表管理
+class DockController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.dock;
+  }
+}
+
+module.exports = CrudController(DockController, meta);

+ 32 - 0
app/model/dock.js

@@ -0,0 +1,32 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+
+const apply = new Schema({
+  user_id: { type: String, required: true, maxLength: 200 }, // 用户id
+  user_name: { type: String, required: true, maxLength: 200 }, // 用户名称
+  buyer: { type: String, required: true, maxLength: 1 }, // 买家/卖家 0/1
+  goodsList: [ Object ],
+  contact: { type: String, required: true, maxLength: 200 }, // 联系人
+  contact_tel: { type: String, required: true, maxLength: 200 }, // 联系人电话
+  email: { type: String, maxLength: 200 }, // 邮箱
+  company: { type: String, maxLength: 200 }, // 单位名称
+  apply_time: { type: String, maxLength: 200 }, // 申请时间
+  status: { type: String, default: 0, maxLength: 1 }, // 申请状态 (0未审核;1已通过;2已拒绝)
+});
+apply.index({ id: 1 });
+apply.index({ userid: 1 });
+const Dock = {
+  title: { type: String, required: true, maxLength: 200 }, // 对接会标题
+  desc: { type: String, maxLength: 1000 }, // 简介
+  status: { type: String, default: '0', maxLength: 1 }, // 状态:0准备中;1已开始;2已结束
+  apply: { type: [ apply ], default: [] },
+};
+const schema = new Schema(Dock, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('dock', schema, 'dock');
+};

+ 3 - 2
app/model/room.js

@@ -4,8 +4,9 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 
 const Room = {
   number: { type: String, required: true, maxLength: 200 }, // 房间号
-  owner_id: { type: String, required: true, maxLength: 200 }, // 播主id
-  owner_name: { type: String, required: true, maxLength: 200 }, // 播主名称
+  title: { type: String, required: true, maxLength: 200 }, // 房间标题
+  owner_id: { type: String, required: true, maxLength: 200 }, // 管理人id
+  owner_name: { type: String, required: true, maxLength: 200 }, // 管理人名称
   room_status: { type: String, default: '0', maxLength: 1 }, // 房间状态:0未审核;1可使用;2已冻结
   live_status: { type: String, default: '0', maxLength: 1 }, // 直播状态:0已下播;1直播中
 };

+ 7 - 1
app/router.js

@@ -25,9 +25,15 @@ module.exports = app => {
   router.post('roomchat', '/api/live/roomchat/:id', controller.roomchat.update);
 
 
-  // 房间表设置路由
+  // 公共聊天设置路由
   router.resources('chat', '/api/live/chat', controller.chat); // index、create、show、destroy
   router.post('chat', '/api/live/chat/:id', controller.chat.update);
 
+  // 对接会表设置路由
+  router.resources('dock', '/api/live/dock', controller.dock); // index、create、show、destroy
+  router.post('dock', '/api/live/dock/:id', controller.dock.update);
+  // 对接会申请表
+  router.post('dock', '/api/live/dock/apply/:id', controller.dock.apply);
+  router.post('dock', '/api/live/dock/apply/:dock_id/check/:id', controller.dock.check);
 
 };

+ 1 - 1
app/service/chat.js

@@ -19,7 +19,7 @@ class ChatService extends CrudService {
     // TODO MQ
     const { mq } = this.ctx;
     if (mq) {
-      const exchange = 'group_chat';
+      const exchange = 'public_chat';
       const parm = {
         durable: true,
         headers: {

+ 53 - 0
app/service/dock.js

@@ -0,0 +1,53 @@
+'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;
+const moment = require('moment');
+class ChatService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'dock');
+    this.model = this.ctx.model.Dock;
+  }
+  // async create(query, { sender_id, sender_name, content }) {
+  //   assert(sender_name, '缺少发言人信息');
+  //   assert(content, '缺少发言内容');
+  //   const send_time = moment().format('YYYY-MM-DD HH:mm:ss');
+  //   const res = await this.model.create({
+  //     sender_id,
+  //     sender_name,
+  //     content,
+  //     send_time,
+  //   });
+  //   return res;
+  // }
+  async apply({ id }, body) {
+    const dock = await this.model.findOne({ _id: ObjectId(id) });
+    if (!dock) {
+      throw new BusinessError('没有查询到该对接会');
+    }
+    dock.apply.push({ ...body, apply_time: moment().format('YYYY-MM-DD HH:mm:ss') });
+    const res = await dock.save();
+    const info = _.last(res.apply);
+    return info;
+  }
+
+  async check({ id, dock_id }, { status }) {
+    assert(status, '请审核是否允许参加对接会');
+    const dock = await this.model.findOne({ _id: ObjectId(dock_id) });
+    if (!dock) {
+      throw new BusinessError('没有查询到该对接会');
+    }
+    const user = dock.apply.id(id);
+    if (!user) {
+      throw new BusinessError('没有查询到用户的申请');
+    }
+    user.status = status;
+    const res = dock.save();
+    return res;
+  }
+}
+
+module.exports = ChatService;

+ 6 - 6
config/config.default.js

@@ -33,12 +33,12 @@ module.exports = appInfo => {
   config.mongoose = {
     url: 'mongodb://localhost:27017/platform',
     options: {
-      user: 'admin',
-      pass: 'admin',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
-      useUnifiedTopology: true,
+      // user: 'admin',
+      // pass: 'admin',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
+      // useUnifiedTopology: true,
     },
   };
   config.amqp = {

+ 6 - 6
config/config.local.js

@@ -11,12 +11,12 @@ module.exports = () => {
   config.mongoose = {
     url: 'mongodb://localhost:27017/platform',
     options: {
-      user: 'admin',
-      pass: 'admin',
-      authSource: 'admin',
-      useNewUrlParser: true,
-      useCreateIndex: true,
-      useUnifiedTopology: true,
+      // user: 'admin',
+      // pass: 'admin',
+      // authSource: 'admin',
+      // useNewUrlParser: true,
+      // useCreateIndex: true,
+      // useUnifiedTopology: true,
     },
   };
 

+ 4 - 4
config/plugin.js

@@ -1,7 +1,7 @@
 'use strict';
 
 /** @type Egg.EggPlugin */
-exports.amqp = {
-  enable: true,
-  package: 'egg-naf-amqp',
-};
+// exports.amqp = {
+//   enable: true,
+//   package: 'egg-naf-amqp',
+// };