optimize
This commit is contained in:
parent
e3c6dc42dd
commit
a1d2767d4b
@ -28,7 +28,7 @@ class UserAddDrops extends Command
|
|||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle(): int
|
||||||
{
|
{
|
||||||
|
|
||||||
$user_id = $this->argument('user_id');
|
$user_id = $this->argument('user_id');
|
||||||
@ -40,7 +40,7 @@ public function handle()
|
|||||||
|
|
||||||
$current_drops = $transaction->getDrops($user->id);
|
$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 . ' 元');
|
$this->info($user->name . ', 当前余额: ' . $user->balance . ' 元');
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public function handle()
|
|||||||
|
|
||||||
if (!$this->confirm('确认添加 ' . $amount . ' Drops?')) {
|
if (!$this->confirm('确认添加 ' . $amount . ' Drops?')) {
|
||||||
$this->info('已取消。');
|
$this->info('已取消。');
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$transaction->increaseDrops($user->id, $amount, '管理员添加 Drops', 'console');
|
$transaction->increaseDrops($user->id, $amount, '管理员添加 Drops', 'console');
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
use App\Http\Requests\Remote\WorkOrderRequest;
|
use App\Http\Requests\Remote\WorkOrderRequest;
|
||||||
use App\Models\WorkOrder\WorkOrder;
|
use App\Models\WorkOrder\WorkOrder;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class WorkOrderController extends Controller
|
class WorkOrderController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -91,71 +91,18 @@ public function increaseDrops($user_id, $amount, $description = null, $payment =
|
|||||||
return $current_drops['drops'];
|
return $current_drops['drops'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount = 0)
|
public function addIncomeDrops($user_id, $amount, $description, $payment = 'balance')
|
||||||
{
|
|
||||||
|
|
||||||
$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)
|
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'type' => 'payout',
|
'type' => 'income',
|
||||||
'payment' => 'drops',
|
'payment' => $payment,
|
||||||
'description' => $description,
|
'description' => $description,
|
||||||
'income' => 0,
|
'income' => 0,
|
||||||
'income_drops' => 0,
|
'income_drops' => (float)$amount,
|
||||||
'outcome' => 0,
|
'outcome' => 0,
|
||||||
'outcome_drops' => (float)$amount,
|
'outcome_drops' => 0,
|
||||||
'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);
|
return $this->addLog($user_id, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,19 +145,28 @@ public function getDrops($user_id = null): float
|
|||||||
return $drops['drops'];
|
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 = '扣除费用请求。')
|
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,7 @@
|
|||||||
<form name="charge" method="POST" target="_blank" action="{{ route('balances.store') }}"
|
<form name="charge" method="POST" target="_blank" action="{{ route('balances.store') }}"
|
||||||
onsubmit="return confirm('请注意: 由于计费方式的特殊性,我们不支持退款,请合理充值。')">
|
onsubmit="return confirm('请注意: 由于计费方式的特殊性,我们不支持退款,请合理充值。')">
|
||||||
@csrf
|
@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>
|
<button type="submit" class="btn btn-primary">充值</button>
|
||||||
</form>
|
</form>
|
||||||
<span>≈ <span id="to_drops"></span> Drops</span>
|
<span>≈ <span id="to_drops"></span> Drops</span>
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
Route::delete('deleteAll', [AuthController::class, 'deleteAll'])->name('deleteAll');
|
Route::delete('deleteAll', [AuthController::class, 'deleteAll'])->name('deleteAll');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Route::get('transactions', [BalanceController::class, 'transactions'])->name('transactions');
|
Route::get('transactions', [BalanceController::class, 'transactions'])->name('transactions');
|
||||||
Route::resource('balances', BalanceController::class);
|
Route::resource('balances', BalanceController::class);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user