Commit 7b890922 authored by 刘小敏's avatar 刘小敏

feat(command): 新增InitCommissionGoods命令及优化佣金日志

parent e44eec3a
......@@ -26,5 +26,6 @@ return [
'app\command\DataStatsCenter',
'app\command\TestLogDb',
'app\command\AgentOrderCommission',
'app\command\InitCommissionGoods',
];
......@@ -168,7 +168,7 @@ class AgentOrderCommission extends Command
}
} catch (\Exception $e) {
$errorCount++;
$this->customLog('error', "订单[{$order['order_sn']}]处理异常: " . $e->getMessage());
$this->customLog('error', "订单[{$order['id']}][{$order['order_sn']}]处理异常: " . $e->getMessage());
}
}
......@@ -270,7 +270,7 @@ class AgentOrderCommission extends Command
// 查找两级代理商,确保代理商申请成功后的订单才分佣
$agents = $this->findAgentChain($buyerUserId, $order['createtime'], 2);
if (empty($agents)) {
$this->customLog('info', "订单[{$orderSn}]跳过: 未找到有效的上级代理商, 买家[{$buyerUserId}]");
$this->customLog('info', "订单[{$orderId}][{$orderSn}]跳过: 未找到有效的上级代理商, 买家[{$buyerUserId}]");
return 'skip';
}
......@@ -290,12 +290,12 @@ class AgentOrderCommission extends Command
$commissionRate = floatval($agentRecord['commission_rate']);
if (!$agentRecord) {
$this->customLog('warning', "订单[{$orderSn}]代理商[{$recordAgentId}}]用户[{$agentUserId}]在shopro_agent表中不存在, 跳过");
$this->customLog('warning', "订单[{$orderId}][{$orderSn}]代理商[{$recordAgentId}}]用户[{$agentUserId}]在shopro_agent表中不存在, 跳过");
continue;
}
if ($commissionRate <= 0) {
$this->customLog('warning', "订单[{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]commission_rate为0或未设置, 跳过");
$this->customLog('warning', "订单[{$orderId}][{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]commission_rate为0或未设置, 跳过");
continue;
}
......@@ -303,7 +303,7 @@ class AgentOrderCommission extends Command
$commissionAmount = round($payFee * ($commissionRate / 100), 2);
if ($commissionAmount <= 0) {
$this->customLog('warning', "订单[{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]计算佣金为0, 跳过");
$this->customLog('warning', "订单[{$orderId}][{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]计算佣金为0, 跳过");
continue;
}
......@@ -350,7 +350,7 @@ class AgentOrderCommission extends Command
if ($exists) {
Db::rollback();
$this->customLog('info', "订单[{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]第{$agentLevel}级已存在佣金记录(事务内), 跳过");
$this->customLog('info', "订单[{$orderId}][{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]第{$agentLevel}级已存在佣金记录(事务内), 跳过");
continue;
}
......@@ -362,19 +362,19 @@ class AgentOrderCommission extends Command
Db::rollback();
// 捕获唯一索引冲突(如有索引),说明真的重复了
if (stripos($e->getMessage(), 'Duplicate entry') !== false) {
$this->customLog('info', "订单[{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]唯一索引冲突,已存在记录, 跳过");
$this->customLog('info', "订单[{$orderId}][{$orderSn}]代理商[{$recordAgentId}]用户[{$agentUserId}]唯一索引冲突,已存在记录, 跳过");
} else {
$this->customLog('error', "订单[{$orderSn}]写入异常: " . $e->getMessage());
$this->customLog('error', "订单[{$orderId}][{$orderSn}]写入异常: " . $e->getMessage());
}
continue;
} catch (\Exception $e) {
Db::rollback();
$this->customLog('error', "订单[{$orderSn}]事务异常: " . $e->getMessage());
$this->customLog('error', "订单[{$orderId}][{$orderSn}]事务异常: " . $e->getMessage());
continue;
}
if ($inserted) {
$this->customLog('info', "订单[{$orderSn}]第{$agentLevel}级代理商[{$recordAgentId}]用户[{$agentUserId}]佣金: ¥{$commissionAmount} (订单金额: ¥{$payFee})");
$this->customLog('info', "订单[{$orderId}][{$orderSn}]第{$agentLevel}级代理商[{$recordAgentId}]用户[{$agentUserId}]佣金: ¥{$commissionAmount} (订单金额: ¥{$payFee})");
$this->affectedAgentIds[$recordAgentId] = true;
$processedCount++;
}
......
......@@ -125,8 +125,10 @@ class InitCommissionGoods extends Command
if ($result > 0) {
$insertCount++;
$this->customLog('info', "商品[{$goodsId}]新增分销记录");
} else {
$skipCount++;
$this->customLog('info', "商品[{$goodsId}]已存在分销记录,跳过");
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment