调整奖励接口

This commit is contained in:
chy
2025-06-24 21:15:14 +08:00
parent 1c0b9a2d93
commit cef90a65b5
23 changed files with 522 additions and 257 deletions

View File

@ -21,36 +21,51 @@ type ListRes struct {
} }
type CreateReq struct { type CreateReq struct {
g.Meta `path:"/reward" method:"post" tags:"Reward" summary:"(系统、商户、门店后台)创建奖励"` g.Meta `path:"/reward" method:"post" tags:"Reward" summary:"(系统、商户、门店后台)创建奖励"`
Name string `json:"name" v:"required#名称不能为空" dc:"名称"` StoreId int64 `json:"storeId" dc:"门店ID"`
Description string `json:"description" v:"required#描述不能为空" dc:"描述"` Name string `json:"name" v:"required#名称不能为空" dc:"名称"`
Value int64 `json:"value" v:"required#数值不能为空" dc:"奖励"` RewardTypeId int64 `json:"rewardTypeId" v:"required#奖励类型ID不能为空" dc:"奖励类型ID"`
Status int `json:"status" dc:"状态" d:"1"` GameId int64 `json:"gameId" v:"required#游戏ID不能为空" dc:"游戏ID"`
StoreId int64 `json:"storeId" dc:"门店ID"` RewardImg string `json:"rewardImg" dc:"奖励图片"`
RewardTypeId int64 `json:"rewardTypeId" v:"required#奖励类型ID不能为空" dc:"奖励类型ID"` QQGoodsId string `json:"qqGoodsId" v:"required#不能为空" dc:"QQ网吧物品ID"`
Source int `json:"source" v:"in:1,2#来源只能为1或2" dc:"来源"` QQGoodsIdStr string `json:"qqGoodsIdStr" v:"required#不能为空" dc:"QQ网吧物品ID字符串"`
ExpireType int `json:"expireType" v:"required#过期类型只能为1或2" dc:"过期类型"` Status int `json:"status" dc:"状态" d:"1启用 2禁用"`
ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间expire_type=1 时使用)"` ExpireType int `json:"expireType" v:"required#过期类型只能为1或2" dc:"过期类型"`
ValidTo *gtime.Time `json:"validTo" dc:"有效结束时间expire_type=1 时使用)"` ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间expire_type=1 时使用)"`
ExpireDays int `json:"expireDays" dc:"领取后多少天过期"` ValidTo *gtime.Time `json:"validTo" dc:"有效结束时间expire_type=1 时使用)"`
ExpireDays int `json:"expireDays" dc:"领取后多少天过期"`
DailyTotalLimit int `json:"dailyTotalLimit" v:"required#每日领取总次数限制" dc:"每日领取总次数限制"`
TotalLimit int `json:"totalLimit" v:"required#奖励总限不能为空" dc:"领取总次数限制"`
UserDailyLimit int `json:"userDailyLimit" v:"required#用户每日领取总次数限制" dc:"用户每日领取总次数限制"`
UserTotalLimit int `json:"userTotalLimit" v:"required#用户领取总次数限制" dc:"用户领取总次数限制"`
GrantQuantify int `json:"grantQuantify" v:"required#发放数量不能为空" dc:"发放数量"`
Source int `json:"source" v:"required#来源不能为空" dc:"来源" d:"1"`
} }
type CreateRes struct { type CreateRes struct {
Id int64 `json:"id" dc:"奖励ID"` Success bool `json:"success" dc:"是否成功"`
} }
type UpdateReq struct { type UpdateReq struct {
g.Meta `path:"/reward" method:"put" tags:"Reward" summary:"(系统、商户、门店后台)更新奖励"` g.Meta `path:"/reward" method:"put" tags:"Reward" summary:"(系统、商户、门店后台)更新奖励"`
Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"` Id int64 `json:"id" v:"required#id不能为空" dc:"ID"`
Name string `json:"name" v:"required#名称不能为空" dc:"名称"` Name string `json:"name" dc:"名称"`
Description string `json:"description" v:"required#描述不能为空" dc:"描述"` RewardType int `json:"rewardType" dc:"奖励类型"`
Value int64 `json:"value" v:"required#数值不能为空" dc:"奖励值"` GameId int64 `json:"gameId" dc:"游戏id"`
Status int `json:"status" dc:"状态" d:"1"` Img string `json:"img" dc:"图片"`
StoreId int64 `json:"storeId" dc:"门店ID"` QQGoodsId string `json:"qqGoodsId" dc:"qq商品id"`
ExpireType int `json:"expireType" dc:"过期类型" d:"1"` QQGoodsIdStr string `json:"qqGoodsIdStr" dc:"qq商品id"`
ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间expire_type=1 时使用)"` Status int `json:"status" dc:"状态" d:"1"`
ValidTo *gtime.Time `json:"validTo" dc:"有效结束时间(expire_type=1 时使用)"` ExpireType int `json:"expireType" dc:"过期类型" d:"1"`
ExpireDays int `json:"expireDays" dc:"领取后多少天过期"` ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间expire_type=1 时使用)"`
ValidTo *gtime.Time `json:"validTo" dc:"有效结束时间expire_type=1 时使用)"`
ExpireDays int `json:"expireDays" dc:"领取后多少天过期"`
DailyTotalLimit int `json:"dailyTotalLimit" dc:"每日领取总次数限制"`
TotalLimit int `json:"totalLimit" dc:"领取总次数限制"`
UserDailyLimit int `json:"userDailyLimit" dc:"用户每日领取总次数限制"`
UserTotalLimit int `json:"userTotalLimit" dc:"用户领取总次数限制"`
GrantQuantify int `json:"grantQuantify" dc:"发放数量"`
Source int `json:"source" v:"required#来源不能为空" dc:"来源" d:"1"`
} }
type UpdateRes struct { type UpdateRes struct {
@ -60,6 +75,7 @@ type UpdateRes struct {
type DeleteReq struct { type DeleteReq struct {
g.Meta `path:"/reward/{id}" method:"delete" tags:"Reward" summary:"(系统、商户、门店后台)删除奖励"` g.Meta `path:"/reward/{id}" method:"delete" tags:"Reward" summary:"(系统、商户、门店后台)删除奖励"`
Id int64 `in:"path" json:"id" v:"required#ID不能为空" dc:"ID"` Id int64 `in:"path" json:"id" v:"required#ID不能为空" dc:"ID"`
Source int `json:"source" v:"required#来源不能为空" dc:"来源" d:"1"`
} }
type DeleteRes struct { type DeleteRes struct {

View File

@ -14,22 +14,30 @@ func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.C
operatorId := fromCtx.GetCtxVar("id").Int64() operatorId := fromCtx.GetCtxVar("id").Int64()
operatorRole := fromCtx.GetCtxVar("role").String() operatorRole := fromCtx.GetCtxVar("role").String()
out, err := service.Reward().Create(ctx, &model.RewardCreateIn{ out, err := service.Reward().Create(ctx, &model.RewardCreateIn{
Name: req.Name, StoreId: req.StoreId,
Description: req.Description, Name: req.Name,
Value: req.Value, RewardTypeId: req.RewardTypeId,
Status: req.Status, GameId: req.GameId,
OperatorId: operatorId, Img: req.RewardImg,
OperatorRole: operatorRole, QQGoodsId: req.QQGoodsId,
StoreId: req.StoreId, QQGoodsIdStr: req.QQGoodsIdStr,
RewardTypeId: req.RewardTypeId, Status: req.Status,
Source: req.Source, OperatorId: operatorId,
ExpireType: req.ExpireType, OperatorRole: operatorRole,
ExpireDays: req.ExpireDays, ExpireType: req.ExpireType,
ValidFrom: req.ValidFrom, ExpireDays: req.ExpireDays,
ValidTo: req.ValidTo, ValidFrom: req.ValidFrom,
ValidTo: req.ValidTo,
DailyTotalLimit: int64(req.DailyTotalLimit),
TotalLimit: int64(req.TotalLimit),
UserDailyLimit: int64(req.UserDailyLimit),
UserTotalLimit: int64(req.UserTotalLimit),
GrantQuantity: int64(req.GrantQuantify),
Source: req.Source,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &v1.CreateRes{Id: out.Id}, nil return &v1.CreateRes{Success: out.Success}, nil
} }

View File

@ -13,7 +13,7 @@ func (c *ControllerV1) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.D
fromCtx := g.RequestFromCtx(ctx) fromCtx := g.RequestFromCtx(ctx)
operatorId := fromCtx.GetCtxVar("id").Int64() operatorId := fromCtx.GetCtxVar("id").Int64()
operatorRole := fromCtx.GetCtxVar("role").String() operatorRole := fromCtx.GetCtxVar("role").String()
out, err := service.Reward().Delete(ctx, &model.RewardDeleteIn{Id: req.Id, OperatorId: operatorId, OperatorRole: operatorRole}) out, err := service.Reward().Delete(ctx, &model.RewardDeleteIn{Id: req.Id, OperatorId: operatorId, OperatorRole: operatorRole, Source: req.Source})
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -14,18 +14,26 @@ func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.U
operatorId := fromCtx.GetCtxVar("id").Int64() operatorId := fromCtx.GetCtxVar("id").Int64()
operatorRole := fromCtx.GetCtxVar("role").String() operatorRole := fromCtx.GetCtxVar("role").String()
out, err := service.Reward().Update(ctx, &model.RewardUpdateIn{ out, err := service.Reward().Update(ctx, &model.RewardUpdateIn{
Id: req.Id, Id: req.Id,
Name: req.Name, Name: req.Name,
Description: req.Description, RewardTypeId: int64(req.RewardType),
Value: req.Value, GameId: req.GameId,
OperatorId: operatorId, Img: req.Img,
OperatorRole: operatorRole, QQGoodsId: req.QQGoodsId,
StoreId: req.StoreId, QQGoodsIdStr: req.QQGoodsIdStr,
Status: req.Status, OperatorId: operatorId,
ExpireType: req.ExpireType, OperatorRole: operatorRole,
ExpireDays: req.ExpireDays, Status: req.Status,
ValidFrom: req.ValidFrom, ExpireType: req.ExpireType,
ValidTo: req.ValidTo, ExpireDays: req.ExpireDays,
ValidFrom: req.ValidFrom,
ValidTo: req.ValidTo,
DailyTotalLimit: int64(req.DailyTotalLimit),
TotalLimit: int64(req.TotalLimit),
UserDailyLimit: int64(req.UserDailyLimit),
UserTotalLimit: int64(req.UserTotalLimit),
GrantQuantity: int64(req.GrantQuantify),
Source: req.Source,
}) })
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -13,9 +13,10 @@ import (
// AdminsDao is the data access object for the table admins. // AdminsDao is the data access object for the table admins.
type AdminsDao struct { type AdminsDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns AdminsColumns // columns contains all the column names of Table for convenient usage. columns AdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// AdminsColumns defines and stores column names for the table admins. // AdminsColumns defines and stores column names for the table admins.
@ -49,11 +50,12 @@ var adminsColumns = AdminsColumns{
} }
// NewAdminsDao creates and returns a new DAO object for table data access. // NewAdminsDao creates and returns a new DAO object for table data access.
func NewAdminsDao() *AdminsDao { func NewAdminsDao(handlers ...gdb.ModelHandler) *AdminsDao {
return &AdminsDao{ return &AdminsDao{
group: "default", group: "default",
table: "admins", table: "admins",
columns: adminsColumns, columns: adminsColumns,
handlers: handlers,
} }
} }
@ -79,7 +81,11 @@ func (dao *AdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *AdminsDao) Ctx(ctx context.Context) *gdb.Model { func (dao *AdminsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// FeedbacksDao is the data access object for the table feedbacks. // FeedbacksDao is the data access object for the table feedbacks.
type FeedbacksDao struct { type FeedbacksDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns FeedbacksColumns // columns contains all the column names of Table for convenient usage. columns FeedbacksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// FeedbacksColumns defines and stores column names for the table feedbacks. // FeedbacksColumns defines and stores column names for the table feedbacks.
@ -51,11 +52,12 @@ var feedbacksColumns = FeedbacksColumns{
} }
// NewFeedbacksDao creates and returns a new DAO object for table data access. // NewFeedbacksDao creates and returns a new DAO object for table data access.
func NewFeedbacksDao() *FeedbacksDao { func NewFeedbacksDao(handlers ...gdb.ModelHandler) *FeedbacksDao {
return &FeedbacksDao{ return &FeedbacksDao{
group: "default", group: "default",
table: "feedbacks", table: "feedbacks",
columns: feedbacksColumns, columns: feedbacksColumns,
handlers: handlers,
} }
} }
@ -81,7 +83,11 @@ func (dao *FeedbacksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *FeedbacksDao) Ctx(ctx context.Context) *gdb.Model { func (dao *FeedbacksDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// GamesDao is the data access object for the table games. // GamesDao is the data access object for the table games.
type GamesDao struct { type GamesDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns GamesColumns // columns contains all the column names of Table for convenient usage. columns GamesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// GamesColumns defines and stores column names for the table games. // GamesColumns defines and stores column names for the table games.
@ -45,11 +46,12 @@ var gamesColumns = GamesColumns{
} }
// NewGamesDao creates and returns a new DAO object for table data access. // NewGamesDao creates and returns a new DAO object for table data access.
func NewGamesDao() *GamesDao { func NewGamesDao(handlers ...gdb.ModelHandler) *GamesDao {
return &GamesDao{ return &GamesDao{
group: "default", group: "default",
table: "games", table: "games",
columns: gamesColumns, columns: gamesColumns,
handlers: handlers,
} }
} }
@ -75,7 +77,11 @@ func (dao *GamesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *GamesDao) Ctx(ctx context.Context) *gdb.Model { func (dao *GamesDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// MerchantAdminsDao is the data access object for the table merchant_admins. // MerchantAdminsDao is the data access object for the table merchant_admins.
type MerchantAdminsDao struct { type MerchantAdminsDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns MerchantAdminsColumns // columns contains all the column names of Table for convenient usage. columns MerchantAdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// MerchantAdminsColumns defines and stores column names for the table merchant_admins. // MerchantAdminsColumns defines and stores column names for the table merchant_admins.
@ -57,11 +58,12 @@ var merchantAdminsColumns = MerchantAdminsColumns{
} }
// NewMerchantAdminsDao creates and returns a new DAO object for table data access. // NewMerchantAdminsDao creates and returns a new DAO object for table data access.
func NewMerchantAdminsDao() *MerchantAdminsDao { func NewMerchantAdminsDao(handlers ...gdb.ModelHandler) *MerchantAdminsDao {
return &MerchantAdminsDao{ return &MerchantAdminsDao{
group: "default", group: "default",
table: "merchant_admins", table: "merchant_admins",
columns: merchantAdminsColumns, columns: merchantAdminsColumns,
handlers: handlers,
} }
} }
@ -87,7 +89,11 @@ func (dao *MerchantAdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *MerchantAdminsDao) Ctx(ctx context.Context) *gdb.Model { func (dao *MerchantAdminsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// MerchantsDao is the data access object for the table merchants. // MerchantsDao is the data access object for the table merchants.
type MerchantsDao struct { type MerchantsDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns MerchantsColumns // columns contains all the column names of Table for convenient usage. columns MerchantsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// MerchantsColumns defines and stores column names for the table merchants. // MerchantsColumns defines and stores column names for the table merchants.
@ -71,11 +72,12 @@ var merchantsColumns = MerchantsColumns{
} }
// NewMerchantsDao creates and returns a new DAO object for table data access. // NewMerchantsDao creates and returns a new DAO object for table data access.
func NewMerchantsDao() *MerchantsDao { func NewMerchantsDao(handlers ...gdb.ModelHandler) *MerchantsDao {
return &MerchantsDao{ return &MerchantsDao{
group: "default", group: "default",
table: "merchants", table: "merchants",
columns: merchantsColumns, columns: merchantsColumns,
handlers: handlers,
} }
} }
@ -101,7 +103,11 @@ func (dao *MerchantsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *MerchantsDao) Ctx(ctx context.Context) *gdb.Model { func (dao *MerchantsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// RewardTypesDao is the data access object for the table reward_types. // RewardTypesDao is the data access object for the table reward_types.
type RewardTypesDao struct { type RewardTypesDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns RewardTypesColumns // columns contains all the column names of Table for convenient usage. columns RewardTypesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// RewardTypesColumns defines and stores column names for the table reward_types. // RewardTypesColumns defines and stores column names for the table reward_types.
@ -43,11 +44,12 @@ var rewardTypesColumns = RewardTypesColumns{
} }
// NewRewardTypesDao creates and returns a new DAO object for table data access. // NewRewardTypesDao creates and returns a new DAO object for table data access.
func NewRewardTypesDao() *RewardTypesDao { func NewRewardTypesDao(handlers ...gdb.ModelHandler) *RewardTypesDao {
return &RewardTypesDao{ return &RewardTypesDao{
group: "default", group: "default",
table: "reward_types", table: "reward_types",
columns: rewardTypesColumns, columns: rewardTypesColumns,
handlers: handlers,
} }
} }
@ -73,7 +75,11 @@ func (dao *RewardTypesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardTypesDao) Ctx(ctx context.Context) *gdb.Model { func (dao *RewardTypesDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// RewardsDao is the data access object for the table rewards. // RewardsDao is the data access object for the table rewards.
type RewardsDao struct { type RewardsDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns RewardsColumns // columns contains all the column names of Table for convenient usage. columns RewardsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// RewardsColumns defines and stores column names for the table rewards. // RewardsColumns defines and stores column names for the table rewards.
@ -71,11 +72,12 @@ var rewardsColumns = RewardsColumns{
} }
// NewRewardsDao creates and returns a new DAO object for table data access. // NewRewardsDao creates and returns a new DAO object for table data access.
func NewRewardsDao() *RewardsDao { func NewRewardsDao(handlers ...gdb.ModelHandler) *RewardsDao {
return &RewardsDao{ return &RewardsDao{
group: "default", group: "default",
table: "rewards", table: "rewards",
columns: rewardsColumns, columns: rewardsColumns,
handlers: handlers,
} }
} }
@ -101,7 +103,11 @@ func (dao *RewardsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RewardsDao) Ctx(ctx context.Context) *gdb.Model { func (dao *RewardsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// RolesDao is the data access object for the table roles. // RolesDao is the data access object for the table roles.
type RolesDao struct { type RolesDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns RolesColumns // columns contains all the column names of Table for convenient usage. columns RolesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// RolesColumns defines and stores column names for the table roles. // RolesColumns defines and stores column names for the table roles.
@ -47,11 +48,12 @@ var rolesColumns = RolesColumns{
} }
// NewRolesDao creates and returns a new DAO object for table data access. // NewRolesDao creates and returns a new DAO object for table data access.
func NewRolesDao() *RolesDao { func NewRolesDao(handlers ...gdb.ModelHandler) *RolesDao {
return &RolesDao{ return &RolesDao{
group: "default", group: "default",
table: "roles", table: "roles",
columns: rolesColumns, columns: rolesColumns,
handlers: handlers,
} }
} }
@ -77,7 +79,11 @@ func (dao *RolesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *RolesDao) Ctx(ctx context.Context) *gdb.Model { func (dao *RolesDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// StoreAdminsDao is the data access object for the table store_admins. // StoreAdminsDao is the data access object for the table store_admins.
type StoreAdminsDao struct { type StoreAdminsDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns StoreAdminsColumns // columns contains all the column names of Table for convenient usage. columns StoreAdminsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// StoreAdminsColumns defines and stores column names for the table store_admins. // StoreAdminsColumns defines and stores column names for the table store_admins.
@ -57,11 +58,12 @@ var storeAdminsColumns = StoreAdminsColumns{
} }
// NewStoreAdminsDao creates and returns a new DAO object for table data access. // NewStoreAdminsDao creates and returns a new DAO object for table data access.
func NewStoreAdminsDao() *StoreAdminsDao { func NewStoreAdminsDao(handlers ...gdb.ModelHandler) *StoreAdminsDao {
return &StoreAdminsDao{ return &StoreAdminsDao{
group: "default", group: "default",
table: "store_admins", table: "store_admins",
columns: storeAdminsColumns, columns: storeAdminsColumns,
handlers: handlers,
} }
} }
@ -87,7 +89,11 @@ func (dao *StoreAdminsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreAdminsDao) Ctx(ctx context.Context) *gdb.Model { func (dao *StoreAdminsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// StoreDesktopSettingsDao is the data access object for the table store_desktop_settings. // StoreDesktopSettingsDao is the data access object for the table store_desktop_settings.
type StoreDesktopSettingsDao struct { type StoreDesktopSettingsDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns StoreDesktopSettingsColumns // columns contains all the column names of Table for convenient usage. columns StoreDesktopSettingsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// StoreDesktopSettingsColumns defines and stores column names for the table store_desktop_settings. // StoreDesktopSettingsColumns defines and stores column names for the table store_desktop_settings.
@ -33,11 +34,12 @@ var storeDesktopSettingsColumns = StoreDesktopSettingsColumns{
} }
// NewStoreDesktopSettingsDao creates and returns a new DAO object for table data access. // NewStoreDesktopSettingsDao creates and returns a new DAO object for table data access.
func NewStoreDesktopSettingsDao() *StoreDesktopSettingsDao { func NewStoreDesktopSettingsDao(handlers ...gdb.ModelHandler) *StoreDesktopSettingsDao {
return &StoreDesktopSettingsDao{ return &StoreDesktopSettingsDao{
group: "default", group: "default",
table: "store_desktop_settings", table: "store_desktop_settings",
columns: storeDesktopSettingsColumns, columns: storeDesktopSettingsColumns,
handlers: handlers,
} }
} }
@ -63,7 +65,11 @@ func (dao *StoreDesktopSettingsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreDesktopSettingsDao) Ctx(ctx context.Context) *gdb.Model { func (dao *StoreDesktopSettingsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// StoreIpsDao is the data access object for the table store_ips. // StoreIpsDao is the data access object for the table store_ips.
type StoreIpsDao struct { type StoreIpsDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns StoreIpsColumns // columns contains all the column names of Table for convenient usage. columns StoreIpsColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// StoreIpsColumns defines and stores column names for the table store_ips. // StoreIpsColumns defines and stores column names for the table store_ips.
@ -41,11 +42,12 @@ var storeIpsColumns = StoreIpsColumns{
} }
// NewStoreIpsDao creates and returns a new DAO object for table data access. // NewStoreIpsDao creates and returns a new DAO object for table data access.
func NewStoreIpsDao() *StoreIpsDao { func NewStoreIpsDao(handlers ...gdb.ModelHandler) *StoreIpsDao {
return &StoreIpsDao{ return &StoreIpsDao{
group: "default", group: "default",
table: "store_ips", table: "store_ips",
columns: storeIpsColumns, columns: storeIpsColumns,
handlers: handlers,
} }
} }
@ -71,7 +73,11 @@ func (dao *StoreIpsDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreIpsDao) Ctx(ctx context.Context) *gdb.Model { func (dao *StoreIpsDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// StoreNetfeeAreaLevelDao is the data access object for the table store_netfee_area_level. // StoreNetfeeAreaLevelDao is the data access object for the table store_netfee_area_level.
type StoreNetfeeAreaLevelDao struct { type StoreNetfeeAreaLevelDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns StoreNetfeeAreaLevelColumns // columns contains all the column names of Table for convenient usage. columns StoreNetfeeAreaLevelColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// StoreNetfeeAreaLevelColumns defines and stores column names for the table store_netfee_area_level. // StoreNetfeeAreaLevelColumns defines and stores column names for the table store_netfee_area_level.
@ -49,11 +50,12 @@ var storeNetfeeAreaLevelColumns = StoreNetfeeAreaLevelColumns{
} }
// NewStoreNetfeeAreaLevelDao creates and returns a new DAO object for table data access. // NewStoreNetfeeAreaLevelDao creates and returns a new DAO object for table data access.
func NewStoreNetfeeAreaLevelDao() *StoreNetfeeAreaLevelDao { func NewStoreNetfeeAreaLevelDao(handlers ...gdb.ModelHandler) *StoreNetfeeAreaLevelDao {
return &StoreNetfeeAreaLevelDao{ return &StoreNetfeeAreaLevelDao{
group: "default", group: "default",
table: "store_netfee_area_level", table: "store_netfee_area_level",
columns: storeNetfeeAreaLevelColumns, columns: storeNetfeeAreaLevelColumns,
handlers: handlers,
} }
} }
@ -79,7 +81,11 @@ func (dao *StoreNetfeeAreaLevelDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreNetfeeAreaLevelDao) Ctx(ctx context.Context) *gdb.Model { func (dao *StoreNetfeeAreaLevelDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// StoreRolesDao is the data access object for the table store_roles. // StoreRolesDao is the data access object for the table store_roles.
type StoreRolesDao struct { type StoreRolesDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns StoreRolesColumns // columns contains all the column names of Table for convenient usage. columns StoreRolesColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// StoreRolesColumns defines and stores column names for the table store_roles. // StoreRolesColumns defines and stores column names for the table store_roles.
@ -39,11 +40,12 @@ var storeRolesColumns = StoreRolesColumns{
} }
// NewStoreRolesDao creates and returns a new DAO object for table data access. // NewStoreRolesDao creates and returns a new DAO object for table data access.
func NewStoreRolesDao() *StoreRolesDao { func NewStoreRolesDao(handlers ...gdb.ModelHandler) *StoreRolesDao {
return &StoreRolesDao{ return &StoreRolesDao{
group: "default", group: "default",
table: "store_roles", table: "store_roles",
columns: storeRolesColumns, columns: storeRolesColumns,
handlers: handlers,
} }
} }
@ -69,7 +71,11 @@ func (dao *StoreRolesDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoreRolesDao) Ctx(ctx context.Context) *gdb.Model { func (dao *StoreRolesDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// StoresDao is the data access object for the table stores. // StoresDao is the data access object for the table stores.
type StoresDao struct { type StoresDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns StoresColumns // columns contains all the column names of Table for convenient usage. columns StoresColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// StoresColumns defines and stores column names for the table stores. // StoresColumns defines and stores column names for the table stores.
@ -51,11 +52,12 @@ var storesColumns = StoresColumns{
} }
// NewStoresDao creates and returns a new DAO object for table data access. // NewStoresDao creates and returns a new DAO object for table data access.
func NewStoresDao() *StoresDao { func NewStoresDao(handlers ...gdb.ModelHandler) *StoresDao {
return &StoresDao{ return &StoresDao{
group: "default", group: "default",
table: "stores", table: "stores",
columns: storesColumns, columns: storesColumns,
handlers: handlers,
} }
} }
@ -81,7 +83,11 @@ func (dao *StoresDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *StoresDao) Ctx(ctx context.Context) *gdb.Model { func (dao *StoresDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// TasksDao is the data access object for the table tasks. // TasksDao is the data access object for the table tasks.
type TasksDao struct { type TasksDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns TasksColumns // columns contains all the column names of Table for convenient usage. columns TasksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// TasksColumns defines and stores column names for the table tasks. // TasksColumns defines and stores column names for the table tasks.
@ -57,11 +58,12 @@ var tasksColumns = TasksColumns{
} }
// NewTasksDao creates and returns a new DAO object for table data access. // NewTasksDao creates and returns a new DAO object for table data access.
func NewTasksDao() *TasksDao { func NewTasksDao(handlers ...gdb.ModelHandler) *TasksDao {
return &TasksDao{ return &TasksDao{
group: "default", group: "default",
table: "tasks", table: "tasks",
columns: tasksColumns, columns: tasksColumns,
handlers: handlers,
} }
} }
@ -87,7 +89,11 @@ func (dao *TasksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *TasksDao) Ctx(ctx context.Context) *gdb.Model { func (dao *TasksDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// UserTasksDao is the data access object for the table user_tasks. // UserTasksDao is the data access object for the table user_tasks.
type UserTasksDao struct { type UserTasksDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns UserTasksColumns // columns contains all the column names of Table for convenient usage. columns UserTasksColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// UserTasksColumns defines and stores column names for the table user_tasks. // UserTasksColumns defines and stores column names for the table user_tasks.
@ -51,11 +52,12 @@ var userTasksColumns = UserTasksColumns{
} }
// NewUserTasksDao creates and returns a new DAO object for table data access. // NewUserTasksDao creates and returns a new DAO object for table data access.
func NewUserTasksDao() *UserTasksDao { func NewUserTasksDao(handlers ...gdb.ModelHandler) *UserTasksDao {
return &UserTasksDao{ return &UserTasksDao{
group: "default", group: "default",
table: "user_tasks", table: "user_tasks",
columns: userTasksColumns, columns: userTasksColumns,
handlers: handlers,
} }
} }
@ -81,7 +83,11 @@ func (dao *UserTasksDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *UserTasksDao) Ctx(ctx context.Context) *gdb.Model { func (dao *UserTasksDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -13,9 +13,10 @@ import (
// UsersDao is the data access object for the table users. // UsersDao is the data access object for the table users.
type UsersDao struct { type UsersDao struct {
table string // table is the underlying table name of the DAO. table string // table is the underlying table name of the DAO.
group string // group is the database configuration group name of the current DAO. group string // group is the database configuration group name of the current DAO.
columns UsersColumns // columns contains all the column names of Table for convenient usage. columns UsersColumns // columns contains all the column names of Table for convenient usage.
handlers []gdb.ModelHandler // handlers for customized model modification.
} }
// UsersColumns defines and stores column names for the table users. // UsersColumns defines and stores column names for the table users.
@ -59,11 +60,12 @@ var usersColumns = UsersColumns{
} }
// NewUsersDao creates and returns a new DAO object for table data access. // NewUsersDao creates and returns a new DAO object for table data access.
func NewUsersDao() *UsersDao { func NewUsersDao(handlers ...gdb.ModelHandler) *UsersDao {
return &UsersDao{ return &UsersDao{
group: "default", group: "default",
table: "users", table: "users",
columns: usersColumns, columns: usersColumns,
handlers: handlers,
} }
} }
@ -89,7 +91,11 @@ func (dao *UsersDao) Group() string {
// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation.
func (dao *UsersDao) Ctx(ctx context.Context) *gdb.Model { func (dao *UsersDao) Ctx(ctx context.Context) *gdb.Model {
return dao.DB().Model(dao.table).Safe().Ctx(ctx) model := dao.DB().Model(dao.table)
for _, handler := range dao.handlers {
model = handler(model)
}
return model.Safe().Ctx(ctx)
} }
// Transaction wraps the transaction logic using function f. // Transaction wraps the transaction logic using function f.

View File

@ -17,7 +17,6 @@ type sReward struct{}
func init() { func init() {
service.RegisterReward(New()) service.RegisterReward(New())
service.RegisterReward(New())
} }
func New() service.IReward { func New() service.IReward {
@ -75,21 +74,26 @@ func (s *sReward) Create(ctx context.Context, in *model.RewardCreateIn) (out *mo
} }
// 创建奖励 // 创建奖励
id, err := dao.Rewards.Ctx(ctx).Data(do.Rewards{ _, err = dao.Rewards.Ctx(ctx).Data(do.Rewards{
RewardTypeId: in.RewardTypeId, StoreId: in.StoreId,
Name: in.Name, Name: in.Name,
StoreId: in.StoreId, RewardTypeId: in.RewardTypeId,
Status: in.Status, ImageUrl: in.Img,
ValidFrom: in.ValidFrom, QqGoodsId: in.QQGoodsId,
ValidTo: in.ValidTo, QqGoodsIdStr: in.QQGoodsIdStr,
ExpireType: in.ExpireType, Status: in.Status,
ExpireDays: in.ExpireDays, ValidFrom: in.ValidFrom,
}).OmitEmptyData().InsertAndGetId() ValidTo: in.ValidTo,
ExpireType: in.ExpireType,
ExpireDays: in.ExpireDays,
DailyTotalLimit: in.DailyTotalLimit,
}).OmitEmptyData().Insert()
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &model.RewardCreateOut{Id: id}, nil return &model.RewardCreateOut{Success: true}, nil
} }
// Update 更新奖励 // Update 更新奖励
@ -105,6 +109,11 @@ func (s *sReward) Update(ctx context.Context, in *model.RewardUpdateIn) (out *mo
return nil, ecode.Params.Sub("奖励不存在") return nil, ecode.Params.Sub("奖励不存在")
} }
// 系统奖励source=1只能由管理员修改
if in.Source == 1 && in.OperatorRole != consts.AdminRoleCode {
return nil, ecode.Params.Sub("只有管理员可以修改系统奖励")
}
storeId := data[dao.Rewards.Columns().StoreId].Int64() storeId := data[dao.Rewards.Columns().StoreId].Int64()
// 权限校验(管理员跳过) // 权限校验(管理员跳过)
@ -154,12 +163,22 @@ func (s *sReward) Update(ctx context.Context, in *model.RewardUpdateIn) (out *mo
_, err = dao.Rewards.Ctx(ctx). _, err = dao.Rewards.Ctx(ctx).
Where(do.Rewards{Id: in.Id}). Where(do.Rewards{Id: in.Id}).
Data(do.Rewards{ Data(do.Rewards{
Name: in.Name, Name: in.Name,
Status: in.Status, RewardTypeId: in.RewardTypeId,
ValidFrom: in.ValidFrom, GameId: in.GameId,
ValidTo: in.ValidTo, ImageUrl: in.Img,
ExpireType: in.ExpireType, QqGoodsId: in.QQGoodsId,
ExpireDays: in.ExpireDays, QqGoodsIdStr: in.QQGoodsIdStr,
Status: in.Status,
ValidFrom: in.ValidFrom,
ValidTo: in.ValidTo,
ExpireType: in.ExpireType,
ExpireDays: in.ExpireDays,
DailyTotalLimit: in.DailyTotalLimit,
TotalLimit: in.TotalLimit,
UserDailyLimit: in.UserDailyLimit,
UserTotalLimit: in.UserTotalLimit,
GrantQuantity: in.GrantQuantity,
}).OmitEmptyData().Update() }).OmitEmptyData().Update()
if err != nil { if err != nil {
@ -186,7 +205,7 @@ func (s *sReward) Update(ctx context.Context, in *model.RewardUpdateIn) (out *mo
// Delete 删除奖励 // Delete 删除奖励
func (s *sReward) Delete(ctx context.Context, in *model.RewardDeleteIn) (out *model.RewardDeleteOut, err error) { func (s *sReward) Delete(ctx context.Context, in *model.RewardDeleteIn) (out *model.RewardDeleteOut, err error) {
data, err := dao.Rewards.Ctx(ctx). data, err := dao.Rewards.Ctx(ctx).
Fields("id", "source", "store_id"). Fields("id", "store_id").
Where(do.Rewards{Id: in.Id}).One() Where(do.Rewards{Id: in.Id}).One()
if err != nil { if err != nil {
return nil, ecode.Fail.Sub("查询奖励失败") return nil, ecode.Fail.Sub("查询奖励失败")
@ -195,7 +214,7 @@ func (s *sReward) Delete(ctx context.Context, in *model.RewardDeleteIn) (out *mo
return nil, ecode.Params.Sub("奖励不存在") return nil, ecode.Params.Sub("奖励不存在")
} }
if data["source"].Int() == 1 && in.OperatorRole != consts.AdminRoleCode { if in.Source == 1 && in.OperatorRole != consts.AdminRoleCode {
return nil, ecode.Params.Sub("只有管理员可以删除系统奖励") return nil, ecode.Params.Sub("只有管理员可以删除系统奖励")
} }
@ -234,15 +253,111 @@ func (s *sReward) Delete(ctx context.Context, in *model.RewardDeleteIn) (out *mo
} }
// List 奖励列表 // List 奖励列表
func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error) { func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error) {
return nil, nil rewardCols := dao.Rewards.Columns()
rewardTypeCols := dao.RewardTypes.Columns()
rewardTypeIds := make([]int64, 0)
// ==== 权限校验 ====
switch in.OperatorRole {
case consts.AdminRoleCode:
// 系统管理员只能查询 source = 1 的奖励
array, err := dao.RewardTypes.Ctx(ctx).Where(do.RewardTypes{Source: 1}).Fields(rewardTypeCols.Id).Array()
if err != nil {
return nil, ecode.Fail.Sub("获取奖励类型列表失败")
}
for _, value := range array {
rewardTypeIds = append(rewardTypeIds, value.Int64())
}
case consts.MerchantRoleCode, consts.StoreRoleCode:
// 合并商户和门店角色权限校验
var exist bool
if in.OperatorRole == consts.MerchantRoleCode {
exist, err = dao.MerchantAdmins.Ctx(ctx).
Where(do.MerchantAdmins{Id: in.OperatorId}).
LeftJoin(
dao.Stores.Table(),
fmt.Sprintf("%s.%s = %s.%s",
dao.MerchantAdmins.Table(), dao.MerchantAdmins.Columns().MerchantId,
dao.Stores.Table(), dao.Stores.Columns().MerchantId,
),
).
Where(fmt.Sprintf("%s.%s = ?", dao.Stores.Table(), dao.Stores.Columns().Id), in.StoreId).
Exist()
} else {
exist, err = dao.StoreAdmins.Ctx(ctx).
Where(do.StoreAdmins{Id: in.OperatorId}).
LeftJoin(
dao.Stores.Table(),
fmt.Sprintf("%s.%s = %s.%s",
dao.StoreAdmins.Table(), dao.StoreAdmins.Columns().StoreId,
dao.Stores.Table(), dao.Stores.Columns().Id,
),
).
Where(fmt.Sprintf("%s.%s = ?", dao.Stores.Table(), dao.Stores.Columns().Id), in.StoreId).
Exist()
}
if err != nil {
return nil, ecode.Fail.Sub("检查操作者权限异常")
}
if !exist {
return nil, ecode.Params.Sub("无门店权限")
}
//
array, err := dao.RewardTypes.Ctx(ctx).Where(do.RewardTypes{Source: 1}).Fields(rewardTypeCols.Id).Array()
if err != nil {
return nil, ecode.Fail.Sub("获取奖励类型列表失败")
}
for _, value := range array {
rewardTypeIds = append(rewardTypeIds, value.Int64())
}
default:
return nil, ecode.Params.Sub("无效的角色")
}
orm := dao.Rewards.Ctx(ctx).WhereIn(dao.Rewards.Columns().RewardTypeId, rewardTypeIds)
// ==== 其他查询条件 ====
if in.Status != 0 {
orm = orm.Where(fmt.Sprintf("%s.%s = ?", dao.Rewards.Table(), rewardCols.Status), in.Status)
}
if in.RewardTypeId != 0 {
// 确保 reward_type_id 过滤独立应用
orm = orm.Where(fmt.Sprintf("%s.%s = ?", dao.Rewards.Table(), rewardCols.RewardTypeId), in.RewardTypeId)
}
if in.Name != "" {
orm = orm.WhereLike(rewardCols.Name, "%"+in.Name+"%")
}
// ==== 总数统计 ====
list := make([]model.Reward, 0)
var total int
err = orm.ScanAndCount(&list, &total, false)
if err != nil {
return nil, err
}
return &model.RewardListOut{
List: list,
Total: total,
}, nil
} }
// GetLift 领取奖励 // GetLift 领取奖励
func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error) { func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error) {
// 遍历奖励类型列表
//for _, v := range in.RewradTypeId {
// if v > 0 {
// // 发背包+兑换
//
// }
// if v > 0 {
// // 直接发背包
// }
//}
activity, err := gamelife.GetGamelifeClient(ctx).RequestActivity(ctx, &model.QQNetbarActivityIn{PopenId: in.PopenId, ServiceName: consts.GetGift, GiftParam: model.GiftParam{ activity, err := gamelife.GetGamelifeClient(ctx).RequestActivity(ctx, &model.QQNetbarActivityIn{PopenId: in.PopenId, ServiceName: consts.GetGift, GiftParam: model.GiftParam{
TaskId: in.TaskId, TaskId: in.TaskId,
AreaId: in.AreaId, AreaId: in.AreaId,

View File

@ -1,70 +1,86 @@
package model package model
import ( import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime" "github.com/gogf/gf/v2/os/gtime"
) )
// Reward 奖励表 // Reward 奖励表
type Reward struct { type Reward struct {
g.Meta `orm:"table:reward"` Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID
Id int64 `json:"id" dc:"奖励ID" orm:"id,primary"` StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID系统奖励为NULL"` // 门店ID系统奖励为NULL
RewardTypeId int64 `json:"rewardTypeId" dc:"奖励类型ID" orm:"reward_type_id"` Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称
RewardTypeName string `json:"rewardTypeName" dc:"奖励类型名称" orm:"reward_type_name"` RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID关联 reward_types 表"` // 奖励类型ID关联 reward_types 表
Name string `json:"name" dc:"奖励名称如100积分、5元优惠券" orm:"name"` GameId int64 `json:"gameId" orm:"game_id" description:"游戏ID"` // 游戏ID
Description string `json:"description" dc:"奖励描述" orm:"description"` ImageUrl string `json:"imageUrl" orm:"image_url" description:"奖励图片链接"` // 奖励图片链接
Source int `json:"source" dc:"来源1=系统内置2=门店自定义" orm:"source"` QqGoodsId string `json:"qqGoodsId" orm:"qq_goods_id" description:"QQ网吧物品ID"` // QQ网吧物品ID
StoreId int64 `json:"storeId" dc:"门店ID系统内置奖励为NULL" orm:"store_id"` QqGoodsIdStr string `json:"qqGoodsIdStr" orm:"qq_goods_id_str" description:"QQ网吧物品ID字符串"` // QQ网吧物品ID字符串
Value int64 `json:"value" dc:"奖励值(如积分数额、优惠金额)" orm:"value"` Status int `json:"status" orm:"status" description:"状态1=启用2=禁用"` // 状态1=启用2=禁用
Status int `json:"status" dc:"状态1=正常0=禁用" orm:"status"` ExpireType int `json:"expireType" orm:"expire_type" description:"过期方式1=时间段过期2=领取后过期"` // 过期方式1=时间段过期2=领取后过期
TotalNum int64 `json:"totalNum" dc:"奖励数量" orm:"total_num"` ValidFrom *gtime.Time `json:"validFrom" orm:"valid_from" description:"有效期开始时间expire_type=1时"` // 有效期开始时间expire_type=1时
UseNum int64 `json:"useNum" dc:"已使用数量" orm:"use_num"` ValidTo *gtime.Time `json:"validTo" orm:"valid_to" description:"有效期结束时间expire_type=1时"` // 有效期结束时间expire_type=1时
CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间" orm:"created_at"` ExpireDays int `json:"expireDays" orm:"expire_days" description:"领取后多少天过期expire_type=2时"` // 领取后多少天过期expire_type=2时
UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间" orm:"updated_at"` DailyTotalLimit uint64 `json:"dailyTotalLimit" orm:"daily_total_limit" description:"每日发放总限NULL表示不限制"` // 每日发放总限NULL表示不限制
DeletedAt *gtime.Time `json:"deletedAt" dc:"软删除时间戳" orm:"deleted_at"` TotalLimit uint64 `json:"totalLimit" orm:"total_limit" description:"奖励总限NULL表示不限制"` // 奖励总限NULL表示不限制
ExpireType int `json:"expireType"` // 过期类型1=时间段过期2=领取后多少天过期 UserDailyLimit uint64 `json:"userDailyLimit" orm:"user_daily_limit" description:"用户每日领取限制NULL表示不限制"` // 用户每日领取限制NULL表示不限制
ValidFrom *gtime.Time `json:"validFrom"` // 有效开始时间expire_type=1 时使用 UserTotalLimit uint64 `json:"userTotalLimit" orm:"user_total_limit" description:"用户领取总次数限制NULL表示不限制"` // 用户领取总次数限制NULL表示不限制
ValidTo *gtime.Time `json:"validTo"` // 有效结束时间expire_type=1 时使用) ReceivedNum uint64 `json:"receivedNum" orm:"received_num" description:"已领取数量"` // 已领取数量
ExpireDays int `json:"expireDays"` // 领取后多少天过期expire_type=2 时使用) GrantQuantity uint64 `json:"grantQuantity" orm:"grant_quantity" description:"每次发放个数"` // 每次发放个数
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:"删除时间(软删除)"` // 删除时间(软删除)
} }
// RewardCreateIn 创建奖励入参 // RewardCreateIn 创建奖励入参
type RewardCreateIn struct { type RewardCreateIn struct {
OperatorId int64 OperatorId int64
OperatorRole string OperatorRole string
RewardTypeId int64 StoreId int64
Name string Name string
Description string RewardTypeId int64
Source int GameId int64
StoreId int64 Img string
Value int64 QQGoodsId string
Status int QQGoodsIdStr string
ExpireType int Status int
ExpireDays int ExpireType int
ValidFrom *gtime.Time ExpireDays int
ValidTo *gtime.Time ValidFrom *gtime.Time
ValidTo *gtime.Time
DailyTotalLimit int64
TotalLimit int64
UserDailyLimit int64
UserTotalLimit int64
GrantQuantity int64
Source int
} }
// RewardCreateOut 创建奖励出参 // RewardCreateOut 创建奖励出参
type RewardCreateOut struct { type RewardCreateOut struct {
Id int64 Success bool `json:"success" dc:"是否成功"`
} }
// RewardUpdateIn 更新奖励入参 // RewardUpdateIn 更新奖励入参
type RewardUpdateIn struct { type RewardUpdateIn struct {
OperatorId int64 Id int64
OperatorRole string OperatorId int64
Id int64 OperatorRole string
RewardTypeId int64 Name string
Name string RewardTypeId int64
Description string GameId int64
StoreId int64 Img string
Value int64 QQGoodsId string
Status int QQGoodsIdStr string
ExpireType int Status int
ExpireDays int ExpireType int
ValidFrom *gtime.Time ExpireDays int
ValidTo *gtime.Time ValidFrom *gtime.Time
ValidTo *gtime.Time
DailyTotalLimit int64
TotalLimit int64
UserDailyLimit int64
UserTotalLimit int64
GrantQuantity int64
Source int
} }
// RewardUpdateOut 更新奖励出参 // RewardUpdateOut 更新奖励出参
@ -77,6 +93,7 @@ type RewardDeleteIn struct {
Id int64 Id int64
OperatorId int64 OperatorId int64
OperatorRole string OperatorRole string
Source int
} }
// RewardDeleteOut 删除奖励出参 // RewardDeleteOut 删除奖励出参
@ -94,7 +111,6 @@ type RewardListIn struct {
StoreId int64 StoreId int64
RewardTypeId int64 RewardTypeId int64
Status int Status int
Source int
} }
// RewardListOut 奖励列表查询出参 // RewardListOut 奖励列表查询出参