2025-01-20 01:55:44 +08:00
|
|
|
package douyin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
2025-01-21 10:38:27 +08:00
|
|
|
"gitea.youtukeji.com.cn/xiabin/youtu_server/game_open_api/internal/svc"
|
2025-01-20 01:55:44 +08:00
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
|
|
|
|
type GetEcpmLogic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewGetEcpmLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEcpmLogic {
|
|
|
|
return &GetEcpmLogic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-01-20 10:10:08 +08:00
|
|
|
func (l *GetEcpmLogic) GetEcpm() (result bool, errNeverNil error) {
|
|
|
|
|
|
|
|
at, err := svc.GetCtxToken(l.ctx)
|
2025-01-20 01:55:44 +08:00
|
|
|
if err != nil {
|
2025-01-20 10:10:08 +08:00
|
|
|
errNeverNil = err
|
2025-01-20 01:55:44 +08:00
|
|
|
return
|
|
|
|
}
|
2025-01-21 16:48:55 +08:00
|
|
|
at.AppIdStr = "tt5bc32d7ec4f6ccb907"
|
|
|
|
at.OpenId = "_0005ITFnsqTvXpTC7wqg6yvQ1_mXhk1TbOv"
|
2025-01-20 01:55:44 +08:00
|
|
|
|
2025-01-21 16:48:55 +08:00
|
|
|
res, err := l.svcCtx.DouyinCli.GetEcpmData(at.AppIdStr, at.OpenId, time.Now().Format(time.DateOnly))
|
2025-01-20 01:55:44 +08:00
|
|
|
if err != nil {
|
|
|
|
l.Logger.Error(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-01-21 16:48:55 +08:00
|
|
|
ecpm, err := l.svcCtx.DouyinCli.GetEcpm(res)
|
2025-01-20 01:55:44 +08:00
|
|
|
if err != nil {
|
|
|
|
l.Logger.Error(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2025-01-21 16:48:55 +08:00
|
|
|
if ecpm > float64(l.svcCtx.DouyinCli.GetEcpmValue(at.AppIdStr)) && len(res) > int(l.svcCtx.DouyinCli.GetEcpmViewCount(at.AppIdStr)) {
|
2025-01-20 01:55:44 +08:00
|
|
|
result = true
|
|
|
|
} else {
|
|
|
|
result = false
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|