service = $service; } public function handle(): int { $today = Carbon::today(); $dateStr = $today->format('Y-m-d'); $dateId = $today->format('Ymd'); try { // 1. 计算当日总流水(TotalBet)并取 1/10 作为奖池 $roomRow = DB::table('QPRecordDB.dbo.RecordGameRoomDayInfo') ->where('DateID', $dateId) ->where('SortID', -1) ->selectRaw('SUM(TotalBet) AS flowing_water_new') ->first(); $flowing = $roomRow && isset($roomRow->flowing_water_new) ? (int)$roomRow->flowing_water_new : 0; // 奖池 = 总流水的 1/10(内部单位),向下取整 $poolAmount = (int)floor($flowing / 4); // 2. 确保当日 superball_daily 记录存在 DB::connection('write')->transaction(function () use ($dateStr, $poolAmount, $today) { // getOrCreateDaily 已经保证有一条记录(带 lucky_number),此处再加锁更新 $daily = DB::connection('write')->table(TableName::agent() . 'superball_daily') ->where('pool_date', $dateStr) ->lockForUpdate() ->first(); if (!$daily) { $this->service->getOrCreateDaily($dateStr); $daily = DB::connection('write')->table(TableName::agent() . 'superball_daily') ->where('pool_date', $dateStr) ->lockForUpdate() ->first(); } // 3. 计算本次要增加的 completed_count 和 total_balls $hour = (int)$today->format('G'); // 0-23 if ($hour < 1) { // 00:00 - 00:59 $completedInc = mt_rand(5, 10); $multipliers = [1, 2, 3, 6]; } else { // 01:00 以后 $completedInc = mt_rand(10, 20); $multipliers = [3,6,10,30]; } $multiplier = $multipliers[array_rand($multipliers)]; $ballsInc = $completedInc * $multiplier; DB::connection('write')->table(TableName::agent() . 'superball_daily') ->where('pool_date', $dateStr) ->update([ 'pool_amount' => $poolAmount, 'completed_count' => (int)$daily->completed_count + $completedInc, 'total_balls' => (int)$daily->total_balls + $ballsInc, 'updated_at' => now()->format('Y-m-d H:i:s'), ]); }); \Log::info("Superball pool stats updated for {$dateStr}, pool_amount={$poolAmount}"); return true; } catch (\Throwable $e) { \Log::error('Superball update pool stats failed: ' . $e->getMessage()); \Log::error('Superball update pool stats', [ 'date' => $dateStr, 'error' => $e->getMessage(), ]); return false; } } }