getuserlogic.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package user
  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 i2bill_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.NickName = user.Nickname
  43. info.Mobile = user.Mobile
  44. info.UserName = resp.UserName
  45. info.Gender = resp.Gender
  46. info.CityName = resp.CityName
  47. info.ErpRoleType = resp.ErpRoleType
  48. return info, nil
  49. }