get_user_logic.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package user
  2. import (
  3. "context"
  4. "fmt"
  5. "git.i2edu.net/i2/i2-bill-api/internal/svc"
  6. "git.i2edu.net/i2/i2-bill-api/internal/types"
  7. "git.i2edu.net/i2/i2-bill-api/model"
  8. "git.i2edu.net/i2/i2-bill-erp/transform"
  9. "strings"
  10. "git.i2edu.net/i2/go-zero/core/logx"
  11. )
  12. type GetUserLogic struct {
  13. logx.Logger
  14. ctx context.Context
  15. svcCtx *svc.ServiceContext
  16. UserId int64
  17. SessionKey string
  18. }
  19. func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetUserLogic {
  20. return GetUserLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *GetUserLogic) GetUser() (*types.InfoResponse, error) {
  27. var user model.User
  28. info := &types.InfoResponse{}
  29. 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)
  30. if err != nil {
  31. logx.Error(err)
  32. return nil, err
  33. }
  34. // 每次都去查找, 暂时没有绑定 erp mk
  35. // resp, err := l.svcCtx.Transformer.GetUser(l.ctx, &transform.UserRequest{Id: user.ErpId, Phone: user.Mobile})
  36. resp, err := l.svcCtx.Transformer.GetUser(l.ctx, &transform.UserRequest{Phone: user.Mobile})
  37. if err != nil {
  38. logx.Error(err)
  39. return nil, err
  40. }
  41. if resp.ErpRoleType != 1 {
  42. //是不是 兼职
  43. 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()
  44. if err != nil {
  45. logx.Error(err)
  46. return nil, err
  47. }
  48. if len(res) > 0 {
  49. //兼职信息
  50. resp.UserName, _ = res[0]["name"].(string)
  51. cityId, _ := res[0]["city_id"].(int64)
  52. cityNodes, err := l.svcCtx.GetErpCity()
  53. if err != nil {
  54. logx.Error(err)
  55. return nil, err
  56. }
  57. for _, node := range cityNodes {
  58. if node.Id == cityId {
  59. resp.CityName = node.Text
  60. break
  61. }
  62. }
  63. resp.Gender = res[0]["sex"].(int64)
  64. resp.ErpRoleType = 2
  65. } else {
  66. resp.ErpRoleType = 0
  67. }
  68. }
  69. if !strings.HasPrefix(user.Avatar, "http") && user.Avatar != "" {
  70. domain := strings.TrimRight(l.svcCtx.Config.AliYunOss.FileUrl, "/")
  71. filePath := strings.TrimLeft(user.Avatar, "/")
  72. user.Avatar = fmt.Sprintf("%s/%s", domain, filePath)
  73. }
  74. info.ID = user.Id
  75. info.Avatar = user.Avatar
  76. info.Birthday = user.Birthday
  77. info.NickName = user.Nickname
  78. info.Mobile = user.Mobile
  79. info.UserName = resp.UserName
  80. info.Gender = resp.Gender
  81. info.CityName = resp.CityName
  82. info.ErpRoleType = resp.ErpRoleType
  83. return info, nil
  84. }