package user import ( "fmt" "mtp2_if/db" "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 // @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() var loginaccount models.Loginaccount loginid := req.UserName // 如果找不到,则直接把登录代码返回去 has, err := engine.Where("Logincode = ?", req.UserName).Get(&loginaccount) if err != nil { // 查询失败 logger.GetLogger().Errorf("GetLoginID failed: %s", err.Error()) appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil) return } if has { loginid = fmt.Sprintf("%v", loginaccount.Loginid) } // 查询成功 logger.GetLogger().Infof("GetLoginID successed: %v", loginaccount) appG.Response(http.StatusOK, e.SUCCESS, loginid) }