login.go 1.7 KB

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