1.配置新版支付模块-菜单和接口都已重构

2.优化充值提现页面
3.菜单翻译问题
4.备份数据库
This commit is contained in:
2026-04-30 11:37:46 +08:00
parent e8c2b9d345
commit c7fc754573
23 changed files with 4042 additions and 400 deletions

View File

@@ -6,6 +6,7 @@ namespace app\admin\controller\config;
use app\common\controller\Backend;
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\service\GameHotDataCoordinator;
use app\common\service\GameHotDataLock;
@@ -22,7 +23,7 @@ class FinanceCashierConfig extends Backend
{
protected bool $modelValidate = false;
protected array $noNeedPermission = ['index', 'save'];
protected array $noNeedPermission = ['index', 'save', 'tierList', 'tierSave'];
private function hasNodePermission(WebmanRequest $request, string $action): bool
{
@@ -109,6 +110,21 @@ class FinanceCashierConfig extends Backend
if (!is_array($payload)) {
return $this->error(__('Parameter %s can not be empty', ['']));
}
$pruneTierCurrencies = [];
if (isset($payload['prune_tier_currency_codes']) && is_array($payload['prune_tier_currency_codes'])) {
foreach ($payload['prune_tier_currency_codes'] as $c) {
if (!is_string($c)) {
continue;
}
$s = strtoupper(trim($c));
if ($s !== '') {
$pruneTierCurrencies[] = $s;
}
}
$pruneTierCurrencies = array_values(array_unique($pruneTierCurrencies));
}
unset($payload['prune_tier_currency_codes']);
try {
$json = FinanceCashierConfigLib::encodeForDb($payload);
} catch (InvalidArgumentException $e) {
@@ -162,11 +178,17 @@ class FinanceCashierConfig extends Backend
'update_time' => $now,
]);
}
if ($pruneTierCurrencies !== []) {
$this->pruneDepositTiersByCurrencies($pruneTierCurrencies, $now);
}
} catch (Throwable $e) {
return $this->error($e->getMessage());
}
GameHotDataCoordinator::afterGameConfigKeyCommitted(FinanceCashierConfigLib::CONFIG_KEY);
GameHotDataCoordinator::afterGameConfigKeyCommitted(DepositChannelLib::CONFIG_KEY);
if ($pruneTierCurrencies !== []) {
GameHotDataCoordinator::afterGameConfigKeyCommitted(DepositTierLib::CONFIG_KEY);
}
return $this->success(__('Saved successfully'));
} finally {
@@ -174,6 +196,83 @@ class FinanceCashierConfig extends Backend
}
}
public function tierList(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
if (!$this->hasNodePermission($request, 'tierList')) {
return $this->error(__('You have no permission'), [], 401);
}
if ($request->method() !== 'GET') {
return $this->error(__('Parameter error'));
}
$list = $this->loadDepositTierItems();
return $this->success('', ['list' => $list]);
}
public function tierSave(WebmanRequest $request): Response
{
$response = $this->initializeBackend($request);
if ($response !== null) {
return $response;
}
if (!$this->hasNodePermission($request, 'tierSave')) {
return $this->error(__('You have no permission'), [], 401);
}
if ($request->method() !== 'POST') {
return $this->error(__('Parameter error'));
}
$payload = $request->post();
if (!is_array($payload)) {
return $this->error(__('Parameter error'));
}
$items = $payload['items'] ?? null;
if (!is_array($items)) {
return $this->error(__('Items must be an array'));
}
try {
$clean = DepositTierLib::prepareItemsForSave(array_values($items));
$json = DepositTierLib::encodeForDb($clean);
} catch (InvalidArgumentException $e) {
return $this->error($e->getMessage());
}
$now = time();
$resourceKey = GameHotDataLock::safeResourceKeyForConfig(DepositTierLib::CONFIG_KEY);
$lock = GameHotDataLock::tryAcquire(GameHotDataLock::TYPE_GAME_CONFIG, $resourceKey);
if (!$lock['acquired']) {
return $this->error(__('This config is locked by another operation, please try again later'));
}
try {
$exists = Db::name('game_config')->where('config_key', DepositTierLib::CONFIG_KEY)->find();
if ($exists) {
Db::name('game_config')->where('config_key', DepositTierLib::CONFIG_KEY)->update([
'config_value' => $json,
'value_type' => 'json',
'update_time' => $now,
]);
} else {
Db::name('game_config')->insert([
'config_key' => DepositTierLib::CONFIG_KEY,
'config_value' => $json,
'value_type' => 'json',
'remark' => '充值档位 JSON 数组financeCashierConfig 统一维护)',
'create_time' => $now,
'update_time' => $now,
]);
}
GameHotDataCoordinator::afterGameConfigKeyCommitted(DepositTierLib::CONFIG_KEY);
return $this->success(__('Saved successfully'));
} catch (Throwable $e) {
return $this->error($e->getMessage());
} finally {
GameHotDataLock::release(GameHotDataLock::TYPE_GAME_CONFIG, $resourceKey, $lock['token'], $lock['redis_lock']);
}
}
/**
* @return array<string, array{name: string, name_en: string, sort: int}>
*/
@@ -194,4 +293,54 @@ class FinanceCashierConfig extends Backend
return $registryOut;
}
/**
* @return list<array<string, mixed>>
*/
private function loadDepositTierItems(): array
{
$row = Db::name('game_config')->where('config_key', DepositTierLib::CONFIG_KEY)->find();
return DepositTierLib::parseFromConfigValue(is_array($row) ? ($row['config_value'] ?? null) : null);
}
/**
* @param list<string> $currencyCodes
*/
private function pruneDepositTiersByCurrencies(array $currencyCodes, int $now): void
{
if ($currencyCodes === []) {
return;
}
$exists = Db::name('game_config')->where('config_key', DepositTierLib::CONFIG_KEY)->find();
$items = $this->loadDepositTierItems();
$filtered = [];
foreach ($items as $row) {
if (!is_array($row)) {
continue;
}
$currency = isset($row['currency']) && is_string($row['currency']) ? strtoupper(trim($row['currency'])) : '';
if ($currency !== '' && in_array($currency, $currencyCodes, true)) {
continue;
}
$filtered[] = $row;
}
$json = DepositTierLib::encodeForDb(DepositTierLib::prepareItemsForSave(array_values($filtered)));
if ($exists) {
Db::name('game_config')->where('config_key', DepositTierLib::CONFIG_KEY)->update([
'config_value' => $json,
'value_type' => 'json',
'update_time' => $now,
]);
} else {
Db::name('game_config')->insert([
'config_key' => DepositTierLib::CONFIG_KEY,
'config_value' => $json,
'value_type' => 'json',
'remark' => '充值档位 JSON 数组financeCashierConfig 统一维护)',
'create_time' => $now,
'update_time' => $now,
]);
}
}
}

