fix
This commit is contained in:
@@ -2,6 +2,7 @@ package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/ctxdata"
|
||||
@@ -57,26 +58,27 @@ func (l *GetRevenueInfoLogic) GetRevenueInfo() (resp *types.GetRevenueInfoResp,
|
||||
todayStart := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
// 本月开始时间(1号 00:00:00)
|
||||
monthStart := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
|
||||
nextMonthStart := monthStart.AddDate(0, 1, 0)
|
||||
|
||||
// 3. 统计佣金总额(从 agent_commission 表统计)
|
||||
// 3. 统计佣金总额(从 agent_commission 表统计,排除已取消的记录 status=3)
|
||||
commissionBuilder := l.svcCtx.AgentCommissionModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ?", agent.Id, globalkey.DelStateNo)
|
||||
Where("agent_id = ? AND del_state = ? AND status != ?", agent.Id, globalkey.DelStateNo, 3)
|
||||
commissionTotal, _ := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, commissionBuilder, "amount")
|
||||
|
||||
// 3.1 统计佣金今日收益
|
||||
// 3.1 统计佣金今日收益(排除已取消的记录 status=3)
|
||||
commissionTodayBuilder := l.svcCtx.AgentCommissionModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, todayStart)
|
||||
Where("agent_id = ? AND del_state = ? AND status != ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, 3, todayStart)
|
||||
commissionToday, _ := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, commissionTodayBuilder, "amount")
|
||||
|
||||
// 3.2 统计佣金本月收益
|
||||
// 3.2 统计佣金本月收益(排除已取消的记录 status=3)
|
||||
commissionMonthBuilder := l.svcCtx.AgentCommissionModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, monthStart)
|
||||
Where("agent_id = ? AND del_state = ? AND status != ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, 3, monthStart)
|
||||
commissionMonth, _ := l.svcCtx.AgentCommissionModel.FindSum(l.ctx, commissionMonthBuilder, "amount")
|
||||
|
||||
// 4. 统计返佣总额(包括推广返佣和升级返佣)
|
||||
// 4.1 统计推广返佣(从 agent_rebate 表)
|
||||
// 4. 统计返佣总额(包括推广返佣和升级返佣,排除已取消的记录 status=3)
|
||||
// 4.1 统计推广返佣(从 agent_rebate 表,排除已取消的记录 status=3)
|
||||
rebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ?", agent.Id, globalkey.DelStateNo)
|
||||
Where("agent_id = ? AND del_state = ? AND status != ?", agent.Id, globalkey.DelStateNo, 3)
|
||||
promoteRebateTotal, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, rebateBuilder, "rebate_amount")
|
||||
|
||||
// 4.2 统计升级返佣(从 agent_upgrade 表,查询 rebate_agent_id = 当前代理ID 且 status = 2(已完成)且 upgrade_type = 1(自主付费)的记录)
|
||||
@@ -88,10 +90,10 @@ func (l *GetRevenueInfoLogic) GetRevenueInfo() (resp *types.GetRevenueInfoResp,
|
||||
|
||||
rebateTotal := promoteRebateTotal + upgradeRebateTotal
|
||||
|
||||
// 4.3 统计返佣今日收益
|
||||
// 4.3 统计返佣今日收益(排除已取消的记录 status=3)
|
||||
// 推广返佣今日
|
||||
promoteRebateTodayBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, todayStart)
|
||||
Where("agent_id = ? AND del_state = ? AND status != ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, 3, todayStart)
|
||||
promoteRebateToday, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, promoteRebateTodayBuilder, "rebate_amount")
|
||||
// 升级返佣今日
|
||||
upgradeRebateTodayBuilder := l.svcCtx.AgentUpgradeModel.SelectBuilder().
|
||||
@@ -100,10 +102,10 @@ func (l *GetRevenueInfoLogic) GetRevenueInfo() (resp *types.GetRevenueInfoResp,
|
||||
upgradeRebateToday, _ := l.svcCtx.AgentUpgradeModel.FindSum(l.ctx, upgradeRebateTodayBuilder, "rebate_amount")
|
||||
rebateToday := promoteRebateToday + upgradeRebateToday
|
||||
|
||||
// 4.4 统计返佣本月收益
|
||||
// 4.4 统计返佣本月收益(排除已取消的记录 status=3)
|
||||
// 推广返佣本月
|
||||
promoteRebateMonthBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
|
||||
Where("agent_id = ? AND del_state = ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, monthStart)
|
||||
Where("agent_id = ? AND del_state = ? AND status != ? AND create_time >= ?", agent.Id, globalkey.DelStateNo, 3, monthStart)
|
||||
promoteRebateMonth, _ := l.svcCtx.AgentRebateModel.FindSum(l.ctx, promoteRebateMonthBuilder, "rebate_amount")
|
||||
// 升级返佣本月
|
||||
upgradeRebateMonthBuilder := l.svcCtx.AgentUpgradeModel.SelectBuilder().
|
||||
@@ -112,16 +114,43 @@ func (l *GetRevenueInfoLogic) GetRevenueInfo() (resp *types.GetRevenueInfoResp,
|
||||
upgradeRebateMonth, _ := l.svcCtx.AgentUpgradeModel.FindSum(l.ctx, upgradeRebateMonthBuilder, "rebate_amount")
|
||||
rebateMonth := promoteRebateMonth + upgradeRebateMonth
|
||||
|
||||
// 5. 统计本月支付宝提现额度使用情况
|
||||
// 5.1 获取配置的支付宝月度额度(默认 800 元)
|
||||
alipayQuota := 800.0
|
||||
if cfg, cfgErr := l.svcCtx.AgentConfigModel.FindOneByConfigKey(l.ctx, "alipay_month_quota"); cfgErr == nil {
|
||||
if parsed, parseErr := parseFloatConfig(cfg.ConfigValue); parseErr == nil && parsed > 0 {
|
||||
alipayQuota = parsed
|
||||
}
|
||||
}
|
||||
|
||||
// 5.2 统计本月已申请/成功的支付宝提现金额(status IN (1,5)),用于前端展示额度占用
|
||||
withdrawBuilder := l.svcCtx.AgentWithdrawalModel.SelectBuilder().
|
||||
Where("agent_id = ? AND withdrawal_type = ? AND status IN (1,5) AND create_time >= ? AND create_time < ?",
|
||||
agent.Id, 1, monthStart, nextMonthStart)
|
||||
alipayUsed, _ := l.svcCtx.AgentWithdrawalModel.FindSum(l.ctx, withdrawBuilder, "amount")
|
||||
if alipayUsed < 0 {
|
||||
alipayUsed = 0
|
||||
}
|
||||
|
||||
return &types.GetRevenueInfoResp{
|
||||
Balance: wallet.Balance,
|
||||
FrozenBalance: wallet.FrozenBalance,
|
||||
TotalEarnings: wallet.TotalEarnings,
|
||||
WithdrawnAmount: wallet.WithdrawnAmount,
|
||||
CommissionTotal: commissionTotal, // 佣金累计总收益(推广订单获得的佣金)
|
||||
CommissionToday: commissionToday, // 佣金今日收益
|
||||
CommissionMonth: commissionMonth, // 佣金本月收益
|
||||
RebateTotal: rebateTotal, // 返佣累计总收益(包括推广返佣和升级返佣)
|
||||
RebateToday: rebateToday, // 返佣今日收益
|
||||
RebateMonth: rebateMonth, // 返佣本月收益
|
||||
Balance: wallet.Balance,
|
||||
FrozenBalance: wallet.FrozenBalance,
|
||||
TotalEarnings: wallet.TotalEarnings,
|
||||
WithdrawnAmount: wallet.WithdrawnAmount,
|
||||
CommissionTotal: commissionTotal, // 佣金累计总收益(推广订单获得的佣金)
|
||||
CommissionToday: commissionToday, // 佣金今日收益
|
||||
CommissionMonth: commissionMonth, // 佣金本月收益
|
||||
RebateTotal: rebateTotal, // 返佣累计总收益(包括推广返佣和升级返佣)
|
||||
RebateToday: rebateToday, // 返佣今日收益
|
||||
RebateMonth: rebateMonth, // 返佣本月收益
|
||||
AlipayMonthQuota: alipayQuota, // 支付宝每月提现总额度
|
||||
AlipayMonthUsed: alipayUsed, // 本月已使用的支付宝提现额度
|
||||
}, nil
|
||||
}
|
||||
|
||||
// parseFloatConfig 解析配置中的浮点数
|
||||
func parseFloatConfig(s string) (float64, error) {
|
||||
var result float64
|
||||
_, err := fmt.Sscanf(s, "%f", &result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user