Browse Source

解决开单重复通知

shish 3 năm trước cách đây
mục cha
commit
03f2512145
1 tập tin đã thay đổi với 30 bổ sung18 xóa
  1. 30 18
      app-hd/controllers/OrderController.php

+ 30 - 18
app-hd/controllers/OrderController.php

@@ -284,7 +284,7 @@ class OrderController extends BaseController
                     WxMessageClass::gatheringIncomeInform($shop, $newOrder);
 
                     util::success(['returnStatus' => 'SUCCESS']);
-                }else{
+                } else {
                     util::complete('没有付款');
                 }
             } else {
@@ -360,15 +360,20 @@ class OrderController extends BaseController
                     payUtil::thirdPay($wxPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
                     $transaction->commit();
 
-                    $newOrder = OrderClass::getById($id, true);
-                    //打印小票
-                    OrderClass::onlinePrint($newOrder);
-                    //语音播报
-                    ShopExtClass::hdGatheringReport($newOrder);
-
-                    $shopId = $newOrder->shopId ?? 0;
-                    $shop = ShopClass::getById($shopId, true);
-                    WxMessageClass::gatheringIncomeInform($shop, $newOrder);
+                    //解决重复通知
+                    $cacheKey = 'shop_order_pay_' . $orderSn;
+                    $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+                    if (empty($has)) {
+                        Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 100, 'has']);
+                        $newOrder = OrderClass::getById($id, true);
+                        //打印小票
+                        OrderClass::onlinePrint($newOrder);
+                        //语音播报
+                        ShopExtClass::hdGatheringReport($newOrder);
+                        $shopId = $newOrder->shopId ?? 0;
+                        $shop = ShopClass::getById($shopId, true);
+                        WxMessageClass::gatheringIncomeInform($shop, $newOrder);
+                    }
 
                     util::success(['returnStatus' => 'SUCCESS']);
                 } else {
@@ -449,15 +454,22 @@ class OrderController extends BaseController
                     payUtil::thirdPay($aliPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
                     $transaction->commit();
 
-                    $newOrder = OrderClass::getById($id, true);
-                    //打印小票
-                    OrderClass::onlinePrint($newOrder);
-                    //语音播报
-                    ShopExtClass::hdGatheringReport($newOrder);
+                    //解决重复通知
+                    $cacheKey = 'shop_order_pay_' . $orderSn;
+                    $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+                    if (empty($has)) {
+						Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 100, 'has']);
 
-                    $shopId = $newOrder->shopId ?? 0;
-                    $shop = ShopClass::getById($shopId, true);
-                    WxMessageClass::gatheringIncomeInform($shop, $newOrder);
+                        $newOrder = OrderClass::getById($id, true);
+                        //打印小票
+                        OrderClass::onlinePrint($newOrder);
+                        //语音播报
+                        ShopExtClass::hdGatheringReport($newOrder);
+
+                        $shopId = $newOrder->shopId ?? 0;
+                        $shop = ShopClass::getById($shopId, true);
+                        WxMessageClass::gatheringIncomeInform($shop, $newOrder);
+                    }
 
                     util::success(['returnStatus' => 'SUCCESS']);
                 }