fix(withdraw): 修复dmepa提现withdraw_info字段长度截断问题及自动升级表结构

这个提交包含在:
chen
2026-09-21 14:51:33 +08:00
父节点 a2220427e2
当前提交 3bd0954df1
共有 5 个文件被更改,包括 332 次插入 和 15 次删除

查看文件

@@ -1188,13 +1188,13 @@ CREATE TABLE IF NOT EXISTS `__PREFIX__shopro_withdraw` (
`amount` decimal(10, 2) NOT NULL DEFAULT '0.00' COMMENT '提现金额',
`paid_fee` decimal(10, 2) NOT NULL DEFAULT '0.00' COMMENT '实际到账',
`charge_fee` decimal(10, 2) NOT NULL DEFAULT '0.00' COMMENT '手续费',
`charge_rate` decimal(10, 3) NOT NULL DEFAULT '0.000' COMMENT '手续费率',
`charge_rate` decimal(10, 4) NOT NULL DEFAULT '0.0000' COMMENT '手续费率',
`withdraw_sn` varchar(191) NOT NULL COMMENT '提现单号',
`withdraw_type` enum('bank','wechat','alipay') NOT NULL COMMENT '提现类型:bank=银行卡,wechat=微信零钱,alipay=支付宝账户',
`withdraw_info` varchar(255) NULL DEFAULT NULL COMMENT '提现信息',
`withdraw_info` text NULL COMMENT '提现信息',
`status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '提现状态:-1=已拒绝,0=待审核,1=处理中,2=已处理',
`platform` enum('H5','App','WechatOfficialAccount','WechatMiniProgram') NULL DEFAULT NULL COMMENT '平台:H5=H5,WechatOfficialAccount=微信公众号,WechatMiniProgram=微信小程序,App=App',
`payment_json` varchar(2500) NULL DEFAULT NULL COMMENT '交易原始数据',
`platform` varchar(50) NULL DEFAULT NULL COMMENT '平台',
`payment_json` text NULL COMMENT '交易原始数据',
`createtime` bigint(16) NULL DEFAULT NULL COMMENT '创建时间',
`updatetime` bigint(16) NULL DEFAULT NULL COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
@@ -1368,4 +1368,12 @@ ALTER TABLE `__PREFIX__shopro_withdraw_log` MODIFY COLUMN `content` text NULL CO
-- 3.2.0 更新 ↓
ALTER TABLE `__PREFIX__shopro_goods_sku` ADD COLUMN `image` varchar(255) NULL DEFAULT NULL COMMENT '缩略图' AFTER `name`;
-- 3.2.0 更新 ↑
-- 3.2.0 更新 ↑
-- 3.2.1 提现与收益中心长文本及高精度升级 ↓
ALTER TABLE `__PREFIX__shopro_withdraw` MODIFY COLUMN `withdraw_info` text NULL COMMENT '提现信息';
ALTER TABLE `__PREFIX__shopro_withdraw` MODIFY COLUMN `charge_rate` decimal(10, 4) NOT NULL DEFAULT '0.0000' COMMENT '手续费率';
ALTER TABLE `__PREFIX__shopro_withdraw` MODIFY COLUMN `platform` varchar(50) NULL DEFAULT NULL COMMENT '平台';
ALTER TABLE `__PREFIX__shopro_withdraw` MODIFY COLUMN `payment_json` text NULL COMMENT '交易原始数据';
ALTER TABLE `__PREFIX__shopro_withdraw_log` MODIFY COLUMN `content` text NULL COMMENT '日志内容';
-- 3.2.1 提现与收益中心长文本及高精度升级 ↑

查看文件

@@ -91,7 +91,7 @@ class Withdraw
$withdraw->withdraw_info = $withdrawInfo;
$withdraw->status = 0;
$withdraw->platform = request()->header('platform');
$withdraw->save();
$this->saveWithdrawSafe($withdraw);
// 扣减对应钱包资金(内扣模式:仅扣除提现申请本金,手续费从提现金额中内扣)
if ($walletType === 'money') {
@@ -201,7 +201,7 @@ class Withdraw
$withdraw->withdraw_info = $withdrawInfo;
$withdraw->status = 0;
$withdraw->platform = request()->header('platform');
$withdraw->save();
$this->saveWithdrawSafe($withdraw);
// 记录合伙人流水
PartnerRewardService::write([
@@ -224,7 +224,7 @@ class Withdraw
'charge_rate' => $chargeRate,
'real_amount' => $realMoney,
],
'settle_date' => date('Y-m-d'),
'settle_date' => null,
'status' => 1,
]);
@@ -663,18 +663,81 @@ class Withdraw
}
/**
* 安全保存提现记录,具备字段溢出与表结构自动修复能力
*/
protected function saveWithdrawSafe($withdraw)
{
try {
$withdraw->save();
} catch (\Exception $e) {
$msg = $e->getMessage();
if (stripos($msg, '22001') !== false || stripos($msg, '1406') !== false || stripos($msg, 'too long') !== false) {
$prefix = config('database.prefix') ?: 'hla_';
try {
\think\Db::execute("ALTER TABLE `{$prefix}shopro_withdraw` MODIFY COLUMN `withdraw_info` text NULL COMMENT '提现信息'");
\think\Db::execute("ALTER TABLE `{$prefix}shopro_withdraw` MODIFY COLUMN `charge_rate` decimal(10, 4) NOT NULL DEFAULT '0.0000' COMMENT '手续费率'");
\think\Db::execute("ALTER TABLE `{$prefix}shopro_withdraw` MODIFY COLUMN `platform` varchar(50) NULL DEFAULT NULL COMMENT '平台'");
\think\Db::execute("ALTER TABLE `{$prefix}shopro_withdraw_log` MODIFY COLUMN `content` text NULL COMMENT '日志内容'");
$withdraw->save();
return $withdraw;
} catch (\Exception $subEx) {
// 若 DDL 无权限或执行失败,执行结构化降级精简以确保提现不中断
$info = $withdraw->withdraw_info;
if (is_array($info)) {
$compact = [
'real_name' => $info['真实姓名'] ?? ($info['real_name'] ?? ''),
'bank_name' => $info['开户行'] ?? ($info['bank_name'] ?? ''),
'card_no' => $info['银行卡号'] ?? ($info['card_no'] ?? ''),
'wallet_type' => $info['wallet_type'] ?? 'madow',
'madow_amount' => $info['madow_amount'] ?? '',
'rate' => $info['rate'] ?? 0,
'charge_fee' => $info['charge_fee'] ?? 0,
'charge_rate' => $info['charge_rate'] ?? 0,
];
$withdraw->withdraw_info = $compact;
$withdraw->save();
return $withdraw;
}
throw $e;
}
}
throw $e;
}
return $withdraw;
}
// 添加日志
private function handleLog($withdraw, $oper_info, $oper = null)
{
$oper = Operator::get($oper);
WithdrawLogModel::insert([
'withdraw_id' => $withdraw->id,
'content' => $oper_info,
'oper_type' => $oper['type'],
'oper_id' => $oper['id'],
'createtime' => time()
]);
try {
WithdrawLogModel::insert([
'withdraw_id' => $withdraw->id,
'content' => $oper_info,
'oper_type' => $oper['type'],
'oper_id' => $oper['id'],
'createtime' => time()
]);
} catch (\Exception $e) {
$msg = $e->getMessage();
if (stripos($msg, '22001') !== false || stripos($msg, '1406') !== false || stripos($msg, 'too long') !== false) {
$prefix = config('database.prefix') ?: 'hla_';
try {
\think\Db::execute("ALTER TABLE `{$prefix}shopro_withdraw_log` MODIFY COLUMN `content` text NULL COMMENT '日志内容'");
} catch (\Exception $ignored) {}
WithdrawLogModel::insert([
'withdraw_id' => $withdraw->id,
'content' => mb_substr($oper_info, 0, 80, 'UTF-8'),
'oper_type' => $oper['type'],
'oper_id' => $oper['id'],
'createtime' => time()
]);
} else {
throw $e;
}
}
return $withdraw;
}