1.新增充值档位配置
2.新增充值/提现配置
This commit is contained in:
@@ -6,7 +6,9 @@ namespace app\api\controller;
|
||||
|
||||
use app\common\library\finance\DepositSettlement;
|
||||
use app\common\library\finance\WithdrawFlow;
|
||||
use app\common\library\game\DepositChannel as DepositChannelLib;
|
||||
use app\common\library\game\DepositTier as DepositTierLib;
|
||||
use app\common\library\game\FinanceCashierConfig as FinanceCashierConfigLib;
|
||||
use app\common\model\DepositOrder;
|
||||
use app\common\model\GameConfig;
|
||||
use app\common\model\WithdrawOrder;
|
||||
@@ -29,19 +31,30 @@ class Finance extends MobileBase
|
||||
|
||||
$lang = $this->currentLang();
|
||||
$tiers = $this->loadEnabledTiers();
|
||||
$effectiveChannels = $this->loadDepositChannelEffective();
|
||||
$list = [];
|
||||
foreach ($tiers as $tier) {
|
||||
$amount = $this->amountString($tier['amount'] ?? '0');
|
||||
$bonus = $this->amountString($tier['bonus_amount'] ?? '0');
|
||||
$total = bcadd($amount, $bonus, 4);
|
||||
$payAmount = $this->amountString($tier['pay_amount'] ?? '0');
|
||||
$currency = isset($tier['currency']) && is_string($tier['currency']) ? strtoupper(trim($tier['currency'])) : 'CNY';
|
||||
if ($currency === '') {
|
||||
$currency = 'CNY';
|
||||
}
|
||||
$localized = DepositTierLib::localize($tier, $lang);
|
||||
$tierId = isset($tier['id']) && is_string($tier['id']) ? $tier['id'] : '';
|
||||
$list[] = [
|
||||
'id' => $tier['id'],
|
||||
'id' => $tierId,
|
||||
'tier_key' => $tierId,
|
||||
'title' => $localized['title'],
|
||||
'currency' => $currency,
|
||||
'pay_amount' => $payAmount,
|
||||
'amount' => $amount,
|
||||
'bonus_amount' => $bonus,
|
||||
'total_amount' => $total,
|
||||
'desc' => $localized['desc'],
|
||||
'channels' => DepositChannelLib::channelsForTier($tierId, $effectiveChannels, $lang),
|
||||
];
|
||||
}
|
||||
return $this->mobileSuccess([
|
||||
@@ -69,7 +82,8 @@ class Finance extends MobileBase
|
||||
* 并把入账动作放到网关回调里完成(回调中调用 DepositSettlement::settle)。
|
||||
*
|
||||
* 请求:application/json 或 x-www-form-urlencoded
|
||||
* - tier_id: 必填,档位 ID(需在 game_config.deposit_tier 启用档位内)
|
||||
* - tier_id / tier_key: 必填,档位唯一标识(与 depositTierList 中 id、tier_key 一致)
|
||||
* - channel_code: 必填,支付渠道代码(与 depositTierList 各档位 channels[].code 一致)
|
||||
* - idempotency_key: 必填,客户端幂等键,短时间内重复提交只生成一次订单
|
||||
*
|
||||
* 响应(统一结构,未来接入第三方也保持此形状):
|
||||
@@ -83,8 +97,12 @@ class Finance extends MobileBase
|
||||
}
|
||||
|
||||
$tierId = $this->stringParam($request->input('tier_id'));
|
||||
if ($tierId === '') {
|
||||
$tierId = $this->stringParam($request->input('tier_key'));
|
||||
}
|
||||
$channelCode = strtolower($this->stringParam($request->input('channel_code')));
|
||||
$idempotencyKey = $this->stringParam($request->input('idempotency_key'));
|
||||
if ($tierId === '' || $idempotencyKey === '') {
|
||||
if ($tierId === '' || $channelCode === '' || $idempotencyKey === '') {
|
||||
return $this->mobileError(1001, 'Missing parameters');
|
||||
}
|
||||
if (mb_strlen($idempotencyKey) > 64) {
|
||||
@@ -96,6 +114,10 @@ class Finance extends MobileBase
|
||||
if (!$tier) {
|
||||
return $this->mobileError(2003, 'Deposit tier not available');
|
||||
}
|
||||
$effectiveChannels = $this->loadDepositChannelEffective();
|
||||
if (!DepositChannelLib::assertChannelAllowsTier($channelCode, $tierId, $effectiveChannels)) {
|
||||
return $this->mobileError(2004, 'Pay channel not available');
|
||||
}
|
||||
|
||||
// 幂等命中:直接返回已有订单
|
||||
try {
|
||||
@@ -112,14 +134,21 @@ class Finance extends MobileBase
|
||||
|
||||
$user = $this->auth->getUser();
|
||||
$orderNo = 'DP' . date('YmdHis') . substr(str_replace('.', '', uniqid('', true)), -6);
|
||||
$curSnap = isset($tier['currency']) && is_string($tier['currency']) ? strtoupper(trim($tier['currency'])) : 'CNY';
|
||||
if ($curSnap === '') {
|
||||
$curSnap = 'CNY';
|
||||
}
|
||||
$tierSnapshot = [
|
||||
'id' => $tier['id'],
|
||||
'title' => is_string($tier['title'] ?? null) ? $tier['title'] : '',
|
||||
'title_en' => is_string($tier['title_en'] ?? null) ? $tier['title_en'] : '',
|
||||
'currency' => $curSnap,
|
||||
'pay_amount' => $this->amountString($tier['pay_amount'] ?? '0'),
|
||||
'amount' => $this->amountString($tier['amount'] ?? '0'),
|
||||
'bonus_amount' => $this->amountString($tier['bonus_amount'] ?? '0'),
|
||||
'desc' => is_string($tier['desc'] ?? null) ? $tier['desc'] : '',
|
||||
'desc_en' => is_string($tier['desc_en'] ?? null) ? $tier['desc_en'] : '',
|
||||
'channel_code' => $channelCode,
|
||||
];
|
||||
|
||||
$now = time();
|
||||
@@ -138,7 +167,7 @@ class Finance extends MobileBase
|
||||
'amount' => $tierSnapshot['amount'],
|
||||
'bonus_amount' => $tierSnapshot['bonus_amount'],
|
||||
'status' => 0,
|
||||
'pay_channel' => 'mock_gateway',
|
||||
'pay_channel' => $channelCode,
|
||||
'deposit_tier_id' => $tier['id'],
|
||||
'proof_image' => '',
|
||||
'pay_account_snapshot' => json_encode($tierSnapshot, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
|
||||
@@ -163,7 +192,9 @@ class Finance extends MobileBase
|
||||
DepositSettlement::settle(
|
||||
$orderId,
|
||||
DepositSettlement::SOURCE_MOCK_GATEWAY,
|
||||
'mock gateway auto settled'
|
||||
'mock gateway auto settled',
|
||||
null,
|
||||
'channel_code=' . $channelCode
|
||||
);
|
||||
} catch (Throwable $e) {
|
||||
return $this->mobileError(2000, $e->getMessage());
|
||||
@@ -483,6 +514,214 @@ class Finance extends MobileBase
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 收银台配置:货币列表(含充值/提现汇率)、支付渠道(pay_channels)、提现银行与文案(供充值/提现页展示)
|
||||
*/
|
||||
public function cashierConfig(Request $request): Response
|
||||
{
|
||||
$response = $this->initializeMobile($request);
|
||||
if ($response !== null) {
|
||||
return $response;
|
||||
}
|
||||
$lang = $this->currentLang();
|
||||
$isZh = str_starts_with($lang, 'zh');
|
||||
$row = GameConfig::where('config_key', FinanceCashierConfigLib::CONFIG_KEY)->find();
|
||||
$cfg = FinanceCashierConfigLib::parseFromConfigValue($row?->config_value ?? null);
|
||||
|
||||
$pc = $cfg['platform_coin'] ?? [];
|
||||
$platformLabel = '';
|
||||
if (is_array($pc)) {
|
||||
$platformLabel = $isZh
|
||||
? (is_string($pc['label_zh'] ?? null) ? $pc['label_zh'] : '')
|
||||
: (is_string($pc['label_en'] ?? null) ? $pc['label_en'] : '');
|
||||
}
|
||||
|
||||
$currencies = [];
|
||||
if (isset($cfg['currencies']) && is_array($cfg['currencies'])) {
|
||||
$list = $cfg['currencies'];
|
||||
usort($list, function (array $a, array $b): int {
|
||||
return $this->sortBySortKeyThenCode($a, $b);
|
||||
});
|
||||
foreach ($list as $c) {
|
||||
if (!is_array($c)) {
|
||||
continue;
|
||||
}
|
||||
$code = isset($c['code']) && is_string($c['code']) ? $c['code'] : '';
|
||||
if ($code === '') {
|
||||
continue;
|
||||
}
|
||||
$dep = isset($c['deposit_coins_per_fiat']) && is_string($c['deposit_coins_per_fiat']) ? $c['deposit_coins_per_fiat'] : '';
|
||||
$wdr = isset($c['withdraw_coins_per_fiat']) && is_string($c['withdraw_coins_per_fiat']) ? $c['withdraw_coins_per_fiat'] : '';
|
||||
$currencies[] = [
|
||||
'code' => $code,
|
||||
'label' => $isZh
|
||||
? (is_string($c['label_zh'] ?? null) ? $c['label_zh'] : '')
|
||||
: (is_string($c['label_en'] ?? null) ? $c['label_en'] : ''),
|
||||
'deposit_coins_per_fiat' => $dep,
|
||||
'withdraw_coins_per_fiat' => $wdr,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$rates = [];
|
||||
foreach ($currencies as $c) {
|
||||
if (!is_array($c)) {
|
||||
continue;
|
||||
}
|
||||
$cur = isset($c['code']) && is_string($c['code']) ? $c['code'] : '';
|
||||
$ratio = isset($c['withdraw_coins_per_fiat']) && is_string($c['withdraw_coins_per_fiat']) ? $c['withdraw_coins_per_fiat'] : '';
|
||||
if ($cur === '' || $ratio === '') {
|
||||
continue;
|
||||
}
|
||||
$rates[] = [
|
||||
'currency' => $cur,
|
||||
'diamonds_per_fiat_unit' => $ratio,
|
||||
];
|
||||
}
|
||||
|
||||
$banks = [];
|
||||
if (isset($cfg['withdraw_banks']) && is_array($cfg['withdraw_banks'])) {
|
||||
$list = $cfg['withdraw_banks'];
|
||||
usort($list, function (array $a, array $b): int {
|
||||
$cmp = $this->sortBySortKeyOnly($a, $b);
|
||||
if ($cmp !== 0) {
|
||||
return $cmp;
|
||||
}
|
||||
$ca = isset($a['code']) && is_string($a['code']) ? $a['code'] : '';
|
||||
$cb = isset($b['code']) && is_string($b['code']) ? $b['code'] : '';
|
||||
|
||||
return strcmp($ca, $cb);
|
||||
});
|
||||
foreach ($list as $b) {
|
||||
if (!is_array($b)) {
|
||||
continue;
|
||||
}
|
||||
$code = isset($b['code']) && is_string($b['code']) ? $b['code'] : '';
|
||||
if ($code === '') {
|
||||
continue;
|
||||
}
|
||||
$banks[] = [
|
||||
'code' => $code,
|
||||
'name' => $isZh
|
||||
? (is_string($b['name_zh'] ?? null) ? $b['name_zh'] : '')
|
||||
: (is_string($b['name_en'] ?? null) ? $b['name_en'] : ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$wl = $cfg['withdraw_limits'] ?? [];
|
||||
$minEw = is_array($wl) && isset($wl['min_ewallet']) && is_string($wl['min_ewallet']) ? $wl['min_ewallet'] : '0';
|
||||
$minBk = is_array($wl) && isset($wl['min_bank']) && is_string($wl['min_bank']) ? $wl['min_bank'] : '0';
|
||||
|
||||
$wc = $cfg['withdraw_copy'] ?? [];
|
||||
$rateMode = is_array($wc) && isset($wc['rate_mode']) && is_string($wc['rate_mode']) ? $wc['rate_mode'] : 'fixed';
|
||||
|
||||
$wf = $cfg['withdraw_fields'] ?? [];
|
||||
$reqCard = is_array($wf) && !empty($wf['require_cardholder']);
|
||||
$reqAcct = is_array($wf) && !empty($wf['require_bank_account']);
|
||||
$reqMail = is_array($wf) && !empty($wf['require_email']);
|
||||
$reqMob = is_array($wf) && !empty($wf['require_mobile']);
|
||||
|
||||
$payChannels = [];
|
||||
$effectiveCh = DepositChannelLib::effectiveRowsFromDb();
|
||||
$regCh = DepositChannelLib::codeRegistry();
|
||||
foreach ($effectiveCh as $row) {
|
||||
if (!is_array($row)) {
|
||||
continue;
|
||||
}
|
||||
$code = isset($row['code']) && is_string($row['code']) ? $row['code'] : '';
|
||||
if ($code === '' || !isset($regCh[$code]) || !is_array($regCh[$code])) {
|
||||
continue;
|
||||
}
|
||||
$meta = $regCh[$code];
|
||||
$nameZh = isset($meta['name']) && is_string($meta['name']) ? $meta['name'] : '';
|
||||
$nameEn = isset($meta['name_en']) && is_string($meta['name_en']) ? $meta['name_en'] : '';
|
||||
$sortNum = filter_var($row['sort'] ?? 0, FILTER_VALIDATE_INT);
|
||||
$statusNum = filter_var($row['status'] ?? 0, FILTER_VALIDATE_INT);
|
||||
$payChannels[] = [
|
||||
'code' => $code,
|
||||
'name' => $isZh ? $nameZh : ($nameEn !== '' ? $nameEn : $nameZh),
|
||||
'sort' => $sortNum !== false ? $sortNum : 0,
|
||||
'status' => $statusNum !== false ? $statusNum : 0,
|
||||
'tier_ids' => isset($row['tier_ids']) && is_array($row['tier_ids']) ? $row['tier_ids'] : [],
|
||||
];
|
||||
}
|
||||
usort($payChannels, function (array $a, array $b): int {
|
||||
$sa = isset($a['sort']) ? filter_var($a['sort'], FILTER_VALIDATE_INT) : false;
|
||||
$sb = isset($b['sort']) ? filter_var($b['sort'], FILTER_VALIDATE_INT) : false;
|
||||
$ia = $sa === false ? 0 : $sa;
|
||||
$ib = $sb === false ? 0 : $sb;
|
||||
if ($ia !== $ib) {
|
||||
return $ia <=> $ib;
|
||||
}
|
||||
$ca = isset($a['code']) && is_string($a['code']) ? $a['code'] : '';
|
||||
$cb = isset($b['code']) && is_string($b['code']) ? $b['code'] : '';
|
||||
|
||||
return strcmp($ca, $cb);
|
||||
});
|
||||
|
||||
return $this->mobileSuccess([
|
||||
'platform_coin_label' => $platformLabel,
|
||||
'currencies' => $currencies,
|
||||
'rates' => $rates,
|
||||
'pay_channels' => $payChannels,
|
||||
'withdraw' => [
|
||||
'banks' => $banks,
|
||||
'min_ewallet' => $minEw,
|
||||
'min_bank' => $minBk,
|
||||
'rate_hint' => $isZh
|
||||
? (is_array($wc) && is_string($wc['rate_hint_zh'] ?? null) ? $wc['rate_hint_zh'] : '')
|
||||
: (is_array($wc) && is_string($wc['rate_hint_en'] ?? null) ? $wc['rate_hint_en'] : ''),
|
||||
'processing_note' => $isZh
|
||||
? (is_array($wc) && is_string($wc['processing_zh'] ?? null) ? $wc['processing_zh'] : '')
|
||||
: (is_array($wc) && is_string($wc['processing_en'] ?? null) ? $wc['processing_en'] : ''),
|
||||
'fee_note' => $isZh
|
||||
? (is_array($wc) && is_string($wc['fee_note_zh'] ?? null) ? $wc['fee_note_zh'] : '')
|
||||
: (is_array($wc) && is_string($wc['fee_note_en'] ?? null) ? $wc['fee_note_en'] : ''),
|
||||
'rate_mode' => $rateMode,
|
||||
'fields' => [
|
||||
'require_cardholder' => $reqCard,
|
||||
'require_bank_account' => $reqAcct,
|
||||
'require_email' => $reqMail,
|
||||
'require_mobile' => $reqMob,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $a
|
||||
* @param array<string, mixed> $b
|
||||
*/
|
||||
private function sortBySortKeyThenCode(array $a, array $b): int
|
||||
{
|
||||
$sa = isset($a['sort']) ? filter_var($a['sort'], FILTER_VALIDATE_INT) : false;
|
||||
$sb = isset($b['sort']) ? filter_var($b['sort'], FILTER_VALIDATE_INT) : false;
|
||||
$ia = $sa === false ? 0 : $sa;
|
||||
$ib = $sb === false ? 0 : $sb;
|
||||
if ($ia !== $ib) {
|
||||
return $ia <=> $ib;
|
||||
}
|
||||
$ca = isset($a['code']) && is_string($a['code']) ? $a['code'] : '';
|
||||
$cb = isset($b['code']) && is_string($b['code']) ? $b['code'] : '';
|
||||
|
||||
return strcmp($ca, $cb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $a
|
||||
* @param array<string, mixed> $b
|
||||
*/
|
||||
private function sortBySortKeyOnly(array $a, array $b): int
|
||||
{
|
||||
$sa = isset($a['sort']) ? filter_var($a['sort'], FILTER_VALIDATE_INT) : false;
|
||||
$sb = isset($b['sort']) ? filter_var($b['sort'], FILTER_VALIDATE_INT) : false;
|
||||
$ia = $sa === false ? 0 : $sa;
|
||||
$ib = $sb === false ? 0 : $sb;
|
||||
|
||||
return $ia <=> $ib;
|
||||
}
|
||||
|
||||
private function stringParam($raw): string
|
||||
{
|
||||
if ($raw === null) {
|
||||
@@ -501,6 +740,14 @@ class Finance extends MobileBase
|
||||
return DepositTierLib::publicList($all);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{code: string, sort: int, status: int, tier_ids: list<string>}>
|
||||
*/
|
||||
private function loadDepositChannelEffective(): array
|
||||
{
|
||||
return DepositChannelLib::effectiveRowsFromDb();
|
||||
}
|
||||
|
||||
private function mapDepositStatus($status): string
|
||||
{
|
||||
if ($this->intValue($status) === 1) {
|
||||
|
||||
Reference in New Issue
Block a user