增加社区列表接口,任务相关接口修改
This commit is contained in:
61
internal/job/earn/earn.go
Normal file
61
internal/job/earn/earn.go
Normal file
@@ -0,0 +1,61 @@
|
||||
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"
|
||||
)
|
||||
|
||||
// Earn 用户数据上报earn平台定时任务
|
||||
type Earn struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewEarn(ctx context.Context, svcCtx *svc.ServiceContext) *Earn {
|
||||
e := &Earn{ctx: ctx, svcCtx: svcCtx}
|
||||
e.Run()
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *Earn) Spec() string {
|
||||
return "@every 5m"
|
||||
}
|
||||
|
||||
func (e *Earn) Run() {
|
||||
e.pushUserInfo(666)
|
||||
e.pushUserBind()
|
||||
}
|
||||
|
||||
func (e *Earn) pushUserInfo(shareId uint) {
|
||||
us, err := e.svcCtx.PromoteBindModel.FindRequirePushUser(e.ctx, shareId)
|
||||
if err != nil {
|
||||
logx.Errorw("find require push user failed", logx.Field("err", err), logx.Field("share_id", shareId))
|
||||
return
|
||||
}
|
||||
for _, u := range us {
|
||||
ui, err := e.svcCtx.UserModel.FindOne(e.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 := e.svcCtx.TwitterModel.FindOne(e.ctx, u.InvitedUid)
|
||||
if err == nil {
|
||||
twitterId = ut.TwitterId
|
||||
}
|
||||
|
||||
e.svcCtx.Earn.SetIdentifiers(cast.ToString(ui.Id), &ea.Identifiers{
|
||||
Email: ea.IdentifierFrom(ui.Email),
|
||||
TwitterId: ea.IdentifierFrom(twitterId),
|
||||
})
|
||||
err = e.svcCtx.PromoteBindModel.UpdatePushUser(e.ctx, u.Id)
|
||||
if err != nil {
|
||||
logx.Errorw("update push user failed", logx.Field("err", err), logx.Field("uid", u.InvitedUid))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Earn) pushUserBind() {}
|
||||
Reference in New Issue
Block a user