72 lines
2.3 KiB
Go
72 lines
2.3 KiB
Go
package earn
|
|
|
|
import (
|
|
"context"
|
|
ea "github.com/earn-alliance/earnalliance-go"
|
|
"github.com/spf13/cast"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"nova_task/internal/svc"
|
|
)
|
|
|
|
type DataReportLogic struct {
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewDataReportLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DataReportLogic {
|
|
return &DataReportLogic{
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *DataReportLogic) PushUserInfo(shareId uint) {
|
|
us, err := l.svcCtx.PromoteBindModel.FindRequirePushUser(l.ctx, shareId)
|
|
if err != nil {
|
|
logx.Errorw("find require push user failed", logx.Field("err", err), logx.Field("share_id", shareId))
|
|
return
|
|
}
|
|
logx.Debugw("find require push user", logx.Field("count", len(us)))
|
|
for _, u := range us {
|
|
ui, err := l.svcCtx.UserModel.FindOne(l.ctx, u.InvitedUid)
|
|
if err != nil {
|
|
logx.Errorw("find user failed", logx.Field("err", err), logx.Field("uid", u.InvitedUid))
|
|
continue
|
|
}
|
|
var twitterId string
|
|
ut, err := l.svcCtx.TwitterModel.FindOne(l.ctx, u.InvitedUid)
|
|
if err == nil {
|
|
twitterId = ut.TwitterId
|
|
}
|
|
|
|
err = l.svcCtx.PromoteBindModel.UpdatePushUser(l.ctx, u.Id)
|
|
if err != nil {
|
|
logx.Errorw("update push user failed", logx.Field("err", err), logx.Field("uid", u.InvitedUid), logx.Field("twitter_id", twitterId), logx.Field("email", ui.Email))
|
|
} else {
|
|
l.svcCtx.Earn.SetIdentifiers(cast.ToString(ui.Id), &ea.Identifiers{
|
|
Email: ea.IdentifierFrom(ui.Email),
|
|
TwitterId: ea.IdentifierFrom(twitterId),
|
|
})
|
|
logx.Infow("push user info success", logx.Field("uid", u.InvitedUid), logx.Field("twitter_id", twitterId), logx.Field("email", ui.Email))
|
|
}
|
|
}
|
|
}
|
|
|
|
func (l *DataReportLogic) PushUserBind(shareId uint) {
|
|
us, err := l.svcCtx.TouristBindModel.FindRequirePushUser(l.ctx, shareId)
|
|
if err != nil {
|
|
logx.Errorw("find require push bind role user failed", logx.Field("err", err), logx.Field("share_id", shareId))
|
|
return
|
|
}
|
|
logx.Debugw("find require push bind role user", logx.Field("count", len(us)))
|
|
for _, u := range us {
|
|
err = l.svcCtx.PromoteBindModel.UpdatePushRole(l.ctx, u.Id)
|
|
if err != nil {
|
|
logx.Errorw("update push user failed", logx.Field("err", err), logx.Field("uid", u.Uid))
|
|
} else {
|
|
l.svcCtx.Earn.Track(cast.ToString(u.Uid), "BIND_ROLE", nil, nil)
|
|
logx.Infow("push user info success", logx.Field("uid", u.Uid))
|
|
}
|
|
}
|
|
}
|