doge 8 godzin temu
rodzic
commit
cfe2e7f2f2

+ 12 - 0
app/Http/Controllers/api/Wallet.php

@@ -39,6 +39,12 @@ class Wallet extends BaseController
     //获取三斤充值通道(微信、支付宝、扫码充值)
     public function getChannel()
     {
+        try {
+            $params = request()->validate(['currency_type' => ['nullable', 'string', 'in:crypto,fiat']],
+                ['currency_type.in' => '充值渠道分类仅支持crypto或fiat']);
+        } catch (ValidationException $e) {
+            return $this->error($e->validator->errors()->first(), [], HttpStatus::CUSTOM_ERROR);
+        }
         $member_id = request()->user->member_id;
         if (empty(request()->user->recharge_channel_group_id)) {
             $recharge_channel_group_id = User::where('member_id', $member_id)->value('recharge_channel_group_id');
@@ -61,6 +67,12 @@ class Wallet extends BaseController
                 return !ZimuPayService::isRechargeChannel($item['value'] ?? '');
             }));
         }
+        $currencyType = $params['currency_type'] ?? null;
+        if ($currencyType !== null && $currencyType !== '') {
+            $list = array_values(array_filter($list, static function ($item) use ($currencyType) {
+                return (($item['value'] ?? '') === 'usdt') === ($currencyType === 'crypto');
+            }));
+        }
         $list = \App\Services\RechargeBonusService::decorate($list, $this->lang, (int)request()->user->from === 1);
         return $this->success([
             'list' => $list,

+ 16 - 0
docs/前端接口/充值渠道-数字货币筛选-前端接入.md

@@ -0,0 +1,16 @@
+# 充值渠道:数字货币筛选
+
+原接口 `GET /api/wallet/channel` 增加可选参数 `currency_type`:
+
+| 参数值 | 返回范围 |
+| --- | --- |
+| 不传 | 全部充值方式 |
+| `crypto` | 数字货币,目前为USDT |
+| `fiat` | 非数字货币,包括微信、支付宝、银行卡、数字人民币及各支付钱包 |
+
+```http
+GET /api/wallet/channel?currency_type=crypto
+GET /api/wallet/channel?currency_type=fiat
+```
+
+返回仍读取 `data.list[]`,Logo、角标和赠送比例字段沿用现有方式。没有符合条件的渠道时返回空数组。

+ 29 - 0
tests/Integration/RechargeBonusTest.php

@@ -185,6 +185,35 @@ class RechargeBonusTest extends TestCase
         $this->assertSame('73.50', $this->balance());
     }
 
+    public function test_wallet_channel_currency_filter_preserves_membership_visibility_and_bonus_fields(): void
+    {
+        DB::table('recharge_channel')->insert(['data_type' => 1, 'type' => 'szrmb', 'name' => '数字人民币']);
+        DB::table('payment_providers')->insert(['id' => 2, 'code' => 'sanjin', 'status' => 1]);
+        DB::table('recharge_channel_group')->where('id', 1)->update(['recharge_type' => 'JDpay,rgcz,usdt,szrmb']);
+        $fetch = function (array $params): array {
+            $request = Request::create('/api/wallet/channel', 'GET', $params); $request->headers->set('lang', 'en');
+            $request->user = \App\Models\User::find(1); $this->app->instance('request', $request);
+            return (new \App\Http\Controllers\api\Wallet())->getChannel()->getData(true);
+        };
+        foreach ([[], ['currency_type' => null], ['currency_type' => '']] as $params) {
+            $body = $fetch($params); $this->assertSame(0, $body['code']); $this->assertCount(4, $body['data']['list']);
+        }
+        $crypto = $fetch(['currency_type' => 'crypto']);
+        $this->assertSame(['usdt'], array_column($crypto['data']['list'], 'value'));
+        $this->assertSame('5', $crypto['data']['list'][0]['bonus_percent']);
+        $this->assertSame('Extra bonus', $crypto['data']['list'][0]['badge_text']);
+        $this->assertArrayHasKey('logo', $crypto['data']['list'][0]);
+        $fiat = $fetch(['currency_type' => 'fiat']);
+        $this->assertSame(['JDpay', 'rgcz', 'szrmb'], array_column($fiat['data']['list'], 'value'));
+        $this->assertSame([0,1,2], array_keys($fiat['data']['list']));
+        DB::table('recharge_channel_group')->where('id', 1)->update(['recharge_type' => 'JDpay']);
+        $this->assertSame([], $fetch(['currency_type' => 'crypto'])['data']['list']);
+        DB::table('recharge_channel_group')->where('id', 1)->update(['recharge_type' => 'usdt']);
+        DB::table('recharge_channel')->where('type', 'usdt')->update(['status' => 0]);
+        $this->assertSame([], $fetch(['currency_type' => 'crypto'])['data']['list']);
+        foreach (['invalid', 'all', ['crypto']] as $value) $this->assertSame(-3, $fetch(['currency_type' => $value])['code']);
+    }
+
     public function test_actual_wallet_channel_response_localizes_bonus_and_retains_original_channel_settings(): void
     {
         $request = Request::create('/api/wallet/channel', 'GET'); $request->headers->set('lang', 'en');