talent.go 6.9 KB

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