diff --git a/beike/Shop/Services/TotalService.php b/beike/Shop/Services/TotalService.php index 0772cb57..5d4ce1b9 100644 --- a/beike/Shop/Services/TotalService.php +++ b/beike/Shop/Services/TotalService.php @@ -114,7 +114,9 @@ class TotalService */ private function getTotalClassMaps() { - $maps = []; + $maps = [ + 'sum_quantity' => "\Beike\\Shop\\Services\\TotalServices\\SumQuantityService" + ]; foreach (self::TOTAL_CODES as $code) { $serviceName = Str::studly($code) . 'Service'; $maps[$code] = "\Beike\\Shop\\Services\\TotalServices\\{$serviceName}"; diff --git a/beike/Shop/Services/TotalServices/ShippingService.php b/beike/Shop/Services/TotalServices/ShippingService.php index 1df0b4a3..ccbc1d91 100644 --- a/beike/Shop/Services/TotalServices/ShippingService.php +++ b/beike/Shop/Services/TotalServices/ShippingService.php @@ -93,6 +93,7 @@ class ShippingService{ if($logisticsId <= 0){ // 获取当前收货地址国家ID $address = $cart->guest_shipping_address ?? $cart->guest_payment_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']); diff --git a/beike/Shop/Services/TotalServices/SumQuantityService.php b/beike/Shop/Services/TotalServices/SumQuantityService.php new file mode 100644 index 00000000..f5b7405a --- /dev/null +++ b/beike/Shop/Services/TotalServices/SumQuantityService.php @@ -0,0 +1,22 @@ +totalService; + $sumQuantity = $totalService->countProducts(); + $totalData = [ + 'code' => 'sum_quantity', + 'title' => trans('admin/dashboard.product_total'), + 'amount' => $sumQuantity, + 'amount_format' => $sumQuantity, + ]; + $totalService->totals[] = $totalData; + + return $totalData; + } +} diff --git a/plugins/FlatShipping/Bootstrap.php b/plugins/FlatShipping/Bootstrap.php index 21c5371b..235b1c80 100644 --- a/plugins/FlatShipping/Bootstrap.php +++ b/plugins/FlatShipping/Bootstrap.php @@ -53,13 +53,13 @@ class Bootstrap $amount = $totalService->amount; $shippingType = plugin_setting('flat_shipping.type', 'fixed'); $shippingValue = plugin_setting('flat_shipping.value', 0); - if ($shippingType == 'fixed') { - return $shippingValue; - } elseif ($shippingType == 'percent') { - return $amount * $shippingValue / 100; + $sumQuantity = $totalService->countProducts(); + if($sumQuantity > 0){ + if ($shippingType == 'fixed') return $shippingValue; + elseif ($shippingType == 'percent') return $amount * $shippingValue / 100; } - return 0; + return 0; } } diff --git a/themes/default/product/product.blade.php b/themes/default/product/product.blade.php index 72b48520..112db3c8 100644 --- a/themes/default/product/product.blade.php +++ b/themes/default/product/product.blade.php @@ -239,7 +239,12 @@ {{-- 购买数量 - 单规格 --}}
- +
@@ -533,6 +538,7 @@ quantity: function (newval, oldval) { let _this = this; let list = {}; + // 请求计算运费 list[0] = { product_id: _this.product_id, product_sku_id: this.product.id, @@ -807,12 +813,22 @@ let stock = _this.add_buy_sku[skuIndex].stock || 0; let quantity = event.target.value || 0; quantity = quantity > stock ? stock : quantity;// 不能超过库存 - _this.add_buy_sku[skuIndex].quantity = quantity; + _this.add_buy_sku[skuIndex].quantity = typeof quantity != 'number' ? quantity.replace(/\D/g,'') : quantity; // 处理深度监听失败的问题 _this.add_buy_sku = Object.assign({}, _this.add_buy_sku); _this.$forceUpdate(); }, + // 单规格 - 购买数量改变 + singleQuantityChange(event){ + let _this = this; + let stock = _this.product.quantity || 0;// 库存 + let quantity = event.target.value || 0;// 购买数量 + quantity = quantity > stock ? stock : quantity;// 不能超过库存 + _this.quantity = typeof quantity != 'number' ? quantity.replace(/\D/g,'') : quantity; + + _this.$forceUpdate(); + }, // 计算当前订单总额 computeOrderMoney(list){ let _this = this; @@ -825,7 +841,7 @@ _this.$forceUpdate(); } }) - } + }, } });