get_user_logic.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // 每次都去查找, 暂时没有绑定 erp mk
  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. if resp.ErpRoleType != 1 {
  39. //是不是 兼职
  40. res, err := l.svcCtx.DB.SQL("select * from i2bill_mkt_part_time_user where del_flag = 0 and user_id = ? and check_state = ?", l.UserId, 57).Query().List()
  41. if err != nil {
  42. logx.Error(err)
  43. return nil, err
  44. }
  45. if len(res) > 0 {
  46. resp.ErpRoleType = 2
  47. }
  48. }
  49. info := &types.InfoResponse{}
  50. info.ID = user.Id
  51. info.Avatar = user.Avatar
  52. info.Birthday = user.Birthday
  53. info.NickName = user.Nickname
  54. info.Mobile = user.Mobile
  55. info.UserName = resp.UserName
  56. info.Gender = resp.Gender
  57. info.CityName = resp.CityName
  58. info.ErpRoleType = resp.ErpRoleType
  59. return info, nil
  60. }