修复:商品详情 - 购买数量可以输入小数

修复:商品购买数量为0时,依然计算了运费
添加:添加商品总数量统计
This commit is contained in:
wuhui_zzw 2023-08-22 17:43:16 +08:00
parent 270623a9ad
commit 399bff4def
5 changed files with 50 additions and 9 deletions

View File

@ -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}";

View File

@ -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']);

View File

@ -0,0 +1,22 @@
<?php
namespace Beike\Shop\Services\TotalServices;
use Beike\Shop\Services\CheckoutService;
class SumQuantityService{
public static function getTotal(CheckoutService $checkout): ?array{
$totalService = $checkout->totalService;
$sumQuantity = $totalService->countProducts();
$totalData = [
'code' => 'sum_quantity',
'title' => trans('admin/dashboard.product_total'),
'amount' => $sumQuantity,
'amount_format' => $sumQuantity,
];
$totalService->totals[] = $totalData;
return $totalData;
}
}

View File

@ -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;
}
}

View File

@ -239,7 +239,12 @@
</div>
{{-- 购买数量 - 单规格 --}}
<div class="quantity-wrap mb-4" v-if="Object.keys(source.skus).length <= 1">
<input type="text" class="form-control" :disabled="!product.quantity" onkeyup="this.value=this.value.replace(/\D/g,'')" v-model="quantity" name="quantity">
<input type="text"
class="form-control"
:disabled="!product.quantity"
:value="quantity"
@input="singleQuantityChange($event)"
name="quantity">
<div class="right" v-if="!isNumSelect">
<i class="bi bi-chevron-up"></i>
<i class="bi bi-chevron-down"></i>
@ -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();
}
})
}
},
}
});