talent.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/consts"
  8. "youngee_m_api/model/gorm_model"
  9. "youngee_m_api/model/http_model"
  10. "youngee_m_api/pack"
  11. )
  12. func PlatformAccInfo(ctx context.Context, talentId string) (*http_model.PlatformAccInfoPreView, error) {
  13. db := GetReadDB(ctx)
  14. var gormPlatform []*gorm_model.YoungeePlatformAccountInfo
  15. // 根据 talent_id 进行筛选
  16. db = db.Debug().Model(gorm_model.YoungeePlatformAccountInfo{}).Where("talent_id = ?", talentId)
  17. err := db.Find(&gormPlatform).Order("bind_date").Error
  18. if err != nil {
  19. if err == gorm.ErrRecordNotFound {
  20. return nil, nil
  21. } else {
  22. return nil, err
  23. }
  24. }
  25. // 查询总数
  26. var total int64
  27. if err = db.Count(&total).Error; err != nil {
  28. logrus.WithContext(ctx).Errorf("[PlatformAccInfo] error query mysql total, err:%+v", err)
  29. return nil, err
  30. }
  31. platform := new(http_model.PlatformAccInfoPreView)
  32. platform.PlatformAccInfoData = pack.GormPlatformToHttpPlatform(gormPlatform)
  33. platform.Total = conv.MustString(total, "")
  34. return platform, err
  35. }
  36. func AccountIncome(ctx context.Context, talentId string) (*http_model.TalentInfoResponse, error) {
  37. db := GetReadDB(ctx)
  38. var talentInfo *gorm_model.YoungeeTalentInfo
  39. // 根据 talent_id 进行筛选
  40. err := db.Debug().Model(gorm_model.YoungeeTalentInfo{}).Where("id = ?", talentId).
  41. First(&talentInfo).Error
  42. if err != nil {
  43. if err == gorm.ErrRecordNotFound {
  44. return nil, nil
  45. } else {
  46. return nil, err
  47. }
  48. }
  49. data := new(http_model.TalentInfoResponse)
  50. data.Income = float32(talentInfo.Income)
  51. data.Withdrawed = float32(talentInfo.Withdrawed)
  52. data.Canwithdraw = float32(talentInfo.Canwithdraw)
  53. data.Withdrawing = float32(talentInfo.Withdrawing)
  54. // 查询是否绑定物流地址
  55. IsBindLocation := talentInfo.IsBindLocation
  56. if IsBindLocation == 1 {
  57. var deliveryInfo *gorm_model.YoungeeTalentDeliveryAddress
  58. db1 := GetReadDB(ctx)
  59. err = db1.Debug().Model(gorm_model.YoungeeTalentDeliveryAddress{}).
  60. Where("talent_id = ? AND default_tag = ?", talentId, 1).
  61. First(&deliveryInfo).Error
  62. if err != nil {
  63. if err == gorm.ErrRecordNotFound {
  64. return nil, nil
  65. } else {
  66. return nil, err
  67. }
  68. }
  69. region := GetRegion(ctx, deliveryInfo.RegionCode)
  70. data.ReceiverName = deliveryInfo.ReceiverName
  71. data.PhoneNumber = deliveryInfo.PhoneNumber
  72. data.DetailAddr = region + deliveryInfo.DetailAddr
  73. } else {
  74. data.ReceiverName = "暂未绑定物流地址"
  75. data.PhoneNumber = "暂未绑定物流地址"
  76. data.DetailAddr = "暂未绑定物流地址"
  77. }
  78. db2 := GetReadDB(ctx)
  79. var talentBankInfo *gorm_model.YounggeeTalentBank
  80. err = db2.Debug().Model(gorm_model.YounggeeTalentBank{}).Where("talent_id = ?", talentId).
  81. First(&talentBankInfo).Error
  82. if err != nil {
  83. if err == gorm.ErrRecordNotFound {
  84. return nil, nil
  85. } else {
  86. return nil, err
  87. }
  88. }
  89. db3 := GetReadDB(ctx)
  90. var infoBank *gorm_model.InfoBank
  91. db3.Debug().Model(gorm_model.InfoBank{}).Where("id = ?", talentBankInfo.BankID).First(&infoBank)
  92. db4 := GetReadDB(ctx)
  93. var infoRegion *gorm_model.InfoRegion
  94. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", talentBankInfo.BankOpenAddress).First(&infoRegion)
  95. provinceCode := conv.MustString(talentBankInfo.BankOpenAddress, "")[0:2] + "0000"
  96. var province *gorm_model.InfoRegion
  97. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(provinceCode, 0)).First(&province)
  98. cityCode := conv.MustString(talentBankInfo.BankOpenAddress, "")[0:4] + "00"
  99. var city *gorm_model.InfoRegion
  100. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(cityCode, 0)).First(&city)
  101. data.Bank = infoBank.Name
  102. data.BankOpenAddress = province.RegionName + city.RegionName + infoRegion.RegionName
  103. data.BankCardNumber = talentBankInfo.BankCardNumber
  104. data.Name = talentBankInfo.Name
  105. data.AliPayNumber = talentBankInfo.AlipayNumber
  106. data.AliPayRealName = talentBankInfo.AlipayRealName
  107. return data, err
  108. }
  109. func GetRegion(ctx context.Context, regionCode int) string {
  110. db4 := GetReadDB(ctx)
  111. var infoRegion *gorm_model.InfoRegion
  112. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", regionCode).First(&infoRegion)
  113. provinceCode := conv.MustString(regionCode, "")[0:2] + "0000"
  114. var province *gorm_model.InfoRegion
  115. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(provinceCode, 0)).First(&province)
  116. cityCode := conv.MustString(regionCode, "")[0:4] + "00"
  117. var city *gorm_model.InfoRegion
  118. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(cityCode, 0)).First(&city)
  119. return province.RegionName + city.RegionName + infoRegion.RegionName
  120. }
  121. func GetTaskRecord(ctx context.Context, talentId string) (*http_model.GetTaskRecordResponse, error) {
  122. db := GetReadDB(ctx)
  123. var taskInfos []*gorm_model.YoungeeTaskInfo
  124. // 根据 talent_id 进行筛选
  125. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("talent_id = ?", talentId)
  126. // 查询总数
  127. var total int64
  128. if err := db.Count(&total).Error; err != nil {
  129. logrus.WithContext(ctx).Errorf("[GetTaskRecord] error query mysql total, err:%+v", err)
  130. return nil, err
  131. }
  132. err := db.Order("update_at desc").Find(&taskInfos).Error
  133. if err != nil {
  134. if err == gorm.ErrRecordNotFound {
  135. return nil, nil
  136. } else {
  137. return nil, err
  138. }
  139. }
  140. projectIdMap := map[int]gorm_model.ProjectInfo{}
  141. for _, taskInfo := range taskInfos {
  142. if _, ok := projectIdMap[taskInfo.ProjectId]; !ok {
  143. db1 := GetReadDB(ctx)
  144. projectInfo := gorm_model.ProjectInfo{}
  145. db1.Where("project_id = ?", taskInfo.ProjectId).First(&projectInfo)
  146. projectIdMap[taskInfo.ProjectId] = projectInfo
  147. }
  148. }
  149. var taskRecordDatas []*http_model.TaskRecordData
  150. for _, taskInfo := range taskInfos {
  151. updateAt := conv.MustString(taskInfo.UpdateAt, "")
  152. updateAt = updateAt[0:19]
  153. taskRecordData := http_model.TaskRecordData{
  154. ProjectId: conv.MustString(taskInfo.ProjectId, ""),
  155. ProjectName: projectIdMap[taskInfo.ProjectId].ProjectName,
  156. ProjectType: consts.GetProjectType(projectIdMap[taskInfo.ProjectId].ProjectType),
  157. ProjectPlatform: consts.GetProjectPlatform(projectIdMap[taskInfo.ProjectId].ProjectPlatform),
  158. TaskId: conv.MustString(taskInfo.TaskId, ""),
  159. TaskStage: consts.GetTaskStage(taskInfo.TaskStage),
  160. UpdatedAt: updateAt,
  161. }
  162. taskRecordDatas = append(taskRecordDatas, &taskRecordData)
  163. }
  164. taskRecordResponse := new(http_model.GetTaskRecordResponse)
  165. taskRecordResponse.TaskRecordData = taskRecordDatas
  166. taskRecordResponse.Total = conv.MustString(total, "")
  167. return taskRecordResponse, nil
  168. }