72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package kgen
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"nova_task/internal/consts"
|
|
"nova_task/internal/model"
|
|
"nova_task/internal/pkg/errs"
|
|
|
|
"nova_task/internal/svc"
|
|
"nova_task/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type KGeNTaskCheckLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewKGeNTaskCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) *KGeNTaskCheckLogic {
|
|
return &KGeNTaskCheckLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *KGeNTaskCheckLogic) KGeNTaskCheck(req *types.KGeNTaskCheckReq) (resp *types.KGeNResultData, err error) {
|
|
uid, resultErr := l.svcCtx.GetUidByEmail(l.ctx, req.Email)
|
|
if resultErr != nil {
|
|
if resultErr.Error.Code == int(errs.ErrUserNotFound) {
|
|
return &types.KGeNResultData{
|
|
IsValid: false,
|
|
}, nil
|
|
}
|
|
return nil, errs.New(errs.Reason(resultErr.Error.Code), resultErr.Error.Message)
|
|
}
|
|
|
|
pb, err := l.svcCtx.PromoteBindModel.FindOneByInvitedUid(l.ctx, uid)
|
|
if err != nil {
|
|
if !errors.Is(err, model.ErrNotFound) {
|
|
return nil, errs.New(errs.ErrDatabaseOperate, err)
|
|
}
|
|
return &types.KGeNResultData{
|
|
IsValid: false,
|
|
}, nil
|
|
}
|
|
|
|
shareId := l.svcCtx.ConfigModel.GetInviterId(l.ctx, consts.KgenIoInviterId)
|
|
|
|
if pb.ShareUid != shareId {
|
|
return &types.KGeNResultData{
|
|
IsValid: false,
|
|
}, nil
|
|
}
|
|
|
|
var isValid bool
|
|
// 1.在官网注册(是否) 2.链接钱包(是否) 3.下载并绑定游戏账号(是否)
|
|
switch req.Type {
|
|
case 1:
|
|
isValid = true
|
|
case 2:
|
|
isValid = pb.IsBindWallet == 1
|
|
case 3:
|
|
isValid = pb.IsCreateRole == 1
|
|
}
|
|
|
|
return &types.KGeNResultData{IsValid: isValid}, nil
|
|
}
|