|
|
@@ -6,6 +6,7 @@
|
|
|
|
|
|
namespace common\components\rabbitmq\consumer;
|
|
|
|
|
|
+use common\components\noticeUtil;
|
|
|
use mikemadisonweb\rabbitmq\components\ConsumerInterface;
|
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
use Yii;
|
|
|
@@ -14,10 +15,10 @@ class notifyConsumer implements ConsumerInterface
|
|
|
{
|
|
|
/**
|
|
|
* 执行消费者逻辑
|
|
|
- *
|
|
|
+ *
|
|
|
* @param AMQPMessage $msg 消息对象
|
|
|
* @return string 消息处理结果
|
|
|
- *
|
|
|
+ *
|
|
|
* ConsumerInterface::MSG_ACK - 确认消息(标记为已处理)并从队列中删除
|
|
|
* ConsumerInterface::MSG_REJECT - 拒绝并从队列中删除消息
|
|
|
* ConsumerInterface::MSG_REQUEUE - 拒绝并重新入队消息
|
|
|
@@ -27,14 +28,14 @@ class notifyConsumer implements ConsumerInterface
|
|
|
try {
|
|
|
// 反序列化消息体
|
|
|
$data = json_decode($msg->body, true);
|
|
|
-
|
|
|
+
|
|
|
if (!is_array($data)) {
|
|
|
Yii::error("Invalid notify message format: {$msg->body}", 'rabbitmq.notify');
|
|
|
return ConsumerInterface::MSG_REJECT;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
Yii::info("Processing notify message: " . json_encode($data), 'rabbitmq.notify');
|
|
|
-
|
|
|
+
|
|
|
// 根据通知类型分发处理
|
|
|
$type = $data['type'] ?? null;
|
|
|
switch ($type) {
|
|
|
@@ -57,7 +58,7 @@ class notifyConsumer implements ConsumerInterface
|
|
|
Yii::warning("Unknown notify type: {$type}", 'rabbitmq.notify');
|
|
|
$result = false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if ($result) {
|
|
|
Yii::info("Notify message processed successfully", 'rabbitmq.notify');
|
|
|
return ConsumerInterface::MSG_ACK;
|
|
|
@@ -65,16 +66,16 @@ class notifyConsumer implements ConsumerInterface
|
|
|
Yii::error("Notify message processing failed", 'rabbitmq.notify');
|
|
|
return ConsumerInterface::MSG_REQUEUE;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
} catch (\Exception $e) {
|
|
|
Yii::error("Notify consumer exception: " . $e->getMessage(), 'rabbitmq.notify');
|
|
|
return ConsumerInterface::MSG_REQUEUE;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 处理新订单通知
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $data 消息数据,包含 order_id, customer_id 等
|
|
|
* @return bool 处理结果
|
|
|
*/
|
|
|
@@ -83,12 +84,14 @@ class notifyConsumer implements ConsumerInterface
|
|
|
// TODO: 实现新订单通知业务逻辑
|
|
|
// 调用对应的 Service 或 Class 层处理
|
|
|
// 例如: 发送短信、推送通知、邮件等
|
|
|
+ $msg = $data['msg'] ?? '';
|
|
|
+ noticeUtil::push($msg, '15280215347');
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 处理新客户通知
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $data 消息数据,包含 customer_id 等
|
|
|
* @return bool 处理结果
|
|
|
*/
|
|
|
@@ -99,10 +102,10 @@ class notifyConsumer implements ConsumerInterface
|
|
|
// 例如: 发送欢迎短信、邮件等
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 处理客户充值通知
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $data 消息数据,包含 customer_id, amount, recharge_no 等
|
|
|
* @return bool 处理结果
|
|
|
*/
|
|
|
@@ -113,10 +116,10 @@ class notifyConsumer implements ConsumerInterface
|
|
|
// 例如: 发送充值成功通知、更新余额等
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 处理客户销账通知
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $data 消息数据,包含 customer_id, amount, writeoff_no 等
|
|
|
* @return bool 处理结果
|
|
|
*/
|
|
|
@@ -127,10 +130,10 @@ class notifyConsumer implements ConsumerInterface
|
|
|
// 例如: 发送销账成功通知、更新账户信息等
|
|
|
return true;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 处理配送状态变更通知
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $data 消息数据,包含 order_id, status, status_desc 等
|
|
|
* @return bool 处理结果
|
|
|
*/
|