SimulationTest.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <?php
  2. namespace Tests\Integration;
  3. use App\Http\Controllers\admin\Simulation as SimulationController;
  4. use App\Models\User;
  5. use App\Services\Simulation\SimulationBetService;
  6. use App\Services\Simulation\SimulationFundService;
  7. use App\Services\Simulation\SimulationMemberService;
  8. use App\Services\Simulation\SimulationResetService;
  9. use App\Services\Simulation\SimulationRunner;
  10. use App\Services\Simulation\SimulationSettings;
  11. use App\Services\Simulation\SimulationTaskService;
  12. use App\Services\UserService;
  13. use App\Support\MemberAudience;
  14. use App\Support\StatsScope;
  15. use Illuminate\Config\Repository;
  16. use Illuminate\Database\Capsule\Manager;
  17. use Illuminate\Database\Schema\Blueprint;
  18. use Illuminate\Events\Dispatcher;
  19. use Illuminate\Foundation\Application;
  20. use Illuminate\Http\Request;
  21. use Illuminate\Support\Facades\DB;
  22. use Illuminate\Support\Facades\Facade;
  23. use Illuminate\Support\Facades\Schema;
  24. use PHPUnit\Framework\TestCase;
  25. /**
  26. * 模拟管理:模拟会员的充值、下注、结算、提现写真实业务表,但正式口径的统计和列表完全看不到;
  27. * 模拟口径只看到模拟会员;自动任务能跑完并可重复调度;重置只删模拟数据。
  28. */
  29. class SimulationTest extends TestCase
  30. {
  31. private Application $app;
  32. protected function setUp(): void
  33. {
  34. parent::setUp();
  35. Facade::clearResolvedInstances();
  36. $this->app = $app = new Application(dirname(__DIR__, 2));
  37. $app->instance('config', new Repository(['app' => ['timezone' => 'Asia/Shanghai', 'locale' => 'zh'], 'admin_realtime' => ['enabled' => false],
  38. 'cache' => ['default' => 'array', 'stores' => ['array' => ['driver' => 'array']], 'prefix' => '']]));
  39. $app->instance('files', new \Illuminate\Filesystem\Filesystem());
  40. $app->instance('path.lang', dirname(__DIR__, 2) . '/lang');
  41. $app->register(\Illuminate\Translation\TranslationServiceProvider::class);
  42. $app->register(\Illuminate\Validation\ValidationServiceProvider::class);
  43. $app->register(\Illuminate\Cache\CacheServiceProvider::class);
  44. $app->instance('log', new \Psr\Log\NullLogger());
  45. $app->instance(\Illuminate\Contracts\Routing\ResponseFactory::class, (new \ReflectionClass(\Illuminate\Routing\ResponseFactory::class))->newInstanceWithoutConstructor());
  46. Request::macro('validate', function (array $rules) { return validator()->validate($this->all(), $rules); });
  47. Facade::setFacadeApplication($app);
  48. $db = new Manager($app);
  49. $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'bot_']);
  50. $db->setEventDispatcher(new Dispatcher($app));
  51. $db->setAsGlobal();
  52. $db->bootEloquent();
  53. $app->instance('db.transactions', new \Illuminate\Database\DatabaseTransactionsManager());
  54. $app->instance('db', $db->getDatabaseManager());
  55. $app->bind('db.schema', fn () => $db->schema());
  56. $this->request();
  57. $this->schema();
  58. $this->seedRealMember();
  59. }
  60. protected function tearDown(): void
  61. {
  62. DB::disconnect();
  63. Facade::clearResolvedInstances();
  64. parent::tearDown();
  65. }
  66. private function request(array $input = [], string $method = 'GET'): void
  67. {
  68. $request = Request::create('/admin/simulation', $method, $input);
  69. $request->user = (object) ['id' => 1, 'username' => 'root'];
  70. $this->app->instance('request', $request);
  71. }
  72. private function schema(): void
  73. {
  74. Schema::create('users', function (Blueprint $t) {
  75. $t->id(); $t->string('member_id')->nullable(); $t->string('user_id')->nullable(); $t->string('account')->nullable();
  76. $t->string('first_name')->nullable(); $t->string('username')->default(''); $t->string('from', 20)->nullable()->default('-1');
  77. $t->unsignedBigInteger('agent_id')->nullable(); $t->string('agent_user_code')->nullable(); $t->string('user_code')->nullable();
  78. $t->integer('is_banned')->default(0); $t->integer('status')->default(0); $t->integer('level')->default(0);
  79. $t->string('register_ip')->default(''); $t->string('register_domain')->default(''); $t->integer('last_active_time')->default(0);
  80. $t->string('language')->default('zh'); $t->integer('recharge_channel_group_id')->default(1); $t->string('admin_note')->default('');
  81. $t->timestamps();
  82. });
  83. (require dirname(__DIR__, 2) . '/database/migrations/2026_11_11_120000_add_user_type_to_users.php')->up();
  84. Schema::create('wallets', function (Blueprint $t) {
  85. $t->id(); $t->unsignedBigInteger('user_id')->default(0); $t->string('member_id'); $t->string('coin')->nullable(); $t->string('net')->nullable();
  86. $t->decimal('available_balance', 30, 10)->default(0); $t->decimal('frozen_balance', 30, 10)->default(0); $t->timestamps();
  87. });
  88. Schema::create('balance_logs', function (Blueprint $t) {
  89. $t->id(); $t->string('member_id'); $t->decimal('amount', 30, 10); $t->decimal('before_balance', 30, 10)->default(0);
  90. $t->decimal('after_balance', 30, 10)->default(0); $t->string('change_type'); $t->string('related_id')->nullable(); $t->string('remark')->nullable();
  91. $t->integer('type')->default(1); $t->string('room_id')->nullable(); $t->timestamps();
  92. });
  93. Schema::create('payment_orders', function (Blueprint $t) {
  94. $t->id(); $t->integer('type'); $t->string('order_no')->nullable(); $t->string('member_id'); $t->decimal('amount', 24, 10);
  95. $t->string('channel')->nullable(); $t->string('bank_name')->nullable(); $t->string('account')->nullable(); $t->string('card_no')->nullable();
  96. $t->integer('status'); $t->string('state')->nullable(); $t->text('callback_data')->nullable(); $t->string('remark')->nullable();
  97. $t->decimal('fee', 24, 8)->default(0); $t->decimal('fee_rate', 12, 6)->default(0); $t->decimal('fee_fixed', 12, 4)->default(0);
  98. $t->decimal('frozen_amount', 24, 10)->default(0); $t->text('recharge_bonus_snapshot')->nullable(); $t->timestamps();
  99. });
  100. Schema::create('level', function (Blueprint $t) { $t->id(); $t->integer('level'); $t->decimal('recharge', 20, 2); });
  101. Schema::create('config', function (Blueprint $t) { $t->id(); $t->string('field'); $t->string('val')->nullable(); });
  102. Schema::create('issues', function (Blueprint $t) {
  103. $t->id(); $t->string('issue_no'); $t->dateTime('start_time'); $t->dateTime('end_time'); $t->integer('status'); $t->timestamps();
  104. });
  105. Schema::create('gameplay_rules', function (Blueprint $t) {
  106. $t->id(); $t->string('keywords'); $t->decimal('odds', 10, 2); $t->decimal('mininum', 12, 2); $t->decimal('maxinum', 12, 2); $t->timestamps();
  107. });
  108. Schema::create('lhc_order', function (Blueprint $t) {
  109. $t->id(); $t->string('issue'); $t->string('ordernum'); $t->string('member_id'); $t->decimal('odds', 10, 2)->default(0);
  110. $t->decimal('amount', 22, 2); $t->decimal('total_amount', 22, 2)->default(0); $t->integer('lottery_status')->default(0);
  111. $t->decimal('win_amount', 22, 2)->default(0); $t->decimal('profit_and_loss', 22, 2)->nullable(); $t->integer('type')->default(5);
  112. $t->integer('is_faker')->default(0); $t->string('bet_source', 16)->nullable(); $t->integer('created_at')->nullable(); $t->integer('updated_at')->nullable();
  113. });
  114. Schema::create('lhc_order_item', function (Blueprint $t) {
  115. $t->id(); $t->string('ordernum'); $t->string('member_id'); $t->string('number'); $t->integer('lottery_status')->default(0);
  116. $t->timestamps();
  117. });
  118. Schema::create('sport_order', function (Blueprint $t) {
  119. $t->id(); $t->string('user_id'); $t->string('order_id'); $t->string('issue'); $t->text('detail')->nullable(); $t->integer('is_roll')->default(0);
  120. $t->decimal('amount', 22, 2); $t->decimal('cny_rate', 22, 10)->nullable(); $t->decimal('win_amount', 22, 2)->default(0);
  121. $t->decimal('return_amount', 22, 2)->default(0); $t->decimal('profit_and_loss', 22, 2)->default(0); $t->string('game_result')->nullable();
  122. $t->integer('is_faker')->default(0); $t->integer('is_win')->default(0); $t->integer('status')->default(0); $t->integer('settlement_status')->default(0);
  123. $t->integer('pay_status')->default(0); $t->integer('pay_time')->nullable(); $t->string('odd_name')->nullable(); $t->decimal('odd', 12, 6)->nullable();
  124. $t->string('odd_value')->nullable(); $t->string('remark')->nullable(); $t->integer('create_time')->default(0); $t->integer('update_time')->default(0);
  125. $t->integer('settlement_time')->nullable();
  126. });
  127. Schema::create('user_login', function (Blueprint $t) {
  128. $t->id(); $t->string('user_id')->nullable(); $t->string('login_account')->default(''); $t->string('login_ip')->default('');
  129. $t->string('login_domain')->default(''); $t->string('platform')->default(''); $t->integer('status')->default(1);
  130. $t->dateTime('logout_time')->nullable(); $t->integer('online_duration')->default(0); $t->timestamps();
  131. });
  132. (require dirname(__DIR__, 2) . '/database/migrations/2026_11_11_130000_create_simulation_tables.php')->up();
  133. DB::table('config')->insert([['field' => 'pc28_switch', 'val' => '0'], ['field' => 'recharge_rate', 'val' => '0']]);
  134. DB::table('config')->where('field', 'simulation_enabled')->update(['val' => '1']);
  135. DB::table('issues')->insert(['issue_no' => '3300001', 'start_time' => now(), 'end_time' => now()->addMinutes(5), 'status' => 1]);
  136. DB::table('gameplay_rules')->insert(['keywords' => '大', 'odds' => 2, 'mininum' => 1, 'maxinum' => 100000]);
  137. }
  138. /** 一个真实会员和一个前台游客,各有充值、投注、订单。 */
  139. private function seedRealMember(): void
  140. {
  141. foreach ([['r1', '1', 0], ['g1', '2', 1]] as $i => [$member, $from, $type]) {
  142. DB::table('users')->insert(['member_id' => $member, 'user_id' => $member, 'account' => $member, 'first_name' => $member, 'from' => $from,
  143. 'user_type' => $type, 'created_at' => now(), 'updated_at' => now()]);
  144. DB::table('wallets')->insert(['user_id' => $i + 1, 'member_id' => $member, 'available_balance' => 90]);
  145. DB::table('balance_logs')->insert([
  146. ['member_id' => $member, 'amount' => 100, 'change_type' => '三方充值', 'created_at' => now(), 'updated_at' => now()],
  147. ['member_id' => $member, 'amount' => -10, 'change_type' => '投注', 'created_at' => now(), 'updated_at' => now()]]);
  148. DB::table('payment_orders')->insert(['type' => 1, 'member_id' => $member, 'amount' => 100, 'status' => 2, 'created_at' => now(), 'updated_at' => now()]);
  149. DB::table('lhc_order')->insert(['issue' => '3300001', 'ordernum' => 'o' . $member, 'member_id' => $member, 'amount' => 10, 'total_amount' => 10]);
  150. }
  151. }
  152. /** 正式口径下各处看到的数字。模拟数据进来前后必须完全一样。 */
  153. private function realView(): array
  154. {
  155. return [
  156. 'stats_deposit' => (float) StatsScope::excludeTestMembers(DB::table('balance_logs'))->where('change_type', '三方充值')->sum('amount'),
  157. 'stats_bet' => (float) StatsScope::excludeTestMembers(DB::table('balance_logs'))->where('change_type', 'like', '%投注')->sum('amount'),
  158. 'stats_wallet' => (float) StatsScope::excludeTestMembers(DB::table('wallets'))->sum('available_balance'),
  159. 'stats_orders' => StatsScope::excludeTestMembers(DB::table('payment_orders'))->count(),
  160. 'real_users' => StatsScope::realUsers(DB::table('users'))->pluck('member_id')->all(),
  161. 'guest_users' => StatsScope::guestUsers(DB::table('users'))->pluck('member_id')->all(),
  162. 'raw_users' => array_column(DB::select('SELECT u.member_id FROM bot_users u WHERE 1 = 1' . StatsScope::rawExcludeTestUsers('u')), 'member_id'),
  163. 'list_users' => MemberAudience::visibleUsers(DB::table('users'))->orderBy('id')->pluck('member_id')->all(),
  164. 'list_ledger' => MemberAudience::visibleUsers(DB::table('balance_logs')->join('users', 'users.member_id', '=', 'balance_logs.member_id'))->count(),
  165. 'list_orders' => MemberAudience::visibleMembers(DB::table('payment_orders'))->count(),
  166. 'list_lottery' => MemberAudience::visibleMembers(DB::table('lhc_order'), 'lhc_order.member_id')->count(),
  167. 'list_sport' => MemberAudience::visibleMembers(DB::table('sport_order'), 'user_id', 'user_id')->count(),
  168. 'list_logins' => MemberAudience::visibleMembers(DB::table('user_login'), 'user_id', 'user_id')->count(),
  169. ];
  170. }
  171. private function wallet(string $memberId): array
  172. {
  173. $w = DB::table('wallets')->where('member_id', $memberId)->first();
  174. return [(float) $w->available_balance, (float) $w->frozen_balance];
  175. }
  176. public function test_simulated_money_and_bets_use_real_tables_but_stay_out_of_the_real_view(): void
  177. {
  178. $before = $this->realView();
  179. $this->assertSame(100.0, $before['stats_deposit'], 'guest deposits are not counted either');
  180. $this->assertSame(['r1'], $before['real_users']);
  181. $this->assertSame(['g1'], $before['guest_users']);
  182. $this->assertSame(['r1', 'g1'], $before['list_users'], 'lists still show guests');
  183. [$a, $b] = array_column(SimulationMemberService::create(2, ['initial_balance' => 1000]), 'member_id');
  184. $user = DB::table('users')->where('member_id', $a)->first();
  185. $this->assertSame(['2', 2, null], [(string) $user->from, (int) $user->user_type, $user->agent_id]);
  186. $this->assertSame([1000.0, 0.0], $this->wallet($a));
  187. // 充值:三方成功、公司入款成功、失败的不入账
  188. $this->assertSame(2, (int) SimulationFundService::recharge($a, 500, 'third')->status);
  189. $this->assertSame(2, (int) SimulationFundService::recharge($a, 200, 'company')->status);
  190. $this->assertSame(3, (int) SimulationFundService::recharge($a, 999, 'third', 'fail')->status);
  191. $this->assertSame(1, (int) SimulationFundService::recharge($a, 50, 'third', 'pending')->status);
  192. $this->assertSame(1700.0, $this->wallet($a)[0]);
  193. // 彩票下在真实期号上;体育按给定结果结算
  194. $lottery = SimulationBetService::lottery($a, '大', 100);
  195. $this->assertSame(['3300001', 'simulation', 0], [$lottery->issue, $lottery->bet_source, (int) $lottery->fresh()->lottery_status]);
  196. $win = SimulationBetService::sport($a, 50, 2);
  197. $this->assertSame('100.00', SimulationBetService::settleSport($win->id, 'win')->win_amount);
  198. $half = SimulationBetService::sport($a, 40, 1.9);
  199. $settled = SimulationBetService::settleSport($half->id, 'half');
  200. $this->assertSame(['20.00', '-20.00'], [$settled->return_amount, $settled->profit_and_loss]);
  201. try { SimulationBetService::settleSport($half->id, 'win'); $this->fail('an order settles once'); }
  202. catch (\Exception $e) { $this->assertStringContainsString('已结算', $e->getMessage()); }
  203. $this->assertSame(1630.0, $this->wallet($a)[0], '1700 - 100 - 50 + 100 - 40 + 20');
  204. $this->assertSame($before, $this->realView());
  205. }
  206. public function test_full_flow_isolation_runner_and_reset(): void
  207. {
  208. $before = $this->realView();
  209. [$a] = array_column(SimulationMemberService::create(1, ['initial_balance' => 1000]), 'member_id');
  210. SimulationFundService::recharge($a, 500, 'third');
  211. SimulationFundService::recharge($a, 200, 'company');
  212. SimulationBetService::lottery($a, '大', 100);
  213. $win = SimulationBetService::sport($a, 50, 2);
  214. SimulationBetService::settleSport($win->id, 'win');
  215. $draw = SimulationBetService::sport($a, 30, 2);
  216. SimulationBetService::settleSport($draw->id, 'draw');
  217. $lose = SimulationBetService::sport($a, 20, 2);
  218. SimulationBetService::settleSport($lose->id, 'lose');
  219. $cancelled = SimulationBetService::sport($a, 10, 2);
  220. SimulationBetService::cancelSport($cancelled->id);
  221. $approved = SimulationFundService::withdrawApply($a, 300);
  222. SimulationFundService::withdrawAudit($approved->id, true);
  223. $rejected = SimulationFundService::withdrawApply($a, 70);
  224. SimulationFundService::withdrawAudit($rejected->id, false, '测试拒绝');
  225. SimulationFundService::adjust($a, 5, 'debit', '扣款');
  226. SimulationMemberService::login($a);
  227. // 1000 + 500 + 200 - 100 - 50 + 100 - 30 + 30 - 20 - 10 + 10 - 300 - 70 + 70 - 5
  228. $this->assertSame([1325.0, 0.0], $this->wallet($a));
  229. $this->assertSame([2, 3], [(int) $approved->fresh()->status, (int) $rejected->fresh()->status]);
  230. $this->assertSame($before, $this->realView(), 'nothing the real back office reads has changed');
  231. $sim = MemberAudience::simulated(fn () => [
  232. 'deposit' => (float) StatsScope::excludeTestMembers(DB::table('balance_logs'))->whereIn('change_type', ['三方充值', '充值'])->sum('amount'),
  233. 'bet' => (float) StatsScope::excludeTestMembers(DB::table('balance_logs'))->where('change_type', 'like', '%投注')->sum('amount'),
  234. 'users' => StatsScope::realUsers(DB::table('users'))->pluck('member_id')->all(),
  235. 'raw' => array_column(DB::select('SELECT u.member_id FROM bot_users u WHERE 1 = 1' . StatsScope::rawExcludeTestUsers('u')), 'member_id'),
  236. 'guests' => StatsScope::guestUsers(DB::table('users'))->count(),
  237. 'list' => MemberAudience::visibleUsers(DB::table('users'))->pluck('member_id')->all(),
  238. 'sport' => MemberAudience::visibleMembers(DB::table('sport_order'), 'user_id', 'user_id')->count(),
  239. ]);
  240. $this->assertSame(['deposit' => 700.0, 'bet' => -210.0, 'users' => [$a], 'raw' => [$a], 'guests' => 0, 'list' => [$a], 'sport' => 4], $sim);
  241. $this->assertFalse(MemberAudience::isSimulated(), 'audience is restored');
  242. // 概览接口与手算一致
  243. $this->request();
  244. $overview = (new SimulationController())->overview()->getData(true);
  245. $this->assertSame(0, $overview['code'], $overview['msg']);
  246. $this->assertSame(['1', '1'], [(string) $overview['data']['members']['total'], (string) $overview['data']['members']['online']]);
  247. $this->assertSame(['700.00', '1000.00', '5.00', '300.00', '1325.00'], [$overview['data']['funds']['recharge'], $overview['data']['funds']['manual_credit'],
  248. $overview['data']['funds']['manual_debit'], $overview['data']['funds']['withdraw'], $overview['data']['funds']['wallet_available']]);
  249. $this->assertSame(['210.00', '140.00', 1], [$overview['data']['bets']['bet_amount'], $overview['data']['bets']['payout'], $overview['data']['bets']['unsettled']]);
  250. // 自动任务:注册 2 人 → 登录 → 充值 → 体育下注 2 次 → 结算 → 提现 → 退出
  251. $steps = [['type' => 'register', 'interval' => 0], ['type' => 'login', 'interval' => 0], ['type' => 'recharge', 'amount' => 100, 'interval' => 0],
  252. ['type' => 'bet', 'category' => 'sport', 'amount' => 10, 'count' => 2, 'interval' => 0], ['type' => 'settle', 'settle_mode' => 'lose', 'interval' => 0],
  253. ['type' => 'withdraw', 'amount' => 30, 'interval' => 0], ['type' => 'logout', 'interval' => 0]];
  254. $runId = SimulationTaskService::start(['name' => '完整流程', 'steps' => $steps, 'member_count' => 2], 1);
  255. $paused = SimulationTaskService::setStatus($runId, 'pause');
  256. $this->assertSame('paused', $paused->status);
  257. $this->assertSame(0, SimulationRunner::tick(), 'a paused run does nothing');
  258. SimulationTaskService::setStatus($runId, 'resume');
  259. for ($i = 0; $i < 60 && DB::table('simulation_task_runs')->where('id', $runId)->value('status') === 'running'; $i++) SimulationRunner::tick();
  260. $run = DB::table('simulation_task_runs')->where('id', $runId)->first();
  261. $this->assertSame(['completed', 16, 16, 0], [$run->status, (int) $run->total, (int) $run->completed, (int) $run->failed], (string) $run->last_error);
  262. $this->assertSame(16, DB::table('simulation_task_events')->where('run_id', $runId)->where('status', 'ok')->count());
  263. $this->assertSame(0, SimulationRunner::tick(), 'a finished run is not executed again');
  264. foreach (json_decode($run->member_ids, true) as $memberId) $this->assertSame([50.0, 0.0], $this->wallet($memberId), '100 - 10 - 10 - 30');
  265. $this->assertSame(3, DB::table('users')->where('user_type', 2)->count());
  266. $this->assertSame($before, $this->realView(), 'the task run did not leak either');
  267. // 重置:只删模拟数据
  268. $preview = SimulationResetService::preview();
  269. $this->assertSame(3, $preview['counts']['users']);
  270. try { SimulationResetService::reset('wrong', SimulationResetService::CONFIRM_TEXT); $this->fail('wrong token must be refused'); }
  271. catch (\Exception $e) { $this->assertStringContainsString('失效', $e->getMessage()); }
  272. $preview = SimulationResetService::preview();
  273. $deleted = SimulationResetService::reset($preview['confirm_token'], $preview['confirm_text']);
  274. $this->assertSame(3, $deleted['users']);
  275. $this->assertSame(0, DB::table('users')->where('user_type', 2)->count());
  276. $this->assertSame([2, 2, 4, 2, 2], [DB::table('users')->count(), DB::table('wallets')->count(), DB::table('balance_logs')->count(),
  277. DB::table('payment_orders')->count(), DB::table('lhc_order')->count()], 'real and guest rows are untouched');
  278. $this->assertSame([0, 0], [DB::table('sport_order')->count(), DB::table('user_login')->count()]);
  279. $this->assertSame($before, $this->realView());
  280. }
  281. public function test_guards_refuse_real_members_and_a_closed_switch(): void
  282. {
  283. foreach ([fn () => SimulationFundService::recharge('r1', 10), fn () => SimulationFundService::adjust('g1', 10, 'credit', 'x'),
  284. fn () => SimulationBetService::sport('r1', 10, 2), fn () => SimulationFundService::withdrawApply('r1', 10)] as $call) {
  285. try { $call(); $this->fail('real members and guests must be refused'); }
  286. catch (\Exception $e) { $this->assertSame('只能操作模拟会员', $e->getMessage()); }
  287. }
  288. $this->assertSame(90.0, $this->wallet('r1')[0]);
  289. $order = \App\Models\PaymentOrder::create(['type' => 1, 'member_id' => 'r1', 'amount' => 10, 'status' => 1]);
  290. try { \App\Services\PaymentOrderService::simulatePaySuccess($order); $this->fail('a real order must not be credited'); }
  291. catch (\Exception $e) { $this->assertStringContainsString('模拟会员', $e->getMessage()); }
  292. SimulationSettings::save(['simulation_enabled' => 0]);
  293. try { SimulationMemberService::create(1); $this->fail('closed switch'); }
  294. catch (\Exception $e) { $this->assertStringContainsString('未开启', $e->getMessage()); }
  295. $this->assertSame(0, SimulationRunner::tick());
  296. $this->assertSame(0, User::where('user_type', 2)->count());
  297. $this->assertNotNull(UserService::class);
  298. }
  299. }