login.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package user
  2. import (
  3. "mtp2_if/global/app"
  4. "mtp2_if/global/e"
  5. "mtp2_if/logger"
  6. "mtp2_if/models"
  7. "net/http"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // GetLoginIDReq 获取登录ID请求参数
  11. type GetLoginIDReq struct {
  12. UserName string `form:"username" binding:"required"`
  13. }
  14. // GetLoginID 获取登录ID
  15. // @Summary 获取登录ID
  16. // @Description UserName 可传入“登录账号”、“登录代码”和“手机号码”
  17. // @Produce json
  18. // @Param username query string true "登录代码"
  19. // @Success 200 {object} app.Response
  20. // @Failure 500 {object} app.Response
  21. // @Router /User/GetLoginID [get]
  22. // @Tags 用户信息
  23. func GetLoginID(c *gin.Context) {
  24. appG := app.Gin{C: c}
  25. // 获取请求参数
  26. var req GetLoginIDReq
  27. if err := appG.C.ShouldBindQuery(&req); err != nil {
  28. logger.GetLogger().Errorf("GetLoginID failed: %s", err.Error())
  29. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  30. return
  31. }
  32. // 通过登录代码查询登录账号
  33. if loginaccount, _ := models.GetLoginAccountByLoginCode(req.UserName); loginaccount != nil {
  34. appG.Response(http.StatusOK, e.SUCCESS, loginaccount.Loginid)
  35. return
  36. }
  37. // 通过手机号码查询登录账号
  38. if loginaccount, _ := models.GetLoginAccountByMobile(req.UserName); loginaccount != nil {
  39. appG.Response(http.StatusOK, e.SUCCESS, loginaccount.Loginid)
  40. return
  41. }
  42. // 找不到或查询错误,都把请求代码返回去
  43. appG.Response(http.StatusOK, e.SUCCESS, req.UserName)
  44. }