user.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package user
  2. import (
  3. "mtp2_if/dbmodels"
  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. // QueryUserReferNumReq 获取用户邀请码请求参数
  12. type QueryUserReferNumReq struct {
  13. UserID int `form:"userID" binding:"required"`
  14. }
  15. // QueryUserReferNum 获取用户邀请码
  16. // @Summary 获取用户邀请码
  17. // @Produce json
  18. // @Param userID query int true "用户ID"
  19. // @Success 200 {object} app.Response
  20. // @Failure 500 {object} app.Response
  21. // @Router /User/QueryUserReferNum [get]
  22. // @Tags 用户信息
  23. func QueryUserReferNum(c *gin.Context) {
  24. appG := app.Gin{C: c}
  25. // 获取请求参数
  26. var req QueryUserReferNumReq
  27. if err := appG.C.ShouldBindQuery(&req); err != nil {
  28. logger.GetLogger().Errorf("QueryUserReferNum failed: %s", err.Error())
  29. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  30. return
  31. }
  32. var (
  33. userAccount *dbmodels.Useraccount
  34. err error
  35. )
  36. if userAccount, err = models.GetUserAccount(req.UserID); err != nil {
  37. // 查询失败
  38. logger.GetLogger().Errorf("QueryUserReferNum failed: %s", err.Error())
  39. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  40. return
  41. }
  42. // 查询成功
  43. logger.GetLogger().Debugln("QueryUserReferNum successed: %v", userAccount.Refernum)
  44. appG.Response(http.StatusOK, e.SUCCESS, userAccount.Refernum)
  45. }
  46. // QueryUserInfoReq 获取用户信息请求参数
  47. type QueryUserInfoReq struct {
  48. UserID int `form:"userID" binding:"required"`
  49. }
  50. // QueryUserInfo 获取用户信息
  51. // @Summary 获取用户信息
  52. // @Produce json
  53. // @Security ApiKeyAuth
  54. // @Param userID query int true "用户ID"
  55. // @Success 200 {object} dbmodels.Userinfo
  56. // @Failure 500 {object} app.Response
  57. // @Router /User/QueryUserInfo [get]
  58. // @Tags 用户信息
  59. func QueryUserInfo(c *gin.Context) {
  60. appG := app.Gin{C: c}
  61. // 获取请求参数
  62. var req QueryUserReferNumReq
  63. if err := appG.C.ShouldBindQuery(&req); err != nil {
  64. logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
  65. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  66. return
  67. }
  68. // 查询数据
  69. var (
  70. data *dbmodels.Userinfo
  71. err error
  72. )
  73. if data, err = models.GetUserInfo(req.UserID); err != nil {
  74. // 查询失败
  75. logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
  76. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  77. return
  78. }
  79. // 查询成功
  80. logger.GetLogger().Debugln("QueryUserInfo successed: %v", data)
  81. appG.Response(http.StatusOK, e.SUCCESS, data)
  82. }
  83. // GetUserAuthStatusReq 获取用户实名认证状态请求参数
  84. type GetUserAuthStatusReq struct {
  85. UserID int `form:"userID" binding:"required"` // 用户ID
  86. }
  87. // GetUserAuthStatus 获取用户实名认证状态
  88. // @Summary 获取用户实名认证状态
  89. // @Produce json
  90. // @Security ApiKeyAuth
  91. // @Param userID query int true "用户ID"
  92. // @Success 200 {bool} app.Response
  93. // @Failure 500 {object} app.Response
  94. // @Router /User/GetUserAuthStatus [get]
  95. // @Tags 用户信息
  96. func GetUserAuthStatus(c *gin.Context) {
  97. appG := app.Gin{C: c}
  98. // 获取请求参数
  99. var req GetUserAuthStatusReq
  100. if err := appG.C.ShouldBindQuery(&req); err != nil {
  101. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  102. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  103. return
  104. }
  105. isAuth := false
  106. var (
  107. userAccount *dbmodels.Useraccount
  108. err error
  109. )
  110. if userAccount, err = models.GetUserAccount(req.UserID); err != nil {
  111. // 查询失败
  112. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  113. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  114. return
  115. }
  116. if userAccount != nil {
  117. if userAccount.Hasauth == 1 {
  118. isAuth = true
  119. }
  120. }
  121. // 查询成功
  122. logger.GetLogger().Debugln("GetUserAuthStatus successed: %v", isAuth)
  123. appG.Response(http.StatusOK, e.SUCCESS, isAuth)
  124. }