77 lines
1.8 KiB
Go
77 lines
1.8 KiB
Go
package carv
|
|
|
|
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 UnlockChapterLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 游戏主线解锁第x章节
|
|
func NewUnlockChapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnlockChapterLogic {
|
|
return &UnlockChapterLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UnlockChapterLogic) UnlockChapter(req *types.UnlockChapterReq) *types.CarvResult {
|
|
uid, errResult := l.svcCtx.GetUidByEmail(l.ctx, req.Email)
|
|
if errResult != nil {
|
|
return errResult
|
|
}
|
|
|
|
pb, err := l.svcCtx.PromoteBindModel.FindOneByInvitedUid(l.ctx, uid)
|
|
if err != nil {
|
|
if !errors.Is(err, model.ErrNotFound) {
|
|
return &types.CarvResult{
|
|
Error: &types.Error{
|
|
Code: int(errs.ErrDatabaseOperate),
|
|
Message: "system error",
|
|
},
|
|
}
|
|
}
|
|
return &types.CarvResult{
|
|
Result: &types.Result{IsValid: false},
|
|
}
|
|
}
|
|
|
|
shareId := l.svcCtx.ConfigModel.GetInviterId(l.ctx, consts.CarvIoInviterId)
|
|
|
|
if pb.ShareUid != shareId {
|
|
return &types.CarvResult{
|
|
Result: &types.Result{IsValid: false},
|
|
}
|
|
}
|
|
|
|
gp, err := l.svcCtx.GameReportModel.FindOneByUid(l.ctx, uid)
|
|
if err != nil {
|
|
if !errors.Is(err, model.ErrNotFound) {
|
|
return &types.CarvResult{
|
|
Error: &types.Error{
|
|
Code: int(errs.ErrDatabaseOperate),
|
|
Message: "system error",
|
|
},
|
|
}
|
|
}
|
|
return &types.CarvResult{Result: &types.Result{IsValid: false}}
|
|
}
|
|
if gp.Chapter >= req.Chapter {
|
|
return &types.CarvResult{Result: &types.Result{IsValid: true}}
|
|
}
|
|
return &types.CarvResult{Result: &types.Result{IsValid: false}}
|
|
}
|