优化分红方式
This commit is contained in:
@@ -90,18 +90,6 @@ class Group extends Backend
|
||||
if ($inheritRes !== null) {
|
||||
return $inheritRes;
|
||||
}
|
||||
$shouldHandleCommissionRate = true;
|
||||
if ($shouldHandleCommissionRate) {
|
||||
if (!$this->isValidCommissionRate($data['commission_rate'] ?? null)) {
|
||||
return $this->error(__('Please enter the correct field', ['commission_rate']));
|
||||
}
|
||||
if ($pidInt !== 0) {
|
||||
$commissionRes = $this->validateSiblingCommissionRate($pidInt, floatval((string)$data['commission_rate']));
|
||||
if ($commissionRes !== null) return $commissionRes;
|
||||
}
|
||||
} else {
|
||||
$data['commission_rate'] = 0;
|
||||
}
|
||||
$rulesRes = $this->handleRules($data);
|
||||
if ($rulesRes instanceof Response) return $rulesRes;
|
||||
|
||||
@@ -173,18 +161,6 @@ class Group extends Backend
|
||||
if ($inheritRes !== null) {
|
||||
return $inheritRes;
|
||||
}
|
||||
$shouldHandleCommissionRate = true;
|
||||
if ($shouldHandleCommissionRate) {
|
||||
if (!$this->isValidCommissionRate($data['commission_rate'] ?? null)) {
|
||||
return $this->error(__('Please enter the correct field', ['commission_rate']));
|
||||
}
|
||||
if ($pidInt !== 0) {
|
||||
$commissionRes = $this->validateSiblingCommissionRate($pidInt, floatval((string)$data['commission_rate']), intval((string)$row['id']));
|
||||
if ($commissionRes !== null) return $commissionRes;
|
||||
}
|
||||
} else {
|
||||
$data['commission_rate'] = 0;
|
||||
}
|
||||
$rulesRes = $this->handleRules($data);
|
||||
if ($rulesRes instanceof Response) return $rulesRes;
|
||||
|
||||
@@ -443,33 +419,6 @@ class Group extends Backend
|
||||
return array_values(array_unique(array_merge($own, $children)));
|
||||
}
|
||||
|
||||
private function isValidCommissionRate(mixed $value): bool
|
||||
{
|
||||
if ($value === null || $value === '') {
|
||||
return false;
|
||||
}
|
||||
$rate = trim((string)$value);
|
||||
if (!preg_match('/^(100(\.00?)?|[0-9]{1,2}(\.[0-9]{1,2})?)$/', $rate)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function validateSiblingCommissionRate(int $pid, float $currentRate, ?int $excludeId = null): ?Response
|
||||
{
|
||||
$query = Db::name('admin_group')->where('pid', $pid);
|
||||
if ($excludeId !== null) {
|
||||
$query = $query->where('id', '<>', $excludeId);
|
||||
}
|
||||
$sum = (float)$query->sum('commission_rate');
|
||||
$remaining = 100 - $sum;
|
||||
if ($currentRate > $remaining + 0.000001) {
|
||||
$exceed = $currentRate - $remaining;
|
||||
return $this->error(sprintf('同一父级角色组分红比例总和不能超过100%%,当前父级剩余 %.2f%%,本次超出 %.2f%%', max(0, $remaining), $exceed));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 顶级角色组可选渠道;子级继承父级 channel_id(不信任客户端提交的子级 channel_id)。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user