diff --git a/api/game/v1/game.go b/api/game/v1/game.go index 28a4d9a..fb89b1d 100644 --- a/api/game/v1/game.go +++ b/api/game/v1/game.go @@ -16,11 +16,12 @@ type ListRes struct { } type CreateReq struct { - g.Meta `path:"/game" method:"post" tags:"Game" summary:"(系统)创建游戏"` - GameID int64 `json:"gameId" v:"required#游戏ID不能为空" dc:"游戏ID"` - GameName string `json:"gameName" v:"required#游戏名称不能为空" dc:"游戏名称"` - GameCode string `json:"gameCode" v:"required#游戏代号不能为空" dc:"游戏代号"` - Avatar string `json:"avatar" dc:"游戏图标"` + g.Meta `path:"/game" method:"post" tags:"Game" summary:"(系统)创建游戏"` + GameID int64 `json:"gameId" v:"required#游戏ID不能为空" dc:"游戏ID"` + GameName string `json:"gameName" v:"required#游戏名称不能为空" dc:"游戏名称"` + GameCode string `json:"gameCode" v:"required#游戏代号不能为空" dc:"游戏代号"` + Avatar string `json:"avatar" dc:"游戏图标"` + BoundType int64 `json:"boundType" v:"required#绑定类型不能为空" dc:"绑定类型"` } type CreateRes struct { @@ -28,12 +29,13 @@ type CreateRes struct { } type UpdateReq struct { - g.Meta `path:"/game" method:"put" tags:"Game" summary:"(系统)更新游戏"` - GameID int64 `json:"gameId" v:"required#游戏ID不能为空" dc:"游戏ID"` - GameName string `json:"gameName" v:"required#游戏名称不能为空" dc:"游戏名称"` - GameCode string `json:"gameCode" v:"required#游戏代号不能为空" dc:"游戏代号"` - Avatar string `json:"avatar" dc:"游戏图标"` - Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"` + g.Meta `path:"/game" method:"put" tags:"Game" summary:"(系统)更新游戏"` + GameID int64 `json:"gameId" v:"required#游戏ID不能为空" dc:"游戏ID"` + GameName string `json:"gameName" v:"required#游戏名称不能为空" dc:"游戏名称"` + GameCode string `json:"gameCode" v:"required#游戏代号不能为空" dc:"游戏代号"` + Avatar string `json:"avatar" dc:"游戏图标"` + Id int64 `json:"id" v:"required#ID不能为空" dc:"ID"` + BoundType int64 `json:"boundType" v:"required#绑定类型不能为空" dc:"绑定类型"` } type UpdateRes struct { diff --git a/internal/controller/game/game_v1_create.go b/internal/controller/game/game_v1_create.go index b7d2eb8..873b999 100644 --- a/internal/controller/game/game_v1_create.go +++ b/internal/controller/game/game_v1_create.go @@ -11,10 +11,11 @@ import ( func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.CreateRes, err error) { out, err := service.Game().CreateGame(ctx, &model.AddGameIn{ - Avatar: req.Avatar, - GameCode: req.GameCode, - GameId: req.GameID, - GameName: req.GameName, + Avatar: req.Avatar, + GameCode: req.GameCode, + GameId: req.GameID, + GameName: req.GameName, + BoundType: req.BoundType, }) if err != nil { diff --git a/internal/controller/reward/reward_v1_list.go b/internal/controller/reward/reward_v1_list.go index 142cf11..974cd93 100644 --- a/internal/controller/reward/reward_v1_list.go +++ b/internal/controller/reward/reward_v1_list.go @@ -13,7 +13,14 @@ func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListR fromCtx := g.RequestFromCtx(ctx) operatorId := fromCtx.GetCtxVar("id").Int64() operatorRole := fromCtx.GetCtxVar("role").String() - out, err := service.Reward().List(ctx, &model.RewardListIn{Page: req.Page, Size: req.Size, OperatorId: operatorId, OperatorRole: operatorRole, StoreId: req.StoreId}) + out, err := service.Reward().List(ctx, &model.RewardListIn{Page: req.Page, + Size: req.Size, + OperatorId: operatorId, + OperatorRole: operatorRole, + StoreId: req.StoreId, + Name: req.Name, + Status: req.Status, + }) if err != nil { return nil, err } diff --git a/internal/dao/internal/games.go b/internal/dao/internal/games.go index 34d43cd..dac75c7 100644 --- a/internal/dao/internal/games.go +++ b/internal/dao/internal/games.go @@ -29,6 +29,7 @@ type GamesColumns struct { CreatedAt string // 创建时间 UpdatedAt string // 更新时间 DeletedAt string // 删除时间 + BoundType string // 1:qq绑定 2:wx绑定 3:all } // gamesColumns holds the columns for the table games. @@ -41,6 +42,7 @@ var gamesColumns = GamesColumns{ CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", + BoundType: "bound_type", } // NewGamesDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/rewards.go b/internal/dao/internal/rewards.go index 823158b..89452c7 100644 --- a/internal/dao/internal/rewards.go +++ b/internal/dao/internal/rewards.go @@ -32,6 +32,8 @@ type RewardsColumns struct { CreatedAt string // 创建时间 UpdatedAt string // 更新时间 DeletedAt string // 软删除时间戳 + TotalNum string // 奖励总数量,NULL表示不限量 + UsedNum string // 已使用数量 } // rewardsColumns holds the columns for the table rewards. @@ -47,6 +49,8 @@ var rewardsColumns = RewardsColumns{ CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", + TotalNum: "total_num", + UsedNum: "used_num", } // NewRewardsDao creates and returns a new DAO object for table data access. diff --git a/internal/dao/internal/store_task_rewards.go b/internal/dao/internal/store_task_rewards.go index 8669463..8db17ae 100644 --- a/internal/dao/internal/store_task_rewards.go +++ b/internal/dao/internal/store_task_rewards.go @@ -25,8 +25,6 @@ type StoreTaskRewardsColumns struct { TaskId string // 门店任务ID RewardId string // 奖励ID StoreId string // 门店ID - Quantity string // 奖励数量(如发放多少个奖励) - Status string // 状态:1=正常,0=禁用 CreatedAt string // 创建时间 UpdatedAt string // 更新时间 DeletedAt string // 软删除时间戳 @@ -38,8 +36,6 @@ var storeTaskRewardsColumns = StoreTaskRewardsColumns{ TaskId: "task_id", RewardId: "reward_id", StoreId: "store_id", - Quantity: "quantity", - Status: "status", CreatedAt: "created_at", UpdatedAt: "updated_at", DeletedAt: "deleted_at", diff --git a/internal/logic/game/game.go b/internal/logic/game/game.go index 764b47c..62e8142 100644 --- a/internal/logic/game/game.go +++ b/internal/logic/game/game.go @@ -65,10 +65,11 @@ func (s *sGame) CreateGame(ctx context.Context, in *model.AddGameIn) (out *model } _, err = dao.Games.Ctx(ctx).Insert(do.Games{ - GameId: in.GameId, - GameName: in.GameName, - GameCode: in.GameCode, - Avatar: in.Avatar, + GameId: in.GameId, + GameName: in.GameName, + GameCode: in.GameCode, + Avatar: in.Avatar, + BoundType: in.BoundType, }) if err != nil { @@ -118,10 +119,11 @@ func (s *sGame) UpdateGame(ctx context.Context, in *model.UpdateGameIn) (out *mo } _, err = dao.Games.Ctx(ctx).Where(do.Games{Id: in.Id}).Update(do.Games{ - GameId: in.GameId, - GameName: in.GameName, - GameCode: in.GameCode, - Avatar: in.Avatar, + GameId: in.GameId, + GameName: in.GameName, + GameCode: in.GameCode, + Avatar: in.Avatar, + BoundType: in.BoundType, }) if err != nil { return nil, ecode.Fail.Sub("修改游戏失败") diff --git a/internal/logic/reward/reward.go b/internal/logic/reward/reward.go index 7d605b6..e3db410 100644 --- a/internal/logic/reward/reward.go +++ b/internal/logic/reward/reward.go @@ -80,7 +80,7 @@ func (s *sReward) Create(ctx context.Context, in *model.RewardCreateIn) (out *mo StoreId: in.StoreId, Value: in.Value, Status: in.Status, - }).InsertAndGetId() + }).OmitEmptyData().InsertAndGetId() if err != nil { return nil, err } @@ -88,7 +88,6 @@ func (s *sReward) Create(ctx context.Context, in *model.RewardCreateIn) (out *mo return &model.RewardCreateOut{Id: id}, nil } -// Update 更新奖励 // Update 更新奖励 func (s *sReward) Update(ctx context.Context, in *model.RewardUpdateIn) (out *model.RewardUpdateOut, err error) { // 查询原始记录,确保存在,并获取 source 与 store_id 用于权限校验 @@ -306,7 +305,7 @@ func (s *sReward) List(ctx context.Context, in *model.RewardListIn) (out *model. dao.Rewards.Table(), dao.Rewards.Columns().RewardTypeId, dao.RewardTypes.Table(), dao.RewardTypes.Columns().Id, ), - ).Fields(fmt.Sprintf("%s.*, %s.%s %s", dao.Rewards.Table(), dao.RewardTypes.Table(), dao.RewardTypes.Columns().Name, "reward_type_name")).Scan(&list) + ).Fields(fmt.Sprintf("%s.*, %s.%s %s", dao.Rewards.Table(), dao.RewardTypes.Table(), dao.RewardTypes.Columns().Name, "reward_type_name")).OrderDesc(dao.Rewards.Columns().CreatedAt).Scan(&list) if err != nil { return nil, err } diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go index 4ba2725..60a7338 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -86,7 +86,7 @@ func (s *sTask) UserTaskRankingList(ctx context.Context, in *model.UserTaskRanki var total int // SELECT `uid`,`nickname` FROM `user` ORDER BY `uid` asc err = m.Page(in.Page, in.Size).LeftJoin(dao.Users.Table(), fmt.Sprintf("`%s`.`id` = `%s`.`user_id`", dao.Users.Table(), dao.UserTasks.Table())). - Fields("username,avatar,count(*) num").Where(dao.UserTasks.Columns().Status, 3). + Fields("username,avatar,count(*) num").Where(dao.UserTasks.Columns().Status, 2). WhereBetween(dao.UserTasks.Columns().CompletedAt, start, end).OrderDesc("num").OrderDesc("username").Group("user_id"). ScanAndCount(&list, &total, false) if err != nil { @@ -98,16 +98,22 @@ func (s *sTask) UserTaskRankingList(ctx context.Context, in *model.UserTaskRanki var loginUserRanking []model.LoginUserRanking var loginUserRankingNum model.LoginUserRankingNum if in.OperatorId != 0 { - err := dao.UserTasks.Ctx(ctx).Fields("count(*) num").Where(dao.UserTasks.Columns().UserId, in.OperatorId).Where(dao.UserTasks.Columns().Status, 3). + value, err := dao.UserTasks.Ctx(ctx).Fields("count(*) num").Where(dao.UserTasks.Columns().UserId, in.OperatorId).Where(dao.UserTasks.Columns().Status, 2). WhereBetween(dao.UserTasks.Columns().CompletedAt, start, end).Group("user_id"). - Scan(&loginUserRankingNum) + Value() if err != nil { return nil, ecode.Fail.Sub("查询当前登录用户完成数失败") } + if value.IsEmpty() { + loginUserRankingNum.Num = 0 + } else { + loginUserRankingNum.Num = value.Int() + } + err = dao.UserTasks.Ctx(ctx).LeftJoin(dao.Users.Table(), fmt.Sprintf("`%s`.`id` = `%s`.`user_id`", dao.Users.Table(), dao.UserTasks.Table())). - Fields("username,count(*) num").Where(dao.UserTasks.Columns().Status, 3). + Fields("username,count(*) num").Where(dao.UserTasks.Columns().Status, 2). WhereBetween(dao.UserTasks.Columns().CompletedAt, start, end).OrderDesc("num").OrderDesc("username").Group("user_id"). Scan(&loginUserRanking) diff --git a/internal/model/do/games.go b/internal/model/do/games.go index 2eba46d..3199fff 100644 --- a/internal/model/do/games.go +++ b/internal/model/do/games.go @@ -20,4 +20,5 @@ type Games struct { CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 DeletedAt *gtime.Time // 删除时间 + BoundType interface{} // 1:qq绑定 2:wx绑定 3:all } diff --git a/internal/model/do/rewards.go b/internal/model/do/rewards.go index 2c1ac2c..2c4d2c8 100644 --- a/internal/model/do/rewards.go +++ b/internal/model/do/rewards.go @@ -23,4 +23,6 @@ type Rewards struct { CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 DeletedAt *gtime.Time // 软删除时间戳 + TotalNum interface{} // 奖励总数量,NULL表示不限量 + UsedNum interface{} // 已使用数量 } diff --git a/internal/model/do/store_task_rewards.go b/internal/model/do/store_task_rewards.go index c871bab..2523941 100644 --- a/internal/model/do/store_task_rewards.go +++ b/internal/model/do/store_task_rewards.go @@ -16,8 +16,6 @@ type StoreTaskRewards struct { TaskId interface{} // 门店任务ID RewardId interface{} // 奖励ID StoreId interface{} // 门店ID - Quantity interface{} // 奖励数量(如发放多少个奖励) - Status interface{} // 状态:1=正常,0=禁用 CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 DeletedAt *gtime.Time // 软删除时间戳 diff --git a/internal/model/entity/games.go b/internal/model/entity/games.go index 76557cd..6b6665f 100644 --- a/internal/model/entity/games.go +++ b/internal/model/entity/games.go @@ -10,12 +10,13 @@ import ( // Games is the golang structure for table games. type Games struct { - Id int64 `json:"id" orm:"id" description:""` // - GameId int64 `json:"gameId" orm:"game_id" description:"腾讯游戏 id"` // 腾讯游戏 id - GameName string `json:"gameName" orm:"game_name" description:"游戏名称"` // 游戏名称 - GameCode string `json:"gameCode" orm:"game_code" description:"游戏代号"` // 游戏代号 - Avatar string `json:"avatar" orm:"avatar" 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:""` // + GameId int64 `json:"gameId" orm:"game_id" description:"腾讯游戏 id"` // 腾讯游戏 id + GameName string `json:"gameName" orm:"game_name" description:"游戏名称"` // 游戏名称 + GameCode string `json:"gameCode" orm:"game_code" description:"游戏代号"` // 游戏代号 + Avatar string `json:"avatar" orm:"avatar" 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:"删除时间"` // 删除时间 + BoundType int `json:"boundType" orm:"bound_type" description:"1:qq绑定 2:wx绑定 3:all"` // 1:qq绑定 2:wx绑定 3:all } diff --git a/internal/model/entity/rewards.go b/internal/model/entity/rewards.go index fb52c8a..e68c936 100644 --- a/internal/model/entity/rewards.go +++ b/internal/model/entity/rewards.go @@ -21,4 +21,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:"软删除时间戳"` // 软删除时间戳 + TotalNum uint64 `json:"totalNum" orm:"total_num" description:"奖励总数量,NULL表示不限量"` // 奖励总数量,NULL表示不限量 + UsedNum uint64 `json:"usedNum" orm:"used_num" description:"已使用数量"` // 已使用数量 } diff --git a/internal/model/entity/store_task_rewards.go b/internal/model/entity/store_task_rewards.go index 3eb2333..355b5c9 100644 --- a/internal/model/entity/store_task_rewards.go +++ b/internal/model/entity/store_task_rewards.go @@ -10,13 +10,11 @@ import ( // StoreTaskRewards is the golang structure for table store_task_rewards. type StoreTaskRewards struct { - Id int64 `json:"id" orm:"id" description:"任务奖励关联ID"` // 任务奖励关联ID - TaskId int64 `json:"taskId" orm:"task_id" description:"门店任务ID"` // 门店任务ID - RewardId int64 `json:"rewardId" orm:"reward_id" description:"奖励ID"` // 奖励ID - StoreId int64 `json:"storeId" orm:"store_id" description:"门店ID"` // 门店ID - Quantity int `json:"quantity" orm:"quantity" description:"奖励数量(如发放多少个奖励)"` // 奖励数量(如发放多少个奖励) - Status int `json:"status" orm:"status" description:"状态:1=正常,0=禁用"` // 状态:1=正常,0=禁用 - 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 + TaskId int64 `json:"taskId" orm:"task_id" description:"门店任务ID"` // 门店任务ID + RewardId int64 `json:"rewardId" orm:"reward_id" description:"奖励ID"` // 奖励ID + StoreId int64 `json:"storeId" orm:"store_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:"软删除时间戳"` // 软删除时间戳 } diff --git a/internal/model/game.go b/internal/model/game.go index 171d327..196dc54 100644 --- a/internal/model/game.go +++ b/internal/model/game.go @@ -1,11 +1,12 @@ package model type Game struct { - GameId int64 `json:"gameId" orm:"game_id"` // 腾讯游戏 id - GameName string `json:"gameName" orm:"game_name"` // 游戏名称 - GameCode string `json:"gameCode" orm:"game_code"` // 游戏代号 - Avatar string `json:"avatar" orm:"avatar"` // 图标 - Id int64 `json:"id" orm:"id"` + GameId int64 `json:"gameId" orm:"game_id"` // 腾讯游戏 id + GameName string `json:"gameName" orm:"game_name"` // 游戏名称 + GameCode string `json:"gameCode" orm:"game_code"` // 游戏代号 + Avatar string `json:"avatar" orm:"avatar"` // 图标 + Id int64 `json:"id" orm:"id"` + BoundType int64 `json:"boundType" orm:"bound_type"` // 绑定类型 1:qq 2:wx 3: all } // GameListIn 游戏列表入参 @@ -22,10 +23,11 @@ type GameListOut struct { // AddGameIn 新增游戏入参 type AddGameIn struct { - GameName string `json:"gameName"` - GameCode string `json:"gameCode"` - Avatar string `json:"avatar"` - GameId int64 `json:"gameId"` + GameName string `json:"gameName"` + GameCode string `json:"gameCode"` + Avatar string `json:"avatar"` + GameId int64 `json:"gameId"` + BoundType int64 `json:"boundType"` } // AddGameOut 新增游戏出参 @@ -35,11 +37,12 @@ type AddGameOut struct { // UpdateGameIn 更新游戏入参 type UpdateGameIn struct { - GameName string `json:"gameName"` - GameCode string `json:"gameCode"` - Avatar string `json:"avatar"` - GameId int64 `json:"gameId"` - Id int64 `json:"id"` + GameName string `json:"gameName"` + GameCode string `json:"gameCode"` + Avatar string `json:"avatar"` + GameId int64 `json:"gameId"` + Id int64 `json:"id"` + BoundType int64 `json:"boundType"` } // UpdateGameOut 更新游戏出参