guhongwei 4 jaren geleden
bovenliggende
commit
8911310377
1 gewijzigde bestanden met toevoegingen van 43 en 10 verwijderingen
  1. 43 10
      app/service/dock.js

+ 43 - 10
app/service/dock.js

@@ -23,7 +23,7 @@ class ChatService extends CrudService {
     // roomid与密码每次加一
     const findroom = await this.model.find().sort({ room_id: -1 });
     if (findroom.length > 0) {
-      const room = (parseInt(findroom[0].room_id) + 1) + '';
+      const room = parseInt(findroom[0].room_id) + 1 + '';
       // 将用户输入的密码进行加密并与查询到的用户数据密码相比对
       const pas = await this.createJwtPwd(room);
       body.room_id = room;
@@ -36,7 +36,11 @@ class ChatService extends CrudService {
       body.password = { secret: pas };
     }
     const res = await this.model.create(body);
-    return { ...JSON.parse(JSON.stringify(res)), password: res.password.secret, room_id: res.room_id };
+    return {
+      ...JSON.parse(JSON.stringify(res)),
+      password: res.password.secret,
+      room_id: res.room_id,
+    };
   }
   // 产品
   async goods({ id }, body) {
@@ -49,7 +53,9 @@ class ChatService extends CrudService {
       let { apply } = dock;
       apply = apply.map(a => {
         a.goodsList = a.goodsList.map(g => {
-          if (g.id === body._id) { g.dockStatus = body.dockStatus; }
+          if (g.id === body._id) {
+            g.dockStatus = body.dockStatus;
+          }
 
           return g;
         });
@@ -108,8 +114,6 @@ class ChatService extends CrudService {
         dock.apply = apply;
         console.log(apply);
       }
-
-
     }
 
     const res = await dock.save();
@@ -146,7 +150,10 @@ class ChatService extends CrudService {
   // 根据申请人id查询所有申请的对接会
   async myapply({ user_id, status, skip, limit }) {
     const total = await this.model.count({ status, 'apply.user_id': user_id });
-    const data = await this.model.find({ status, 'apply.user_id': user_id }).skip(Number(skip)).limit(Number(limit));
+    const data = await this.model
+      .find({ status, 'apply.user_id': user_id })
+      .skip(Number(skip))
+      .limit(Number(limit));
     const result = { total, data };
     return result;
   }
@@ -198,7 +205,8 @@ class ChatService extends CrudService {
     if (dock) {
       const applydata = [];
       for (const elm of dock.apply) {
-        const url = 'http://localhost:9004/api/market/transaction?userid=' + elm.user_id;
+        const url =
+          'http://localhost:9004/api/market/transaction?userid=' + elm.user_id;
         const res = await this.ctx.curl(url, {
           method: 'get',
           headers: {
@@ -206,7 +214,10 @@ class ChatService extends CrudService {
           },
           dataType: 'json',
         });
-        const newdata = { ...JSON.parse(JSON.stringify(elm)), transdata: res.data.data };
+        const newdata = {
+          ...JSON.parse(JSON.stringify(elm)),
+          transdata: res.data.data,
+        };
         applydata.push(newdata);
       }
       data.apply = applydata;
@@ -230,7 +241,9 @@ class ChatService extends CrudService {
 
   async getgoodslist({ name }) {
     assert(name, '请输入产品名称');
-    const res = await this.model.find({ 'apply.goodsList.name': { $regex: name } });
+    const res = await this.model.find({
+      'apply.goodsList.name': { $regex: name },
+    });
     const data = [];
     for (const elm of res) {
       const applys = elm.apply;
@@ -251,7 +264,27 @@ class ChatService extends CrudService {
     const { id } = data;
     assert(id, '缺少vip用户的uid');
     console.log(id);
-    const res = await this.model.update({ vipuser: { $elemMatch: { uid: id } } }, { $pull: { vipuser: { uid: id } } });
+    const res = await this.model.update(
+      { vipuser: { $elemMatch: { uid: id } } },
+      { $pull: { vipuser: { uid: id } } }
+    );
+    return res;
+  }
+  async update({ id }, data) {
+    const arr = await this.model.findById(id);
+    const bool = _.isEqual(data.file_path, arr.file_path);
+    if (!bool) {
+      // TODO MQ
+      const { mq } = this.ctx;
+      if (mq) {
+        const exchange = 'dock_video';
+        const parm = {
+          durable: true,
+        };
+        await mq.fanout(exchange, dock_id, '', parm);
+      }
+    }
+    const res = await this.model.update({ _id: ObjectId(id) }, data);
     return res;
   }
 }