shish преди 1 месец
родител
ревизия
1639b7e45a
променени са 2 файла, в които са добавени 12 реда и са изтрити 10 реда
  1. 8 10
      app-ghs/controllers/OrderController.php
  2. 4 0
      biz/shop/classes/ShopExtClass.php

+ 8 - 10
app-ghs/controllers/OrderController.php

@@ -1548,26 +1548,24 @@ class OrderController extends BaseController
                 }
             });
 
-            $saleId = $return->id ?? 0;
-            $order = OrderClass::getById($saleId, true);
+            // 复杂分支/关键逻辑:优化。直接将创建成功的 $return 赋值给 $order,避免重复 SELECT 销售单
+            $order = $return;
             if (!empty($order)) {
 
                 //订单发跑腿流程
                 GhsDeliveryOrderClass::prepareAskData($post, $order);
 
+                $saleId = $order->id ?? 0;
                 $shopId = $order->shopId ?? 0;
                 $customId = $order->customId ?? 0;
                 $ghsId = $order->ghsId ?? 0;
-                $custom = CustomClass::getById($customId, true);
                 $date = date("Y-m-d H:i:s");
-                if (!empty($custom)) {
-                    $custom->recentExpend = $date;
-                    $custom->save();
+                // 复杂分支/关键逻辑:优化。使用 updateByCondition 直接更新最后下单时间,避免先 SELECT 再 UPDATE 的性能开销
+                if ($customId > 0) {
+                    CustomClass::updateByCondition(['id' => $customId], ['recentExpend' => $date]);
                 }
-                $ghs = GhsClass::getById($ghsId, true);
-                if (!empty($ghs)) {
-                    $ghs->recentExpend = $date;
-                    $ghs->save();
+                if ($ghsId > 0) {
+                    GhsClass::updateByCondition(['id' => $ghsId], ['recentExpend' => $date]);
                 }
                 $shop = ShopClass::getById($shopId, true);
                 if (isset($order->payStatus) && $order->payStatus == 1) {

+ 4 - 0
biz/shop/classes/ShopExtClass.php

@@ -202,6 +202,10 @@ class ShopExtClass extends BaseClass
             $sound = $mainPay . '元,请出示付款码';
             $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
             $curl = new curl\Curl();
+            // 复杂分支/关键逻辑:设置 cURL 连接和执行超时,并强制使用 IPv4,防止因外部音箱接口卡顿或 DNS 解析慢拖垮收银结账主进程
+            $curl->setOption(CURLOPT_CONNECTTIMEOUT, 1); // 连接超时限制为 1 秒,避免网络握手长时间卡死
+            $curl->setOption(CURLOPT_TIMEOUT, 1);        // 总执行时间限制为 1 秒,避免请求挂起时间过长
+            $curl->setOption(CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // 强制 IPv4 解析,防止 IPv6 解析超时重试
             $curl->get($url);
         }
     }