liuyu 4 年之前
父节点
当前提交
ae6911a07e
共有 3 个文件被更改,包括 37 次插入12 次删除
  1. 1 0
      app/model/dock.js
  2. 29 12
      app/service/dock.js
  3. 7 0
      config/config.default.js

+ 1 - 0
app/model/dock.js

@@ -30,6 +30,7 @@ const Dock = {
   file_path: { type: String, required: false }, // 视频路径
   place: { type: String, required: false }, // 位置
   roomname: { type: String, required: false }, // 房间号
+  u_id: { type: String, required: false, maxLength: 200 }, // 所属用户
 };
 const schema = new Schema(Dock, { toJSON: { virtuals: true } });
 schema.index({ id: 1 });

+ 29 - 12
app/service/dock.js

@@ -11,18 +11,35 @@ class ChatService extends CrudService {
     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 create(body) {
+    const res = await this.model.create(body);
+    if (res) {
+      const url = this.ctx.app.config.axios.auth.baseUrl;
+      const newdata = {
+        name: body.adminuser,
+        phone: body.phone,
+        passwd: body.passwd,
+        uid: res.id,
+        role: '4',
+        pid: body.pid,
+        code: body.code,
+      };
+      const user = await this.ctx.curl(url, {
+        method: 'post',
+        headers: {
+          'content-type': 'application/json',
+        },
+        dataType: 'json',
+        data: JSON.stringify(newdata),
+      });
+      if (user.data.errcode === 0) {
+        const result = await this.model.findById(res.id);
+        result.u_id = user.data.data.id;
+        result.save();
+      }
+    }
+    return res;
+  }
   async apply({ id }, body) {
     const dock = await this.model.findOne({ _id: ObjectId(id) });
     if (!dock) {

+ 7 - 0
config/config.default.js

@@ -30,6 +30,13 @@ module.exports = appInfo => {
     },
   };
 
+  // axios service config
+  config.axios = {
+    auth: { // 用户鉴权服务
+      baseUrl: 'http://localhost:9999/api/auth/user',
+    },
+  };
+
   config.mongoose = {
     url: 'mongodb://localhost:27017/platform',
     options: {