新增获取解密手机号
This commit is contained in:
parent
43d5023b80
commit
c004eb7c2a
@ -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)
|
||||
}
|
||||
|
||||
@ -4,7 +4,8 @@ package controller
|
||||
type Api struct {
|
||||
sysSetting // 系统设置
|
||||
userDoctorManage // 医生管理
|
||||
Admin // 公共方法
|
||||
Admin // 公共方法-验证权限
|
||||
Public // 公共方法-不验证权限
|
||||
basic // 基础数据
|
||||
order // 订单管理
|
||||
userPatientManage // 患者管理
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user