```
feat(split): 优化分佣计算逻辑支持多种数据类型 重构SplitCalculator类中的佣金计算方法,添加对数组和对象结果集的统一处理, 提高代码的健壮性和可维护性。 - 使用isEmptyResult方法替代直接调用isEmpty判断 - 使用toResultList方法统一处理不同类型的查询结果 - 支持数组、集合对象等多种数据结构的遍历操作 ```
这个提交包含在:
@@ -81,11 +81,11 @@ class SplitCalculator
|
|||||||
|
|
||||||
$payFee = floatval($order['pay_fee']);
|
$payFee = floatval($order['pay_fee']);
|
||||||
$commissionRewards = CommissionReward::where('order_id', $orderId)->where('status', '>=', 0)->select();
|
$commissionRewards = CommissionReward::where('order_id', $orderId)->where('status', '>=', 0)->select();
|
||||||
if ($commissionRewards->isEmpty()) {
|
if ($this->isEmptyResult($commissionRewards)) {
|
||||||
$issues[] = '该订单无分销佣金记录(未产生推广关系或未参与分销)';
|
$issues[] = '该订单无分销佣金记录(未产生推广关系或未参与分销)';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($commissionRewards as $reward) {
|
foreach ($this->toResultList($commissionRewards) as $reward) {
|
||||||
$userId = intval($reward['agent_id']);
|
$userId = intval($reward['agent_id']);
|
||||||
$amount = floatval($reward['commission']);
|
$amount = floatval($reward['commission']);
|
||||||
if ($userId <= 0) {
|
if ($userId <= 0) {
|
||||||
@@ -108,7 +108,7 @@ class SplitCalculator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$regionalRewards = $this->getRegionalRewardsByOrderId($orderId);
|
$regionalRewards = $this->getRegionalRewardsByOrderId($orderId);
|
||||||
foreach ($regionalRewards as $reward) {
|
foreach ($this->toResultList($regionalRewards) as $reward) {
|
||||||
$uid = intval($reward['agent_user_id']);
|
$uid = intval($reward['agent_user_id']);
|
||||||
$amount = floatval($reward['commission']);
|
$amount = floatval($reward['commission']);
|
||||||
if ($uid <= 0 || $amount <= 0) {
|
if ($uid <= 0 || $amount <= 0) {
|
||||||
@@ -144,6 +144,28 @@ class SplitCalculator
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function isEmptyResult($result)
|
||||||
|
{
|
||||||
|
if (is_array($result)) {
|
||||||
|
return count($result) === 0;
|
||||||
|
}
|
||||||
|
if (is_object($result) && method_exists($result, 'isEmpty')) {
|
||||||
|
return $result->isEmpty();
|
||||||
|
}
|
||||||
|
return empty($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function toResultList($result)
|
||||||
|
{
|
||||||
|
if (is_array($result)) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
if (is_object($result) && method_exists($result, 'all')) {
|
||||||
|
return $result->all();
|
||||||
|
}
|
||||||
|
return $result ? (array) $result : [];
|
||||||
|
}
|
||||||
|
|
||||||
protected function getRegionalRewardsByOrderId($orderId)
|
protected function getRegionalRewardsByOrderId($orderId)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
在新工单中引用
屏蔽一个用户