fix
This commit is contained in:
@@ -89,9 +89,47 @@ func (l *AdminGetRevenueStatisticsLogic) AdminGetRevenueStatistics(req *types.Ad
|
|||||||
// 总利润 = 总收入 - 所有订单成本
|
// 总利润 = 总收入 - 所有订单成本
|
||||||
totalProfitAmount := deductionAmount + nonDeductionAmount - orderCostAmount
|
totalProfitAmount := deductionAmount + nonDeductionAmount - orderCostAmount
|
||||||
|
|
||||||
// 今日利润与总利润计算方式相同(这里简化为直接使用总利润)
|
// 计算今日利润 = 今日代理订单金额 + 今日非代理订单金额 - 今日订单成本总和
|
||||||
// 如需精确计算今日利润,可参考总利润的计算方式,添加时间条件
|
|
||||||
todayProfitAmount := totalProfitAmount
|
// 1. 查询今日代理订单金额
|
||||||
|
todayDeductionBuilder := l.svcCtx.AgentPlatformDeductionModel.SelectBuilder().
|
||||||
|
Where("create_time >= ? AND create_time < ?", startOfDay, endOfDay)
|
||||||
|
todayDeductionAmount, err := l.svcCtx.AgentPlatformDeductionModel.FindSum(
|
||||||
|
l.ctx,
|
||||||
|
todayDeductionBuilder,
|
||||||
|
"amount")
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("查询今日代理订单金额失败: %v", err)
|
||||||
|
return nil, fmt.Errorf("查询今日代理订单金额失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 查询今日非代理订单金额
|
||||||
|
todayNonDeductionBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||||
|
Where("status = ? AND pay_time >= ? AND pay_time < ? AND id NOT IN (SELECT order_id FROM agent_platform_deduction WHERE order_id IS NOT NULL)",
|
||||||
|
"paid", startOfDay, endOfDay)
|
||||||
|
todayNonDeductionAmount, err := l.svcCtx.OrderModel.FindSum(
|
||||||
|
l.ctx,
|
||||||
|
todayNonDeductionBuilder,
|
||||||
|
"amount")
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("查询今日非代理订单金额失败: %v", err)
|
||||||
|
return nil, fmt.Errorf("查询今日非代理订单金额失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 查询今日订单成本总和
|
||||||
|
todayOrderCostBuilder := l.svcCtx.OrderModel.SelectBuilder().
|
||||||
|
Where("status = ? AND pay_time >= ? AND pay_time < ?", "paid", startOfDay, endOfDay)
|
||||||
|
todayOrderCostAmount, err := l.svcCtx.OrderModel.FindSum(
|
||||||
|
l.ctx,
|
||||||
|
todayOrderCostBuilder,
|
||||||
|
"sales_cost")
|
||||||
|
if err != nil {
|
||||||
|
logx.Errorf("查询今日订单成本总和失败: %v", err)
|
||||||
|
return nil, fmt.Errorf("查询今日订单成本总和失败: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 计算今日利润 = 今日代理订单金额 + 今日非代理订单金额 - 今日订单成本总和
|
||||||
|
todayProfitAmount := todayDeductionAmount + todayNonDeductionAmount - todayOrderCostAmount
|
||||||
|
|
||||||
// 构建响应
|
// 构建响应
|
||||||
resp = &types.AdminGetRevenueStatisticsResp{
|
resp = &types.AdminGetRevenueStatisticsResp{
|
||||||
|
|||||||
Reference in New Issue
Block a user