getuserlogic.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. resp, err := l.svcCtx.Transformer.GetUser(l.ctx, &transform.UserRequest{Id: user.ErpId, Phone: user.Mobile})
  32. if err != nil {
  33. logx.Error(err)
  34. return nil, err
  35. }
  36. info := &types.InfoResponse{}
  37. info.ID = user.Id
  38. info.Avatar = user.Avatar
  39. info.Birthday = user.Birthday
  40. info.UserName = user.Username
  41. info.NickName = user.Nickname
  42. info.Gender = user.Gender
  43. info.IsJzMem = resp.IsJzMem
  44. info.IsJzMk = resp.IsJzMk
  45. return info, nil
  46. }