From 37ca5a7462a6188d1a7eac21fda92034ecb01752 Mon Sep 17 00:00:00 2001 From: denghui <1016848185@qq.com> Date: Fri, 4 Jul 2025 14:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=208=E5=9C=88=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/auth/auth.go | 1 + api/auth/v1/auth.go | 9 ++ api/wx/v1/wx.go | 5 +- .../auth/auth_v1_quan_8_autologin.go | 21 +++ .../wx/wx_v1_get_wechat_scene_id.go | 13 +- internal/dao/internal/admins.go | 22 +-- internal/dao/internal/feedbacks.go | 22 +-- internal/dao/internal/games.go | 22 +-- internal/dao/internal/merchant_admins.go | 22 +-- internal/dao/internal/merchants.go | 22 +-- internal/dao/internal/notices.go | 22 +-- internal/dao/internal/reward_callback.go | 22 +-- internal/dao/internal/reward_types.go | 22 +-- internal/dao/internal/reward_waters.go | 22 +-- internal/dao/internal/rewards.go | 22 +-- internal/dao/internal/roles.go | 22 +-- internal/dao/internal/store_admins.go | 22 +-- .../dao/internal/store_desktop_settings.go | 22 +-- internal/dao/internal/store_ips.go | 22 +-- .../dao/internal/store_netfee_area_level.go | 22 +-- internal/dao/internal/store_roles.go | 22 +-- internal/dao/internal/stores.go | 22 +-- internal/dao/internal/task_rewards.go | 22 +-- internal/dao/internal/tasks.go | 22 +-- internal/dao/internal/user_task_rewards.go | 22 +-- internal/dao/internal/user_tasks.go | 22 +-- internal/dao/internal/users.go | 24 ++- internal/logic/user/user.go | 108 +++++++++++++ internal/model/do/users.go | 1 + internal/model/entity/users.go | 1 + internal/model/user.go | 18 +++ internal/service/reward.go | 145 ++++++++++++++++++ internal/service/task.go | 1 - internal/service/user.go | 2 + 34 files changed, 497 insertions(+), 314 deletions(-) create mode 100644 internal/controller/auth/auth_v1_quan_8_autologin.go diff --git a/api/auth/auth.go b/api/auth/auth.go index a7bd84e..01d5436 100644 --- a/api/auth/auth.go +++ b/api/auth/auth.go @@ -16,4 +16,5 @@ type IAuthV1 interface { MerchantCode(ctx context.Context, req *v1.MerchantCodeReq) (res *v1.MerchantCodeRes, err error) MerchantRegister(ctx context.Context, req *v1.MerchantRegisterReq) (res *v1.MerchantRegisterRes, err error) StoreLogin(ctx context.Context, req *v1.StoreLoginReq) (res *v1.StoreLoginRes, err error) + Quan8Autologin(ctx context.Context, req *v1.Quan8AutologinReq) (res *v1.Quan8AutologinRes, err error) } diff --git a/api/auth/v1/auth.go b/api/auth/v1/auth.go index e731fe3..a7b431f 100644 --- a/api/auth/v1/auth.go +++ b/api/auth/v1/auth.go @@ -58,3 +58,12 @@ type StoreLoginRes struct { g.Meta `mime:"application/json"` Token string `json:"token"` } + +type Quan8AutologinReq struct { + g.Meta `path:"/quan8/autologin" method:"post" tags:"PC/Auth" summary:"8圈用户自动登录该系统"` + UUID string `json:"uuid" v:"required#UUID不能为空" dc:"UUID"` + StoreId int64 +} +type Quan8AutologinRes struct { + Token string `json:"token"` +} diff --git a/api/wx/v1/wx.go b/api/wx/v1/wx.go index fea6d5c..66756fc 100644 --- a/api/wx/v1/wx.go +++ b/api/wx/v1/wx.go @@ -44,8 +44,9 @@ type WeChatPollingRes struct { } type GetWechatSceneIdReq struct { - g.Meta `path:"/wechat/sceneId" method:"get" tags:"PC/WeChat" summary:"(PC)获取微信场景ID"` - NetbarAccount string `json:"netbarAccount" v:"required" dc:"网关账号"` + g.Meta `path:"/wechat/sceneId" method:"get" tags:"PC/WeChat" summary:"(PC)获取微信场景ID"` + StoreId int `json:"storeId" v:"required#门店 id 账号不能为空" dc:"门店ID"` + UUID string `json:"uuid" dc:"8圈唯一 id"` } type GetWechatSceneIdRes struct { diff --git a/internal/controller/auth/auth_v1_quan_8_autologin.go b/internal/controller/auth/auth_v1_quan_8_autologin.go new file mode 100644 index 0000000..3a3fcec --- /dev/null +++ b/internal/controller/auth/auth_v1_quan_8_autologin.go @@ -0,0 +1,21 @@ +package auth + +import ( + "context" + "server/internal/model" + "server/internal/service" + + "server/api/auth/v1" +) + +func (c *ControllerV1) Quan8Autologin(ctx context.Context, req *v1.Quan8AutologinReq) (res *v1.Quan8AutologinRes, err error) { + out, err := service.User().Quan8Autologin(ctx, &model.Quan8AutologinIn{ + UUID: req.UUID, + StoreId: req.StoreId, + }) + if err != nil { + return + } + return &v1.Quan8AutologinRes{Token: out.Token}, nil + +} diff --git a/internal/controller/wx/wx_v1_get_wechat_scene_id.go b/internal/controller/wx/wx_v1_get_wechat_scene_id.go index 6f1c324..d6ad9d9 100644 --- a/internal/controller/wx/wx_v1_get_wechat_scene_id.go +++ b/internal/controller/wx/wx_v1_get_wechat_scene_id.go @@ -2,11 +2,18 @@ package wx import ( "context" - "fmt" "server/api/wx/v1" - "time" + "server/internal/model" + "server/internal/service" ) func (c *ControllerV1) GetWechatSceneId(ctx context.Context, req *v1.GetWechatSceneIdReq) (res *v1.GetWechatSceneIdRes, err error) { - return &v1.GetWechatSceneIdRes{SceneId: fmt.Sprintf("%s_%d", req.NetbarAccount, time.Now().Unix())}, nil + out, err := service.User().GenerateSceneId(ctx, &model.GenerateSceneIdIn{ + StoreId: req.StoreId, + UUId: req.UUID, + }) + if err != nil { + return nil, err + } + return &v1.GetWechatSceneIdRes{SceneId: out.SceneId}, nil } diff --git a/internal/dao/internal/admins.go b/internal/dao/internal/admins.go index dc72d15..7c3f2be 100644 --- a/internal/dao/internal/admins.go +++ b/internal/dao/internal/admins.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // AdminsColumns defines and stores column names for the table admins. @@ -50,12 +49,11 @@ var adminsColumns = AdminsColumns{ } // NewAdminsDao creates and returns a new DAO object for table data access. -func NewAdminsDao(handlers ...gdb.ModelHandler) *AdminsDao { +func NewAdminsDao() *AdminsDao { return &AdminsDao{ - group: "default", - table: "admins", - columns: adminsColumns, - handlers: handlers, + group: "default", + table: "admins", + columns: adminsColumns, } } @@ -81,11 +79,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 7a8d085..d67a1e5 100644 --- a/internal/dao/internal/feedbacks.go +++ b/internal/dao/internal/feedbacks.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // FeedbacksColumns defines and stores column names for the table feedbacks. @@ -52,12 +51,11 @@ var feedbacksColumns = FeedbacksColumns{ } // NewFeedbacksDao creates and returns a new DAO object for table data access. -func NewFeedbacksDao(handlers ...gdb.ModelHandler) *FeedbacksDao { +func NewFeedbacksDao() *FeedbacksDao { return &FeedbacksDao{ - group: "default", - table: "feedbacks", - columns: feedbacksColumns, - handlers: handlers, + group: "default", + table: "feedbacks", + columns: feedbacksColumns, } } @@ -83,11 +81,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 dac75c7..b53dd54 100644 --- a/internal/dao/internal/games.go +++ b/internal/dao/internal/games.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // GamesColumns defines and stores column names for the table games. @@ -46,12 +45,11 @@ var gamesColumns = GamesColumns{ } // NewGamesDao creates and returns a new DAO object for table data access. -func NewGamesDao(handlers ...gdb.ModelHandler) *GamesDao { +func NewGamesDao() *GamesDao { return &GamesDao{ - group: "default", - table: "games", - columns: gamesColumns, - handlers: handlers, + group: "default", + table: "games", + columns: gamesColumns, } } @@ -77,11 +75,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 64533e1..51ac691 100644 --- a/internal/dao/internal/merchant_admins.go +++ b/internal/dao/internal/merchant_admins.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // MerchantAdminsColumns defines and stores column names for the table merchant_admins. @@ -58,12 +57,11 @@ var merchantAdminsColumns = MerchantAdminsColumns{ } // NewMerchantAdminsDao creates and returns a new DAO object for table data access. -func NewMerchantAdminsDao(handlers ...gdb.ModelHandler) *MerchantAdminsDao { +func NewMerchantAdminsDao() *MerchantAdminsDao { return &MerchantAdminsDao{ - group: "default", - table: "merchant_admins", - columns: merchantAdminsColumns, - handlers: handlers, + group: "default", + table: "merchant_admins", + columns: merchantAdminsColumns, } } @@ -89,11 +87,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 717f855..6dd5d05 100644 --- a/internal/dao/internal/merchants.go +++ b/internal/dao/internal/merchants.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // MerchantsColumns defines and stores column names for the table merchants. @@ -72,12 +71,11 @@ var merchantsColumns = MerchantsColumns{ } // NewMerchantsDao creates and returns a new DAO object for table data access. -func NewMerchantsDao(handlers ...gdb.ModelHandler) *MerchantsDao { +func NewMerchantsDao() *MerchantsDao { return &MerchantsDao{ - group: "default", - table: "merchants", - columns: merchantsColumns, - handlers: handlers, + group: "default", + table: "merchants", + columns: merchantsColumns, } } @@ -103,11 +101,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/notices.go b/internal/dao/internal/notices.go index 9c2cfce..5cc451a 100644 --- a/internal/dao/internal/notices.go +++ b/internal/dao/internal/notices.go @@ -13,10 +13,9 @@ import ( // NoticesDao is the data access object for the table notices. type NoticesDao 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 NoticesColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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 NoticesColumns // columns contains all the column names of Table for convenient usage. } // NoticesColumns defines and stores column names for the table notices. @@ -50,12 +49,11 @@ var noticesColumns = NoticesColumns{ } // NewNoticesDao creates and returns a new DAO object for table data access. -func NewNoticesDao(handlers ...gdb.ModelHandler) *NoticesDao { +func NewNoticesDao() *NoticesDao { return &NoticesDao{ - group: "default", - table: "notices", - columns: noticesColumns, - handlers: handlers, + group: "default", + table: "notices", + columns: noticesColumns, } } @@ -81,11 +79,7 @@ func (dao *NoticesDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *NoticesDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/reward_callback.go b/internal/dao/internal/reward_callback.go index d148d1c..3cc67a2 100644 --- a/internal/dao/internal/reward_callback.go +++ b/internal/dao/internal/reward_callback.go @@ -13,10 +13,9 @@ import ( // RewardCallbackDao is the data access object for the table reward_callback. type RewardCallbackDao 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 RewardCallbackColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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 RewardCallbackColumns // columns contains all the column names of Table for convenient usage. } // RewardCallbackColumns defines and stores column names for the table reward_callback. @@ -50,12 +49,11 @@ var rewardCallbackColumns = RewardCallbackColumns{ } // NewRewardCallbackDao creates and returns a new DAO object for table data access. -func NewRewardCallbackDao(handlers ...gdb.ModelHandler) *RewardCallbackDao { +func NewRewardCallbackDao() *RewardCallbackDao { return &RewardCallbackDao{ - group: "default", - table: "reward_callback", - columns: rewardCallbackColumns, - handlers: handlers, + group: "default", + table: "reward_callback", + columns: rewardCallbackColumns, } } @@ -81,11 +79,7 @@ func (dao *RewardCallbackDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *RewardCallbackDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/reward_types.go b/internal/dao/internal/reward_types.go index c035828..b79610a 100644 --- a/internal/dao/internal/reward_types.go +++ b/internal/dao/internal/reward_types.go @@ -13,10 +13,9 @@ import ( // RewardTypesDao is the data access object for the table reward_types. type RewardTypesDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns RewardTypesColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns RewardTypesColumns // columns contains all the column names of Table for convenient usage. } // RewardTypesColumns defines and stores column names for the table reward_types. @@ -46,12 +45,11 @@ var rewardTypesColumns = RewardTypesColumns{ } // NewRewardTypesDao creates and returns a new DAO object for table data access. -func NewRewardTypesDao(handlers ...gdb.ModelHandler) *RewardTypesDao { +func NewRewardTypesDao() *RewardTypesDao { return &RewardTypesDao{ - group: "default", - table: "reward_types", - columns: rewardTypesColumns, - handlers: handlers, + group: "default", + table: "reward_types", + columns: rewardTypesColumns, } } @@ -77,11 +75,7 @@ func (dao *RewardTypesDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *RewardTypesDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/reward_waters.go b/internal/dao/internal/reward_waters.go index 83c4803..593f014 100644 --- a/internal/dao/internal/reward_waters.go +++ b/internal/dao/internal/reward_waters.go @@ -13,10 +13,9 @@ import ( // RewardWatersDao is the data access object for the table reward_waters. type RewardWatersDao 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 RewardWatersColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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 RewardWatersColumns // columns contains all the column names of Table for convenient usage. } // RewardWatersColumns defines and stores column names for the table reward_waters. @@ -48,12 +47,11 @@ var rewardWatersColumns = RewardWatersColumns{ } // NewRewardWatersDao creates and returns a new DAO object for table data access. -func NewRewardWatersDao(handlers ...gdb.ModelHandler) *RewardWatersDao { +func NewRewardWatersDao() *RewardWatersDao { return &RewardWatersDao{ - group: "default", - table: "reward_waters", - columns: rewardWatersColumns, - handlers: handlers, + group: "default", + table: "reward_waters", + columns: rewardWatersColumns, } } @@ -79,11 +77,7 @@ func (dao *RewardWatersDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *RewardWatersDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/rewards.go b/internal/dao/internal/rewards.go index dd33c89..6b91001 100644 --- a/internal/dao/internal/rewards.go +++ b/internal/dao/internal/rewards.go @@ -13,10 +13,9 @@ import ( // RewardsDao is the data access object for the table rewards. type RewardsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of the current DAO. - columns RewardsColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns RewardsColumns // columns contains all the column names of Table for convenient usage. } // RewardsColumns defines and stores column names for the table rewards. @@ -76,12 +75,11 @@ var rewardsColumns = RewardsColumns{ } // NewRewardsDao creates and returns a new DAO object for table data access. -func NewRewardsDao(handlers ...gdb.ModelHandler) *RewardsDao { +func NewRewardsDao() *RewardsDao { return &RewardsDao{ - group: "default", - table: "rewards", - columns: rewardsColumns, - handlers: handlers, + group: "default", + table: "rewards", + columns: rewardsColumns, } } @@ -107,11 +105,7 @@ func (dao *RewardsDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *RewardsDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 b540549..9eab304 100644 --- a/internal/dao/internal/roles.go +++ b/internal/dao/internal/roles.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // RolesColumns defines and stores column names for the table roles. @@ -48,12 +47,11 @@ var rolesColumns = RolesColumns{ } // NewRolesDao creates and returns a new DAO object for table data access. -func NewRolesDao(handlers ...gdb.ModelHandler) *RolesDao { +func NewRolesDao() *RolesDao { return &RolesDao{ - group: "default", - table: "roles", - columns: rolesColumns, - handlers: handlers, + group: "default", + table: "roles", + columns: rolesColumns, } } @@ -79,11 +77,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 538322c..7bcffcc 100644 --- a/internal/dao/internal/store_admins.go +++ b/internal/dao/internal/store_admins.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // StoreAdminsColumns defines and stores column names for the table store_admins. @@ -58,12 +57,11 @@ var storeAdminsColumns = StoreAdminsColumns{ } // NewStoreAdminsDao creates and returns a new DAO object for table data access. -func NewStoreAdminsDao(handlers ...gdb.ModelHandler) *StoreAdminsDao { +func NewStoreAdminsDao() *StoreAdminsDao { return &StoreAdminsDao{ - group: "default", - table: "store_admins", - columns: storeAdminsColumns, - handlers: handlers, + group: "default", + table: "store_admins", + columns: storeAdminsColumns, } } @@ -89,11 +87,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 88c9cb5..dec1ba9 100644 --- a/internal/dao/internal/store_desktop_settings.go +++ b/internal/dao/internal/store_desktop_settings.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // StoreDesktopSettingsColumns defines and stores column names for the table store_desktop_settings. @@ -34,12 +33,11 @@ var storeDesktopSettingsColumns = StoreDesktopSettingsColumns{ } // NewStoreDesktopSettingsDao creates and returns a new DAO object for table data access. -func NewStoreDesktopSettingsDao(handlers ...gdb.ModelHandler) *StoreDesktopSettingsDao { +func NewStoreDesktopSettingsDao() *StoreDesktopSettingsDao { return &StoreDesktopSettingsDao{ - group: "default", - table: "store_desktop_settings", - columns: storeDesktopSettingsColumns, - handlers: handlers, + group: "default", + table: "store_desktop_settings", + columns: storeDesktopSettingsColumns, } } @@ -65,11 +63,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/store_ips.go b/internal/dao/internal/store_ips.go index dfdfd58..20197cb 100644 --- a/internal/dao/internal/store_ips.go +++ b/internal/dao/internal/store_ips.go @@ -13,10 +13,9 @@ import ( // StoreIpsDao is the data access object for the table store_ips. type StoreIpsDao 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 StoreIpsColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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 StoreIpsColumns // columns contains all the column names of Table for convenient usage. } // StoreIpsColumns defines and stores column names for the table store_ips. @@ -42,12 +41,11 @@ var storeIpsColumns = StoreIpsColumns{ } // NewStoreIpsDao creates and returns a new DAO object for table data access. -func NewStoreIpsDao(handlers ...gdb.ModelHandler) *StoreIpsDao { +func NewStoreIpsDao() *StoreIpsDao { return &StoreIpsDao{ - group: "default", - table: "store_ips", - columns: storeIpsColumns, - handlers: handlers, + group: "default", + table: "store_ips", + columns: storeIpsColumns, } } @@ -73,11 +71,7 @@ func (dao *StoreIpsDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *StoreIpsDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/store_netfee_area_level.go b/internal/dao/internal/store_netfee_area_level.go index ffa209a..e2a43a6 100644 --- a/internal/dao/internal/store_netfee_area_level.go +++ b/internal/dao/internal/store_netfee_area_level.go @@ -13,10 +13,9 @@ import ( // StoreNetfeeAreaLevelDao is the data access object for the table store_netfee_area_level. type StoreNetfeeAreaLevelDao 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 StoreNetfeeAreaLevelColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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 StoreNetfeeAreaLevelColumns // columns contains all the column names of Table for convenient usage. } // StoreNetfeeAreaLevelColumns defines and stores column names for the table store_netfee_area_level. @@ -50,12 +49,11 @@ var storeNetfeeAreaLevelColumns = StoreNetfeeAreaLevelColumns{ } // NewStoreNetfeeAreaLevelDao creates and returns a new DAO object for table data access. -func NewStoreNetfeeAreaLevelDao(handlers ...gdb.ModelHandler) *StoreNetfeeAreaLevelDao { +func NewStoreNetfeeAreaLevelDao() *StoreNetfeeAreaLevelDao { return &StoreNetfeeAreaLevelDao{ - group: "default", - table: "store_netfee_area_level", - columns: storeNetfeeAreaLevelColumns, - handlers: handlers, + group: "default", + table: "store_netfee_area_level", + columns: storeNetfeeAreaLevelColumns, } } @@ -81,11 +79,7 @@ func (dao *StoreNetfeeAreaLevelDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *StoreNetfeeAreaLevelDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 137e1fa..8528459 100644 --- a/internal/dao/internal/store_roles.go +++ b/internal/dao/internal/store_roles.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // StoreRolesColumns defines and stores column names for the table store_roles. @@ -40,12 +39,11 @@ var storeRolesColumns = StoreRolesColumns{ } // NewStoreRolesDao creates and returns a new DAO object for table data access. -func NewStoreRolesDao(handlers ...gdb.ModelHandler) *StoreRolesDao { +func NewStoreRolesDao() *StoreRolesDao { return &StoreRolesDao{ - group: "default", - table: "store_roles", - columns: storeRolesColumns, - handlers: handlers, + group: "default", + table: "store_roles", + columns: storeRolesColumns, } } @@ -71,11 +69,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 69ed619..8bbdc42 100644 --- a/internal/dao/internal/stores.go +++ b/internal/dao/internal/stores.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // StoresColumns defines and stores column names for the table stores. @@ -52,12 +51,11 @@ var storesColumns = StoresColumns{ } // NewStoresDao creates and returns a new DAO object for table data access. -func NewStoresDao(handlers ...gdb.ModelHandler) *StoresDao { +func NewStoresDao() *StoresDao { return &StoresDao{ - group: "default", - table: "stores", - columns: storesColumns, - handlers: handlers, + group: "default", + table: "stores", + columns: storesColumns, } } @@ -83,11 +81,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/task_rewards.go b/internal/dao/internal/task_rewards.go index adf18fb..d745649 100644 --- a/internal/dao/internal/task_rewards.go +++ b/internal/dao/internal/task_rewards.go @@ -13,10 +13,9 @@ import ( // TaskRewardsDao is the data access object for the table task_rewards. type TaskRewardsDao 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 TaskRewardsColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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 TaskRewardsColumns // columns contains all the column names of Table for convenient usage. } // TaskRewardsColumns defines and stores column names for the table task_rewards. @@ -36,12 +35,11 @@ var taskRewardsColumns = TaskRewardsColumns{ } // NewTaskRewardsDao creates and returns a new DAO object for table data access. -func NewTaskRewardsDao(handlers ...gdb.ModelHandler) *TaskRewardsDao { +func NewTaskRewardsDao() *TaskRewardsDao { return &TaskRewardsDao{ - group: "default", - table: "task_rewards", - columns: taskRewardsColumns, - handlers: handlers, + group: "default", + table: "task_rewards", + columns: taskRewardsColumns, } } @@ -67,11 +65,7 @@ func (dao *TaskRewardsDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *TaskRewardsDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 72333ac..ced9c75 100644 --- a/internal/dao/internal/tasks.go +++ b/internal/dao/internal/tasks.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // TasksColumns defines and stores column names for the table tasks. @@ -46,12 +45,11 @@ var tasksColumns = TasksColumns{ } // NewTasksDao creates and returns a new DAO object for table data access. -func NewTasksDao(handlers ...gdb.ModelHandler) *TasksDao { +func NewTasksDao() *TasksDao { return &TasksDao{ - group: "default", - table: "tasks", - columns: tasksColumns, - handlers: handlers, + group: "default", + table: "tasks", + columns: tasksColumns, } } @@ -77,11 +75,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/dao/internal/user_task_rewards.go b/internal/dao/internal/user_task_rewards.go index aff73a2..3aaa431 100644 --- a/internal/dao/internal/user_task_rewards.go +++ b/internal/dao/internal/user_task_rewards.go @@ -13,10 +13,9 @@ import ( // UserTaskRewardsDao is the data access object for the table user_task_rewards. type UserTaskRewardsDao 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 UserTaskRewardsColumns // columns contains all the column names of Table for convenient usage. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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 UserTaskRewardsColumns // columns contains all the column names of Table for convenient usage. } // UserTaskRewardsColumns defines and stores column names for the table user_task_rewards. @@ -58,12 +57,11 @@ var userTaskRewardsColumns = UserTaskRewardsColumns{ } // NewUserTaskRewardsDao creates and returns a new DAO object for table data access. -func NewUserTaskRewardsDao(handlers ...gdb.ModelHandler) *UserTaskRewardsDao { +func NewUserTaskRewardsDao() *UserTaskRewardsDao { return &UserTaskRewardsDao{ - group: "default", - table: "user_task_rewards", - columns: userTaskRewardsColumns, - handlers: handlers, + group: "default", + table: "user_task_rewards", + columns: userTaskRewardsColumns, } } @@ -89,11 +87,7 @@ func (dao *UserTaskRewardsDao) Group() string { // Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *UserTaskRewardsDao) Ctx(ctx context.Context) *gdb.Model { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 8b66fba..a9c2e7f 100644 --- a/internal/dao/internal/user_tasks.go +++ b/internal/dao/internal/user_tasks.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // UserTasksColumns defines and stores column names for the table user_tasks. @@ -54,12 +53,11 @@ var userTasksColumns = UserTasksColumns{ } // NewUserTasksDao creates and returns a new DAO object for table data access. -func NewUserTasksDao(handlers ...gdb.ModelHandler) *UserTasksDao { +func NewUserTasksDao() *UserTasksDao { return &UserTasksDao{ - group: "default", - table: "user_tasks", - columns: userTasksColumns, - handlers: handlers, + group: "default", + table: "user_tasks", + columns: userTasksColumns, } } @@ -85,11 +83,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).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 340eaf7..55d0eda 100644 --- a/internal/dao/internal/users.go +++ b/internal/dao/internal/users.go @@ -13,10 +13,9 @@ 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. - handlers []gdb.ModelHandler // handlers for customized model modification. + 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. } // UsersColumns defines and stores column names for the table users. @@ -37,6 +36,7 @@ type UsersColumns struct { DeletedAt string // 软删除时间 RoleId string // 角色ID LastLoginStoreId string // 上次登录门店ID + Quan8Uuid string // 8圈使用的 uuid } // usersColumns holds the columns for the table users. @@ -57,15 +57,15 @@ var usersColumns = UsersColumns{ DeletedAt: "deleted_at", RoleId: "role_id", LastLoginStoreId: "last_login_store_id", + Quan8Uuid: "quan8_uuid", } // NewUsersDao creates and returns a new DAO object for table data access. -func NewUsersDao(handlers ...gdb.ModelHandler) *UsersDao { +func NewUsersDao() *UsersDao { return &UsersDao{ - group: "default", - table: "users", - columns: usersColumns, - handlers: handlers, + group: "default", + table: "users", + columns: usersColumns, } } @@ -91,11 +91,7 @@ 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 { - model := dao.DB().Model(dao.table) - for _, handler := range dao.handlers { - model = handler(model) - } - return model.Safe().Ctx(ctx) + return dao.DB().Model(dao.table).Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. diff --git a/internal/logic/user/user.go b/internal/logic/user/user.go index 31c8118..e8680cc 100644 --- a/internal/logic/user/user.go +++ b/internal/logic/user/user.go @@ -353,3 +353,111 @@ func (s *sUser) GamelifePackUrl(ctx context.Context, in *model.GamelifePackUrlIn Url: url, }, nil } + +func (s *sUser) Quan8Autologin(ctx context.Context, in *model.Quan8AutologinIn) (out *model.Quan8AutologinOut, err error) { + b, err := dao.Stores.Ctx(ctx).WherePri(in.StoreId).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查找门店失败") + } + if !b { + return nil, ecode.Params.Sub("门店 id 错误") + } + // Fetch default role + value, err := dao.Roles.Ctx(ctx).Where(do.Roles{Code: consts.UserRoleCode}).Fields(dao.Roles.Columns().Code, dao.Roles.Columns().Id).One() + if err != nil { + return nil, ecode.Fail.Sub("查找角色失败") + } + + // Check if user exists by Quan8 UUID + exist, err := dao.Users.Ctx(ctx).Where(do.Users{Quan8Uuid: in.UUID}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查找用户失败") + } + + var userId int64 + if !exist { + // User doesn't exist, create new user + var username string + for { + randomStr := grand.Str("abcdefghijklmnopqrstuvwxyz0123456789", 8) + username = "qy_" + randomStr + count, err := dao.Users.Ctx(ctx).Where(do.Users{Username: username}).Count() + if err != nil { + return nil, ecode.Fail.Sub("检查用户名失败") + } + if count == 0 { + break // username is unique + } + } + + password, err := encrypt.EncryptPassword(consts.DefaultPassword) + if err != nil { + return nil, ecode.Fail.Sub("加密密码失败") + } + + user := &entity.Users{ + Quan8Uuid: in.UUID, + Username: username, + Nickname: username, + PasswordHash: password, + Avatar: consts.DefaultUserAvatar, + FirstVisitAt: gtime.Now(), + LastLoginAt: gtime.Now(), + WxPopenId: utility.GenerateUserID("WX"), + QqPopenId: utility.GenerateUserID("QQ"), + RoleId: value[dao.Roles.Columns().Id].Int64(), + LastLoginStoreId: in.StoreId, + } + + userId, err = dao.Users.Ctx(ctx).InsertAndGetId(user) + if err != nil { + return nil, ecode.Fail.Sub("创建用户失败") + } + } else { + value, err := dao.Users.Ctx(ctx).Where(do.Users{Quan8Uuid: in.UUID}).Fields(dao.Users.Columns().Id).Value() + if err != nil { + return nil, ecode.Fail.Sub("查找用户失败") + } + userId = value.Int64() + + if _, err := dao.Users.Ctx(ctx).Where(do.Users{Id: userId}).Update(do.Users{LastLoginAt: gtime.Now(), LastLoginStoreId: in.StoreId}); err != nil { + return nil, ecode.Fail.Sub("更新登录时间失败") + } + } + // Generate token + token, err := jwt.GenerateToken(&jwt.TokenIn{ + UserId: userId, + Role: value[dao.Roles.Columns().Code].String(), + }) + if err != nil { + return nil, ecode.Fail.Sub("生成token失败") + } + return &model.Quan8AutologinOut{ + Token: token, + }, nil +} + +func (s *sUser) GenerateSceneId(ctx context.Context, in *model.GenerateSceneIdIn) (out *model.GenerateSceneIdOut, err error) { + var sceneId string + + // Check if user exists by UUID if provided + if in.UUId != "" { + exist, err := dao.Users.Ctx(ctx).Where(do.Users{Quan8Uuid: in.UUId}).Exist() + if err != nil { + return nil, ecode.Fail.Sub("查找用户失败") + } + if !exist { + return nil, ecode.Params.Sub("用户不存在") + } + // UUID is provided and user exists, use "is" flag + sceneId = fmt.Sprintf("%d_1_%s", in.StoreId, in.UUId) + } else { + // UUID is empty, use "not" flag with random string + randomStr := grand.Str("abcdefghijklmnopqrstuvwxyz0123456789", 8) + sceneId = fmt.Sprintf("%d_0_%s", in.StoreId, randomStr) + } + + return &model.GenerateSceneIdOut{ + SceneId: sceneId, + }, nil +} diff --git a/internal/model/do/users.go b/internal/model/do/users.go index 3920057..d99cbca 100644 --- a/internal/model/do/users.go +++ b/internal/model/do/users.go @@ -28,4 +28,5 @@ type Users struct { DeletedAt *gtime.Time // 软删除时间 RoleId interface{} // 角色ID LastLoginStoreId interface{} // 上次登录门店ID + Quan8Uuid interface{} // 8圈使用的 uuid } diff --git a/internal/model/entity/users.go b/internal/model/entity/users.go index 4f4153e..39770a9 100644 --- a/internal/model/entity/users.go +++ b/internal/model/entity/users.go @@ -26,4 +26,5 @@ type Users struct { DeletedAt *gtime.Time `json:"deletedAt" orm:"deleted_at" description:"软删除时间"` // 软删除时间 RoleId int64 `json:"roleId" orm:"role_id" description:"角色ID"` // 角色ID LastLoginStoreId int64 `json:"lastLoginStoreId" orm:"last_login_store_id" description:"上次登录门店ID"` // 上次登录门店ID + Quan8Uuid string `json:"quan8Uuid" orm:"quan8_uuid" description:"8圈使用的 uuid"` // 8圈使用的 uuid } diff --git a/internal/model/user.go b/internal/model/user.go index fdc6eb1..71d95c8 100644 --- a/internal/model/user.go +++ b/internal/model/user.go @@ -204,3 +204,21 @@ type GamelifePackUrlIn struct { type GamelifePackUrlOut struct { Url string } +type Quan8AutologinIn struct { + UUID string + NetbarAccount string + StoreId int64 +} + +type Quan8AutologinOut struct { + Token string +} + +type GenerateSceneIdIn struct { + StoreId int + UUId string +} + +type GenerateSceneIdOut struct { + SceneId string +} diff --git a/internal/service/reward.go b/internal/service/reward.go index 0adc112..920b298 100644 --- a/internal/service/reward.go +++ b/internal/service/reward.go @@ -21,6 +21,151 @@ type ( // List 奖励列表 List(ctx context.Context, in *model.RewardListIn) (out *model.RewardListOut, err error) // GetLift 领取奖励 + // func (s *sReward) GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error) { + // + // giftParam := model.GiftParam{} + // var needUrl bool + // // 判断奖励类型 + // if in.Source == 1 { + // // 系统奖励处理 + // if in.RewradTypeId == 16 { + // // 需要大区角色 + // giftParam.AreaId = in.AreaId + // giftParam.Gid = in.GameId + // giftParam.RoleIdx = in.RoleIdx + // giftParam.TaskId = in.TaskId + // } else { + // // 不需要 + // giftParam.TaskId = in.TaskId + // giftParam.Gid = in.GameId + // + // } + // if in.RewardId != 16 && in.RewardId != 37 { + // needUrl = true + // } + // } else { + // // 门店奖励处理 + // + // } + // + // glog.Info(ctx, "调用 tencent开始") + // activity, err := gamelife.GetGamelifeClient(ctx).RequestActivity(ctx, &model.QQNetbarActivityIn{PopenId: in.PopenId, ServiceName: consts.GetGift, GiftParam: giftParam}) + // + // if err != nil { + // return nil, err + // } + // glog.Info(ctx, "调用 tencent结束") + // fmt.Print(activity) + // + // result, ok := activity.(*model.GiftResponse) + // if !ok { + // return nil, ecode.Fail.Sub("数据类型转换失败") + // } + // + // if len(result.GiftItem) == 0 { + // return nil, ecode.Fail.Sub("奖励领取异常") + // } + // + // // 存储数据库记录 + // var data model.GetRewardOut + // if err = dao.RewardWaters.Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) { + // for _, item := range result.GiftItem { + // marshal, err := json.Marshal(item.Water) + // if err != nil { + // return ecode.Fail.Sub("序列化 json 数据出现异常") + // } + // _, err = dao.RewardWaters.Ctx(ctx).Insert(model.RewardWaters{ + // OrderId: item.Water.OrderId, + // Status: int64(item.Result), + // Uid: item.Water.Uid, + // Water: string(marshal), + // TaskId: in.TaskId, + // GameId: int64(in.GameId), + // }) + // + // if err != nil { + // return ecode.Fail.Sub("添加奖励领取记录异常") + // } + // + // // 根据 result判断 + // data.Result = int64(item.Result) + // if item.Result == 1 { + // //// 奖励发放成功,修改状态,扣除数量 + // glog.Infof(ctx, "奖励发放成功1,修改状态,扣除数量") + // // 查询当前奖励是否为最后一个, 如果是则更新任务状态为2 完成 + // count, err := dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: in.UserTaskId}).WhereIn(dao.UserTaskRewards.Columns().Status, []int{2, 3, 5}).Count() + // if err != nil { + // return ecode.Fail.Sub("查询用户任务奖励失败") + // } + // + // if count == 1 { + // // 修改任务记录状态2 + // _, err = dao.UserTasks.Ctx(ctx).Where(do.UserTasks{Id: in.UserTaskId}).Data(do.UserTasks{ + // Status: 2, + // }).Update() + // + // if err != nil { + // return ecode.Fail.Sub("修改用户任务状态失败") + // } + // } + // + // // 增加奖励已领取数量 + // _, err = dao.Rewards.Ctx(ctx).Where(do.Rewards{Id: in.RewardId}).Increment(dao.Rewards.Columns().ReceivedNum, 1) + // if err != nil { + // return ecode.Fail.Sub("获取奖励领取记录异常") + // } + // + // // 修改用户任务奖励记录状态 + // _, err = dao.UserTaskRewards.Ctx(ctx).Where(do.UserTaskRewards{UserTaskId: in.UserTaskId, RewardId: in.RewardId}).Data(do.UserTaskRewards{ + // Status: consts.RewardSuccessStatus, + // }).Update() + // + // if err != nil { + // return ecode.Fail.Sub("修改用户任务奖励记录状态异常") + // } + // } else if item.Result == 2 || item.Result == 3 { + // // 发放背包成功,修改状态 + // glog.Infof(ctx, "奖励发放成功2,修改状态") + // _, err = dao.UserTaskRewards.Ctx(ctx).Data(do.UserTaskRewards{ + // Status: consts.RewardExchangeStatus, + // }).Where(do.UserTaskRewards{ + // Id: in.UserTaskId, + // RewardId: in.RewardId, + // }).Update() + // + // if err != nil { + // return ecode.Fail.Sub("修改用户任务奖励记录状态异常") + // } + // } else if item.Result == 4 { + // // 奖励领取失败,不做操作,直接返回 + // glog.Infof(ctx, "领取奖励失败") + // return ecode.Fail.Sub("领取奖励失败") + // } + // + // //data.List = append(data.List, model.GetRewardNewOut{ + // // Result: int64(item.Result), + // // Water: item.Water, + // //}) + // } + // + // return + // + // }); err != nil { + // return + // } + // + // if needUrl { + // data.Url, err = gamelife.GetGamelifeClient(ctx).GetGamelifePackageUrl(ctx, in.PopenId, in.GameCode, in.GameId, in.BindType) + // if err != nil { + // return nil, ecode.Fail.Sub("获取绑定链接失败") + // } + // } + // + // //return &model.GetRewardOut{ + // // List: data.List, + // //}, err + // return &data, err + // } GetLift(ctx context.Context, in *model.GetRewardIn) (out *model.GetRewardOut, err error) // GetGoodsList 调用外部获取物品列表 GetGoodsList(ctx context.Context, in *model.GetGoodsListIn) (out *model.GetGoodsListOut, err error) diff --git a/internal/service/task.go b/internal/service/task.go index e1724d4..1dcbf65 100644 --- a/internal/service/task.go +++ b/internal/service/task.go @@ -22,7 +22,6 @@ type ( // GetTask 完成任务 GetTask(ctx context.Context, in *model.GetTaskIn) (out *model.GetTaskOut, err error) GetUserTaskRecordsList(ctx context.Context, in *model.UserTaskRecordsListIn) (out *model.UserTaskRecordsListOut, err error) - // GetTaskList PC-WEB获取任务列表 GetTaskList(ctx context.Context, in *model.GetTaskListV2In) (out *model.GetTaskListV2Out, err error) SyncTaskFromGamelife(ctx context.Context) (out *model.SyncTaskOut, err error) } diff --git a/internal/service/user.go b/internal/service/user.go index 74b30b0..40cebae 100644 --- a/internal/service/user.go +++ b/internal/service/user.go @@ -25,6 +25,8 @@ type ( DelUser(ctx context.Context, in *model.DelUserIn) (out *model.DeleteOut, err error) GetUserGameRole(ctx context.Context, in *model.GetUserGameRoleIn) (out *model.GetUserGameRoleOut, err error) GamelifePackUrl(ctx context.Context, in *model.GamelifePackUrlIn) (out *model.GamelifePackUrlOut, err error) + Quan8Autologin(ctx context.Context, in *model.Quan8AutologinIn) (out *model.Quan8AutologinOut, err error) + GenerateSceneId(ctx context.Context, in *model.GenerateSceneIdIn) (out *model.GenerateSceneIdOut, err error) } )