PromotionActivitiesTest.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. <?php
  2. namespace Tests\Integration;
  3. use App\Http\Controllers\admin\ActivityReward as AdminActivity;
  4. use App\Models\PromotionActivity as ActivityReward;
  5. use App\Models\BalanceLog;
  6. use App\Services\PromotionAdminService;
  7. use App\Services\PromotionFacts;
  8. use App\Services\PromotionService;
  9. use App\Support\PromotionRules;
  10. use Carbon\Carbon;
  11. use Illuminate\Config\Repository;
  12. use Illuminate\Database\Capsule\Manager;
  13. use Illuminate\Database\Schema\Blueprint;
  14. use Illuminate\Foundation\Application;
  15. use Illuminate\Http\Request;
  16. use Illuminate\Support\Facades\DB;
  17. use Illuminate\Support\Facades\Facade;
  18. use Illuminate\Translation\ArrayLoader;
  19. use Illuminate\Translation\Translator;
  20. use Illuminate\Validation\Factory;
  21. use Illuminate\Validation\ValidationException;
  22. use PHPUnit\Framework\TestCase;
  23. /** Runs real migrations, qualification, wallet writes and state machines in SQLite, without .env/providers. */
  24. class PromotionActivitiesTest extends TestCase
  25. {
  26. private Application $app;
  27. private PromotionService $service;
  28. private string $originalTimezone;
  29. protected function setUp(): void
  30. {
  31. $this->originalTimezone = date_default_timezone_get(); date_default_timezone_set('Asia/Shanghai'); Carbon::setTestNow(Carbon::parse('2026-10-26 12:00:00', 'Asia/Shanghai'));
  32. Facade::clearResolvedInstances(); $this->app = new Application(dirname(__DIR__, 2));
  33. $this->app->instance('config', new Repository(['app' => ['locale' => 'zh', 'timezone' => 'Asia/Shanghai'], 'third_game' => ['currency' => 'CNY']])); Facade::setFacadeApplication($this->app);
  34. $db = new Manager($this->app); $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'bot_']);
  35. $db->setAsGlobal(); $db->bootEloquent(); $this->app->instance('db', $db->getDatabaseManager()); $this->app->bind('db.schema', fn () => $db->schema());
  36. $this->app->instance('translator', new Translator(new ArrayLoader(), 'zh'));
  37. $this->app->instance('validator', new Factory($this->app['translator'], $this->app));
  38. $this->app->instance('log', new \Psr\Log\NullLogger()); $this->app->instance('request', Request::create('/api/promotion/progress'));
  39. $this->app->instance(\Illuminate\Contracts\Routing\ResponseFactory::class, new class {
  40. public function json($data, $status = 200, $headers = [], $options = 0) { return new \Illuminate\Http\JsonResponse($data, $status, $headers, $options); }
  41. });
  42. Request::macro('validate', function ($rules) { return app('validator')->make($this->all(), $rules)->validate(); });
  43. foreach ([
  44. 'activity_rewards' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,title TEXT,sub_title TEXT,type INTEGER,status INTEGER,start_time INTEGER,end_time INTEGER,lang TEXT,params TEXT,detail_image TEXT,pc_image TEXT,detail_banner TEXT,pc_banner TEXT,content TEXT,created_at TEXT,updated_at TEXT',
  45. 'users' => 'id INTEGER PRIMARY KEY,member_id TEXT UNIQUE,user_id TEXT,language TEXT,"from" INTEGER,level INTEGER DEFAULT 0,recharge_channel_group_id INTEGER DEFAULT 1,created_at TEXT,updated_at TEXT',
  46. 'wallets' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,member_id TEXT UNIQUE,available_balance TEXT DEFAULT "0",frozen_balance TEXT DEFAULT "0",created_at TEXT,updated_at TEXT',
  47. 'balance_logs' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,member_id TEXT,type INTEGER DEFAULT 1,amount TEXT,change_type TEXT,before_balance TEXT,after_balance TEXT,related_id INTEGER,remark TEXT,frozen_status INTEGER,created_at TEXT,updated_at TEXT',
  48. 'share_members' => 'user_id INTEGER PRIMARY KEY,parent_user_id INTEGER,bound_at TEXT',
  49. 'share_policies' => 'id INTEGER PRIMARY KEY,effective_date TEXT,valid_member_min_deposit TEXT,valid_member_min_effective_bet TEXT',
  50. 'share_bet_facts' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,user_id INTEGER,source TEXT,source_id TEXT,bet_at TEXT,bet_amount TEXT,net_profit TEXT,effective_amount TEXT,currency TEXT,settled INTEGER DEFAULT 1,voided INTEGER DEFAULT 0',
  51. 'user_login' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,user_id TEXT,status INTEGER,platform TEXT,created_at TEXT',
  52. 'reporting_activity' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,user_id INTEGER,session_hash TEXT,observed_at TEXT',
  53. 'menus' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,parent_id INTEGER,title TEXT,icon TEXT,uri TEXT,permission_name TEXT,sort INTEGER,status INTEGER,type INTEGER,created_at TEXT,updated_at TEXT',
  54. ] as $table => $columns) DB::statement('CREATE TABLE bot_' . $table . ' (' . $columns . ')');
  55. foreach (['2026_10_13_120000_add_activity_eligibility_fields.php', '2026_10_14_120000_add_activity_reward_quotas.php', '2026_10_25_120000_add_game_category_to_activity_rewards.php', '2026_10_26_160000_create_promotion_activities.php', '2026_10_27_130000_initialize_fixed_promotion_activities.php', '2026_10_27_140000_add_promotion_activity_translations.php'] as $migration) (require dirname(__DIR__, 2) . '/database/migrations/' . $migration)->up();
  56. $this->member(1); $this->member(2, 1);
  57. DB::table('share_policies')->insert(['id' => 1, 'effective_date' => '2026-10-01', 'valid_member_min_deposit' => '200', 'valid_member_min_effective_bet' => '300']);
  58. $this->service = new PromotionService();
  59. }
  60. protected function tearDown(): void { Carbon::setTestNow(); date_default_timezone_set($this->originalTimezone); DB::disconnect(); Facade::clearResolvedInstances(); parent::tearDown(); }
  61. private function travel(string $time): void { Carbon::setTestNow(Carbon::parse($time, 'Asia/Shanghai')); }
  62. private function member(int $id, ?int $parent = null, string $at = '2026-10-01 00:00:00'): void
  63. {
  64. DB::table('users')->insert(['id' => $id, 'member_id' => 'm' . $id, 'user_id' => 'u' . $id, 'language' => 'zh', 'from' => 1, 'created_at' => $at, 'updated_at' => $at]);
  65. DB::table('wallets')->insert(['member_id' => 'm' . $id, 'available_balance' => '0', 'frozen_balance' => '0']);
  66. if ($parent) DB::table('share_members')->insert(['user_id' => $id, 'parent_user_id' => $parent, 'bound_at' => $at]);
  67. }
  68. private function activity(int $type = 9, array $params = [], int $status = 1): int
  69. {
  70. $input = ['translations' => $this->texts(), 'type' => $type, 'status' => $status,
  71. 'start_time' => '2026-10-01 00:00:00', 'end_time' => '2026-12-31 23:59:59', 'lang' => 'zh', 'params' => $params];
  72. if (in_array($type, [7, 9], true)) $input['id'] = (int) DB::table('promotion_activities')->where('type', $type)->value('id');
  73. return (int) (new PromotionAdminService())->save($input)['id'];
  74. }
  75. private function texts(): array
  76. {
  77. return ['zh' => ['title' => '测试活动', 'content' => '<p>中文活动正文</p>'],
  78. 'en' => ['title' => 'Test promotion', 'content' => '<p>English content</p>'],
  79. 'vi' => ['title' => 'Khuyến mãi', 'content' => '<p>Nội dung</p>']];
  80. }
  81. private function deposit(int $id, string $amount, ?string $time = null, string $type = '充值'): BalanceLog
  82. {
  83. return BalanceLog::create(['member_id' => 'm' . $id, 'type' => 1, 'amount' => $amount, 'change_type' => $type, 'created_at' => $time ?? PromotionFacts::now()]);
  84. }
  85. private function rawDeposit(int $id, string $amount, string $time, string $type = '充值'): int
  86. {
  87. return DB::table('balance_logs')->insertGetId(['member_id' => 'm' . $id, 'type' => 1, 'amount' => $amount, 'change_type' => $type, 'created_at' => $time, 'updated_at' => $time]);
  88. }
  89. private function bet(int $id, string $stake, string $profit, string $time, array $extra = []): int
  90. {
  91. $next = (int)DB::table('share_bet_facts')->max('id') + 1;
  92. return DB::table('share_bet_facts')->insertGetId($extra + ['user_id' => $id, 'source' => 'sport_order', 'source_id' => (string)$next,
  93. 'bet_at' => $time, 'bet_amount' => $stake, 'net_profit' => $profit, 'effective_amount' => '999999', 'currency' => 'CNY', 'settled' => 1, 'voided' => 0]);
  94. }
  95. private function invalid(callable $callback, string $message): void
  96. {
  97. try { $callback(); $this->fail('Expected validation failure: ' . $message); }
  98. catch (ValidationException $e) { $this->assertStringContainsString($message, $e->validator->errors()->first()); }
  99. }
  100. private function complete(int $activity): array
  101. {
  102. $this->rawDeposit(1, '3000', '2026-10-26 12:01:00'); $this->rawDeposit(2, '500', '2026-10-26 12:01:00');
  103. $this->bet(1, '6000', '-5000', '2026-10-26 12:01:00'); $this->bet(2, '4000', '-3000', '2026-10-26 12:01:00');
  104. DB::table('user_login')->insert(['user_id' => 'm1', 'status' => 1, 'platform' => 'H5', 'created_at' => '2026-10-26 12:01:00']);
  105. for ($i = 0; $i <= 60; ++$i) DB::table('reporting_activity')->insert(['user_id' => 1, 'session_hash' => 'a', 'observed_at' => Carbon::parse('2026-10-26 12:01:00')->addMinutes($i)->format('Y-m-d H:i:s')]);
  106. $this->travel('2026-10-26 14:00:00'); return $this->service->progress($activity, 1, 'H5');
  107. }
  108. public function test_images_are_only_configurable_for_first_deposit_not_fixed_loss_or_wheel_campaigns(): void
  109. {
  110. $admin = new PromotionAdminService();
  111. foreach ([7, 8, 9] as $type) {
  112. $id = $this->activity($type);
  113. DB::table('promotion_activities')->where('id', $id)->update(['image' => 'previous.png']);
  114. $input = $admin->detail($id); $input['image'] = $type === 8 ? 'first-deposit.png' : ['ignored-legacy-upload'];
  115. $saved = $admin->save($input);
  116. foreach ([$saved, $admin->detail($id), $admin->listing(['type' => $type])['data'][0], $this->service->listing(1, 'H5', 'zh', $type)['data'][0]] as $row) {
  117. $this->assertSame($type === 8, array_key_exists('image', $row));
  118. }
  119. $this->assertSame($type === 8 ? 'first-deposit.png' : 'previous.png', DB::table('promotion_activities')->where('id', $id)->value('image'));
  120. }
  121. }
  122. public function test_subtitles_are_not_required_saved_or_returned_for_any_independent_activity(): void
  123. {
  124. $admin = new PromotionAdminService();
  125. foreach ([7, 8, 9] as $type) {
  126. $id = $this->activity($type); $legacy = $this->texts();
  127. foreach ($legacy as &$text) $text['sub_title'] = 'Historical subtitle'; unset($text);
  128. DB::table('promotion_activities')->where('id', $id)->update(['sub_title' => 'Historical subtitle', 'translations' => json_encode($legacy)]);
  129. $detail = $admin->detail($id);
  130. $this->assertArrayNotHasKey('sub_title', $detail);
  131. foreach ($detail['translations'] as $text) $this->assertSame(['title', 'content'], array_keys($text));
  132. $input = $detail; $input['sub_title'] = 'Ignored legacy input';
  133. foreach ($input['translations'] as &$text) $text['sub_title'] = ['ignored legacy input']; unset($text);
  134. $saved = $admin->save($input);
  135. $this->assertSame($this->texts(), $saved['translations']);
  136. $this->assertSame('Historical subtitle', DB::table('promotion_activities')->where('id', $id)->value('sub_title'));
  137. foreach ([$saved, $admin->listing(['type' => $type])['data'][0], $admin->status($id, 1),
  138. $this->service->listing(1, 'H5', 'zh', $type)['data'][0], $this->service->detail($id, 1, 'H5', 'zh')] as $row) {
  139. $this->assertArrayNotHasKey('sub_title', $row);
  140. }
  141. }
  142. }
  143. public function test_three_languages_edit_one_campaign_and_keep_rules_history_and_other_tabs(): void
  144. {
  145. $admin = new PromotionAdminService();
  146. foreach ([7, 8, 9] as $type) {
  147. $id = $this->activity($type); $before = $admin->detail($id);
  148. $count = DB::table('promotion_activities')->count();
  149. $input = $before; $input['translations']['en']['title'] = 'Updated English title';
  150. $saved = $admin->save($input);
  151. $this->assertSame($id, $saved['id']);
  152. $this->assertSame($count, DB::table('promotion_activities')->count());
  153. $this->assertSame($before['translations']['zh'], $saved['translations']['zh']);
  154. $this->assertSame($before['translations']['vi'], $saved['translations']['vi']);
  155. $this->assertSame('Updated English title', $admin->detail($id)['translations']['en']['title']);
  156. foreach (['params', 'rewarded_count', 'budget_used', 'first_published_at'] as $field) $this->assertSame($before[$field], $saved[$field]);
  157. foreach (['zh', 'en', 'vi'] as $lang) {
  158. $rows = $this->service->listing(1, 'H5', $lang, $type)['data'];
  159. $this->assertCount(1, $rows); $this->assertSame($id, $rows[0]['activity_id']);
  160. $this->assertSame($saved['translations'][$lang]['title'], $rows[0]['title']);
  161. $state = $this->service->detail($id, 1, 'H5', $lang);
  162. $this->assertSame($lang, $state['lang']);
  163. $this->assertSame($saved['translations'][$lang]['title'], $state['title']);
  164. $this->assertSame($saved['translations'][$lang]['content'], $state['content']);
  165. }
  166. }
  167. $this->assertSame(['zh', 'en', 'vi'], array_column($admin->options()['languages'], 'value'));
  168. }
  169. public function test_all_six_text_fields_are_required_and_invalid_tabs_cannot_overwrite_saved_content(): void
  170. {
  171. $id = $this->activity(9); $admin = new PromotionAdminService(); $input = $admin->detail($id);
  172. $before = DB::table('promotion_activities')->where('id', $id)->first();
  173. foreach (['zh', 'en', 'vi'] as $lang) {
  174. foreach (['title', 'content'] as $field) {
  175. $bad = $input; unset($bad['translations'][$lang][$field]);
  176. try { $admin->save($bad); $this->fail('Missing language text was accepted'); }
  177. catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations.' . $lang . '.' . $field)); }
  178. $bad = $input; $bad['translations'][$lang][$field] = '<p>&nbsp;<br></p>';
  179. $this->invalid(fn () => $admin->save($bad), '不能为空');
  180. }
  181. $bad = $input; unset($bad['translations'][$lang]);
  182. $this->invalid(fn () => $admin->save($bad), '完整填写');
  183. }
  184. $bad = $input; unset($bad['translations']); $bad['title'] = '旧单语言表单';
  185. $this->invalid(fn () => $admin->save($bad), '完整填写');
  186. $bad = $input; $bad['translations']['fr'] = $input['translations']['en'];
  187. try { $admin->save($bad); $this->fail('Unknown language was accepted'); }
  188. catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations')); }
  189. $bad = $input; $bad['translations']['en']['title'] = str_repeat('a', 141);
  190. try { $admin->save($bad); $this->fail('Oversized title was accepted'); }
  191. catch (ValidationException $e) { $this->assertTrue($e->validator->errors()->has('translations.en.title')); }
  192. $this->assertEquals($before, DB::table('promotion_activities')->where('id', $id)->first());
  193. }
  194. public function test_admin_http_save_returns_all_tabs_and_rejects_partial_language_payloads(): void
  195. {
  196. $controller = new \App\Http\Controllers\admin\Promotion(); $admin = new PromotionAdminService();
  197. $input = ['type' => 8, 'status' => 0, 'start_time' => '2026-10-26', 'end_time' => '2026-12-31', 'translations' => $this->texts()];
  198. $this->app->instance('request', Request::create('/admin/promotion/submit', 'POST', $input));
  199. $saved = $controller->submit($admin)->getData(true);
  200. $this->assertSame(0, $saved['code']); $this->assertSame($this->texts(), $saved['data']['translations']);
  201. $input['id'] = $saved['data']['id']; unset($input['translations']['en']);
  202. $this->app->instance('request', Request::create('/admin/promotion/submit', 'POST', $input));
  203. $failed = $controller->submit($admin)->getData(true);
  204. $this->assertSame(-3, $failed['code']); $this->assertStringContainsString('英文', $failed['msg']);
  205. $this->assertSame($this->texts(), $admin->detail($input['id'])['translations']);
  206. }
  207. public function test_incomplete_legacy_activity_can_be_hidden_but_cannot_be_published_without_all_tabs(): void
  208. {
  209. $id = (int) DB::table('promotion_activities')->where('type', 7)->value('id');
  210. $admin = new PromotionAdminService();
  211. $this->assertSame(0, (int) $admin->status($id, 0)['status']);
  212. $this->invalid(fn () => $admin->status($id, 1), '不能为空');
  213. $this->assertSame(0, (int) DB::table('promotion_activities')->where('id', $id)->value('status'));
  214. $this->assertNull(DB::table('promotion_campaigns')->where('activity_id', $id)->value('first_published_at'));
  215. }
  216. public function test_first_deposit_translation_does_not_split_or_duplicate_awards(): void
  217. {
  218. $id = $this->activity(8, ['min_deposit' => 100, 'reward_amount' => 25]);
  219. DB::table('users')->where('id', 1)->update(['language' => 'vi']);
  220. $deposit = $this->deposit(1, '100'); $this->service->onDeposit($deposit);
  221. $this->assertSame(1, DB::table('promotion_rewards')->where('activity_id', $id)->count());
  222. DB::table('users')->where('id', 1)->update(['language' => 'en']);
  223. $this->service->onDeposit($deposit);
  224. $this->assertSame(1, DB::table('promotion_rewards')->where('activity_id', $id)->count());
  225. $this->assertSame('25.0000000000', (string) DB::table('wallets')->where('member_id', 'm1')->value('available_balance'));
  226. $this->assertSame(1, DB::table('promotion_accounts')->where('activity_id', $id)->count());
  227. }
  228. public function test_translation_migration_preserves_legacy_texts_and_campaign_identity(): void
  229. {
  230. $migration = require dirname(__DIR__, 2) . '/database/migrations/2026_10_27_140000_add_promotion_activity_translations.php';
  231. $migration->down();
  232. $id = DB::table('promotion_activities')->where('type', 7)->value('id');
  233. DB::table('promotion_activities')->where('id', $id)->update(['lang' => 'en', 'title' => 'Existing title', 'sub_title' => 'Existing subtitle', 'content' => '<p>Existing content</p>']);
  234. $rows = DB::table('promotion_activities')->orderBy('id')->get();
  235. $published = DB::table('promotion_campaigns')->orderBy('activity_id')->get();
  236. $migration->up();
  237. foreach ($rows as $row) {
  238. $saved = DB::table('promotion_activities')->where('id', $row->id)->first();
  239. foreach ((array) $row as $field => $value) $this->assertSame($value, $saved->$field);
  240. }
  241. $texts = (new PromotionAdminService())->detail((int) $id)['translations'];
  242. $this->assertSame(['title' => 'Existing title', 'content' => '<p>Existing content</p>'], $texts['en']);
  243. $this->assertSame('', $texts['zh']['title']);
  244. $this->assertEquals($published, DB::table('promotion_campaigns')->orderBy('activity_id')->get());
  245. $this->assertSame(0, DB::table('menus')->count());
  246. $this->assertSame(0, $this->service->listing(1, 'H5', 'vi', 7)['total']);
  247. }
  248. public function test_probability_default_zero_boundaries_and_incomplete_gate(): void
  249. {
  250. $this->assertSame('20.00', PromotionRules::normalize(9, [])['completion_probability']);
  251. $this->assertSame('0.00', PromotionRules::normalize(9, ['completion_probability' => 0])['completion_probability']);
  252. $this->assertTrue(PromotionRules::draw(66599, true, '20.00', fn ($a, $b) => $a === 1 ? 2000 : 0)['reached']);
  253. $this->assertFalse(PromotionRules::draw(66599, true, '20.00', fn ($a, $b) => $a === 1 ? 2001 : 0)['reached']);
  254. $this->assertFalse(PromotionRules::draw(66599, false, '100.00', fn ($a, $b) => $a)['reached']);
  255. $this->invalid(fn () => PromotionRules::normalize(9, ['completion_probability' => 100.01]), 'between');
  256. }
  257. public function test_day_amounts_do_not_add_together_but_completed_flags_survive_midnight(): void
  258. {
  259. $id = $this->activity(); $this->service->progress($id, 1);
  260. $this->rawDeposit(1, '2000', '2026-10-26 13:00:00');
  261. $this->travel('2026-10-27 14:00:00'); $this->rawDeposit(1, '1000', '2026-10-27 12:00:00');
  262. $state = $this->service->progress($id, 1);
  263. $this->assertFalse($state['completed_tasks']['deposit']); $this->assertSame(0, (int)$state['spins']);
  264. $this->rawDeposit(1, '2000', '2026-10-27 13:00:00'); $state = $this->service->progress($id, 1);
  265. $this->assertTrue($state['completed_tasks']['deposit']); $this->assertSame(1, (int)$state['spins']);
  266. $this->travel('2026-10-28 14:00:00'); $state = $this->service->progress($id, 1);
  267. $this->assertTrue($state['completed_tasks']['deposit']); $this->assertSame(1, (int)$state['spins']);
  268. }
  269. public function test_repeated_rounds_keep_unused_spins_and_daily_flags_but_require_new_other_events(): void
  270. {
  271. $id = $this->activity(9, ['completion_probability' => 100]); $state = $this->complete($id);
  272. $this->assertTrue($state['conditions_complete']); $this->assertSame(7, (int)$state['spins']);
  273. $spin = $this->service->spin($id, 1, 'request_spin_00001');
  274. $this->assertTrue($spin['spin']['reached']); $this->assertSame('666.00', $spin['spin']['coins']);
  275. $this->assertSame($spin['spin'], $this->service->spin($id, 1, 'request_spin_00001')['spin']);
  276. $claim = $this->service->claim($id, 1, 1); $this->assertSame(2, $claim['round_no']); $this->assertSame(6, (int)$claim['spins']);
  277. $this->assertTrue($this->service->claim($id, 1, 1)['replayed']);
  278. $state = $this->service->progress($id, 1); $this->assertSame('0.00', $state['coins']);
  279. $this->assertSame(6, (int)$state['spins']); $this->assertTrue($state['completed_tasks']['online']); $this->assertTrue($state['completed_tasks']['login']);
  280. foreach (['invite', 'deposit', 'team_deposit', 'bet', 'team_bet'] as $task) $this->assertFalse($state['completed_tasks'][$task]);
  281. $this->rawDeposit(1, '3000', '2026-10-26 14:00:00'); $this->rawDeposit(2, '500', '2026-10-26 14:00:00');
  282. $this->bet(1, '6000', '-5000', '2026-10-26 14:00:00'); $this->bet(2, '4000', '-3000', '2026-10-26 14:00:00');
  283. $this->member(3, 1, '2026-10-26 14:00:00'); $this->rawDeposit(3, '200', '2026-10-26 14:00:00'); $this->bet(3, '300', '-300', '2026-10-26 14:00:00');
  284. $state = $this->service->progress($id, 1); $this->assertTrue($state['conditions_complete']); $this->assertSame(11, (int)$state['spins']);
  285. $this->assertTrue($this->service->spin($id, 1, 'request_spin_00002')['spin']['reached']); $this->service->claim($id, 1, 2);
  286. $this->assertSame('1332.0000000000', (string)DB::table('wallets')->where('member_id', 'm1')->value('available_balance'));
  287. $this->assertSame(2, DB::table('promotion_rewards')->count()); $this->assertSame(1, (int)DB::table('promotion_activities')->where('id', $id)->value('rewarded_count'));
  288. }
  289. public function test_probability_changes_affect_new_spins_and_reserved_reward_can_be_claimed_after_down(): void
  290. {
  291. $id = $this->activity(9, ['completion_probability' => 0]); $this->complete($id);
  292. $first = $this->service->spin($id, 1, 'request_spin_00001'); $this->assertFalse($first['spin']['reached']);
  293. $row = ActivityReward::find($id); $rules = json_decode($row->params, true); $rules['completion_probability'] = '100.00'; $row->params = json_encode($rules); $row->save();
  294. $next = $this->service->spin($id, 1, 'request_spin_00002'); $this->assertTrue($next['spin']['reached']);
  295. $this->assertSame('0', (string)DB::table('promotion_spins')->orderBy('id')->value('probability'));
  296. DB::table('promotion_activities')->where('id', $id)->update(['status' => 0]);
  297. $this->service->claim($id, 1, 1); $this->invalid(fn () => $this->service->progress($id, 1), '未上架');
  298. $this->assertTrue($this->service->claim($id, 1, 1)['replayed']);
  299. }
  300. public function test_first_deposit_is_historical_first_and_does_not_refill_on_relisting(): void
  301. {
  302. $id = $this->activity(8, ['min_deposit' => '100', 'reward_amount' => '25']);
  303. $first = $this->deposit(1, '99'); $this->service->onDeposit($first); $this->service->onDeposit($first);
  304. $second = $this->deposit(1, '1000'); $this->service->onDeposit($second);
  305. $this->assertSame(0, DB::table('promotion_rewards')->count());
  306. $other = $this->deposit(2, '100'); $this->service->onDeposit($other); $this->service->onDeposit($other);
  307. $this->assertSame(1, DB::table('promotion_rewards')->count());
  308. $this->assertSame('25.0000000000', (string)DB::table('wallets')->where('member_id', 'm2')->value('available_balance'));
  309. $published = DB::table('promotion_campaigns')->where('activity_id', $id)->value('first_published_at');
  310. $this->travel('2026-10-27 12:00:00'); $row = ActivityReward::find($id); $row->status = 0; $row->save(); PromotionService::publish($row);
  311. $row->status = 1; $row->save(); PromotionService::publish($row);
  312. $this->assertSame($published, DB::table('promotion_campaigns')->where('activity_id', $id)->value('first_published_at'));
  313. $this->service->onDeposit($this->deposit(2, '500')); $this->assertSame(1, DB::table('promotion_rewards')->count());
  314. }
  315. public function test_loss_uses_post_publication_net_profit_then_only_new_direct_invitees_with_both_thresholds(): void
  316. {
  317. $this->bet(1, '900', '-900', '2026-10-25 12:00:00'); $id = $this->activity(7);
  318. $this->invalid(fn () => $this->service->apply($id, 1), '净亏');
  319. $this->bet(1, '600', '-600', '2026-10-26 12:00:00'); $this->bet(1, '200', '100', '2026-10-26 12:00:00');
  320. // A referral created in the same second, but before applying, is still an existing user.
  321. DB::table('users')->where('id', 2)->update(['created_at' => '2026-10-26 12:00:00']);
  322. DB::table('share_members')->where('user_id', 2)->update(['bound_at' => '2026-10-26 12:00:00']);
  323. $this->service->apply($id, 1); $this->service->apply($id, 1);
  324. $this->rawDeposit(2, '500', '2026-10-26 12:00:00'); $this->bet(2, '300', '-300', '2026-10-26 12:00:00');
  325. foreach ([3, 4, 5] as $child) {
  326. $this->member($child, 1, '2026-10-26 12:00:00'); $this->rawDeposit($child, '200', '2026-10-26 12:00:00');
  327. if ($child !== 5) $this->bet($child, '300', '-300', '2026-10-26 12:00:00');
  328. }
  329. $this->invalid(fn () => $this->service->claim($id, 1, 1), '人数不足');
  330. $this->bet(5, '1000', '-300', '2026-10-26 12:00:00'); $this->service->claim($id, 1, 1); $this->service->claim($id, 1, 1);
  331. $this->assertSame(1, DB::table('promotion_rewards')->count()); $this->assertSame('500.0000000000', (string)DB::table('wallets')->where('member_id', 'm1')->value('available_balance'));
  332. }
  333. public function test_successful_online_time_deduplicates_devices_and_does_not_count_closed_session_as_online(): void
  334. {
  335. $id = $this->activity();
  336. foreach (['a', 'b'] as $session) for ($i = 0; $i <= 30; ++$i) DB::table('reporting_activity')->insert(['user_id' => 1, 'session_hash' => $session,
  337. 'observed_at' => Carbon::parse('2026-10-26 12:00:00')->addMinutes($i)->format('Y-m-d H:i:s')]);
  338. $this->travel('2026-10-26 16:00:00'); $state = $this->service->progress($id, 1);
  339. $this->assertArrayNotHasKey('online', $state['completed_tasks']);
  340. $this->assertSame(1800, (new PromotionFacts())->online(1, '2026-10-26 12:00:00')['2026-10-26']);
  341. }
  342. public function test_effective_minimum_void_pending_and_next_day_policy_are_respected(): void
  343. {
  344. DB::table('share_policies')->insert(['id' => 2, 'effective_date' => '2026-10-27', 'valid_member_min_deposit' => '9999', 'valid_member_min_effective_bet' => '9999']);
  345. $facts = new PromotionFacts(); $this->assertSame(1, $facts->policy()['id']);
  346. $this->bet(1, '1000', '50', '2026-10-26 12:00:00'); $this->bet(1, '500', '-500', '2026-10-26 12:00:00', ['voided' => 1]);
  347. $this->bet(1, '500', '-500', '2026-10-26 12:00:00', ['settled' => 0]);
  348. $this->assertSame('50.0000000000', $facts->total($facts->betting([1], '2026-10-26 12:00:00')['effective']));
  349. $this->travel('2026-10-27 00:00:00'); $this->assertSame(2, $facts->policy()['id']);
  350. }
  351. public function test_turnover_rewards_only_unlock_from_new_bets_and_only_once(): void
  352. {
  353. $id = $this->activity(8, ['min_deposit' => 100, 'reward_amount' => 25, 'turnover_ratio' => 2]);
  354. $this->bet(1, '100', '-100', '2026-10-26 12:00:00');
  355. $this->service->onDeposit($this->deposit(1, '100')); $this->assertSame(0, $this->service->unlock(1));
  356. $this->bet(1, '1000', '-49', '2026-10-26 12:00:00'); $this->assertSame(0, $this->service->unlock(1));
  357. $this->bet(1, '1', '-1', '2026-10-26 12:00:00'); $this->assertSame(1, $this->service->unlock(1)); $this->assertSame(0, $this->service->unlock(1));
  358. $this->assertSame('25.0000000000', (string)DB::table('wallets')->where('member_id', 'm1')->value('available_balance'));
  359. $this->assertSame('0.0000000000', (string)DB::table('wallets')->where('member_id', 'm1')->value('frozen_balance'));
  360. }
  361. public function test_quota_is_checked_before_consuming_a_spin_and_a_win_reserves_its_slot(): void
  362. {
  363. $id = $this->activity(9, ['completion_probability' => 100]); $this->complete($id);
  364. DB::table('promotion_activities')->where('id', $id)->update(['reward_quota' => 0]);
  365. $this->invalid(fn () => $this->service->spin($id, 1, 'request_spin_00001'), '份数');
  366. $this->assertSame(7, (int)DB::table('promotion_accounts')->value('spins'));
  367. DB::table('promotion_activities')->where('id', $id)->update(['reward_quota' => 1]);
  368. $this->service->spin($id, 1, 'request_spin_00001');
  369. $this->assertSame('reserved', DB::table('promotion_rewards')->value('status')); $this->assertSame(1, (int)DB::table('promotion_activities')->where('id', $id)->value('rewarded_count'));
  370. }
  371. public function test_independent_campaigns_do_not_touch_old_catalog_and_member_routes_live_in_member_project(): void
  372. {
  373. $id = $this->activity(9); $this->activity(7); $this->activity(8);
  374. $this->assertSame(0, DB::table('activity_rewards')->count());
  375. $this->assertArrayNotHasKey(9, \App\Support\ActivityCatalog::activityTypes());
  376. $this->assertSame(3, $this->service->listing(1, 'H5')['total']);
  377. $this->assertSame($id, $this->service->listing(1, 'H5', 'zh', 9)['data'][0]['activity_id']);
  378. $this->assertSame(0, DB::table('menus')->count(), 'Activity setup must leave menus to the frontend');
  379. $router = new \Illuminate\Routing\Router(new \Illuminate\Events\Dispatcher($this->app), $this->app); $this->app->instance('router', $router);
  380. $router->group(['prefix' => 'api'], function () { require dirname(__DIR__, 2) . '/routes/api.php'; });
  381. $memberRoutes=array_filter($router->getRoutes()->getRoutes(),fn ($route)=>str_starts_with($route->uri(),'api/promotion'));
  382. $this->assertSame([],$memberRoutes,'Member promotion routes must be owned by melbet_sport-api');
  383. $router->group(['prefix' => 'admin'], function () { require dirname(__DIR__, 2) . '/routes/admin.php'; });
  384. $route = $router->getRoutes()->match(Request::create('/admin/promotion/submit', 'POST'));
  385. $this->assertContains('admin.jwt', $route->middleware()); $this->assertContains('check.button.uri', $route->middleware());
  386. }
  387. public function test_promotion_migration_preserves_frontend_owned_menus_on_up_and_down(): void
  388. {
  389. DB::table('menus')->insert([
  390. ['id' => 1, 'parent_id' => 0, 'title' => '前端活动菜单', 'uri' => 'promotion', 'permission_name' => 'promotion.manage', 'type' => 1],
  391. ['id' => 2, 'parent_id' => 1, 'title' => '前端活动记录', 'uri' => 'admin/promotion/records', 'permission_name' => 'admin.promotion.records', 'type' => 2],
  392. ['id' => 3, 'parent_id' => 0, 'title' => '其他菜单', 'uri' => 'other', 'permission_name' => 'other.manage', 'type' => 1],
  393. ]);
  394. $before = DB::table('menus')->orderBy('id')->get()->toJson();
  395. $migration = require dirname(__DIR__, 2) . '/database/migrations/2026_10_26_160000_create_promotion_activities.php';
  396. $migration->down();
  397. $this->assertSame($before, DB::table('menus')->orderBy('id')->get()->toJson(), 'Rollback must preserve frontend menus and permissions');
  398. $this->assertFalse(DB::connection()->getSchemaBuilder()->hasTable('promotion_activities'));
  399. $migration->up();
  400. $this->assertSame($before, DB::table('menus')->orderBy('id')->get()->toJson(), 'Migration must not add or modify frontend menus and permissions');
  401. $this->assertTrue(DB::connection()->getSchemaBuilder()->hasTable('promotion_activities'));
  402. }
  403. public function test_admin_http_amounts_are_compact_without_changing_saved_rules_or_counters(): void
  404. {
  405. $id = $this->activity(8, ['min_deposit' => '200', 'reward_amount' => '10.12']);
  406. $request = Request::create('/admin/promotion/detail', 'GET', ['id' => $id]); $this->app->instance('request', $request);
  407. $response = (new \App\Http\Controllers\admin\Promotion())->detail(new PromotionAdminService())->getData(true);
  408. $this->assertSame(0, $response['code']);
  409. $this->assertSame('200', $response['data']['params']['min_deposit']);
  410. $this->assertSame('10.12', $response['data']['params']['reward_amount']);
  411. $this->assertSame($id, $response['data']['id']);
  412. $saved = json_decode(DB::table('promotion_activities')->where('id', $id)->value('params'), true);
  413. $this->assertSame('200.00', $saved['min_deposit']);
  414. $this->assertSame('10.12', $saved['reward_amount']);
  415. }
  416. public function test_fixed_activities_are_initialized_disabled_without_publishing_or_creating_menus(): void
  417. {
  418. $this->assertSame(2, DB::table('promotion_activities')->count());
  419. foreach ([7, 9] as $type) {
  420. $row = DB::table('promotion_activities')->where('type', $type)->first();
  421. $this->assertNotNull($row); $this->assertSame(0, (int) $row->status);
  422. $this->assertNull(DB::table('promotion_campaigns')->where('activity_id', $row->id)->value('first_published_at'));
  423. }
  424. $options = (new PromotionAdminService())->options();
  425. $this->assertSame([7, 8, 9], array_column($options['types'], 'value'));
  426. $this->assertSame([8], array_column($options['create_types'], 'value'));
  427. $this->assertSame(0, DB::table('menus')->count());
  428. }
  429. public function test_fixed_types_cannot_be_created_even_when_no_configuration_exists(): void
  430. {
  431. $admin = new PromotionAdminService();
  432. foreach ([7, 9] as $type) {
  433. $input = ['translations' => $this->texts(), 'type' => $type, 'status' => 0,
  434. 'start_time' => '2026-10-01 00:00:00', 'end_time' => '2026-12-31 23:59:59'];
  435. $this->invalid(fn () => $admin->save($input), '不支持新增');
  436. $this->assertSame(1, DB::table('promotion_activities')->where('type', $type)->count());
  437. $id = DB::table('promotion_activities')->where('type', $type)->value('id');
  438. DB::table('promotion_campaigns')->where('activity_id', $id)->delete();
  439. DB::table('promotion_activities')->where('id', $id)->delete();
  440. $this->invalid(fn () => $admin->save($input), '不支持新增');
  441. $this->assertSame(0, DB::table('promotion_activities')->where('type', $type)->count());
  442. }
  443. }
  444. public function test_first_deposit_still_allows_multiple_new_configurations_and_type_change_is_rejected(): void
  445. {
  446. $first = $this->activity(8); $second = $this->activity(8);
  447. $this->assertNotSame($first, $second);
  448. $this->assertSame(2, DB::table('promotion_activities')->where('type', 8)->count());
  449. $this->invalid(fn () => (new PromotionAdminService())->save(['id' => $first, 'translations' => $this->texts(), 'type' => 9, 'status' => 0,
  450. 'start_time' => '2026-10-01 00:00:00', 'end_time' => '2026-12-31 23:59:59']), '不能变更活动类型');
  451. $this->assertSame(8, (int) DB::table('promotion_activities')->where('id', $first)->value('type'));
  452. }
  453. public function test_fixed_initialization_and_relisting_do_not_replace_existing_activity_or_reset_its_history(): void
  454. {
  455. $id = $this->activity(9, ['completion_probability' => 0]);
  456. DB::table('promotion_activities')->where('id', $id)->update(['rewarded_count' => 3, 'budget_used' => '1998']);
  457. $before = (array) DB::table('promotion_activities')->where('id', $id)->first();
  458. $published = DB::table('promotion_campaigns')->where('activity_id', $id)->value('first_published_at');
  459. $migration = require dirname(__DIR__, 2) . '/database/migrations/2026_10_27_130000_initialize_fixed_promotion_activities.php';
  460. $this->travel('2026-10-27 12:00:00'); $migration->up(); $migration->down();
  461. $this->assertSame($before, (array) DB::table('promotion_activities')->where('id', $id)->first());
  462. $this->assertSame(2, DB::table('promotion_activities')->count());
  463. $admin = new PromotionAdminService(); $admin->status($id, 0); $admin->status($id, 1);
  464. $this->assertSame($published, DB::table('promotion_campaigns')->where('activity_id', $id)->value('first_published_at'));
  465. $this->assertSame(3, (int) DB::table('promotion_activities')->where('id', $id)->value('rewarded_count'));
  466. }
  467. public function test_admin_partial_rule_edit_preserves_other_settings_and_zero_probability(): void
  468. {
  469. $id = $this->activity(9, ['turnover_ratio' => 3, 'deposit_amount' => 5000]);
  470. $saved = (new PromotionAdminService())->save(['id' => $id, 'translations' => $this->texts(), 'type' => 9, 'status' => 1,
  471. 'start_time' => '2026-10-01', 'end_time' => '2026-12-31', 'params' => ['completion_probability' => 0]]);
  472. $this->assertSame('0.00', $saved['params']['completion_probability']); $this->assertSame('3.00', $saved['params']['turnover_ratio']);
  473. $this->assertSame('5000.00', $saved['params']['deposit_amount']); $this->assertSame(0, DB::table('activity_rewards')->count());
  474. }
  475. public function test_voided_task_progress_is_not_eligible_for_completion_probability(): void
  476. {
  477. $id = $this->activity(9, ['completion_probability' => 100]); $this->complete($id);
  478. DB::table('share_bet_facts')->where('user_id', 2)->update(['voided' => 1]);
  479. $state = $this->service->progress($id, 1); $this->assertFalse($state['conditions_complete']);
  480. $this->assertFalse($state['completed_tasks']['invite']); $this->assertFalse($state['completed_tasks']['team_bet']);
  481. $this->assertFalse($this->service->spin($id, 1, 'request_spin_voided')['spin']['reached']);
  482. }
  483. public function test_real_chain_credit_hook_awards_first_deposit_once_and_rolls_back_a_failed_award(): void
  484. {
  485. foreach ([
  486. 'config' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,field TEXT,val TEXT',
  487. 'level' => 'id INTEGER PRIMARY KEY,level INTEGER,recharge TEXT',
  488. 'recharge_channel_group' => 'id INTEGER PRIMARY KEY,activity_type TEXT,deleted_at TEXT',
  489. 'backflow' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,date TEXT,member_id TEXT,recharge_amount TEXT DEFAULT "0",withdrawal_amount TEXT DEFAULT "0",backflow_ratio TEXT,amount TEXT,created_at TEXT,updated_at TEXT',
  490. 'recharges' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,member_id TEXT,status INTEGER,amount TEXT,created_at TEXT,updated_at TEXT',
  491. ] as $table => $columns) DB::statement('CREATE TABLE bot_' . $table . ' (' . $columns . ')');
  492. foreach (['huishui_percentage' => '0', 'huishui_restriction' => '0', 'recharge_rate' => '0'] as $field => $val) DB::table('config')->insert(compact('field', 'val'));
  493. $id = $this->activity(8, ['min_deposit' => 100, 'reward_amount' => 25]);
  494. $source = DB::table('recharges')->insertGetId(['member_id' => 'm1', 'status' => 0, 'amount' => 100]);
  495. $recharge = \App\Models\Recharge::find($source);
  496. $this->assertTrue(\App\Services\RechargeService::creditConfirmedRecharge($recharge, ['status' => 1], '100.00'));
  497. $this->assertFalse(\App\Services\RechargeService::creditConfirmedRecharge($recharge, ['status' => 1], '100.00'));
  498. $this->assertSame('125.0000000000', (string)DB::table('wallets')->where('member_id', 'm1')->value('available_balance'));
  499. $this->assertSame(1, DB::table('promotion_rewards')->count());
  500. $source = DB::table('recharges')->insertGetId(['member_id' => 'm2', 'status' => 0, 'amount' => 100]);
  501. DB::statement("CREATE TRIGGER reject_award BEFORE INSERT ON bot_promotion_rewards BEGIN SELECT RAISE(ABORT, 'award failure'); END");
  502. try { \App\Services\RechargeService::creditConfirmedRecharge(\App\Models\Recharge::find($source), ['status' => 1], '100.00'); $this->fail('Expected failed award'); }
  503. catch (\Illuminate\Database\QueryException $e) { $this->assertStringContainsString('award failure', $e->getMessage()); }
  504. $this->assertSame(0, (int)DB::table('recharges')->where('id', $source)->value('status'));
  505. $this->assertSame('0', (string)DB::table('wallets')->where('member_id', 'm2')->value('available_balance'));
  506. $this->assertSame(0, DB::table('balance_logs')->where('member_id', 'm2')->count());
  507. }
  508. public function test_promotion_heartbeat_records_login_once_and_online_without_other_reporting_tables(): void
  509. {
  510. DB::statement('DROP TABLE bot_reporting_activity'); $id = $this->activity();
  511. for ($i = 0; $i <= 60; ++$i) {
  512. $this->travel(Carbon::parse('2026-10-26 12:00:00')->addMinutes($i)->format('Y-m-d H:i:s'));
  513. $this->service->heartbeat(1, 'secret-token', 'H5'); $this->service->heartbeat(1, 'secret-token', 'H5');
  514. }
  515. $state = $this->service->progress($id, 1);
  516. $this->assertTrue($state['completed_tasks']['online']); $this->assertTrue($state['completed_tasks']['login']); $this->assertSame(2, (int)$state['spins']);
  517. $this->assertSame(61, DB::table('promotion_presence')->count());
  518. $this->assertStringNotContainsString('secret-token', DB::table('promotion_presence')->first()->session_hash);
  519. $this->assertCount(7, $state['tasks']); $this->assertSame(0, $state['tasks'][0]['remaining_seconds']);
  520. $this->travel('2026-10-27 00:01:00'); $this->service->heartbeat(1, 'secret-token', 'H5');
  521. $this->assertSame(3, (int)$this->service->progress($id, 1)['spins']);
  522. }
  523. public function test_missing_old_first_deposit_hook_is_not_back_awarded_when_campaign_starts_later(): void
  524. {
  525. $deposit = $this->deposit(1, '1000'); $this->travel('2026-10-26 13:00:00'); $this->activity(8);
  526. $this->service->onDeposit($deposit);
  527. $this->assertSame(0, DB::table('promotion_rewards')->count());
  528. }
  529. public function test_manual_payment_approval_keeps_first_deposit_bonus_instead_of_overwriting_it_with_principal(): void
  530. {
  531. foreach ([
  532. 'config' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,field TEXT,val TEXT',
  533. 'level' => 'id INTEGER PRIMARY KEY,level INTEGER,recharge TEXT',
  534. 'recharge_channel_group' => 'id INTEGER PRIMARY KEY,activity_type TEXT,deleted_at TEXT',
  535. 'backflow' => 'id INTEGER PRIMARY KEY AUTOINCREMENT,date TEXT,member_id TEXT,recharge_amount TEXT DEFAULT "0",withdrawal_amount TEXT DEFAULT "0",backflow_ratio TEXT,amount TEXT,created_at TEXT,updated_at TEXT',
  536. 'payment_orders' => 'id INTEGER PRIMARY KEY,member_id TEXT,status INTEGER,type INTEGER,amount TEXT,remark TEXT,state INTEGER,created_at TEXT,updated_at TEXT',
  537. ] as $table => $columns) DB::statement('CREATE TABLE bot_' . $table . ' (' . $columns . ')');
  538. foreach (['huishui_percentage' => '0', 'huishui_restriction' => '0', 'recharge_rate' => '0'] as $field => $val) DB::table('config')->insert(compact('field', 'val'));
  539. $this->activity(8, ['min_deposit' => 100, 'reward_amount' => 25]);
  540. DB::table('payment_orders')->insert(['id' => 1, 'member_id' => 'm1', 'status' => 5, 'type' => 3, 'amount' => '100']);
  541. $this->app->instance('request', Request::create('/admin/paymentOrder/manualAudit', 'POST', ['id' => 1, 'status' => 2]));
  542. $body = (new \App\Http\Controllers\admin\PaymentOrder())->manualAudit()->getData(true);
  543. $this->assertSame(0, $body['code'], $body['msg']);
  544. $this->assertSame('125.0000000000', (string)DB::table('wallets')->where('member_id', 'm1')->value('available_balance'));
  545. $deposit = DB::table('balance_logs')->where('change_type', '充值')->first();
  546. $this->assertSame('0', (string)$deposit->before_balance); $this->assertSame('100.0000000000', (string)$deposit->after_balance);
  547. $this->assertSame(1, DB::table('promotion_rewards')->count());
  548. $this->assertNotSame(0, (new \App\Http\Controllers\admin\PaymentOrder())->manualAudit()->getData(true)['code']);
  549. $this->assertSame(1, DB::table('promotion_rewards')->count());
  550. }
  551. }