user.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package user
  2. import (
  3. "fmt"
  4. "mtp2_if/db"
  5. "mtp2_if/global/app"
  6. "mtp2_if/global/e"
  7. "mtp2_if/logger"
  8. "mtp2_if/models"
  9. "net/http"
  10. "github.com/gin-gonic/gin"
  11. )
  12. // QueryUserReferNumReq 获取用户邀请码请求参数
  13. type QueryUserReferNumReq struct {
  14. UserID string `form:"userID" binding:"required"`
  15. }
  16. // QueryUserReferNum 获取用户邀请码
  17. // @Summary 获取用户邀请码
  18. // @Produce json
  19. // @Security ApiKeyAuth
  20. // @Param username query string true "登录代码"
  21. // @Success 200 {object} app.Response
  22. // @Failure 500 {object} app.Response
  23. // @Router /User/QueryUserReferNum [get]
  24. // @Tags 用户信息
  25. func QueryUserReferNum(c *gin.Context) {
  26. appG := app.Gin{C: c}
  27. // 获取请求参数
  28. var req GetLoginIDReq
  29. if err := appG.C.ShouldBindQuery(&req); err != nil {
  30. logger.GetLogger().Errorf("QueryPreasleApply failed: %s", err.Error())
  31. appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
  32. return
  33. }
  34. // 查询数据
  35. engine := db.GetEngine()
  36. var loginaccount models.Loginaccount
  37. loginid := req.UserName // 如果找不到,则直接把登录代码返回去
  38. has, err := engine.Where("Logincode = ?", req.UserName).Get(&loginaccount)
  39. if err != nil {
  40. // 查询失败
  41. logger.GetLogger().Errorf("GetLoginID failed: %s", err.Error())
  42. appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
  43. return
  44. }
  45. if has {
  46. loginid = fmt.Sprintf("%v", loginaccount.Loginid)
  47. }
  48. // 查询成功
  49. logger.GetLogger().Infof("GetLoginID successed: %v", loginaccount)
  50. appG.Response(http.StatusOK, e.SUCCESS, loginid)
  51. }