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); + } +}