llp 1 settimana fa
parent
commit
dba9ccadca
2 ha cambiato i file con 31 aggiunte e 1 eliminazioni
  1. 7 1
      config/logging.php
  2. 24 0
      packages/Longyi/Gift/src/Models/GiftCards.php

+ 7 - 1
config/logging.php

@@ -64,7 +64,13 @@ return [
             'level'                => env('LOG_LEVEL', 'debug'),
             'level'                => env('LOG_LEVEL', 'debug'),
             'replace_placeholders' => true,
             'replace_placeholders' => true,
         ],
         ],
-
+        'giftcard' => [
+            'driver'               => 'daily',
+            'path'                 => storage_path('logs/giftcard.log'),
+            'level'                => 'info',
+            'days'                 => 14,
+            'replace_placeholders' => true,
+        ],
         'daily' => [
         'daily' => [
             'driver'               => 'daily',
             'driver'               => 'daily',
             'path'                 => storage_path('logs/laravel.log'),
             'path'                 => storage_path('logs/laravel.log'),

+ 24 - 0
packages/Longyi/Gift/src/Models/GiftCards.php

@@ -31,6 +31,30 @@ class GiftCards extends Model implements GiftCardsContract
         'customer_id' => 'integer',
         'customer_id' => 'integer',
         'expirationdate' => 'date',
         'expirationdate' => 'date',
     ];
     ];
+    protected static function booted()
+    {
+        // 监听保存后事件
+        static::saved(function ($giftCard) {
+            // 在这里添加你的逻辑
+            // 例如:记录日志、发送通知等
+            $original = $giftCard->getOriginal();
+            $amountStr = '';
+            $amount = 0;
+            if (isset($original['remaining_giftcard_amount'])) {
+                $amount = $original['remaining_giftcard_amount'] - $giftCard->remaining_giftcard_amount;
+            }
+            if ($amount > 0) {
+                $amountStr .= '-' . abs($amount);
+            } else {
+                $amountStr .= '+' . abs($amount);
+            }
+            \Log::channel('giftcard')->info('礼品卡已更新', [
+                'giftcard_number' => $giftCard->giftcard_number,
+                'used_amount' => $amountStr,
+                'remaining_amount' => $giftCard->remaining_giftcard_amount,
+            ]);
+        });
+    }
 
 
     public static function setGiftCardCode($giftcard)
     public static function setGiftCardCode($giftcard)
     {
     {