login.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package handlers
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "shopperthree_manage_v2/app/business"
  5. "shopperthree_manage_v2/app/models"
  6. "shopperthree_manage_v2/logger"
  7. "shopperthree_manage_v2/pkg/ierr"
  8. )
  9. /**
  10. * showdoc
  11. * @catalog 登录
  12. * @title 登录接口
  13. * @description 登录接口
  14. * @method POST
  15. * @url ~/v1/login
  16. * @param phone 必选 string 手机号码
  17. * @param password 必选 string 密码
  18. * @return {"code":0,"data":{"user_id":"3543","phone":"18522905678","token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiIzNTQzIiwiUGhvbmUiOiIxODUyMjkwNTY3OCIsIkV4cGlyZSI6MTU5OTc1MDE1OSwiUm9sZSI6Mn0.yzhKxq4CAYG-YdRIZOj83Buupp2WsooS4K4iAgCFnT0","role":2}}
  19. * @return_param user_id string 用户id
  20. * @return_param phone string 手机号码
  21. * @return_param token string 后面要用的token
  22. * @return_param role int 角色(1商户2管理员)
  23. * @remark (请求需要在header上面带上token,如果是商户key为merchant_token,如果是管理员key为admin_token)
  24. * @number 2
  25. */
  26. func Login(c *gin.Context) {
  27. var req models.LoginRequest
  28. if err := c.ShouldBind(&req); err != nil {
  29. logger.Error("Login bind err",
  30. logger.Err(err),
  31. logger.Any("req", req),
  32. )
  33. ResponseErr(c, ierr.NewIError(ierr.ParamErr, err.Error()))
  34. return
  35. }
  36. reply, err := business.Login(&req)
  37. if err != nil {
  38. logger.Error("Login err",
  39. logger.Err(err),
  40. logger.Any("req", req),
  41. )
  42. ResponseErr(c, err)
  43. return
  44. }
  45. ResponseSuccess(c, reply)
  46. }