Browse Source

update

master
dengbiao 2 months ago
parent
commit
af67cd390b
1 changed files with 24 additions and 22 deletions
  1. +24
    -22
      app/svc/svc_wx_data.go

+ 24
- 22
app/svc/svc_wx_data.go View File

@@ -8,6 +8,7 @@ import (
"code.fnuoos.com/zhimeng/model.git/src/super/implement"
"code.fnuoos.com/zhimeng/model.git/src/super/model"
"errors"
"fmt"
"github.com/shopspring/decimal"
"time"
)
@@ -41,24 +42,24 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode
}

// 3、计算媒体、代理收益、平台留存、佣金留存、协议分成、协议总分成
publisherIncome := originalWxAdData.PublisherIncome
mediaRevenue := publisherIncome * mediumDivisionStrategy.MediaRevenueRate / 100 // 媒体收益
agentRevenue := publisherIncome * mediumDivisionStrategy.AgentRevenueRate / 100 // 代理收益
platformRetention := publisherIncome * mediumDivisionStrategy.PlatformRetentionRate / 100 // 平台留存
commissionRetention := publisherIncome * mediumDivisionStrategy.CommissionRetentionRate / 100 // 佣金留存
agreementSharingTotal := (mediaRevenue + agentRevenue) / (100 - mediumDivisionStrategy.AgreementSharingRate) // 协议总分成(倒推)
agreementSharing := agreementSharingTotal - (mediaRevenue + agentRevenue) // 协议分成
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、判断是否有调价留存
var priceAdjustmentRetention int
if req.NowEcpm != req.OriginalEcpm || req.NowExposureCount != req.OriginalExposureCount {
tmpMediaRevenue := int(utils.StrToFloat64(req.NowEcpm) * float64(req.NowExposureCount) / 1000)
priceAdjustmentRetention = tmpMediaRevenue - mediaRevenue
mediaRevenue = tmpMediaRevenue
priceAdjustmentRetention = int(float64(tmpMediaRevenue) - mediaRevenue)
mediaRevenue = float64(tmpMediaRevenue)
}

// 4、计算各代理收益
var extraRevenue int
var extraRevenue float64
var agentRevenueFlows []struct {
AgentId int `json:"agent_id"`
AgentRevenueRate int `json:"agent_revenue_rate"`
@@ -67,8 +68,8 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode
ExtraRevenue int `json:"extra_revenue"`
}
for _, v := range *mediumDivisionStrategyWithAgentFlows {
tmpAgentRevenue := agentRevenue * v.AgentRevenueRate / 100
tmpExtraRevenue := commissionRetention * v.ExtraRevenueRate / 100
tmpAgentRevenue := agentRevenue * float64(v.AgentRevenueRate) / 100
tmpExtraRevenue := commissionRetention * float64(v.ExtraRevenueRate) / 100
extraRevenue += tmpExtraRevenue
agentRevenueFlows = append(agentRevenueFlows, struct {
AgentId int `json:"agent_id"`
@@ -80,8 +81,8 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode
AgentId: v.AgentId,
AgentRevenueRate: v.AgentRevenueRate,
ExtraRevenueRate: v.ExtraRevenueRate,
AgentRevenue: tmpAgentRevenue,
ExtraRevenue: tmpExtraRevenue,
AgentRevenue: int(tmpAgentRevenue),
ExtraRevenue: int(tmpExtraRevenue),
})
}

@@ -106,14 +107,14 @@ func GenerateWxAdData(req md.GenerateWxAdData) (err error, generateWxAdData mode
ClickCount: originalWxAdData.ClickCount,
ClickRate: originalWxAdData.ClickRate,
Ecpm: req.NowEcpm, // 现-ecpm
PlatformRetention: platformRetention,
CommissionRetention: commissionRetention,
PlatformRetention: int(platformRetention),
CommissionRetention: int(commissionRetention),
PriceAdjustmentRetention: priceAdjustmentRetention,
MediaRevenue: mediaRevenue,
AgentRevenue: agentRevenue,
ExtraRevenue: extraRevenue,
AgreementSharing: agreementSharing,
AgreementSharingTotal: agreementSharingTotal,
MediaRevenue: int(mediaRevenue),
AgentRevenue: int(agentRevenue),
ExtraRevenue: int(extraRevenue),
AgreementSharing: int(agreementSharing),
AgreementSharingTotal: int(agreementSharingTotal),
PlatformRetentionRate: mediumDivisionStrategy.PlatformRetentionRate,
CommissionRetentionRate: mediumDivisionStrategy.CommissionRetentionRate,
MediaRevenueRate: mediumDivisionStrategy.MediaRevenueRate,
@@ -203,8 +204,9 @@ func ClacEcpm(req md.ClacEcpmReq) (err error, ecpm string) {
mediaRevenue := publisherIncome.Mul(mediaRevenueRate.Div(rateValue)) // 媒体收益
agentRevenue := publisherIncome.Mul(agentRevenueRate.Div(rateValue)) // 代理收益

agreementSharingTotal := (mediaRevenue.Add(agentRevenue)).Div(rateValue.Sub(agreementSharingRate)) // 协议总分成(倒推)
agreementSharingTotal := mediaRevenue.Add(agentRevenue).Div(rateValue.Sub(agreementSharingRate).Div(rateValue)) // 协议总分成(倒推)

fmt.Println(mediaRevenue, agentRevenue, agreementSharingRate, rateValue.Sub(agreementSharingRate), agreementSharingTotal)
// 4、倒退出当前ecpm值
ecpm = agreementSharingTotal.Div(exposureCount.Div(thousandRateValue)).Round(2).String()
return


Loading…
Cancel
Save