PaymentChannelOptionsTest.php 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <?php
  2. namespace Tests\Integration;
  3. use App\Http\Controllers\admin\PaymentConfiguration;
  4. use App\Http\Controllers\admin\RechargeChannel;
  5. use App\Http\Controllers\admin\PaymentCompany;
  6. use App\Services\PaymentChannelLinkService;
  7. use App\Services\Payment\RechargeChannelConfigurationService;
  8. use App\Models\PaymentGateway;
  9. use App\Models\RechargeChannel as ChannelModel;
  10. use App\Services\Payment\PaymentProviderService;
  11. use App\Services\PaymentOrderService;
  12. use Illuminate\Config\Repository;
  13. use Illuminate\Database\Capsule\Manager;
  14. use Illuminate\Database\Schema\Blueprint;
  15. use Illuminate\Foundation\Application;
  16. use Illuminate\Http\JsonResponse;
  17. use Illuminate\Http\Request;
  18. use Illuminate\Support\Facades\DB;
  19. use Illuminate\Support\Facades\Facade;
  20. use Illuminate\Translation\ArrayLoader;
  21. use Illuminate\Translation\Translator;
  22. use Illuminate\Validation\Factory;
  23. use PHPUnit\Framework\TestCase;
  24. class PaymentChannelOptionsTest extends TestCase
  25. {
  26. private Application $app;
  27. protected function setUp(): void
  28. {
  29. Facade::clearResolvedInstances();
  30. $this->app = new Application(dirname(__DIR__, 2));
  31. $this->app->instance('config', new Repository(['app' => ['locale' => 'zh']]));
  32. Facade::setFacadeApplication($this->app);
  33. $db = new Manager($this->app);
  34. $db->addConnection(['driver' => 'sqlite', 'database' => ':memory:', 'prefix' => 'bot_']);
  35. $db->setAsGlobal();
  36. $db->bootEloquent();
  37. $this->app->instance('db', $db->getDatabaseManager());
  38. $this->app->bind('db.schema', fn () => $db->schema());
  39. $translator = new Translator(new ArrayLoader(), 'zh');
  40. $this->app->instance('translator', $translator);
  41. $this->app->instance('validator', new Factory($translator, $this->app));
  42. $this->app->instance(\Illuminate\Contracts\Routing\ResponseFactory::class, new class {
  43. public function json($data, $status = 200, $headers = [], $options = 0) {
  44. return new JsonResponse($data, $status, $headers, $options);
  45. }
  46. });
  47. Request::macro('validate', function (array $rules) {
  48. return app('validator')->make($this->all(), $rules)->validate();
  49. });
  50. $db->schema()->create('recharge_channel', function (Blueprint $t) {
  51. $t->id(); $t->integer('from'); $t->integer('data_type'); $t->string('key');
  52. $t->string('name'); $t->string('type'); $t->decimal('rate', 8, 4);
  53. $t->decimal('min')->nullable(); $t->decimal('max')->nullable(); $t->string('fixed')->nullable();
  54. $t->integer('status'); $t->integer('sort'); $t->timestamps();
  55. });
  56. $db->schema()->create('recharge_channel_group', function (Blueprint $t) {
  57. $t->id(); $t->string('name'); $t->text('recharge_type')->nullable();
  58. $t->text('withdraw_type')->nullable(); $t->text('activity_type')->nullable(); $t->timestamps();
  59. });
  60. $fixture = require dirname(__DIR__) . '/fixtures/payment_provider_channels.php';
  61. DB::table('recharge_channel')->insert($fixture['channels']);
  62. DB::table('recharge_channel_group')->insert($fixture['groups']);
  63. (require dirname(__DIR__, 2) . '/database/migrations/2026_09_08_160000_add_payment_provider_status_and_channel_soft_deletes.php')->up();
  64. (require dirname(__DIR__, 2) . '/database/migrations/2026_09_08_170000_add_soft_deletes_to_recharge_channel_groups.php')->up();
  65. (require dirname(__DIR__, 2) . '/database/migrations/2026_10_28_150000_add_recharge_channel_logo.php')->up();
  66. (require dirname(__DIR__, 2) . '/database/migrations/2026_10_28_160000_create_recharge_method_logos.php')->up();
  67. $db->schema()->create('operation_audits', function (Blueprint $t) {
  68. $t->id(); $t->string('resource_type'); $t->unsignedBigInteger('resource_id')->nullable();
  69. $t->string('action'); $t->json('changes'); $t->unsignedBigInteger('operator_id')->nullable();
  70. $t->string('operator_name'); $t->timestamp('created_at')->useCurrent();
  71. });
  72. }
  73. protected function tearDown(): void
  74. {
  75. DB::disconnect();
  76. Facade::clearResolvedInstances();
  77. parent::tearDown();
  78. }
  79. private function request(string $path, array $params): void
  80. {
  81. $this->app->instance('request', Request::create($path, 'GET', $params));
  82. }
  83. private function channelList(array $params): array
  84. {
  85. $this->request('/admin/rechargeChannel/list', $params);
  86. $response = (new RechargeChannel())->list()->getData(true);
  87. $this->assertSame(0, $response['code']);
  88. return $response['data'];
  89. }
  90. public function test_sanjin_fixed_amounts_accept_list_roundtrip_without_any_minimum_or_maximum(): void
  91. {
  92. $params = ['id' => 10, 'data_type' => 1, 'payment_company' => 'sanjin', 'type' => 'zfbge', 'rate' => '0.027'];
  93. $result = $this->saveChannel($params + ['fixed' => [945, '988.00000000', 990, 945], 'min' => 'not applicable', 'max' => ['unused']]);
  94. $this->assertSame(0, $result['code'], $result['msg']);
  95. $row = ChannelModel::find(10);
  96. $this->assertSame(['945', '988', '990'], $row->fixed);
  97. $this->assertNull($row->min); $this->assertNull($row->max);
  98. $result = $this->saveChannel($params + ['fixed' => $row->fixed]);
  99. $this->assertSame(0, $result['code'], $result['msg']);
  100. $this->assertSame(0, $this->saveChannel($params + ['fixed' => '100, 200.50'])['code']);
  101. $this->assertSame(['100', '200.50'], ChannelModel::find(10)->fixed);
  102. $this->assertSame(0, $this->saveChannel($params)['code']);
  103. $this->assertSame(['100', '200.50'], ChannelModel::find(10)->fixed);
  104. $created = $this->saveChannel($this->newChannel(['payment_company' => 'sanjin', 'type' => 'zfbge', 'key' => 'fixed-test', 'fixed' => ['300', '500']]));
  105. $this->assertSame(0, $created['code'], $created['msg']);
  106. $new = ChannelModel::where('key', 'fixed-test')->first();
  107. $this->assertNull($new->min); $this->assertNull($new->max);
  108. $this->assertSame(['300', '500'], $new->fixed);
  109. }
  110. public function test_fixed_amount_validation_and_other_channel_range_validation_remain_independent(): void
  111. {
  112. $params = ['id' => 10, 'data_type' => 1, 'payment_company' => 'sanjin', 'type' => 'zfbge', 'rate' => '0.027'];
  113. $before = DB::table('recharge_channel')->where('id', 10)->first();
  114. foreach ([null, [], '', [0], [-1], ['1.234'], [['invalid']], ['key' => 100], 'abc'] as $fixed) {
  115. $this->assertSame(-3, $this->saveChannel($params + ['fixed' => $fixed])['code']);
  116. $this->assertEquals($before, DB::table('recharge_channel')->where('id', 10)->first());
  117. }
  118. $badRange = $this->saveChannel(['id' => 2, 'data_type' => 1, 'payment_company' => 'sanjin', 'type' => 'wxsm', 'rate' => '0.01', 'min' => 100, 'max' => 50]);
  119. $this->assertSame(-3, $badRange['code']);
  120. try {
  121. (new RechargeChannelConfigurationService())->save($params + ['fixed' => [], 'min' => 1, 'max' => 2]);
  122. $this->fail('Invalid direct-service fixed amounts accepted');
  123. } catch (\Illuminate\Validation\ValidationException $e) { $this->assertArrayHasKey('fixed', $e->errors()); }
  124. }
  125. public function test_logo_options_include_every_payment_method_even_without_enabled_or_existing_channels(): void
  126. {
  127. $this->request('/admin/rechargeChannel/saveLogo', []);
  128. $service = new \App\Services\Payment\RechargeChannelLogoService();
  129. DB::table('recharge_channel')->where('data_type', 1)->update(['status' => 0]);
  130. DB::table('payment_providers')->update(['status' => 0]);
  131. $options = $service->options();
  132. $this->assertSame(13, $options['total']);
  133. $rows = array_column($options['data'], null, 'channel_type');
  134. foreach (['wxsm','ylsm','szrmb','zfbsm','zfbge','zfbzk','sdjt','JDpay','NOpay12','NOpay13','ZIMUpay','usdt','rgcz'] as $type) {
  135. $this->assertArrayHasKey($type, $rows);
  136. }
  137. $this->assertSame('三斤支付 / 微信扫码', $rows['wxsm']['channel_name']);
  138. DB::table('recharge_channel')->delete(); DB::table('recharge_channel_group')->delete();
  139. $this->assertSame(13, $service->options()['total']);
  140. $result = $service->save(['channel_type' => 'wxsm', 'logo' => 'https://cdn.example.test/wx.png']);
  141. $this->assertSame('https://cdn.example.test/wx.png', $result['logo']);
  142. $this->assertSame(0, DB::table('recharge_channel')->count());
  143. $this->assertSame('https://cdn.example.test/wx.png', array_column($service->options()['data'], null, 'channel_type')['wxsm']['logo']);
  144. $this->assertSame('', $service->save(['channel_type' => 'wxsm', 'logo' => null])['logo']);
  145. $this->request('/admin/rechargeChannel/logoOptions', []);
  146. $this->assertSame(13, (new RechargeChannel())->logoOptions($service)->getData(true)['data']['total']);
  147. $router = new \Illuminate\Routing\Router(new \Illuminate\Events\Dispatcher($this->app), $this->app);
  148. $this->app->instance('router', $router);
  149. $router->group(['prefix' => 'admin'], function () { require dirname(__DIR__, 2) . '/routes/admin.php'; });
  150. foreach (['logoOptions' => ['GET', 'admin/rechargeChannel/list'], 'saveLogo' => ['POST', 'admin/rechargeChannel/update']] as $path => [$method, $permission]) {
  151. $route = $router->getRoutes()->match(Request::create('/admin/rechargeChannel/' . $path, $method));
  152. $this->assertSame($permission, $route->defaults['permission_uri']);
  153. $this->assertContains('admin.jwt', $route->middleware()); $this->assertContains('check.button.uri', $route->middleware());
  154. }
  155. try { $service->save(['channel_type' => 'DF001', 'logo' => '/a.png']); $this->fail('Withdrawal-only method accepted'); }
  156. catch (\Illuminate\Validation\ValidationException $e) { $this->assertArrayHasKey('channel_type', $e->errors()); }
  157. }
  158. public function test_logo_preconfiguration_is_inherited_by_later_channels_and_migration_retains_old_uploads(): void
  159. {
  160. $this->request('/admin/rechargeChannel/saveLogo', []);
  161. $migration = require dirname(__DIR__, 2) . '/database/migrations/2026_10_28_160000_create_recharge_method_logos.php';
  162. $migration->down();
  163. DB::table('recharge_channel')->where('id', 2)->update(['logo' => '/storage/wx.png']);
  164. $migration->up();
  165. $this->assertSame('/storage/wx.png', DB::table('recharge_method_logos')->where('channel_type', 'wxsm')->value('logo'));
  166. DB::table('recharge_channel')->where('type', 'JDpay')->where('data_type', 1)->delete();
  167. $service = new \App\Services\Payment\RechargeChannelLogoService();
  168. $service->save(['channel_type' => 'JDpay', 'logo' => 'https://cdn.example.test/jd.png']);
  169. $body = $this->saveChannel($this->newChannel(['payment_company' => 'jd', 'type' => 'JDpay']));
  170. $this->assertSame(0, $body['code'], $body['msg']);
  171. $this->assertSame('https://cdn.example.test/jd.png', \App\Models\RechargeChannel::where('data_type', 1)->where('type', 'JDpay')->first()->logo);
  172. }
  173. public function test_deposit_logos_upload_save_share_by_method_and_can_be_cleared(): void
  174. {
  175. $this->app['config']->set('app.url', 'https://admin.example.test');
  176. $before = DB::table('recharge_channel')->where('id', 24)->first();
  177. $this->assertSame(0, $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'jd', 'type' => 'JDpay', 'rate' => '0.01', 'logo' => '/storage/images/jd.png'])['code']);
  178. $row = \App\Models\RechargeChannel::find(24);
  179. $this->assertSame('https://admin.example.test/storage/images/jd.png', $row->logo);
  180. $this->assertSame((string)$before->type, $row->type);
  181. $this->assertSame(0, $this->saveChannel($this->newChannel(['data_type' => 1, 'payment_company' => 'jd', 'type' => 'JDpay', 'rate' => '0.02']))['code']);
  182. $peers = \App\Models\RechargeChannel::where('data_type', 1)->where('type', 'JDpay')->get();
  183. $this->assertCount(2, $peers);
  184. foreach ($peers as $peer) $this->assertSame($row->logo, $peer->logo);
  185. $this->assertSame(0, $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'jd', 'type' => 'JDpay', 'rate' => '0.01', 'logo' => 'https://cdn.example.test/jd.webp'])['code']);
  186. foreach (\App\Models\RechargeChannel::where('data_type', 1)->where('type', 'JDpay')->get() as $peer) $this->assertSame('https://cdn.example.test/jd.webp', $peer->logo);
  187. $this->assertSame(0, $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'jd', 'type' => 'JDpay', 'rate' => '0.01', 'logo' => null])['code']);
  188. foreach (\App\Models\RechargeChannel::where('data_type', 1)->where('type', 'JDpay')->get() as $peer) $this->assertSame('', $peer->logo);
  189. foreach (['javascript:alert(1)', '//evil.test/a.png', ['bad']] as $logo) {
  190. $this->assertSame(-3, $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'jd', 'type' => 'JDpay', 'rate' => '0.01', 'logo' => $logo])['code']);
  191. }
  192. }
  193. public function test_company_options_use_all_rows_not_first_page(): void
  194. {
  195. $page1 = $this->channelList(['data_type' => '1']);
  196. $this->assertSame(19, $page1['total']);
  197. $this->assertCount(15, $page1['data']);
  198. $this->assertNotContains('jd', array_column($page1['data'], 'payment_company'));
  199. $page2 = $this->channelList(['data_type' => '1', 'page' => 2]);
  200. $this->assertSame(['zimu', 'no', 'no', 'jd'], array_column($page2['data'], 'payment_company'));
  201. $this->request('/admin/paymentConfig/options', ['kind' => 'deposit']);
  202. $data = (new PaymentConfiguration(new PaymentChannelLinkService()))->options()->getData(true);
  203. $this->assertSame(0, $data['code']);
  204. $this->assertSame([false, false, false, false], array_column($data['data']['payment_companies'], 'disabled'));
  205. }
  206. public function test_channel_list_displays_provider_separately_from_channel_name(): void
  207. {
  208. $data = $this->channelList(['data_type' => '1', 'payment_company' => 'jd']);
  209. $this->assertSame(1, $data['total']);
  210. $this->assertSame('JD钱包', $data['data'][0]['name']);
  211. $this->assertSame('JD支付', $data['data'][0]['payment_company_label']);
  212. $this->assertSame(1, $data['data'][0]['from']);
  213. $this->assertSame(24, $data['data'][0]['id']);
  214. $withdraw = $this->channelList(['data_type' => '2', 'payment_company' => 'jd']);
  215. $this->assertSame(25, $withdraw['data'][0]['id']);
  216. $this->assertSame(0, $this->channelList(['data_type' => '2', 'payment_company' => 'sanjin'])['total']);
  217. }
  218. public function test_missing_group_returns_reason_without_enabling_or_rewriting_config(): void
  219. {
  220. DB::table('recharge_channel_group')->update(['recharge_type' => 'wxsm,zfbsm']);
  221. $this->request('/admin/paymentConfig/options', ['kind' => 'deposit']);
  222. $data = (new PaymentConfiguration(new PaymentChannelLinkService()))->options()->getData(true)['data'];
  223. $this->assertSame([false, true, true, true], array_column($data['payment_companies'], 'disabled'));
  224. $this->assertSame(['', 'group_missing', 'group_missing', 'group_missing'], array_column($data['payment_companies'], 'disabled_reason_code'));
  225. $this->assertSame('wxsm,zfbsm', DB::table('recharge_channel_group')->value('recharge_type'));
  226. $this->assertSame(0, DB::table('recharge_channel')->where('id', 31)->value('status'));
  227. }
  228. public function test_group_editor_options_include_new_types_even_before_any_group_uses_them(): void
  229. {
  230. DB::table('recharge_channel_group')->update(['recharge_type' => 'wxsm', 'withdraw_type' => 'DF001']);
  231. $this->request('/admin/rechargeChannel/getChannel', ['data_type' => 1]);
  232. $response = (new RechargeChannel())->getChannel()->getData(true);
  233. $this->assertSame(0, $response['code']);
  234. $names = array_column($response['data']['data'], 'name', 'type');
  235. $this->assertSame('JD钱包', $names['JDpay']);
  236. $this->assertSame('NO快捷充值-扫码支付', $names['NOpay12']);
  237. $this->assertSame('NO快捷充值-余额支付', $names['NOpay13']);
  238. $this->assertSame('808充值', $names['ZIMUpay']);
  239. $this->assertSame(13, $response['data']['total']);
  240. $this->request('/admin/rechargeChannel/getChannel', ['data_type' => 2]);
  241. $names = array_column((new RechargeChannel())->getChannel()->getData(true)['data']['data'], 'name', 'type');
  242. $this->assertSame('JD钱包', $names['JDpay']);
  243. $this->assertSame('NO快捷提现', $names['NOwithdraw']);
  244. $this->assertSame('808账户提现', $names['ZIMUwithdraw']);
  245. $this->assertArrayNotHasKey('ZIMUcash', $names);
  246. $this->assertSame('wxsm', DB::table('recharge_channel_group')->value('recharge_type'));
  247. }
  248. private function formOptions(int $dataType = 1, ?int $id = null): array
  249. {
  250. $this->request('/admin/rechargeChannel/options', ['data_type' => $dataType] + ($id ? ['id' => $id] : []));
  251. $response = (new RechargeChannel())->options(new RechargeChannelConfigurationService())->getData(true);
  252. $this->assertSame(0, $response['code']);
  253. return $response['data'];
  254. }
  255. private function saveChannel(array $params): array
  256. {
  257. $this->app->instance('request', Request::create('/admin/rechargeChannel/update', 'POST', $params));
  258. return (new RechargeChannel())->update(new RechargeChannelConfigurationService())->getData(true);
  259. }
  260. private function newChannel(array $overrides = []): array
  261. {
  262. return $overrides + ['data_type' => 1, 'payment_company' => 'no', 'type' => 'NOpay12',
  263. 'rate' => '0.0300', 'name' => '测试通道', 'key' => 'test-key', 'min' => 1, 'max' => 100];
  264. }
  265. public function test_creation_catalog_works_without_any_database_channels_or_groups(): void
  266. {
  267. DB::table('recharge_channel')->delete();
  268. DB::table('recharge_channel_group')->delete();
  269. $data = $this->formOptions();
  270. $this->assertSame(['sanjin', 'jd', 'no', 'zimu'], array_column($data['payment_companies'], 'value'));
  271. $this->assertTrue($data['identity_editable']);
  272. $this->assertSame('', $data['identity_edit_reason']);
  273. $this->assertContains('NOpay12', array_column($data['types'], 'value'));
  274. $this->assertSame(['qianbao', 'jd', 'no', 'zimu'], array_column($this->formOptions(2)['payment_companies'], 'value'));
  275. $this->assertSame([], $this->formOptions(3)['payment_companies']);
  276. }
  277. public function test_create_selected_company_then_switch_company_and_type_on_same_record(): void
  278. {
  279. $result = $this->saveChannel($this->newChannel());
  280. $this->assertSame(0, $result['code']);
  281. $this->assertSame([], $result['data']);
  282. $row = DB::table('recharge_channel')->where('key', 'test-key')->first();
  283. $this->assertSame(1, $row->from);
  284. $this->assertSame(1, $row->status);
  285. $this->assertSame(0, $row->sort);
  286. $result = $this->saveChannel(['id' => $row->id, 'data_type' => 1,
  287. 'payment_company' => 'jd', 'type' => 'JDpay', 'rate' => '0.02']);
  288. $this->assertSame(0, $result['code']);
  289. $data = $this->channelList(['data_type' => '1', 'key' => 'test-key'])['data'][0];
  290. $this->assertSame($row->id, $data['id']);
  291. $this->assertSame('jd', $data['payment_company']);
  292. $this->assertSame('JD支付 / 测试通道', $data['display_name']);
  293. }
  294. public function test_invalid_company_type_or_source_is_rejected_without_writing(): void
  295. {
  296. $before = DB::table('recharge_channel')->count();
  297. foreach ([
  298. ['payment_company' => 'jd', 'type' => 'NOpay12'],
  299. ['payment_company' => 'no', 'type' => '12'],
  300. ['payment_company' => 'no', 'type' => 'usdt'],
  301. ['payment_company' => 'no', 'from' => 2],
  302. ['payment_company' => 'sanjin', 'type' => 'DF001', 'data_type' => 2],
  303. ] as $override) {
  304. $this->assertSame(-3, $this->saveChannel($this->newChannel($override))['code']);
  305. }
  306. $this->assertSame($before, DB::table('recharge_channel')->count());
  307. }
  308. public function test_native_and_activity_channels_do_not_require_or_fabricate_company(): void
  309. {
  310. foreach ([[1, 'usdt', 2], [1, 'rgcz', 3], [2, 'rgtx', 3], [3, 'recharge', 1]] as [$direction, $type, $from]) {
  311. $result = $this->saveChannel($this->newChannel(['payment_company' => null, 'data_type' => $direction,
  312. 'type' => $type, 'key' => 'local-' . $type]));
  313. $this->assertSame(0, $result['code']);
  314. $row = $this->channelList(['key' => 'local-' . $type])['data'][0];
  315. $this->assertSame($from, $row['from']);
  316. $this->assertNull($row['payment_company']);
  317. $this->assertSame('测试通道', $row['display_name']);
  318. }
  319. }
  320. public function test_existing_valid_clients_can_omit_derived_company_and_from(): void
  321. {
  322. $params = $this->newChannel();
  323. unset($params['payment_company']);
  324. $this->assertSame(0, $this->saveChannel($params)['code']);
  325. $row = $this->channelList(['key' => 'test-key'])['data'][0];
  326. $this->assertSame('no', $row['payment_company']);
  327. $this->assertSame(1, $row['from']);
  328. }
  329. public function test_linked_channel_locks_identity_but_keeps_regular_edit_available(): void
  330. {
  331. DB::connection()->getSchemaBuilder()->create('payment_gateways', function (Blueprint $t) {
  332. $t->id(); $t->unsignedBigInteger('recharge_channel_id'); $t->softDeletes();
  333. });
  334. DB::table('payment_gateways')->insert(['recharge_channel_id' => 24]);
  335. $options = $this->formOptions(1, 24);
  336. $this->assertFalse($options['identity_editable']);
  337. $this->assertNotSame('', $options['identity_edit_reason']);
  338. $result = $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'no',
  339. 'type' => 'NOpay12', 'rate' => '0.01']);
  340. $this->assertSame(-3, $result['code']);
  341. $this->assertSame('JDpay', DB::table('recharge_channel')->where('id', 24)->value('type'));
  342. $result = $this->saveChannel(['id' => 24, 'data_type' => 1, 'payment_company' => 'jd',
  343. 'type' => 'JDpay', 'rate' => '0.01', 'name' => 'JD新名称']);
  344. $this->assertSame(0, $result['code']);
  345. DB::table('payment_gateways')->update(['deleted_at' => now()]);
  346. $this->assertTrue($this->formOptions(1, 24)['identity_editable']);
  347. $this->assertSame(0, $this->saveChannel(['id' => 24, 'data_type' => 1,
  348. 'payment_company' => 'no', 'type' => 'NOpay12', 'rate' => '0.01'])['code']);
  349. }
  350. public function test_switching_company_does_not_rewrite_group_permissions(): void
  351. {
  352. $groups = DB::table('recharge_channel_group')->orderBy('id')->get()->toJson();
  353. $this->assertSame(0, $this->saveChannel(['id' => 24, 'data_type' => 1,
  354. 'payment_company' => 'no', 'type' => 'NOpay12', 'rate' => '0.01'])['code']);
  355. $this->assertSame($groups, DB::table('recharge_channel_group')->orderBy('id')->get()->toJson());
  356. $this->assertSame(-3, $this->saveChannel(['id' => 24, 'data_type' => 2,
  357. 'payment_company' => 'no', 'type' => 'NOwithdraw', 'rate' => '0.01'])['code']);
  358. }
  359. public function test_group_option_names_include_company_without_changing_values(): void
  360. {
  361. $this->request('/admin/rechargeChannel/getChannel', ['data_type' => 1]);
  362. $rows = array_column((new RechargeChannel())->getChannel()->getData(true)['data']['data'], null, 'type');
  363. $this->assertSame('JD钱包', $rows['JDpay']['name']);
  364. $this->assertSame('jd', $rows['JDpay']['payment_company']);
  365. $this->assertSame('JD支付 / JD钱包', $rows['JDpay']['display_name']);
  366. $this->assertSame('USDT充值', $rows['usdt']['display_name']);
  367. }
  368. public function test_merchant_save_rechecks_channel_identity_inside_transaction(): void
  369. {
  370. DB::table('recharge_channel')->where('id', 26)->update(['type' => 'JDpay']);
  371. $this->request('/admin/paymentConfig/gateways/save', []);
  372. $controller = new PaymentConfiguration(new PaymentChannelLinkService());
  373. $method = new \ReflectionMethod($controller, 'saveModel');
  374. $method->setAccessible(true);
  375. $this->expectException(\InvalidArgumentException::class);
  376. $this->expectExceptionMessage('支付公司与所选通道不匹配');
  377. $method->invoke($controller, PaymentGateway::class, ['kind' => 'deposit', 'recharge_channel_id' => 26,
  378. 'recharge_channel_group_ids' => [1], 'payment_company' => 'no', 'payment_method' => 'NOpay12'], 'payment_gateway');
  379. }
  380. private function setCompanyStatus(string $code, int $status): array
  381. {
  382. $this->app->instance('request', Request::create('/admin/paymentCompany/status', 'POST', ['payment_company' => $code, 'status' => $status]));
  383. return (new PaymentCompany())->status(new PaymentProviderService())->getData(true);
  384. }
  385. private function deleteChannel(int $id): array
  386. {
  387. $this->app->instance('request', Request::create('/admin/rechargeChannel/delete', 'POST', ['id' => $id]));
  388. return (new RechargeChannel())->delete(new RechargeChannelConfigurationService())->getData(true);
  389. }
  390. public function test_company_management_lists_registered_providers_and_filters_status(): void
  391. {
  392. $this->request('/admin/paymentCompany/list', []);
  393. $result = (new PaymentCompany())->list(new PaymentProviderService())->getData(true);
  394. $this->assertSame(0, $result['code']);
  395. $this->assertSame(5, $result['data']['total']);
  396. $rows = array_column($result['data']['data'], null, 'payment_company');
  397. $this->assertSame('SHA256', $rows['no']['signature_algorithm']);
  398. $this->assertSame([1, 2], $rows['no']['data_types']);
  399. $this->assertSame(3, $rows['no']['channel_count']);
  400. $this->assertSame(0, $this->setCompanyStatus('no', 0)['code']);
  401. $this->assertSame(0, $this->setCompanyStatus('no', 0)['code']);
  402. $this->assertSame(1, DB::table('operation_audits')->where('resource_type', 'payment_company')->count());
  403. $this->request('/admin/paymentCompany/list', ['status' => 0]);
  404. $this->assertSame(1, (new PaymentCompany())->list(new PaymentProviderService())->getData(true)['data']['total']);
  405. $this->assertSame(-3, $this->setCompanyStatus('unknown', 0)['code']);
  406. $this->assertSame(-3, $this->setCompanyStatus('no', 9)['code']);
  407. }
  408. public function test_company_switch_disables_options_and_runtime_without_rewriting_channels(): void
  409. {
  410. $groups = DB::table('recharge_channel_group')->get()->toJson();
  411. $this->assertSame(0, $this->setCompanyStatus('no', 0)['code']);
  412. $this->assertFalse(ChannelModel::checkRechargeChannel('NOpay12', 1));
  413. $this->assertFalse(ChannelModel::checkWithdrawChannel('NOwithdraw', 1));
  414. $this->assertNotFalse(ChannelModel::checkRechargeChannel('JDpay', 1));
  415. $this->assertNotFalse(ChannelModel::checkRechargeChannel('usdt', 1));
  416. $this->assertArrayNotHasKey('NOpay12', ChannelModel::product(1));
  417. $this->assertSame(1, DB::table('recharge_channel')->where('id', 26)->value('status'));
  418. $this->assertSame($groups, DB::table('recharge_channel_group')->get()->toJson());
  419. $this->request('/admin/paymentConfig/options', ['kind' => 'deposit']);
  420. $options = (new PaymentConfiguration(new PaymentChannelLinkService()))->options()->getData(true)['data'];
  421. $companies = array_column($options['payment_companies'], null, 'value');
  422. $this->assertSame('provider_disabled', $companies['no']['disabled_reason_code']);
  423. $this->assertFalse(array_column($options['recharge_channels'], null, 'id')[26]['selectable']);
  424. $form = $this->formOptions();
  425. $this->assertTrue(array_column($form['payment_companies'], null, 'value')['no']['disabled']);
  426. $row = $this->channelList(['data_type' => '1', 'type' => 'NOpay12'])['data'][0];
  427. $this->assertSame(1, $row['status']);
  428. $this->assertSame(0, $row['company_status']);
  429. $this->assertSame(0, $row['effective_status']);
  430. $this->assertSame(-3, $this->saveChannel($this->newChannel())['code']);
  431. $this->assertSame(0, $this->setCompanyStatus('no', 1)['code']);
  432. $this->assertNotFalse(ChannelModel::checkRechargeChannel('NOpay12', 1));
  433. }
  434. public function test_reenable_company_does_not_enable_individually_disabled_channels(): void
  435. {
  436. $this->setCompanyStatus('zimu', 0);
  437. $this->setCompanyStatus('zimu', 1);
  438. $this->assertSame(0, DB::table('recharge_channel')->where('id', 31)->value('status'));
  439. $this->assertFalse(ChannelModel::checkWithdrawChannel('ZIMUcash', 1));
  440. $this->assertNotFalse(ChannelModel::checkWithdrawChannel('ZIMUwithdraw', 1));
  441. }
  442. public function test_disabled_company_blocks_new_external_requests_before_any_wallet_or_network_work(): void
  443. {
  444. $this->setCompanyStatus('no', 0);
  445. $this->assertSame('支付公司已禁用', PaymentOrderService::createPay('test-user', 100, 'NOpay12')['text']);
  446. $this->assertSame('支付公司已禁用', PaymentOrderService::autoCreatePayout('test-user', 100, 'NOwithdraw', '', '', '')['text']);
  447. $this->assertFalse(PaymentProviderService::requestEnabled('nopay12', 1));
  448. $this->assertTrue(PaymentProviderService::requestEnabled('JDpay', 1));
  449. }
  450. public function test_delete_last_deposit_type_soft_deletes_and_cleans_only_its_group_membership(): void
  451. {
  452. $beforeWithdraw = DB::table('recharge_channel_group')->where('id', 1)->value('withdraw_type');
  453. $this->assertSame(0, $this->deleteChannel(24)['code']);
  454. $this->assertNull(ChannelModel::query()->find(24));
  455. $deleted = ChannelModel::withTrashed()->findOrFail(24);
  456. $this->assertTrue($deleted->trashed());
  457. $this->assertSame(0, (int)$deleted->status);
  458. $this->assertSame('JD钱包', $deleted->name);
  459. $types = explode(',', DB::table('recharge_channel_group')->where('id', 1)->value('recharge_type'));
  460. $this->assertNotContains('JDpay', $types);
  461. $this->assertContains('NOpay12', $types);
  462. $this->assertSame($beforeWithdraw, DB::table('recharge_channel_group')->where('id', 1)->value('withdraw_type'));
  463. $this->assertNotFalse(ChannelModel::checkWithdrawChannel('JDpay', 1));
  464. $this->assertFalse(ChannelModel::checkRechargeChannel('JDpay', 1));
  465. $this->assertSame(0, $this->deleteChannel(24)['code']);
  466. $this->assertSame(1, DB::table('operation_audits')->where('resource_type', 'recharge_channel')->count());
  467. $this->setCompanyStatus('jd', 0); $this->setCompanyStatus('jd', 1);
  468. $this->assertNull(ChannelModel::query()->find(24));
  469. }
  470. public function test_delete_one_of_several_same_type_channels_preserves_groups_until_last_removed(): void
  471. {
  472. $this->assertSame(0, $this->deleteChannel(6)['code']);
  473. $this->assertStringContainsString('zfbsm', DB::table('recharge_channel_group')->where('id', 1)->value('recharge_type'));
  474. $this->assertSame(3, ChannelModel::query()->where('data_type', 1)->where('type', 'zfbsm')->count());
  475. foreach ([7, 8, 9] as $id) $this->assertSame(0, $this->deleteChannel($id)['code']);
  476. $this->assertStringNotContainsString('zfbsm', DB::table('recharge_channel_group')->where('id', 1)->value('recharge_type'));
  477. }
  478. public function test_delete_is_blocked_by_payment_config_reference_and_does_not_touch_activity(): void
  479. {
  480. DB::connection()->getSchemaBuilder()->create('payment_gateways', function (Blueprint $t) {
  481. $t->id(); $t->unsignedBigInteger('recharge_channel_id'); $t->softDeletes();
  482. });
  483. DB::table('payment_gateways')->insert(['recharge_channel_id' => 24]);
  484. $this->assertSame(-3, $this->deleteChannel(24)['code']);
  485. $this->assertNotNull(ChannelModel::query()->find(24));
  486. $this->assertSame(-3, $this->deleteChannel(21)['code']);
  487. $this->assertNotNull(ChannelModel::query()->find(21));
  488. DB::table('payment_gateways')->update(['deleted_at' => now()]);
  489. $this->assertSame(0, $this->deleteChannel(24)['code']);
  490. }
  491. public function test_migration_retry_keeps_disabled_company_and_deleted_channel(): void
  492. {
  493. $this->setCompanyStatus('no', 0);
  494. $this->deleteChannel(24);
  495. (require dirname(__DIR__, 2) . '/database/migrations/2026_09_08_160000_add_payment_provider_status_and_channel_soft_deletes.php')->up();
  496. $this->assertSame(0, PaymentProviderService::statuses()['no']);
  497. $this->assertTrue(ChannelModel::withTrashed()->findOrFail(24)->trashed());
  498. $this->assertSame(5, DB::table('payment_providers')->count());
  499. }
  500. private function paymentOrderFixture(int $type, string $channel, int $status): \App\Models\PaymentOrder
  501. {
  502. DB::connection()->getSchemaBuilder()->create('payment_orders', function (Blueprint $t) {
  503. $t->id(); $t->integer('type'); $t->string('channel'); $t->integer('status');
  504. $t->string('order_no'); $t->string('member_id'); $t->decimal('amount', 18, 4);
  505. $t->string('state')->nullable(); $t->text('callback_data')->nullable(); $t->timestamps();
  506. });
  507. $this->app->instance('log', new class {
  508. public function channel($channel) { return $this; }
  509. public function error($message, array $context = []) {}
  510. });
  511. return \App\Models\PaymentOrder::query()->create(['type' => $type, 'channel' => $channel,
  512. 'status' => $status, 'order_no' => 'test-order', 'member_id' => 'test-user', 'amount' => 10]);
  513. }
  514. public function test_pending_payout_cannot_be_sent_after_company_disabled(): void
  515. {
  516. $order = $this->paymentOrderFixture(2, 'NOwithdraw', PaymentOrderService::STATUS_STAY);
  517. $this->setCompanyStatus('no', 0);
  518. $result = PaymentOrderService::createPayout($order->id);
  519. $this->assertSame(-3, $result['code']);
  520. $this->assertSame('支付公司已禁用', $result['msg']);
  521. $this->assertSame(PaymentOrderService::STATUS_STAY, $order->fresh()->status);
  522. }
  523. public function test_pending_payout_cannot_be_sent_after_last_channel_deleted(): void
  524. {
  525. $order = $this->paymentOrderFixture(2, 'JDpay', PaymentOrderService::STATUS_STAY);
  526. $this->assertSame(0, $this->deleteChannel(25)['code']);
  527. $result = PaymentOrderService::createPayout($order->id);
  528. $this->assertSame(-3, $result['code']);
  529. $this->assertSame('提现通道已停用或删除', $result['msg']);
  530. $this->assertSame(PaymentOrderService::STATUS_STAY, $order->fresh()->status);
  531. }
  532. public function test_existing_pay_callback_is_not_blocked_by_company_switch(): void
  533. {
  534. $order = $this->paymentOrderFixture(1, 'NOpay12', PaymentOrderService::STATUS_PROCESS);
  535. $this->setCompanyStatus('no', 0);
  536. $method = new \ReflectionMethod(PaymentOrderService::class, 'applyPayCallback');
  537. $method->setAccessible(true);
  538. $this->assertTrue($method->invoke(null, $order, '10', 'failed', 'success', 'failed', ['status' => 'failed']));
  539. $this->assertSame(PaymentOrderService::STATUS_FAIL, $order->fresh()->status);
  540. $this->assertNotNull($order->fresh()->callback_data);
  541. }
  542. public function test_company_disabled_updates_saved_gateway_effective_status(): void
  543. {
  544. $channel = ChannelModel::query()->findOrFail(26);
  545. $gateway = new PaymentGateway(['payment_company' => 'no', 'payment_method' => 'NOpay12',
  546. 'status' => 1, 'recharge_channel_group_ids' => [1]]);
  547. $gateway->setRelation('rechargeChannel', $channel);
  548. $this->setCompanyStatus('no', 0);
  549. $data = (new PaymentChannelLinkService())->formatOne($gateway);
  550. $this->assertSame(1, $data['config_status']);
  551. $this->assertSame(1, $data['channel_status']);
  552. $this->assertSame(0, $data['company_status']);
  553. $this->assertSame(0, $data['effective_status']);
  554. $this->expectException(\RuntimeException::class);
  555. $this->expectExceptionMessage('NO支付已禁用');
  556. (new PaymentChannelLinkService())->validate(26, [1], 1);
  557. }
  558. public function test_empty_group_types_can_be_saved_after_last_channel_removed(): void
  559. {
  560. $this->app->instance('request', Request::create('/admin/rechargeChannel/updateGroup', 'POST',
  561. ['id' => 1, 'name' => '全部充值', 'recharge_type' => [], 'withdraw_type' => []]));
  562. $this->assertSame(0, (new RechargeChannel())->updateGroup()->getData(true)['code']);
  563. $this->assertSame('', DB::table('recharge_channel_group')->where('id', 1)->value('recharge_type'));
  564. $this->assertSame('yuebao,old_user,recharge', DB::table('recharge_channel_group')->where('id', 1)->value('activity_type'));
  565. }
  566. private function saveGroup(array $params): array
  567. {
  568. $this->app->instance('request', Request::create('/admin/rechargeChannel/updateGroup', 'POST', $params));
  569. return (new RechargeChannel())->updateGroup()->getData(true);
  570. }
  571. private function groupPayload(int $id = 1): array
  572. {
  573. $group = DB::table('recharge_channel_group')->where('id', $id)->first();
  574. return ['id' => $id, 'name' => $group->name, 'recharge_type' => explode(',', $group->recharge_type),
  575. 'withdraw_type' => explode(',', $group->withdraw_type)];
  576. }
  577. public function test_legacy_group_can_be_saved_and_only_invalid_existing_types_are_cleaned(): void
  578. {
  579. $payload = $this->groupPayload();
  580. $result = $this->saveGroup($payload);
  581. $this->assertSame(0, $result['code']);
  582. $this->assertSame([], $result['data']);
  583. $this->assertStringContainsString('已清理', $result['msg']);
  584. $saved = $this->groupPayload();
  585. $this->assertSame(array_values(array_diff($payload['recharge_type'], ['1', '2', '3'])), $saved['recharge_type']);
  586. $this->assertSame(array_values(array_diff($payload['withdraw_type'], ['ylk', 'zfb', 'szrmb'])), $saved['withdraw_type']);
  587. $this->assertSame('yuebao,old_user,recharge', DB::table('recharge_channel_group')->where('id', 1)->value('activity_type'));
  588. $audit = DB::table('operation_audits')->where('resource_type', 'recharge_channel_group')->first();
  589. $this->assertNotNull($audit);
  590. $this->assertSame(['1', '2', '3'], json_decode($audit->changes, true)['after']['removed_types']['recharge_type']);
  591. }
  592. public function test_new_unknown_type_in_existing_group_is_rejected_atomically(): void
  593. {
  594. $payload = $this->groupPayload();
  595. $payload['recharge_type'][] = 'not_a_type';
  596. $before = DB::table('recharge_channel_group')->where('id', 1)->first();
  597. $result = $this->saveGroup($payload);
  598. $this->assertSame(-3, $result['code']);
  599. $this->assertStringContainsString('not_a_type', $result['msg']);
  600. $this->assertSame($before->recharge_type, DB::table('recharge_channel_group')->where('id', 1)->value('recharge_type'));
  601. $this->assertSame(0, DB::table('operation_audits')->count());
  602. }
  603. public function test_new_group_cannot_reuse_invalid_values_from_another_group(): void
  604. {
  605. $payload = $this->groupPayload();
  606. unset($payload['id']);
  607. $result = $this->saveGroup($payload);
  608. $this->assertSame(-3, $result['code']);
  609. $this->assertStringContainsString('1,2,3', $result['msg']);
  610. $this->assertSame(2, DB::table('recharge_channel_group')->count());
  611. }
  612. public function test_group_types_trim_deduplicate_and_keep_disabled_company_membership(): void
  613. {
  614. $this->setCompanyStatus('no', 0);
  615. $result = $this->saveGroup(['id' => 1, 'name' => '组合',
  616. 'recharge_type' => [' JDpay ', 'JDpay', ' NOpay12 '], 'withdraw_type' => [' DF001 ']]);
  617. $this->assertSame(0, $result['code']);
  618. $this->assertSame('JDpay,NOpay12', DB::table('recharge_channel_group')->where('id', 1)->value('recharge_type'));
  619. $this->assertSame('DF001', DB::table('recharge_channel_group')->where('id', 1)->value('withdraw_type'));
  620. }
  621. public function test_nested_option_objects_are_rejected_without_writing(): void
  622. {
  623. $result = $this->saveGroup(['id' => 1, 'name' => '组合',
  624. 'recharge_type' => [['type' => 'JDpay', 'name' => 'JD钱包']], 'withdraw_type' => ['DF001']]);
  625. $this->assertSame(-3, $result['code']);
  626. $this->assertStringContainsString('type', $result['msg']);
  627. $this->assertSame(0, DB::table('operation_audits')->count());
  628. }
  629. public function test_existing_deleted_type_is_removed_and_not_restored(): void
  630. {
  631. DB::table('recharge_channel')->where('id', 24)->update(['deleted_at' => now(), 'status' => 0]);
  632. $this->assertSame(0, $this->saveGroup($this->groupPayload())['code']);
  633. $saved = $this->groupPayload();
  634. $this->assertNotContains('JDpay', $saved['recharge_type']);
  635. $this->assertContains('JDpay', $saved['withdraw_type']);
  636. $this->assertTrue(ChannelModel::withTrashed()->findOrFail(24)->trashed());
  637. }
  638. private function deleteGroup(int $id): array
  639. {
  640. $this->app->instance('request', Request::create('/admin/rechargeChannel/deleteGroup', 'POST', ['id' => $id]));
  641. return (new RechargeChannel())->deleteGroup(new RechargeChannelConfigurationService())->getData(true);
  642. }
  643. public function test_unreferenced_group_can_be_soft_deleted_without_deleting_channels(): void
  644. {
  645. $count = ChannelModel::query()->count();
  646. $this->assertSame(0, $this->deleteGroup(2)['code']);
  647. $this->assertNull(\App\Models\RechargeChannelGroup::query()->find(2));
  648. $this->assertTrue(\App\Models\RechargeChannelGroup::withTrashed()->findOrFail(2)->trashed());
  649. $this->assertSame($count, ChannelModel::query()->count());
  650. $this->assertSame(0, $this->deleteGroup(2)['code']);
  651. $this->assertSame(1, DB::table('operation_audits')->where('action', 'delete')->count());
  652. $this->request('/admin/rechargeChannel/groupList', []);
  653. $this->assertSame(1, (new RechargeChannel())->groupList()->getData(true)['data']['total']);
  654. $this->assertSame(-3, $this->saveGroup(['id' => 2, 'name' => '已删除', 'recharge_type' => [], 'withdraw_type' => []])['code']);
  655. }
  656. public function test_default_group_and_member_assigned_group_cannot_be_deleted(): void
  657. {
  658. $this->assertSame(-3, $this->deleteGroup(1)['code']);
  659. $this->assertSame(-3, $this->deleteGroup(999)['code']);
  660. DB::connection()->getSchemaBuilder()->create('users', function (Blueprint $t) {
  661. $t->id(); $t->string('member_id'); $t->unsignedBigInteger('recharge_channel_group_id')->nullable(); $t->timestamps();
  662. });
  663. DB::table('users')->insert(['member_id' => 'test', 'recharge_channel_group_id' => 2]);
  664. $result = $this->deleteGroup(2);
  665. $this->assertSame(-3, $result['code']);
  666. $this->assertStringContainsString('会员', $result['msg']);
  667. $this->assertNotNull(\App\Models\RechargeChannelGroup::query()->find(2));
  668. $this->assertSame(0, DB::table('operation_audits')->count());
  669. }
  670. public function test_numeric_and_string_payment_config_group_references_block_delete(): void
  671. {
  672. DB::connection()->getSchemaBuilder()->create('payment_collection_channels', function (Blueprint $t) {
  673. $t->id(); $t->json('recharge_channel_group_ids'); $t->softDeletes();
  674. });
  675. foreach (['[2]', '["2"]', '["02"]'] as $json) {
  676. DB::table('payment_collection_channels')->delete();
  677. DB::table('payment_collection_channels')->insert(['recharge_channel_group_ids' => $json]);
  678. $result = $this->deleteGroup(2);
  679. $this->assertSame(-3, $result['code']);
  680. $this->assertStringContainsString('被支付配置引用', $result['msg']);
  681. $this->assertNotNull(\App\Models\RechargeChannelGroup::query()->find(2));
  682. }
  683. DB::table('payment_collection_channels')->update(['deleted_at' => now()]);
  684. $this->assertSame(0, $this->deleteGroup(2)['code']);
  685. }
  686. public function test_deleted_group_cannot_be_assigned_to_members_or_new_payment_config(): void
  687. {
  688. DB::connection()->getSchemaBuilder()->create('users', function (Blueprint $t) {
  689. $t->id(); $t->string('member_id'); $t->unsignedBigInteger('recharge_channel_group_id')->nullable(); $t->timestamps();
  690. });
  691. DB::table('users')->insert(['member_id' => 'test', 'recharge_channel_group_id' => 1]);
  692. $this->assertSame(0, $this->deleteGroup(2)['code']);
  693. $this->app->instance('request', Request::create('/admin/user/setRechargeChannelGroup', 'POST',
  694. ['member_id' => ['test'], 'recharge_channel_group_id' => 2]));
  695. $this->assertSame(-3, (new \App\Http\Controllers\admin\User())->setRechargeChannelGroup()->getData(true)['code']);
  696. $this->assertSame(1, DB::table('users')->where('member_id', 'test')->value('recharge_channel_group_id'));
  697. $this->expectException(\RuntimeException::class);
  698. $this->expectExceptionMessage('部分通道组合不存在');
  699. (new PaymentChannelLinkService())->validate(24, [2], 1, true);
  700. }
  701. }