llp před 5 dny
rodič
revize
46f01f7a46

+ 11 - 5
packages/Longyi/Gift/src/Services/GiftCardService.php

@@ -10,9 +10,13 @@ class GiftCardService
     /**
     /**
      * 激活礼品卡
      * 激活礼品卡
      */
      */
-    public function activate(string $code): void
+    public function activate(string $code, ?int $customerId = null): void
     {
     {
-        $customerId = auth()->user()->id;
+        $customerId = $customerId ?? auth()->user()?->id;
+
+        if (! $customerId) {
+            throw new \Exception('Customer not authenticated.');
+        }
 
 
         $giftCard = GiftCards::where('giftcard_number', $code)
         $giftCard = GiftCards::where('giftcard_number', $code)
             ->where('customer_id', $customerId)
             ->where('customer_id', $customerId)
@@ -39,20 +43,22 @@ class GiftCardService
     /**
     /**
      * 删除礼品卡
      * 删除礼品卡
      */
      */
-    public function remove(): void
+    public function remove(?int $customerId = null): void
     {
     {
+        $customerId = $customerId ?? auth()->user()?->id;
+
         $cart = Cart::getCart();
         $cart = Cart::getCart();
 
 
         GiftCards::removeGiftCardCode();
         GiftCards::removeGiftCardCode();
 
 
         Cart::collectTotals();
         Cart::collectTotals();
 
 
-        if ($cart->giftcard_number) {
+        if ($cart->giftcard_number && $customerId) {
             $giftCard = GiftCards::where(
             $giftCard = GiftCards::where(
                 'giftcard_number',
                 'giftcard_number',
                 $cart->giftcard_number
                 $cart->giftcard_number
             )
             )
-            ->where('customer_id', auth()->user()->id)
+            ->where('customer_id', $customerId)
             ->first();
             ->first();
 
 
             if ($giftCard) {
             if ($giftCard) {

+ 49 - 0
packages/Webkul/BagistoApi/src/Dto/CartData.php

@@ -94,6 +94,42 @@ class CartData
     #[ApiProperty(description: 'Applied coupon code')]
     #[ApiProperty(description: 'Applied coupon code')]
     public ?string $couponCode = null;
     public ?string $couponCode = null;
 
 
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Applied gift card number')]
+    public ?string $giftcardNumber = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Gift card discount amount')]
+    public ?float $giftcardAmount = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Base gift card discount amount')]
+    public ?float $baseGiftcardAmount = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Formatted gift card discount amount')]
+    public ?string $formattedGiftcardAmount = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Remaining gift card balance after use')]
+    public ?float $remainingGiftcardAmount = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Formatted remaining gift card balance')]
+    public ?string $formattedRemainingGiftcardAmount = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'VIP member discount amount')]
+    public ?float $vipPlusAmount = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Base VIP member discount amount')]
+    public ?float $baseVipPlusAmount = null;
+
+    #[Groups(['query', 'mutation'])]
+    #[ApiProperty(description: 'Formatted VIP member discount amount')]
+    public ?string $formattedVipPlusAmount = null;
+
     #[Groups(['query', 'mutation'])]
     #[Groups(['query', 'mutation'])]
     public ?bool $success = null;
     public ?bool $success = null;
 
 
@@ -264,6 +300,19 @@ class CartData
             (is_string($cart->additional) ? json_decode($cart->additional, true) : $cart->additional) : [];
             (is_string($cart->additional) ? json_decode($cart->additional, true) : $cart->additional) : [];
         $data->couponCode = $additional['coupon_code'] ?? null;
         $data->couponCode = $additional['coupon_code'] ?? null;
 
 
+        // Gift card
+        $data->giftcardNumber = $cart->giftcard_number ?? null;
+        $data->giftcardAmount = (float) ($cart->giftcard_amount ?? 0);
+        $data->baseGiftcardAmount = (float) ($cart->base_giftcard_amount ?? 0);
+        $data->formattedGiftcardAmount = core()->currency($cart->giftcard_amount ?? 0);
+        $data->remainingGiftcardAmount = (float) ($cart->remaining_giftcard_amount ?? 0);
+        $data->formattedRemainingGiftcardAmount = core()->currency($cart->remaining_giftcard_amount ?? 0);
+
+        // VIP member discount
+        $data->vipPlusAmount = (float) ($cart->vip_plus_amount ?? 0);
+        $data->baseVipPlusAmount = (float) ($cart->base_vip_plus_amount ?? 0);
+        $data->formattedVipPlusAmount = core()->currency($cart->vip_plus_amount ?? 0);
+
         if ($cart->billing_address) {
         if ($cart->billing_address) {
             $data->billingAddress = [
             $data->billingAddress = [
                 'id'        => $cart->billing_address->id,
                 'id'        => $cart->billing_address->id,

+ 18 - 0
packages/Webkul/BagistoApi/src/Resources/config/serializer/CartData.yaml

@@ -61,6 +61,24 @@ Webkul\BagistoApi\Dto\CartData:
       type: string
       type: string
     couponCode:
     couponCode:
       type: string
       type: string
+    giftcardNumber:
+      type: string
+    giftcardAmount:
+      type: float
+    baseGiftcardAmount:
+      type: float
+    formattedGiftcardAmount:
+      type: string
+    remainingGiftcardAmount:
+      type: float
+    formattedRemainingGiftcardAmount:
+      type: string
+    vipPlusAmount:
+      type: float
+    baseVipPlusAmount:
+      type: float
+    formattedVipPlusAmount:
+      type: string
     isGuest:
     isGuest:
       type: bool
       type: bool
     itemsQty:
     itemsQty:

+ 3 - 3
packages/Webkul/BagistoApi/src/State/SaveCheckoutCartProcessor.php

@@ -182,8 +182,10 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
     {
     {
         $code = trim($code);
         $code = trim($code);
 
 
+        $customerId = Cart::getCart()?->customer_id;
+
         if ($code === '') {
         if ($code === '') {
-            $this->giftCardService->remove();
+            $this->giftCardService->remove($customerId);
 
 
             return;
             return;
         }
         }
@@ -192,8 +194,6 @@ class SaveCheckoutCartProcessor implements ProcessorInterface
             return;
             return;
         }
         }
 
 
-        $customerId = Cart::getCart()?->customer_id;
-
         if (! $customerId) {
         if (! $customerId) {
             throw new OperationFailedException(__('bagistoapi::app.graphql.checkout.customer-not-found'));
             throw new OperationFailedException(__('bagistoapi::app.graphql.checkout.customer-not-found'));
         }
         }