文件
Henglianshutong/application/admin/model/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

248 行
7.5 KiB
PHP

<?php
namespace app\admin\model\shopro;
class Config extends Common
{
/**
* 主键
*/
protected $pk = 'code';
protected $name = 'shopro_config';
protected $autoWriteTimestamp = false;
/**
* 获取配置组
*
* @param string $code
* @param boolean $cache
* @return array
*/
public static function getConfigs($code, $cache = true)
{
// 从缓存中获取
if ($cache) {
$config = operate_disabled(false) ? cache("config:{$code}") : null;
if (empty($config)) {
$config = self::getConfigs($code, false);
}
}
// 从数据库中查找
if (!$cache) {
$row = self::where('code', $code)->find();
if(!$row) return null;
if($row['type'] !== 'group') {
$config = $row->value;
}else {
$config = [];
$list = self::where('parent_code', $code)->select();
foreach ($list as &$row) {
if ($row['type'] === 'group') {
$row->value = self::getConfigs($row->code, false);
} else {
cache("config:{$row->code}", $row->value);
}
$config[self::getShortCode($row)] = $row->value;
}
if ($code === 'shop.recharge_withdraw.withdraw' && !isset($config['status'])) {
$config['status'] = !empty($config['methods']) ? 1 : 0;
}
}
// 设置配置缓存
cache("config:{$code}", $config);
}
return $config;
}
/**
* 获取单一配置项
*
* @param string $code
* @param boolean $cache
* @return mixed
*/
public static function getConfigField($code, $cache = true)
{
// 从缓存中获取
if ($cache) {
$config = cache("config:{$code}");
if (empty($config)) {
$config = self::getConfigField($code, false);
}
}
// 从数据库中查找
if (!$cache) {
$config = self::where('code', $code)->value('value');
// 设置配置缓存
cache("config:{$code}", $config);
}
return $config;
}
private static function getShortCode($config)
{
if (!empty($config['parent_code'])) {
return str_replace("{$config['parent_code']}.", "", $config['code']);
}
return $config['code'];
}
/**
* 更新配置
*
* @param string $code
* @param array $configParams
* @return void
*/
public static function setConfigs(string $code, array $configParams)
{
operate_filter();
foreach ($configParams as $configKey => $configValue) {
self::setConfigField($code . '.' . $configKey, $configValue);
}
self::getConfigs(explode('.', $code)[0], false);
return self::getConfigs($code);
}
/**
* 更新配置项
*/
private static function setConfigField($code, $value)
{
$config = self::where('code', $code)->find();
if ($config) {
if ($config['type'] === 'group') {
foreach ($value as $k => $v) {
self::setConfigField($code . '.' . $k, $v);
}
} else {
$config->value = $value;
$config->save();
}
} else {
// 自动补齐缺失的提现配置项,确保热更新无缝落地
if ($code === 'shop.recharge_withdraw.withdraw.status') {
self::create([
'code' => $code,
'parent_code' => 'shop.recharge_withdraw.withdraw',
'name' => '开启提现',
'type' => 'boolean',
'value' => (string)intval($value),
'rule' => 'required',
'weigh' => 50
]);
} elseif ($code === 'shop.recharge_withdraw.withdraw.madow_withdraw_enable') {
self::create([
'code' => $code,
'parent_code' => 'shop.recharge_withdraw.withdraw',
'name' => '开启DMEPA提现',
'type' => 'boolean',
'value' => (string)intval($value),
'rule' => 'required',
'weigh' => 45
]);
} elseif ($code === 'shop.recharge_withdraw.withdraw.madow_charge_rate') {
self::create([
'code' => $code,
'parent_code' => 'shop.recharge_withdraw.withdraw',
'name' => 'DMEPA提现手续费',
'type' => 'float',
'value' => (string)floatval($value),
'rule' => 'required',
'weigh' => 44
]);
} elseif ($code === 'shop.recharge_withdraw.withdraw.madow_min_amount') {
self::create([
'code' => $code,
'parent_code' => 'shop.recharge_withdraw.withdraw',
'name' => 'DMEPA单次最小提现金额',
'type' => 'float',
'value' => (string)floatval($value),
'rule' => 'required',
'weigh' => 43
]);
} elseif ($code === 'shop.commission.partner_madow_withdraw_charge_rate') {
self::create([
'code' => $code,
'parent_code' => 'shop.commission',
'name' => 'DMEPA提现手续费率',
'type' => 'number',
'value' => (string)floatval($value),
'weigh' => 85
]);
}
}
}
/**
* 修改器 数据的保存格式
*
* @param string|array $value
* @param array $data
* @return string
*/
public function setValueAttr($value, $data)
{
switch ($data['type']) {
case 'array':
$value = is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
break;
}
return $value;
}
/**
* 获取器,选项
*
* @param string|array $value
* @param array $data
* @return array
*/
public function getStoreRangeAttr($value, $data)
{
return $this->attrFormatJson($value, $data, 'store_range');
}
/**
* 获取器,返回的格式
*
* @param string|array $value
* @param array $data
* @return array
*/
public function getValueAttr($value, $data)
{
$value = $value ?: ($data['value'] ?? null);
switch ($data['type']) {
case 'array':
$value = $this->attrFormatJson($value, $data, 'value', true);
break;
case 'boolean':
$value = intval($value) ? 1 : 0;
break;
case 'int':
$value = intval($value);
break;
case 'float':
$value = floatval($value);
break;
}
return config_show($value, $data);
}
}