optimize
This commit is contained in:
parent
e3c6dc42dd
commit
a1d2767d4b
@ -28,7 +28,7 @@ class UserAddDrops extends Command
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
public function handle(): int
|
||||
{
|
||||
|
||||
$user_id = $this->argument('user_id');
|
||||
@ -48,7 +48,7 @@ public function handle()
|
||||
|
||||
if (!$this->confirm('确认添加 ' . $amount . ' Drops?')) {
|
||||
$this->info('已取消。');
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
$transaction->increaseDrops($user->id, $amount, '管理员添加 Drops', 'console');
|
||||
|
@ -6,7 +6,6 @@
|
||||
use App\Http\Requests\Remote\WorkOrderRequest;
|
||||
use App\Models\WorkOrder\WorkOrder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WorkOrderController extends Controller
|
||||
{
|
||||
|
@ -91,71 +91,18 @@ public function increaseDrops($user_id, $amount, $description = null, $payment =
|
||||
return $current_drops['drops'];
|
||||
}
|
||||
|
||||
public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount = 0)
|
||||
{
|
||||
|
||||
$cache_key = 'user_drops_' . $user_id;
|
||||
|
||||
$current_drops = Cache::get($cache_key, [
|
||||
'drops' => 0,
|
||||
]);
|
||||
|
||||
$current_drops['drops'] = $current_drops['drops'] - $amount;
|
||||
|
||||
$current_drops['drops'] = round($current_drops['drops'], 5);
|
||||
|
||||
Cache::forever($cache_key, $current_drops);
|
||||
|
||||
if ($auto) {
|
||||
$description = '平台按时间自动扣费。';
|
||||
} else {
|
||||
$description = '集成模块发起的扣费。';
|
||||
}
|
||||
|
||||
// $this->addPayoutDrops($user_id, $amount, $description, $host_id, $module_id);
|
||||
}
|
||||
|
||||
public function reduceDropsWithoutHost($user_id, $amount = 0, $description = null)
|
||||
{
|
||||
|
||||
$cache_key = 'user_drops_' . $user_id;
|
||||
|
||||
$current_drops = Cache::get($cache_key, [
|
||||
'drops' => 0,
|
||||
]);
|
||||
|
||||
$current_drops['drops'] = $current_drops['drops'] - $amount;
|
||||
|
||||
$current_drops['drops'] = round($current_drops['drops'], 5);
|
||||
|
||||
Cache::forever($cache_key, $current_drops);
|
||||
|
||||
$this->addPayoutDrops($user_id, $amount, $description, null, null);
|
||||
}
|
||||
|
||||
public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id)
|
||||
public function addIncomeDrops($user_id, $amount, $description, $payment = 'balance')
|
||||
{
|
||||
$data = [
|
||||
'type' => 'payout',
|
||||
'payment' => 'drops',
|
||||
'type' => 'income',
|
||||
'payment' => $payment,
|
||||
'description' => $description,
|
||||
'income' => 0,
|
||||
'income_drops' => 0,
|
||||
'income_drops' => (float)$amount,
|
||||
'outcome' => 0,
|
||||
'outcome_drops' => (float)$amount,
|
||||
'host_id' => $host_id,
|
||||
'module_id' => $module_id,
|
||||
'outcome_drops' => 0,
|
||||
];
|
||||
|
||||
|
||||
// $amount = (double) $amount;
|
||||
|
||||
// Log::debug($amount);
|
||||
|
||||
// $month = now()->month;
|
||||
|
||||
// Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
||||
|
||||
return $this->addLog($user_id, $data);
|
||||
}
|
||||
|
||||
@ -198,19 +145,28 @@ public function getDrops($user_id = null): float
|
||||
return $drops['drops'];
|
||||
}
|
||||
|
||||
public function addIncomeDrops($user_id, $amount, $description, $payment = 'balance')
|
||||
public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount = 0)
|
||||
{
|
||||
$data = [
|
||||
'type' => 'income',
|
||||
'payment' => $payment,
|
||||
'description' => $description,
|
||||
'income' => 0,
|
||||
'income_drops' => (float)$amount,
|
||||
'outcome' => 0,
|
||||
'outcome_drops' => 0,
|
||||
];
|
||||
|
||||
return $this->addLog($user_id, $data);
|
||||
$cache_key = 'user_drops_' . $user_id;
|
||||
|
||||
$current_drops = Cache::get($cache_key, [
|
||||
'drops' => 0,
|
||||
]);
|
||||
|
||||
$current_drops['drops'] = $current_drops['drops'] - $amount;
|
||||
|
||||
$current_drops['drops'] = round($current_drops['drops'], 5);
|
||||
|
||||
Cache::forever($cache_key, $current_drops);
|
||||
|
||||
if ($auto) {
|
||||
$description = '平台按时间自动扣费。';
|
||||
} else {
|
||||
$description = '集成模块发起的扣费。';
|
||||
}
|
||||
|
||||
// $this->addPayoutDrops($user_id, $amount, $description, $host_id, $module_id);
|
||||
}
|
||||
|
||||
public function reduceAmount($user_id, $amount = 0, $description = '扣除费用请求。')
|
||||
@ -420,4 +376,48 @@ public function transferDrops(User $user, User $to, float $amount, string|null $
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function reduceDropsWithoutHost($user_id, $amount = 0, $description = null)
|
||||
{
|
||||
|
||||
$cache_key = 'user_drops_' . $user_id;
|
||||
|
||||
$current_drops = Cache::get($cache_key, [
|
||||
'drops' => 0,
|
||||
]);
|
||||
|
||||
$current_drops['drops'] = $current_drops['drops'] - $amount;
|
||||
|
||||
$current_drops['drops'] = round($current_drops['drops'], 5);
|
||||
|
||||
Cache::forever($cache_key, $current_drops);
|
||||
|
||||
$this->addPayoutDrops($user_id, $amount, $description, null, null);
|
||||
}
|
||||
|
||||
public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id)
|
||||
{
|
||||
$data = [
|
||||
'type' => 'payout',
|
||||
'payment' => 'drops',
|
||||
'description' => $description,
|
||||
'income' => 0,
|
||||
'income_drops' => 0,
|
||||
'outcome' => 0,
|
||||
'outcome_drops' => (float)$amount,
|
||||
'host_id' => $host_id,
|
||||
'module_id' => $module_id,
|
||||
];
|
||||
|
||||
|
||||
// $amount = (double) $amount;
|
||||
|
||||
// Log::debug($amount);
|
||||
|
||||
// $month = now()->month;
|
||||
|
||||
// Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
||||
|
||||
return $this->addLog($user_id, $data);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@
|
||||
Route::delete('deleteAll', [AuthController::class, 'deleteAll'])->name('deleteAll');
|
||||
|
||||
|
||||
|
||||
Route::get('transactions', [BalanceController::class, 'transactions'])->name('transactions');
|
||||
Route::resource('balances', BalanceController::class);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user