From 1276d0a98bdfc433c4e87e2bc1a22abbd698f21d Mon Sep 17 00:00:00 2001 From: TL Date: Wed, 8 Feb 2023 15:05:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=BB=84=E6=8A=98=E6=89=A3?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 客户组编辑释放出折扣率 会员组折扣 客户组折扣 wip 会员组折扣 会员组折扣 --- beike/Shop/Services/TotalService.php | 1 + .../TotalServices/CustomerDiscountService.php | 47 +++++++++++++++++++ .../pages/customer_groups/index.blade.php | 6 +++ resources/lang/en/shop/carts.php | 1 + resources/lang/zh_cn/shop/carts.php | 1 + 5 files changed, 56 insertions(+) create mode 100644 beike/Shop/Services/TotalServices/CustomerDiscountService.php diff --git a/beike/Shop/Services/TotalService.php b/beike/Shop/Services/TotalService.php index c03236aa..84b6c834 100644 --- a/beike/Shop/Services/TotalService.php +++ b/beike/Shop/Services/TotalService.php @@ -21,6 +21,7 @@ class TotalService 'subtotal', 'tax', 'shipping', + 'customer_discount', 'order_total', ]; diff --git a/beike/Shop/Services/TotalServices/CustomerDiscountService.php b/beike/Shop/Services/TotalServices/CustomerDiscountService.php new file mode 100644 index 00000000..e32134a5 --- /dev/null +++ b/beike/Shop/Services/TotalServices/CustomerDiscountService.php @@ -0,0 +1,47 @@ + + * @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; + } +} diff --git a/resources/beike/admin/views/pages/customer_groups/index.blade.php b/resources/beike/admin/views/pages/customer_groups/index.blade.php index 20ba15e9..1872fa56 100644 --- a/resources/beike/admin/views/pages/customer_groups/index.blade.php +++ b/resources/beike/admin/views/pages/customer_groups/index.blade.php @@ -62,6 +62,12 @@ + + + + + + @if (0) diff --git a/resources/lang/en/shop/carts.php b/resources/lang/en/shop/carts.php index ca7bc4f1..097e17d2 100644 --- a/resources/lang/en/shop/carts.php +++ b/resources/lang/en/shop/carts.php @@ -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', diff --git a/resources/lang/zh_cn/shop/carts.php b/resources/lang/zh_cn/shop/carts.php index 6d6b8afa..df517dc2 100644 --- a/resources/lang/zh_cn/shop/carts.php +++ b/resources/lang/zh_cn/shop/carts.php @@ -17,6 +17,7 @@ return [ 'quantity' => '数量', 'subtotal' => '小计', 'product_total' => '商品总计', + 'customer_discount' => '会员优惠', 'order_total' => '应付总金额', 'shipping_fee' => '运费', 'all' => '全部',