talent.go 6.0 KB

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