103 lines
2.2 KiB
Go
103 lines
2.2 KiB
Go
package carv
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"github.com/spf13/cast"
|
|
"nova_task/internal/model"
|
|
"nova_task/internal/pkg/errs"
|
|
"time"
|
|
|
|
"nova_task/internal/svc"
|
|
"nova_task/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type WalletCheckInLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 每日钱包签到任务
|
|
func NewWalletCheckInLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WalletCheckInLogic {
|
|
return &WalletCheckInLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *WalletCheckInLogic) WalletCheckIn(req *types.EmailKey) *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.GetCarvIoInviterId(l.ctx)
|
|
|
|
if pb.ShareUid != shareId {
|
|
return &types.CarvResult{
|
|
Result: &types.Result{IsValid: false},
|
|
}
|
|
}
|
|
|
|
task, err := l.svcCtx.TaskModel.FindDailyPayTask(l.ctx)
|
|
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{
|
|
Error: &types.Error{
|
|
Code: int(errs.ErrTaskNotFound),
|
|
Message: "task not exist",
|
|
},
|
|
}
|
|
}
|
|
taskSeq := cast.ToInt(time.Now().Format("20060102"))
|
|
tp, err := l.svcCtx.TaskProgressModel.FindOneByUidTaskIdTaskSeq(l.ctx, int(uid), task.Id, taskSeq)
|
|
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 tp.Stage >= model.TASK_PROGRESS_WAIT_REWARD {
|
|
return &types.CarvResult{
|
|
Result: &types.Result{IsValid: true},
|
|
}
|
|
}
|
|
|
|
return &types.CarvResult{
|
|
Result: &types.Result{IsValid: false},
|
|
}
|
|
}
|