user.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package user
  2. import (
  3. "mtp2_if/db"
  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 string `form:"userID" binding:"required"`
  14. }
  15. // QueryUserReferNum 获取用户邀请码
  16. // @Summary 获取用户邀请码
  17. // @Produce json
  18. // @Param userID query string 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. // 查询数据
  33. engine := db.GetEngine()
  34. var userAccount models.Useraccount
  35. _, err := engine.Where("USERID = ?", req.UserID).Get(&userAccount)
  36. if 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().Infof("QueryUserReferNum successed: %v", userAccount.Refernum)
  44. appG.Response(http.StatusOK, e.SUCCESS, userAccount.Refernum)
  45. }
  46. // QueryUserInfoReq 获取用户信息请求参数
  47. type QueryUserInfoReq struct {
  48. UserID string `form:"userID" binding:"required"`
  49. }
  50. // QueryUserInfo 获取用户信息
  51. // @Summary 获取用户信息
  52. // @Produce json
  53. // @Security ApiKeyAuth
  54. // @Param userID query string true "用户ID"
  55. // @Success 200 {object} models.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. engine := db.GetEngine()
  70. var data models.Userinfo
  71. _, err := engine.Where("USERID = ?", req.UserID).Get(&data)
  72. if err != nil {
  73. // 查询失败
  74. logger.GetLogger().Errorf("QueryUserInfo failed: %s", err.Error())
  75. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  76. return
  77. }
  78. // 查询成功
  79. logger.GetLogger().Infof("QueryUserInfo successed: %v", data)
  80. appG.Response(http.StatusOK, e.SUCCESS, data)
  81. }
  82. // GetUserAuthStatusReq 获取用户实名认证状态请求参数
  83. type GetUserAuthStatusReq struct {
  84. UserID int `form:"userID" binding:"required"` // 用户ID
  85. }
  86. // GetUserAuthStatus 获取用户实名认证状态
  87. // @Summary 获取用户实名认证状态
  88. // @Produce json
  89. // @Security ApiKeyAuth
  90. // @Param userID query int true "用户ID"
  91. // @Success 200 {bool} app.Response
  92. // @Failure 500 {object} app.Response
  93. // @Router /User/GetUserAuthStatus [get]
  94. // @Tags 用户信息
  95. func GetUserAuthStatus(c *gin.Context) {
  96. appG := app.Gin{C: c}
  97. // 获取请求参数
  98. var req GetUserAuthStatusReq
  99. if err := appG.C.ShouldBindQuery(&req); err != nil {
  100. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  101. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  102. return
  103. }
  104. isAuth := false
  105. var userAccount models.Useraccount
  106. engine := db.GetEngine()
  107. has, err := engine.Where("USERID = ?", req.UserID).Get(&userAccount)
  108. if err != nil {
  109. // 获取行情报价牌分类菜单
  110. logger.GetLogger().Errorf("GetUserAuthStatus failed: %s", err.Error())
  111. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_QUOTEMENU_FAIL, nil)
  112. return
  113. }
  114. if has {
  115. if userAccount.Hasauth == 1 {
  116. isAuth = true
  117. }
  118. }
  119. // 查询成功
  120. logger.GetLogger().Infof("GetUserAuthStatus successed: %v", isAuth)
  121. appG.Response(http.StatusOK, e.SUCCESS, isAuth)
  122. }