request->post(); $orderTime = date('Y-m-d H:i:s'); // --------- $ghsShopId ---------- $ghsId = $post['ghsId'] ?? 0; $ghs = GhsClass::getById($ghsId, true); if (empty($ghs)) { util::fail('获取批发商失败'); } $ghsShopId = $ghs->shopId; // --------- $customId $customId = $ghs->customId ?? 0; $custom = CustomClass::getById($customId, true); if (empty($custom)) { util::fail('获取custom数据失败'); } $weight = $post['weight'] ?? 1; // 生成随机订单号 //$snData = ['shopId' => $ghsShopId, 'mainId' => $ghs->mainId, 'ghsId' => $ghsId, 'customId' => $customId]; //$orderSn = orderSn::getGhsOrderSn($snData); $prefix = 'XSD_CS-'; $orderSn = $prefix . round(microtime(true) * 1000); //构建出 Order 数据 $order = [ 'orderSn' => $orderSn, 'customName' => $custom['name'], 'customMobile' => $custom['mobile'], 'fullAddress' => $custom['fullAddress'], 'floor' => $custom['floor'], 'dist' => $custom['dist'], 'lat' => $custom['lat'], 'long' => $custom['long'], 'address' => $custom['address'], //'toAddress' => $order['address'], 'city' => $custom['city'], 'weight' => $weight, 'remark' => $post['remark'] ?? '', 'prePrice' => 10, // TODO 要从前端获取 'actPrice' => 10, // TODO ]; $ghsShop = ShopClass::getById($ghsShopId); $ds = new DispatchService($ghs->mainId); $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime); if(isset($platformQuotes['error'])){ util::fail($platformQuotes['error']); } $deliveryList = []; // 格式化各平台报价为前端展示格式 $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes); // 按 price 从低到高排序 ArrayHelper::multisort($deliveryList, 'price', SORT_ASC); $ret['deliveryList'] = $deliveryList; util::success($ret, "success"); } }