email reward
This commit is contained in:
42
internal/logic/admin/add_email_reward_logic.go
Normal file
42
internal/logic/admin/add_email_reward_logic.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/shopspring/decimal"
|
||||
"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 AddEmailRewardLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 每日钱包签到任务
|
||||
func NewAddEmailRewardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddEmailRewardLogic {
|
||||
return &AddEmailRewardLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AddEmailRewardLogic) AddEmailReward(req *types.EmailReward) error {
|
||||
_, err := l.svcCtx.EmailRewardModel.Insert(l.ctx, &model.NhEmailReward{
|
||||
Email: req.Email,
|
||||
RewardType: req.RewardType,
|
||||
Value: decimal.NewFromFloat(req.Value),
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("add email reward failed", logx.Field("err", err), logx.Field("email", req.Email))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
|
||||
return errs.Success()
|
||||
}
|
||||
84
internal/logic/admin/send_email_reward_logic.go
Normal file
84
internal/logic/admin/send_email_reward_logic.go
Normal file
@@ -0,0 +1,84 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/zeromicro/go-zero/core/threading"
|
||||
"nova_task/internal/model"
|
||||
"nova_task/internal/pkg/errs"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"nova_task/internal/svc"
|
||||
)
|
||||
|
||||
type SendEmailRewardLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 执行发放奖励操作
|
||||
func NewSendEmailRewardLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendEmailRewardLogic {
|
||||
return &SendEmailRewardLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *SendEmailRewardLogic) SendEmailReward() error {
|
||||
rewards, err := l.svcCtx.EmailRewardModel.AllRequireSend(l.ctx)
|
||||
if err != nil {
|
||||
l.Errorw("get email reward failed", logx.Field("err", err))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
|
||||
if len(rewards) <= 0 {
|
||||
return errs.Success()
|
||||
}
|
||||
|
||||
threading.GoSafe(func() {
|
||||
ctx := context.Background()
|
||||
for _, rw := range rewards {
|
||||
u, err := l.svcCtx.UserModel.FindOneByEmail(ctx, rw.Email)
|
||||
if err != nil {
|
||||
l.Errorw("find user failed", logx.Field("err", err), logx.Field("email", rw.Email))
|
||||
continue
|
||||
}
|
||||
|
||||
err = l.svcCtx.EmailRewardModel.SetSent(ctx, rw.Id, u.Id)
|
||||
if err != nil {
|
||||
l.Errorw("set sent failed", logx.Field("err", err), logx.Field("id", rw.Id), logx.Field("uid", u.Id))
|
||||
continue
|
||||
}
|
||||
|
||||
// points,elite_points,castile,keys
|
||||
switch strings.ToLower(rw.RewardType) {
|
||||
case "points":
|
||||
err = l.svcCtx.TaskAssetModel.AddPoint(ctx, u.Id, rw.Value)
|
||||
case "elite_points":
|
||||
err = l.svcCtx.TaskAssetModel.AddElitePoints(ctx, u.Id, rw.Value)
|
||||
case "castile":
|
||||
err = l.svcCtx.TaskAssetModel.AddCastile(ctx, u.Id, rw.Value)
|
||||
case "keys":
|
||||
err = l.svcCtx.TaskAssetModel.AddKeys(ctx, u.Id, int(rw.Value.IntPart()))
|
||||
}
|
||||
if err != nil {
|
||||
l.Errorw("add asset failed", logx.Field("err", err), logx.Field("uid", u.Id), logx.Field("rewardType", rw.RewardType), logx.Field("value", rw.Value))
|
||||
}
|
||||
_, err = l.svcCtx.TaskAssetRecordModel.Insert(ctx, &model.NhTaskAssetRecord{
|
||||
Uid: int(u.Id),
|
||||
AssetField: rw.RewardType,
|
||||
Count: rw.Value.InexactFloat64(),
|
||||
Remark: rw.Remark,
|
||||
CreateTime: int(time.Now().Unix()),
|
||||
})
|
||||
if err != nil {
|
||||
l.Errorw("insert task asset record failed", logx.Field("err", err), logx.Field("uid", u.Id), logx.Field("rewardType", rw.RewardType), logx.Field("value", rw.Value))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
31
internal/logic/carv/bind_wallet_logic.go
Normal file
31
internal/logic/carv/bind_wallet_logic.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package carv
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"nova_task/internal/svc"
|
||||
"nova_task/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type BindWalletLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 注册绑定钱包任务
|
||||
func NewBindWalletLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BindWalletLogic {
|
||||
return &BindWalletLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *BindWalletLogic) BindWallet(req *types.EmailKey) (resp *types.CarvResult, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
31
internal/logic/carv/download_and_bind_role_logic.go
Normal file
31
internal/logic/carv/download_and_bind_role_logic.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package carv
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"nova_task/internal/svc"
|
||||
"nova_task/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DownloadAndBindRoleLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 下载并绑定Castile游戏角色
|
||||
func NewDownloadAndBindRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DownloadAndBindRoleLogic {
|
||||
return &DownloadAndBindRoleLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DownloadAndBindRoleLogic) DownloadAndBindRole(req *types.EmailKey) (resp *types.CarvResult, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
31
internal/logic/carv/unlock_chapter_logic.go
Normal file
31
internal/logic/carv/unlock_chapter_logic.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package carv
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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) (resp *types.CarvResult, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
31
internal/logic/carv/wallet_check_in_logic.go
Normal file
31
internal/logic/carv/wallet_check_in_logic.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package carv
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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) (resp *types.CarvResult, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
@@ -29,13 +29,24 @@ func NewStakeNftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StakeNft
|
||||
|
||||
func (l *StakeNftLogic) StakeNft(req *types.StakeNftList) error {
|
||||
uid := utils.GetUidUint(l.ctx)
|
||||
err := l.svcCtx.StakeNftModel.StakeNft(l.ctx, uid, req.RoleId, req.TokenIds)
|
||||
if err != nil {
|
||||
l.Errorw("stake nft failed", logx.Field("err", err), logx.Field("uid", uid), logx.Field("tokenIds", req.TokenIds))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
|
||||
for _, tokenId := range req.TokenIds {
|
||||
tkHolder, err := l.svcCtx.NftHolderModel.FindOneByTokenId(l.ctx, tokenId)
|
||||
if err != nil {
|
||||
if errors.Is(err, model.ErrNotFound) {
|
||||
l.Errorw("find nft holder not exist", logx.Field("err", err), logx.Field("uid", uid), logx.Field("tokenId", tokenId))
|
||||
continue
|
||||
}
|
||||
l.Errorw("find nft holder failed", logx.Field("err", err), logx.Field("uid", uid), logx.Field("tokenId", tokenId))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
l.svcCtx.WalletModel.FindUidByAddress(l.ctx, tkHolder.Address)
|
||||
err = l.svcCtx.StakeNftModel.StakeNft(l.ctx, uid, req.RoleId, tokenId)
|
||||
if err != nil {
|
||||
l.Errorw("stake nft failed", logx.Field("err", err), logx.Field("uid", uid), logx.Field("tokenIds", req.TokenIds))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
}
|
||||
|
||||
var sns []int8
|
||||
var propertyId string
|
||||
if utils.IsBigTarot(tokenId) {
|
||||
@@ -50,7 +61,7 @@ func (l *StakeNftLogic) StakeNft(req *types.StakeNftList) error {
|
||||
Uid: uid,
|
||||
RoleId: int64(req.RoleId),
|
||||
TokenId: cast.ToUint(tokenId),
|
||||
PropertyId: "",
|
||||
PropertyId: propertyId,
|
||||
Sn: sn,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,7 @@ func NewUnStakeNftLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnStak
|
||||
|
||||
func (l *UnStakeNftLogic) UnStakeNft(req *types.UnStakeNftReq) error {
|
||||
uid := utils.GetUidUint(l.ctx)
|
||||
err := l.svcCtx.StakeNftModel.UnStakeNft(l.ctx, uid, req.TokenId)
|
||||
err := l.svcCtx.StakeNftModel.UnStakeNft(l.ctx, uid, req.TokenId, false)
|
||||
if err != nil {
|
||||
l.Errorw("unstake nft failed", logx.Field("err", err), logx.Field("uid", uid), logx.Field("tokenIds", req.TokenId))
|
||||
return errs.New(errs.ErrDatabaseOperate, err)
|
||||
|
||||
Reference in New Issue
Block a user