瀏覽代碼

consumer 不能随意创建??

shizhongqi 4 月之前
父節點
當前提交
2715e8bac8

+ 0 - 1
common/components/rabbitmq/cancelLimitBuyConsumer.php

@@ -11,7 +11,6 @@ use bizGhs\product\classes\ProductClass;
 use common\components\noticeUtil;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
-use Yii;
 
 class cancelLimitBuyConsumer implements ConsumerInterface
 {

+ 19 - 3
common/components/rabbitmq/stockConsumer.php

@@ -7,6 +7,7 @@
 namespace common\components\rabbitmq;
 
 use bizGhs\order\classes\OrderItemClass;
+use bizGhs\product\classes\ProductClass;
 use common\components\noticeUtil;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
@@ -71,11 +72,26 @@ class stockConsumer implements ConsumerInterface
     {
         $productId = intval($data['productId'] ?? 0);
         if ($productId <= 0) {
-            noticeUtil::push('库存的消费者报错:limit_buy_clear 缺少 productId', '15280215347');
-            return false;
+            noticeUtil::push('取消限购的消费者报错:limit_buy_clear 缺少 productId', '15280215347');
+            return true;
         }
 
-        return OrderItemClass::clearLimitBuyByProductId($productId);
+        $clearAt = intval($data['clearAt'] ?? 0);
+        if ($clearAt <= 0) {
+            noticeUtil::push('取消限购的消费者报错:limit_buy_clear 缺少 clearAt', '15280215347');
+            return true;
+        }
+
+        // 旧消息直接忽略,避免“先到期的旧消息”提前清空
+        if (!ProductClass::checkLimitBuyClearMessage($productId, $clearAt)) {
+            return true;
+        }
+
+        $result = OrderItemClass::clearLimitBuyByProductId($productId);
+        if ($result) {
+            ProductClass::clearLimitBuyClearMark($productId);
+        }
+        return $result;
     }
 
 }

+ 2 - 1
common/config/rabbitMQ.php

@@ -164,7 +164,8 @@ $rabbitMQ = [
             'name' => 'stockConsumer',
             'callbacks' => [
                 'stockQueue' => '\common\components\rabbitmq\stockConsumer',
-                'limitBuyQueue' => '\common\components\rabbitmq\cancelLimitBuyConsumer',
+                //'limitBuyQueue' => '\common\components\rabbitmq\cancelLimitBuyConsumer',
+                'limitBuyQueue' => '\common\components\rabbitmq\stockConsumer',
             ]
         ],
         [