|
|
@@ -11,6 +11,7 @@ use bizGhs\product\classes\ProductClass;
|
|
|
use common\components\noticeUtil;
|
|
|
use mikemadisonweb\rabbitmq\components\ConsumerInterface;
|
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
+use Yii;
|
|
|
|
|
|
class stockConsumer implements ConsumerInterface
|
|
|
{
|
|
|
@@ -36,6 +37,9 @@ class stockConsumer implements ConsumerInterface
|
|
|
print_r($data);
|
|
|
// 根据操作类型分发处理
|
|
|
$type = $data['type'] ?? null;
|
|
|
+ if ($type == 'limit_buy_clear') {
|
|
|
+ Yii::info('限购延迟消息开始消费: ' . json_encode($data, JSON_UNESCAPED_UNICODE), __METHOD__);
|
|
|
+ }
|
|
|
switch ($type) {
|
|
|
case 'add':
|
|
|
$result = true;
|
|
|
@@ -50,8 +54,14 @@ class stockConsumer implements ConsumerInterface
|
|
|
$result = false;
|
|
|
}
|
|
|
if ($result) {
|
|
|
+ if ($type == 'limit_buy_clear') {
|
|
|
+ Yii::info('限购延迟消息消费成功(ACK): ' . json_encode($data, JSON_UNESCAPED_UNICODE), __METHOD__);
|
|
|
+ }
|
|
|
return ConsumerInterface::MSG_ACK;
|
|
|
} else {
|
|
|
+ if ($type == 'limit_buy_clear') {
|
|
|
+ Yii::warning('限购延迟消息消费失败,准备重入队: ' . json_encode($data, JSON_UNESCAPED_UNICODE), __METHOD__);
|
|
|
+ }
|
|
|
noticeUtil::push("库存的消费者报错:Stock message processing failed");
|
|
|
return ConsumerInterface::MSG_REQUEUE;
|
|
|
}
|
|
|
@@ -83,12 +93,25 @@ class stockConsumer implements ConsumerInterface
|
|
|
|
|
|
// 旧消息直接忽略,避免“先到期的旧消息”提前清空
|
|
|
if (!ProductClass::checkLimitBuyClearMessage($productId, $clearAt)) {
|
|
|
+ Yii::info('限购延迟消息已忽略(旧消息): ' . json_encode([
|
|
|
+ 'productId' => $productId,
|
|
|
+ 'clearAt' => $clearAt,
|
|
|
+ ], JSON_UNESCAPED_UNICODE), __METHOD__);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
$result = OrderItemClass::clearLimitBuyByProductId($productId);
|
|
|
if ($result) {
|
|
|
ProductClass::clearLimitBuyClearMark($productId);
|
|
|
+ Yii::info('限购字段清理完成: ' . json_encode([
|
|
|
+ 'productId' => $productId,
|
|
|
+ 'clearAt' => $clearAt,
|
|
|
+ ], JSON_UNESCAPED_UNICODE), __METHOD__);
|
|
|
+ } else {
|
|
|
+ Yii::warning('限购字段清理失败: ' . json_encode([
|
|
|
+ 'productId' => $productId,
|
|
|
+ 'clearAt' => $clearAt,
|
|
|
+ ], JSON_UNESCAPED_UNICODE), __METHOD__);
|
|
|
}
|
|
|
return $result;
|
|
|
}
|