新增游戏绑定方式,修改任务排行

This commit is contained in:
chy
2025-06-18 16:39:53 +08:00
parent e6a53f4837
commit 217b550d0f
16 changed files with 92 additions and 68 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -29,6 +29,7 @@ type GamesColumns struct {
CreatedAt string // 创建时间
UpdatedAt string // 更新时间
DeletedAt string // 删除时间
BoundType string // 1qq绑定 2wx绑定 3all
}
// 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.

View File

@ -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.

View File

@ -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",

View File

@ -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("修改游戏失败")

View File

@ -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
}

View File

@ -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)

View File

@ -20,4 +20,5 @@ type Games struct {
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 删除时间
BoundType interface{} // 1qq绑定 2wx绑定 3all
}

View File

@ -23,4 +23,6 @@ type Rewards struct {
CreatedAt *gtime.Time // 创建时间
UpdatedAt *gtime.Time // 更新时间
DeletedAt *gtime.Time // 软删除时间戳
TotalNum interface{} // 奖励总数量NULL表示不限量
UsedNum interface{} // 已使用数量
}

View File

@ -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 // 软删除时间戳

View File

@ -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:"1qq绑定 2wx绑定 3all"` // 1qq绑定 2wx绑定 3all
}

View File

@ -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:"已使用数量"` // 已使用数量
}

View File

@ -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:"软删除时间"` // 软删除时间
}

View File

@ -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"` // 绑定类型 1qq 2wx 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 更新游戏出参