ShareAdminManagementTest.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?php
  2. namespace Tests\Integration;
  3. use App\Console\Commands\BackfillShareCommissions;
  4. use App\Http\Controllers\admin\ShareEarning;
  5. use App\Http\Controllers\admin\SharingManagement;
  6. use App\Models\BalanceLog;
  7. use App\Models\ShareSetting;
  8. use App\Services\BalanceLogService;
  9. use App\Services\ShareCommissionDiagnostics;
  10. use App\Services\Sharing\ShareAdminService;
  11. use App\Services\Sharing\ShareClaimAuditService;
  12. use Carbon\Carbon;
  13. use Illuminate\Config\Repository;
  14. use Illuminate\Database\Capsule\Manager;
  15. use Illuminate\Database\Schema\Blueprint;
  16. use Illuminate\Foundation\Application;
  17. use Illuminate\Http\JsonResponse;
  18. use Illuminate\Http\Request;
  19. use Illuminate\Support\Facades\DB;
  20. use Illuminate\Support\Facades\Facade;
  21. use Illuminate\Translation\ArrayLoader;
  22. use Illuminate\Translation\Translator;
  23. use Illuminate\Validation\Factory;
  24. use Illuminate\Validation\ValidationException;
  25. use PHPUnit\Framework\TestCase;
  26. use Symfony\Component\Console\Tester\CommandTester;
  27. /** Only an isolated, prefixed SQLite database; never boots project providers or reads .env. */
  28. class ShareAdminManagementTest extends TestCase
  29. {
  30. private Application $app;
  31. private ShareAdminService $admin;
  32. private ShareClaimAuditService $claims;
  33. protected function setUp(): void
  34. {
  35. Facade::clearResolvedInstances();
  36. Carbon::setTestNow(Carbon::parse('2026-10-24 18:00:00', 'Asia/Shanghai'));
  37. $this->app = new Application(dirname(__DIR__, 2));
  38. $this->app->instance('config', new Repository(['app' => ['locale' => 'zh', 'timezone' => 'Asia/Shanghai']]));
  39. Facade::setFacadeApplication($this->app);
  40. $db = new Manager($this->app);
  41. $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'bot_']);
  42. $db->setAsGlobal(); $db->bootEloquent();
  43. $this->app->instance('db', $db->getDatabaseManager());
  44. $this->app->bind('db.schema', fn () => $db->schema());
  45. $translator = new Translator(new ArrayLoader(), 'zh');
  46. $this->app->instance('translator', $translator);
  47. $this->app->instance('validator', new Factory($translator, $this->app));
  48. $this->app->instance(\Illuminate\Contracts\Routing\ResponseFactory::class, new class {
  49. public function json($data, $status = 200, $headers = [], $options = 0) { return new JsonResponse($data, $status, $headers, $options); }
  50. });
  51. Request::macro('validate', function (array $rules) { return app('validator')->make($this->all(), $rules)->validate(); });
  52. $db->schema()->create('share_settings', function (Blueprint $t) {
  53. $t->id(); $t->integer('enabled')->default(0); $t->integer('benefit_enabled')->default(0);
  54. $t->string('share_domain')->default(''); $t->decimal('valid_member_min_deposit', 20, 2)->default(20);
  55. $t->decimal('non_seller_threshold', 24, 10)->default(200); $t->decimal('tier_one_rate', 8, 4)->default(4);
  56. $t->decimal('tier_two_rate', 8, 4)->default(6); $t->integer('operator_id')->nullable(); $t->string('operator_name')->default(''); $t->timestamps();
  57. });
  58. $db->schema()->create('users', function (Blueprint $t) {
  59. $t->id(); $t->string('member_id')->unique(); $t->string('account'); $t->string('first_name'); $t->timestamps();
  60. });
  61. $db->schema()->create('wallets', function (Blueprint $t) {
  62. $t->id(); $t->string('member_id')->unique(); $t->decimal('available_balance', 24, 10)->default(0); $t->timestamps();
  63. });
  64. $db->schema()->create('balance_logs', function (Blueprint $t) {
  65. $t->id(); $t->string('member_id'); $t->string('change_type'); $t->integer('type')->default(1);
  66. foreach (['amount', 'before_balance', 'after_balance'] as $field) $t->decimal($field, 24, 10);
  67. $t->integer('related_id')->nullable(); $t->text('remark')->nullable(); $t->timestamps();
  68. });
  69. $db->schema()->create('operation_audits', function (Blueprint $t) {
  70. $t->id(); $t->string('resource_type'); $t->integer('resource_id')->nullable(); $t->string('action');
  71. $t->json('changes'); $t->integer('operator_id')->nullable(); $t->string('operator_name'); $t->timestamp('created_at')->useCurrent();
  72. });
  73. (require dirname(__DIR__, 2) . '/database/migrations/2026_10_24_120000_create_member_sharing_system.php')->up();
  74. $request = Request::create('/admin/shareEarning/settings', 'GET');
  75. $request->user = (object)['id' => 8, 'username' => 'admin'];
  76. $this->app->instance('request', $request);
  77. $this->admin = new ShareAdminService(); $this->claims = new ShareClaimAuditService();
  78. }
  79. protected function tearDown(): void
  80. {
  81. BalanceLogService::$MODEL = BalanceLog::class;
  82. Carbon::setTestNow(); DB::disconnect(); Facade::clearResolvedInstances(); parent::tearDown();
  83. }
  84. private function config(array $extra = []): array
  85. {
  86. return array_replace(['enabled' => 1, 'benefit_enabled' => 1, 'share_domain' => 'https://PC.example.com/',
  87. 'valid_member_min_deposit' => '20.00', 'valid_member_min_effective_bet' => '100.00'], $extra);
  88. }
  89. private function initialized(): void
  90. {
  91. DB::table('share_system_state')->insert(['key' => 'initialized_at', 'value' => '2026-10-24 18:00:00']);
  92. }
  93. private function fails(callable $callback, string $contains): void
  94. {
  95. try { $callback(); $this->fail('Expected validation rejection'); }
  96. catch (ValidationException $e) { $this->assertStringContainsString($contains, $e->validator->errors()->first()); }
  97. }
  98. public function test_explicit_setup_and_initializer_gate_enablement(): void
  99. {
  100. $this->assertNull($this->admin->settings()['activation_date']);
  101. $this->fails(fn () => $this->admin->saveSettings($this->config()), '初始化');
  102. $this->assertSame(0, DB::table('share_settings')->count());
  103. $this->initialized();
  104. $incomplete = $this->config(); unset($incomplete['valid_member_min_effective_bet']);
  105. $this->fails(fn () => $this->admin->saveSettings($incomplete), 'required_if');
  106. $this->fails(fn () => $this->admin->saveSettings($this->config(['tier_one_rate' => 4])), '已移除');
  107. $this->fails(fn () => $this->admin->saveSettings($this->config(['activation_date' => '2020-01-01'])), '不可指定');
  108. $this->fails(fn () => $this->admin->saveSettings($this->config(['share_domain' => 'https://pc.example/a'])), '源地址');
  109. $data = $this->admin->saveSettings($this->config());
  110. $this->assertSame('2026-10-25', $data['activation_date']);
  111. $this->assertSame('https://pc.example.com', $data['share_domain']);
  112. $this->assertSame(0, $data['current_policy']['benefit_enabled']);
  113. $this->assertSame(1, $data['pending_policy']['benefit_enabled']);
  114. $this->assertArrayNotHasKey('tier_one_rate', $data);
  115. $this->assertArrayNotHasKey('indirect_bonus_rate', $data);
  116. $this->assertArrayNotHasKey('indirect_bonus_rate', $data['current_policy']);
  117. $this->assertArrayNotHasKey('indirect_bonus_rate', $data['pending_policy']);
  118. $this->assertSame(12, count($data['pending_policy']['rules']['third:1']));
  119. }
  120. public function test_pending_policy_edits_preserve_past_policy_and_activation_date(): void
  121. {
  122. $this->initialized();
  123. $first = $this->admin->saveSettings($this->config());
  124. $pendingId = $first['pending_policy']['id'];
  125. $this->admin->saveRateRules('third:1', [['min_valid_members' => 1, 'min_performance' => '1000000', 'rate' => '0.25']]);
  126. $again = $this->admin->saveSettings($this->config(['valid_member_min_effective_bet' => '250']));
  127. $this->assertSame($pendingId, $again['pending_policy']['id']);
  128. $this->assertSame('0.2500', $again['pending_policy']['rules']['third:1'][0]['rate']);
  129. Carbon::setTestNow(Carbon::parse('2026-10-25 01:00:00', 'Asia/Shanghai'));
  130. $before = (array)DB::table('share_policies')->where('id', $pendingId)->first();
  131. $this->admin->saveSettings($this->config(['benefit_enabled' => 0]));
  132. $this->admin->saveRateRules('third:2', [['min_valid_members' => 0, 'min_performance' => 10, 'rate' => '0.50']]);
  133. $this->assertSame($before, (array)DB::table('share_policies')->where('id', $pendingId)->first());
  134. $this->assertSame(0, $this->admin->settings()['pending_policy']['benefit_enabled']);
  135. $this->admin->saveSettings($this->config());
  136. $this->assertSame('2026-10-25', $this->admin->settings()['activation_date']);
  137. $this->assertSame(3, DB::table('share_policies')->count());
  138. }
  139. public function test_retired_indirect_coefficient_is_rejected_even_when_null_without_saving(): void
  140. {
  141. $this->initialized();
  142. foreach ([null, 0, '30.0000'] as $value) {
  143. $this->fails(fn () => $this->admin->saveSettings($this->config(['indirect_bonus_rate' => $value])), '已移除');
  144. }
  145. $this->assertSame(0, DB::table('share_settings')->count());
  146. $this->assertSame(1, DB::table('share_policies')->count());
  147. $this->assertSame(0, DB::table('operation_audits')->count());
  148. $request = Request::create('/admin/shareEarning/settings', 'POST', $this->config(['indirect_bonus_rate' => '30']));
  149. $this->app->instance('request', $request);
  150. $body = (new ShareEarning())->saveSettings($this->admin)->getData(true);
  151. $this->assertSame(-3, $body['code']);
  152. $this->assertStringContainsString('已移除', $body['msg']);
  153. $this->assertSame(0, DB::table('share_settings')->count());
  154. }
  155. public function test_rule_edits_need_no_coefficient_and_preserve_archived_policy_values(): void
  156. {
  157. $this->initialized();
  158. DB::table('share_settings')->insert(['indirect_bonus_rate' => '25.0000']);
  159. DB::table('share_policies')->update(['indirect_bonus_rate' => '30.0000']);
  160. $archived = (array) DB::table('share_policies')->where('effective_date', '1970-01-01')->first();
  161. $settings = $this->admin->saveSettings($this->config());
  162. $this->assertArrayNotHasKey('indirect_bonus_rate', $settings);
  163. $this->assertArrayNotHasKey('indirect_bonus_rate', $settings['current_policy']);
  164. $this->assertArrayNotHasKey('indirect_bonus_rate', $settings['pending_policy']);
  165. $this->assertNull(DB::table('share_policies')->where('id', $settings['pending_policy']['id'])->value('indirect_bonus_rate'));
  166. $this->assertSame('25.0000', bcadd((string) DB::table('share_settings')->value('indirect_bonus_rate'), '0', 4));
  167. $model = ShareSetting::query()->firstOrFail();
  168. $this->assertArrayNotHasKey('indirect_bonus_rate', $model->getCasts());
  169. $this->assertArrayNotHasKey('indirect_bonus_rate', $model->toArray());
  170. $rules = $this->admin->saveRateRules('third:1', [['min_valid_members' => 0, 'min_performance' => 0, 'rate' => '10']]);
  171. $this->assertSame('10.0000', $rules['categories'][0]['pending_rules'][0]['rate']);
  172. $this->admin->saveSettings($this->config(['valid_member_min_effective_bet' => '250']));
  173. $this->admin->saveLevel(['level' => 2, 'name' => '二级', 'image' => '', 'incremental_commission' => '10']);
  174. $settings = $this->admin->settings();
  175. $this->assertSame('10.0000', $settings['pending_policy']['rules']['third:1'][0]['rate']);
  176. $this->assertSame('250.00', $settings['pending_policy']['valid_member_min_effective_bet']);
  177. $this->assertArrayNotHasKey('indirect_bonus_rate', $settings['pending_policy']);
  178. $this->assertNull(DB::table('share_policies')->where('id', $settings['pending_policy']['id'])->value('indirect_bonus_rate'));
  179. $this->assertSame($archived, (array) DB::table('share_policies')->where('id', $archived['id'])->first());
  180. Carbon::setTestNow(Carbon::parse('2026-10-25 01:00:00', 'Asia/Shanghai'));
  181. $this->assertSame('10.0000', $this->admin->rateRules('third:1')['categories'][0]['current_rules'][0]['rate']);
  182. $this->assertArrayNotHasKey('indirect_bonus_rate', $this->admin->settings()['current_policy']);
  183. }
  184. public function test_diagnostic_and_backfill_output_hide_archived_coefficient_without_writes(): void
  185. {
  186. $schema = DB::connection()->getSchemaBuilder();
  187. $schema->table('users', function (Blueprint $t) {
  188. $t->string('user_code')->default(''); $t->string('agent_user_code')->nullable(); $t->integer('from')->default(1);
  189. });
  190. $schema->create('config', function (Blueprint $t) {
  191. $t->id(); $t->string('field'); $t->string('val');
  192. });
  193. $schema->create('share_commission_records', function (Blueprint $t) {
  194. $t->id(); $t->date('stat_date'); $t->integer('status');
  195. });
  196. DB::table('config')->insert(['field' => 'recharge_rate', 'val' => '2.5000']);
  197. DB::table('share_settings')->insert(['indirect_bonus_rate' => '30', 'valid_member_min_effective_bet' => '100']);
  198. $before = (array) DB::table('share_settings')->first();
  199. $data = (new ShareCommissionDiagnostics())->inspect(null);
  200. $this->assertArrayNotHasKey('indirect_bonus_rate', $data);
  201. $this->assertEquals('100', $data['valid_member_min_effective_bet']);
  202. $command = new BackfillShareCommissions();
  203. $command->setLaravel($this->app);
  204. $tester = new CommandTester($command);
  205. $tester->execute(['--diagnose' => true, '--all' => true]);
  206. $this->assertSame(0, $tester->getStatusCode(), $tester->getDisplay());
  207. $this->assertStringNotContainsString('indirect_bonus_rate', $tester->getDisplay());
  208. $this->assertStringContainsString('valid_member_min_effective_bet: 100', $tester->getDisplay());
  209. $this->assertSame($before, (array) DB::table('share_settings')->first());
  210. $this->assertSame(0, DB::table('share_commission_records')->count());
  211. $this->assertSame(0, DB::table('balance_logs')->count());
  212. }
  213. public function test_deposit_precision_and_display_switch_do_not_silently_change_money_configuration(): void
  214. {
  215. $this->initialized();
  216. $this->fails(fn () => $this->admin->saveSettings($this->config(['valid_member_min_deposit' => '20.123'])), 'regex');
  217. $this->assertSame(0, DB::table('share_settings')->count());
  218. $this->assertSame(1, DB::table('share_policies')->count());
  219. $saved = $this->admin->saveSettings($this->config(['enabled' => 0, 'valid_member_min_deposit' => '20.12']));
  220. $this->assertSame(0, $saved['enabled']);
  221. $this->assertSame(1, $saved['benefit_enabled']);
  222. $this->assertSame(1, $saved['pending_policy']['benefit_enabled']);
  223. $this->assertSame('20.12', $saved['pending_policy']['valid_member_min_deposit']);
  224. $this->assertSame('20.12', $saved['valid_member_min_deposit']);
  225. $this->assertSame('20.1200000000', bcadd((string)DB::table('share_policies')->where('effective_date', '2026-10-25')->value('valid_member_min_deposit'), '0', 10));
  226. }
  227. public function test_rules_are_ordered_by_threshold_and_invalid_ladders_are_rejected_without_pending_writes(): void
  228. {
  229. $this->admin->saveRateRules('third:1', [
  230. ['min_valid_members' => 2, 'min_performance' => '100', 'rate' => '0.30'],
  231. ['min_valid_members' => 1, 'min_performance' => '100', 'rate' => '0.20'],
  232. ['min_valid_members' => 0, 'min_performance' => '10', 'rate' => '0.10'],
  233. ]);
  234. $rules = $this->admin->rateRules('third:1')['categories'][0]['pending_rules'];
  235. $this->assertSame([0, 1, 2], array_column($rules, 'min_valid_members'));
  236. $this->assertSame(['10.00', '100.00', '100.00'], array_column($rules, 'min_performance'));
  237. $before = (array)DB::table('share_policies')->where('effective_date', '2026-10-25')->first();
  238. $this->fails(fn () => $this->admin->saveRateRules('third:1', [
  239. ['min_valid_members' => 1, 'min_performance' => '100.0', 'rate' => '0.20'],
  240. ['min_valid_members' => 1, 'min_performance' => '100.00', 'rate' => '0.30'],
  241. ]), '不可重复');
  242. $this->fails(fn () => $this->admin->saveRateRules('third:1', [
  243. ['min_valid_members' => 2, 'min_performance' => '100', 'rate' => '0.20'],
  244. ['min_valid_members' => 1, 'min_performance' => '200', 'rate' => '0.30'],
  245. ]), '人数门槛不可降低');
  246. $this->fails(fn () => $this->admin->saveRateRules('third:1', [
  247. ['min_valid_members' => 1, 'min_performance' => '100', 'rate' => '0.30'],
  248. ['min_valid_members' => 2, 'min_performance' => '200', 'rate' => '0.20'],
  249. ]), '返佣比例不可降低');
  250. $this->assertSame($before, (array)DB::table('share_policies')->where('effective_date', '2026-10-25')->first());
  251. $this->assertSame(1, DB::table('operation_audits')->count());
  252. }
  253. public function test_levels_sum_increments_and_never_downgrade_members(): void
  254. {
  255. DB::table('share_members')->insert(['user_id' => 7, 'level' => 1, 'bound_at' => '2026-10-24 00:00:00']);
  256. DB::table('share_accounts')->insert(['user_id' => 7, 'earned_amount' => 25]);
  257. $this->admin->saveLevel(['level' => 2, 'name' => '二级', 'image' => '', 'incremental_commission' => 10]);
  258. $this->admin->saveLevel(['level' => 3, 'name' => '三级', 'image' => '/three.png', 'incremental_commission' => 20]);
  259. $this->assertSame(2, (int)DB::table('share_members')->value('level'));
  260. $levels = $this->admin->levels()['data'];
  261. $this->assertSame('30.00', $levels[2]['cumulative_commission']);
  262. $this->admin->saveLevel(['id' => $levels[1]['id'], 'level' => 2, 'name' => '二级', 'image' => '', 'incremental_commission' => 100]);
  263. $this->assertSame(2, (int)DB::table('share_members')->value('level'));
  264. $this->fails(fn () => $this->admin->deleteLevel($levels[1]['id']), '已有会员');
  265. $this->admin->deleteLevel($levels[2]['id']);
  266. $this->assertCount(2, $this->admin->levels()['data']);
  267. }
  268. private function pending(string $earned = '10.019', string $amount = '10.01'): int
  269. {
  270. DB::table('users')->insert(['id' => 7, 'member_id' => 'M7', 'account' => 'member7', 'first_name' => '会员']);
  271. DB::table('wallets')->insert(['member_id' => 'M7', 'available_balance' => 20]);
  272. DB::table('share_accounts')->insert(['user_id' => 7, 'earned_amount' => $earned, 'paid_amount' => 0, 'reserved_amount' => $amount]);
  273. return DB::table('share_claims')->insertGetId(['user_id' => 7, 'request_id' => 'req-1', 'active_user_id' => 7,
  274. 'amount' => $amount, 'status' => 'pending', 'created_at' => '2026-10-24 12:00:00', 'updated_at' => '2026-10-24 12:00:00']);
  275. }
  276. public function test_approval_credits_member_wallet_once_and_retains_fractional_remainder(): void
  277. {
  278. $id = $this->pending();
  279. $approved = $this->claims->audit($id, 'approve', 8, '已核对');
  280. $this->assertSame('approved', $approved['status']);
  281. $this->assertSame('0.00', $approved['commission_account']['spendable_amount']);
  282. $this->assertSame('10.01', $approved['commission_account']['paid_amount']);
  283. $this->assertEquals('30.01', DB::table('wallets')->value('available_balance'));
  284. $this->assertEquals('0.0090000000', bcsub((string)DB::table('share_accounts')->value('earned_amount'), (string)DB::table('share_accounts')->value('paid_amount'), 10));
  285. $this->assertNull(DB::table('share_claims')->value('active_user_id'));
  286. $this->claims->audit($id, 'approve', 8, '重复');
  287. $this->assertSame(1, DB::table('balance_logs')->count());
  288. $this->assertSame(1, DB::table('operation_audits')->count());
  289. $this->assertSame('分享佣金领取', DB::table('balance_logs')->value('change_type'));
  290. $this->assertSame(8, (int)DB::table('operation_audits')->value('operator_id'));
  291. $this->fails(fn () => $this->claims->audit($id, 'reject', 8), '不可更改');
  292. }
  293. public function test_recomputed_insufficiency_blocks_approval_and_rejection_releases_full_reservation(): void
  294. {
  295. $id = $this->pending('5.00', '10.01');
  296. $this->assertFalse($this->claims->detail($id)['can_approve']);
  297. $this->fails(fn () => $this->claims->audit($id, 'approve', 8), '重新申请');
  298. $this->assertSame('pending', DB::table('share_claims')->value('status'));
  299. $this->assertEquals(20, DB::table('wallets')->value('available_balance'));
  300. $rejected = $this->claims->audit($id, 'reject', 8, '请重新申请');
  301. $this->assertSame('5.00', $rejected['commission_account']['spendable_amount']);
  302. $this->assertSame(0, DB::table('balance_logs')->count());
  303. $this->claims->audit($id, 'reject', 8);
  304. $this->assertSame(1, DB::table('operation_audits')->count());
  305. }
  306. public function test_audit_failure_rolls_back_wallet_log_account_and_claim(): void
  307. {
  308. $id = $this->pending();
  309. DB::statement("CREATE TRIGGER block_operation_audit BEFORE INSERT ON bot_operation_audits BEGIN SELECT RAISE(ABORT, 'audit offline'); END");
  310. try { $this->claims->audit($id, 'approve', 8); $this->fail('Expected audit write failure'); }
  311. catch (\Illuminate\Database\QueryException $e) { $this->assertStringContainsString('audit offline', $e->getMessage()); }
  312. $this->assertEquals(20, DB::table('wallets')->value('available_balance'));
  313. $this->assertSame('pending', DB::table('share_claims')->value('status'));
  314. $this->assertEquals(0, DB::table('share_accounts')->value('paid_amount'));
  315. $this->assertEquals('10.01', DB::table('share_accounts')->value('reserved_amount'));
  316. $this->assertSame(0, DB::table('balance_logs')->count());
  317. }
  318. public function test_admin_controller_envelopes_and_filtered_lists(): void
  319. {
  320. $id = $this->pending();
  321. $this->assertSame(0, (new ShareEarning())->settings($this->admin)->getData(true)['code']);
  322. $request = Request::create('/admin/shareEarning/claims/audit', 'POST', ['id' => $id, 'action' => 'approve']);
  323. $request->user = (object)['id' => 8, 'username' => 'admin'];
  324. $this->app->instance('request', $request);
  325. $body = (new SharingManagement())->auditClaim($this->claims)->getData(true);
  326. $this->assertSame(0, $body['code']); $this->assertSame('approved', $body['data']['status']);
  327. $list = $this->claims->list(['status' => 'approved', 'account' => 'member7', 'start_date' => '2026-10-24', 'end_date' => '2026-10-24']);
  328. $this->assertSame(1, $list['total']); $this->assertSame('10.01', $list['data'][0]['amount']);
  329. $this->assertSame(0, $this->claims->list(['status' => 'pending'])['total']);
  330. }
  331. public function test_database_errors_do_not_expose_sql_in_admin_responses(): void
  332. {
  333. $this->app->instance('log', new \Psr\Log\NullLogger());
  334. DB::statement('DROP TABLE bot_share_levels');
  335. $body = (new SharingManagement())->levels($this->admin)->getData(true);
  336. $this->assertSame(-3, $body['code']);
  337. $this->assertStringContainsString('暂不可用', $body['msg']);
  338. $this->assertStringNotContainsString('SQLSTATE', $body['msg']);
  339. $this->assertStringNotContainsString('share_levels', $body['msg']);
  340. }
  341. public function test_money_configuration_cannot_lose_subcent_values_during_frontend_roundtrip(): void
  342. {
  343. $this->initialized();
  344. $this->fails(fn () => $this->admin->saveSettings($this->config(['valid_member_min_effective_bet'=>'0.001'])), 'regex');
  345. $this->fails(fn () => $this->admin->saveRateRules('third:2', [['min_valid_members'=>0,'min_performance'=>'0.001','rate'=>'0.1']]), 'regex');
  346. $this->fails(fn () => $this->admin->saveLevel(['level'=>2,'name'=>'二级','image'=>'','incremental_commission'=>'0.001']), 'regex');
  347. $this->assertSame(1, DB::table('share_policies')->count());
  348. $this->assertSame(1, DB::table('share_levels')->count());
  349. }
  350. }