setConfig(['default' => 'isolated', 'connections' => ['isolated' => ['type' => 'mysql', 'socket' => $params['socket'], 'database' => $params['database'], 'username' => 'root', 'password' => '', 'prefix' => '', 'charset' => 'utf8mb4', 'fields_strict' => true, 'debug' => false]]]); $app->instance('think\DbManager', $db); $app->instance('log', new Psr\Log\NullLogger()); $call = fn () => (new app\common\service\sharing\ShareService(1))->claim(['request_id' => $params['request_id']]); file_put_contents($params['ready'], 'ready'); $result = !empty($params['hold']) ? think\facade\Db::transaction(function () use ($params, $call) { think\facade\Db::table('bot_share_accounts')->where('user_id', 1)->lock(true)->find(); SharingMysqlSupport::hold($params); return $call(); }) : $call(); } else { $loader = require $params['laravel_autoload']; $loader->setPsr4('App\\', dirname(__DIR__, 2) . '/app'); SharingMysqlSupport::laravel($params['socket'], $params['database']); if (!empty($params['hold'])) { $held = false; Illuminate\Support\Facades\DB::listen(function ($event) use ($params, &$held) { $sync = $params['action'] === 'sync'; $targetQuery = $sync ? str_starts_with(strtolower($event->sql), 'update `bot_share_bet_facts`') : (str_contains($event->sql, 'share_accounts') && str_contains(strtolower($event->sql), 'for update')); if (!$held && $targetQuery) { $held = true; if ($sync) { $partial = Illuminate\Support\Facades\DB::table('share_bet_facts')->where('source', 'lhc_order_item')->sum('effective_amount'); file_put_contents($params['partial'], bcadd((string)$partial, '0', 10)); } SharingMysqlSupport::hold($params); } }); } file_put_contents($params['ready'], 'ready'); $result = match ($params['action']) { 'audit' => (new App\Services\Sharing\ShareClaimAuditService())->audit((int)$params['claim_id'], 'approve', 8, 'mysql concurrency fixture'), 'sync' => (new App\Services\Sharing\BetFactSynchronizer())->sync('2026-10-24', '2026-10-24', true), default => (new App\Services\Sharing\ShareSettlementService())->settle('2026-10-24'), }; } echo json_encode(['ok' => true, 'result' => $result], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR); } catch (Throwable $e) { echo json_encode(['ok' => false, 'exception' => get_class($e), 'message' => $e->getMessage()], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR); exit(1); }