Просмотр исходного кода

生成采购单时,如果跑腿平台询价请求失败或获取的数据为空,则直接报错且返回

shizhongqi 8 месяцев назад
Родитель
Сommit
e4cb7e43d3
1 измененных файлов с 12 добавлено и 4 удалено
  1. 12 4
      app-hd/controllers/PurchaseController.php

+ 12 - 4
app-hd/controllers/PurchaseController.php

@@ -581,7 +581,7 @@ class PurchaseController extends BaseController
                         $currentWeight = bcmul($thisWeight, $bigNum, 2);
                         $weight = bcadd($currentWeight, $weight, 2);
                     }
-                    // TODO 使用平台估价接口获取费用与距离
+                    // 使用平台估价接口获取费用与距离 -- 弃用
                     //$result = PurchaseClass::getDistanceFee($this->shop, $ghsShopInfo, $weight, $custom);
                     //$sendCost = $result['fee'] ?? 0;
                     //$sendDistance = $result['distance'] ?? 0;
@@ -616,9 +616,15 @@ class PurchaseController extends BaseController
                     if(isset($platformQuotes['error'])){
                         Yii::error($platformQuotes['error']);
                         noticeUtil::push($platform . "-跑腿平台估价接口获取费用与距离失败:mainId=" . $this->mainId);
+                        util::fail($platform . "-跑腿平台估价接口获取费用与距离失败:mainId=" . $this->mainId);
                     } else {
-                        $deliveryList = [];
                         // 格式化各平台报价为前端展示格式
+                        $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
+                        if(is_array($deliveryList) && empty($deliveryList)){ // 重试一次
+                            sleep(2);
+                            $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
+                        }
+
                         $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
                         if(is_array($deliveryList) && !empty($deliveryList)){
                             $result = $deliveryList[0];
@@ -638,7 +644,7 @@ class PurchaseController extends BaseController
                                     foreach($hcMap as $rule){
                                         if($productCount >= $rule['num'] && $post['itemTotalAmount'] >= $rule['price'] && $sendDistance <= $rule['distance']*1000){
                                             $sendCost = 0;
-                                            noticeUtil::push("orderSn=" . $orderSn . " 免跑腿费,满足条件:".json_encode($rule));
+                                            noticeUtil::push("ghsMainId={$ghsInfo['mainId']}, orderSn={$orderSn}, 免跑腿费,满足条件:".json_encode($rule));
                                             break;
                                         }
                                     }
@@ -647,7 +653,9 @@ class PurchaseController extends BaseController
                                 $sendCost = 0;
                             }
                         }else{
-                            noticeUtil::push("ghsMainId={$ghsInfo['mainId']}, orderSn={$orderSn}  请求" . $platform . "平台报价失败。可能造成免跑腿费失败。");
+                            noticeUtil::push("ghsMainId={$ghsInfo['mainId']}, orderSn={$orderSn}  请求 {$platform} 平台报价失败。");
+                            Yii::error("ghsMainId={$ghsInfo['mainId']}, orderSn={$orderSn}  请求" . $platform . "平台报价失败。");
+                            util::fail("ghsMainId={$ghsInfo['mainId']}, orderSn={$orderSn}  请求 {$platform} 平台报价失败。");
                         }
                     }
                 }