|
@@ -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)
|
|
|
{
|
|
{
|