2025-01-20 10:10:08 +08:00

55 lines
1.1 KiB
Go

package douyin
import (
"context"
"time"
"youtu_server/game_open_api/internal/app_api_helper"
"github.com/zeromicro/go-zero/core/logx"
"youtu_server/game_open_api/internal/svc"
)
type GetEcpmLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetEcpmLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEcpmLogic {
app_api_helper.Init(ctx, svcCtx.AppAccount)
return &GetEcpmLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetEcpmLogic) GetEcpm() (result bool, errNeverNil error) {
at, err := svc.GetCtxToken(l.ctx)
if err != nil {
errNeverNil = err
return
}
res, err := app_api_helper.DouyinCli.GetEcpmData(at.AppIdStr, at.OpenId, time.Now().Format(time.DateOnly))
if err != nil {
l.Logger.Error(err.Error())
return
}
ecpm, err := app_api_helper.DouyinCli.GetEcpm(res)
if err != nil {
l.Logger.Error(err.Error())
return
}
if ecpm > float64(app_api_helper.DouyinCli.GetEcpmValue(at.AppIdStr)) && len(res) > int(app_api_helper.DouyinCli.GetEcpmViewCount(at.AppIdStr)) {
result = true
} else {
result = false
}
return
}