From a5fef1c695be3deb7c9521071430fd4373a0988d Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Thu, 15 Sep 2022 13:09:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20=E8=AE=A1=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Transaction.php | 26 ++++---------------------- config/drops.php | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index fc98070..5d2b950 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -76,16 +76,9 @@ public function getDrops($user_id = null) $decimal = config('drops.decimal'); - // 计算需要乘以多少 - $multiple = 1; - for ($i = 0; $i < $decimal; $i++) { - $multiple *= 10; - } - $drops = Cache::get($cache_key); - // 除以 $multiple - $drops = $drops / $multiple; + $drops = $drops / $decimal; return $drops; } @@ -108,17 +101,11 @@ public function increaseDrops($user_id, $amount = 0) $decimal = config('drops.decimal'); - // 计算需要乘以多少 - $multiple = 1; - for ($i = 0; $i < $decimal; $i++) { - $multiple *= 10; - } - $amount = $amount * $multiple; + $amount = $amount * $decimal; $drops = Cache::increment($cache_key, $amount); - return $drops; } @@ -129,23 +116,18 @@ public function reduceDrops($user_id, $amount = 0, $description = null) $decimal = config('drops.decimal'); - // 计算需要乘以多少 - $multiple = 1; - for ($i = 0; $i < $decimal; $i++) { - $multiple *= 10; - } $month = now()->month; Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount); - $amount = $amount * $multiple; + $amount = $amount * $decimal; $drops = Cache::decrement($cache_key, $amount); // (new App\Models\Transaction)->create(['name' => 1]); - $this->addPayoutDrops($user_id, $amount, $description); + $this->addPayoutDrops($user_id, $amount / $decimal, $description); return $drops; } diff --git a/config/drops.php b/config/drops.php index 5350ad8..0e5dd20 100644 --- a/config/drops.php +++ b/config/drops.php @@ -2,5 +2,5 @@ return [ 'rate' => 1000, - 'decimal' => 5, + 'decimal' => 10000, ];