gomod引用
This commit is contained in:
@@ -28,13 +28,6 @@ func (s *adPosition) Add(ctx context.Context, req *dto.AddAdPositionReq) (res *d
|
||||
adPosition.UpdatedAt = now
|
||||
adPosition.IsDeleted = false
|
||||
|
||||
// 初始化统计字段
|
||||
adPosition.DailyImpressions = 0
|
||||
adPosition.DailyClicks = 0
|
||||
adPosition.DailyRevenue = 0
|
||||
adPosition.CTR = 0
|
||||
// eCPM字段是未导出的,无法直接设置
|
||||
|
||||
if err = dao.AdPosition.Insert(ctx, adPosition); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -121,62 +114,5 @@ func (s *adPosition) MatchAd(ctx context.Context, positionCode string, userInfo
|
||||
|
||||
// UpdateAdPositionStatistics 更新广告位统计
|
||||
func (s *adPosition) UpdateAdPositionStatistics(ctx context.Context, id string, impressions, clicks, revenue int64) (err error) {
|
||||
// 获取广告位信息
|
||||
adPosition, err := dao.AdPosition.GetOne(ctx, id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 计算统计数据
|
||||
totalImpressions := adPosition.DailyImpressions + impressions
|
||||
totalClicks := adPosition.DailyClicks + clicks
|
||||
totalRevenue := adPosition.DailyRevenue + revenue
|
||||
|
||||
// 计算比率
|
||||
ctr := 0.0
|
||||
if totalImpressions > 0 {
|
||||
ctr = float64(totalClicks) / float64(totalImpressions)
|
||||
}
|
||||
|
||||
ecpm := int64(0)
|
||||
if totalImpressions > 0 {
|
||||
ecpm = totalRevenue * 1000 / totalImpressions
|
||||
}
|
||||
|
||||
// 构建更新数据
|
||||
stats := map[string]interface{}{
|
||||
"dailyImpressions": totalImpressions,
|
||||
"dailyClicks": totalClicks,
|
||||
"dailyRevenue": totalRevenue,
|
||||
"ctr": ctr,
|
||||
"ecpm": ecpm,
|
||||
"updatedAt": time.Now(),
|
||||
}
|
||||
|
||||
// 更新广告位统计
|
||||
err = dao.AdPosition.UpdateStatistics(ctx, id, stats)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 插入统计记录
|
||||
today := time.Now()
|
||||
todayStart := time.Date(today.Year(), today.Month(), today.Day(), 0, 0, 0, 0, today.Location()).Unix()
|
||||
|
||||
statistics := &entity.AdStatistics{
|
||||
StatType: "adPosition",
|
||||
StatDimension: "day",
|
||||
TargetId: id,
|
||||
TargetName: adPosition.Name,
|
||||
StatDate: todayStart,
|
||||
Impressions: impressions,
|
||||
Clicks: clicks,
|
||||
Cost: 0, // 广告位不记录消耗,只记录收入
|
||||
Revenue: revenue,
|
||||
CTR: ctr,
|
||||
// eCPM字段是未导出的,无法直接设置
|
||||
}
|
||||
|
||||
err = dao.AdStatistics.Upsert(ctx, statistics)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user