talent.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.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. region := ""
  81. if talentInfo.IsBindBank == 1 {
  82. db2 := GetReadDB(ctx)
  83. var talentBankInfo *gorm_model.YounggeeTalentBank
  84. err = db2.Model(gorm_model.YounggeeTalentBank{}).Where("talent_id = ?", talentId).
  85. First(&talentBankInfo).Error
  86. if err != nil {
  87. if err == gorm.ErrRecordNotFound {
  88. return nil, nil
  89. } else {
  90. return nil, err
  91. }
  92. }
  93. if talentBankInfo.BankOpenAddress != 0 {
  94. region = GetRegion(ctx, talentBankInfo.BankOpenAddress)
  95. }
  96. data.Bank = talentBankInfo.Bank
  97. data.BankOpenAddress = region
  98. data.BankCardNumber = talentBankInfo.BankCardNumber
  99. data.Name = talentBankInfo.Name
  100. data.AliPayNumber = "暂无"
  101. data.AliPayRealName = "暂无"
  102. } else {
  103. data.Bank = "暂无"
  104. data.BankCardNumber = "暂无"
  105. data.BankOpenAddress = "暂无"
  106. data.Name = "暂无"
  107. data.AliPayNumber = "暂无"
  108. data.AliPayRealName = "暂无"
  109. }
  110. return data, err
  111. }
  112. func GetRegion(ctx context.Context, regionCode int) string {
  113. db4 := GetReadDB(ctx)
  114. var infoRegion *gorm_model.InfoRegion
  115. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", regionCode).First(&infoRegion)
  116. provinceCode := conv.MustString(regionCode, "")[0:2] + "0000"
  117. var province *gorm_model.InfoRegion
  118. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(provinceCode, 0)).First(&province)
  119. cityCode := conv.MustString(regionCode, "")[0:4] + "00"
  120. var city *gorm_model.InfoRegion
  121. db4.Debug().Model(gorm_model.InfoRegion{}).Where("self_code = ?", conv.MustInt(cityCode, 0)).First(&city)
  122. fmt.Println("province,city,infoRegion Code :", provinceCode, cityCode, regionCode)
  123. fmt.Println("province,city,infoRegion RegionName :", province.RegionName, city.RegionName, infoRegion.RegionName)
  124. return province.RegionName + city.RegionName + infoRegion.RegionName
  125. }
  126. func GetTaskRecord(ctx context.Context, talentId string) (*http_model.GetTaskRecordResponse, error) {
  127. db := GetReadDB(ctx)
  128. var taskInfos []*gorm_model.YoungeeTaskInfo
  129. // 根据 talent_id 进行筛选
  130. db = db.Debug().Model(gorm_model.YoungeeTaskInfo{}).Where("talent_id = ?", talentId)
  131. // 查询总数
  132. var total int64
  133. if err := db.Count(&total).Error; err != nil {
  134. logrus.WithContext(ctx).Errorf("[GetTaskRecord] error query mysql total, err:%+v", err)
  135. return nil, err
  136. }
  137. err := db.Order("update_at desc").Find(&taskInfos).Error
  138. if err != nil {
  139. if err == gorm.ErrRecordNotFound {
  140. return nil, nil
  141. } else {
  142. return nil, err
  143. }
  144. }
  145. projectIdMap := map[string]gorm_model.ProjectInfo{}
  146. for _, taskInfo := range taskInfos {
  147. if _, ok := projectIdMap[taskInfo.ProjectId]; !ok {
  148. db1 := GetReadDB(ctx)
  149. projectInfo := gorm_model.ProjectInfo{}
  150. db1.Where("project_id = ?", taskInfo.ProjectId).First(&projectInfo)
  151. projectIdMap[taskInfo.ProjectId] = projectInfo
  152. }
  153. }
  154. var taskRecordDatas []*http_model.TaskRecordData
  155. for _, taskInfo := range taskInfos {
  156. updateAt := conv.MustString(taskInfo.UpdateAt, "")
  157. updateAt = updateAt[0:19]
  158. taskRecordData := http_model.TaskRecordData{
  159. ProjectId: conv.MustString(taskInfo.ProjectId, ""),
  160. ProjectName: projectIdMap[taskInfo.ProjectId].ProjectName,
  161. ProjectType: consts.GetProjectType(projectIdMap[taskInfo.ProjectId].ProjectType),
  162. ProjectPlatform: consts.GetProjectPlatform(projectIdMap[taskInfo.ProjectId].ProjectPlatform),
  163. TaskId: conv.MustString(taskInfo.TaskId, ""),
  164. TaskStage: consts.GetTaskStage(taskInfo.TaskStage),
  165. UpdatedAt: updateAt,
  166. }
  167. taskRecordDatas = append(taskRecordDatas, &taskRecordData)
  168. }
  169. taskRecordResponse := new(http_model.GetTaskRecordResponse)
  170. taskRecordResponse.TaskRecordData = taskRecordDatas
  171. taskRecordResponse.Total = conv.MustString(total, "")
  172. return taskRecordResponse, nil
  173. }