From e6a53f4837ecbb98614f9aa0fb2327c9c774df67 Mon Sep 17 00:00:00 2001 From: chy <2463300564@qq.com> Date: Tue, 17 Jun 2025 19:49:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=97=E8=A1=A8=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20qq=E7=BD=91=E5=90=A7=E5=A5=96=E5=8A=B1=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=EF=BC=8C=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/dao/internal/reward_types.go | 22 +++++++++++++-------- internal/dao/internal/rewards.go | 22 +++++++++++++-------- internal/dao/internal/store_task_rewards.go | 22 +++++++++++++-------- internal/dao/internal/tasks.go | 4 ++++ internal/dao/internal/user_tasks.go | 22 +++++++++++++-------- internal/logic/task/task.go | 15 ++++++++++---- internal/model/do/tasks.go | 2 ++ internal/model/entity/tasks.go | 22 +++++++++++---------- internal/model/task.go | 7 +++++++ 9 files changed, 92 insertions(+), 46 deletions(-) diff --git a/internal/dao/internal/reward_types.go b/internal/dao/internal/reward_types.go index 9d2a944..30b7375 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. @@ -45,11 +46,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, } } @@ -75,7 +77,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/rewards.go b/internal/dao/internal/rewards.go index 797b726..823158b 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. @@ -49,11 +50,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, } } @@ -79,7 +81,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/store_task_rewards.go b/internal/dao/internal/store_task_rewards.go index ea8fe2a..8669463 100644 --- a/internal/dao/internal/store_task_rewards.go +++ b/internal/dao/internal/store_task_rewards.go @@ -13,9 +13,10 @@ import ( // StoreTaskRewardsDao is the data access object for the table store_task_rewards. type StoreTaskRewardsDao 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 StoreTaskRewardsColumns // 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 StoreTaskRewardsColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } // StoreTaskRewardsColumns defines and stores column names for the table store_task_rewards. @@ -45,11 +46,12 @@ var storeTaskRewardsColumns = StoreTaskRewardsColumns{ } // NewStoreTaskRewardsDao creates and returns a new DAO object for table data access. -func NewStoreTaskRewardsDao() *StoreTaskRewardsDao { +func NewStoreTaskRewardsDao(handlers ...gdb.ModelHandler) *StoreTaskRewardsDao { return &StoreTaskRewardsDao{ - group: "default", - table: "store_task_rewards", - columns: storeTaskRewardsColumns, + group: "default", + table: "store_task_rewards", + columns: storeTaskRewardsColumns, + handlers: handlers, } } @@ -75,7 +77,11 @@ func (dao *StoreTaskRewardsDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *StoreTaskRewardsDao) 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 7434913..b7c9b15 100644 --- a/internal/dao/internal/tasks.go +++ b/internal/dao/internal/tasks.go @@ -31,6 +31,8 @@ type TasksColumns struct { QqNetbarTaskRules string // 任务规则 GameId string // 游戏唯一id StoreId string // 门店 id + QqNetbarReward string // + Status string // 1:启用 2:禁用 } // tasksColumns holds the columns for the table tasks. @@ -45,6 +47,8 @@ var tasksColumns = TasksColumns{ QqNetbarTaskRules: "qq_netbar_task_rules", GameId: "game_id", StoreId: "store_id", + QqNetbarReward: "qq_netbar_reward", + Status: "status", } // NewTasksDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/user_tasks.go b/internal/dao/internal/user_tasks.go index 095425b..73bf579 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. @@ -47,11 +48,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, } } @@ -77,7 +79,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/logic/task/task.go b/internal/logic/task/task.go index 73da102..4ba2725 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -140,7 +140,6 @@ func (s *sTask) UserTaskRankingList(ctx context.Context, in *model.UserTaskRanki // GetNonLoginTaskList 获取下发到指定网吧的任务列表(未登录) func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetNonLoginTaskListIn) (out *model.GetNonLoginTaskListOut, err error) { - // TODO 调用外部接口 // 调用外部接口 data, err := tencent.GetNonLoginTaskList(ctx, in) if err != nil { @@ -157,7 +156,7 @@ func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetNonLoginTa return nil, ecode.Fail.Sub("当前网吧不存在") } - // TODO 任务列表数据处理 + // 任务列表数据处理 if jsonData, ok := data.(map[string]interface{}); ok { // 现在可以访问 jsonData 中的字段 list := jsonData["task_list"] @@ -179,6 +178,14 @@ func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetNonLoginTa return nil, ecode.Fail.Sub("查询该任务失败") } + str := "" + for i, vv := range v.PrizeList { + str += vv.PrizeName + if i+1 != len(v.PrizeList) { + str += "," + } + } + // 数据库是否存在,无则添加 if !exist { _, err := dao.Tasks.Ctx(ctx).Insert(do.Tasks{ @@ -188,6 +195,7 @@ func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetNonLoginTa QqNetbarTaskRules: v.QQNetBarTaskRules, GameId: in.Gid, StoreId: store.Id, + QqNetbarReward: str, }) if err != nil { return nil, ecode.Fail.Sub("添加任务失败") @@ -203,14 +211,13 @@ func (s *sTask) GetNonLoginTaskList(ctx context.Context, in *model.GetNonLoginTa func (s *sTask) GetLoginTaskList(ctx context.Context, in *model.GetLoginTaskListIn) (out *model.GetLoginTaskListOut, err error) { - // TODO 调用外部接口 // 调用外部接口 data, err := tencent.GetLoginTaskList(ctx, in) if err != nil { return nil, err } - // TODO 任务列表数据处理 + // 任务列表数据处理 return &model.GetLoginTaskListOut{ Data: data, }, err diff --git a/internal/model/do/tasks.go b/internal/model/do/tasks.go index 2152f8f..e7d167f 100644 --- a/internal/model/do/tasks.go +++ b/internal/model/do/tasks.go @@ -22,4 +22,6 @@ type Tasks struct { QqNetbarTaskRules interface{} // 任务规则 GameId interface{} // 游戏唯一id StoreId interface{} // 门店 id + QqNetbarReward interface{} // + Status interface{} // 1:启用 2:禁用 } diff --git a/internal/model/entity/tasks.go b/internal/model/entity/tasks.go index 1ee418a..da8d71d 100644 --- a/internal/model/entity/tasks.go +++ b/internal/model/entity/tasks.go @@ -10,14 +10,16 @@ import ( // Tasks is the golang structure for table tasks. type Tasks struct { - Id int64 `json:"id" orm:"id" description:"任务唯一标识符"` // 任务唯一标识符 - QqNetbarTaskId string `json:"qqNetbarTaskId" orm:"qq_netbar_task_id" description:"QQ网吧任务ID"` // QQ网吧任务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:"软删除时间戳"` // 软删除时间戳 - QqNetbarTaskName string `json:"qqNetbarTaskName" orm:"qq_netbar_task_name" description:"QQ网吧任务名称"` // QQ网吧任务名称 - QqNetbarTaskMemo string `json:"qqNetbarTaskMemo" orm:"qq_netbar_task_memo" description:"任务描述"` // 任务描述 - QqNetbarTaskRules string `json:"qqNetbarTaskRules" orm:"qq_netbar_task_rules" description:"任务规则"` // 任务规则 - GameId int64 `json:"gameId" orm:"game_id" description:"游戏唯一id"` // 游戏唯一id - StoreId int64 `json:"storeId" orm:"store_id" description:"门店 id"` // 门店 id + Id int64 `json:"id" orm:"id" description:"任务唯一标识符"` // 任务唯一标识符 + QqNetbarTaskId string `json:"qqNetbarTaskId" orm:"qq_netbar_task_id" description:"QQ网吧任务ID"` // QQ网吧任务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:"软删除时间戳"` // 软删除时间戳 + QqNetbarTaskName string `json:"qqNetbarTaskName" orm:"qq_netbar_task_name" description:"QQ网吧任务名称"` // QQ网吧任务名称 + QqNetbarTaskMemo string `json:"qqNetbarTaskMemo" orm:"qq_netbar_task_memo" description:"任务描述"` // 任务描述 + QqNetbarTaskRules string `json:"qqNetbarTaskRules" orm:"qq_netbar_task_rules" description:"任务规则"` // 任务规则 + GameId int64 `json:"gameId" orm:"game_id" description:"游戏唯一id"` // 游戏唯一id + StoreId int64 `json:"storeId" orm:"store_id" description:"门店 id"` // 门店 id + QqNetbarReward string `json:"qqNetbarReward" orm:"qq_netbar_reward" description:""` // + Status int `json:"status" orm:"status" description:"1:启用 2:禁用"` // 1:启用 2:禁用 } diff --git a/internal/model/task.go b/internal/model/task.go index 6e869fb..a447a19 100644 --- a/internal/model/task.go +++ b/internal/model/task.go @@ -16,6 +16,8 @@ type Tasks struct { QqNetbarTaskRules string `json:"qqNetbarTaskRules" orm:"qq_netbar_task_rules" description:"任务规则"` // 任务规则 GameId int64 `json:"gameId" orm:"game_id" description:"游戏唯一id"` // 游戏唯一id StoreId int64 `json:"storeId" orm:"store_id" description:"门店 id"` // 门店 id + Status int `json:"status" orm:"status" description:"状态"` // 状态 + QQNetBarReward string `json:"qqNetbarReward" orm:"qq_netbar_reward" description:"qq网吧奖励名称"` // 任务奖励 } type GetNonLoginTaskListIn struct { @@ -64,6 +66,11 @@ type MyData struct { QQNetBarTaskName string `json:"title"` QQNetBarTaskRules string `json:"rule_desc"` //StoreId int `json:"store_id"` + PrizeList []PrizeList `json:"prize_list"` +} + +type PrizeList struct { + PrizeName string `json:"prize_name"` } type TaskListIn struct {