修复:运费计算错误、未登录和登录后的运费不一致
This commit is contained in:
parent
ab24642207
commit
a4bbe1c4d8
|
|
@ -14,6 +14,7 @@ namespace Beike\Shop\Services\TotalServices;
|
|||
|
||||
use Beike\Libraries\Weight;
|
||||
use Beike\Models\Logistics;
|
||||
use Beike\Models\Product;
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
|
|
@ -46,16 +47,20 @@ class ShippingService{
|
|||
$logisticsInfo = self::getLogistics($logisticsId,$checkout->cart);
|
||||
if($logisticsInfo) {
|
||||
// 商品信息处理 获取同一个商品的数量
|
||||
$products = $checkout->selectedProducts->toArray() ?? [];
|
||||
$products = $totalService->getCartProducts();
|
||||
// $products = $checkout->selectedProducts->toArray() ?? [];
|
||||
$productsList = collect($products)->groupBy('product_id')->map(function($group){
|
||||
$firstInfo = $group->first();
|
||||
$productWeightInfo = Product::query()
|
||||
->select(['id','weight','weight_class'])
|
||||
->find($firstInfo['product_id']);
|
||||
if($productWeightInfo) $productWeightInfo = $productWeightInfo->toArray();
|
||||
// 重量转换 - 物流重量单位为 千克;商品重量需要进行转换
|
||||
$weight = $firstInfo['product']['weight'] ?? 0;
|
||||
$weight = $productWeightInfo['weight'] ?? 0;
|
||||
$sumQuantity = $group->sum('quantity');
|
||||
$sumWeight = (float)sprintf("%.2f",($weight * $sumQuantity));
|
||||
$weightClass = $firstInfo['product']['weight_class'];
|
||||
$weightClass = $productWeightInfo['weight_class'];
|
||||
$sumWeight = Weight::convert($sumWeight,$weightClass);// 总重量 单位:克
|
||||
|
||||
return [
|
||||
'product_id' => $firstInfo['product_id'],
|
||||
'sum_quantity' => $sumQuantity,
|
||||
|
|
@ -92,11 +97,12 @@ class ShippingService{
|
|||
private static function getLogistics($logisticsId,$cart){
|
||||
if($logisticsId <= 0){
|
||||
// 获取当前收货地址国家ID
|
||||
$address = $cart->guest_shipping_address ?? $cart->guest_payment_address;
|
||||
$cartArr = $cart->toArray();
|
||||
$address = $cart->guest_shipping_address ?? $cart->guest_payment_address ?? $cartArr['payment_address'] ?? $cartArr['shipping_address'];
|
||||
if(!$address) return [];
|
||||
$countryId = $address['country_id'];
|
||||
// 获取全部物流 返回第一个物流信息ID
|
||||
$logisticsList = Logistics::getAll($countryId,['type','first_weight','first_weight_fee','continuation_weight_max','add_weight','continuation_weight_fee','num_fee']);
|
||||
$logisticsList = Logistics::getAll($countryId,['id','type','first_weight','first_weight_fee','continuation_weight_max','add_weight','continuation_weight_fee','num_fee']);
|
||||
|
||||
return $logisticsList[0] ?? [];
|
||||
}else{
|
||||
|
|
|
|||
Loading…
Reference in New Issue