|
|
@@ -16,7 +16,7 @@ use common\components\push;
|
|
|
use mikemadisonweb\rabbitmq\components\ConsumerInterface;
|
|
|
use PhpAmqpLib\Message\AMQPMessage;
|
|
|
|
|
|
-class notifyConsumer implements ConsumerInterface
|
|
|
+class notifyConsumer extends baseConsumer
|
|
|
{
|
|
|
/**
|
|
|
* 执行消费者逻辑
|
|
|
@@ -31,6 +31,7 @@ class notifyConsumer implements ConsumerInterface
|
|
|
public function execute(AMQPMessage $msg)
|
|
|
{
|
|
|
try {
|
|
|
+ $this->ensureDbConnection();
|
|
|
// 反序列化消息体
|
|
|
$data = unserialize($msg->body);
|
|
|
if (!is_array($data)) {
|
|
|
@@ -40,31 +41,28 @@ class notifyConsumer implements ConsumerInterface
|
|
|
print_r($data);
|
|
|
// 根据通知类型分发处理
|
|
|
$type = $data['type'] ?? null;
|
|
|
- switch ($type) {
|
|
|
- case 'ghs_new_order_notify':
|
|
|
- //供货商的新订单通知
|
|
|
- $result = $this->ghsNewOrderNotify($data);
|
|
|
- break;
|
|
|
- case 'hd_new_order_notify':
|
|
|
- //花店的新订单通知
|
|
|
- $result = $this->hdNewOrderNotify($data);
|
|
|
- break;
|
|
|
- case 'hd_new_cg_notify':
|
|
|
- //花店的新采购单通知
|
|
|
- $result = $this->hdNewCgNotify($data);
|
|
|
- break;
|
|
|
- case 'ghs_pt_error':
|
|
|
- //供货商跑腿异常通知
|
|
|
- $result = $this->ghsPtErrorAction($data);
|
|
|
- break;
|
|
|
- case 'hd_pt_error':
|
|
|
- //花店跑腿异常通知
|
|
|
- $result = $this->hdPtErrorAction($data);
|
|
|
- break;
|
|
|
- default:
|
|
|
- noticeUtil::push("通知的消费者提示:Unknown notify type: {$type}", '15280215347');
|
|
|
- $result = false;
|
|
|
- }
|
|
|
+ $result = $this->runWithDbReconnect(function () use ($type, $data) {
|
|
|
+ switch ($type) {
|
|
|
+ case 'ghs_new_order_notify':
|
|
|
+ //供货商的新订单通知
|
|
|
+ return $this->ghsNewOrderNotify($data);
|
|
|
+ case 'hd_new_order_notify':
|
|
|
+ //花店的新订单通知
|
|
|
+ return $this->hdNewOrderNotify($data);
|
|
|
+ case 'hd_new_cg_notify':
|
|
|
+ //花店的新采购单通知
|
|
|
+ return $this->hdNewCgNotify($data);
|
|
|
+ case 'ghs_pt_error':
|
|
|
+ //供货商跑腿异常通知
|
|
|
+ return $this->ghsPtErrorAction($data);
|
|
|
+ case 'hd_pt_error':
|
|
|
+ //花店跑腿异常通知
|
|
|
+ return $this->hdPtErrorAction($data);
|
|
|
+ default:
|
|
|
+ noticeUtil::push("通知的消费者提示:Unknown notify type: {$type}", '15280215347');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
if ($result) {
|
|
|
return ConsumerInterface::MSG_ACK;
|
|
|
} else {
|