lrf402788946 4 tahun lalu
induk
melakukan
ff447f3001

+ 53 - 0
app/controller/users/.person_chat.js

@@ -0,0 +1,53 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!sender_id",
+      "sender_name",
+      "!receiver_id",
+      "receiver_name",
+      "!room_id",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "!sender_id",
+      "sender_name",
+      "!receiver_id",
+      "receiver_name",
+      "!room_id",
+      "is_read",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        sender_id: "sender_id",
+        receiver_id: "receiver_id",
+        room_id: "room_id",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["send_time"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 41 - 0
app/controller/users/.person_room.js

@@ -0,0 +1,41 @@
+module.exports = {
+  create: {
+    requestBody: ["!p1_id", "p1", "!p2_id", "p2"],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: ["p1_id", "p1", "p2_id", "p2"],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        p1_id: "p1_id",
+        p1: "p1",
+        p2_id: "p2_id",
+        p2: "p2",
+        "create_time@start": "create_time@start",
+        "create_time@end": "create_time@end",
+      },
+      // options: {
+      //   "meta.state": 0 // 默认条件
+      // },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["last_time"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 15 - 0
app/controller/users/person_chat.js

@@ -0,0 +1,15 @@
+'use strict';
+const meta = require('./.person_chat.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 个人聊天
+class Person_chatController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.users.personChat;
+  }
+
+  // async 
+}
+module.exports = CrudController(Person_chatController, meta);

+ 17 - 0
app/controller/users/person_room.js

@@ -0,0 +1,17 @@
+'use strict';
+const meta = require('./.person_room.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 个人聊天房间
+class Person_roomController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.users.personRoom;
+  }
+  async index() {
+    const { data, total } = await this.service.query(this.ctx.query);
+    this.ctx.ok({ data, total });
+  }
+}
+module.exports = CrudController(Person_roomController, meta);

+ 27 - 0
app/model/person_chat.js

