talent.go 6.7 KB

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