This commit is contained in:
2026-01-13 18:30:10 +08:00
parent 0206710e29
commit 04df8460a4
29 changed files with 2472 additions and 111 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/pkg/errors"
"ycc-server/app/main/api/internal/service"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
@@ -224,7 +225,7 @@ func (l *AdminGetDashboardStatisticsLogic) calculateAgentStatistics(todayStart,
func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart, todayEnd, monthStart, monthEnd time.Time, revenueStats types.AdminRevenueStatistics) (types.AdminProfitStatistics, error) {
var stats types.AdminProfitStatistics
// 公司交税比例6%
// 税务成本比例6%
const companyTaxRate = 0.06
// 今日利润计算
@@ -244,20 +245,44 @@ func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart,
if err != nil {
return stats, err
}
// 今日公司交订单金额的6%
// 今日税务成本订单金额的6%
todayCompanyTax := todayRevenue * companyTaxRate
// 今日平台收入agent_withdrawal_tax表中tax_status=2的tax_amount总和
// 今日提现收agent_withdrawal_tax表中tax_status=2的tax_amount总和
todayTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
Where("del_state = ? AND tax_status = ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 2, todayStart, todayEnd)
todayTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, todayTaxIncomeBuilder, "tax_amount")
if err != nil {
return stats, err
}
// 今日利润 = 营收 - 佣金 - 返利 - 公司交税 + 平台收入税
stats.TodayProfit = todayRevenue - todayCommission - todayRebate - todayCompanyTax + todayTaxIncome
// 今日API调用成本
todayApiCost := 0.0
if l.svcCtx.TianyuanapiCallLogService != nil {
todayApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{
StartDate: todayStart,
EndDate: todayEnd,
})
if err != nil {
logx.Errorf("获取今日API调用成本失败: %v", err)
} else {
todayApiCost = todayApiStats.TotalCost
}
}
// 今日利润 = 营收 - 佣金 - 返利 - 税务成本 - API调用成本 + 提现收税
stats.TodayProfit = todayRevenue - todayCommission - todayRebate - todayCompanyTax - todayApiCost + todayTaxIncome
if todayRevenue > 0 {
stats.TodayProfitRate = stats.TodayProfit / todayRevenue * 100
}
// 今日明细
stats.TodayDetail = types.AdminProfitDetail{
Revenue: todayRevenue,
Commission: todayCommission,
Rebate: todayRebate,
CompanyTax: todayCompanyTax,
ApiCost: todayApiCost,
TaxIncome: todayTaxIncome,
Profit: stats.TodayProfit,
ProfitRate: stats.TodayProfitRate,
}
// 当月利润计算
// 当月营收
@@ -276,20 +301,44 @@ func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart,
if err != nil {
return stats, err
}
// 当月公司交
// 当月税务成本
monthCompanyTax := monthRevenue * companyTaxRate
// 当月平台收入
// 当月提现收
monthTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
Where("del_state = ? AND tax_status = ? AND create_time >= ? AND create_time < ?", globalkey.DelStateNo, 2, monthStart, monthEnd)
monthTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, monthTaxIncomeBuilder, "tax_amount")
if err != nil {
return stats, err
}
// 当月API调用成本
monthApiCost := 0.0
if l.svcCtx.TianyuanapiCallLogService != nil {
monthApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{
StartDate: monthStart,
EndDate: monthEnd,
})
if err != nil {
logx.Errorf("获取当月API调用成本失败: %v", err)
} else {
monthApiCost = monthApiStats.TotalCost
}
}
// 当月利润
stats.MonthProfit = monthRevenue - monthCommission - monthRebate - monthCompanyTax + monthTaxIncome
stats.MonthProfit = monthRevenue - monthCommission - monthRebate - monthCompanyTax - monthApiCost + monthTaxIncome
if monthRevenue > 0 {
stats.MonthProfitRate = stats.MonthProfit / monthRevenue * 100
}
// 当月明细
stats.MonthDetail = types.AdminProfitDetail{
Revenue: monthRevenue,
Commission: monthCommission,
Rebate: monthRebate,
CompanyTax: monthCompanyTax,
ApiCost: monthApiCost,
TaxIncome: monthTaxIncome,
Profit: stats.MonthProfit,
ProfitRate: stats.MonthProfitRate,
}
// 总利润计算
// 总营收
@@ -303,25 +352,46 @@ func (l *AdminGetDashboardStatisticsLogic) calculateProfitStatistics(todayStart,
}
// 总返利
totalRebateBuilder := l.svcCtx.AgentRebateModel.SelectBuilder().
Where("del_state = ? AND status != ?", globalkey.DelStateNo, 3)
Where("status != ?", 3)
totalRebate, err := l.svcCtx.AgentRebateModel.FindSum(l.ctx, totalRebateBuilder, "rebate_amount")
if err != nil {
return stats, err
}
// 总公司交
// 总税务成本
totalCompanyTax := totalRevenue * companyTaxRate
// 总平台收入
// 总提现收
totalTaxIncomeBuilder := l.svcCtx.AgentWithdrawalTaxModel.SelectBuilder().
Where("del_state = ? AND tax_status = ?", globalkey.DelStateNo, 2)
Where("tax_status = ?", 2)
totalTaxIncome, err := l.svcCtx.AgentWithdrawalTaxModel.FindSum(l.ctx, totalTaxIncomeBuilder, "tax_amount")
if err != nil {
return stats, err
}
// 总API调用成本
totalApiCost := 0.0
if l.svcCtx.TianyuanapiCallLogService != nil {
totalApiStats, err := l.svcCtx.TianyuanapiCallLogService.GetStatistics(l.ctx, service.StatisticsFilter{})
if err != nil {
logx.Errorf("获取总API调用成本失败: %v", err)
} else {
totalApiCost = totalApiStats.TotalCost
}
}
// 总利润
stats.TotalProfit = totalRevenue - totalCommission - totalRebate - totalCompanyTax + totalTaxIncome
stats.TotalProfit = totalRevenue - totalCommission - totalRebate - totalCompanyTax - totalApiCost + totalTaxIncome
if totalRevenue > 0 {
stats.TotalProfitRate = stats.TotalProfit / totalRevenue * 100
}
// 总计明细
stats.TotalDetail = types.AdminProfitDetail{
Revenue: totalRevenue,
Commission: totalCommission,
Rebate: totalRebate,
CompanyTax: totalCompanyTax,
ApiCost: totalApiCost,
TaxIncome: totalTaxIncome,
Profit: stats.TotalProfit,
ProfitRate: stats.TotalProfitRate,
}
return stats, nil
}

