|
|
@@ -0,0 +1,63 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * 跑腿发单消费者
|
|
|
+ */
|
|
|
+
|
|
|
+namespace common\components\rabbitmq;
|
|
|
+
|
|
|
+use common\components\noticeUtil;
|
|
|
+use mikemadisonweb\rabbitmq\components\ConsumerInterface;
|
|
|
+use PhpAmqpLib\Message\AMQPMessage;
|
|
|
+use Yii;
|
|
|
+
|
|
|
+class ptConsumer implements ConsumerInterface
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 执行消费者逻辑
|
|
|
+ *
|
|
|
+ * @param AMQPMessage $msg 消息对象
|
|
|
+ * @return string 消息处理结果
|
|
|
+ *
|
|
|
+ * ConsumerInterface::MSG_ACK - 确认消息(标记为已处理)并从队列中删除
|
|
|
+ * ConsumerInterface::MSG_REJECT - 拒绝并从队列中删除消息
|
|
|
+ * ConsumerInterface::MSG_REQUEUE - 拒绝并重新入队消息
|
|
|
+ */
|
|
|
+ public function execute(AMQPMessage $msg)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ // 反序列化消息体
|
|
|
+ $data = unserialize($msg->body);
|
|
|
+ if (!is_array($data)) {
|
|
|
+ noticeUtil::push("跑腿发单的消费者报错:Invalid notify message format: {$msg->body}", '15280215347');
|
|
|
+ return ConsumerInterface::MSG_REJECT;
|
|
|
+ }
|
|
|
+ print_r($data);
|
|
|
+ // 根据操作类型分发处理
|
|
|
+ $type = $data['type'] ?? null;
|
|
|
+ switch ($type) {
|
|
|
+ case 'hd_pt_create_order':
|
|
|
+ //花店跑腿开始下单
|
|
|
+ $result = \bizHd\express\classes\ExpressClass::beginCreateOrder($data);
|
|
|
+ break;
|
|
|
+ case 'ghs_pt_create_order':
|
|
|
+ //供货商跑腿开始下单
|
|
|
+ $result = \bizGhs\express\classes\ExpressClass::beginCreateOrder($data);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ noticeUtil::push("跑腿发单的消费者报错,不存在的类型: {$type}");
|
|
|
+ $result = false;
|
|
|
+ }
|
|
|
+ if ($result) {
|
|
|
+ return ConsumerInterface::MSG_ACK;
|
|
|
+ } else {
|
|
|
+ noticeUtil::push("跑腿发单的消费者报错:Notify message processing failed", '15280215347');
|
|
|
+ return ConsumerInterface::MSG_REQUEUE;
|
|
|
+ }
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ noticeUtil::push("跑腿发单的消费者报错:" . $e->getMessage());
|
|
|
+ return ConsumerInterface::MSG_REQUEUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|