demo.go 890 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package user
  2. import (
  3. "app/commons/constant"
  4. "app/commons/core"
  5. "fmt"
  6. "github.com/gin-gonic/gin"
  7. )
  8. func (s *Server) Info(ctx *gin.Context) {
  9. c := s.FromContext(ctx)
  10. c.Resp(map[string]interface{}{
  11. "uid": c.Uid(),
  12. "userId": c.UserId(),
  13. "openId": c.OpenId(),
  14. })
  15. }
  16. func (s *Server) SetParent(ctx *gin.Context) {
  17. c := s.FromContext(ctx)
  18. type UserReq struct {
  19. Code *string `json:"code"`
  20. }
  21. req := new(UserReq)
  22. if err := c.ShouldBindJSON(&req); err != nil {
  23. c.Resp(constant.ErrorParams)
  24. return
  25. }
  26. core.Log.Infof("req:%v", req.Code)
  27. user, err := s.GetUserByUserId(c.UserId())
  28. if err != nil {
  29. c.Resp(constant.ErrorParams)
  30. return
  31. }
  32. dbTx := s.DB().Begin()
  33. err = s.CreateUserRelationActionLog(dbTx, user, fmt.Sprintf("SetParentByUser:%s", c.Uid()), "", req.Code)
  34. if err != nil {
  35. dbTx.Rollback()
  36. c.Resp(err.Error())
  37. return
  38. }
  39. dbTx.Commit()
  40. c.Resp(nil)
  41. }