argument('user_id'); $this->info("开始测试用户 {$userId} 的登录资金账户创建功能..."); try { // 检查用户是否存在 $user = User::find($userId); if (!$user) { $this->error("用户 {$userId} 不存在"); return 1; } $this->info("用户信息: ID={$user->id}, 用户名={$user->username}"); // 检查用户当前的资金账户 $this->info("检查用户当前的资金账户..."); $accounts = \App\Module\Fund\Models\FundModel::userAccount($userId); $this->info("当前资金账户数量: " . $accounts->count()); foreach ($accounts as $account) { $this->line(" - 账户ID: {$account->id}, 资金类型: {$account->fund_id->value}, 余额: {$account->balance}"); } // 模拟触发登录成功事件 $this->info("模拟触发登录成功事件..."); Event::dispatch(new LoginSuccessEvent($user, 'test-session-' . time())); // 再次检查用户的资金账户 $this->info("重新检查用户的资金账户..."); $accountsAfter = \App\Module\Fund\Models\FundModel::userAccount($userId); $this->info("登录后资金账户数量: " . $accountsAfter->count()); foreach ($accountsAfter as $account) { $this->line(" - 账户ID: {$account->id}, 资金类型: {$account->fund_id->value}, 余额: {$account->balance}"); } // 直接测试AccountService::check4user方法 $this->info("直接测试 AccountService::check4user 方法..."); AccountService::check4user($userId); // 最终检查 $this->info("最终检查用户的资金账户..."); $accountsFinal = \App\Module\Fund\Models\FundModel::userAccount($userId); $this->info("最终资金账户数量: " . $accountsFinal->count()); foreach ($accountsFinal as $account) { $this->line(" - 账户ID: {$account->id}, 资金类型: {$account->fund_id->value}, 余额: {$account->balance}"); } $this->info("测试完成!"); return 0; } catch (\Exception $e) { $this->error("测试失败: " . $e->getMessage()); $this->error("错误详情: " . $e->getTraceAsString()); return 1; } } }