feat: 扩展奖池、风控与报表能力,新增对账补偿、广播和人工操作接口
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Jackpot;
|
||||
|
||||
use App\Models\JackpotPool;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\JackpotPayoutLog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
final class AdminJackpotPoolManualBurstController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request, JackpotPool $pool): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'draw_id' => 'required|integer|exists:draws,id',
|
||||
'amount' => 'nullable|integer|min:1',
|
||||
]);
|
||||
|
||||
$payload = DB::transaction(function () use ($pool, $data): array {
|
||||
/** @var JackpotPool $locked */
|
||||
$locked = JackpotPool::query()->whereKey($pool->id)->lockForUpdate()->firstOrFail();
|
||||
$poolBefore = (int) $locked->current_amount;
|
||||
$amount = isset($data['amount']) ? min((int) $data['amount'], $poolBefore) : $poolBefore;
|
||||
|
||||
if ($amount <= 0) {
|
||||
return [
|
||||
'current_amount' => $poolBefore,
|
||||
'burst_amount' => 0,
|
||||
'log_id' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$drawId = (int) $data['draw_id'];
|
||||
|
||||
$locked->forceFill([
|
||||
'current_amount' => $poolBefore - $amount,
|
||||
'last_trigger_draw_id' => $drawId,
|
||||
])->save();
|
||||
|
||||
$log = JackpotPayoutLog::query()->create([
|
||||
'draw_id' => $drawId,
|
||||
'jackpot_pool_id' => $locked->id,
|
||||
'trigger_type' => 'manual',
|
||||
'total_payout_amount' => $amount,
|
||||
'winner_count' => 0,
|
||||
'trigger_snapshot_json' => [
|
||||
'pool_amount_before' => $poolBefore,
|
||||
'manual' => true,
|
||||
],
|
||||
]);
|
||||
|
||||
return [
|
||||
'current_amount' => (int) $locked->current_amount,
|
||||
'burst_amount' => $amount,
|
||||
'log_id' => (int) $log->id,
|
||||
];
|
||||
});
|
||||
|
||||
return ApiResponse::success($payload);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user