feat(partner): 完善马豆实时动态汇率与精度自适应,支持交易数据清理与汇率重置
这个提交包含在:
@@ -84,6 +84,11 @@ class IdentityService
|
||||
|
||||
public static function formatMadow($value)
|
||||
{
|
||||
$floatVal = (float) $value;
|
||||
// 当存在小于 1 豆且大于 0 的微量马豆时,自适应保留有效小数(最多4位),避免直接抹零显示为 0 豆
|
||||
if ($floatVal > 0 && $floatVal < 1) {
|
||||
return rtrim(rtrim(number_format($floatVal, 4, '.', ''), '0'), '.');
|
||||
}
|
||||
return number_format((float) $value, 0, '.', '');
|
||||
}
|
||||
|
||||
|
||||
@@ -104,10 +104,12 @@ class PartnerConfig
|
||||
'venue_share' => $venue . '加权奖励',
|
||||
'county_share' => $county . '加权奖励',
|
||||
'madow_share' => '每日贡献马豆',
|
||||
'admin_madow' => '管理员调整马豆',
|
||||
'voucher_grant' => '消费补贴发放',
|
||||
'voucher_release' => '消费补贴到账',
|
||||
'voucher_consume' => '消费券抵扣',
|
||||
'voucher_consume_refund' => '消费券退款退还',
|
||||
'admin_voucher' => '管理员调整兑换券',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -11,21 +11,33 @@ use app\admin\model\shopro\commission\CommissionGoods;
|
||||
*/
|
||||
class RateService
|
||||
{
|
||||
public function currentRate()
|
||||
/**
|
||||
* 获取大盘当前即时生效汇率(基于全网合格订单 N 实时动态计算,短缓存 120 秒保障高并发读性能)
|
||||
*
|
||||
* @param bool $forceRefresh 是否强制穿透缓存实时重算
|
||||
* @return float
|
||||
*/
|
||||
public function currentRate($forceRefresh = false)
|
||||
{
|
||||
$latest = RateLog::order('id', 'desc')->find();
|
||||
if ($latest && (float) $latest->rate > 0) {
|
||||
return (float) $latest->rate;
|
||||
}
|
||||
$cached = cache('partner_madow_current_rate');
|
||||
if ($cached !== null && $cached !== false && (float) $cached > 0) {
|
||||
return (float) $cached;
|
||||
if (!$forceRefresh) {
|
||||
$cached = cache('partner_madow_current_rate');
|
||||
if ($cached !== null && $cached !== false && (float) $cached > 0) {
|
||||
return (float) $cached;
|
||||
}
|
||||
}
|
||||
$rate = $this->calcRate($this->countN());
|
||||
cache('partner_madow_current_rate', $rate, 300);
|
||||
cache('partner_madow_current_rate', $rate, 120);
|
||||
return $rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动清除当前马豆汇率缓存(订单支付、退款或后台调整时调用)
|
||||
*/
|
||||
public static function clearCache()
|
||||
{
|
||||
cache('partner_madow_current_rate', null);
|
||||
}
|
||||
|
||||
public function calcRate($n = null)
|
||||
{
|
||||
$n = $n === null ? $this->countN() : intval($n);
|
||||
|
||||
在新工单中引用
屏蔽一个用户