View File

@@ -3,6 +3,7 @@
namespace app\admin\controller\order;
use app\common\controller\Backend;
use app\common\library\finance\DDPayGateway;
use support\think\Db;
use support\Response;
use Throwable;
@@ -251,6 +252,264 @@ class WithdrawOrder extends Backend
return $this->error($e->getMessage());
}
// 审核通过后自动发起 DDPAY 出金(并在失败时回冲余额)
try {
$fresh = Db::name('withdraw_order')->where('id', $id)->find();
if (!is_array($fresh)) {
// 理论上不会发生:只写失败备注
Db::name('withdraw_order')->where('id', $id)->update([
'remark' => '[ddpay] payout order missing',
'update_time' => time(),
]);
} else {
$orderNo = is_string($fresh['order_no'] ?? null) ? trim($fresh['order_no'] ?? '') : strval($fresh['order_no'] ?? '');
$receiveType = is_string($fresh['receive_type'] ?? null) ? strtolower(trim($fresh['receive_type'] ?? '')) : '';
// 当前仅接入 bank 类型出金(与移动端 withdrawCreate 校验一致)
if ($orderNo !== '' && $receiveType === 'bank') {
$base = \app\common\library\finance\DDPayGateway::publicBaseUrlForCallbacks($request);
if ($base === '') {
$base = 'https://' . strval($request->host());
}
$callbackUrl = rtrim($base, '/') . '/api/finance/ddpayPayoutNotify';
$payoutAmount = is_string($fresh['actual_amount'] ?? null) && $fresh['actual_amount'] !== '' ? trim($fresh['actual_amount']) : $newActual;
$receiverName = is_string($fresh['ddpay_receiver_name'] ?? null) ? trim($fresh['ddpay_receiver_name'] ?? '') : '';
$receiverAccount = is_string($fresh['receive_account'] ?? null) ? trim($fresh['receive_account'] ?? '') : '';
$bankName = is_string($fresh['ddpay_bank_name'] ?? null) ? trim($fresh['ddpay_bank_name'] ?? '') : '';
$bankBranch = is_string($fresh['ddpay_bank_branch'] ?? null) ? trim($fresh['ddpay_bank_branch'] ?? '') : 'N/A';
if ($receiverName === '' || $receiverAccount === '' || $bankName === '') {
// 缺少 DDPAY 出金字段:回冲并置为失败
Db::startTrans();
try {
$amountRefund = bcadd(strval($fresh['amount'] ?? '0'), '0', 2);
$updated = Db::name('withdraw_order')
->where('id', $id)
->where('status', 1)
->update([
'status' => 2,
'remark' => '[ddpay] missing payout fields',
'update_time' => time(),
]);
if ($updated > 0 && bccomp($amountRefund, '0', 2) > 0) {
$userIdRefund = intval(strval($fresh['user_id'] ?? 0));
$userRow = Db::name('user')->where('id', $userIdRefund)->find();
$beforeCoin = bcadd(strval($userRow['coin'] ?? '0'), '0', 2);
$afterCoin = bcadd($beforeCoin, $amountRefund, 2);
Db::name('user')->where('id', $userIdRefund)->update([
'coin' => $afterCoin,
'total_withdraw_coin' => Db::raw('total_withdraw_coin - ' . $amountRefund),
'update_time' => time(),
]);
$idempotencyKey = 'wd_ddpay_failed_' . strval($orderNo);
$exists = Db::name('user_wallet_record')->where('idempotency_key', $idempotencyKey)->find();
if (!$exists) {
$channelId = null;
if (isset($fresh['channel_id']) && is_numeric(strval($fresh['channel_id']))) {
$channelId = intval(strval($fresh['channel_id']));
}
Db::name('user_wallet_record')->insert([
'user_id' => $userIdRefund,
'channel_id' => $channelId,
'biz_type' => 'withdraw_refund',
'direction' => 1,
'amount' => $amountRefund,
'balance_before' => $beforeCoin,
'balance_after' => $afterCoin,
'ref_type' => 'withdraw_order',
'ref_id' => intval(strval($id)),
'idempotency_key' => $idempotencyKey,
'operator_admin_id' => null,
'remark' => '[ddpay] missing payout fields refund',
'create_time' => time(),
]);
}
}
Db::commit();
} catch (Throwable $e2) {
Db::rollback();
}
} else {
$clientId = config('app.ddpay_client_id', '');
$identifier = config('app.ddpay_identifier', '');
$ddReq = [
'client_id' => $clientId,
'identifier' => $identifier,
'bill_number' => $orderNo,
'amount' => $payoutAmount,
'receiver_name' => $receiverName,
'receiver_account' => $receiverAccount,
'bank[name]' => $bankName,
'bank_branch' => $bankBranch,
'callback_url' => $callbackUrl,
];
$ddResp = [];
$ts = '';
try {
$ddResp = DDPayGateway::payoutInitiation($ddReq);
$ts = is_string($ddResp['transaction_status'] ?? null) ? strtolower(trim($ddResp['transaction_status'] ?? '')) : '';
} catch (Throwable $e) {
// initiation 异常同“failed”处理回冲并置失败
$ts = 'failed';
$ddResp = ['error' => (string) $e->getMessage()];
}
if (is_array($ddResp)) {
Db::name('withdraw_order')
->where('id', $id)
->update([
'ddpay_payout_snapshot' => json_encode([
'init_request' => $ddReq,
'init_response' => $ddResp,
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
]);
}
if ($ts === 'completed') {
Db::name('withdraw_order')
->where('id', $id)
->where('status', 1)
->update([
'status' => 3,
'remark' => '[ddpay] payout completed',
'update_time' => time(),
]);
} elseif ($ts === 'failed') {
$amountRefund = bcadd(strval($fresh['amount'] ?? '0'), '0', 2);
Db::startTrans();
try {
$updated = Db::name('withdraw_order')
->where('id', $id)
->where('status', 1)
->update([
'status' => 2,
'remark' => '[ddpay] payout failed',
'update_time' => time(),
]);
if ($updated > 0 && bccomp($amountRefund, '0', 2) > 0) {
$userIdRefund = intval(strval($fresh['user_id'] ?? 0));
$userRow = Db::name('user')->where('id', $userIdRefund)->find();
$beforeCoin = bcadd(strval($userRow['coin'] ?? '0'), '0', 2);
$afterCoin = bcadd($beforeCoin, $amountRefund, 2);
Db::name('user')->where('id', $userIdRefund)->update([
'coin' => $afterCoin,
'total_withdraw_coin' => Db::raw('total_withdraw_coin - ' . $amountRefund),
'update_time' => time(),
]);
$idempotencyKey = 'wd_ddpay_failed_' . strval($orderNo);
$exists = Db::name('user_wallet_record')->where('idempotency_key', $idempotencyKey)->find();
if (!$exists) {
$channelId = null;
if (isset($fresh['channel_id']) && is_numeric(strval($fresh['channel_id']))) {
$channelId = intval(strval($fresh['channel_id']));
}
Db::name('user_wallet_record')->insert([
'user_id' => $userIdRefund,
'channel_id' => $channelId,
'biz_type' => 'withdraw_refund',
'direction' => 1,
'amount' => $amountRefund,
'balance_before' => $beforeCoin,
'balance_after' => $afterCoin,
'ref_type' => 'withdraw_order',
'ref_id' => intval(strval($id)),
'idempotency_key' => $idempotencyKey,
'operator_admin_id' => null,
'remark' => '[ddpay] payout failed refund',
'create_time' => time(),
]);
}
}
Db::commit();
} catch (Throwable $e3) {
Db::rollback();
}
} else {
// pending按文档做一次 status inquiry 兜底Webhook 仍会最终落账)
try {
$inq = DDPayGateway::payoutStatusInquiry([
'client_id' => $clientId,
'bill_number' => $orderNo,
]);
$ts2 = is_string($inq['transaction_status'] ?? null) ? strtolower(trim($inq['transaction_status'] ?? '')) : '';
if ($ts2 === 'completed') {
Db::name('withdraw_order')
->where('id', $id)
->where('status', 1)
->update([
'status' => 3,
'remark' => '[ddpay] payout completed (after status inquiry)',
'update_time' => time(),
]);
} elseif ($ts2 === 'failed') {
$amountRefund = bcadd(strval($fresh['amount'] ?? '0'), '0', 2);
Db::startTrans();
try {
$updated = Db::name('withdraw_order')
->where('id', $id)
->where('status', 1)
->update([
'status' => 2,
'remark' => '[ddpay] payout failed (after status inquiry)',
'update_time' => time(),
]);
if ($updated > 0 && bccomp($amountRefund, '0', 2) > 0) {
$userIdRefund = intval(strval($fresh['user_id'] ?? 0));
$userRow = Db::name('user')->where('id', $userIdRefund)->find();
$beforeCoin = bcadd(strval($userRow['coin'] ?? '0'), '0', 2);
$afterCoin = bcadd($beforeCoin, $amountRefund, 2);
Db::name('user')->where('id', $userIdRefund)->update([
'coin' => $afterCoin,
'total_withdraw_coin' => Db::raw('total_withdraw_coin - ' . $amountRefund),
'update_time' => time(),
]);
$idempotencyKey = 'wd_ddpay_failed_' . strval($orderNo);
$exists = Db::name('user_wallet_record')->where('idempotency_key', $idempotencyKey)->find();
if (!$exists) {
$channelId = null;
if (isset($fresh['channel_id']) && is_numeric(strval($fresh['channel_id']))) {
$channelId = intval(strval($fresh['channel_id']));
}
Db::name('user_wallet_record')->insert([
'user_id' => $userIdRefund,
'channel_id' => $channelId,
'biz_type' => 'withdraw_refund',
'direction' => 1,
'amount' => $amountRefund,
'balance_before' => $beforeCoin,
'balance_after' => $afterCoin,
'ref_type' => 'withdraw_order',
'ref_id' => intval(strval($id)),
'idempotency_key' => $idempotencyKey,
'operator_admin_id' => null,
'remark' => '[ddpay] payout failed refund (after status inquiry)',
'create_time' => time(),
]);
}
}
Db::commit();
} catch (Throwable $e4) {
Db::rollback();
}
}
} catch (Throwable $e5) {
// ignoreWebhook 会兜底
}
}
}
}
}
} catch (Throwable $e) {
// 外部出金调用失败不阻断审核流:只记录 remark避免阻塞用户提现
Db::name('withdraw_order')->where('id', $id)->update([
'remark' => '[ddpay] payout flow exception: ' . substr((string) $e->getMessage(), 0, 200),
'update_time' => time(),
]);
}
return $this->success(__('Approved'), [
'id' => $id,
'amount' => $newAmount,