修改奖励配置新增过期类型和时间

This commit is contained in:
chy
2025-06-23 20:48:22 +08:00
parent 2c59949e87
commit 3166edc3dd
8 changed files with 94 additions and 26 deletions

View File

@ -2,6 +2,7 @@ package v1
import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
type ListReq struct {
@ -28,6 +29,10 @@ type CreateReq struct {
StoreId int64 `json:"storeId" dc:"门店ID"`
RewardTypeId int64 `json:"rewardTypeId" v:"required#奖励类型ID不能为空" dc:"奖励类型ID"`
Source int `json:"source" v:"in:1,2#来源只能为1或2" dc:"来源"`
ExpireType int `json:"expireType" v:"required#过期类型只能为1或2" dc:"过期类型"`
ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间expire_type=1 时使用)"`
ValidTo *gtime.Time `json:"validTo" dc:"有效结束时间expire_type=1 时使用)"`
ExpireDays int `json:"expireDays" dc:"领取后多少天过期"`
}
type CreateRes struct {
@ -42,6 +47,10 @@ type UpdateReq struct {
Value int64 `json:"value" v:"required#数值不能为空" dc:"奖励值"`
Status int `json:"status" dc:"状态" d:"1"`
StoreId int64 `json:"storeId" dc:"门店ID"`
ExpireType int `json:"expireType" dc:"过期类型" d:"1"`
ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间expire_type=1 时使用)"`
ValidTo *gtime.Time `json:"validTo" dc:"有效结束时间expire_type=1 时使用)"`
ExpireDays int `json:"expireDays" dc:"领取后多少天过期"`
}
type UpdateRes struct {

View File

@ -23,6 +23,10 @@ func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.C
StoreId: req.StoreId,
RewardTypeId: req.RewardTypeId,
Source: req.Source,
ExpireType: req.ExpireType,
ExpireDays: req.ExpireDays,
ValidFrom: req.ValidFrom,
ValidTo: req.ValidTo,
})
if err != nil {
return nil, err

View File

@ -22,6 +22,10 @@ func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.U
OperatorRole: operatorRole,
StoreId: req.StoreId,
Status: req.Status,
ExpireType: req.ExpireType,
ExpireDays: req.ExpireDays,
ValidFrom: req.ValidFrom,
ValidTo: req.ValidTo,
})
if err != nil {
return nil, err

View File

@ -34,6 +34,10 @@ type RewardsColumns struct {
DeletedAt string // 软删除时间戳
TotalNum string // 奖励总数量NULL表示不限量
UsedNum string // 已使用数量
ExpireType string // 过期类型1=时间段过期2=领取后多少天过期
ValidFrom string // 有效开始时间expire_type=1 时使用)
ValidTo string // 有效结束时间expire_type=1 时使用)
ExpireDays string // 领取后多少天过期expire_type=2 时使用)
}
// rewardsColumns holds the columns for the table rewards.
@ -51,6 +55,10 @@ var rewardsColumns = RewardsColumns{
DeletedAt: "deleted_at",
TotalNum: "total_num",
UsedNum: "used_num",
ExpireType: "expire_type",
ValidFrom: "valid_from",
ValidTo: "valid_to",
ExpireDays: "expire_days",
}
// NewRewardsDao creates and returns a new DAO object for table data access.

View File

@ -82,6 +82,10 @@ func (s *sReward) Create(ctx context.Context, in *model.RewardCreateIn) (out *mo
StoreId: in.StoreId,
Value: in.Value,
Status: in.Status,
ValidFrom: in.ValidFrom,
ValidTo: in.ValidTo,
ExpireType: in.ExpireType,
ExpireDays: in.ExpireDays,
}).OmitEmptyData().InsertAndGetId()
if err != nil {
return nil, err
@ -161,11 +165,30 @@ func (s *sReward) Update(ctx context.Context, in *model.RewardUpdateIn) (out *mo
Description: in.Description,
Value: in.Value,
Status: in.Status,
ValidFrom: in.ValidFrom,
ValidTo: in.ValidTo,
ExpireType: in.ExpireType,
ExpireDays: in.ExpireDays,
}).OmitEmptyData().Update()
if err != nil {
return nil, ecode.Fail.Sub("更新奖励失败")
}
// 判断过期类型
if in.ExpireType == 1 {
in.ExpireDays = 0
_, err = dao.Rewards.Ctx(ctx).Where(do.Rewards{Id: in.Id}).Update("expire_days = null")
if err != nil {
return nil, err
}
} else {
_, err = dao.Rewards.Ctx(ctx).Where(do.Rewards{Id: in.Id}).Update("valid_from = null,valid_to = null")
if err != nil {
return nil, err
}
}
return &model.RewardUpdateOut{Success: true}, nil
}

View File

@ -25,4 +25,8 @@ type Rewards struct {
DeletedAt *gtime.Time // 软删除时间戳
TotalNum interface{} // 奖励总数量NULL表示不限量
UsedNum interface{} // 已使用数量
ExpireType interface{} // 过期类型1=时间段过期2=领取后多少天过期
ValidFrom *gtime.Time // 有效开始时间expire_type=1 时使用)
ValidTo *gtime.Time // 有效结束时间expire_type=1 时使用)
ExpireDays interface{} // 领取后多少天过期expire_type=2 时使用)
}

View File

@ -23,4 +23,8 @@ type Rewards struct {
DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳
TotalNum uint64 `json:"totalNum" orm:"total_num" description:"奖励总数量NULL表示不限量"` // 奖励总数量NULL表示不限量
UsedNum uint64 `json:"usedNum" orm:"used_num" 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 时使用)
}

View File

@ -22,6 +22,10 @@ type Reward struct {
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间" orm:"created_at"`
UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间" orm:"updated_at"`
DeletedAt *gtime.Time `json:"deletedAt" dc:"软删除时间戳" orm:"deleted_at"`
ExpireType int `json:"expireType"` // 过期类型1=时间段过期2=领取后多少天过期
ValidFrom *gtime.Time `json:"validFrom"` // 有效开始时间expire_type=1 时使用)
ValidTo *gtime.Time `json:"validTo"` // 有效结束时间expire_type=1 时使用)
ExpireDays int `json:"expireDays"` // 领取后多少天过期expire_type=2 时使用)
}
// RewardCreateIn 创建奖励入参
@ -35,6 +39,10 @@ type RewardCreateIn struct {
StoreId int64
Value int64
Status int
ExpireType int
ExpireDays int
ValidFrom *gtime.Time
ValidTo *gtime.Time
}
// RewardCreateOut 创建奖励出参
@ -53,6 +61,10 @@ type RewardUpdateIn struct {
StoreId int64
Value int64
Status int
ExpireType int
ExpireDays int
ValidFrom *gtime.Time
ValidTo *gtime.Time
}
// RewardUpdateOut 更新奖励出参