| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package user
- import (
- "encoding/hex"
- "fmt"
- "mtp2_if/db"
- "mtp2_if/global/app"
- "mtp2_if/global/e"
- "mtp2_if/global/utils"
- "mtp2_if/logger"
- "mtp2_if/models"
- "net/http"
- "github.com/gin-gonic/gin"
- )
- // GetLoginIDReq 获取登录ID请求参数
- type GetLoginIDReq struct {
- UserName string `form:"username" binding:"required"`
- }
- // GetLoginID 获取登录ID
- // @Summary 获取登录ID
- // @Description UserName 可传入“登录账号”、“登录代码”和“手机号码”
- // @Produce json
- // @Param username query string true "登录代码"
- // @Success 200 {object} app.Response
- // @Failure 500 {object} app.Response
- // @Router /User/GetLoginID [get]
- // @Tags 用户信息
- func GetLoginID(c *gin.Context) {
- appG := app.Gin{C: c}
- // 获取请求参数
- var req GetLoginIDReq
- if err := appG.C.ShouldBindQuery(&req); err != nil {
- logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- engine := db.GetEngine()
- loginid := req.UserName // 如果找不到,则直接把登录代码返回去
- // 通过登录代码查询登录账号
- var loginaccount models.Loginaccount
- has, _ := engine.Where("Logincode = ?", req.UserName).Get(&loginaccount)
- if has {
- loginid = fmt.Sprintf("%v", loginaccount.Loginid)
- } else {
- // 通过手机号码查询登录账号
- // 手机号码需要AES加密
- key, _ := hex.DecodeString(utils.AESSecretKey)
- if mobileEncrypted, err := utils.AESEncrypt([]byte(req.UserName), key); err == nil {
- // 加密成功后进行查询
- has, _ := engine.Join("INNER", "USERINFO", "USERINFO.USERID = LOGINACCOUNT.USERID").
- Where("USERINFO.MOBILE = ?", hex.EncodeToString(mobileEncrypted)).Get(&loginaccount)
- if has {
- loginid = fmt.Sprintf("%v", loginaccount.Loginid)
- }
- }
- }
- // 查询成功
- logger.GetLogger().Infof("GetLoginID successed: %v", loginaccount)
- appG.Response(http.StatusOK, e.SUCCESS, loginid)
- }
|