public function chooseShippingWay($skuList, $weightP, $outside, $zone) { $culModel = new OwShippingFeeCulModel(); $weight = $weightP; //重量 KG $L = $outside['L']; //长 CM $W = $outside['W']; //宽 CM $H = $outside['H']; //高 CM $shipsetting = $culModel->getShipSettings(); $rate = $shipsetting['firerate']; //燃油附加费 $home = $shipsetting['homeshipfee']; //住宅运输费 $exchange = $shipsetting['usdexchange']; //美元rmb汇率 $result = array(); //可成立的运输方式列表 格式 array(运输方式名称=>运费) /* $usps_fix = $culModel->uspsShipfee_fix($length,$width, $hight, 'fix', 'inside'); //usps 固定运费 if ($usps_fix) { $result['usps_fix'] = $usps_fix; } $usps_A = $culModel->usps_serviceA($length,$width, $hight,$weight); if ($usps_A) { //usps 套餐A $result['usps_A'] = $usps_A; } $usps_B = $culModel->usps_serviceB($length,$width, $hight, $weight); //usps 套餐B if ($usps_B) { $result['usps_B'] = $usps_B; } $usps_C = $culModel->usps_serviceC($length,$width, $hight, $weight); if ($usps_C) { $result['usps_C'] = $usps_C; } */ $ground_re = $culModel->ground_re($weight, $zone); //GROUND RESIDENTIAL if ($ground_re) { $result['ground_re'] = $ground_re + $ground_re * $rate; //运费加燃油附加费 + 住宅运送费 } $ground_co = $culModel->ground_co($weight, $zone); //GROUND COMMERCIAL if ($ground_co) { $result['ground_co'] = $ground_co + $ground_co * $rate + $home; //运费加燃油附加费 } /* $SurePost = $culModel->SurePost($length, $width, $hight, $weight, $zone); //SurePost运费 if ($SurePost) { $result['SurePost'] = ($SurePost + ($SurePost*$rate)); //运费加燃油附加费 }*/ /* $ups = $culModel->upsShipfee($weight); //ups运费计算 if ($ups) { $result['UPS Ground'] = $ups + ($ups*$rate) + $home; } */ $usps_gel = $culModel->uspsGeneral($weight, $zone); //usps通用运费计算 if ($usps_gel) { $result['USPS'] = $usps_gel; } // print_r($result);exit; $mini = array('ship' => '', 'fee' => 10000); foreach ($result as $key => $fee) { if ($fee < $mini['fee']) { $mini['ship'] = $key; $mini['fee'] = $fee; } } // print_r($mini); // exit; /* if($weight_oz <= 13){//重量小于13盎司直接选USPS运输方式 $getUspsCost = "SELECT cost FROM ow_usps_calcfree WHERE weight = '{$weight_oz}' AND unit = 'oz'"; $getUspsCost = $dbcon->execute($getUspsCost); $getUspsCost = $dbcon->fetch_one($getUspsCost); $shipCost = $getUspsCost['cost']; $carrier = 'USPS'; }else{ $getUspsCost = "SELECT cost FROM ow_usps_calcfree WHERE weight = '{$weight_lbs}' AND zone = '{$zone}' AND unit = 'lbs'"; $getUspsCost = $dbcon->execute($getUspsCost); $getUspsCost = $dbcon->fetch_one($getUspsCost); $uspsCost = $getUspsCost['cost'];//USPS运费 $getUpsCost = "SELECT cost FROM ow_ups_calcfree WHERE weight = '{$weight_lbs}' AND zone = '{$zone}' AND unit = 'lbs'"; $getUpsCost = $dbcon->execute($getUpsCost); $getUpsCost = $dbcon->fetch_one($getUpsCost); $upsCost = $getUpsCost['cost'];//UPS运费 $upsCost = $upsCost*(1+0.07) + 2.8; //添加 燃油附加费 和住宅配送费 if($uspsCost <= $upsCost){//运费对比 $shipCost = $uspsCost; $carrier = 'USPS'; }else{ $shipCost = $upsCost; $carrier = 'UPS Ground'; } if(empty($uspsCost)){ $shipCost = $upsCost; $carrier = 'UPS Ground'; } } */ /*------------- 运输方式选择 -------------- */ $carrier = $culModel->carrerMap($mini['ship']); $shipCost = $mini['fee']; $extensionInfo = array(); $returnData = array('shippingCode' => '', 'fee' => 0, 'extensionInfo' => $extensionInfo); if ($carrier == 'USPS') { //如果是usps 则需要计算对应的 packageType 和 mailClass $extensionInfo = $culModel->generateUSPSExtensionInfo($skuList, $weight); if (FALSE === $extensionInfo) { //不满足usps的发货条件 self::$errMsg = OwShippingFeeCulModel::$errMsg; return FALSE; } } if ($shipCost != '' && $carrier != '') { $returnData['shippingCode'] = $carrier; $returnData['fee'] = $shipCost; $returnData['extensionInfo'] = $extensionInfo; } return $returnData; }
public function generateUSPSExtensionInfo($skuList, $weight) { $returnData = array('mailclass' => '', 'packageType' => ''); $weight_oz = $this->Kg2Oz($weight); //重量转盎司 $packageType = 'Parcel'; if ($weight_oz <= 13) { $mailclass = 'First'; $packageType = ''; } else { $mailclass = 'Priority'; } $letterSkus = $this->getLorFSku('Letter'); $flatSkus = $this->getLorFSku('Flat'); $pureSku = array_keys($skuList); // print_r($pureSku); $letter_count = count(array_intersect($pureSku, $letterSkus)); $flat_count = count(array_intersect($pureSku, $flatSkus)); $skuCount = count($skuList); // echo $letter_count, "==",$flat_count; /* * 若果包含letter料号 或 flat料号 但是多于一种料号 则需要拆分订单 */ if ($skuCount > 1 && ($letter_count > 0 || $flat_count > 0)) { self::$errMsg = '包含flat/letter料号的多料号订单'; return FALSE; } if ($letter_count > 0 && 1 == $skuCount) { //使用letter发货 $packageType = 'Letter'; } else { if ($flat_count > 0 && 1 == $skuCount) { $packageType = 'Flat'; } } $returnData = array('mailclass' => $mailclass, 'packageType' => $packageType); return $returnData; }