Skip to content

Commit

Permalink
新增 批量发放奖励功能
Browse files Browse the repository at this point in the history
  • Loading branch information
liufei-ereach committed Dec 12, 2023
1 parent a969a3f commit 4ec7cee
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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),
];
21 changes: 21 additions & 0 deletions src/Event/MoneyAllHistoryEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Mattoid\MoneyHistory\Event;

class MoneyAllHistoryEvent
{

public $list;
public $money;
public $source;
public $sourceDesc;

public function __construct($list = array(), $money = 0, $source = "", $sourceDesc = "")
{
$this->list = $list;
$this->money = $money;
$this->source = $source;
$this->sourceDesc = $sourceDesc;
}

}
34 changes: 34 additions & 0 deletions src/Listeners/MoneyAllHistoryListeners.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Mattoid\MoneyHistory\Listeners;

use Mattoid\MoneyHistory\Event\MoneyAllHistoryEvent;
use Mattoid\MoneyHistory\model\UserMoneyHistory;

class MoneyAllHistoryListeners extends HistoryListeners
{
protected $source;
protected $sourceDesc;

public function handle(MoneyAllHistoryEvent $event) {
$this->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);
}
}

0 comments on commit 4ec7cee

Please sign in to comment.