diff --git a/api/task/task.go b/api/task/task.go index 8999042..ffda4bf 100644 --- a/api/task/task.go +++ b/api/task/task.go @@ -16,4 +16,5 @@ type ITaskV1 interface { GetLoginTaskList(ctx context.Context, req *v1.GetLoginTaskListReq) (res *v1.GetLoginTaskListRes, err error) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) Selector(ctx context.Context, req *v1.SelectorReq) (res *v1.SelectorRes, err error) + GetTask(ctx context.Context, req *v1.GetTaskReq) (res *v1.GetTaskRes, err error) } diff --git a/api/task/v1/task.go b/api/task/v1/task.go index 82c3f0a..e61c4c1 100644 --- a/api/task/v1/task.go +++ b/api/task/v1/task.go @@ -34,7 +34,7 @@ type NonLoginTaskListRes struct { } type GetLoginTaskListReq struct { - g.Meta `path:"/task/getLoginTaskList" method:"get" tags:"Task" summary:"(PC)网吧未登录任务列表"` + g.Meta `path:"/task/getLoginTaskList" method:"get" tags:"Task" summary:"(PC)网吧已登录任务列表"` NetBarAccount string `json:"netBarAccount" v:"required#网关账号不能为空" dc:"网关账号"` //Num int `json:"num" v:"required#不能为空" dc:""` //Pageidx string `json:"pageidx" dc:"分页索引"` @@ -50,10 +50,10 @@ type GetLoginTaskListRes struct { type ListReq struct { g.Meta `path:"/task/list" method:"get" tags:"Task" summary:"(PC)任务列表"` //StoreId int `json:"storeId" dc:"门店 id"` - StoreId int `json:"storeId" v:"required#门店 id不能为空" dc:"门店 id"` - Gid int `json:"gid" v:"required#游戏唯一id不能为空" dc:"游戏唯一id"` - Page int `json:"page" dc:"页数"` - Size int `json:"size" dc:"条数"` + StoreId int `json:"storeId" dc:"门店 id"` + Gid int `json:"gid" dc:"游戏唯一id"` + Page int `json:"page" dc:"页数"` + Size int `json:"size" dc:"条数"` } type ListRes struct { @@ -69,3 +69,14 @@ type SelectorReq struct { type SelectorRes struct { List interface{} `json:"list"` } + +// GetTaskReq 添加任务记录 +type GetTaskReq struct { + g.Meta `path:"/task/get" method:"post" tags:"Task" summary:"(PC)任务领取"` + TaskId int `json:"taskId" v:"required#任务id不能为空" dc:"任务id"` + StoreId int `json:"storeId" v:"required#门店 id不能为空" dc:"门店 id"` +} + +type GetTaskRes struct { + Success bool `json:"success"` +} diff --git a/api/user/user.go b/api/user/user.go index beac2c3..7ff0b72 100644 --- a/api/user/user.go +++ b/api/user/user.go @@ -19,4 +19,5 @@ type IUserV1 interface { GetUserBoundInfo(ctx context.Context, req *v1.GetUserBoundInfoReq) (res *v1.GetUserBoundInfoRes, err error) GetBoundUrl(ctx context.Context, req *v1.GetBoundUrlReq) (res *v1.GetBoundUrlRes, err error) GetUnboundUrl(ctx context.Context, req *v1.GetUnboundUrlReq) (res *v1.GetUnboundUrlRes, err error) + DelUser(ctx context.Context, req *v1.DelUserReq) (res *v1.DelUserRes, err error) } diff --git a/api/user/v1/user.go b/api/user/v1/user.go index 39b55c0..f512153 100644 --- a/api/user/v1/user.go +++ b/api/user/v1/user.go @@ -90,3 +90,12 @@ type GetUnboundUrlReq struct { type GetUnboundUrlRes struct { Url string `json:"url" dc:"解绑的 h5 页面 url"` } + +type DelUserReq struct { + g.Meta `path:"/user/del/{id}" method:"delete" tags:"User" summary:"(PC)删除用户"` + Id int `json:"id" v:"required#用户id不能为空" dc:"用户id"` +} + +type DelUserRes struct { + Success bool `json:"success" dc:"是否成功"` +} diff --git a/internal/controller/rewardType/rewardType_v1_create.go b/internal/controller/rewardType/rewardType_v1_create.go index 9352366..e761a7f 100644 --- a/internal/controller/rewardType/rewardType_v1_create.go +++ b/internal/controller/rewardType/rewardType_v1_create.go @@ -13,7 +13,14 @@ func (c *ControllerV1) Create(ctx context.Context, req *v1.CreateReq) (res *v1.C fromCtx := g.RequestFromCtx(ctx) operatorId := fromCtx.GetCtxVar("id").Int64() operatorRole := fromCtx.GetCtxVar("role").String() - out, err := service.RewardType().Create(ctx, &model.RewardTypeCreateIn{OperatorId: operatorId, OperatorRole: operatorRole, Name: req.Name, Description: req.Description, Source: req.Source, Status: req.Status, StoreId: req.StoreId}) + out, err := service.RewardType().Create(ctx, &model.RewardTypeCreateIn{ + OperatorId: operatorId, + OperatorRole: operatorRole, + Name: req.Name, + Description: req.Description, + Source: req.Source, + Status: req.Status, + StoreId: req.StoreId}) if err != nil { return nil, err } diff --git a/internal/controller/task/task_v1_get_task.go b/internal/controller/task/task_v1_get_task.go new file mode 100644 index 0000000..3122e90 --- /dev/null +++ b/internal/controller/task/task_v1_get_task.go @@ -0,0 +1,24 @@ +package task + +import ( + "context" + "github.com/gogf/gf/v2/frame/g" + "server/internal/model" + "server/internal/service" + + "server/api/task/v1" +) + +func (c *ControllerV1) GetTask(ctx context.Context, req *v1.GetTaskReq) (res *v1.GetTaskRes, err error) { + + userId := g.RequestFromCtx(ctx).GetCtxVar("id").Int() + out, err := service.Task().GetTask(ctx, &model.GetTaskIn{ + TaskId: req.TaskId, + StoreId: req.StoreId, + UserId: userId, + }) + if err != nil { + return nil, err + } + return &v1.GetTaskRes{Success: out.Success}, nil +} diff --git a/internal/controller/user/user_v1_del_user.go b/internal/controller/user/user_v1_del_user.go new file mode 100644 index 0000000..ca48fa7 --- /dev/null +++ b/internal/controller/user/user_v1_del_user.go @@ -0,0 +1,19 @@ +package user + +import ( + "context" + "server/internal/model" + "server/internal/service" + + "server/api/user/v1" +) + +func (c *ControllerV1) DelUser(ctx context.Context, req *v1.DelUserReq) (res *v1.DelUserRes, err error) { + + out, err := service.User().DelUser(ctx, &model.DelUserIn{Id: int64(req.Id)}) + + if err != nil { + return nil, err + } + return &v1.DelUserRes{Success: out.Success}, nil +} 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 993ab21..34d43cd 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. @@ -43,11 +44,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, } } @@ -73,7 +75,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/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 d6469fa..600d641 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. @@ -45,11 +46,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, } } @@ -75,7 +77,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_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/tasks.go b/internal/dao/internal/tasks.go index ef2f3a2..7434913 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. @@ -47,11 +48,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, } } @@ -77,7 +79,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/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/game/game.go b/internal/logic/game/game.go index cbdd8f9..764b47c 100644 --- a/internal/logic/game/game.go +++ b/internal/logic/game/game.go @@ -24,7 +24,7 @@ func (s *sGame) GameList(ctx context.Context, in *model.GameListIn) (out *model. list := make([]model.Game, 0) var total int - err = dao.Games.Ctx(ctx).Page(in.Page, in.Size).ScanAndCount(&list, &total, false) + err = dao.Games.Ctx(ctx).Page(in.Page, in.Size).OrderDesc(dao.Games.Columns().CreatedAt).ScanAndCount(&list, &total, false) if err != nil { return nil, ecode.Fail.Sub("游戏列表获取失败") } diff --git a/internal/logic/rewardType/rewardType.go b/internal/logic/rewardType/rewardType.go index 196f826..bab9168 100644 --- a/internal/logic/rewardType/rewardType.go +++ b/internal/logic/rewardType/rewardType.go @@ -328,6 +328,15 @@ func (s *sRewardType) List(ctx context.Context, in *model.RewardTypeListIn) (out return nil, err } + if in.OperatorRole == consts.AdminRoleCode { + orm = orm.LeftJoin(dao.Stores.Table(), fmt.Sprintf( + "%s.%s = %s.%s", + dao.RewardTypes.Table(), dao.RewardTypes.Columns().StoreId, + dao.Stores.Table(), dao.Stores.Columns().Id), + ).Fields(fmt.Sprintf("%s.*, %s.%s %s", + dao.RewardTypes.Table(), dao.Stores.Table(), dao.Stores.Columns().Name, "storeName")) + } + // 查询分页数据 err = orm.Page(in.Page, in.Size). OrderAsc(fmt.Sprintf("%s.%s", dao.RewardTypes.Table(), dao.RewardTypes.Columns().Source)). diff --git a/internal/logic/task/task.go b/internal/logic/task/task.go index 9bd46da..73da102 100644 --- a/internal/logic/task/task.go +++ b/internal/logic/task/task.go @@ -9,6 +9,7 @@ import ( "server/internal/model/do" "server/internal/service" "server/utility/ecode" + "server/utility/snowid" "server/utility/tencent" "sort" "strconv" @@ -220,8 +221,12 @@ func (s *sTask) GetTaskList(ctx context.Context, in *model.TaskListIn) (out *mod var data []model.Tasks var total int m := dao.Tasks.Ctx(ctx) - //err = m.Page(in.Page, in.Size).Where(do.Tasks{GameId: in.Gid, StoreId: in.StoreId}).LeftJoin(dao.StoreTaskRewards.Table(), fmt.Sprintf("`%s`.`id` = `%s`.`task_id`", dao.Tasks.Table(), dao.StoreTaskRewards.Table())).ScanAndCount(&data, &total, false) - err = m.Page(in.Page, in.Size).Where(do.Tasks{GameId: in.Gid, StoreId: in.StoreId}).WithAll().ScanAndCount(&data, &total, false) + + if in.StoreId != 0 { + m = m.Where(do.Tasks{StoreId: in.StoreId}) + } + + err = m.Page(in.Page, in.Size).Where(do.Tasks{GameId: in.Gid}).WithAll().ScanAndCount(&data, &total, false) if err != nil { return nil, ecode.Fail.Sub("任务列表获取失败") @@ -250,3 +255,39 @@ func (s *sTask) GetSelectorList(ctx context.Context, in *model.SelectorIn) (out } return &data, nil } + +// GetTask 完成任务 +func (s *sTask) GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.GetTaskOut, err error) { + + var userTask []*model.UserTask + err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId, StoreId: in.StoreId}).WhereNot("status", 3).Scan(&userTask) + if err != nil { + return nil, ecode.Fail.Sub("查询用户该任务记录失败") + } + + if userTask != nil { + return nil, ecode.Fail.Sub("该任务记录已存在") + } + + // TODO 流水号未知 + serialNumber, err := snowid.GetSnowClient().GenerateSerialNumber() + if err != nil { + return nil, ecode.Fail.Sub("生成流水号异常") + } + + dao.UserTasks.Ctx(ctx).Where(do.UserTasks{UserId: in.UserId, TaskId: in.TaskId}) + _, err = dao.UserTasks.Ctx(ctx).Insert(do.UserTasks{ + UserId: in.UserId, + TaskId: in.TaskId, + StoreId: in.StoreId, + Status: 1, + SerialNumber: serialNumber, + }) + + if err != nil { + return nil, ecode.Fail.Sub("添加任务记录异常") + } + return &model.GetTaskOut{ + Success: true, + }, nil +} diff --git a/internal/logic/user/user.go b/internal/logic/user/user.go index 8003b02..457539f 100644 --- a/internal/logic/user/user.go +++ b/internal/logic/user/user.go @@ -280,3 +280,22 @@ func (s *sUser) BoundInfo(ctx context.Context, in *model.UserBoundInfoIn) (out * Utype: result.Utype, }, nil } + +func (s *sUser) DelUser(ctx context.Context, in *model.DelUserIn) (out *model.DeleteOut, err error) { + + exist, err := dao.Users.Ctx(ctx).Where(do.Users{Id: in.Id}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查询该用户失败") + } + + if !exist { + return nil, ecode.Params.Sub("该用户不存在") + } + + _, err = dao.Users.Ctx(ctx).Delete(do.Users{Id: in.Id}) + if err != nil { + return nil, ecode.Fail.Sub("删除用户失败") + } + + return &model.DeleteOut{Success: true}, nil +} diff --git a/internal/model/rewardType.go b/internal/model/rewardType.go index f5ddc7f..2197799 100644 --- a/internal/model/rewardType.go +++ b/internal/model/rewardType.go @@ -15,6 +15,7 @@ type RewardType struct { CreatedAt *gtime.Time `json:"createdAt" dc:"创建时间" orm:"created_at"` UpdatedAt *gtime.Time `json:"updatedAt" dc:"更新时间" orm:"updated_at"` DeletedAt *gtime.Time `json:"deletedAt" dc:"软删除时间戳" orm:"deleted_at"` + StoreName string `json:"storeName" dc:"门店名称" orm:"storeName"` } // RewardTypeCreateIn 创建奖励类型入参 diff --git a/internal/model/task.go b/internal/model/task.go index 523b497..6e869fb 100644 --- a/internal/model/task.go +++ b/internal/model/task.go @@ -97,7 +97,3 @@ type StoreData struct { MerchantId int `json:"merchantId" orm:"merchant_id"` StoreName string `json:"storeName" orm:"name"` } - -type S struct { - Name string `json:"name"` -} diff --git a/internal/model/user.go b/internal/model/user.go index b2c54c9..8c2130c 100644 --- a/internal/model/user.go +++ b/internal/model/user.go @@ -173,3 +173,11 @@ type UserBoundInfoOut struct { Nick string Utype int8 } + +type DelUserIn struct { + Id int64 +} + +type DelUserOut struct { + Success bool +} diff --git a/internal/model/userTask.go b/internal/model/userTask.go index 677d417..502faae 100644 --- a/internal/model/userTask.go +++ b/internal/model/userTask.go @@ -5,7 +5,7 @@ import ( "github.com/gogf/gf/v2/os/gtime" ) -type UserTaskRanking struct { +type UserTask struct { g.Meta `orm:"table:task"` Id int `orm:"column:id" json:"id"` // UserId int `orm:"column:user_id" json:"userId"` // 用户 id @@ -50,3 +50,14 @@ type LoginUserRanking struct { type LoginUserRankingNum struct { Num int `orm:"num" json:"num"` } + +// GetTaskIn 添加任务记录入参 +type GetTaskIn struct { + TaskId int `json:"taskId"` + StoreId int `json:"storeId"` + UserId int `json:"userId"` +} + +type GetTaskOut struct { + Success bool `json:"success"` +} diff --git a/internal/service/task.go b/internal/service/task.go index b8e9e83..a709d88 100644 --- a/internal/service/task.go +++ b/internal/service/task.go @@ -18,6 +18,8 @@ type ( GetLoginTaskList(ctx context.Context, in *model.GetLoginTaskListIn) (out *model.GetLoginTaskListOut, err error) GetTaskList(ctx context.Context, in *model.TaskListIn) (out *model.TaskListOut, err error) GetSelectorList(ctx context.Context, in *model.SelectorIn) (out *[]model.SelectorOut, err error) + // GetTask 完成任务 + GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.GetTaskOut, err error) } ) diff --git a/internal/service/user.go b/internal/service/user.go index 7d5b9b3..c890cab 100644 --- a/internal/service/user.go +++ b/internal/service/user.go @@ -22,6 +22,7 @@ type ( BoundUrl(ctx context.Context, in *model.UserBoundUrlIn) (out *model.UserBoundUrlOut, err error) UnBoundUrl(ctx context.Context, in *model.UserBoundUrlIn) (out *model.UserUnBoundUrlOut, err error) BoundInfo(ctx context.Context, in *model.UserBoundInfoIn) (out *model.UserBoundInfoOut, err error) + DelUser(ctx context.Context, in *model.DelUserIn) (out *model.DeleteOut, err error) } ) diff --git a/utility/myCasbin/casbin.go b/utility/myCasbin/casbin.go index 7177977..92bb470 100644 --- a/utility/myCasbin/casbin.go +++ b/utility/myCasbin/casbin.go @@ -76,10 +76,12 @@ func init() { // 任务 enforcer.AddPolicy("user", "/x/task/getLoginTaskList", "GET", "获取任务列表(已登录)") + enforcer.AddPolicy("user", "/x/task/get", "POST", "领取任务") } // 门店 { + // 门店:修改 // 奖励类型 @@ -137,6 +139,9 @@ func init() { // 任务 enforcer.AddPolicy("admin", "/x/task/selector", "GET", "管理员获取任务列表二级选择器") + + // 用户:删除 + enforcer.AddPolicy("admin", "/x/user/del/{id}", "DELETE", "删除用户") } instance = &myCasbin{Enforcer: enforcer} diff --git a/utility/snowid/snowid.go b/utility/snowid/snowid.go index b7a0bbf..0da03bc 100644 --- a/utility/snowid/snowid.go +++ b/utility/snowid/snowid.go @@ -50,3 +50,8 @@ func (c *snowClient) generateCodeWithPrefix(prefix string) (string, error) { id := c.node.Generate().Int64() return fmt.Sprintf("%s%d", prefix, id), nil } + +// GenerateSerialNumber 生成任务流水号 +func (c *snowClient) GenerateSerialNumber() (string, error) { + return c.generateCodeWithPrefix("SN") +}