talent.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package db
  2. import (
  3. "context"
  4. "github.com/caixw/lib.go/conv"
  5. "github.com/sirupsen/logrus"
  6. "gorm.io/gorm"
  7. "youngee_m_api/model/gorm_model"
  8. "youngee_m_api/model/http_model"
  9. "youngee_m_api/pack"
  10. )
  11. func PlatformAccInfo(ctx context.Context, talentId string) (*http_model.PlatformAccInfoPreView, error) {
  12. db := GetReadDB(ctx)
  13. var gormPlatform []*gorm_model.YoungeePlatformAccountInfo
  14. // 根据 talent_id 进行筛选
  15. db = db.Debug().Model(gorm_model.YoungeePlatformAccountInfo{}).Where("talent_id = ?", talentId)
  16. err := db.Find(&gormPlatform).Order("bind_date").Error
  17. if err != nil {
  18. if err == gorm.ErrRecordNotFound {
  19. return nil, nil
  20. } else {
  21. return nil, err
  22. }
  23. }
  24. // 查询总数
  25. var total int64
  26. if err = db.Count(&total).Error; err != nil {
  27. logrus.WithContext(ctx).Errorf("[PlatformAccInfo] error query mysql total, err:%+v", err)
  28. return nil, err
  29. }
  30. platform := new(http_model.PlatformAccInfoPreView)
  31. platform.PlatformAccInfoData = pack.GormPlatformToHttpPlatform(gormPlatform)
  32. platform.Total = conv.MustString(total, "")
  33. return platform, err
  34. }
  35. func AccountIncome(ctx context.Context, talentId string) (*http_model.TalentInfoResponse, error) {
  36. db := GetReadDB(ctx)
  37. var talentInfo *gorm_model.YoungeeTalentInfo
  38. // 根据 talent_id 进行筛选
  39. err := db.Debug().Model(gorm_model.YoungeeTalentInfo{}).Where("id = ?", talentId).
  40. First(&talentInfo).Error
  41. if err != nil {
  42. if err == gorm.ErrRecordNotFound {
  43. return nil, nil
  44. } else {
  45. return nil, err
  46. }
  47. }
  48. data := new(http_model.TalentInfoResponse)
  49. data.Income = talentInfo.Income
  50. data.Withdrawed = talentInfo.Withdrawed
  51. data.Canwithdraw = talentInfo.Canwithdraw
  52. data.Withdrawing = talentInfo.Withdrawing
  53. // 查询是否绑定物流地址
  54. IsBindLocation := talentInfo.IsBindLocation
  55. if IsBindLocation == 1 {
  56. var deliveryInfo *gorm_model.YoungeeTalentDeliveryAddress
  57. db1 := GetReadDB(ctx)
  58. err = db1.Debug().Model(gorm_model.YoungeeTalentDeliveryAddress{}).
  59. Where("talent_id = ? AND default_tag = ?", talentId, 1).
  60. First(&deliveryInfo).Error
  61. if err != nil {
  62. if err == gorm.ErrRecordNotFound {
  63. return nil, nil
  64. } else {
  65. return nil, err
  66. }
  67. }
  68. data.ReceiverName = deliveryInfo.ReceiverName
  69. data.PhoneNumber = deliveryInfo.PhoneNumber
  70. data.DetailAddr = deliveryInfo.DetailAddr
  71. }
  72. return data, err
  73. }