'lottery_source_test', 'database.connections.lottery_source_test' => ['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'bot_'], 'logging.channels.dblog' => ['driver' => 'null'], 'cache.default' => 'array', 'admin_realtime.enabled' => false, ]); Bus::fake([SendTelegramGroupMessageJob::class]); DB::statement('CREATE TABLE bot_users (id INTEGER PRIMARY KEY, member_id TEXT, first_name TEXT, "from" INTEGER, is_banned INTEGER)'); DB::statement('CREATE TABLE bot_wallets (id INTEGER PRIMARY KEY, member_id TEXT, available_balance NUMERIC, updated_at TEXT)'); DB::statement('CREATE TABLE bot_config (id INTEGER PRIMARY KEY, field TEXT, val TEXT)'); DB::statement('CREATE TABLE bot_gameplay_rules (id INTEGER PRIMARY KEY, keywords TEXT, odds NUMERIC, mininum NUMERIC, maxinum NUMERIC)'); DB::statement('CREATE TABLE bot_keyboard (id INTEGER PRIMARY KEY, button TEXT)'); foreach (['issues', 'pc_issues'] as $table) { DB::statement("CREATE TABLE bot_{$table} (id INTEGER PRIMARY KEY, issue_no TEXT, status INTEGER, end_time TEXT, winning_numbers TEXT, combo TEXT)"); DB::table($table)->insert(['issue_no' => '123', 'status' => 1, 'end_time' => date('Y-m-d H:i:s', time() + 120)]); } DB::statement('CREATE TABLE bot_lhc_order (id INTEGER PRIMARY KEY, member_id TEXT, type INTEGER, issue TEXT, ordernum TEXT, odds NUMERIC, amount NUMERIC, total_amount NUMERIC, coupon_id INTEGER, lottery_status INTEGER DEFAULT 0, created_at INTEGER, updated_at INTEGER)'); DB::statement('CREATE TABLE bot_lhc_order_item (id INTEGER PRIMARY KEY, member_id TEXT, ordernum TEXT, number TEXT, created_at INTEGER, updated_at INTEGER)'); DB::statement('CREATE TABLE bot_balance_logs (id INTEGER PRIMARY KEY, member_id TEXT, amount NUMERIC, before_balance NUMERIC, after_balance NUMERIC, change_type TEXT, related_id INTEGER, remark TEXT, created_at TEXT, updated_at TEXT)'); DB::table('users')->insert(['member_id' => '1001', 'first_name' => 'Alice', 'from' => -1, 'is_banned' => 0]); DB::table('wallets')->insert(['member_id' => '1001', 'available_balance' => 100]); DB::table('gameplay_rules')->insert(['keywords' => '大', 'odds' => 2, 'mininum' => 1, 'maxinum' => 100]); DB::table('config')->insert([ ['field' => 'service_customer', 'val' => 'test'], ['field' => 'maintenance_switch', 'val' => '0'], ['field' => 'pc28_switch', 'val' => '0'], ['field' => 'group_language', 'val' => 'zh'], ]); } protected function tearDown(): void { DB::disconnect(); Model::clearBootedModels(); parent::tearDown(); } private function adminOrder(string $action, array $params = []): array { $this->app->instance('request', Request::create("/admin/lhcOrder/{$action}", 'GET', $params)); $response = (new LhcOrder())->{$action}()->getData(true); $this->assertSame(0, $response['code'], $response['msg']); return $response['data']; } #[RunInSeparateProcess] #[PreserveGlobalState(false)] public function test_orders_are_tagged_and_telegram_merges_only_its_own_bets(): void { $order = ['member_id' => '1001', 'type' => 5, 'issue' => '123', 'amount' => 10, 'total_amount' => 10, 'created_at' => time()]; DB::table('lhc_order')->insert($order + ['ordernum' => 'old']); DB::table('lhc_order_item')->insert(['member_id' => '1001', 'ordernum' => 'old', 'number' => '大']); (require dirname(__DIR__, 2) . '/database/migrations/2026_11_06_130000_add_bet_source_to_lhc_order.php')->up(); DB::table('lhc_order')->insert($order + ['ordernum' => 'web', 'bet_source' => 'frontend']); DB::table('lhc_order_item')->insert(['member_id' => '1001', 'ordernum' => 'web', 'number' => '大']); $this->assertStringContainsString('下注成功', BetService::bet('1001', '大10')['text']); $this->assertStringContainsString('下注成功', BetService::bet('1001', '大15')['text']); DB::table('config')->where('field', 'pc28_switch')->update(['val' => '1']); $this->assertStringContainsString('下注成功', BetService::bet('1001', '大20')['text']); $list = $this->adminOrder('list'); $this->assertSame(4, $list['total']); $this->assertSame([-1], array_values(array_unique(array_column($list['data'], 'user_from')))); $telegram = $this->adminOrder('list', ['bet_source' => 'telegram', 'type' => 5]); $this->assertSame(1, $telegram['total']); $this->assertEquals(25, $telegram['data'][0]['total_amount']); $this->assertSame('telegram', $this->adminOrder('info', ['id' => $telegram['data'][0]['id']])['bet_source']); $push = AdminRealtimeRows::resolve('lhc_order', (string) $telegram['data'][0]['id'], 'created'); $this->assertSame('telegram', $push[0]['data']['bet_source']); $this->assertSame(1, $this->adminOrder('list', ['bet_source' => 'telegram', 'type' => 6])['total']); $frontend = $this->adminOrder('list', ['bet_source' => 'frontend']); $this->assertSame(1, $frontend['total']); $this->assertEquals(10, $frontend['data'][0]['total_amount']); $this->assertSame('frontend', $this->adminOrder('info', ['id' => $frontend['data'][0]['id']])['bet_source']); DB::table('issues')->delete(); $legacy = $this->adminOrder('list', ['bet_source' => 'unknown']); $this->assertSame(1, $legacy['total']); $this->assertEquals(10, $legacy['data'][0]['total_amount']); $this->assertNull($this->adminOrder('info', ['id' => $legacy['data'][0]['id']])['bet_source']); } }