调整新增奖励

This commit is contained in:
chy
2025-06-30 14:29:36 +08:00
parent 9abd6940fd
commit 09e9ebe8c3
5 changed files with 43 additions and 17 deletions

View File

@ -13,6 +13,7 @@ import (
"server/internal/service"
"server/utility/ecode"
"server/utility/gamelife"
"strconv"
"time"
)
@ -76,6 +77,9 @@ func (s *sReward) Create(ctx context.Context, in *model.RewardCreateIn) (out *mo
}
}
// 券ID-根据时间戳生成
id := "Q" + strconv.FormatInt(time.Now().Unix(), 10)
// 创建奖励
_, err = dao.Rewards.Ctx(ctx).Data(do.Rewards{
StoreId: in.StoreId,
@ -94,6 +98,8 @@ func (s *sReward) Create(ctx context.Context, in *model.RewardCreateIn) (out *mo
GameId: in.GameId,
UserDailyLimit: in.UserDailyLimit,
UserTotalLimit: in.UserTotalLimit,
PrizeId: id,
Source: in.Source,
}).OmitEmptyData().Insert()
if err != nil {
@ -700,15 +706,14 @@ func (s *sReward) CallBack(ctx context.Context, in *model.RewardCallbackIn) (out
func (s *sReward) GetUserClaimList(ctx context.Context, in *model.GetUserClaimListIn) (out *model.GetUserClaimListOut, err error) {
// Initialize result slice
rewards := make([]model.Reward, 0)
rewards := make([]model.UserClaimReward, 0)
var totalCount int
var userTaskId int64
if in.UserTaskId == 0 {
value, err := dao.UserTasks.Ctx(ctx).
Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId}).
Fields(dao.UserTasks.Columns().Id).
Value()
Fields(dao.UserTasks.Columns().Id).Value()
if err != nil {
return nil, ecode.Fail.Sub("查询用户任务失败")
}
@ -744,7 +749,7 @@ func (s *sReward) GetUserClaimList(ctx context.Context, in *model.GetUserClaimLi
}
// Scan rewards
if err = query.Fields(fmt.Sprintf("%s.*", dao.Rewards.Table())).Scan(&rewards); err != nil {
if err = query.Fields(fmt.Sprintf("user_task_rewards.reward_id,reward_id, user_task_rewards.status reward_status,user_task_rewards.reward_name reward_name, rewards.*")).WithAll().Scan(&rewards); err != nil {
return nil, ecode.Fail.Sub("任务奖励获取失败")
}

View File

@ -33,6 +33,20 @@ type Reward struct {
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"删除时间(软删除)"` // 删除时间(软删除)
}
type SimpleReward struct {
g.Meta `orm:"table:rewards"`
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称
RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID关联 reward_types 表"` // 奖励类型ID关联 reward_types 表
Source int `json:"source" orm:"source" description:"奖励来源,1=系统奖励对接腾讯2=门店追加"` // 奖励来源,1=系统奖励对接腾讯2=门店追加
GameId int64 `json:"gameId" orm:"game_id" description:"游戏ID"` // 游戏ID
ImageUrl string `json:"imageUrl" orm:"image_url" description:"奖励图片链接"` // 奖励图片链接
ExpireType int `json:"expireType" orm:"expire_type" description:"过期方式1=时间段过期2=领取后过期"` // 过期方式1=时间段过期2=领取后过期
ValidFrom *gtime.Time `json:"validFrom" orm:"valid_from" description:"有效期开始时间expire_type=1时"` // 有效期开始时间expire_type=1时
ValidTo *gtime.Time `json:"validTo" orm:"valid_to" description:"有效期结束时间expire_type=1时"` // 有效期结束时间expire_type=1时
ExpireDays int `json:"expireDays" orm:"expire_days" description:"领取后多少天过期expire_type=2时"` // 领取后多少天过期expire_type=2时
}
// RewardCreateIn 创建奖励入参
type RewardCreateIn struct {

View File

@ -1,6 +1,9 @@
package model
import "github.com/gogf/gf/v2/os/gtime"
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
type GetUserClaimListIn struct {
UserId int64
@ -9,18 +12,9 @@ type GetUserClaimListIn struct {
NetbarAccount string
StoreId int64
}
type UserTaskReward struct {
RewardName string `json:"rewardName" orm:"reward_name"` // 奖励名称冗余字段
Source int `json:"source" orm:"source"` // 奖励来源1是系统奖励统一调用, 2是门店奖励
RewardType int `json:"rewardType" orm:"reward_type"` // 奖励类型, 实现不同的领取操作
Status int `json:"status" orm:"status"` // 状态1=待用户完成任务2=待领取3=已领取, 待兑换4=已过期5=发放失败, 6=结束、
ExpireType int `json:"expireType" orm:"expire_type"` // 过期方式1=时间段过期2=领取后过期
ValidFrom *gtime.Time `json:"validFrom" orm:"valid_from" ` // 有效期开始时间expire_type=1时
ValidTo *gtime.Time `json:"validTo" orm:"valid_to"` // 有效期结束时间expire_type=1时
ExpireDays int `json:"expireDays" orm:"expire_days"` // 领取后多少天过期expire_type=2时
}
type GetUserClaimListOut struct {
List []Reward
List []UserClaimReward
Total int
}
@ -38,3 +32,11 @@ type UserTaskRewards struct {
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间"` // 软删除时间
ExpiredAt *gtime.Time `json:"expiredAt" orm:"expired_at" description:"奖励过期时间"` // 奖励过期时间
}
type UserClaimReward struct {
g.Meta `orm:"table:user_task_rewards"`
RewardId int64 `json:"rewardId" orm:"reward_id"`
Status int64 `json:"status" orm:"reward_status"`
RewardName string `json:"rewardName" orm:"reward_name"`
SimpleReward SimpleReward `json:"reward" orm:"with:id=reward_id"`
}

View File

@ -4,7 +4,7 @@ import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
_ "server/utility/gamelife"
_ "server/utility/mqtt/emqx"
//_ "server/utility/mqtt/emqx"
_ "server/utility/myCasbin"
_ "server/utility/oss/aliyun"
_ "server/utility/rsa"