This commit is contained in:
iVampireSP.com 2022-11-16 20:35:09 +08:00
parent e3c6dc42dd
commit a1d2767d4b
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
5 changed files with 73 additions and 75 deletions

View File

@ -28,7 +28,7 @@ class UserAddDrops extends Command
*
* @return int
*/
public function handle()
public function handle(): int
{
$user_id = $this->argument('user_id');
@ -40,7 +40,7 @@ public function handle()
$current_drops = $transaction->getDrops($user->id);
$this->info($user->name . ', 当前 ' . $current_drops. ' Drops');
$this->info($user->name . ', 当前 ' . $current_drops . ' Drops');
$this->info($user->name . ', 当前余额: ' . $user->balance . ' 元');
@ -48,7 +48,7 @@ public function handle()
if (!$this->confirm('确认添加 ' . $amount . ' Drops?')) {
$this->info('已取消。');
return;
return 0;
}
$transaction->increaseDrops($user->id, $amount, '管理员添加 Drops', 'console');

View File

@ -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
{

View File

@ -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);
}
}

View File

@ -13,7 +13,7 @@
<form name="charge" method="POST" target="_blank" action="{{ route('balances.store') }}"
onsubmit="return confirm('请注意: 由于计费方式的特殊性,我们不支持退款,请合理充值。')">
@csrf
<input type="number" id="amount" name="amount" value="10" min="1" max="1000" />
<input type="number" id="amount" name="amount" value="10" min="1" max="1000"/>
<button type="submit" class="btn btn-primary">充值</button>
</form>
<span> <span id="to_drops"></span> Drops</span>

View File

@ -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);