diff --git a/internal/consts/consts.go b/internal/consts/consts.go index 1728d35..5e6d79f 100644 --- a/internal/consts/consts.go +++ b/internal/consts/consts.go @@ -3,3 +3,7 @@ package consts const ( DefaultPassword = "Aa123456" ) + +const ( + DefaultUserAvatar = "https://arenaxx.oss-cn-chengdu.aliyuncs.com/user/default-user-image.png" +) diff --git a/internal/consts/userTaskReward.go b/internal/consts/userTaskReward.go index 05413fa..a7a616a 100644 --- a/internal/consts/userTaskReward.go +++ b/internal/consts/userTaskReward.go @@ -2,11 +2,10 @@ package consts // 用户任务奖励状态 const ( - RewardInitStatus = iota + 1 - RewardPendingStatus - RewardClaimedStatus - RewardExchangeStatus - RewardSuccessStatus - RewardExpiredStatus - RewardFailedStatus + RewardInitStatus = iota + 1 // 待完成 + RewardPendingStatus // 待领取 + RewardExchangeStatus // 已领取,待兑换 + RewardExpiredStatus // 已过期 + RewardFailedStatus // 领取失败 + RewardSuccessStatus // 奖励已成功发放 ) diff --git a/internal/dao/internal/admins.go b/internal/dao/internal/admins.go index 7c3f2be..dc72d15 100644 --- a/internal/dao/internal/admins.go +++ b/internal/dao/internal/admins.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewAdminsDao() *AdminsDao { +func NewAdminsDao(handlers ...gdb.ModelHandler) *AdminsDao { return &AdminsDao{ - group: "default", - table: "admins", - columns: adminsColumns, + group: "default", + table: "admins", + 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. 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. diff --git a/internal/dao/internal/feedbacks.go b/internal/dao/internal/feedbacks.go index d67a1e5..7a8d085 100644 --- a/internal/dao/internal/feedbacks.go +++ b/internal/dao/internal/feedbacks.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewFeedbacksDao() *FeedbacksDao { +func NewFeedbacksDao(handlers ...gdb.ModelHandler) *FeedbacksDao { return &FeedbacksDao{ - group: "default", - table: "feedbacks", - columns: feedbacksColumns, + group: "default", + table: "feedbacks", + 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. 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. diff --git a/internal/dao/internal/games.go b/internal/dao/internal/games.go index b53dd54..dac75c7 100644 --- a/internal/dao/internal/games.go +++ b/internal/dao/internal/games.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewGamesDao() *GamesDao { +func NewGamesDao(handlers ...gdb.ModelHandler) *GamesDao { return &GamesDao{ - group: "default", - table: "games", - columns: gamesColumns, + group: "default", + table: "games", + 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. 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. diff --git a/internal/dao/internal/merchant_admins.go b/internal/dao/internal/merchant_admins.go index 51ac691..64533e1 100644 --- a/internal/dao/internal/merchant_admins.go +++ b/internal/dao/internal/merchant_admins.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewMerchantAdminsDao() *MerchantAdminsDao { +func NewMerchantAdminsDao(handlers ...gdb.ModelHandler) *MerchantAdminsDao { return &MerchantAdminsDao{ - group: "default", - table: "merchant_admins", - columns: merchantAdminsColumns, + group: "default", + table: "merchant_admins", + 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. 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. diff --git a/internal/dao/internal/merchants.go b/internal/dao/internal/merchants.go index 6dd5d05..717f855 100644 --- a/internal/dao/internal/merchants.go +++ b/internal/dao/internal/merchants.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewMerchantsDao() *MerchantsDao { +func NewMerchantsDao(handlers ...gdb.ModelHandler) *MerchantsDao { return &MerchantsDao{ - group: "default", - table: "merchants", - columns: merchantsColumns, + group: "default", + table: "merchants", + 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. 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. diff --git a/internal/dao/internal/notices.go b/internal/dao/internal/notices.go index 5cc451a..9c2cfce 100644 --- a/internal/dao/internal/notices.go +++ b/internal/dao/internal/notices.go @@ -13,9 +13,10 @@ 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. + 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. } // NoticesColumns defines and stores column names for the table notices. @@ -49,11 +50,12 @@ var noticesColumns = NoticesColumns{ } // NewNoticesDao creates and returns a new DAO object for table data access. -func NewNoticesDao() *NoticesDao { +func NewNoticesDao(handlers ...gdb.ModelHandler) *NoticesDao { return &NoticesDao{ - group: "default", - table: "notices", - columns: noticesColumns, + group: "default", + table: "notices", + columns: noticesColumns, + handlers: handlers, } } @@ -79,7 +81,11 @@ 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 { - 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. diff --git a/internal/dao/internal/reward_types.go b/internal/dao/internal/reward_types.go index 591cab5..b8d246d 100644 --- a/internal/dao/internal/reward_types.go +++ b/internal/dao/internal/reward_types.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewRewardTypesDao() *RewardTypesDao { +func NewRewardTypesDao(handlers ...gdb.ModelHandler) *RewardTypesDao { return &RewardTypesDao{ - group: "default", - table: "reward_types", - columns: rewardTypesColumns, + group: "default", + table: "reward_types", + 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. 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. diff --git a/internal/dao/internal/reward_waters.go b/internal/dao/internal/reward_waters.go index 8ae98e1..6534919 100644 --- a/internal/dao/internal/reward_waters.go +++ b/internal/dao/internal/reward_waters.go @@ -13,9 +13,10 @@ 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. + 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. } // RewardWatersColumns defines and stores column names for the table reward_waters. @@ -29,7 +30,6 @@ type RewardWatersColumns struct { CreatedAt string // UpdatedAt string // DeletedAt string // - GameId string // 游戏唯一 id } // rewardWatersColumns holds the columns for the table reward_waters. @@ -43,15 +43,15 @@ var rewardWatersColumns = RewardWatersColumns{ CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", - GameId: "game_id", } // NewRewardWatersDao creates and returns a new DAO object for table data access. -func NewRewardWatersDao() *RewardWatersDao { +func NewRewardWatersDao(handlers ...gdb.ModelHandler) *RewardWatersDao { return &RewardWatersDao{ - group: "default", - table: "reward_waters", - columns: rewardWatersColumns, + group: "default", + table: "reward_waters", + columns: rewardWatersColumns, + handlers: handlers, } } @@ -77,7 +77,11 @@ 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 { - 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. diff --git a/internal/dao/internal/rewards.go b/internal/dao/internal/rewards.go index 86d8d4c..1f3bc3b 100644 --- a/internal/dao/internal/rewards.go +++ b/internal/dao/internal/rewards.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewRewardsDao() *RewardsDao { +func NewRewardsDao(handlers ...gdb.ModelHandler) *RewardsDao { return &RewardsDao{ - group: "default", - table: "rewards", - columns: rewardsColumns, + group: "default", + table: "rewards", + 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. 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. diff --git a/internal/dao/internal/roles.go b/internal/dao/internal/roles.go index 9eab304..b540549 100644 --- a/internal/dao/internal/roles.go +++ b/internal/dao/internal/roles.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewRolesDao() *RolesDao { +func NewRolesDao(handlers ...gdb.ModelHandler) *RolesDao { return &RolesDao{ - group: "default", - table: "roles", - columns: rolesColumns, + group: "default", + table: "roles", + 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. 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. diff --git a/internal/dao/internal/store_admins.go b/internal/dao/internal/store_admins.go index 7bcffcc..538322c 100644 --- a/internal/dao/internal/store_admins.go +++ b/internal/dao/internal/store_admins.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewStoreAdminsDao() *StoreAdminsDao { +func NewStoreAdminsDao(handlers ...gdb.ModelHandler) *StoreAdminsDao { return &StoreAdminsDao{ - group: "default", - table: "store_admins", - columns: storeAdminsColumns, + group: "default", + table: "store_admins", + 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. 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. diff --git a/internal/dao/internal/store_desktop_settings.go b/internal/dao/internal/store_desktop_settings.go index dec1ba9..88c9cb5 100644 --- a/internal/dao/internal/store_desktop_settings.go +++ b/internal/dao/internal/store_desktop_settings.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewStoreDesktopSettingsDao() *StoreDesktopSettingsDao { +func NewStoreDesktopSettingsDao(handlers ...gdb.ModelHandler) *StoreDesktopSettingsDao { return &StoreDesktopSettingsDao{ - group: "default", - table: "store_desktop_settings", - columns: storeDesktopSettingsColumns, + group: "default", + table: "store_desktop_settings", + 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. 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. diff --git a/internal/dao/internal/store_ips.go b/internal/dao/internal/store_ips.go index 20197cb..dfdfd58 100644 --- a/internal/dao/internal/store_ips.go +++ b/internal/dao/internal/store_ips.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewStoreIpsDao() *StoreIpsDao { +func NewStoreIpsDao(handlers ...gdb.ModelHandler) *StoreIpsDao { return &StoreIpsDao{ - group: "default", - table: "store_ips", - columns: storeIpsColumns, + group: "default", + table: "store_ips", + 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. 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. diff --git a/internal/dao/internal/store_netfee_area_level.go b/internal/dao/internal/store_netfee_area_level.go index e2a43a6..ffa209a 100644 --- a/internal/dao/internal/store_netfee_area_level.go +++ b/internal/dao/internal/store_netfee_area_level.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewStoreNetfeeAreaLevelDao() *StoreNetfeeAreaLevelDao { +func NewStoreNetfeeAreaLevelDao(handlers ...gdb.ModelHandler) *StoreNetfeeAreaLevelDao { return &StoreNetfeeAreaLevelDao{ - group: "default", - table: "store_netfee_area_level", - columns: storeNetfeeAreaLevelColumns, + group: "default", + table: "store_netfee_area_level", + 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. 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. diff --git a/internal/dao/internal/store_roles.go b/internal/dao/internal/store_roles.go index 8528459..137e1fa 100644 --- a/internal/dao/internal/store_roles.go +++ b/internal/dao/internal/store_roles.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewStoreRolesDao() *StoreRolesDao { +func NewStoreRolesDao(handlers ...gdb.ModelHandler) *StoreRolesDao { return &StoreRolesDao{ - group: "default", - table: "store_roles", - columns: storeRolesColumns, + group: "default", + table: "store_roles", + 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. 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. diff --git a/internal/dao/internal/stores.go b/internal/dao/internal/stores.go index 8bbdc42..69ed619 100644 --- a/internal/dao/internal/stores.go +++ b/internal/dao/internal/stores.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewStoresDao() *StoresDao { +func NewStoresDao(handlers ...gdb.ModelHandler) *StoresDao { return &StoresDao{ - group: "default", - table: "stores", - columns: storesColumns, + group: "default", + table: "stores", + 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. 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. diff --git a/internal/dao/internal/task_rewards.go b/internal/dao/internal/task_rewards.go index ea0ec0a..95ce8f4 100644 --- a/internal/dao/internal/task_rewards.go +++ b/internal/dao/internal/task_rewards.go @@ -13,9 +13,10 @@ 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. + 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. } // TaskRewardsColumns defines and stores column names for the table task_rewards. @@ -31,11 +32,12 @@ var taskRewardsColumns = TaskRewardsColumns{ } // NewTaskRewardsDao creates and returns a new DAO object for table data access. -func NewTaskRewardsDao() *TaskRewardsDao { +func NewTaskRewardsDao(handlers ...gdb.ModelHandler) *TaskRewardsDao { return &TaskRewardsDao{ - group: "default", - table: "task_rewards", - columns: taskRewardsColumns, + group: "default", + table: "task_rewards", + columns: taskRewardsColumns, + handlers: handlers, } } @@ -61,7 +63,11 @@ 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 { - 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. diff --git a/internal/dao/internal/tasks.go b/internal/dao/internal/tasks.go index 526632b..dfd5153 100644 --- a/internal/dao/internal/tasks.go +++ b/internal/dao/internal/tasks.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewTasksDao() *TasksDao { +func NewTasksDao(handlers ...gdb.ModelHandler) *TasksDao { return &TasksDao{ - group: "default", - table: "tasks", - columns: tasksColumns, + group: "default", + table: "tasks", + 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. 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. diff --git a/internal/dao/internal/user_task_rewards.go b/internal/dao/internal/user_task_rewards.go index da3d00e..0ec45fc 100644 --- a/internal/dao/internal/user_task_rewards.go +++ b/internal/dao/internal/user_task_rewards.go @@ -13,9 +13,10 @@ 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. + 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. } // UserTaskRewardsColumns defines and stores column names for the table user_task_rewards. @@ -24,9 +25,10 @@ type UserTaskRewardsColumns struct { UserTaskId string // 关联用户任务记录ID RewardId string // 奖励ID RewardName string // 奖励名称冗余字段 - Status string // 状态:1=待完成,2=待领取,3=已领取,4=待兑换,5=已完成,6=已过期,7=发放失败 + Status string // 状态:1=待用户完成任务,2=待领取,3=已领取, 待兑换,4=已过期,5=发放失败, 6=结束 Remark string // 备注或失败原因 ExternalOrderId string // 第三方发放平台的订单ID + InnerOrderId string // 系统内部订单ID CreatedAt string // 创建时间 UpdatedAt string // 更新时间 DeletedAt string // 软删除时间 @@ -41,17 +43,19 @@ var userTaskRewardsColumns = UserTaskRewardsColumns{ Status: "status", Remark: "remark", ExternalOrderId: "external_order_id", + InnerOrderId: "inner_order_id", CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", } // NewUserTaskRewardsDao creates and returns a new DAO object for table data access. -func NewUserTaskRewardsDao() *UserTaskRewardsDao { +func NewUserTaskRewardsDao(handlers ...gdb.ModelHandler) *UserTaskRewardsDao { return &UserTaskRewardsDao{ - group: "default", - table: "user_task_rewards", - columns: userTaskRewardsColumns, + group: "default", + table: "user_task_rewards", + columns: userTaskRewardsColumns, + handlers: handlers, } } @@ -77,7 +81,11 @@ 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 { - 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. diff --git a/internal/dao/internal/user_tasks.go b/internal/dao/internal/user_tasks.go index 69ac1d3..257329e 100644 --- a/internal/dao/internal/user_tasks.go +++ b/internal/dao/internal/user_tasks.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewUserTasksDao() *UserTasksDao { +func NewUserTasksDao(handlers ...gdb.ModelHandler) *UserTasksDao { return &UserTasksDao{ - group: "default", - table: "user_tasks", - columns: userTasksColumns, + group: "default", + table: "user_tasks", + 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. 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. diff --git a/internal/dao/internal/users.go b/internal/dao/internal/users.go index c5aa79d..340eaf7 100644 --- a/internal/dao/internal/users.go +++ b/internal/dao/internal/users.go @@ -13,9 +13,10 @@ 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. + 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. } // 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. -func NewUsersDao() *UsersDao { +func NewUsersDao(handlers ...gdb.ModelHandler) *UsersDao { return &UsersDao{ - group: "default", - table: "users", - columns: usersColumns, + group: "default", + table: "users", + 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. 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. diff --git a/internal/logic/reward/reward.go b/internal/logic/reward/reward.go index 4b56d50..3012b27 100644 --- a/internal/logic/reward/reward.go +++ b/internal/logic/reward/reward.go @@ -412,7 +412,7 @@ func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *mode // 根据 result判断 if item.Result == 1 { // 奖励发放成功,修改状态,扣除数量 - + dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{ExternalOrderId: item.Water.OrderId}).Update(consts.RewardSuccessStatus) } else if item.Result == 2 || item.Result == 3 { // 发放背包成功,修改状态 } else if item.Result == 4 { diff --git a/internal/logic/user/user.go b/internal/logic/user/user.go index 3a487b6..31c8118 100644 --- a/internal/logic/user/user.go +++ b/internal/logic/user/user.go @@ -92,7 +92,7 @@ func (s *sUser) Login(ctx context.Context, in *model.UserLoginIn) (out *model.Us Username: username, Nickname: username, PasswordHash: password, - Avatar: "adssssssssssssss", // FIXME 后续替换成默认头像的 oss 链接 + Avatar: consts.DefaultUserAvatar, FirstVisitAt: gtime.Now(), LastLoginAt: gtime.Now(), WxPopenId: utility.GenerateUserID("WX"), diff --git a/internal/model/do/reward_waters.go b/internal/model/do/reward_waters.go index 098a39d..82b9055 100644 --- a/internal/model/do/reward_waters.go +++ b/internal/model/do/reward_waters.go @@ -21,5 +21,4 @@ type RewardWaters struct { CreatedAt *gtime.Time // UpdatedAt *gtime.Time // DeletedAt *gtime.Time // - GameId interface{} // 游戏唯一 id } diff --git a/internal/model/do/user_task_rewards.go b/internal/model/do/user_task_rewards.go index 1b966b9..20bf094 100644 --- a/internal/model/do/user_task_rewards.go +++ b/internal/model/do/user_task_rewards.go @@ -16,9 +16,10 @@ type UserTaskRewards struct { UserTaskId interface{} // 关联用户任务记录ID RewardId interface{} // 奖励ID RewardName interface{} // 奖励名称冗余字段 - Status interface{} // 状态:1=待完成,2=待领取,3=已领取,4=待兑换,5=已完成,6=已过期,7=发放失败 + Status interface{} // 状态:1=待用户完成任务,2=待领取,3=已领取, 待兑换,4=已过期,5=发放失败, 6=结束 Remark interface{} // 备注或失败原因 ExternalOrderId interface{} // 第三方发放平台的订单ID + InnerOrderId interface{} // 系统内部订单ID CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 DeletedAt *gtime.Time // 软删除时间 diff --git a/internal/model/entity/reward_waters.go b/internal/model/entity/reward_waters.go index f7142ba..9673b4b 100644 --- a/internal/model/entity/reward_waters.go +++ b/internal/model/entity/reward_waters.go @@ -19,5 +19,4 @@ type RewardWaters 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:""` // - GameId int64 `json:"gameId" orm:"game_id" description:"游戏唯一 id"` // 游戏唯一 id } diff --git a/internal/model/entity/user_task_rewards.go b/internal/model/entity/user_task_rewards.go index d24bf50..df801ff 100644 --- a/internal/model/entity/user_task_rewards.go +++ b/internal/model/entity/user_task_rewards.go @@ -10,14 +10,15 @@ import ( // UserTaskRewards is the golang structure for table user_task_rewards. type UserTaskRewards struct { - Id int64 `json:"id" orm:"id" description:"用户任务奖励记录唯一标识符"` // 用户任务奖励记录唯一标识符 - UserTaskId int64 `json:"userTaskId" orm:"user_task_id" description:"关联用户任务记录ID"` // 关联用户任务记录ID - RewardId int64 `json:"rewardId" orm:"reward_id" description:"奖励ID"` // 奖励ID - RewardName string `json:"rewardName" orm:"reward_name" description:"奖励名称冗余字段"` // 奖励名称冗余字段 - Status int `json:"status" orm:"status" description:"状态:1=待完成,2=待领取,3=已领取,4=待兑换,5=已完成,6=已过期,7=发放失败"` // 状态:1=待完成,2=待领取,3=已领取,4=待兑换,5=已完成,6=已过期,7=发放失败 - Remark string `json:"remark" orm:"remark" description:"备注或失败原因"` // 备注或失败原因 - ExternalOrderId string `json:"externalOrderId" orm:"external_order_id" description:"第三方发放平台的订单ID"` // 第三方发放平台的订单ID - 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:"用户任务奖励记录唯一标识符"` // 用户任务奖励记录唯一标识符 + UserTaskId int64 `json:"userTaskId" orm:"user_task_id" description:"关联用户任务记录ID"` // 关联用户任务记录ID + RewardId int64 `json:"rewardId" orm:"reward_id" description:"奖励ID"` // 奖励ID + RewardName string `json:"rewardName" orm:"reward_name" description:"奖励名称冗余字段"` // 奖励名称冗余字段 + Status int `json:"status" orm:"status" description:"状态:1=待用户完成任务,2=待领取,3=已领取, 待兑换,4=已过期,5=发放失败, 6=结束"` // 状态:1=待用户完成任务,2=待领取,3=已领取, 待兑换,4=已过期,5=发放失败, 6=结束 + Remark string `json:"remark" orm:"remark" description:"备注或失败原因"` // 备注或失败原因 + ExternalOrderId string `json:"externalOrderId" orm:"external_order_id" description:"第三方发放平台的订单ID"` // 第三方发放平台的订单ID + InnerOrderId string `json:"innerOrderId" orm:"inner_order_id" description:"系统内部订单ID"` // 系统内部订单ID + 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:"软删除时间"` // 软删除时间 }