From 81c2769b92007bab69c7b424c777a4576baf108b Mon Sep 17 00:00:00 2001 From: chy <2463300564@qq.com> Date: Tue, 10 Jun 2025 09:50:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=BD=93=E5=89=8D=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E7=94=A8=E6=88=B7=E6=8E=92=E5=90=8D=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +- api/game/v1/game.go | 48 +++++++ api/task/v1/task.go | 10 +- internal/cmd/cmd.go | 4 + internal/controller/game/game_v1_delete.go | 2 +- internal/controller/game/game_v1_list.go | 3 +- internal/controller/game/game_v1_update.go | 1 + internal/controller/task/task_v1_ranking.go | 11 +- internal/dao/internal/games.go | 6 +- internal/dao/internal/tasks.go | 22 +-- internal/dao/internal/user_tasks.go | 24 ++-- internal/logic/game/game.go | 149 ++++++++++++++++++++ internal/logic/logic.go | 2 + internal/logic/task/task.go | 129 +++++++++++++++++ internal/middleware/auth.go | 2 +- internal/model/do/games.go | 3 +- internal/model/do/user_tasks.go | 1 + internal/model/entity/games.go | 3 +- internal/model/entity/user_tasks.go | 1 + internal/model/game.go | 57 ++++++++ internal/model/userTask.go | 48 +++++++ utility/myCasbin/casbin.go | 8 ++ 22 files changed, 505 insertions(+), 33 deletions(-) create mode 100644 api/game/v1/game.go create mode 100644 internal/logic/game/game.go create mode 100644 internal/logic/task/task.go create mode 100644 internal/model/game.go create mode 100644 internal/model/userTask.go diff --git a/.gitignore b/.gitignore index 8762c90..09c2d04 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,6 @@ manifest/output/ temp/ temp.yaml bin -arenax \ No newline at end of file +arenax +*/*/config.yaml +*/config.yaml \ No newline at end of file diff --git a/api/game/v1/game.go b/api/game/v1/game.go new file mode 100644 index 0000000..64fc3ec --- /dev/null +++ b/api/game/v1/game.go @@ -0,0 +1,48 @@ +package v1 + +import "github.com/gogf/gf/v2/frame/g" + +type ListReq struct { + g.Meta `path:"/game" method:"get" tags:"Game" summary:"获取游戏列表"` + Page int `json:"page" dc:"页数"` + Size int `json:"size" dc:"每页数量"` +} + +type ListRes struct { + List interface{} `json:"list" dc:"游戏列表"` + Total int `json:"total" dc:"总数"` +} + +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:"游戏图标"` +} + +type CreateRes struct { + Success bool `json:"success" dc:"是否成功"` +} + +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"` +} + +type UpdateRes struct { + Success bool `json:"success" dc:"是否成功"` +} + +type DeleteReq struct { + g.Meta `path:"/game/{id}" method:"delete" tags:"Game" summary:"删除游戏"` + ID int64 `json:"Id" v:"required#ID不能为空" dc:"ID"` +} + +type DeleteRes struct { + Success bool `json:"success" dc:"是否成功"` +} diff --git a/api/task/v1/task.go b/api/task/v1/task.go index c40dd19..20f140e 100644 --- a/api/task/v1/task.go +++ b/api/task/v1/task.go @@ -2,17 +2,17 @@ package v1 import "github.com/gogf/gf/v2/frame/g" +type ListReq struct { +} type RankingReq struct { g.Meta `path:"/task/ranking" method:"get" tags:"Task" summary:"任务排行榜"` StoreId int `json:"storeId" v:"required#请选择店铺" dc:"门店id"` Page int `json:"page" dc:"页数"` Size int `json:"size" dc:"条数"` + Type int `json:"type" v:"required#请选择排行榜类型" dc:"排行榜类型"` } type RankingRes struct { -} - -type ListReq struct { -} -type ListRes struct { + List interface{} `json:"list"` + Total int `json:"total"` } diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 3cbbb82..66a91a9 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -8,10 +8,12 @@ import ( "server/internal/controller/admin" "server/internal/controller/auth" "server/internal/controller/feedback" + "server/internal/controller/game" "server/internal/controller/merchant" "server/internal/controller/reward" "server/internal/controller/rewardType" "server/internal/controller/role" + "server/internal/controller/task" "server/internal/controller/upload" "server/internal/controller/user" "server/internal/controller/wx" @@ -44,6 +46,8 @@ var ( feedback.NewV1(), user.NewV1(), reward.NewV1(), + task.NewV1(), + game.NewV1(), ) }) }) diff --git a/internal/controller/game/game_v1_delete.go b/internal/controller/game/game_v1_delete.go index 475f855..1406faa 100644 --- a/internal/controller/game/game_v1_delete.go +++ b/internal/controller/game/game_v1_delete.go @@ -10,7 +10,7 @@ import ( func (c *ControllerV1) Delete(ctx context.Context, req *v1.DeleteReq) (res *v1.DeleteRes, err error) { - out, err := service.Game().DeleteGame(ctx, &model.DeleteGameIn{GameId: req.GameID}) + out, err := service.Game().DeleteGame(ctx, &model.DeleteGameIn{Id: req.ID}) if err != nil { return nil, err } diff --git a/internal/controller/game/game_v1_list.go b/internal/controller/game/game_v1_list.go index 96926e5..4908633 100644 --- a/internal/controller/game/game_v1_list.go +++ b/internal/controller/game/game_v1_list.go @@ -9,7 +9,8 @@ import ( ) func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) { - out, err := service.Game().GameList(ctx, &model.GameListIn{}) + + out, err := service.Game().GameList(ctx, &model.GameListIn{req.Page, req.Size}) if err != nil { return nil, err } diff --git a/internal/controller/game/game_v1_update.go b/internal/controller/game/game_v1_update.go index bc96be6..f8b93d5 100644 --- a/internal/controller/game/game_v1_update.go +++ b/internal/controller/game/game_v1_update.go @@ -14,6 +14,7 @@ func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.U GameName: req.GameName, GameCode: req.GameCode, Avatar: req.Avatar, + Id: req.Id, }) if err != nil { return nil, err diff --git a/internal/controller/task/task_v1_ranking.go b/internal/controller/task/task_v1_ranking.go index 3522b48..f91661f 100644 --- a/internal/controller/task/task_v1_ranking.go +++ b/internal/controller/task/task_v1_ranking.go @@ -10,11 +10,14 @@ import ( func (c *ControllerV1) Ranking(ctx context.Context, req *v1.RankingReq) (res *v1.RankingRes, err error) { + //operatorId := g.RequestFromCtx(ctx).GetCtxVar("id").Int() + operatorId := 4 out, err := service.Task().UserTaskRankingList(ctx, &model.UserTaskRankingIn{ - Page: req.Page, - Size: req.Size, - StoreId: req.StoreId, - Type: req.Type, + Page: req.Page, + Size: req.Size, + StoreId: req.StoreId, + Type: req.Type, + OperatorId: operatorId, }) if err != nil { diff --git a/internal/dao/internal/games.go b/internal/dao/internal/games.go index 2d4ca9d..34d43cd 100644 --- a/internal/dao/internal/games.go +++ b/internal/dao/internal/games.go @@ -21,9 +21,10 @@ type GamesDao struct { // GamesColumns defines and stores column names for the table games. type GamesColumns struct { + Id string // GameId string // 腾讯游戏 id GameName string // 游戏名称 - GameaCode string // 游戏代号 + GameCode string // 游戏代号 Avatar string // 图标 CreatedAt string // 创建时间 UpdatedAt string // 更新时间 @@ -32,9 +33,10 @@ type GamesColumns struct { // gamesColumns holds the columns for the table games. var gamesColumns = GamesColumns{ + Id: "id", GameId: "game_id", GameName: "game_name", - GameaCode: "gamea_code", + GameCode: "game_code", Avatar: "avatar", CreatedAt: "created_at", UpdatedAt: "updated_at", diff --git a/internal/dao/internal/tasks.go b/internal/dao/internal/tasks.go index 414dc25..6541eb6 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. @@ -37,11 +38,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, } } @@ -67,7 +69,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_tasks.go b/internal/dao/internal/user_tasks.go index e62f00e..b4e59d1 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. @@ -29,6 +30,7 @@ type UserTasksColumns struct { UpdatedAt string // 更新时间 CompletedAt string // 任务完成时间 DeletedAt string // 软删除时间戳 + StoreId string // 门店 id } // userTasksColumns holds the columns for the table user_tasks. @@ -42,14 +44,16 @@ var userTasksColumns = UserTasksColumns{ UpdatedAt: "updated_at", CompletedAt: "completed_at", DeletedAt: "deleted_at", + StoreId: "store_id", } // 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, } } @@ -75,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/game/game.go b/internal/logic/game/game.go new file mode 100644 index 0000000..cbdd8f9 --- /dev/null +++ b/internal/logic/game/game.go @@ -0,0 +1,149 @@ +package game + +import ( + "context" + "server/internal/dao" + "server/internal/model" + "server/internal/model/do" + "server/internal/service" + "server/utility/ecode" +) + +type sGame struct { +} + +func New() service.IGame { + return &sGame{} +} + +func init() { + service.RegisterGame(New()) +} + +func (s *sGame) GameList(ctx context.Context, in *model.GameListIn) (out *model.GameListOut, err error) { + + list := make([]model.Game, 0) + var total int + err = dao.Games.Ctx(ctx).Page(in.Page, in.Size).ScanAndCount(&list, &total, false) + if err != nil { + return nil, ecode.Fail.Sub("游戏列表获取失败") + } + return &model.GameListOut{ + List: list, + Total: total, + }, nil +} + +func (s *sGame) CreateGame(ctx context.Context, in *model.AddGameIn) (out *model.AddGameOut, err error) { + + // 判断游戏是否存在 + exist, err := dao.Games.Ctx(ctx).Where(do.Games{GameId: in.GameId}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("新增游戏异常") + } + + if exist { + return nil, ecode.Params.Sub("游戏ID已存在") + } + + exist, err = dao.Games.Ctx(ctx).Where(do.Games{GameName: in.GameName}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("新增游戏异常") + } + + if exist { + return nil, ecode.Params.Sub("游戏名称已存在") + } + + exist, err = dao.Games.Ctx(ctx).Where(do.Games{GameCode: in.GameCode}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("新增游戏异常") + } + + if exist { + return nil, ecode.Params.Sub("游戏编码已存在") + } + + _, err = dao.Games.Ctx(ctx).Insert(do.Games{ + GameId: in.GameId, + GameName: in.GameName, + GameCode: in.GameCode, + Avatar: in.Avatar, + }) + + if err != nil { + return nil, ecode.Fail.Sub("新增游戏失败") + } + + return &model.AddGameOut{Success: true}, nil +} + +func (s *sGame) UpdateGame(ctx context.Context, in *model.UpdateGameIn) (out *model.UpdateGameOut, err error) { + + // 判断游戏是否存在 + exist, err := dao.Games.Ctx(ctx).Where(do.Games{Id: in.Id}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("修改游戏异常") + } + + if !exist { + return nil, ecode.Params.Sub("该游戏不存在") + } + + exist, err = dao.Games.Ctx(ctx).Where(do.Games{GameId: in.GameId}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("修改游戏异常") + } + + if exist { + return nil, ecode.Params.Sub("游戏ID已存在") + } + + exist, err = dao.Games.Ctx(ctx).Where(do.Games{GameName: in.GameName}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("修改游戏异常") + } + + if exist { + return nil, ecode.Params.Sub("游戏名称已存在") + } + + exist, err = dao.Games.Ctx(ctx).Where(do.Games{GameCode: in.GameCode}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("修改游戏异常") + } + + if exist { + return nil, ecode.Params.Sub("游戏编码已存在") + } + + _, 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, + }) + if err != nil { + return nil, ecode.Fail.Sub("修改游戏失败") + } + return &model.UpdateGameOut{Success: true}, nil +} + +func (s *sGame) DeleteGame(ctx context.Context, in *model.DeleteGameIn) (out *model.DeleteGameOut, err error) { + + // 判断是否存在 + exist, err := dao.Games.Ctx(ctx).Where(do.Games{Id: in.Id}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("删除该游戏异常") + } + + if !exist { + return nil, ecode.Params.Sub("游戏不存在") + } + + _, err = dao.Games.Ctx(ctx).Delete(do.Games{Id: in.Id}) + if err != nil { + return nil, ecode.Fail.Sub("删除游戏失败") + } + return &model.DeleteGameOut{Success: true}, nil +} diff --git a/internal/logic/logic.go b/internal/logic/logic.go index 7bcac31..ee63395 100644 --- a/internal/logic/logic.go +++ b/internal/logic/logic.go @@ -7,6 +7,7 @@ package logic import ( _ "server/internal/logic/admin" _ "server/internal/logic/feedback" + _ "server/internal/logic/game" _ "server/internal/logic/merchant" _ "server/internal/logic/merchantAdmin" _ "server/internal/logic/reward" @@ -14,6 +15,7 @@ import ( _ "server/internal/logic/role" _ "server/internal/logic/store" _ "server/internal/logic/storeAdmin" + _ "server/internal/logic/task" _ "server/internal/logic/upload" _ "server/internal/logic/user" ) diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go new file mode 100644 index 0000000..a8bfe8e --- /dev/null +++ b/internal/logic/task/task.go @@ -0,0 +1,129 @@ +package task + +import ( + "context" + "fmt" + "server/internal/dao" + "server/internal/model" + "server/internal/service" + "server/utility/ecode" + "sort" + "time" +) + +type sTask struct{} + +func New() service.ITask { + return &sTask{} +} + +func init() { + service.RegisterTask(New()) +} + +func (s *sTask) UserTaskRankingList(ctx context.Context, in *model.UserTaskRankingIn) (out *model.UserTaskRankingOut, err error) { + + // 判断排行类型 + var start, end time.Time + if in.Type == 1 { + // 日 + now := time.Now() + // 当天开始时间 + start = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) + // 当天结束时间 + end = time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 0, now.Location()) + + fmt.Println("开始时间:", start) + fmt.Println("结束时间:", end) + + } else if in.Type == 2 { + // 周 + now := time.Now() + loc := now.Location() + weekday := int(now.Weekday()) + if weekday == 0 { // 周日是0 + weekday = 7 + } + // 本周开始时间(周一 00:00:00) + start = time.Date(now.Year(), now.Month(), now.Day()-weekday+1, 0, 0, 0, 0, loc) + // 本周结束时间(周日 23:59:59) + end = time.Date(now.Year(), now.Month(), now.Day()-weekday+7, 23, 59, 59, 0, loc) + } else if in.Type == 3 { + // 月 + now := time.Now() + loc := now.Location() + // 本月开始时间(1号 00:00:00) + start = time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, loc) + // 下月1号 + nextMonth := start.AddDate(0, 1, 0) + // 本月结束时间(本月最后一天 23:59:59) + end = nextMonth.Add(-time.Second) + } else { + return nil, ecode.Params.Sub("排行方式错误") + } + m := dao.UserTasks.Ctx(ctx) + + // 构建查询条件 + if in.Page == 0 { + in.Page = 1 + } + + if in.Size == 0 { + in.Size = 10 + } + + if in.StoreId > 0 { + m = m.Where(dao.UserTasks.Columns().StoreId, in.StoreId) + } + + list := make([]model.UserTaskRankingArgs, 0) + 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). + WhereBetween(dao.UserTasks.Columns().CompletedAt, start, end).OrderDesc(dao.UserTasks.Columns().CompletedAt).Group("user_id"). + ScanAndCount(&list, &total, false) + if err != nil { + return nil, ecode.Fail.Sub("查询排行榜失败") + } + + // 判断登录查询当前任务完成数量,排名 + var completedDay, rankingDay int + var loginUserRanking []model.LoginUserRanking + 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). + WhereBetween(dao.UserTasks.Columns().CompletedAt, start, end).OrderDesc(dao.UserTasks.Columns().CompletedAt).Group("user_id"). + Scan(&completedDay) + + if err != nil { + return nil, ecode.Fail.Sub("查询当前登录用户完成数失败") + } + + err = dao.UserTasks.Ctx(ctx).Fields("user_id,count(*) num").Where(dao.UserTasks.Columns().Status, 3). + WhereBetween(dao.UserTasks.Columns().CompletedAt, start, end).OrderDesc(dao.UserTasks.Columns().CompletedAt).Group("user_id"). + Scan(&loginUserRanking) + + if err != nil { + return nil, ecode.Fail.Sub("查询当前登录用户排名失败") + } + + // 查找当前登录用户排名 + index := sort.Search(len(loginUserRanking), func(i int) bool { + return loginUserRanking[i].Num >= completedDay + }) + //for index, ranking := range loginUserRanking { + // if ranking.UserId == in.OperatorId { + // rankingDay = index + 1 + // break + // } + //} + rankingDay = index + 1 + } + + return &model.UserTaskRankingOut{ + List: list, + Total: total, + CompletedDay: completedDay, + RankingDay: rankingDay, + }, nil +} diff --git a/internal/middleware/auth.go b/internal/middleware/auth.go index 7c51cfd..7f1fe8a 100644 --- a/internal/middleware/auth.go +++ b/internal/middleware/auth.go @@ -31,7 +31,7 @@ func Auth(r *ghttp.Request) { ctx := r.GetCtx() if token == "" { glog.Infof(ctx, "未登录用户访问: %s %s", r.URL.Path, r.Method) - r.SetCtxVar("permission", "guest") + r.SetCtxVar("role", "guest") } else { if !strings.HasPrefix(token, "Bearer ") { Exit(r, ecode.InvalidOperation.Sub("无效的token格式")) diff --git a/internal/model/do/games.go b/internal/model/do/games.go index 5f5856b..2eba46d 100644 --- a/internal/model/do/games.go +++ b/internal/model/do/games.go @@ -12,9 +12,10 @@ import ( // Games is the golang structure of table games for DAO operations like Where/Data. type Games struct { g.Meta `orm:"table:games, do:true"` + Id interface{} // GameId interface{} // 腾讯游戏 id GameName interface{} // 游戏名称 - GameaCode interface{} // 游戏代号 + GameCode interface{} // 游戏代号 Avatar interface{} // 图标 CreatedAt *gtime.Time // 创建时间 UpdatedAt *gtime.Time // 更新时间 diff --git a/internal/model/do/user_tasks.go b/internal/model/do/user_tasks.go index c9b7eb0..3c9a229 100644 --- a/internal/model/do/user_tasks.go +++ b/internal/model/do/user_tasks.go @@ -21,4 +21,5 @@ type UserTasks struct { UpdatedAt *gtime.Time // 更新时间 CompletedAt *gtime.Time // 任务完成时间 DeletedAt *gtime.Time // 软删除时间戳 + StoreId interface{} // 门店 id } diff --git a/internal/model/entity/games.go b/internal/model/entity/games.go index aa927ac..76557cd 100644 --- a/internal/model/entity/games.go +++ b/internal/model/entity/games.go @@ -10,9 +10,10 @@ 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:"游戏名称"` // 游戏名称 - GameaCode string `json:"gameaCode" orm:"gamea_code" 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:"更新时间"` // 更新时间 diff --git a/internal/model/entity/user_tasks.go b/internal/model/entity/user_tasks.go index ebef287..8173ea6 100644 --- a/internal/model/entity/user_tasks.go +++ b/internal/model/entity/user_tasks.go @@ -19,4 +19,5 @@ type UserTasks struct { UpdatedAt *gtime.Time `json:"updatedAt" orm:"updated_at" description:"更新时间"` // 更新时间 CompletedAt *gtime.Time `json:"completedAt" orm:"completed_at" description:"任务完成时间"` // 任务完成时间 DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间戳"` // 软删除时间戳 + StoreId int64 `json:"storeId" orm:"store_id" description:"门店 id"` // 门店 id } diff --git a/internal/model/game.go b/internal/model/game.go new file mode 100644 index 0000000..97d0a2a --- /dev/null +++ b/internal/model/game.go @@ -0,0 +1,57 @@ +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"` // 图标 +} + +// GameListIn 游戏列表入参 +type GameListIn struct { + Page int `json:"page"` + Size int `json:"size"` +} + +// GameListOut 游戏列表出参 +type GameListOut struct { + List interface{} `json:"list" dc:"游戏列表"` + Total int `json:"total" dc:"总数"` +} + +// AddGameIn 新增游戏入参 +type AddGameIn struct { + GameName string `json:"gameName"` + GameCode string `json:"gameCode"` + Avatar string `json:"avatar"` + GameId int64 `json:"gameId"` +} + +// AddGameOut 新增游戏出参 +type AddGameOut struct { + Success bool `json:"success" dc:"是否成功"` +} + +// UpdateGameIn 更新游戏入参 +type UpdateGameIn struct { + GameName string `json:"gameName"` + GameCode string `json:"gameCode"` + Avatar string `json:"avatar"` + GameId int64 `json:"gameId"` + Id int64 `json:"id"` +} + +// UpdateGameOut 更新游戏出参 +type UpdateGameOut struct { + Success bool `json:"success" dc:"是否成功"` +} + +// DeleteGameIn 删除游戏入参 +type DeleteGameIn struct { + Id int64 `json:"Id"` +} + +// DeleteGameOut 删除游戏出参 +type DeleteGameOut struct { + Success bool `json:"success" dc:"是否成功"` +} diff --git a/internal/model/userTask.go b/internal/model/userTask.go new file mode 100644 index 0000000..be828a6 --- /dev/null +++ b/internal/model/userTask.go @@ -0,0 +1,48 @@ +package model + +import ( + "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/os/gtime" +) + +type UserTaskRanking struct { + g.Meta `orm:"table:task"` + Id int `orm:"column:id" json:"id"` // + UserId int `orm:"column:user_id" json:"userId"` // 用户 id + TaskId int `orm:"column:task_id" json:"taskId"` // 任务 id + Status int `orm:"column:status" json:"status"` // 状态 1:待完成 2:完成 + SerialNumber string `orm:"column:serial_number" json:"serialNumber"` // 流水号 + StoreId int `orm:"column:store_id" json:"storeId"` // 门店 id + CreatedAt *gtime.Time `orm:"column:created_at" json:"createdAt"` + UpdatedAt *gtime.Time `orm:"column:updated_at" json:"updatedAt"` + CompletedAT *gtime.Time `orm:"column:completed_at" json:"completedAt"` + DeletedAt *gtime.Time `orm:"column:deleted_at" json:"deletedAt"` +} + +// UserTaskRankingIn 任务排行榜入参 +type UserTaskRankingIn struct { + Page int + Size int + StoreId int + Type int // 排行榜类型 1:日 2:周 3:月 + OperatorId int +} + +// UserTaskRankingOut 用户排行榜出参 +type UserTaskRankingOut struct { + List []UserTaskRankingArgs + Total int + CompletedDay int + RankingDay int +} + +type UserTaskRankingArgs struct { + UserName string `orm:"username" json:"username"` + Avatar string `orm:"avatar" json:"avatar"` + Total int `orm:"num" json:"num"` +} + +type LoginUserRanking struct { + UserId int `orm:"user_id" json:"user_id"` + Num int `orm:"num" json:"num"` +} diff --git a/utility/myCasbin/casbin.go b/utility/myCasbin/casbin.go index baf21eb..1360227 100644 --- a/utility/myCasbin/casbin.go +++ b/utility/myCasbin/casbin.go @@ -41,6 +41,10 @@ func init() { // 游客 { // 任务 + enforcer.AddPolicy("guest", "/x/task/ranking", "GET", "获取排行榜") + + // 游戏列表 + enforcer.AddPolicy("guest", "/x/game", "GET", "获取游戏列表") } // 用户 { @@ -98,6 +102,10 @@ func init() { enforcer.AddPolicy("admin", "/x/reward/system", "GET", "管理员获取系统奖励列表") enforcer.AddPolicy("admin", "/x/reward/system/*", "DELETE", "管理员删除系统单个奖励") enforcer.AddPolicy("admin", "/x/reward/system", "PUT", "管理员修改单个系统奖励") + + enforcer.AddPolicy("admin", "/x/game", "POST", "管理员创建门店奖励") + enforcer.AddPolicy("admin", "/x/game/*", "DELETE", "管理员删除门店单个奖励") + enforcer.AddPolicy("admin", "/x/game", "PUT", "管理员修改单个门店奖励") } instance = &myCasbin{Enforcer: enforcer}