request->post(); $orderTime = date('Y-m-d H:i:s'); // --------- $ghsShopId ---------- $ghsShopId = $this->shopId; if (empty($ghsShopId)) { util::fail('店铺不存在'); } $user = $this->user; if (empty($user)) { util::fail('用户不存在'); } $mainId = $this->mainId; if (empty($mainId)) { util::fail('商户不存在'); } $buyType = $post['buyType'] ?? 'huaCai'; //订单类型 $order = $this->generateOrderData($buyType, $user, $post); $ghsShop = ShopClass::getById($ghsShopId); if (empty($ghsShop)) { util::fail('店铺信息不存在'); } $ds = new DispatchService($mainId); $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime); if(isset($platformQuotes['error'])){ util::fail($platformQuotes['error']); } // 格式化各平台报价为前端展示格式 $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes); // 按 price 从低到高排序 ArrayHelper::multisort($deliveryList, 'price', SORT_ASC); $ret['deliveryList'] = $deliveryList; util::success($ret, "success"); } private function generateOrderData($buyType, $user, $post) { // 生成随机订单号,不要跟原来的混起来,跑腿-销售单- $prefix = 'PT-XSD-' . $this->mainId . '-'; $orderSn = $prefix . round(microtime(true) * 1000); //构建出 Order 数据 if($buyType == 'huaCai'){//订单类型是:花材 $order = [ 'orderSn' => $orderSn, 'customName' => $user['name'], 'customMobile' => $user['mobile'], 'fullAddress' => $user['fullAddress'], 'floor' => $user['floor'], 'dist' => $user['dist'], 'lat' => $user['lat'], 'long' => $user['long'], 'address' => $user['address'], //'toAddress' => $order['address'], 'city' => $user['city'], 'weight' => $post['weight'] ?? 1, 'remark' => $post['remark'] ?? '', 'prePrice' => floatval($post['totalPrice'] ?? 0), 'actPrice' => floatval($post['totalPrice'] ?? 0), ]; }elseif($buyType == 'huaShu'){//订单类型是:花束 $order = [ 'orderSn' => $orderSn, 'customName' => $post['receiveUserName'], 'customMobile' => $post['receiveMobile'], 'fullAddress' => $post['address'], 'floor' => $post['floor'] ?? '', 'dist' => $post['dist'] ?? '', 'lat' => $post['region']['latitude'], 'long' => $post['region']['longitude'], 'address' => $post['address'], //'toAddress' => $order['address'], 'city' => $post['city'], 'weight' => $post['weight'] ?? 1, 'remark' => $post['remark'] ?? '', 'prePrice' => floatval($post['totalPrice'] ?? 0), 'actPrice' => floatval($post['totalPrice'] ?? 0), ]; }else{ util::fail('不存在此订单类型'); } return $order; } }