@@ -0,0 +1,27 @@
+'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 { ObjectId } = require('mongoose').Types;
+// 个人聊天表
+const person_chat = {
+  sender_id: { type: ObjectId, required: true }, // 发送人id
+  sender_name: { type: String, required: false }, // 发送人名字
+  receiver_id: { type: ObjectId, required: true }, // 接收人id
+  receiver_name: { type: String, required: false }, // 接收人名字
+  room_id: { type: ObjectId, required: true }, // 聊天房间id
+  is_read: { type: Boolean, default: false }, // 是否已读
+  send_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
+};
+const schema = new Schema(person_chat, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ sender_id: 1 });
+schema.index({ sender_name: 1 });
+schema.index({ receiver_id: 1 });
+schema.index({ receiver_name: 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Person_chat', schema, 'person_chat');
+};

+ 24 - 0
app/model/person_room.js

@@ -0,0 +1,24 @@
+'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 { ObjectId } = require('mongoose').Types;
+// 个人聊天房间表
+const person_room = {
+  p1_id: { type: ObjectId, required: true }, // 第一个人id
+  p1: { type: String, required: false }, // 第一个人名
+  p2_id: { type: ObjectId, required: true }, // 第二个人id
+  p2: { type: String, required: false }, // 第二个人名
+  create_time: { type: String, default: moment().format('YYYY-MM-DD HH:mm:ss') },
+  last_time: { type: String }, // 最后发言时间
+};
+const schema = new Schema(person_room, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.index({ p1_id: 1 });
+schema.index({ p2_id: 1 });
+schema.plugin(metaPlugin);
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Person_room', schema, 'person_room');
+};

+ 2 - 0
app/router.js

@@ -14,6 +14,8 @@ module.exports = app => {
   require('./router/users/organization')(app); // 机构用户
   require('./router/users/expert')(app); // 专家用户
   require('./router/users/product')(app); // 产品
+  require('./router/users/person_room')(app); // 个人聊天房间
+  require('./router/users/person_chat')(app); // 个人聊天
   require('./router/system/menu')(app); // 菜单
   require('./router/system/category')(app); // 字典类别
   require('./router/system/code')(app); // 字典

+ 12 - 0
app/router/users/person_chat.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'users';
+  const target = 'personChat';
+  router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 12 - 0
app/router/users/person_room.js

@@ -0,0 +1,12 @@
+'use strict';
+
+
+module.exports = app => {
+  const { router, controller } = app;
+  const profix = '/api/live/';
+  const vision = 'v0';
+  const index = 'users';
+  const target = 'personRoom';
+  router.resources(target, `${profix}${vision}/${index}/${target}`, controller[index][target]); // index、create、show、destroy
+  router.post(target, `${profix}${vision}/${index}/${target}/update/:id`, controller[index][target].update);
+};

+ 4 - 2
app/service/dock/index.js

@@ -76,14 +76,16 @@ class IndexService extends CrudService {
     return token;
   }
 
-  async dockProduct({ dock_id, type, skip = 0, limit = 10 } = {}) {
+  async dockProduct({ dock_id, type, field, skip = 0, limit = 10 } = {}) {
     assert(dock_id, '缺少展会信息');
     assert(type, '要查询的类型');
+    const query = { 'goodsList.status': '1' };
+    if (field) query['goodsList.field'] = field;
     const res = await this.dockUser.aggregate([
       { $match: { dock_id: ObjectId(dock_id), 'goodsList.type': type } },
       { $project: { goodsList: 1 } },
       { $unwind: '$goodsList' },
-      { $match: { 'goodsList.status': '1' } },
+      { $match: query },
     ]);
     const list = res.map(i => i.goodsList);
     return { data: _.slice(list, skip, skip + limit), total: list.length };

+ 0 - 1
app/service/system/code.js

@@ -23,7 +23,6 @@ class CodeService extends CrudService {
       filter.code = { $regex: /0000/ };
     } else {
       const prefix = code.substr(0, 2);
-      console.log(prefix);
       filter.code = { $regex: `${prefix}\\d{2}(?<!00)00` };
     }
     const res = await this.model.find(filter);

+ 0 - 1
app/service/users/admin.js

@@ -58,7 +58,6 @@ class AdminService extends CrudService {
     const icdata = { user_id: res._id, code, user_name: res.name };
     try {
       const res = await this.inviteCode.create(icdata);
-      console.log(res);
     } catch (error) {
       await this.model.deleteOne({ _id: res._id });
       throw new BusinessError(ErrorCode.DATABASE_FAULT, '该邀请码已被使用,请重新更换邀请码');

+ 16 - 0
app/service/users/person_chat.js

@@ -0,0 +1,16 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const { ObjectId } = require('mongoose').Types;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 个人聊天表
+class Person_chatService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'person_chat');
+    this.model = this.ctx.model.PersonChat;
+  }
+}
+
+module.exports = Person_chatService;

+ 35 - 0
app/service/users/person_room.js

@@ -0,0 +1,35 @@
+'use strict';
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { BusinessError, ErrorCode } = require('naf-core').Error;
+const { ObjectId } = require('mongoose').Types;
+const _ = require('lodash');
+const assert = require('assert');
+
+// 个人聊天房间表
+class Person_roomService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'person_room');
+    this.model = this.ctx.model.PersonRoom;
+  }
+  async query(query) {
+    query = this.ctx.service.util.util.turnDateRangeQuery(this.ctx.service.util.util.turnFilter(query));
+    const { p_id, skip = 0, limit = 0 } = query;
+    const condition = { last_time: { $exists: true }, ...query };
+    if (p_id) {
+      condition.$or = [{ p1_id: ObjectId(p_id) }, { p2_id: ObjectId(p_id) }];
+      delete condition.p_id;
+    }
+    const data = await this.model.find(condition).skip(parseInt(skip)).limit(parseInt(limit));
+    const total = await this.model.count(condition);
+    return { data, total };
+  }
+  async create(payload) {
+    const { p1_id, p2_id } = payload;
+    const obj = await this.model.findOne({ $or: [{ p1_id, p2_id }, { p1_id: p2_id, p2_id: p1_id }] });
+    if (obj) return obj;
+    const res = await this.model.create(payload);
+    return res;
+  }
+}
+
+module.exports = Person_roomService;

+ 0 - 1
app/service/users/product.js

@@ -11,7 +11,6 @@ class ProductService extends CrudService {
     this.organization = this.ctx.model.Organization;
   }
   async query({ skip = 0, limit = 0, ...query } = {}) {
-    console.log(skip, limit);
     const { code, ...oq } = query;
     let res = [];
     let total = 0;