Browse Source

重复通知问题

shish 3 years ago
parent
commit
644de26e25
2 changed files with 28 additions and 20 deletions
  1. 26 18
      app-hd/controllers/NoticeController.php
  2. 2 2
      app-hd/controllers/OrderController.php

+ 26 - 18
app-hd/controllers/NoticeController.php

@@ -53,27 +53,35 @@ class NoticeController extends PublicController
             //支付成功后续流程
             payUtil::thirdPay($wxPay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
             $transaction->commit();
-            $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
-            if (!empty($cg)) {
-                //微信通知
-                $saleId = $cg->saleId ?? 0;
-                $order = OrderClass::getById($saleId, true);
-                if (!empty($order)) {
-                    $shopId = $order->shopId ?? 0;
-                    $shop = ShopClass::getById($shopId, true);
-                    if (!empty($shop)) {
-                        WxMessageClass::ghsHasNewOrderInform($shop, $order);
-                    }
-                    //订单生成时唤起在线打印
-                    if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
-                        OrderClass::onlinePrint($order);
-                        $order->printNum += 1;
-                        $order->save();
+
+            //解决重复通知
+            $cacheKey = 'hd_shop_cg_pay_' . $orderSn;
+            $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+            if (empty($has)) {
+                Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
+                $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
+                if (!empty($cg)) {
+                    //微信通知
+                    $saleId = $cg->saleId ?? 0;
+                    $order = OrderClass::getById($saleId, true);
+                    if (!empty($order)) {
+                        //订单生成时唤起在线打印
+                        if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'need')) {
+                            OrderClass::onlinePrint($order);
+                            $order->printNum += 1;
+                            $order->save();
+                        }
+                        $shopId = $order->shopId ?? 0;
+                        $shop = ShopClass::getById($shopId, true);
+                        if (!empty($shop)) {
+                            WxMessageClass::ghsHasNewOrderInform($shop, $order);
+                        }
+                        //花店采购供货商端收到通知
+                        NoticeClass::ghsNewOrderNotice($order);
                     }
-                    //花店采购供货商端收到通知
-                    NoticeClass::ghsNewOrderNotice($order);
                 }
             }
+
             echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
         } catch (\Exception $e) {
             $transaction->rollBack();

+ 2 - 2
app-hd/controllers/OrderController.php

@@ -361,7 +361,7 @@ class OrderController extends BaseController
                     $transaction->commit();
 
                     //解决重复通知
-                    $cacheKey = 'shop_order_pay_' . $orderSn;
+                    $cacheKey = 'hd_shop_order_pay_' . $orderSn;
                     $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
                     if (empty($has)) {
                         Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
@@ -455,7 +455,7 @@ class OrderController extends BaseController
                     $transaction->commit();
 
                     //解决重复通知
-                    $cacheKey = 'shop_order_pay_' . $orderSn;
+                    $cacheKey = 'hd_shop_order_pay_' . $orderSn;
                     $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
                     if (empty($has)) {
 						Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);