shish 7 tháng trước cách đây
mục cha
commit
9f99aa8c65

+ 24 - 0
biz-ghs/express/classes/ExpressClass.php

@@ -9,13 +9,37 @@ use bizHd\purchase\classes\PurchaseClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\expressUtil;
+use common\components\noticeUtil;
 use common\components\util;
+use Yii;
 
 class ExpressClass extends BaseClass
 {
 
     public static $baseFile = '\bizGhs\express\models\DeliveryOrder';
 
+    //要求下单
+    public static function askCreateOrder($data)
+    {
+        try {
+            $orderId = $data['orderId'] ?? 0;
+            $producer = Yii::$app->rabbitmq->getProducer('ptProducer');
+            $msg = serialize(['type' => 'ghs_pt_create_order', 'orderId' => $orderId]);
+            $producer->publish($msg, 'ptExchange', 'ptRoute', ['delivery_mode' => 2, 'content_type' => 'application/octet-stream']);
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "批发,跑腿下单,生产消息端报错 {$orderId} {$msg}";
+            noticeUtil::push($remind, '15280215347');
+        }
+    }
+
+    //开始下单 ssh
+    public static function beginCreateOrder($data)
+    {
+        //零售,进行下单流程处理
+        return true;
+    }
+
     public static function getTrack($params, $order)
     {
         $merchant = WxOpenClass::getGhsWxInfo();

+ 24 - 0
biz-hd/express/classes/ExpressClass.php

@@ -5,6 +5,7 @@ namespace bizHd\express\classes;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\expressUtil;
+use common\components\noticeUtil;
 use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
@@ -14,6 +15,29 @@ class ExpressClass extends BaseClass
 
     public static $baseFile = '\bizHd\express\models\Express';
 
+
+    public static function askCreateOrder($data)
+    {
+        try {
+            $orderId = $data['orderId'] ?? 0;
+            $producer = Yii::$app->rabbitmq->getProducer('ptProducer');
+            $msg = serialize(['type' => 'hd_pt_create_order', 'orderId' => $orderId]);
+            $producer->publish($msg, 'ptExchange', 'ptRoute', ['delivery_mode' => 2, 'content_type' => 'application/octet-stream']);
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "零售花店,跑腿下单,生产消息端报错 {$orderId} {$msg}";
+            noticeUtil::push($remind, '15280215347');
+        }
+    }
+
+    //开始下单 ssh
+    public static function beginCreateOrder($data)
+    {
+        //批发,进行下单流程处理
+        return true;
+    }
+
+
     public static function getTrack($params, $cg)
     {
         $merchant = WxOpenClass::getGhsWxInfo();

+ 63 - 0
common/components/rabbitmq/ptConsumer.php

@@ -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;
+        }
+    }
+
+}
+

+ 28 - 2
common/config/rabbitMQ.php

@@ -31,6 +31,11 @@ $rabbitMQ = [
             'name' => 'notifyExchange',
             'type' => 'direct',
             'durable' => true,
+        ],
+        [
+            'name' => 'ptExchange',
+            'type' => 'direct',
+            'durable' => true,
         ]
     ],
 
@@ -53,6 +58,11 @@ $rabbitMQ = [
             'passive' => false,
             'durable' => true,
         ],
+        [
+            'name' => 'ptQueue',
+            'passive' => false,
+            'durable' => true,
+        ],
     ],
 
     /**
@@ -74,6 +84,11 @@ $rabbitMQ = [
             'queue' => 'notifyQueue',
             'exchange' => 'notifyExchange',
             'routing_keys' => ['notifyRoute'],
+        ],
+        [
+            'queue' => 'ptQueue',
+            'exchange' => 'ptExchange',
+            'routing_keys' => ['ptRoute'],
         ]
     ],
 
@@ -92,7 +107,11 @@ $rabbitMQ = [
         [
             //通知生产者
             'name' => 'notifyProducer',
-        ]
+        ],
+        [
+            //跑腿下单生产者
+            'name' => 'ptProducer',
+        ],
     ],
 
     /**
@@ -119,7 +138,14 @@ $rabbitMQ = [
             'callbacks' => [
                 'notifyQueue' => '\common\components\rabbitmq\notifyConsumer',
             ]
-        ]
+        ],
+        [
+            //跑腿下单消费者
+            'name' => 'ptConsumer',
+            'callbacks' => [
+                'ptQueue' => '\common\components\rabbitmq\ptConsumer',
+            ]
+        ],
     ],
 ];
 return $rabbitMQ;