| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- // No application bootstrap, .env, provider or pre-existing database is loaded by this worker.
- error_reporting(E_ALL & ~E_DEPRECATED);
- require __DIR__ . '/sharing_mysql_support.php';
- use Tests\Fixtures\SharingMysqlSupport;
- $params = json_decode($argv[1], true, 512, JSON_THROW_ON_ERROR);
- try {
- SharingMysqlSupport::guardedPdo($params['socket'], $params['database']);
- if ($params['framework'] === 'tp') {
- $tpRoot = $params['tp_root'];
- require $tpRoot . '/vendor/autoload.php';
- foreach (['ShareSupport', 'ShareService'] as $class) require $tpRoot . '/app/common/service/sharing/' . $class . '.php';
- $app = new think\App($tpRoot . '/');
- think\Container::setInstance($app);
- $db = new think\DbManager();
- $db->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);
- }
|