login.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * @Author: deng.yinping deng.yinping@muchinfo.cn
  3. * @Date: 2024-02-22 11:11:03
  4. * @LastEditors: deng.yinping deng.yinping@muchinfo.cn
  5. * @LastEditTime: 2024-04-17 14:52:08
  6. * @FilePath: \MTP20_IF\controllers\user\login.go
  7. * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  8. */
  9. package user
  10. import (
  11. "fmt"
  12. "mtp2_if/global/app"
  13. "mtp2_if/global/e"
  14. "mtp2_if/logger"
  15. "mtp2_if/models"
  16. "net/http"
  17. "github.com/gin-gonic/gin"
  18. )
  19. // GetLoginIDReq 获取登录ID请求参数
  20. type GetLoginIDReq struct {
  21. UserName string `form:"username" binding:"required"`
  22. }
  23. // GetLoginID 获取登录ID
  24. // @Summary 获取登录ID
  25. // @Description UserName 可传入“登录账号”、“登录代码”和“手机号码”
  26. // @Produce json
  27. // @Param username query string true "登录代码"
  28. // @Success 200 {object} app.Response
  29. // @Failure 500 {object} app.Response
  30. // @Router /User/GetLoginID [get]
  31. // @Tags 用户信息
  32. func GetLoginID(c *gin.Context) {
  33. appG := app.Gin{C: c}
  34. // 获取请求参数
  35. var req GetLoginIDReq
  36. if err := appG.C.ShouldBindQuery(&req); err != nil {
  37. logger.GetLogger().Errorf("GetLoginID failed: %s", err.Error())
  38. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  39. return
  40. }
  41. // 通过登录代码查询登录账号
  42. if loginaccount, _ := models.GetLoginAccountByLoginCode(req.UserName); loginaccount != nil {
  43. appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
  44. return
  45. }
  46. // // 通过LoginAccount表手机号码查询登录账号
  47. // if loginaccount, _ := models.GetLoginAccount2(req.UserName); loginaccount != nil {
  48. // appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
  49. // return
  50. // }
  51. // // 通过UserInfo表手机号码查询登录账号
  52. // if loginaccount, _ := models.GetLoginAccountByMobile(req.UserName); loginaccount != nil {
  53. // appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
  54. // return
  55. // }
  56. // 根据登录账号与手机号绑定表获取登录账号(上面两个查询不正确 20240417)
  57. // GetLoginAccountByMobile2 通过手机号码查询登录账号信息(三方认证表 userauthinfo)
  58. if loginaccount, _ := models.GetLoginAccountByMobile2(req.UserName); loginaccount != nil {
  59. appG.Response(http.StatusOK, e.SUCCESS, fmt.Sprintf("%v", loginaccount.Loginid))
  60. return
  61. }
  62. // 找不到或查询错误,都把请求代码返回去
  63. appG.Response(http.StatusOK, e.SUCCESS, req.UserName)
  64. }