From 9bfdaf5fa214b4fcf33458803bcc53663b031ceb Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Thu, 26 Jun 2025 11:15:17 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E9=A2=86=E5=8F=96=E4=BB=BB=E5=8A=A1=E6=97=B6=EF=BC=8C=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=AF=B9=E5=BA=94=E7=9A=84=E5=A5=96=E5=8A=B1=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/reward/v1/reward.go | 4 ++-- api/task/v1/task.go | 4 ++-- internal/logic/task/task.go | 9 ++++++--- internal/model/userTask.go | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/api/reward/v1/reward.go b/api/reward/v1/reward.go index 49ad507..30ef77a 100644 --- a/api/reward/v1/reward.go +++ b/api/reward/v1/reward.go @@ -27,8 +27,8 @@ type CreateReq struct { RewardTypeId int64 `json:"rewardTypeId" v:"required#奖励类型ID不能为空" dc:"奖励类型ID"` GameId int64 `json:"gameId" dc:"游戏ID"` RewardImg string `json:"rewardImg" dc:"奖励图片"` - QQGoodsId string `json:"qqGoodsId" v:"required#不能为空" dc:"QQ网吧物品ID"` - QQGoodsIdStr string `json:"qqGoodsIdStr" v:"required#不能为空" dc:"QQ网吧物品ID字符串"` + QQGoodsId string `json:"qqGoodsId" dc:"QQ网吧物品ID"` + QQGoodsIdStr string `json:"qqGoodsIdStr" dc:"QQ网吧物品ID字符串"` Status int `json:"status" dc:"状态" d:"1:启用 2:禁用"` ExpireType int `json:"expireType" v:"required#过期类型只能为1或2" dc:"过期类型"` ValidFrom *gtime.Time `json:"validFrom" dc:"有效开始时间(expire_type=1 时使用)"` diff --git a/api/task/v1/task.go b/api/task/v1/task.go index 811afc4..6e72bb7 100644 --- a/api/task/v1/task.go +++ b/api/task/v1/task.go @@ -75,10 +75,10 @@ type SelectorRes struct { // GetTaskReq 添加任务记录 type GetTaskReq struct { g.Meta `path:"/task/get" method:"post" tags:"Task" summary:"(PC)任务领取"` - TaskId int `json:"taskId" v:"required#任务id不能为空" dc:"任务id"` + TaskId string `json:"taskId" v:"required#任务id不能为空" dc:"任务id"` StoreId int `json:"storeId" dc:"门店 id、网关账号必传一个"` NetBarAccount string `json:"netBarAccount" dc:"门店 id、网关账号必传一个"` - GameId int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"` + GameId int `json:"gameId" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"` TaskName string `json:"taskName" v:"required#任务名称不能为空" dc:"任务名称"` } diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go index 4308550..b0c33ec 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "github.com/gogf/gf/v2/database/gdb" + "github.com/gogf/gf/v2/util/guid" "server/internal/consts" "server/internal/dao" "server/internal/model" @@ -359,6 +360,7 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge return ecode.Fail.Sub("创建用户任务记录失败") } + snowid.GetSnowClient() // 查询该任务相关联的奖励, 创建对应奖励下发记录id array, err := dao.TaskRewards.Ctx(ctx).Where(do.TaskRewards{TaskId: in.TaskId}).Fields(dao.TaskRewards.Columns().RewardId).Array() if err != nil { @@ -366,9 +368,10 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge } for _, v := range array { _, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{ - UserTaskId: id, - RewardId: v.Int64(), - Status: consts.RewardInitStatus, + UserTaskId: id, + RewardId: v.Int64(), + Status: consts.RewardInitStatus, + InnerOrderId: fmt.Sprintf("reward%s", guid.S()), }).Insert() if err != nil { return ecode.Fail.Sub("创建用户任务奖励记录失败") diff --git a/internal/model/userTask.go b/internal/model/userTask.go index b2cd648..55e0914 100644 --- a/internal/model/userTask.go +++ b/internal/model/userTask.go @@ -59,7 +59,7 @@ type LoginUserRankingNum struct { // GetTaskIn 添加任务记录入参 type GetTaskIn struct { - TaskId int `json:"taskId"` + TaskId string `json:"taskId"` StoreId int `json:"storeId"` NetBarAccount string `json:"netBarAccount"` UserId int `json:"userId"` From 8107b9a7192b6b5092b5716790f7f4bbf36482b9 Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Thu, 26 Jun 2025 14:52:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=A5=96=E5=8A=B1?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=92=8C=E5=A5=96=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/task/task.go | 1 + api/task/v1/task.go | 15 ++++++ .../task_v1_get_user_task_records_list.go | 23 ++++++++ internal/dao/internal/admins.go | 22 +++----- internal/dao/internal/feedbacks.go | 22 +++----- internal/dao/internal/games.go | 22 +++----- internal/dao/internal/merchant_admins.go | 22 +++----- internal/dao/internal/merchants.go | 22 +++----- internal/dao/internal/notices.go | 22 +++----- internal/dao/internal/reward_callback.go | 22 +++----- internal/dao/internal/reward_types.go | 52 ++++++++----------- internal/dao/internal/reward_waters.go | 22 +++----- internal/dao/internal/rewards.go | 26 +++++----- internal/dao/internal/roles.go | 22 +++----- internal/dao/internal/store_admins.go | 22 +++----- .../dao/internal/store_desktop_settings.go | 22 +++----- internal/dao/internal/store_ips.go | 22 +++----- .../dao/internal/store_netfee_area_level.go | 22 +++----- internal/dao/internal/store_roles.go | 22 +++----- internal/dao/internal/stores.go | 22 +++----- internal/dao/internal/task_rewards.go | 22 +++----- internal/dao/internal/tasks.go | 22 +++----- internal/dao/internal/user_task_rewards.go | 24 ++++----- internal/dao/internal/user_tasks.go | 22 +++----- internal/dao/internal/users.go | 22 +++----- internal/logic/reward/reward.go | 39 ++++---------- internal/logic/rewardType/rewardType.go | 5 +- internal/logic/task/task.go | 12 +++-- internal/model/do/reward_types.go | 17 +++--- internal/model/do/rewards.go | 2 + internal/model/do/user_task_rewards.go | 1 + internal/model/entity/reward_types.go | 15 +++--- internal/model/entity/rewards.go | 2 + internal/model/entity/user_task_rewards.go | 1 + internal/model/reward.go | 48 ++++++++--------- internal/model/userTask.go | 13 +++++ internal/service/reward.go | 1 + internal/service/task.go | 1 + 38 files changed, 313 insertions(+), 403 deletions(-) create mode 100644 internal/controller/task/task_v1_get_user_task_records_list.go diff --git a/api/task/task.go b/api/task/task.go index ffda4bf..1082c50 100644 --- a/api/task/task.go +++ b/api/task/task.go @@ -17,4 +17,5 @@ type ITaskV1 interface { List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) Selector(ctx context.Context, req *v1.SelectorReq) (res *v1.SelectorRes, err error) GetTask(ctx context.Context, req *v1.GetTaskReq) (res *v1.GetTaskRes, err error) + GetUserTaskRecordsList(ctx context.Context, req *v1.GetUserTaskRecordsListReq) (res *v1.GetUserTaskRecordsListRes, err error) } diff --git a/api/task/v1/task.go b/api/task/v1/task.go index 6e72bb7..32c8c54 100644 --- a/api/task/v1/task.go +++ b/api/task/v1/task.go @@ -85,3 +85,18 @@ type GetTaskReq struct { type GetTaskRes struct { Success bool `json:"success"` } + +type GetUserTaskRecordsListReq struct { + g.Meta `path:"/task/records" method:"get" tags:"Task" summary:"(PC)用户任务记录列表"` + TaskId string `json:"taskId" dc:"任务 id"` + StoreId int `json:"storeId" dc:"门店 id"` + NetbarAccount string `json:"netbarAccount" dc:"网关账号"` + Page int `json:"page" dc:"页数"` + Size int `json:"size" dc:"条数"` + StartTime int32 `json:"startTime" dc:"开始时间"` + EndTime int32 `json:"endTime" dc:"结束时间"` +} +type GetUserTaskRecordsListRes struct { + List interface{} `json:"list"` + Total int `json:"total"` +} diff --git a/internal/controller/task/task_v1_get_user_task_records_list.go b/internal/controller/task/task_v1_get_user_task_records_list.go new file mode 100644 index 0000000..b9ffb06 --- /dev/null +++ b/internal/controller/task/task_v1_get_user_task_records_list.go @@ -0,0 +1,23 @@ +package task + +import ( + "context" + "github.com/gogf/gf/v2/frame/g" + "server/internal/model" + "server/internal/service" + + "server/api/task/v1" +) + +func (c *ControllerV1) GetUserTaskRecordsList(ctx context.Context, req *v1.GetUserTaskRecordsListReq) (res *v1.GetUserTaskRecordsListRes, err error) { + fromCtx := g.RequestFromCtx(ctx) + userId := fromCtx.GetCtxVar("id").Int() + out, err := service.Task().GetUserTaskRecordsList(ctx, &model.UserTaskRecordsListIn{UserId: userId}) + if err != nil { + return nil, err + } + return &v1.GetUserTaskRecordsListRes{ + List: out.List, + Total: out.Total, + }, nil +} diff --git a/internal/dao/internal/admins.go b/internal/dao/internal/admins.go index dc72d15..7c3f2be 100644 --- a/internal/dao/internal/admins.go +++ b/internal/dao/internal/admins.go @@ -13,10 +13,9 @@ import ( // AdminsDao is the data access object for the table admins. type AdminsDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // AdminsColumns defines and stores column names for the table admins. @@ -50,12 +49,11 @@ var adminsColumns = AdminsColumns{ } // NewAdminsDao creates and returns a new DAO object for table data access. -func NewAdminsDao(handlers ...gdb.ModelHandler) *AdminsDao { +func NewAdminsDao() *AdminsDao { return &AdminsDao{ - group: "default", - table: "admins", - columns: adminsColumns, - handlers: handlers, + group: "default", + table: "admins", + columns: adminsColumns, } } @@ -81,11 +79,7 @@ func (dao *AdminsDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/feedbacks.go b/internal/dao/internal/feedbacks.go index 7a8d085..d67a1e5 100644 --- a/internal/dao/internal/feedbacks.go +++ b/internal/dao/internal/feedbacks.go @@ -13,10 +13,9 @@ import ( // FeedbacksDao is the data access object for the table feedbacks. type FeedbacksDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // FeedbacksColumns defines and stores column names for the table feedbacks. @@ -52,12 +51,11 @@ var feedbacksColumns = FeedbacksColumns{ } // NewFeedbacksDao creates and returns a new DAO object for table data access. -func NewFeedbacksDao(handlers ...gdb.ModelHandler) *FeedbacksDao { +func NewFeedbacksDao() *FeedbacksDao { return &FeedbacksDao{ - group: "default", - table: "feedbacks", - columns: feedbacksColumns, - handlers: handlers, + group: "default", + table: "feedbacks", + columns: feedbacksColumns, } } @@ -83,11 +81,7 @@ func (dao *FeedbacksDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/games.go b/internal/dao/internal/games.go index dac75c7..b53dd54 100644 --- a/internal/dao/internal/games.go +++ b/internal/dao/internal/games.go @@ -13,10 +13,9 @@ import ( // GamesDao is the data access object for the table games. type GamesDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // GamesColumns defines and stores column names for the table games. @@ -46,12 +45,11 @@ var gamesColumns = GamesColumns{ } // NewGamesDao creates and returns a new DAO object for table data access. -func NewGamesDao(handlers ...gdb.ModelHandler) *GamesDao { +func NewGamesDao() *GamesDao { return &GamesDao{ - group: "default", - table: "games", - columns: gamesColumns, - handlers: handlers, + group: "default", + table: "games", + columns: gamesColumns, } } @@ -77,11 +75,7 @@ func (dao *GamesDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/merchant_admins.go b/internal/dao/internal/merchant_admins.go index 64533e1..51ac691 100644 --- a/internal/dao/internal/merchant_admins.go +++ b/internal/dao/internal/merchant_admins.go @@ -13,10 +13,9 @@ import ( // MerchantAdminsDao is the data access object for the table merchant_admins. type MerchantAdminsDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // MerchantAdminsColumns defines and stores column names for the table merchant_admins. @@ -58,12 +57,11 @@ var merchantAdminsColumns = MerchantAdminsColumns{ } // NewMerchantAdminsDao creates and returns a new DAO object for table data access. -func NewMerchantAdminsDao(handlers ...gdb.ModelHandler) *MerchantAdminsDao { +func NewMerchantAdminsDao() *MerchantAdminsDao { return &MerchantAdminsDao{ - group: "default", - table: "merchant_admins", - columns: merchantAdminsColumns, - handlers: handlers, + group: "default", + table: "merchant_admins", + columns: merchantAdminsColumns, } } @@ -89,11 +87,7 @@ func (dao *MerchantAdminsDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/merchants.go b/internal/dao/internal/merchants.go index 717f855..6dd5d05 100644 --- a/internal/dao/internal/merchants.go +++ b/internal/dao/internal/merchants.go @@ -13,10 +13,9 @@ import ( // MerchantsDao is the data access object for the table merchants. type MerchantsDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // MerchantsColumns defines and stores column names for the table merchants. @@ -72,12 +71,11 @@ var merchantsColumns = MerchantsColumns{ } // NewMerchantsDao creates and returns a new DAO object for table data access. -func NewMerchantsDao(handlers ...gdb.ModelHandler) *MerchantsDao { +func NewMerchantsDao() *MerchantsDao { return &MerchantsDao{ - group: "default", - table: "merchants", - columns: merchantsColumns, - handlers: handlers, + group: "default", + table: "merchants", + columns: merchantsColumns, } } @@ -103,11 +101,7 @@ func (dao *MerchantsDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/notices.go b/internal/dao/internal/notices.go index 9c2cfce..5cc451a 100644 --- a/internal/dao/internal/notices.go +++ b/internal/dao/internal/notices.go @@ -13,10 +13,9 @@ import ( // NoticesDao is the data access object for the table notices. type NoticesDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns NoticesColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns NoticesColumns // columns contains all the column names of Table for convenient usage. } // NoticesColumns defines and stores column names for the table notices. @@ -50,12 +49,11 @@ var noticesColumns = NoticesColumns{ } // NewNoticesDao creates and returns a new DAO object for table data access. -func NewNoticesDao(handlers ...gdb.ModelHandler) *NoticesDao { +func NewNoticesDao() *NoticesDao { return &NoticesDao{ - group: "default", - table: "notices", - columns: noticesColumns, - handlers: handlers, + group: "default", + table: "notices", + columns: noticesColumns, } } @@ -81,11 +79,7 @@ func (dao *NoticesDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *NoticesDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/reward_callback.go b/internal/dao/internal/reward_callback.go index 249829d..e5291f6 100644 --- a/internal/dao/internal/reward_callback.go +++ b/internal/dao/internal/reward_callback.go @@ -13,10 +13,9 @@ import ( // RewardCallbackDao is the data access object for the table reward_callback. type RewardCallbackDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns RewardCallbackColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns RewardCallbackColumns // columns contains all the column names of Table for convenient usage. } // RewardCallbackColumns defines and stores column names for the table reward_callback. @@ -48,12 +47,11 @@ var rewardCallbackColumns = RewardCallbackColumns{ } // NewRewardCallbackDao creates and returns a new DAO object for table data access. -func NewRewardCallbackDao(handlers ...gdb.ModelHandler) *RewardCallbackDao { +func NewRewardCallbackDao() *RewardCallbackDao { return &RewardCallbackDao{ - group: "default", - table: "reward_callback", - columns: rewardCallbackColumns, - handlers: handlers, + group: "default", + table: "reward_callback", + columns: rewardCallbackColumns, } } @@ -79,11 +77,7 @@ func (dao *RewardCallbackDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *RewardCallbackDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/reward_types.go b/internal/dao/internal/reward_types.go index b8d246d..ae9bf09 100644 --- a/internal/dao/internal/reward_types.go +++ b/internal/dao/internal/reward_types.go @@ -13,43 +13,39 @@ import ( // RewardTypesDao is the data access object for the table reward_types. type RewardTypesDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // RewardTypesColumns defines and stores column names for the table reward_types. type RewardTypesColumns struct { - Id string // 奖励类型ID - Name string // 类型名称 - TencentTypeId string // 腾讯奖励类型ID(仅系统奖励有效) - Source string // 奖励来源:1=腾讯系统,2=本系统,3=其他 - CreatedAt string // 创建时间 - UpdatedAt string // 更新时间 - DeletedAt string // 软删除时间 - StoreId string // 门店 id + Id string // 奖励类型ID + Name string // 类型名称 + Code string // 唯一编码 + IconUrl string // 图标链接地址 + CreatedAt string // 创建时间 + UpdatedAt string // 更新时间 + DeletedAt string // 软删除时间 } // rewardTypesColumns holds the columns for the table reward_types. var rewardTypesColumns = RewardTypesColumns{ - Id: "id", - Name: "name", - TencentTypeId: "tencent_type_id", - Source: "source", - CreatedAt: "created_at", - UpdatedAt: "updated_at", - DeletedAt: "deleted_at", - StoreId: "store_id", + Id: "id", + Name: "name", + Code: "code", + IconUrl: "icon_url", + CreatedAt: "created_at", + UpdatedAt: "updated_at", + DeletedAt: "deleted_at", } // NewRewardTypesDao creates and returns a new DAO object for table data access. -func NewRewardTypesDao(handlers ...gdb.ModelHandler) *RewardTypesDao { +func NewRewardTypesDao() *RewardTypesDao { return &RewardTypesDao{ - group: "default", - table: "reward_types", - columns: rewardTypesColumns, - handlers: handlers, + group: "default", + table: "reward_types", + columns: rewardTypesColumns, } } @@ -75,11 +71,7 @@ func (dao *RewardTypesDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/reward_waters.go b/internal/dao/internal/reward_waters.go index 6534919..d40f2c7 100644 --- a/internal/dao/internal/reward_waters.go +++ b/internal/dao/internal/reward_waters.go @@ -13,10 +13,9 @@ import ( // RewardWatersDao is the data access object for the table reward_waters. type RewardWatersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns RewardWatersColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns RewardWatersColumns // columns contains all the column names of Table for convenient usage. } // RewardWatersColumns defines and stores column names for the table reward_waters. @@ -46,12 +45,11 @@ var rewardWatersColumns = RewardWatersColumns{ } // NewRewardWatersDao creates and returns a new DAO object for table data access. -func NewRewardWatersDao(handlers ...gdb.ModelHandler) *RewardWatersDao { +func NewRewardWatersDao() *RewardWatersDao { return &RewardWatersDao{ - group: "default", - table: "reward_waters", - columns: rewardWatersColumns, - handlers: handlers, + group: "default", + table: "reward_waters", + columns: rewardWatersColumns, } } @@ -77,11 +75,7 @@ func (dao *RewardWatersDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *RewardWatersDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/rewards.go b/internal/dao/internal/rewards.go index 1f3bc3b..6b91001 100644 --- a/internal/dao/internal/rewards.go +++ b/internal/dao/internal/rewards.go @@ -13,10 +13,9 @@ import ( // RewardsDao is the data access object for the table rewards. type RewardsDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // RewardsColumns defines and stores column names for the table rewards. @@ -43,6 +42,8 @@ type RewardsColumns struct { CreatedAt string // 创建时间 UpdatedAt string // 更新时间 DeletedAt string // 删除时间(软删除) + PrizeId string // 券 id + Source string // 奖励来源,1 为系统奖励对接腾讯,2 是门店 } // rewardsColumns holds the columns for the table rewards. @@ -69,15 +70,16 @@ var rewardsColumns = RewardsColumns{ CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", + PrizeId: "prize_id", + Source: "source", } // NewRewardsDao creates and returns a new DAO object for table data access. -func NewRewardsDao(handlers ...gdb.ModelHandler) *RewardsDao { +func NewRewardsDao() *RewardsDao { return &RewardsDao{ - group: "default", - table: "rewards", - columns: rewardsColumns, - handlers: handlers, + group: "default", + table: "rewards", + columns: rewardsColumns, } } @@ -103,11 +105,7 @@ func (dao *RewardsDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/roles.go b/internal/dao/internal/roles.go index b540549..9eab304 100644 --- a/internal/dao/internal/roles.go +++ b/internal/dao/internal/roles.go @@ -13,10 +13,9 @@ import ( // RolesDao is the data access object for the table roles. type RolesDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // RolesColumns defines and stores column names for the table roles. @@ -48,12 +47,11 @@ var rolesColumns = RolesColumns{ } // NewRolesDao creates and returns a new DAO object for table data access. -func NewRolesDao(handlers ...gdb.ModelHandler) *RolesDao { +func NewRolesDao() *RolesDao { return &RolesDao{ - group: "default", - table: "roles", - columns: rolesColumns, - handlers: handlers, + group: "default", + table: "roles", + columns: rolesColumns, } } @@ -79,11 +77,7 @@ func (dao *RolesDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/store_admins.go b/internal/dao/internal/store_admins.go index 538322c..7bcffcc 100644 --- a/internal/dao/internal/store_admins.go +++ b/internal/dao/internal/store_admins.go @@ -13,10 +13,9 @@ import ( // StoreAdminsDao is the data access object for the table store_admins. type StoreAdminsDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // StoreAdminsColumns defines and stores column names for the table store_admins. @@ -58,12 +57,11 @@ var storeAdminsColumns = StoreAdminsColumns{ } // NewStoreAdminsDao creates and returns a new DAO object for table data access. -func NewStoreAdminsDao(handlers ...gdb.ModelHandler) *StoreAdminsDao { +func NewStoreAdminsDao() *StoreAdminsDao { return &StoreAdminsDao{ - group: "default", - table: "store_admins", - columns: storeAdminsColumns, - handlers: handlers, + group: "default", + table: "store_admins", + columns: storeAdminsColumns, } } @@ -89,11 +87,7 @@ func (dao *StoreAdminsDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/store_desktop_settings.go b/internal/dao/internal/store_desktop_settings.go index 88c9cb5..dec1ba9 100644 --- a/internal/dao/internal/store_desktop_settings.go +++ b/internal/dao/internal/store_desktop_settings.go @@ -13,10 +13,9 @@ import ( // StoreDesktopSettingsDao is the data access object for the table store_desktop_settings. type StoreDesktopSettingsDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // StoreDesktopSettingsColumns defines and stores column names for the table store_desktop_settings. @@ -34,12 +33,11 @@ var storeDesktopSettingsColumns = StoreDesktopSettingsColumns{ } // NewStoreDesktopSettingsDao creates and returns a new DAO object for table data access. -func NewStoreDesktopSettingsDao(handlers ...gdb.ModelHandler) *StoreDesktopSettingsDao { +func NewStoreDesktopSettingsDao() *StoreDesktopSettingsDao { return &StoreDesktopSettingsDao{ - group: "default", - table: "store_desktop_settings", - columns: storeDesktopSettingsColumns, - handlers: handlers, + group: "default", + table: "store_desktop_settings", + columns: storeDesktopSettingsColumns, } } @@ -65,11 +63,7 @@ func (dao *StoreDesktopSettingsDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/store_ips.go b/internal/dao/internal/store_ips.go index dfdfd58..20197cb 100644 --- a/internal/dao/internal/store_ips.go +++ b/internal/dao/internal/store_ips.go @@ -13,10 +13,9 @@ import ( // StoreIpsDao is the data access object for the table store_ips. type StoreIpsDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // StoreIpsColumns defines and stores column names for the table store_ips. @@ -42,12 +41,11 @@ var storeIpsColumns = StoreIpsColumns{ } // NewStoreIpsDao creates and returns a new DAO object for table data access. -func NewStoreIpsDao(handlers ...gdb.ModelHandler) *StoreIpsDao { +func NewStoreIpsDao() *StoreIpsDao { return &StoreIpsDao{ - group: "default", - table: "store_ips", - columns: storeIpsColumns, - handlers: handlers, + group: "default", + table: "store_ips", + columns: storeIpsColumns, } } @@ -73,11 +71,7 @@ func (dao *StoreIpsDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/store_netfee_area_level.go b/internal/dao/internal/store_netfee_area_level.go index ffa209a..e2a43a6 100644 --- a/internal/dao/internal/store_netfee_area_level.go +++ b/internal/dao/internal/store_netfee_area_level.go @@ -13,10 +13,9 @@ import ( // StoreNetfeeAreaLevelDao is the data access object for the table store_netfee_area_level. type StoreNetfeeAreaLevelDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // StoreNetfeeAreaLevelColumns defines and stores column names for the table store_netfee_area_level. @@ -50,12 +49,11 @@ var storeNetfeeAreaLevelColumns = StoreNetfeeAreaLevelColumns{ } // NewStoreNetfeeAreaLevelDao creates and returns a new DAO object for table data access. -func NewStoreNetfeeAreaLevelDao(handlers ...gdb.ModelHandler) *StoreNetfeeAreaLevelDao { +func NewStoreNetfeeAreaLevelDao() *StoreNetfeeAreaLevelDao { return &StoreNetfeeAreaLevelDao{ - group: "default", - table: "store_netfee_area_level", - columns: storeNetfeeAreaLevelColumns, - handlers: handlers, + group: "default", + table: "store_netfee_area_level", + columns: storeNetfeeAreaLevelColumns, } } @@ -81,11 +79,7 @@ func (dao *StoreNetfeeAreaLevelDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/store_roles.go b/internal/dao/internal/store_roles.go index 137e1fa..8528459 100644 --- a/internal/dao/internal/store_roles.go +++ b/internal/dao/internal/store_roles.go @@ -13,10 +13,9 @@ import ( // StoreRolesDao is the data access object for the table store_roles. type StoreRolesDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // StoreRolesColumns defines and stores column names for the table store_roles. @@ -40,12 +39,11 @@ var storeRolesColumns = StoreRolesColumns{ } // NewStoreRolesDao creates and returns a new DAO object for table data access. -func NewStoreRolesDao(handlers ...gdb.ModelHandler) *StoreRolesDao { +func NewStoreRolesDao() *StoreRolesDao { return &StoreRolesDao{ - group: "default", - table: "store_roles", - columns: storeRolesColumns, - handlers: handlers, + group: "default", + table: "store_roles", + columns: storeRolesColumns, } } @@ -71,11 +69,7 @@ func (dao *StoreRolesDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/stores.go b/internal/dao/internal/stores.go index 69ed619..8bbdc42 100644 --- a/internal/dao/internal/stores.go +++ b/internal/dao/internal/stores.go @@ -13,10 +13,9 @@ import ( // StoresDao is the data access object for the table stores. type StoresDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // StoresColumns defines and stores column names for the table stores. @@ -52,12 +51,11 @@ var storesColumns = StoresColumns{ } // NewStoresDao creates and returns a new DAO object for table data access. -func NewStoresDao(handlers ...gdb.ModelHandler) *StoresDao { +func NewStoresDao() *StoresDao { return &StoresDao{ - group: "default", - table: "stores", - columns: storesColumns, - handlers: handlers, + group: "default", + table: "stores", + columns: storesColumns, } } @@ -83,11 +81,7 @@ func (dao *StoresDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/task_rewards.go b/internal/dao/internal/task_rewards.go index 95ce8f4..ea0ec0a 100644 --- a/internal/dao/internal/task_rewards.go +++ b/internal/dao/internal/task_rewards.go @@ -13,10 +13,9 @@ import ( // TaskRewardsDao is the data access object for the table task_rewards. type TaskRewardsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns TaskRewardsColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns TaskRewardsColumns // columns contains all the column names of Table for convenient usage. } // TaskRewardsColumns defines and stores column names for the table task_rewards. @@ -32,12 +31,11 @@ var taskRewardsColumns = TaskRewardsColumns{ } // NewTaskRewardsDao creates and returns a new DAO object for table data access. -func NewTaskRewardsDao(handlers ...gdb.ModelHandler) *TaskRewardsDao { +func NewTaskRewardsDao() *TaskRewardsDao { return &TaskRewardsDao{ - group: "default", - table: "task_rewards", - columns: taskRewardsColumns, - handlers: handlers, + group: "default", + table: "task_rewards", + columns: taskRewardsColumns, } } @@ -63,11 +61,7 @@ func (dao *TaskRewardsDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *TaskRewardsDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/tasks.go b/internal/dao/internal/tasks.go index dfd5153..526632b 100644 --- a/internal/dao/internal/tasks.go +++ b/internal/dao/internal/tasks.go @@ -13,10 +13,9 @@ import ( // TasksDao is the data access object for the table tasks. type TasksDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // TasksColumns defines and stores column names for the table tasks. @@ -58,12 +57,11 @@ var tasksColumns = TasksColumns{ } // NewTasksDao creates and returns a new DAO object for table data access. -func NewTasksDao(handlers ...gdb.ModelHandler) *TasksDao { +func NewTasksDao() *TasksDao { return &TasksDao{ - group: "default", - table: "tasks", - columns: tasksColumns, - handlers: handlers, + group: "default", + table: "tasks", + columns: tasksColumns, } } @@ -89,11 +87,7 @@ func (dao *TasksDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/user_task_rewards.go b/internal/dao/internal/user_task_rewards.go index 0ec45fc..12edf5d 100644 --- a/internal/dao/internal/user_task_rewards.go +++ b/internal/dao/internal/user_task_rewards.go @@ -13,10 +13,9 @@ import ( // UserTaskRewardsDao is the data access object for the table user_task_rewards. type UserTaskRewardsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns UserTaskRewardsColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns UserTaskRewardsColumns // columns contains all the column names of Table for convenient usage. } // UserTaskRewardsColumns defines and stores column names for the table user_task_rewards. @@ -32,6 +31,7 @@ type UserTaskRewardsColumns struct { CreatedAt string // 创建时间 UpdatedAt string // 更新时间 DeletedAt string // 软删除时间 + ExpiredAt string // 奖励过期时间 } // userTaskRewardsColumns holds the columns for the table user_task_rewards. @@ -47,15 +47,15 @@ var userTaskRewardsColumns = UserTaskRewardsColumns{ CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", + ExpiredAt: "expired_at", } // NewUserTaskRewardsDao creates and returns a new DAO object for table data access. -func NewUserTaskRewardsDao(handlers ...gdb.ModelHandler) *UserTaskRewardsDao { +func NewUserTaskRewardsDao() *UserTaskRewardsDao { return &UserTaskRewardsDao{ - group: "default", - table: "user_task_rewards", - columns: userTaskRewardsColumns, - handlers: handlers, + group: "default", + table: "user_task_rewards", + columns: userTaskRewardsColumns, } } @@ -81,11 +81,7 @@ func (dao *UserTaskRewardsDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *UserTaskRewardsDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/user_tasks.go b/internal/dao/internal/user_tasks.go index 257329e..69ac1d3 100644 --- a/internal/dao/internal/user_tasks.go +++ b/internal/dao/internal/user_tasks.go @@ -13,10 +13,9 @@ import ( // UserTasksDao is the data access object for the table user_tasks. type UserTasksDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // UserTasksColumns defines and stores column names for the table user_tasks. @@ -52,12 +51,11 @@ var userTasksColumns = UserTasksColumns{ } // NewUserTasksDao creates and returns a new DAO object for table data access. -func NewUserTasksDao(handlers ...gdb.ModelHandler) *UserTasksDao { +func NewUserTasksDao() *UserTasksDao { return &UserTasksDao{ - group: "default", - table: "user_tasks", - columns: userTasksColumns, - handlers: handlers, + group: "default", + table: "user_tasks", + columns: userTasksColumns, } } @@ -83,11 +81,7 @@ func (dao *UserTasksDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/users.go b/internal/dao/internal/users.go index 340eaf7..c5aa79d 100644 --- a/internal/dao/internal/users.go +++ b/internal/dao/internal/users.go @@ -13,10 +13,9 @@ import ( // UsersDao is the data access object for the table users. type UsersDao struct { - table string // table is the underlying table name of the 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the 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. } // UsersColumns defines and stores column names for the table users. @@ -60,12 +59,11 @@ var usersColumns = UsersColumns{ } // NewUsersDao creates and returns a new DAO object for table data access. -func NewUsersDao(handlers ...gdb.ModelHandler) *UsersDao { +func NewUsersDao() *UsersDao { return &UsersDao{ - group: "default", - table: "users", - columns: usersColumns, - handlers: handlers, + group: "default", + table: "users", + columns: usersColumns, } } @@ -91,11 +89,7 @@ func (dao *UsersDao) Group() string { // 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/logic/reward/reward.go b/internal/logic/reward/reward.go index 3012b27..eae482f 100644 --- a/internal/logic/reward/reward.go +++ b/internal/logic/reward/reward.go @@ -260,20 +260,18 @@ func (s *sReward) Delete(ctx context.Context, in *model.RewardDeleteIn) (out *mo func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error) { rewardCols := dao.Rewards.Columns() - rewardTypeCols := dao.RewardTypes.Columns() - rewardTypeIds := make([]int64, 0) - // ==== 权限校验 ==== + orm := dao.Rewards.Ctx(ctx).LeftJoin( + dao.RewardTypes.Table(), + fmt.Sprintf( + "%s.%s = %s.%s", + dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId, + dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id, + ), + ).Fields(fmt.Sprintf("%s.*,%s.name as reward_type_name", dao.Rewards.Table(), dao.RewardTypes.Table())) 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()) - } - + orm = orm.Where(rewardCols.Source, 1) case consts.MerchantRoleCode, consts.StoreRoleCode: // 合并商户和门店角色权限校验 var exist bool @@ -308,28 +306,11 @@ func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model. if !exist { return nil, ecode.Params.Sub("无门店权限") } - - // - array, err := dao.RewardTypes.Ctx(ctx).Where(do.RewardTypes{Source: 2, StoreId: in.StoreId}).Fields(rewardTypeCols.Id).Array() - if err != nil { - return nil, ecode.Fail.Sub("获取奖励类型列表失败") - } - for _, value := range array { - rewardTypeIds = append(rewardTypeIds, value.Int64()) - } + orm = orm.Where(rewardCols.Source, 2) default: return nil, ecode.Params.Sub("无效的角色") } - orm := dao.Rewards.Ctx(ctx).LeftJoin( - dao.RewardTypes.Table(), - fmt.Sprintf( - "%s.%s = %s.%s", - dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId, - dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id, - ), - ).Fields(fmt.Sprintf("%s.*,%s.name as reward_type_name", dao.Rewards.Table(), dao.RewardTypes.Table())). - WhereIn(dao.Rewards.Columns().RewardTypeId, rewardTypeIds) // ==== 其他查询条件 ==== if in.Status != 0 { orm = orm.Where(fmt.Sprintf("%s.%s = ?", dao.Rewards.Table(), rewardCols.Status), in.Status) diff --git a/internal/logic/rewardType/rewardType.go b/internal/logic/rewardType/rewardType.go index 4b95892..f8b1a1a 100644 --- a/internal/logic/rewardType/rewardType.go +++ b/internal/logic/rewardType/rewardType.go @@ -32,10 +32,7 @@ func (s *sRewardType) Create(ctx context.Context, in *model.RewardTypeCreateIn) } data := do.RewardTypes{ - Name: in.Name, - Source: in.Source, - StoreId: in.StoreId, - TencentTypeId: in.TencentTypeId, + Name: in.Name, } id, err := dao.RewardTypes.Ctx(ctx).OmitEmptyData().Data(data).InsertAndGetId() diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go index b0c33ec..08f4ff5 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -190,12 +190,10 @@ func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetTaskListIn dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id, dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId)). Fields( - fmt.Sprintf("%s.*, `%s`.`%s` AS %s, `%s`.`%s` AS %s", + fmt.Sprintf( + "%s.*, `%s`.`%s` AS %s", dao.Rewards.Table(), - dao.RewardTypes.Table(), dao.RewardTypes.Columns().Name, - "reward_type_name", - dao.RewardTypes.Table(), dao.RewardTypes.Columns().Source, - "reward_type_source", + dao.RewardTypes.Table(), dao.RewardTypes.Columns().Name, "reward_type_name", ), ).Where(dao.TaskRewards.Columns().TaskId, task.TaskID).Scan(&data.Rewards) if err != nil { @@ -385,3 +383,7 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge Success: true, }, nil } + +func (s *sTask) GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRecordsListIn) (out *model.UserTaskRecordsListOut, err error) { + return +} diff --git a/internal/model/do/reward_types.go b/internal/model/do/reward_types.go index 3c6634f..a70b718 100644 --- a/internal/model/do/reward_types.go +++ b/internal/model/do/reward_types.go @@ -11,13 +11,12 @@ import ( // RewardTypes is the golang structure of table reward_types for DAO operations like Where/Data. type RewardTypes struct { - g.Meta `orm:"table:reward_types, do:true"` - Id interface{} // 奖励类型ID - Name interface{} // 类型名称 - TencentTypeId interface{} // 腾讯奖励类型ID(仅系统奖励有效) - Source interface{} // 奖励来源:1=腾讯系统,2=本系统,3=其他 - CreatedAt *gtime.Time // 创建时间 - UpdatedAt *gtime.Time // 更新时间 - DeletedAt *gtime.Time // 软删除时间 - StoreId interface{} // 门店 id + g.Meta `orm:"table:reward_types, do:true"` + Id interface{} // 奖励类型ID + Name interface{} // 类型名称 + Code interface{} // 唯一编码 + IconUrl interface{} // 图标链接地址 + CreatedAt *gtime.Time // 创建时间 + UpdatedAt *gtime.Time // 更新时间 + DeletedAt *gtime.Time // 软删除时间 } diff --git a/internal/model/do/rewards.go b/internal/model/do/rewards.go index e565a19..21a6d2f 100644 --- a/internal/model/do/rewards.go +++ b/internal/model/do/rewards.go @@ -34,4 +34,6 @@ type Rewards struct { CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 DeletedAt *gtime.Time // 删除时间(软删除) + PrizeId interface{} // 券 id + Source interface{} // 奖励来源,1 为系统奖励对接腾讯,2 是门店 } diff --git a/internal/model/do/user_task_rewards.go b/internal/model/do/user_task_rewards.go index 20bf094..d188677 100644 --- a/internal/model/do/user_task_rewards.go +++ b/internal/model/do/user_task_rewards.go @@ -23,4 +23,5 @@ type UserTaskRewards struct { CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 DeletedAt *gtime.Time // 软删除时间 + ExpiredAt *gtime.Time // 奖励过期时间 } diff --git a/internal/model/entity/reward_types.go b/internal/model/entity/reward_types.go index 3a8c360..eb2f34f 100644 --- a/internal/model/entity/reward_types.go +++ b/internal/model/entity/reward_types.go @@ -10,12 +10,11 @@ import ( // RewardTypes is the golang structure for table reward_types. type RewardTypes struct { - Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID - Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称 - TencentTypeId int `json:"tencentTypeId" orm:"tencent_type_id" description:"腾讯奖励类型ID(仅系统奖励有效)"` // 腾讯奖励类型ID(仅系统奖励有效) - Source int `json:"source" orm:"source" description:"奖励来源:1=腾讯系统,2=本系统,3=其他"` // 奖励来源:1=腾讯系统,2=本系统,3=其他 - 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:"软删除时间"` // 软删除时间 - StoreId int64 `json:"storeId" orm:"store_id" description:"门店 id"` // 门店 id + Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID + Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称 + Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码 + IconUrl string `json:"iconUrl" orm:"icon_url" 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:"软删除时间"` // 软删除时间 } diff --git a/internal/model/entity/rewards.go b/internal/model/entity/rewards.go index 9ce56fe..88113c6 100644 --- a/internal/model/entity/rewards.go +++ b/internal/model/entity/rewards.go @@ -32,4 +32,6 @@ type Rewards struct { 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:"删除时间(软删除)"` // 删除时间(软删除) + PrizeId string `json:"prizeId" orm:"prize_id" description:"券 id"` // 券 id + Source int `json:"source" orm:"source" description:"奖励来源,1 为系统奖励对接腾讯,2 是门店"` // 奖励来源,1 为系统奖励对接腾讯,2 是门店 } diff --git a/internal/model/entity/user_task_rewards.go b/internal/model/entity/user_task_rewards.go index df801ff..50027d2 100644 --- a/internal/model/entity/user_task_rewards.go +++ b/internal/model/entity/user_task_rewards.go @@ -21,4 +21,5 @@ type UserTaskRewards struct { 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:"软删除时间"` // 软删除时间 + ExpiredAt *gtime.Time `json:"expiredAt" orm:"expired_at" description:"奖励过期时间"` // 奖励过期时间 } diff --git a/internal/model/reward.go b/internal/model/reward.go index 561b407..533a0d4 100644 --- a/internal/model/reward.go +++ b/internal/model/reward.go @@ -6,30 +6,30 @@ import ( // Reward 奖励表 type Reward struct { - Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID - StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID,系统奖励为NULL"` // 门店ID,系统奖励为NULL - Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称 - RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID,关联 reward_types 表"` // 奖励类型ID,关联 reward_types 表 - RewardTypeName string `json:"rewardTypeName" orm:"reward_type_name" description:"奖励类型名称"` // 奖励类型名称 - RewardTypeSource int `json:"rewardTypeSource" orm:"reward_type_source" description:"奖励类型来源"` // 奖励类型来源 - GameId int64 `json:"gameId" orm:"game_id" description:"游戏ID"` // 游戏ID - ImageUrl string `json:"imageUrl" orm:"image_url" description:"奖励图片链接"` // 奖励图片链接 - QqGoodsId string `json:"qqGoodsId" orm:"qq_goods_id" description:"QQ网吧物品ID"` // QQ网吧物品ID - QqGoodsIdStr string `json:"qqGoodsIdStr" orm:"qq_goods_id_str" description:"QQ网吧物品ID字符串"` // QQ网吧物品ID字符串 - Status int `json:"status" orm:"status" description:"状态:1=启用,2=禁用"` // 状态:1=启用,2=禁用 - 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时) - DailyTotalLimit uint64 `json:"dailyTotalLimit" orm:"daily_total_limit" description:"每日发放总限(NULL表示不限制)"` // 每日发放总限(NULL表示不限制) - TotalLimit uint64 `json:"totalLimit" orm:"total_limit" description:"奖励总限(NULL表示不限制)"` // 奖励总限(NULL表示不限制) - UserDailyLimit uint64 `json:"userDailyLimit" orm:"user_daily_limit" description:"用户每日领取限制(NULL表示不限制)"` // 用户每日领取限制(NULL表示不限制) - UserTotalLimit uint64 `json:"userTotalLimit" orm:"user_total_limit" description:"用户领取总次数限制(NULL表示不限制)"` // 用户领取总次数限制(NULL表示不限制) - ReceivedNum uint64 `json:"receivedNum" orm:"received_num" description:"已领取数量"` // 已领取数量 - 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:"删除时间(软删除)"` // 删除时间(软删除) + Id int64 `json:"id" orm:"id" description:"奖励ID"` // 奖励ID + StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID,系统奖励为NULL"` // 门店ID,系统奖励为NULL + Name string `json:"name" orm:"name" description:"奖励名称"` // 奖励名称 + RewardTypeId int64 `json:"rewardTypeId" orm:"reward_type_id" description:"奖励类型ID,关联 reward_types 表"` // 奖励类型ID,关联 reward_types 表 + RewardTypeName string `json:"rewardTypeName" orm:"reward_type_name" description:"奖励类型名称"` // 奖励类型名称 + 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:"奖励图片链接"` // 奖励图片链接 + QqGoodsId string `json:"qqGoodsId" orm:"qq_goods_id" description:"QQ网吧物品ID"` // QQ网吧物品ID + QqGoodsIdStr string `json:"qqGoodsIdStr" orm:"qq_goods_id_str" description:"QQ网吧物品ID字符串"` // QQ网吧物品ID字符串 + Status int `json:"status" orm:"status" description:"状态:1=启用,2=禁用"` // 状态:1=启用,2=禁用 + 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时) + DailyTotalLimit uint64 `json:"dailyTotalLimit" orm:"daily_total_limit" description:"每日发放总限(NULL表示不限制)"` // 每日发放总限(NULL表示不限制) + TotalLimit uint64 `json:"totalLimit" orm:"total_limit" description:"奖励总限(NULL表示不限制)"` // 奖励总限(NULL表示不限制) + UserDailyLimit uint64 `json:"userDailyLimit" orm:"user_daily_limit" description:"用户每日领取限制(NULL表示不限制)"` // 用户每日领取限制(NULL表示不限制) + UserTotalLimit uint64 `json:"userTotalLimit" orm:"user_total_limit" description:"用户领取总次数限制(NULL表示不限制)"` // 用户领取总次数限制(NULL表示不限制) + ReceivedNum uint64 `json:"receivedNum" orm:"received_num" description:"已领取数量"` // 已领取数量 + 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 创建奖励入参 diff --git a/internal/model/userTask.go b/internal/model/userTask.go index 55e0914..313b6f3 100644 --- a/internal/model/userTask.go +++ b/internal/model/userTask.go @@ -70,3 +70,16 @@ type GetTaskIn struct { type GetTaskOut struct { Success bool `json:"success"` } + +type UserTaskRecordsListIn struct { + UserId int + Page int + Size int + StoreId int + NetBarAccount string +} + +type UserTaskRecordsListOut struct { + List []UserTask + Total int +} diff --git a/internal/service/reward.go b/internal/service/reward.go index b0943ed..9d88ec2 100644 --- a/internal/service/reward.go +++ b/internal/service/reward.go @@ -29,6 +29,7 @@ type ( // GetGoodsDetails 物品详情 GetGoodsDetails(ctx context.Context, in *model.GetGoodsDetailsIn) (out *model.QueryUserGoodsDetailResponse, err error) OperateTaskReward(ctx context.Context, in *model.OperateTaskRewardIn) (out *model.OperateTaskRewardOut, err error) + // CallBack 奖励回调 CallBack(ctx context.Context, in *model.RewardCallbackIn) (out *model.RewardCallbackOut, err error) } ) diff --git a/internal/service/task.go b/internal/service/task.go index abec86d..53ce6f8 100644 --- a/internal/service/task.go +++ b/internal/service/task.go @@ -21,6 +21,7 @@ type ( GetSelectorList(ctx context.Context, in *model.SelectorIn) (out *[]model.SelectorOut, err error) // GetTask 完成任务 GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.GetTaskOut, err error) + GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRecordsListIn) (out *model.UserTaskRecordsListOut, err error) } ) From efed64ed9e99a3e5d4cd32471ad28dc01db2daad Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Thu, 26 Jun 2025 16:31:43 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=BC=93=E5=AD=98+mqtt?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E6=B6=88=E6=81=AF=E7=9B=91=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/consts/redis.go | 4 +- .../rewardType/rewardType_v1_list.go | 12 +- .../statistic_v1_get_online_device.go | 9 +- internal/logic/rewardType/rewardType.go | 24 ---- .../storeDesktopSetting.go | 15 +- internal/logic/task/task.go | 16 ++- internal/model/rewardType.go | 28 ++-- internal/packed/packed.go | 2 +- utility/mqtt/emqx/emqx.go | 132 +++++++++++++++++- 9 files changed, 180 insertions(+), 62 deletions(-) diff --git a/internal/consts/redis.go b/internal/consts/redis.go index 2ef0834..a7549e9 100644 --- a/internal/consts/redis.go +++ b/internal/consts/redis.go @@ -22,6 +22,6 @@ const ( ) const ( - NetbarOnlineNumberKey = "%s:online:device:%s" - NetbarOnlineDeviceSetKey = "%s:online_devices" + NetbarOnlineNumberKey = "%s:online_number" + OnlineDeviceSetKey = "online:devices" ) diff --git a/internal/controller/rewardType/rewardType_v1_list.go b/internal/controller/rewardType/rewardType_v1_list.go index c586be6..ea170b5 100644 --- a/internal/controller/rewardType/rewardType_v1_list.go +++ b/internal/controller/rewardType/rewardType_v1_list.go @@ -20,13 +20,11 @@ func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListR ) out, err := service.RewardType().List(ctx, &model.RewardTypeListIn{ - Page: req.Page, - Size: req.Size, - OperatorId: operatorId, - OperatorRole: operatorRole, - StoreId: req.StoreId, - Name: req.Name, - Source: req.Source, + Page: req.Page, + Size: req.Size, + StoreId: req.StoreId, + Name: req.Name, + Source: req.Source, }) if err != nil { diff --git a/internal/controller/statistic/statistic_v1_get_online_device.go b/internal/controller/statistic/statistic_v1_get_online_device.go index adbbf6e..2c2d859 100644 --- a/internal/controller/statistic/statistic_v1_get_online_device.go +++ b/internal/controller/statistic/statistic_v1_get_online_device.go @@ -10,6 +10,11 @@ import ( ) func (c *ControllerV1) GetOnlineDevice(ctx context.Context, req *v1.GetOnlineDeviceReq) (res *v1.GetOnlineDeviceRes, err error) { - card, err := g.Redis().SCard(ctx, fmt.Sprintf(consts.NetbarOnlineDeviceSetKey, req.NetbarAccount)) - return &v1.GetOnlineDeviceRes{Total: card}, err + get, err := g.Redis().Get(ctx, fmt.Sprintf(consts.NetbarOnlineNumberKey, req.NetbarAccount)) + if err != nil { + return nil, err + } + return &v1.GetOnlineDeviceRes{ + Total: get.Int64(), + }, nil } diff --git a/internal/logic/rewardType/rewardType.go b/internal/logic/rewardType/rewardType.go index f8b1a1a..9268a97 100644 --- a/internal/logic/rewardType/rewardType.go +++ b/internal/logic/rewardType/rewardType.go @@ -107,30 +107,6 @@ func (s *sRewardType) Delete(ctx context.Context, in *model.RewardTypeDeleteIn) func (s *sRewardType) List(ctx context.Context, in *model.RewardTypeListIn) (out *model.RewardTypeListOut, err error) { mod := dao.RewardTypes.Ctx(ctx).Where("deleted_at IS NULL") - switch in.OperatorRole { - case consts.AdminRoleCode: - // 系统管理员只能看系统奖励类型 - mod = mod.Where("source", 1) - - case consts.MerchantRoleCode: - // 校验商户是否对该门店有权限 - if err = checkRewardTypePermission(ctx, in.OperatorRole, in.OperatorId, 2, in.StoreId); err != nil { - return nil, err - } - // 只查询该门店的奖励类型(source=2且store_id=指定门店) - mod = mod.Where("source", 2).WhereIn("store_id", in.StoreId) - - case consts.StoreRoleCode: - // 校验门店权限 - if err = checkRewardTypePermission(ctx, in.OperatorRole, in.OperatorId, 2, in.StoreId); err != nil { - return nil, err - } - mod = mod.Where("source", 2).Where("store_id", in.StoreId) - - default: - return nil, ecode.Params.Sub("无效的操作角色") - } - // 其余过滤条件 if in.Name != "" { mod = mod.WhereLike("name", "%"+in.Name+"%") diff --git a/internal/logic/storeDesktopSetting/storeDesktopSetting.go b/internal/logic/storeDesktopSetting/storeDesktopSetting.go index 9a3a444..681eada 100644 --- a/internal/logic/storeDesktopSetting/storeDesktopSetting.go +++ b/internal/logic/storeDesktopSetting/storeDesktopSetting.go @@ -13,17 +13,10 @@ import ( ) type sStoreDesktopSetting struct { - mqttCLient mqtt.MqttClient } func New() service.IStoreDesktopSetting { - client, b := mqtt.GetClient("emqx") - if !b { - return nil - } - return &sStoreDesktopSetting{ - mqttCLient: client, - } + return &sStoreDesktopSetting{} } func init() { service.RegisterStoreDesktopSetting(New()) @@ -74,7 +67,11 @@ func (s *sStoreDesktopSetting) Save(ctx context.Context, in model.SaveDesktopSet if err != nil { return nil, err } - err = s.mqttCLient.Publish(fmt.Sprintf("/desktop/%d", in.StoreId), marshal) + client, b := mqtt.GetClient("emqx") + if !b { + return nil, gerror.New("获取MQTT客户端失败") + } + err = client.Publish(fmt.Sprintf("/desktop/%d", in.StoreId), marshal) if err != nil { return nil, err } diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go index 08f4ff5..a410cf7 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -385,5 +385,19 @@ func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.Ge } func (s *sTask) GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRecordsListIn) (out *model.UserTaskRecordsListOut, err error) { - return + list := make([]model.UserTask, 0) + var total int + orm := dao.UserTasks.Ctx(ctx).Where(dao.UserTasks.Columns().Id, in.UserId) + + if in.StoreId != 0 { + orm = orm.Where(dao.UserTasks.Columns().StoreId, in.StoreId) + } + err = orm.Page(in.Page, in.Size).ScanAndCount(&list, &total, false) + if err != nil { + return nil, ecode.Fail.Sub("获取用户任务列表失败") + } + return &model.UserTaskRecordsListOut{ + List: list, + Total: total, + }, nil } diff --git a/internal/model/rewardType.go b/internal/model/rewardType.go index dec3cf1..b36d766 100644 --- a/internal/model/rewardType.go +++ b/internal/model/rewardType.go @@ -6,13 +6,13 @@ import ( // RewardType 奖励类型表 type RewardType struct { - Id int64 `json:"id" dc:"奖励类型ID"` - Name string `json:"name" dc:"奖励类型名称(如积分、优惠券)"` - TencentTypeId int `json:"tencentTypeId" dc:"腾讯奖励类型ID(仅系统奖励有效)"` - Source int `json:"source" dc:"来源:1=腾讯系统,2=本系统,3=其他"` - CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间"` - UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间"` - DeletedAt *gtime.Time `json:"deletedAt" dc:"软删除时间戳"` + Id int64 `json:"id" orm:"id" description:"奖励类型ID"` // 奖励类型ID + Name string `json:"name" orm:"name" description:"类型名称"` // 类型名称 + Code string `json:"code" orm:"code" description:"唯一编码"` // 唯一编码 + IconUrl string `json:"iconUrl" orm:"icon_url" 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:"软删除时间"` // 软删除时间 } // RewardTypeCreateIn 创建奖励类型入参 @@ -59,14 +59,12 @@ type RewardTypeDeleteOut struct { // RewardTypeListIn 获取奖励类型列表入参 type RewardTypeListIn struct { - OperatorId int64 - OperatorRole string - Page int - Size int - Name string - StoreId int64 - Status int - Source int + Page int + Size int + Name string + StoreId int64 + Status int + Source int } // RewardTypeListOut 获取奖励类型列表出参 diff --git a/internal/packed/packed.go b/internal/packed/packed.go index e61b667..d483800 100644 --- a/internal/packed/packed.go +++ b/internal/packed/packed.go @@ -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" diff --git a/utility/mqtt/emqx/emqx.go b/utility/mqtt/emqx/emqx.go index b7b9de0..7e7e8a5 100644 --- a/utility/mqtt/emqx/emqx.go +++ b/utility/mqtt/emqx/emqx.go @@ -3,6 +3,9 @@ package emqx import ( "context" "fmt" + "github.com/gogf/gf/v2/encoding/gjson" + "server/internal/consts" + "strconv" "sync" "time" @@ -84,9 +87,20 @@ func (e *emqxClient) Subscribe(topic string, handler func(topic string, payload return err } +type DeviceData struct { + NetbarAccount string `json:"netbarAccount"` + DeviceId string `json:"deviceId"` + DeviceName string `json:"deviceName"` + IP string `json:"ip"` + MACAddress string `json:"macAddress"` +} + // init 注册emqx客户端 func init() { + + // 创建可取消的上下文 ctx := context.Background() + // 加载 MQTT 配置 cfg := g.Config() host := cfg.MustGet(ctx, "mqtt.emqx.host").String() port := cfg.MustGet(ctx, "mqtt.emqx.port").Int() @@ -97,6 +111,122 @@ func init() { broker := fmt.Sprintf("tcp://%s:%d", host, port) client := New(broker, clientId, username, password) + // 注册 MQTT 客户端 mqtt.Register("emqx", client) - glog.Infof(ctx, "EMQX客户端注册完成,broker=%s, clientID=%s", broker, clientId) + + glog.Infof(ctx, "EMQX 客户端注册完成,broker=%s, clientID=%s", broker, clientId) + // 订阅设备上线消息 + go func() { + ctx := context.Background() + err := client.Subscribe("/up", func(topic string, payload []byte) { + glog.Infof(ctx, "收到 MQTT 消息,topic=%s", topic) + + var data DeviceData + if err := gjson.Unmarshal(payload, &data); err != nil { + glog.Errorf(ctx, "[/up] 解析设备信息失败: %v", err) + return + } + + // 增加门店在线设备计数 + key := fmt.Sprintf(consts.NetbarOnlineNumberKey, data.NetbarAccount) + if _, err := g.Redis().Incr(ctx, key); err != nil { + glog.Errorf(ctx, "增加 Redis 计数失败 %s: %v", key, err) + return + } + + // 更新在线设备集合 + setKey := "system:online:devices" + if _, err := g.Redis().HSet(ctx, setKey, map[string]interface{}{ + data.DeviceId: time.Now().Unix(), + }); err != nil { + glog.Errorf(ctx, "更新在线设备集合失败 %s: %v", setKey, err) + return + } + + // 存储设备信息(用于离线检测时获取 NetbarAccount) + deviceKey := fmt.Sprintf("device:%s", data.DeviceId) + if _, err := g.Redis().HSet(ctx, deviceKey, map[string]interface{}{ + "netbarAccount": data.NetbarAccount, + "deviceName": data.DeviceName, + "ip": data.IP, + "macAddress": data.MACAddress, + }); err != nil { + glog.Errorf(ctx, "存储设备信息失败 %s: %v", deviceKey, err) + } + }) + if err != nil { + glog.Errorf(ctx, "订阅 /up 失败: %v", err) + } + }() + + // 监控离线设备 + go func() { + ctx := context.Background() + ticker := time.NewTicker(10 * time.Second) + defer ticker.Stop() + + for { + select { + case <-ctx.Done(): + glog.Info(ctx, "停止离线设备监控") + return + case <-ticker.C: + setKey := "system:online:devices" + devicesVar, err := g.Redis().HGetAll(ctx, setKey) + if err != nil { + glog.Errorf(ctx, "获取在线设备失败: %v", err) + continue + } + + // 转换为 map[string]string + devices := devicesVar.MapStrStr() + if len(devices) == 0 { + continue + } + + now := time.Now().Unix() + for deviceId, timestampStr := range devices { + // 使用 strconv.ParseInt 替代 time.ParseInt + timestamp, err := strconv.ParseInt(timestampStr, 10, 64) + if err != nil { + glog.Errorf(ctx, "无效时间戳 for 设备 %s: %v", deviceId, err) + continue + } + + // 检查设备是否离线(超过 10 秒未更新) + if now-timestamp > 10 { + // 获取设备信息 + dataKey := fmt.Sprintf("device:%s", deviceId) + dataVar, err := g.Redis().HGetAll(ctx, dataKey) + if err != nil { + glog.Errorf(ctx, "获取设备数据失败 %s: %v", dataKey, err) + continue + } + + // 转换为 map[string]string + data := dataVar.MapStrStr() + netbarAccount, exists := data["netbarAccount"] + if !exists { + glog.Errorf(ctx, "设备 %s 缺少 netbarAccount", deviceId) + continue + } + + // 减少在线设备计数 + key := fmt.Sprintf(consts.NetbarOnlineNumberKey, netbarAccount) + if _, err := g.Redis().Decr(ctx, key); err != nil { + glog.Errorf(ctx, "减少 Redis 计数失败 %s: %v", key, err) + } + + // 从在线设备集合中移除 + if _, err := g.Redis().HDel(ctx, setKey, deviceId); err != nil { + glog.Errorf(ctx, "移除设备 %s 从在线集合失败: %v", deviceId, err) + } else { + glog.Infof(ctx, "设备 %s 已标记为离线", deviceId) + } + } + } + } + } + }() + }