fix(withdraw): 修复提现台账导出PHP8兼容性与页面崩溃问题,统一大余额与导出体验

这个提交包含在:
chen
2026-09-21 15:11:58 +08:00
父节点 3bd0954df1
当前提交 dbd0ac5e02
共有 21 个文件被更改,包括 255 次插入 和 165 次删除

查看文件

@@ -72,112 +72,109 @@ class Withdraw extends Common
'updatetime' => '操作时间',
];
$total = $this->model->sheepFilter()->count();
if ($total <= 0) {
$this->error('导出数据为空');
try {
$total = (new WithdrawModel)->sheepFilter()->count();
if ($total <= 0) {
$this->error('导出数据为空');
}
$export = new \addons\shopro\library\Export();
$params = [
'file_name' => '提现管理台账',
'cell_titles' => $cellTitles,
'total' => $total,
'is_sub_cell' => false,
];
$totalAmount = 0;
$totalPaidFee = 0;
$totalChargeFee = 0;
$result = $export->export($params, function ($pages) use (&$totalAmount, &$totalPaidFee, &$totalChargeFee, $total) {
$datas = (new WithdrawModel)->sheepFilter()->with(['user'])
->limit((($pages['page'] - 1) * $pages['list_rows']), $pages['list_rows'])
->select();
$newDatas = [];
foreach ($datas as $withdraw) {
$user = $withdraw['user'] ?? null;
$displayInfo = $withdraw['withdraw_info_display'] ?? ($withdraw['withdraw_info'] ?? []);
// 收款账户信息
$payeeName = $displayInfo['真实姓名'] ?? ($displayInfo['姓名'] ?? ($displayInfo['微信用户'] ?? ''));
$bankName = $displayInfo['开户行'] ?? ($displayInfo['开户银行'] ?? '');
$cardNo = $displayInfo['银行卡号'] ?? ($displayInfo['卡号'] ?? ($displayInfo['支付宝账户'] ?? ($displayInfo['支付宝账号'] ?? ($displayInfo['微信ID'] ?? ''))));
if ($cardNo !== '') {
$cardNo = "\t" . $cardNo;
}
// 提现资产类型
$assetType = !empty($withdraw['is_madow_withdraw']) ? 'DMEPA' : (!empty($withdraw['is_money_withdraw']) ? '钱包余额' : ($displayInfo['提现资产'] ?? '钱包余额'));
// 资产折算明细
$assetDetailParts = [];
if (!empty($displayInfo['扣除DMEPA'])) {
$assetDetailParts[] = '扣除: ' . $displayInfo['扣除DMEPA'];
}
if (!empty($displayInfo['市值汇率'])) {
$assetDetailParts[] = $displayInfo['市值汇率'];
}
if (!empty($displayInfo['换算市值'])) {
$assetDetailParts[] = '市值: ' . $displayInfo['换算市值'];
}
$assetDetail = implode('; ', $assetDetailParts);
$amount = floatval($withdraw['amount'] ?? 0);
$paidFee = floatval($withdraw['paid_fee'] ?? 0) > 0 ? floatval($withdraw['paid_fee']) : floatval($withdraw['real_amount'] ?? $amount);
$chargeFee = floatval($withdraw['charge_fee'] ?? 0);
$totalAmount = function_exists('bcadd') ? bcadd((string)$totalAmount, (string)$amount, 2) : ($totalAmount + $amount);
$totalPaidFee = function_exists('bcadd') ? bcadd((string)$totalPaidFee, (string)$paidFee, 2) : ($totalPaidFee + $paidFee);
$totalChargeFee = function_exists('bcadd') ? bcadd((string)$totalChargeFee, (string)$chargeFee, 2) : ($totalChargeFee + $chargeFee);
$createTime = is_numeric($withdraw['createtime'] ?? null) && intval($withdraw['createtime']) > 0
? date('Y-m-d H:i:s', intval($withdraw['createtime']))
: ($withdraw['createtime'] ?: '-');
$updateTime = is_numeric($withdraw['updatetime'] ?? null) && intval($withdraw['updatetime']) > 0
? date('Y-m-d H:i:s', intval($withdraw['updatetime']))
: ($withdraw['updatetime'] ?: '-');
$newDatas[] = [
'id' => $withdraw['id'],
'withdraw_sn' => "\t" . (string)($withdraw['withdraw_sn'] ?? ''),
'user_nickname' => $user['nickname'] ?? ('用户 ' . $withdraw['user_id']),
'user_mobile' => "\t" . (string)($user['mobile'] ?? ''),
'asset_type' => $assetType,
'amount' => number_format($amount, 2, '.', ''),
'paid_fee' => number_format($paidFee, 2, '.', ''),
'charge_rate_format' => $withdraw['charge_rate_format'] ?? '0.0%',
'charge_fee' => number_format($chargeFee, 2, '.', ''),
'withdraw_type_text' => $withdraw['withdraw_type_text'] ?? '-',
'payee_name' => $payeeName ?: '-',
'bank_name' => $bankName ?: '-',
'card_no' => $cardNo ?: '-',
'asset_detail' => $assetDetail ?: '-',
'status_text' => $withdraw['status_text'] ?? '-',
'createtime' => $createTime,
'updatetime' => $updateTime,
];
}
if ($pages['is_last_page']) {
$newDatas[] = [
'id' => '合计: 共 ' . $total . ' 条记录;提现总额:¥' . number_format((float)$totalAmount, 2, '.', '') . ';实际到账总额:¥' . number_format((float)$totalPaidFee, 2, '.', '') . ';手续费总额:¥' . number_format((float)$totalChargeFee, 2, '.', '')
];
}
return $newDatas;
});
$this->success('导出成功' . (isset($result['file_path']) && $result['file_path'] ? ',请在服务器: “' . $result['file_path'] . '” 查看' : ''), null, $result);
} catch (HttpResponseException $e) {
throw $e;
} catch (\Throwable $e) {
$this->error('导出处理失败: ' . $e->getMessage());
}
$export = new \addons\shopro\library\Export();
$params = [
'file_name' => '提现管理台账',
'cell_titles' => $cellTitles,
'total' => $total,
'is_sub_cell' => false,
];
$totalAmount = 0;
$totalPaidFee = 0;
$totalChargeFee = 0;
$result = $export->export($params, function ($pages) use (&$totalAmount, &$totalPaidFee, &$totalChargeFee, $total) {
$datas = $this->model->sheepFilter()->with(['user'])
->limit((($pages['page'] - 1) * $pages['list_rows']), $pages['list_rows'])
->select();
$newDatas = [];
foreach ($datas as $withdraw) {
$user = $withdraw['user'] ?? null;
$displayInfo = $withdraw['withdraw_info_display'] ?? ($withdraw['withdraw_info'] ?? []);
// 收款账户信息
$payeeName = $displayInfo['真实姓名'] ?? ($displayInfo['姓名'] ?? ($displayInfo['微信用户'] ?? ''));
$bankName = $displayInfo['开户行'] ?? ($displayInfo['开户银行'] ?? '');
$cardNo = $displayInfo['银行卡号'] ?? ($displayInfo['卡号'] ?? ($displayInfo['支付宝账户'] ?? ($displayInfo['支付宝账号'] ?? ($displayInfo['微信ID'] ?? ''))));
if ($cardNo !== '') {
$cardNo = "\t" . $cardNo;
}
// 提现资产类型
$assetType = $withdraw['is_madow_withdraw'] ? 'DMEPA' : ($withdraw['is_money_withdraw'] ? '商城余额' : ($displayInfo['提现资产'] ?? '商城余额'));
// 资产折算明细
$assetDetailParts = [];
if (!empty($displayInfo['扣除DMEPA'])) {
$assetDetailParts[] = '扣除: ' . $displayInfo['扣除DMEPA'];
}
if (!empty($displayInfo['市值汇率'])) {
$assetDetailParts[] = $displayInfo['市值汇率'];
}
if (!empty($displayInfo['换算市值'])) {
$assetDetailParts[] = '市值: ' . $displayInfo['换算市值'];
}
$assetDetail = implode('; ', $assetDetailParts);
$amount = floatval($withdraw['amount'] ?? 0);
$paidFee = floatval($withdraw['paid_fee'] ?? 0) > 0 ? floatval($withdraw['paid_fee']) : floatval($withdraw['real_amount'] ?? $amount);
$chargeFee = floatval($withdraw['charge_fee'] ?? 0);
$totalAmount = function_exists('bcadd') ? bcadd((string)$totalAmount, (string)$amount, 2) : ($totalAmount + $amount);
$totalPaidFee = function_exists('bcadd') ? bcadd((string)$totalPaidFee, (string)$paidFee, 2) : ($totalPaidFee + $paidFee);
$totalChargeFee = function_exists('bcadd') ? bcadd((string)$totalChargeFee, (string)$chargeFee, 2) : ($totalChargeFee + $chargeFee);
$newDatas[] = [
'id' => $withdraw['id'],
'withdraw_sn' => "\t" . (string)($withdraw['withdraw_sn'] ?? ''),
'user_nickname' => $user['nickname'] ?? ('用户 ' . $withdraw['user_id']),
'user_mobile' => "\t" . (string)($user['mobile'] ?? ''),
'asset_type' => $assetType,
'amount' => number_format($amount, 2, '.', ''),
'paid_fee' => number_format($paidFee, 2, '.', ''),
'charge_rate_format' => $withdraw['charge_rate_format'] ?? '0.0%',
'charge_fee' => number_format($chargeFee, 2, '.', ''),
'withdraw_type_text' => $withdraw['withdraw_type_text'] ?? '-',
'payee_name' => $payeeName ?: '-',
'bank_name' => $bankName ?: '-',
'card_no' => $cardNo ?: '-',
'asset_detail' => $assetDetail ?: '-',
'status_text' => $withdraw['status_text'] ?? '-',
'createtime' => $withdraw['createtime'] ?? '-',
'updatetime' => $withdraw['updatetime'] ?? '-',
];
}
if ($pages['is_last_page']) {
$newDatas[] = [
'id' => '合计: 共 ' . $total . ' 条记录',
'withdraw_sn' => '',
'user_nickname' => '',
'user_mobile' => '',
'asset_type' => '',
'amount' => number_format((float)$totalAmount, 2, '.', ''),
'paid_fee' => number_format((float)$totalPaidFee, 2, '.', ''),
'charge_rate_format' => '',
'charge_fee' => number_format((float)$totalChargeFee, 2, '.', ''),
'withdraw_type_text' => '',
'payee_name' => '',
'bank_name' => '',
'card_no' => '',
'asset_detail' => '',
'status_text' => '',
'createtime' => '',
'updatetime' => '',
];
}
return $newDatas;
});
return $result;
}