URS转账手续费配置模块提供基于用户房屋等级和达人等级的差异化转账手续费管理。通过灵活的配置规则,实现转入和转出操作的精细化费率控制,既能鼓励用户充值,又能合理控制资金流出。
| 字段名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| id | bigint | - | 主键ID |
| house_level | int | 0 | 房屋等级(0表示所有等级) |
| talent_level | int | 0 | 达人等级(0表示所有等级) |
| transfer_type | enum('in','out') | 'out' | 转账类型 |
| fee_rate | decimal(8,4) | 0.0500 | 手续费率(0-1之间) |
| description | varchar(255) | - | 配置描述 |
| priority | int | 0 | 优先级(数值越大优先级越高) |
| status | tinyint | 1 | 状态:1启用,0禁用 |
| created_at | timestamp | CURRENT_TIMESTAMP | 创建时间 |
| updated_at | timestamp | CURRENT_TIMESTAMP | 更新时间 |
-- 主键索引
PRIMARY KEY (id)
-- 单字段索引
KEY idx_house_level (house_level)
KEY idx_talent_level (talent_level)
KEY idx_priority (priority)
KEY idx_status (status)
-- 复合索引
KEY idx_house_talent_status (house_level, talent_level, status)
KEY idx_type_house_talent_status (transfer_type, house_level, talent_level, status)
配置按以下优先级顺序匹配:
1. 查询所有启用状态的配置
2. 筛选匹配转账类型的配置
3. 筛选匹配房屋等级的配置(精确匹配或等级0)
4. 筛选匹配达人等级的配置(精确匹配或等级0)
5. 按优先级降序排序
6. 返回第一个匹配的配置
/**
* 根据用户ID获取最优手续费率
* @param int $userId 农场用户ID
* @param string $transferType 转账类型:'in'转入,'out'转出
* @return float 手续费率
*/
public static function getBestFeeRateForUser(int $userId, string $transferType = 'out'): float
/**
* 根据房屋等级和达人等级计算最优手续费率
* @param int $houseLevel 房屋等级
* @param int $talentLevel 达人等级
* @param string $transferType 转账类型
* @return float 手续费率
*/
public static function calculateBestFeeRate(int $houseLevel, int $talentLevel, string $transferType = 'out'): float
use App\Module\UrsPromotion\Services\UrsTransferFeeService;
// 获取用户转出费率
$userId = 10001;
$transferOutRate = UrsTransferFeeService::getBestFeeRateForUser($userId, 'out');
echo "用户转出费率: " . ($transferOutRate * 100) . "%";
// 获取用户转入费率
$transferInRate = UrsTransferFeeService::getBestFeeRateForUser($userId, 'in');
echo "用户转入费率: " . ($transferInRate * 100) . "%";
// 房屋7级,达人3级用户的转出费率
$feeRate = UrsTransferFeeService::calculateBestFeeRate(7, 3, 'out');
echo "费率: " . ($feeRate * 100) . "%";
// 转账业务逻辑中
$amount = 1000; // 转账金额
$feeRate = UrsTransferFeeService::getBestFeeRateForUser($userId, 'out');
$feeAmount = $amount * $feeRate;
$actualAmount = $amount - $feeAmount;
echo "转账金额: {$amount}";
echo "手续费: {$feeAmount}";
echo "实际到账: {$actualAmount}";
系统通过事件监听器自动应用最优费率:
// 监听用户等级变化事件
class UrsTransferFeeListener
{
public function handle($event)
{
// 清除用户费率缓存
// 重新计算最优费率
// 记录费率变化日志
}
}