|
|
@@ -32,78 +32,27 @@ class stockConsumer implements ConsumerInterface
|
|
|
noticeUtil::push("库存的消费者报错:Invalid notify message format: {$msg->body}", '15280215347');
|
|
|
return ConsumerInterface::MSG_REJECT;
|
|
|
}
|
|
|
- //print_r($data);
|
|
|
+ print_r($data);
|
|
|
// 根据操作类型分发处理
|
|
|
- $action = $data['action'] ?? null;
|
|
|
- switch ($action) {
|
|
|
+ $type = $data['type'] ?? null;
|
|
|
+ switch ($type) {
|
|
|
case 'add':
|
|
|
- $result = $this->handleAddStock($data);
|
|
|
- break;
|
|
|
- case 'reduce':
|
|
|
- $result = $this->handleReduceStock($data);
|
|
|
- break;
|
|
|
- case 'adjust':
|
|
|
- $result = $this->handleAdjustStock($data);
|
|
|
+ $result = true;
|
|
|
break;
|
|
|
default:
|
|
|
- Yii::warning("Unknown stock action: {$action}", 'rabbitmq.stock');
|
|
|
+ noticeUtil::push("库存的消费者报错,未知 type: {$type}");
|
|
|
$result = false;
|
|
|
}
|
|
|
-
|
|
|
if ($result) {
|
|
|
- Yii::info("Stock message processed successfully", 'rabbitmq.stock');
|
|
|
return ConsumerInterface::MSG_ACK;
|
|
|
} else {
|
|
|
- Yii::error("Stock message processing failed", 'rabbitmq.stock');
|
|
|
+ noticeUtil::push("库存的消费者报错:Stock message processing failed");
|
|
|
return ConsumerInterface::MSG_REQUEUE;
|
|
|
}
|
|
|
-
|
|
|
} catch (\Exception $e) {
|
|
|
- Yii::error("Stock consumer exception: " . $e->getMessage(), 'rabbitmq.stock');
|
|
|
+ noticeUtil::push("库存的消费者报错:" . $e->getMessage());
|
|
|
return ConsumerInterface::MSG_REQUEUE;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理库存补充(增加)
|
|
|
- *
|
|
|
- * @param array $data 消息数据,包含 material_id, quantity 等
|
|
|
- * @return bool 处理结果
|
|
|
- */
|
|
|
- private function handleAddStock($data)
|
|
|
- {
|
|
|
- // TODO: 实现库存增加业务逻辑
|
|
|
- // 调用对应的 Service 或 Class 层处理
|
|
|
- // 例如: StockClass::addStock($data);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理库存扣减
|
|
|
- *
|
|
|
- * @param array $data 消息数据,包含 material_id, quantity 等
|
|
|
- * @return bool 处理结果
|
|
|
- */
|
|
|
- private function handleReduceStock($data)
|
|
|
- {
|
|
|
- // TODO: 实现库存扣减业务逻辑
|
|
|
- // 调用对应的 Service 或 Class 层处理
|
|
|
- // 例如: StockClass::reduceStock($data);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 处理库存调整
|
|
|
- *
|
|
|
- * @param array $data 消息数据,包含 material_id, quantity, type 等
|
|
|
- * @return bool 处理结果
|
|
|
- */
|
|
|
- private function handleAdjustStock($data)
|
|
|
- {
|
|
|
- // TODO: 实现库存调整业务逻辑
|
|
|
- // 调用对应的 Service 或 Class 层处理
|
|
|
- // 例如: StockClass::adjustStock($data);
|
|
|
- return true;
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
+}
|