View File

@@ -0,0 +1,46 @@
package agent
import (
"context"
"ycc-server/app/main/api/internal/logic/query"
"ycc-server/app/main/api/internal/svc"
"ycc-server/app/main/api/internal/types"
"github.com/pkg/errors"
"ycc-server/common/ctxdata"
"ycc-server/common/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type CheckOrderAgentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCheckOrderAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CheckOrderAgentLogic {
return &CheckOrderAgentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CheckOrderAgentLogic) CheckOrderAgent(req *types.CheckOrderAgentReq) (resp *types.CheckOrderAgentResp, err error) {
// 获取当前用户ID
userId, err := ctxdata.GetUidFromCtx(l.ctx)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取用户ID失败: %v", err)
}
// 检查订单是否属于当前代理推广
isAgent, err := query.IsOrderAgent(l.ctx, l.svcCtx, userId, req.OrderId)
if err != nil {
return nil, err
}
return &types.CheckOrderAgentResp{
IsAgentOrder: isAgent,
}, nil
}

View File

@@ -36,7 +36,7 @@ func (l *QuerySingleTestLogic) QuerySingleTest(req *types.QuerySingleTestReq) (r
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 序列化参数失败 : %d", err)
}
apiResp, err := l.svcCtx.ApiRequestService.PreprocessRequestApi(marshalParams, req.Api)
apiResp, err := l.svcCtx.ApiRequestService.PreprocessRequestApi(l.ctx, marshalParams, req.Api)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "单查测试, 获取接口失败 : %d", err)
}