修改奖励配置新增过期类型和时间
This commit is contained in:
@ -2,6 +2,7 @@ package v1
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
type ListReq struct {
|
||||
@ -21,13 +22,17 @@ type ListRes struct {
|
||||
|
||||
type CreateReq struct {
|
||||
g.Meta `path:"/reward" method:"post" tags:"Reward" summary:"(系统、商户、门店后台)创建奖励"`
|
||||
Name string `json:"name" v:"required#名称不能为空" dc:"名称"`
|
||||
Description string `json:"description" v:"required#描述不能为空" dc:"描述"`
|
||||
Value int64 `json:"value" v:"required#数值不能为空" dc:"奖励值"`
|
||||
Status int `json:"status" dc:"状态" d:"1"`
|
||||
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:"来源"`
|
||||
Name string `json:"name" v:"required#名称不能为空" dc:"名称"`
|
||||
Description string `json:"description" v:"required#描述不能为空" dc:"描述"`
|
||||
Value int64 `json:"value" v:"required#数值不能为空" dc:"奖励值"`
|
||||
Status int `json:"status" dc:"状态" d:"1"`
|
||||
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 {
|
||||
@ -36,12 +41,16 @@ type CreateRes struct {
|
||||
|
||||
type UpdateReq struct {
|
||||
g.Meta `path:"/reward" method:"put" tags:"Reward" summary:"(系统、商户、门店后台)更新奖励"`
|
||||
Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
|
||||
Name string `json:"name" v:"required#名称不能为空" dc:"名称"`
|
||||
Description string `json:"description" v:"required#描述不能为空" dc:"描述"`
|
||||
Value int64 `json:"value" v:"required#数值不能为空" dc:"奖励值"`
|
||||
Status int `json:"status" dc:"状态" d:"1"`
|
||||
StoreId int64 `json:"storeId" dc:"门店ID"`
|
||||
Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"`
|
||||
Name string `json:"name" v:"required#名称不能为空" dc:"名称"`
|
||||
Description string `json:"description" v:"required#描述不能为空" dc:"描述"`
|
||||
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 {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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 时使用)
|
||||
}
|
||||
|
||||
@ -10,17 +10,21 @@ import (
|
||||
|
||||
// Rewards is the golang structure for table rewards.
|
||||
type Rewards struct {
|
||||
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
|
||||
RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID"` // 奖励类型ID
|
||||
Name string `json:"name" orm:"name" description:"奖励名称(如100积分、5元优惠券)"` // 奖励名称(如100积分、5元优惠券)
|
||||
Description string `json:"description" orm:"description" description:"奖励描述"` // 奖励描述
|
||||
Source int `json:"source" orm:"source" description:"来源:1=系统内置,2=门店自定义"` // 来源:1=系统内置,2=门店自定义
|
||||
StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID,系统内置奖励为NULL"` // 门店ID,系统内置奖励为NULL
|
||||
Value uint64 `json:"value" orm:"value" description:"奖励值(如积分数额、优惠金额)"` // 奖励值(如积分数额、优惠金额)
|
||||
Status int `json:"status" orm:"status" description:"状态:1=正常,2=禁用"` // 状态:1=正常,2=禁用
|
||||
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
|
||||
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:"已使用数量"` // 已使用数量
|
||||
Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
|
||||
RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID"` // 奖励类型ID
|
||||
Name string `json:"name" orm:"name" description:"奖励名称(如100积分、5元优惠券)"` // 奖励名称(如100积分、5元优惠券)
|
||||
Description string `json:"description" orm:"description" description:"奖励描述"` // 奖励描述
|
||||
Source int `json:"source" orm:"source" description:"来源:1=系统内置,2=门店自定义"` // 来源:1=系统内置,2=门店自定义
|
||||
StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID,系统内置奖励为NULL"` // 门店ID,系统内置奖励为NULL
|
||||
Value uint64 `json:"value" orm:"value" description:"奖励值(如积分数额、优惠金额)"` // 奖励值(如积分数额、优惠金额)
|
||||
Status int `json:"status" orm:"status" description:"状态:1=正常,2=禁用"` // 状态:1=正常,2=禁用
|
||||
CreatedAt *gtime.Time `json:"createdAt" orm:"created_at" description:"创建时间"` // 创建时间
|
||||
UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间
|
||||
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 时使用)
|
||||
}
|
||||
|
||||
@ -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 更新奖励出参
|
||||
|
||||
Reference in New Issue
Block a user