Przeglądaj źródła

add 计算应用数据方法

master
dengbiao 1 miesiąc temu
rodzic
commit
49575d224c
2 zmienionych plików z 86 dodań i 1 usunięć
  1. +17
    -0
      app/md/md_generate_wx_ad_data.go
  2. +69
    -1
      app/svc/svc_wx_data.go

+ 17
- 0
app/md/md_generate_wx_ad_data.go Wyświetl plik

@@ -14,6 +14,23 @@ type ClacEcpmReq struct {
GenerateDataId int `json:"generate_data_id" example:"原始数据id"`
}

type CalcApplicationDataReq struct {
OriginalDataId int `json:"original_data_id" example:"原始数据id"`
OriginalExposureCount int `json:"original_exposure_count" example:"原-曝光量"`
OriginalEcpm string `json:"original_ecpm" example:"原-广告千次曝光收益(分)"`
NowExposureCount int `json:"now_exposure_count" example:"现-曝光量"`
NowEcpm string `json:"now_ecpm" example:"现-广告千次曝光收益(分)"`
}

type CalcApplicationDataResp struct {
PlatformRetention float64 `json:"platform_retention" example:"平台留存"`
CommissionRetention float64 `json:"commission_retention" example:"佣金留存"`
MediaRevenue float64 `json:"media_revenue" example:"媒体收益"`
AgentRevenue float64 `json:"agent_revenue" example:"代理收益"`
ExtraRevenue float64 `json:"extra_revenue" example:"额外收益"`
AgreementSharing float64 `json:"agreement_sharing" example:"协议分成"`
}

type SettlementWxAdData struct {
GenerateDataId int `json:"generate_data_id" example:"生成数据id"`
}

+ 69
- 1
app/svc/svc_wx_data.go Wyświetl plik

@@ -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
}

Ładowanie…
Anuluj
Zapisz