shish 8 luni în urmă
părinte
comite
f734d6e7c4

+ 5 - 9
app-ghs/controllers/OrderController.php

@@ -2,6 +2,8 @@
 
 namespace ghs\controllers;
 
+use biz\common\classes\GhsNotifyClass;
+use biz\common\classes\HdNotifyClass;
 use biz\shop\classes\ShopExtClass;
 use bizGhs\custom\classes\CustomDebtChangeClass;
 use bizGhs\express\services\DadaExpressServices;
@@ -1304,14 +1306,8 @@ class OrderController extends BaseController
                 if (isset($order->payStatus) && $order->payStatus == 1) {
                     if (!empty($shop)) {
                         //通知批发店员工
-                        $noticeText = json_encode(['orderId' => $saleId]);
-                        $noticeKey = "hdCgNoticeGhs";
-                        Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
-
-                        //通知花店员工
-                        $noticeText = json_encode(['id' => $order->purchaseId]);
-                        $noticeKey = "ghsKdNoticeHd";
-                        Yii::$app->redis->executeCommand('LPUSH', [$noticeKey, $noticeText]);
+                        GhsNotifyClass::newOrderNotify($saleId);
+                        HdNotifyClass::newCgNotify($order->purchaseId);
                     }
                 }
                 //订单生成时唤起在线打印
@@ -2976,7 +2972,7 @@ class OrderController extends BaseController
         util::complete('打印成功');
     }
 
-	//修改地址 ssh 20251123
+    //修改地址 ssh 20251123
     public function actionModifyAddress()
     {
         $post = Yii::$app->request->post();

+ 26 - 0
biz/common/classes/GhsNotifyClass.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace biz\common\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\noticeUtil;
+use Yii;
+
+class GhsNotifyClass extends BaseClass
+{
+
+    //供货商新订单通知 ssh 20251202
+    public static function newOrderNotify($orderId)
+    {
+        try {
+            $producer = Yii::$app->rabbitmq->getProducer('notifyProducer');
+            $msg = serialize(['type' => 'ghs_new_order_notify', 'orderId' => $orderId]);
+            $producer->publish($msg, 'notifyExchange', 'notifyRoute');
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "供货商新订单通知,生产消息报错 {$orderId} {$msg}";
+            noticeUtil::push($remind, '15280215347');
+        }
+    }
+
+}

+ 38 - 0
biz/common/classes/HdNotifyClass.php

@@ -0,0 +1,38 @@
+<?php
+
+namespace biz\common\classes;
+
+use biz\base\classes\BaseClass;
+use common\components\noticeUtil;
+use Yii;
+
+class HdNotifyClass extends BaseClass
+{
+
+    public static function newOrderNotify($orderId)
+    {
+        try {
+            $producer = Yii::$app->rabbitmq->getProducer('notifyProducer');
+            $msg = serialize(['type' => 'hd_new_order_notify', 'orderId' => $orderId]);
+            $producer->publish($msg, 'notifyExchange', 'notifyRoute');
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "花店新订单通知,生产消息报错 {$orderId} {$msg}";
+            noticeUtil::push($remind, '15280215347');
+        }
+    }
+
+    public static function newCgNotify($cgId)
+    {
+        try {
+            $producer = Yii::$app->rabbitmq->getProducer('notifyProducer');
+            $msg = serialize(['type' => 'hd_new_cg_notify', 'cgId' => $cgId]);
+            $producer->publish($msg, 'notifyExchange', 'notifyRoute');
+        } catch (\Exception $e) {
+            $msg = $e->getMessage();
+            $remind = "花店新采购单通知,生产消息报错 {$cgId} {$msg}";
+            noticeUtil::push($remind, '15280215347');
+        }
+    }
+
+}

+ 50 - 15
common/components/rabbitmq/notifyConsumer.php

@@ -6,7 +6,12 @@
 
 namespace common\components\rabbitmq;
 
+use biz\wx\classes\WxMessageClass;
+use bizGhs\order\classes\OrderClass;
+use bizHd\purchase\classes\PurchaseClass;
+use bizHd\shop\classes\ShopClass;
 use common\components\noticeUtil;
+use common\components\push;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 use Yii;
@@ -35,17 +40,17 @@ class notifyConsumer implements ConsumerInterface
             // 根据通知类型分发处理
             $type = $data['type'] ?? null;
             switch ($type) {
-                case 'ghs_new_order':
+                case 'ghs_new_order_notify':
                     //供货商的新订单通知
-                    $result = $this->ghsNewOrder($data);
+                    $result = $this->ghsNewOrderNotify($data);
                     break;
-                case 'hd_new_order':
+                case 'hd_new_order_notify':
                     //花店的新订单通知
-                    $result = $this->hdNewOrder($data);
+                    $result = $this->hdNewOrderNotify($data);
                     break;
-                case 'hd_new_cg_order':
+                case 'hd_new_cg_notify':
                     //花店的新采购单通知
-                    $result = $this->hdNewCgOrder($data);
+                    $result = $this->hdNewCgNotify($data);
                     break;
                 default:
                     noticeUtil::push("通知的消费者提示:Unknown notify type: {$type}", '15280215347');
@@ -63,24 +68,54 @@ class notifyConsumer implements ConsumerInterface
         }
     }
 
-    private function ghsNewOrder($data)
+    private function ghsNewOrderNotify($data)
     {
-        $msg = $data['msg'] ?? '';
-        noticeUtil::push($msg, '15280215347');
+        $orderId = $data['orderId'] ?? 0;
+        if (!empty($orderId)) {
+            return false;
+        }
+        $order = OrderClass::getById($orderId, true);
+        if (empty($order)) {
+            return false;
+        }
+        $shopId = $order->shopId ?? 0;
+        $shop = ShopClass::getById($shopId, true);
+        if (empty($shop)) {
+            return false;
+        }
+        WxMessageClass::ghsHasNewOrderInform($shop, $order);
+
+        // 向供货商App发通知
+        $cgId = $order->purchaseId ?? 0;
+        $cg = PurchaseClass::getById($cgId, true);
+        $cgShop = ShopClass::getById($cg->shopId, true, 'shopName, merchantName');
+        $push = new push('ghs', push::MSG_TYPE_ORDER);
+        $push->ghsOrderMessage($shop, $cgShop, $order);
         return true;
     }
 
-    private function hdNewOrder($data)
+    private function hdNewOrderNotify($data)
     {
-        $msg = $data['msg'] ?? '';
-        noticeUtil::push($msg, '15280215347');
         return true;
     }
 
-    private function hdNewCgOrder($data)
+    private function hdNewCgNotify($data)
     {
-        $msg = $data['msg'] ?? '';
-        noticeUtil::push($msg, '15280215347');
+        $cgId = $data['cgId'] ?? 0;
+        $cg = PurchaseClass::getById($cgId, true);
+        $shopId = $cg->shopId ?? 0;
+        $shop = ShopClass::getById($shopId, true);
+        $allDevices = \bizHd\device\classes\HdDeviceClass::getAllByCondition(['shopId' => $shopId]);
+        $cids = array_column($allDevices, 'clientId');
+        $title = '买花成功';
+        $shopName = $shop->merchantName . ($shop->shopName != '首店' ? '(' . $shop->shopName . ')' : '');
+        $content = $shopName . ' ¥' . $cg->actPrice;
+        $payload = [
+            "page" => "pagesPurchase/purDetails",
+            "params" => ["id" => $cgId]
+        ];
+        $push = new push('hd', push::MSG_TYPE_ORDER);
+        $push->pushByCloud($cids, $title, $content, $payload);
         return true;
     }