From c004eb7c2ab62075096f719655fa18c5014e51d2 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Tue, 19 Sep 2023 09:39:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96=E8=A7=A3?= =?UTF-8?q?=E5=AF=86=E6=89=8B=E6=9C=BA=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/admin.go | 87 +++++++++++++++++----------------------- api/controller/base.go | 3 +- api/controller/public.go | 59 +++++++++++++++++++++++++++ api/requests/admin.go | 7 ++++ api/router/router.go | 7 +++- api/service/User.go | 27 +++++++++++++ 6 files changed, 137 insertions(+), 53 deletions(-) diff --git a/api/controller/admin.go b/api/controller/admin.go index 5e1ad3e..1073f46 100644 --- a/api/controller/admin.go +++ b/api/controller/admin.go @@ -5,7 +5,6 @@ import ( "hospital-admin-api/api/requests" "hospital-admin-api/api/responses" "hospital-admin-api/api/service" - "hospital-admin-api/config" "hospital-admin-api/global" "hospital-admin-api/utils" "strconv" @@ -13,55 +12,6 @@ import ( type Admin struct{} -// GetCaptcha 获取验证码 -func (b *Admin) GetCaptcha(c *gin.Context) { - id, b64s, err := utils.GenerateCaptcha() - if err != nil { - responses.FailWithMessage("验证码获取失败", c) - } - - responses.OkWithData(gin.H{ - "id": id, - "b64s": b64s, - }, c) -} - -// Login 登陆 -func (b *Admin) Login(c *gin.Context) { - var adminRequest requests.AdminRequest - - if err := c.ShouldBind(&adminRequest.Login); err != nil { - responses.FailWithMessage(err.Error(), c) - return - } - - // 参数验证 - if err := global.Validate.Struct(adminRequest.Login); err != nil { - responses.FailWithMessage(utils.Translate(err), c) - return - } - - // 验证验证码 - if config.C.Env == "prod" { - isValid := utils.VerifyCaptcha(adminRequest.Login) - if !isValid { - // 验证码错误 - responses.FailWithMessage("验证码错误", c) - return - } - } - - // 登陆 - adminService := service.AdminService{} - token, err := adminService.Login(adminRequest.Login) - if err != nil { - responses.FailWithMessage(err.Error(), c) - return - } - - responses.OkWithData(token, c) -} - // GetOssSign 获取oss签名 func (b *Admin) GetOssSign(c *gin.Context) { var adminRequest requests.AdminRequest @@ -161,3 +111,40 @@ func (b *Admin) GetDecryptOrderProductConsignee(c *gin.Context) { OrderProductConsignee, _ := orderProductService.GetOrderProductConsignee(orderProductId) responses.OkWithData(OrderProductConsignee, c) } + +// GetDecryptMobile 获取解密手机号 +func (b *Admin) GetDecryptMobile(c *gin.Context) { + var adminRequest requests.AdminRequest + + if err := c.ShouldBind(&adminRequest.GetDecryptMobile); err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 参数验证 + if err := global.Validate.Struct(adminRequest.GetDecryptMobile); err != nil { + responses.FailWithMessage(utils.Translate(err), c) + return + } + + // 将 id 转换为 int64 类型 + userId, err := strconv.ParseInt(adminRequest.GetDecryptMobile.UserId, 10, 64) + if err != nil { + responses.Fail(c) + return + } + + var familyId int64 + if adminRequest.GetDecryptMobile.FamilyId != "" { + familyId, err = strconv.ParseInt(adminRequest.GetDecryptMobile.FamilyId, 10, 64) + if err != nil { + responses.Fail(c) + return + } + } + + // 获取用户身份证号 + userService := service.UserService{} + userMobile, _ := userService.GetUserMobile(userId, familyId) + responses.OkWithData(userMobile, c) +} diff --git a/api/controller/base.go b/api/controller/base.go index 369b172..ef444af 100644 --- a/api/controller/base.go +++ b/api/controller/base.go @@ -4,7 +4,8 @@ package controller type Api struct { sysSetting // 系统设置 userDoctorManage // 医生管理 - Admin // 公共方法 + Admin // 公共方法-验证权限 + Public // 公共方法-不验证权限 basic // 基础数据 order // 订单管理 userPatientManage // 患者管理 diff --git a/api/controller/public.go b/api/controller/public.go index 85a5d6d..8627851 100644 --- a/api/controller/public.go +++ b/api/controller/public.go @@ -1,3 +1,62 @@ package controller +import ( + "github.com/gin-gonic/gin" + "hospital-admin-api/api/requests" + "hospital-admin-api/api/responses" + "hospital-admin-api/api/service" + "hospital-admin-api/config" + "hospital-admin-api/global" + "hospital-admin-api/utils" +) + type Public struct{} + +// GetCaptcha 获取验证码 +func (b *Public) GetCaptcha(c *gin.Context) { + id, b64s, err := utils.GenerateCaptcha() + if err != nil { + responses.FailWithMessage("验证码获取失败", c) + } + + responses.OkWithData(gin.H{ + "id": id, + "b64s": b64s, + }, c) +} + +// Login 登陆 +func (b *Public) Login(c *gin.Context) { + var adminRequest requests.AdminRequest + + if err := c.ShouldBind(&adminRequest.Login); err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + // 参数验证 + if err := global.Validate.Struct(adminRequest.Login); err != nil { + responses.FailWithMessage(utils.Translate(err), c) + return + } + + // 验证验证码 + if config.C.Env == "prod" { + isValid := utils.VerifyCaptcha(adminRequest.Login) + if !isValid { + // 验证码错误 + responses.FailWithMessage("验证码错误", c) + return + } + } + + // 登陆 + adminService := service.AdminService{} + token, err := adminService.Login(adminRequest.Login) + if err != nil { + responses.FailWithMessage(err.Error(), c) + return + } + + responses.OkWithData(token, c) +} diff --git a/api/requests/admin.go b/api/requests/admin.go index 408f88a..c294540 100644 --- a/api/requests/admin.go +++ b/api/requests/admin.go @@ -4,6 +4,7 @@ type AdminRequest struct { Login // 登陆 GetOssSign // 获取医生列表-分页 GetDecryptCardNum // 获取用户身份证号 + GetDecryptMobile // 获取用户手机号 } // Login 登陆 @@ -25,3 +26,9 @@ type GetDecryptCardNum struct { FamilyId string `json:"family_id" form:"family_id" label:"家庭成员"` // 家庭成员id UserId string `json:"user_id" form:"user_id" validate:"required" label:"用户"` // 用户id } + +// GetDecryptMobile 获取用户手机号 +type GetDecryptMobile struct { + FamilyId string `json:"family_id" form:"family_id" label:"家庭成员"` // 家庭成员id + UserId string `json:"user_id" form:"user_id" validate:"required" label:"用户"` // 用户id +} diff --git a/api/router/router.go b/api/router/router.go index 03eefa5..9125553 100644 --- a/api/router/router.go +++ b/api/router/router.go @@ -74,10 +74,10 @@ func Init() *gin.Engine { func publicRouter(r *gin.Engine, api controller.Api) { adminGroup := r.Group("/admin") // 验证码 - adminGroup.GET("/captcha", api.Admin.GetCaptcha) + adminGroup.GET("/captcha", api.Public.GetCaptcha) // 登陆 - adminGroup.POST("/login", api.Admin.Login) + adminGroup.POST("/login", api.Public.Login) } // adminRouter 公共路由-验证权限 @@ -103,6 +103,9 @@ func adminRouter(r *gin.Engine, api controller.Api) { // 解密药品订单收货人数据 decryptGroup.GET("/order/product/consignee/:order_product_id", api.Admin.GetDecryptOrderProductConsignee) + + // 解密手机号 + decryptGroup.GET("/mobile", api.Admin.GetDecryptMobile) } } diff --git a/api/service/User.go b/api/service/User.go index 8dba18a..bfdf1d7 100644 --- a/api/service/User.go +++ b/api/service/User.go @@ -61,3 +61,30 @@ func (r *UserService) GetUserBankNumByDoctorId(doctorId int64) (string, error) { return doctorBankCard.BankCardCode, nil } + +// GetUserMobile 获取用户手机号 +func (r *UserService) GetUserMobile(userId, familyId int64) (string, error) { + var mobile string + + // 获取用户数据 + userDao := dao.UserDao{} + user, err := userDao.GetUserById(userId) + if err != nil || user == nil { + return "", errors.New("用户错误") + } + + mobile = user.Mobile + + if familyId != 0 { + // 存在家庭成员 + patientFamilyDao := dao.PatientFamilyDao{} + patientFamily, err := patientFamilyDao.GetPatientFamilyById(familyId) + if err != nil || patientFamily == nil { + return "", errors.New("获取失败") + } + + mobile = patientFamily.Mobile + } + + return mobile, nil +}