diff --git a/app/svc/svc_data_center_generate_data.go b/app/svc/svc_data_center_generate_data.go index 6414a3c..c75c451 100644 --- a/app/svc/svc_data_center_generate_data.go +++ b/app/svc/svc_data_center_generate_data.go @@ -186,10 +186,20 @@ func DataCenterGenerateDataDel(c *gin.Context, req md.DataCenterGenerateDataComm if data.IsGenerateReport == 1 { return errors.New("记录已应用,不能删除") } + + // 1、删除 generate_wx_ad_data 数据 _, err := db.Db.Where("id=?", req.Id).Delete(&model.GenerateWxAdData{}) if err != nil { return err } + + // 2、删除 generate_wx_ad_data_with_agent_flow 数据 + _, err = db.Db.Where("generate_data_id=?", req.Id).Delete(&model.GenerateWxAdDataWithAgentFlow{}) + if err != nil { + return err + } + + // 3、修改 original_wx_ad_data 状态值 db.Db.Where("id=?", data.OriginalDataId).Cols("is_apply").Update(&model.OriginalWxAdData{IsApply: 0}) return nil } diff --git a/app/svc/svc_wx_data.go b/app/svc/svc_wx_data.go index cbcc7a4..b530da6 100644 --- a/app/svc/svc_wx_data.go +++ b/app/svc/svc_wx_data.go @@ -43,8 +43,8 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode // 3、计算媒体、代理收益、平台留存、佣金留存、协议分成、协议总分成 publisherIncome := float64(originalWxAdData.PublisherIncome) - mediaRevenue := publisherIncome * float64(mediumDivisionStrategy.MediaRevenueRate) / 100 // 媒体收益 - agentRevenue := publisherIncome * float64(mediumDivisionStrategy.AgentRevenueRate) / 100 // 代理收益 + mediaRevenue := utils.RoundToTwoDecimalPlaces(publisherIncome * float64(mediumDivisionStrategy.MediaRevenueRate) / 100) // 媒体收益 + agentRevenue := utils.RoundToTwoDecimalPlaces(publisherIncome * float64(mediumDivisionStrategy.AgentRevenueRate) / 100) // 代理收益 platformRetention := publisherIncome * float64(mediumDivisionStrategy.PlatformRetentionRate) / 100 // 平台留存 commissionRetention := publisherIncome * float64(mediumDivisionStrategy.CommissionRetentionRate) / 100 // 佣金留存 agreementSharingTotal := (mediaRevenue + agentRevenue) / ((100 - float64(mediumDivisionStrategy.AgreementSharingRate)) / 100) // 协议总分成(倒推) @@ -75,7 +75,7 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode ExtraRevenue int `json:"extra_revenue"` } for _, v := range *mediumDivisionStrategyWithAgentFlows { - tmpAgentRevenue := agentRevenue * float64(v.AgentRevenueRate) / 100 + tmpAgentRevenue := utils.RoundToTwoDecimalPlaces(agentRevenue * float64(v.AgentRevenueRate) / 100) tmpExtraRevenue := commissionRetention * float64(v.ExtraRevenueRate) / 100 extraRevenue += tmpExtraRevenue agentRevenueFlows = append(agentRevenueFlows, struct { diff --git a/app/utils/rand.go b/app/utils/rand.go index 61869aa..793e6c8 100644 --- a/app/utils/rand.go +++ b/app/utils/rand.go @@ -3,6 +3,7 @@ package utils import ( crand "crypto/rand" "fmt" + "math" "math/big" "math/rand" "strconv" @@ -52,3 +53,7 @@ func GenerateUniqueRandomNumbers(n int) string { return numbersStr } + +func RoundToTwoDecimalPlaces(num float64) float64 { + return math.Round(num*100) / 100 +}