56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package douyin
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
"youtu_server/game_open_api/internal/app_api_helper"
|
|
|
|
"youtu_server/game_open_api/internal/svc"
|
|
"youtu_server/game_open_api/internal/types"
|
|
|
|
"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 {
|
|
app_api_helper.Init(ctx, svcCtx.AppAccount)
|
|
return &GetEcpmLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *GetEcpmLogic) GetEcpm(req *types.GetEcpmRequest) (result bool, errNeverNil error) {
|
|
user, err := l.svcCtx.AppUser.FindOne(l.ctx, req.UserId)
|
|
if err != nil {
|
|
l.Logger.Error(err.Error())
|
|
return
|
|
}
|
|
|
|
res, err := app_api_helper.DouyinCli.GetEcpmData(req.AppId, user.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(req.AppId)) && len(res) > int(app_api_helper.DouyinCli.GetEcpmViewCount(req.AppId)) {
|
|
result = true
|
|
} else {
|
|
result = false
|
|
}
|
|
|
|
return
|
|
}
|