|
|
@@ -61,7 +61,7 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode |
|
|
|
fmt.Println(utils.Float64ToStr(utils.StrToFloat64(ecpm) / 100)) |
|
|
|
if req.NowEcpm != utils.Float64ToStr(utils.StrToFloat64(ecpm)/100) || req.NowExposureCount != req.OriginalExposureCount { |
|
|
|
tmpMediaRevenue := int(utils.StrToFloat64(req.NowEcpm) * float64(req.NowExposureCount) / 1000) |
|
|
|
priceAdjustmentRetention = int(float64(tmpMediaRevenue) - mediaRevenue) |
|
|
|
priceAdjustmentRetention = int(mediaRevenue - float64(tmpMediaRevenue)) |
|
|
|
mediaRevenue = float64(tmpMediaRevenue) |
|
|
|
} |
|
|
|
|
|
|
@@ -535,3 +535,71 @@ func SettlementWxAdData(req md.SettlementWxAdData) (err error) { |
|
|
|
} |
|
|
|
return session.Commit() |
|
|
|
} |
|
|
|
|
|
|
|
func CalcApplicationData(req md.CalcApplicationDataReq) (err error, resp md.CalcApplicationDataResp) { |
|
|
|
// 1、查找原始数据记录 |
|
|
|
originalWxAdDataDb := implement.NewOriginalWxAdDataDb(db.Db) |
|
|
|
originalWxAdData, err := originalWxAdDataDb.GetOriginalWxAdData(req.OriginalDataId) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if originalWxAdData == nil { |
|
|
|
err = errors.New("未查询到原始数据记录") |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 2、查询对应媒体、代理的分成策略 |
|
|
|
mediumDivisionStrategyDb := implement.NewMediumDivisionStrategyDb(db.Db) |
|
|
|
mediumDivisionStrategy, err := mediumDivisionStrategyDb.GetOriginalWxAdDataByMediumId(originalWxAdData.MediumId) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
if mediumDivisionStrategy == nil { |
|
|
|
err = errors.New("未查询到对应代理的分成策略") |
|
|
|
return |
|
|
|
} |
|
|
|
mediumDivisionStrategyWithAgentFlowDb := implement.NewMediumDivisionStrategyWithAgentFlowDb(db.Db) |
|
|
|
mediumDivisionStrategyWithAgentFlows, err := mediumDivisionStrategyWithAgentFlowDb.FindMediumDivisionStrategyWithAgentFlowByStrategyId(mediumDivisionStrategy.MediumId) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 3、计算媒体、代理收益、平台留存、佣金留存、协议分成、协议总分成 |
|
|
|
publisherIncome := float64(originalWxAdData.PublisherIncome) |
|
|
|
mediaRevenue := publisherIncome * float64(mediumDivisionStrategy.MediaRevenueRate) / 100 // 媒体收益 |
|
|
|
agentRevenue := 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) // 协议总分成(倒推) |
|
|
|
agreementSharing := agreementSharingTotal - (mediaRevenue + agentRevenue) // 协议分成 |
|
|
|
|
|
|
|
// 3、判断是否有调价留存 |
|
|
|
ecpmReq := md.ClacEcpmReq{ |
|
|
|
OriginalExposureCount: originalWxAdData.ExposureCount, |
|
|
|
OriginalEcpm: originalWxAdData.Ecpm, |
|
|
|
GenerateDataId: originalWxAdData.Id, |
|
|
|
} |
|
|
|
_, ecpm := ClacEcpm(ecpmReq) |
|
|
|
fmt.Println(utils.Float64ToStr(utils.StrToFloat64(ecpm) / 100)) |
|
|
|
if req.NowEcpm != utils.Float64ToStr(utils.StrToFloat64(ecpm)/100) || req.NowExposureCount != req.OriginalExposureCount { |
|
|
|
tmpMediaRevenue := int(utils.StrToFloat64(req.NowEcpm) * float64(req.NowExposureCount) / 1000) |
|
|
|
mediaRevenue = float64(tmpMediaRevenue) |
|
|
|
} |
|
|
|
|
|
|
|
// 4、计算各代理收益 |
|
|
|
var extraRevenue float64 |
|
|
|
for _, v := range *mediumDivisionStrategyWithAgentFlows { |
|
|
|
tmpExtraRevenue := commissionRetention * float64(v.ExtraRevenueRate) / 100 |
|
|
|
extraRevenue += tmpExtraRevenue |
|
|
|
} |
|
|
|
|
|
|
|
resp = md.CalcApplicationDataResp{ |
|
|
|
PlatformRetention: platformRetention, |
|
|
|
CommissionRetention: commissionRetention, |
|
|
|
MediaRevenue: mediaRevenue, |
|
|
|
AgentRevenue: agentRevenue, |
|
|
|
ExtraRevenue: extraRevenue, |
|
|
|
AgreementSharing: agreementSharing, |
|
|
|
} |
|
|
|
return |
|
|
|
} |