lrf 2 anos atrás
pai
commit
8f28e865c0
2 arquivos alterados com 27 adições e 0 exclusões
  1. 8 0
      app/service/shop/shopNotice.js
  2. 19 0
      app/service/util/rabbitMq.js

+ 8 - 0
app/service/shop/shopNotice.js

@@ -38,6 +38,10 @@ class ShopNoticeService extends CrudService {
       }
     }
     await this.model.insertMany(list);
+    // 发mq消息
+    for (const i of list) {
+      await this.ctx.service.util.rabbitMq.shopMsg(i.shop);
+    }
 
   }
   /**
@@ -72,6 +76,10 @@ class ShopNoticeService extends CrudService {
       }
     }
     await this.model.insertMany(list);
+    // 发mq消息
+    for (const i of list) {
+      await this.ctx.service.util.rabbitMq.shopMsg(i.shop);
+    }
   }
   /**
    * 提示售后消息

+ 19 - 0
app/service/util/rabbitMq.js

@@ -12,6 +12,25 @@ class RabbitmqService extends Service {
     this.task = this.app.config.taskMqConfig;
   }
 
+  /**
+   * 店铺系统消息
+   * @param shop_id 店铺id
+   */
+  async shopMsg(shop_id) {
+    const { mq } = this.ctx;
+    const ex = 'shopMsg';
+    try {
+      const ch = await mq.conn.createChannel();
+      await ch.assertExchange(ex, 'direct', { durable: true });
+      await ch.publish(ex, shop_id, Buffer.from('check msg'));
+      await ch.close();
+    } catch (error) {
+      console.error('mq--店铺系统消息--任务队列生成失败');
+      console.error(error);
+    }
+  }
+
+
   // 初始化死信机制
   async initDeadProcess() {
     try {