llp 1 неделя назад
Родитель
Сommit
2935d740c2

+ 12 - 1
packages/Longyi/Gift/src/Http/Controllers/Admin/GiftController.php

@@ -5,6 +5,7 @@ namespace Longyi\Gift\Http\Controllers\Admin;
 use Illuminate\Http\JsonResponse;
 use Illuminate\View\View;
 use Longyi\Gift\Models\GiftCards;
+use Longyi\Gift\Models\GiftCardUsageLog;
 use Webkul\Admin\Http\Controllers\Controller;
 use Longyi\Gift\DataGrids\GiftCards\GiftCardsDataGrid;
 use Longyi\Gift\Repositories\GiftCardsRepository;
@@ -62,7 +63,17 @@ class GiftController extends Controller
         $data['remaining_giftcard_amount'] = $data['giftcard_amount'] ?? 0;
 
         $this->giftCardsRepository->create($data);
-
+        // 记录使用日志
+        GiftCardUsageLog::create([
+            'giftcard_number' => $data['giftcard_number'],
+            'customer_id' => $data['customer_id'],
+            'used_amount' => 0,
+            'balance_before' => $data['giftcard_amount'],
+            'balance_after' => $data['giftcard_amount'],
+            'action_type' => GiftCardUsageLog::ACTION_ADD,
+            'status' => 'completed',
+            'notes' => "Administrator addition",
+        ]);
         if (request()->expectsJson()) {
             return new JsonResponse([
                 'message' => '礼品卡创建成功',

+ 1 - 1
packages/Longyi/Gift/src/Listeners/OrderCancelHandler.php

@@ -57,7 +57,7 @@ class OrderCancelHandler
             'balance_after' => $giftCard->remaining_giftcard_amount,
             'action_type' => GiftCardUsageLog::ACTION_REFUND,
             'status' => 'completed',
-            'notes' => "订单 #{$order->increment_id} 取消,礼品卡余额已恢复",
+            'notes' => "order #{$order->increment_id} cancel,The balance of the gift card has been restored",
         ]);
 //        Log::channel('giftcard')->info('订单已取消,礼品卡余额已恢复', [
 //            'order_id' => $order->id,

+ 1 - 1
packages/Longyi/Gift/src/Listeners/OrderPlacedHandler.php

@@ -57,7 +57,7 @@ class OrderPlacedHandler
             'balance_after' => $giftCard->remaining_giftcard_amount,
             'action_type' => GiftCardUsageLog::ACTION_USE,
             'status' => 'completed',
-            'notes' => "订单 #{$order->increment_id} 使用礼品卡",
+            'notes' => "order #{$order->increment_id} Use a gift card",
         ]);
 //        \Log::channel('giftcard')->info('订单创建成功,礼品卡余额已扣除', [
 //            'order_id' => $order->id,

+ 2 - 0
packages/Longyi/Gift/src/Models/GiftCardUsageLog.php

@@ -38,6 +38,7 @@ class GiftCardUsageLog extends Model
     const ACTION_USE = 1;      // 使用
     const ACTION_REFUND = 2;   // 退款
     const ACTION_ADJUST = 3;   // 手动调整
+    const ACTION_ADD = 4;   // 添加
 
     /**
      * 获取关联的礼品卡
@@ -72,6 +73,7 @@ class GiftCardUsageLog extends Model
             self::ACTION_USE => '使用',
             self::ACTION_REFUND => '退款',
             self::ACTION_ADJUST => '手动调整',
+            self::ACTION_ADD => '添加',
             default => '未知',
         };
     }