文件
chen a2220427e2 feat(withdraw): DMEPA提现手续费与最小提现额度配置收敛至商城配置页面并实现内扣闭环
1. 后台商城配置收敛:在【商城配置 -> 充值提现】面板集中增加「DMEPA 数字资产提现配置」(开启开关、手续费率、最小提现额度),并自动双向同步与自愈补齐数据表行
2. 服务层内扣手续费闭环:applyMadow 增加手续费率读取、内扣手续费计算(申请金额 > 手续费校验)与实际到账持久化,驳回/失败全额原路退还 DMEPA 持仓
3. API 与前台联动:rules() 与 madow() 接口返回手续费率,withdraw.vue 实时动态计算扣除 DMEPA 枚数、手续费内扣金额与预计到账金额
4. 后台列表与导出优化:提现管理列表与导出功能支持展示换算市值、手续费与到账金额
5. 新增及更新 3 套自动化规格测试(累计 130 项断言全部通过)
2026-09-21 14:33:20 +08:00

179 行
5.6 KiB
PHP

<?php
namespace addons\shopro\controller;
use think\Db;
use think\exception\HttpResponseException;
use app\admin\model\shopro\Withdraw as WithdrawModel;
use addons\shopro\service\Withdraw as WithdrawService;
class Withdraw extends Common
{
protected $noNeedLogin = [];
protected $noNeedRight = ['*'];
public function index()
{
$user = auth_user();
$withdraws = WithdrawModel::where(['user_id' => $user->id])->order('id desc')->paginate($this->request->param('list_rows', 10))->each(function ($withdraw) {
$withdraw->hidden(['withdraw_info']);
});
$this->success('获取成功', $withdraws);
}
// 提现规则
public function rules()
{
$user = auth_user();
$config = (new WithdrawService($user))->config;
$config['madow_withdraw_enable'] = \addons\shopro\service\partner\PartnerConfig::isMadowWithdrawEnabled() ? 1 : 0;
$config['madow_min_amount'] = \addons\shopro\service\partner\PartnerConfig::madowWithdrawMin();
$config['madow_charge_rate'] = \addons\shopro\service\partner\PartnerConfig::madowWithdrawChargeRate();
$this->success('提现规则', $config);
}
// 发起提现请求
public function apply()
{
if (!$this->request->isPost()) {
$this->error('');
}
$this->repeatFilter('addons/shopro/withdraw');
$user = auth_user();
$params = $this->request->param();
$this->svalidate($params, ".apply");
$withdrawService = new WithdrawService($user);
// 申请提现
Db::startTrans();
try {
$withdraw = $withdrawService->apply($params);
Db::commit();
} catch (HttpResponseException $e) {
$data = $e->getResponse()->getData();
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
$this->error($message);
} catch (\Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
// 微信新版本商家转账
if ($withdraw->withdraw_type === 'wechat') {
try {
$transferData = $withdrawService->handleWechatTransfer($withdraw);
} catch (HttpResponseException $e) {
$data = $e->getResponse()->getData();
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
$this->error($message);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
// 支付宝提现+自动打款
if ($withdraw->withdraw_type === 'alipay' && $withdrawService->config['auto_arrival']) {
try {
// 记录提现日志
$withdrawService->handleAlipayWithdraw($withdraw);
} catch (HttpResponseException $e) {
$data = $e->getResponse()->getData();
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
$this->error($message);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
$this->success('申请成功', [
'id' => $withdraw->id,
'type' => $withdraw->withdraw_type,
'withdraw_sn' => $withdraw->withdraw_sn,
'transfer_data' => $transferData ?? null,
]);
}
// 继续提现(仅支持微信商家转账)
public function transfer()
{
if (!$this->request->isPost()) {
$this->error('');
}
$this->repeatFilter('addons/shopro/withdraw');
$user = auth_user();
$params = $this->request->param();
$this->svalidate($params, ".transfer");
$withdrawService = new WithdrawService($user);
// 如果 微信提现, result 为 package_info,其他的为 withdrawModel 对象
$result = $withdrawService->retry($params);
$this->success('操作成功', $result);
}
// 取消提现(仅支持微信商家转账)
public function cancel()
{
if (!$this->request->isPost()) {
$this->error('');
}
$this->repeatFilter('addons/shopro/withdraw');
$user = auth_user();
$params = $this->request->param();
$this->svalidate($params, ".cancel");
$withdrawService = new WithdrawService($user);
try {
$result = $withdrawService->cancel($params);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
$this->success('操作成功', $result);
}
// 取消提现(仅支持微信商家转账)
public function retry()
{
if (!$this->request->isPost()) {
$this->error('');
}
$this->repeatFilter('addons/shopro/withdraw');
$user = auth_user();
$params = $this->request->param();
$this->svalidate($params, ".retry");
$withdrawService = new WithdrawService($user);
try {
$withdraw = $withdrawService->retry($params);
$transferData = $withdrawService->handleWechatTransfer($withdraw);
} catch (\Exception $e) {
$this->error($e->getMessage());
}
$this->success('申请成功', [
'id' => $withdraw->id,
'type' => $withdraw->withdraw_type,
'withdraw_sn' => $withdraw->withdraw_sn,
'transfer_data' => $transferData ?? null,
]);
}
}