getuserlogic.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package logic
  2. import (
  3. "context"
  4. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  5. "git.i2edu.net/i2/i2-bill-api/internal/types"
  6. "git.i2edu.net/i2/i2-bill-api/model"
  7. "git.i2edu.net/i2/i2-bill-erp/transform"
  8. "git.i2edu.net/i2/go-zero/core/logx"
  9. )
  10. type GetUserLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. UserId int64
  15. SessionKey string
  16. }
  17. func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetUserLogic {
  18. return GetUserLogic{
  19. Logger: logx.WithContext(ctx),
  20. ctx: ctx,
  21. svcCtx: svcCtx,
  22. }
  23. }
  24. func (l *GetUserLogic) GetUser() (*types.InfoResponse, error) {
  25. var user model.User
  26. err := l.svcCtx.SqlConn.QueryRowPartial(&user, "select id, erp_id, avatar, birthday, username, nickname, gender, mobile from user where `id` = ? limit 1", l.UserId)
  27. if err != nil {
  28. logx.Error(err)
  29. return nil, err
  30. }
  31. // 每次都去查找, 暂时没有绑定
  32. // resp, err := l.svcCtx.Transformer.GetUser(l.ctx, &transform.UserRequest{Id: user.ErpId, Phone: user.Mobile})
  33. resp, err := l.svcCtx.Transformer.GetUser(l.ctx, &transform.UserRequest{Phone: user.Mobile})
  34. if err != nil {
  35. logx.Error(err)
  36. return nil, err
  37. }
  38. info := &types.InfoResponse{}
  39. info.ID = user.Id
  40. info.Avatar = user.Avatar
  41. info.Birthday = user.Birthday
  42. info.UserName = user.Username
  43. info.NickName = user.Nickname
  44. info.Gender = user.Gender
  45. info.ErpRoleType = resp.ErpRoleType
  46. return info, nil
  47. }