From 399bff4defee77145012e82ab6f1d3b40ff30c6e Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Tue, 22 Aug 2023 17:43:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=AF=A6=E6=83=85=20-=20=E8=B4=AD=E4=B9=B0=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=BE=93=E5=85=A5=E5=B0=8F=E6=95=B0=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=95=86=E5=93=81=E8=B4=AD=E4=B9=B0?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E4=B8=BA0=E6=97=B6=EF=BC=8C=E4=BE=9D?= =?UTF-8?q?=E7=84=B6=E8=AE=A1=E7=AE=97=E4=BA=86=E8=BF=90=E8=B4=B9=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E6=B7=BB=E5=8A=A0=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=80=BB=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Shop/Services/TotalService.php | 4 +++- .../TotalServices/ShippingService.php | 1 + .../TotalServices/SumQuantityService.php | 22 +++++++++++++++++++ plugins/FlatShipping/Bootstrap.php | 10 ++++----- themes/default/product/product.blade.php | 22 ++++++++++++++++--- 5 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 beike/Shop/Services/TotalServices/SumQuantityService.php 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(); } }) - } + }, } });