This commit is contained in:
iVampireSP.com 2022-10-09 14:53:25 +08:00
parent 0be5144254
commit 6d75d872ce
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 21 additions and 1 deletions

View File

@ -68,6 +68,12 @@ public function usages()
$month_cache_key = 'user_' . auth()->id() . '_month_' . $month . '_hosts_drops';
$hosts_drops = Cache::get($month_cache_key, []);
return $this->success($hosts_drops);
$month_cache_key = 'user_' . auth()->id() . '_month_' . $month . '_hosts_balances';
$hosts_balances = Cache::get($month_cache_key, []);
return $this->success([
'drops' => $hosts_drops,
'balances' => $hosts_balances
]);
}
}

View File

@ -157,6 +157,20 @@ public function costBalance($amount = 1)
{
$transaction = new Transaction();
$month = now()->month;
$month_cache_key = 'user_' . $this->user_id . '_month_' . $month . '_hosts_balances';
$hosts_drops = Cache::get($month_cache_key, []);
// 统计 Host 消耗的 Drops
if (isset($hosts_drops[$this->id])) {
$hosts_drops[$this->id] += $amount;
} else {
$hosts_drops[$this->id] = $amount;
}
Cache::put($month_cache_key, $hosts_drops, 604800);
$left = $transaction->reduceAmount($this->user_id, $amount);
broadcast(new UserEvent($this->user_id, 'balances.amount.reduced', $this->user));