改进 计费
This commit is contained in:
parent
a9ef38ff5f
commit
a5fef1c695
@ -76,16 +76,9 @@ public function getDrops($user_id = null)
|
|||||||
|
|
||||||
$decimal = config('drops.decimal');
|
$decimal = config('drops.decimal');
|
||||||
|
|
||||||
// 计算需要乘以多少
|
|
||||||
$multiple = 1;
|
|
||||||
for ($i = 0; $i < $decimal; $i++) {
|
|
||||||
$multiple *= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
$drops = Cache::get($cache_key);
|
$drops = Cache::get($cache_key);
|
||||||
|
|
||||||
// 除以 $multiple
|
$drops = $drops / $decimal;
|
||||||
$drops = $drops / $multiple;
|
|
||||||
|
|
||||||
return $drops;
|
return $drops;
|
||||||
}
|
}
|
||||||
@ -108,17 +101,11 @@ public function increaseDrops($user_id, $amount = 0)
|
|||||||
|
|
||||||
$decimal = config('drops.decimal');
|
$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);
|
$drops = Cache::increment($cache_key, $amount);
|
||||||
|
|
||||||
|
|
||||||
return $drops;
|
return $drops;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,23 +116,18 @@ public function reduceDrops($user_id, $amount = 0, $description = null)
|
|||||||
|
|
||||||
$decimal = config('drops.decimal');
|
$decimal = config('drops.decimal');
|
||||||
|
|
||||||
// 计算需要乘以多少
|
|
||||||
$multiple = 1;
|
|
||||||
for ($i = 0; $i < $decimal; $i++) {
|
|
||||||
$multiple *= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
$month = now()->month;
|
$month = now()->month;
|
||||||
|
|
||||||
Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
||||||
|
|
||||||
$amount = $amount * $multiple;
|
$amount = $amount * $decimal;
|
||||||
|
|
||||||
$drops = Cache::decrement($cache_key, $amount);
|
$drops = Cache::decrement($cache_key, $amount);
|
||||||
|
|
||||||
// (new App\Models\Transaction)->create(['name' => 1]);
|
// (new App\Models\Transaction)->create(['name' => 1]);
|
||||||
|
|
||||||
$this->addPayoutDrops($user_id, $amount, $description);
|
$this->addPayoutDrops($user_id, $amount / $decimal, $description);
|
||||||
|
|
||||||
return $drops;
|
return $drops;
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'rate' => 1000,
|
'rate' => 1000,
|
||||||
'decimal' => 5,
|
'decimal' => 10000,
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user