From 4ec7cee4fbf911b9ea61925d977c4ac5309b1545 Mon Sep 17 00:00:00 2001 From: liufei Date: Tue, 12 Dec 2023 17:00:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=8F=91=E6=94=BE=E5=A5=96=E5=8A=B1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend.php | 5 +++- src/Event/MoneyAllHistoryEvent.php | 21 +++++++++++++ src/Listeners/MoneyAllHistoryListeners.php | 34 ++++++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/Event/MoneyAllHistoryEvent.php create mode 100644 src/Listeners/MoneyAllHistoryListeners.php diff --git a/extend.php b/extend.php index 9fa4f0e..dcb321a 100644 --- a/extend.php +++ b/extend.php @@ -11,6 +11,8 @@ use Flarum\Extend; +use Mattoid\MoneyHistory\Event\MoneyAllHistoryEvent; +use Mattoid\MoneyHistory\Listeners\MoneyAllHistoryListeners; use Mattoid\MoneyHistory\Listeners\MoneyHistoryListeners; use Mattoid\MoneyHistory\Event\MoneyHistoryEvent; @@ -24,5 +26,6 @@ new Extend\Locales(__DIR__.'/locale'), (new Extend\Event()) - ->listen(MoneyHistoryEvent::class, MoneyHistoryListeners::class), + ->listen(MoneyHistoryEvent::class, MoneyHistoryListeners::class) + ->listen(MoneyAllHistoryEvent::class, MoneyAllHistoryListeners::class), ]; diff --git a/src/Event/MoneyAllHistoryEvent.php b/src/Event/MoneyAllHistoryEvent.php new file mode 100644 index 0000000..c7a4632 --- /dev/null +++ b/src/Event/MoneyAllHistoryEvent.php @@ -0,0 +1,21 @@ +list = $list; + $this->money = $money; + $this->source = $source; + $this->sourceDesc = $sourceDesc; + } + +} diff --git a/src/Listeners/MoneyAllHistoryListeners.php b/src/Listeners/MoneyAllHistoryListeners.php new file mode 100644 index 0000000..d0a93a1 --- /dev/null +++ b/src/Listeners/MoneyAllHistoryListeners.php @@ -0,0 +1,34 @@ +source = $event->source; + $this->sourceDesc = $event->sourceDesc; + $insert = []; + + foreach ($event->list as $item) { + $insert[] = [ + "user_id" => $item->id, + "type" => $event->money > 0 ? "C" : "D", + "money" => $event->money > 0 ? $event->money : -$event->money, + "source" => $this->source, + "source_desc" => $this->sourceDesc, + "balance_money" => isset($item->init_money) ? $item->init_money : $item->money - $event->money, + "last_money" => $event->money, + "create_user_id" => isset($item->create_user_id) ? $item->create_user_id : $item->id, + "change_time" => Date("Y-m-d H:i:s") + ]; + } + + UserMoneyHistory::query()->insert($insert); + } +}