| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package user
- import (
- "fmt"
- "mtp2_if/global/app"
- "mtp2_if/global/e"
- "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("GetLoginID failed: %s", err.Error())
- appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
- return
- }
- // 通过登录代码查询登录账号
- if loginaccount, _ := models.GetLoginAccountByLoginCode(req.UserName); loginaccount != nil {
- appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
- return
- }
- // 通过LoginAccount表手机号码查询登录账号
- if loginaccount, _ := models.GetLoginAccount2(req.UserName); loginaccount != nil {
- appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
- return
- }
- // 通过UserInfo表手机号码查询登录账号
- if loginaccount, _ := models.GetLoginAccountByMobile(req.UserName); loginaccount != nil {
- appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
- return
- }
- // 找不到或查询错误,都把请求代码返回去
- appG.Response(http.StatusOK, e.SUCCESS, req.UserName)
- }
|