parent
27bfe41623
commit
1276d0a98b
|
|
@ -21,6 +21,7 @@ class TotalService
|
|||
'subtotal',
|
||||
'tax',
|
||||
'shipping',
|
||||
'customer_discount',
|
||||
'order_total',
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* CustomerDiscountService.php
|
||||
*
|
||||
* @copyright 2023 beikeshop.com - All Rights Reserved
|
||||
* @link https://beikeshop.com
|
||||
* @author TL <mengwb@guangda.work>
|
||||
* @created 2023-02-07 18:49:15
|
||||
* @modified 2023-02-07 18:49:15
|
||||
*/
|
||||
|
||||
namespace Beike\Shop\Services\TotalServices;
|
||||
|
||||
use Beike\Shop\Services\CheckoutService;
|
||||
|
||||
class CustomerDiscountService
|
||||
{
|
||||
/**
|
||||
* @param CheckoutService $checkout
|
||||
* @return array
|
||||
*/
|
||||
public static function getTotal(CheckoutService $checkout)
|
||||
{
|
||||
$totalService = $checkout->totalService;
|
||||
|
||||
$discountFactor = current_customer()->customerGroup->discount_factor;
|
||||
if ($discountFactor <= 0) {
|
||||
return;
|
||||
}
|
||||
if ($discountFactor > 1) {
|
||||
$discountFactor = 1;
|
||||
}
|
||||
$amount = $totalService->getSubTotal() * $discountFactor / 100;
|
||||
|
||||
$totalData = [
|
||||
'code' => 'customer_discount',
|
||||
'title' => trans('shop/carts.customer_discount'),
|
||||
'amount' => -$amount,
|
||||
'amount_format' => currency_format(-$amount),
|
||||
];
|
||||
|
||||
$totalService->amount += $totalData['amount'];
|
||||
$totalService->totals[] = $totalData;
|
||||
|
||||
return $totalData;
|
||||
}
|
||||
}
|
||||
|
|
@ -62,6 +62,12 @@
|
|||
</el-form-item>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="{{ __('admin/customer_group.discount_rate') }}">
|
||||
<el-input class="mb-0" type="number" v-model="dialog.form.discount_factor" placeholder="{{ __('admin/customer_group.discount_rate') }}">
|
||||
<template slot="append">%</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
|
||||
@if (0)
|
||||
<el-form-item label="{{ __('customer_group.level') }}">
|
||||
<el-input class="mb-0" v-model="dialog.form.level" placeholder="{{ __('customer_group.level') }}"></el-input>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ return [
|
|||
'quantity' => 'Quantity',
|
||||
'subtotal' => 'Subtotal',
|
||||
'product_total' => 'Product Total',
|
||||
'customer_discount' => 'Customer Discount',
|
||||
'order_total' => 'Order Total',
|
||||
'shipping_fee' => 'Shipping Fee',
|
||||
'all' => 'All',
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ return [
|
|||
'quantity' => '数量',
|
||||
'subtotal' => '小计',
|
||||
'product_total' => '商品总计',
|
||||
'customer_discount' => '会员优惠',
|
||||
'order_total' => '应付总金额',
|
||||
'shipping_fee' => '运费',
|
||||
'all' => '全部',
|
||||
|
|
|
|||
Loading…
Reference in New Issue