文件
Henglianshutong/application/admin/controller/shopro/Config.php
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

579 行
27 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\admin\controller\shopro;
use app\admin\model\shopro\Config as ShoproConfig;
class Config extends Common
{
protected $noNeedRight = ['index', 'platformStatus', 'getPlatformUrl'];
public function index()
{
$configList = [
[
'label' => '基本信息',
'name' => 'shopro/config/basic',
'status' => $this->auth->check('shopro/config/basic')
],
[
'label' => '用户配置',
'name' => 'shopro/config/user',
'status' => $this->auth->check('shopro/config/user')
],
[
'label' => '平台配置',
'name' => 'shopro/config/platform',
'status' => $this->auth->check('shopro/config/platform')
],
[
'label' => '订单配置',
'name' => 'shopro/config/order',
'status' => $this->auth->check('shopro/config/order')
],
[
'label' => '商品配置',
'name' => 'shopro/config/goods',
'status' => $this->auth->check('shopro/config/goods')
],
[
'label' => '物流配置',
'name' => 'shopro/config/dispatch',
'status' => $this->auth->check('shopro/config/dispatch')
],
[
'label' => '充值提现',
'name' => 'shopro/config/rechargewithdraw',
'status' => $this->auth->check('shopro/config/rechargewithdraw')
],
[
'label' => '分销基础',
'name' => 'shopro/config/commission',
'status' => $this->auth->check('shopro/config/commission')
],
[
'label' => '收益中心规则',
'name' => 'shopro/config/partner',
'status' => $this->auth->check('shopro/config/commission')
],
[
'label' => '支付配置',
'name' => 'shopro/pay_config',
'status' => $this->auth->check('shopro/pay_config')
],
[
'label' => '客服配置',
'name' => 'shopro/config/chat',
'status' => $this->auth->check('shopro/config/chat')
],
[
'label' => 'Redis配置',
'name' => 'shopro/config/redis',
'status' => $this->auth->check('shopro/config/redis')
]
];
$this->assignconfig("configList", $configList);
return $this->view->fetch();
}
/**
* 基本配置
*/
public function basic()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.basic', false);
} elseif ('POST' === $this->request->method()) {
$configs = ShoproConfig::setConfigs('shop.basic', $this->request->param());
}
$this->success('操作成功', null, $configs);
}
/**
* 用户默认配置
*/
public function user()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.user', false);
} elseif ('POST' === $this->request->method()) {
$configs = ShoproConfig::setConfigs('shop.user', $this->request->param());
}
$this->success('操作成功', null, $configs);
}
/**
* 物流配置
*/
public function dispatch()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.dispatch', false);
$configs['callback'] = $this->request->domain() . '/addons/shopro/order.express/push';
} elseif ('POST' === $this->request->method()) {
$configs = ShoproConfig::setConfigs('shop.dispatch', $this->request->param());
}
$this->success('操作成功', null, $configs);
}
/**
* 平台状态
*/
public function platformStatus()
{
$status = [
'H5' => ShoproConfig::getConfigs('shop.platform.H5.status', false),
'App' => ShoproConfig::getConfigs('shop.platform.App.status', false),
'WechatMiniProgram' => ShoproConfig::getConfigs('shop.platform.WechatMiniProgram.status', false),
'WechatOfficialAccount' => ShoproConfig::getConfigs('shop.platform.WechatOfficialAccount.status', false),
];
$this->success('操作成功', null, $status);
}
/**
* 平台配置
*/
public function platform($platform)
{
if (!$this->request->isAjax()) {
return $this->view->fetch();
}
if (!in_array($platform, ['App', 'H5', 'WechatMiniProgram', 'WechatOfficialAccount'])) {
$this->error('平台不支持');
}
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.platform.' . $platform, false);
} elseif ('POST' === $this->request->method()) {
$params = $this->request->param();
if (!isset($params['share']['methods'])) {
$params['share']['methods'] = [];
}
if (!isset($params['payment']['methods'])) {
$params['payment']['methods'] = [];
}
$configs = ShoproConfig::setConfigs('shop.platform.' . $platform, $params);
}
$this->success('操作成功', null, $configs);
}
public function commission()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.commission', false);
} elseif ('POST' === $this->request->method()) {
check_env('commission');
$params = $this->request->param();
$configs = ShoproConfig::setConfigs('shop.commission', $params);
}
$this->success('操作成功', null, $configs);
}
/**
* 收益中心规则
*/
public function partner()
{
$keys = [
'partner_mode', 'partner_enable', 'partner_count_type', 'partner_active_days',
'partner_chain_max_depth', 'partner_push3_amounts', 'partner_madow_mode',
'partner_show_madow_rate',
'partner_madow_base_rate', 'partner_madow_step_orders',
'partner_madow_rule_title', 'partner_madow_rules',
'partner_madow_withdraw_enable', 'partner_madow_withdraw_min', 'partner_madow_withdraw_charge_rate',
'partner_voucher_times', 'partner_voucher_days',
'partner_voucher_rule_title', 'partner_voucher_rules',
'partner_maker_bonus', 'partner_maker_peer_rate',
'partner_maker_overtaken_rate', 'partner_team_total', 'partner_venue_split',
'partner_county_full', 'partner_venue_share_per_order', 'partner_county_share_per_order',
'partner_venue_peer_rate', 'partner_county_peer_rate',
'partner_role_name_taster', 'partner_role_name_maker', 'partner_role_name_venue',
'partner_role_name_county', 'partner_role_name_partner',
];
$ruleDefaults = [
'partner_madow_rule_title' => '市值与增值规则',
'partner_madow_rules' => [
['title' => 'dmepa获取与核算', 'desc' => '平台合伙人与创客达成考核或完成订单后,系统将于次日 00:30 起统一参与每日dmepa加权核算并自动分发。'],
['title' => '市值动态增值', 'desc' => '市值随全平台订单增加而上浮增值。全网完成订单总量越多,dmepa单价所对应的市值越高,共享生态红利。'],
['title' => '价值说明与权益', 'desc' => '市值仅作为平台数字生态资产价值参考展示,不可直接兑换现金提现。具体权益按平台股东与合伙人章程执行。'],
],
'partner_voucher_rule_title' => '兑换券释放与使用规则',
'partner_voucher_rules' => [
['title' => '赠送与释放天数', 'desc' => '会员在平台完成符合条件的商城订单后,系统将按订单金额(默认 1.5 倍)生成兑换券计划,分 365 天按日线性释放。'],
['title' => '每日自动到账', 'desc' => '系统将于次日 00:30 起统一执行日结核算,按期释放的兑换券将自动计入您的「可用兑换券」账户,无需手动领取。'],
['title' => '全场购物直接抵扣', 'desc' => '可用兑换券可在平台商城下单结算时作为现金抵扣使用,尊享优惠抵扣权益。'],
],
];
if ('GET' === $this->request->method()) {
$all = ShoproConfig::getConfigs('shop.commission', false) ?: [];
$configs = [];
foreach ($keys as $key) {
$configs[$key] = $all[$key] ?? null;
}
$defaults = array_merge([
'partner_mode' => 1,
'partner_enable' => 1,
'partner_count_type' => 'order',
'partner_active_days' => 30,
'partner_chain_max_depth' => 50,
'partner_push3_amounts' => [398, 400, 600],
'partner_madow_mode' => 'madow',
'partner_show_madow_rate' => 1,
'partner_madow_withdraw_enable' => 1,
'partner_madow_withdraw_min' => 1,
'partner_madow_withdraw_charge_rate' => 0,
'partner_madow_base_rate' => '0.00000075',
'partner_madow_step_orders' => 1,
'partner_voucher_times' => 1.5,
'partner_voucher_days' => 365,
'partner_maker_bonus' => ['2' => 20, '3' => 40, '4' => 60, '5' => 80, '6' => 100, '7' => 120],
'partner_maker_peer_rate' => 0.10,
'partner_maker_overtaken_rate' => 0.05,
'partner_team_total' => 100,
'partner_venue_split' => 50,
'partner_county_full' => 100,
'partner_venue_share_per_order' => 100,
'partner_county_share_per_order' => 50,
'partner_venue_peer_rate' => 0.10,
'partner_county_peer_rate' => 0.10,
'partner_role_name_taster' => '品酒师',
'partner_role_name_maker' => '创客',
'partner_role_name_venue' => '酒道馆',
'partner_role_name_county' => '区县代理',
'partner_role_name_partner' => '合伙股东',
], $ruleDefaults);
foreach ($defaults as $key => $value) {
if ($configs[$key] === null || $configs[$key] === '') {
$configs[$key] = $value;
}
}
$configs['partner_show_madow_rate'] = isset($configs['partner_show_madow_rate']) ? intval($configs['partner_show_madow_rate']) : 1;
$configs['partner_madow_withdraw_enable'] = isset($configs['partner_madow_withdraw_enable']) ? intval($configs['partner_madow_withdraw_enable']) : 1;
$configs['partner_madow_withdraw_min'] = isset($configs['partner_madow_withdraw_min']) ? floatval($configs['partner_madow_withdraw_min']) : 1.0;
$configs['partner_madow_withdraw_charge_rate'] = isset($configs['partner_madow_withdraw_charge_rate']) ? floatval($configs['partner_madow_withdraw_charge_rate']) : 0.0;
foreach (['partner_madow_rules', 'partner_voucher_rules'] as $ruleKey) {
if (isset($configs[$ruleKey]) && is_string($configs[$ruleKey])) {
$decoded = json_decode($configs[$ruleKey], true);
if (is_array($decoded)) {
$configs[$ruleKey] = $decoded;
}
}
}
} elseif ('POST' === $this->request->method()) {
check_env('commission');
$params = $this->request->param();
$save = [];
foreach ($keys as $key) {
if (array_key_exists($key, $params)) {
$save[$key] = $params[$key];
}
}
if (isset($save['partner_show_madow_rate'])) {
$save['partner_show_madow_rate'] = intval($save['partner_show_madow_rate']);
}
if (isset($save['partner_madow_withdraw_enable'])) {
$save['partner_madow_withdraw_enable'] = intval($save['partner_madow_withdraw_enable']);
}
if (isset($save['partner_madow_withdraw_min'])) {
$save['partner_madow_withdraw_min'] = max(0.0, floatval($save['partner_madow_withdraw_min']));
}
if (isset($save['partner_madow_withdraw_charge_rate'])) {
$save['partner_madow_withdraw_charge_rate'] = max(0.0, floatval($save['partner_madow_withdraw_charge_rate']));
}
// 确保数据库存在 partner_show_madow_rate 配置行
$existConfig = ShoproConfig::where('code', 'shop.commission.partner_show_madow_rate')->find();
if (!$existConfig) {
ShoproConfig::create([
'code' => 'shop.commission.partner_show_madow_rate',
'parent_code' => 'shop.commission',
'name' => '显示马币市值',
'description' => '1=显示 0=隐藏',
'type' => 'int',
'value' => '1',
'weigh' => 86
]);
}
// 确保数据库存在规则条目等必要配置行
$ensureConfigs = [
'shop.commission.partner_madow_withdraw_enable' => ['name' => '开启dmepa提现', 'desc' => '1=开启 0=关闭', 'type' => 'int', 'value' => '1', 'weigh' => 86],
'shop.commission.partner_madow_withdraw_min' => ['name' => 'dmepa最低提现金额', 'desc' => 'dmepa最低提现金额(元)', 'type' => 'number', 'value' => '1', 'weigh' => 86],
'shop.commission.partner_madow_withdraw_charge_rate' => ['name' => 'dmepa提现手续费率', 'desc' => 'dmepa提现手续费率(%)', 'type' => 'number', 'value' => '0', 'weigh' => 86],
'shop.commission.partner_madow_rule_title' => ['name' => 'dmepa规则弹窗标题', 'desc' => '我的dmepa市值规则弹窗标题', 'type' => 'string', 'value' => '市值与增值规则', 'weigh' => 86],
'shop.commission.partner_madow_rules' => ['name' => 'dmepa规则说明条目', 'desc' => '我的dmepa市值规则条目', 'type' => 'array', 'value' => json_encode($ruleDefaults['partner_madow_rules'], JSON_UNESCAPED_UNICODE), 'weigh' => 86],
'shop.commission.partner_voucher_rule_title' => ['name' => '兑换券规则弹窗标题', 'desc' => '兑换券规则弹窗标题', 'type' => 'string', 'value' => '兑换券释放与使用规则', 'weigh' => 89],
'shop.commission.partner_voucher_rules' => ['name' => '兑换券规则说明条目', 'desc' => '兑换券规则条目', 'type' => 'array', 'value' => json_encode($ruleDefaults['partner_voucher_rules'], JSON_UNESCAPED_UNICODE), 'weigh' => 89],
];
foreach ($ensureConfigs as $confCode => $confMeta) {
$existConfig = ShoproConfig::where('code', $confCode)->find();
if (!$existConfig) {
ShoproConfig::create([
'code' => $confCode,
'parent_code' => 'shop.commission',
'name' => $confMeta['name'],
'description' => $confMeta['desc'],
'type' => $confMeta['type'],
'value' => $confMeta['value'],
'weigh' => $confMeta['weigh'],
]);
}
}
foreach (['partner_role_name_taster', 'partner_role_name_maker', 'partner_role_name_venue', 'partner_role_name_county', 'partner_role_name_partner'] as $roleKey) {
if (isset($save[$roleKey])) {
$save[$roleKey] = trim((string) $save[$roleKey]);
}
}
if (isset($save['partner_active_days']) && intval($save['partner_active_days']) < 1) {
$this->error('领取窗口天数须 ≥ 1');
}
if (!empty($save['partner_maker_bonus']) && is_array($save['partner_maker_bonus'])) {
$prev = null;
foreach ([2, 3, 4, 5, 6, 7] as $lv) {
$val = isset($save['partner_maker_bonus'][$lv])
? (float) $save['partner_maker_bonus'][$lv]
: (isset($save['partner_maker_bonus'][(string) $lv]) ? (float) $save['partner_maker_bonus'][(string) $lv] : null);
if ($val === null) {
continue;
}
if ($prev !== null && $val < $prev) {
$makerName = !empty($save['partner_role_name_maker']) ? $save['partner_role_name_maker'] : '创客';
$this->error($makerName . ' V1–V6 单笔基数必须递增');
}
$prev = $val;
}
}
if (isset($save['partner_team_total'], $save['partner_venue_split'])
&& (float) $save['partner_venue_split'] > (float) $save['partner_team_total']) {
$venueName = !empty($save['partner_role_name_venue']) ? $save['partner_role_name_venue'] : '酒道馆';
$this->error($venueName . '管理奖不能大于团队管理奖总预算');
}
$configs = ShoproConfig::setConfigs('shop.commission', $save);
$this->success('规则已更新,仅对之后的新订单生效。', null, $configs);
return;
}
$this->success('操作成功', null, $configs);
}
/**
* 订单配置
*/
public function order()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.order', false);
} elseif ('POST' === $this->request->method()) {
$configs = ShoproConfig::setConfigs('shop.order', $this->request->param());
}
$this->success('操作成功', null, $configs);
}
/**
* 商品配置
*/
public function goods()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.goods', false);
} elseif ('POST' === $this->request->method()) {
$configs = ShoproConfig::setConfigs('shop.goods', $this->request->param());
}
$this->success('操作成功', null, $configs);
}
/**
* 充值提现配置
*/
public function rechargeWithdraw()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('shop.recharge_withdraw', false);
if ($configs && isset($configs['withdraw'])) {
if (!isset($configs['withdraw']['status'])) {
$configs['withdraw']['status'] = !empty($configs['withdraw']['methods']) ? 1 : 0;
} else {
$configs['withdraw']['status'] = intval($configs['withdraw']['status']);
}
// 读取 DMEPA 专属提现配置(优先提现配置,降级兼容合伙股东历史配置)
$partnerEnable = ShoproConfig::getConfigField('shop.commission.partner_madow_withdraw_enable', false);
$partnerMin = ShoproConfig::getConfigField('shop.commission.partner_madow_withdraw_min', false);
$partnerChargeRate = ShoproConfig::getConfigField('shop.commission.partner_madow_withdraw_charge_rate', false);
if (!isset($configs['withdraw']['madow_withdraw_enable']) || $configs['withdraw']['madow_withdraw_enable'] === '') {
$configs['withdraw']['madow_withdraw_enable'] = ($partnerEnable !== null && $partnerEnable !== '') ? intval($partnerEnable) : 1;
} else {
$configs['withdraw']['madow_withdraw_enable'] = intval($configs['withdraw']['madow_withdraw_enable']);
}
if (!isset($configs['withdraw']['madow_min_amount']) || $configs['withdraw']['madow_min_amount'] === '') {
$configs['withdraw']['madow_min_amount'] = ($partnerMin !== null && $partnerMin !== '') ? floatval($partnerMin) : 1.0;
} else {
$configs['withdraw']['madow_min_amount'] = floatval($configs['withdraw']['madow_min_amount']);
}
if (!isset($configs['withdraw']['madow_charge_rate']) || $configs['withdraw']['madow_charge_rate'] === '') {
$configs['withdraw']['madow_charge_rate'] = ($partnerChargeRate !== null && $partnerChargeRate !== '') ? floatval($partnerChargeRate) : 0.0;
} else {
$configs['withdraw']['madow_charge_rate'] = floatval($configs['withdraw']['madow_charge_rate']);
}
}
} elseif ('POST' === $this->request->method()) {
$params = $this->request->param();
if (!isset($params['recharge']['methods'])) {
$params['recharge']['methods'] = [];
}
if (!isset($params['recharge']['quick_amounts'])) {
$params['recharge']['quick_amounts'] = [];
}
if (!isset($params['withdraw']['methods'])) {
$params['withdraw']['methods'] = [];
}
if (!isset($params['withdraw']['status'])) {
$params['withdraw']['status'] = 0;
} else {
$params['withdraw']['status'] = intval($params['withdraw']['status']);
}
if (isset($params['withdraw'])) {
if (isset($params['withdraw']['madow_withdraw_enable'])) {
$params['withdraw']['madow_withdraw_enable'] = intval($params['withdraw']['madow_withdraw_enable']);
}
if (isset($params['withdraw']['madow_charge_rate'])) {
$params['withdraw']['madow_charge_rate'] = max(0.0, floatval($params['withdraw']['madow_charge_rate']));
}
if (isset($params['withdraw']['madow_min_amount'])) {
$params['withdraw']['madow_min_amount'] = max(0.0, floatval($params['withdraw']['madow_min_amount']));
}
}
$configs = ShoproConfig::setConfigs('shop.recharge_withdraw', $params);
// 双向同步合伙股东配置项,确保老服务读取与全链路向后兼容
if (isset($params['withdraw']['madow_withdraw_enable'])) {
ShoproConfig::setConfigs('shop.commission', [
'partner_madow_withdraw_enable' => $params['withdraw']['madow_withdraw_enable']
]);
}
if (isset($params['withdraw']['madow_charge_rate'])) {
ShoproConfig::setConfigs('shop.commission', [
'partner_madow_withdraw_charge_rate' => $params['withdraw']['madow_charge_rate']
]);
}
if (isset($params['withdraw']['madow_min_amount'])) {
ShoproConfig::setConfigs('shop.commission', [
'partner_madow_withdraw_min' => $params['withdraw']['madow_min_amount']
]);
}
if ($configs && isset($configs['withdraw'])) {
$configs['withdraw']['status'] = isset($configs['withdraw']['status']) ? intval($configs['withdraw']['status']) : (!empty($configs['withdraw']['methods']) ? 1 : 0);
}
}
$this->success('操作成功', null, $configs);
}
/**
* 客服配置
*/
public function chat()
{
if ('GET' === $this->request->method()) {
$configs = ShoproConfig::getConfigs('chat', false);
} elseif ('POST' === $this->request->method()) {
$configs = ShoproConfig::setConfigs('chat', $this->request->param());
// 存文件
file_put_contents(
ROOT_PATH . 'application' . DS . 'extra' . DS . 'chat.php',
'<?php' . "\n\nreturn " . short_var_export($this->request->param(), true) . ";"
);
}
$this->success('操作成功', null, $configs);
}
/**
* redis 配置
*/
public function redis()
{
if ('GET' === $this->request->method()) {
$default = [
'host' => '127.0.0.1', // redis 主机地址
'password' => '', // redis 密码
'port' => 6379, // redis 端口
'select' => 1, // redis 数据库
'timeout' => 0, // redis 超时时间
'persistent' => false, // redis 持续性,连接复用
];
$redis = \think\Config::get('redis');
$redis['empty_password'] = 0;
$redis['password'] = ''; // 隐藏密码
$configs = $redis ? array_merge($default, $redis) : $default;
} elseif ('POST' === $this->request->method()) {
operate_filter();
$configs = $this->request->param();
$empty_password = (int)$configs['empty_password']; // 是否设置空密码
unset($configs['empty_password']);
if (isset($configs['password']) && empty($configs['password'])) {
$redis = \think\Config::get('redis');
// 不修改密码,保持为原始值
$configs['password'] = $redis['password'] ?? '';
} elseif ($empty_password) {
$configs['password'] = '';
}
$configs['persistent'] = (isset($configs['persistent']) && ($configs['persistent'] === true || $configs['persistent'] == 'true')) ? true : false;
// 存文件
file_put_contents(
ROOT_PATH . 'application' . DS . 'extra' . DS . 'redis.php',
'<?php' . "\n\nreturn " . short_var_export($configs, true) . ";"
);
}
$this->success('操作成功', null, $configs);
}
public function getPlatformUrl()
{
$h5Url = ShoproConfig::getConfigField('shop.basic.domain');
$wechatMpAppid = ShoproConfig::getConfigField('shop.platform.WechatMiniProgram.app_id');
$this->success('', null, [
'url' => $h5Url,
'appid' => $wechatMpAppid
]);
}
}