// ========================================================================== // GFast自动生成controller操作代码。 // 生成日期:2024-07-26 15:32:12 // 生成路径: internal/app/system/controller/user_registration.go // 生成人:gfast // desc:极光推送 // company:云南奇讯科技有限公司 // ========================================================================== package controller import ( "context" "errors" "github.com/tiger1103/gfast/v3/api/v1/system" "github.com/tiger1103/gfast/v3/internal/app/system/dao" ct "github.com/tiger1103/gfast/v3/internal/app/system/logic/context" "github.com/tiger1103/gfast/v3/internal/app/system/service" ) type userRegistrationController struct { BaseController } var UserRegistration = new(userRegistrationController) // List 列表 func (c *userRegistrationController) List(ctx context.Context, req *system.UserRegistrationSearchReq) (res *system.UserRegistrationSearchRes, err error) { res, err = service.UserRegistration().List(ctx, req) return } // Get 获取极光推送 func (c *userRegistrationController) Get(ctx context.Context, req *system.UserRegistrationGetReq) (res *system.UserRegistrationGetRes, err error) { res = new(system.UserRegistrationGetRes) res.UserRegistrationInfoRes, err = service.UserRegistration().GetById(ctx, req.Id) return } // Add 添加极光推送 func (c *userRegistrationController) Add(ctx context.Context, req *system.UserRegistrationAddReq) (res *system.UserRegistrationAddRes, err error) { err = service.UserRegistration().Add(ctx, req) return } // Edit 修改极光推送 func (c *userRegistrationController) Edit(ctx context.Context, req *system.UserRegistrationEditReq) (res *system.UserRegistrationEditRes, err error) { err = service.UserRegistration().Edit(ctx, req) return } // Delete 删除极光推送 func (c *userRegistrationController) Delete(ctx context.Context, req *system.UserRegistrationDeleteReq) (res *system.UserRegistrationDeleteRes, err error) { err = service.UserRegistration().Delete(ctx, req.Ids) return } // 为当前用户设备绑定极光推送 func (c *userRegistrationController) BindRegistration(ctx context.Context, req *system.UserRegistrationRegisterReq) (res *system.UserRegistrationRegisterRes, err error) { // 获取用户信息 userInfo := ct.New().GetLoginUser(ctx) if userInfo == nil { return nil, errors.New("用户未登录") } // 极光推送设备唯一标识 registrationID := req.RegistrationId // sys_user 表中的用户 ID userID := int(userInfo.Id) openID := userInfo.OpenId // 如果用户已经绑定过了则更新,否则添加 if service.UserRegistration().IsBind(ctx, userID) { _, err = dao.UserRegistration.Ctx(ctx).Data(dao.UserRegistration.Columns().RegistrationId, registrationID). Where(dao.UserRegistration.Columns().UserId, userID).Update() } else { err = service.UserRegistration().Add(ctx, &system.UserRegistrationAddReq{ UserId: userID, OpenId: openID, RegistrationId: registrationID, }) } return }