task_info_service.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package service
  2. import (
  3. "youngee_b_api/app/dao"
  4. "youngee_b_api/app/entity"
  5. "youngee_b_api/app/vo"
  6. )
  7. type TaskInfoService struct{}
  8. // 带货待发货、待签收、已签收统计
  9. func (t TaskInfoService) LogisticsSelectionTalentCount(param *vo.LogisticsSelectionTalentParam) map[string]int64 {
  10. res := make(map[string]int64)
  11. var needDelivery int64
  12. var needReceive int64
  13. var received int64
  14. dao.Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ? AND free_stage = ?", param.SelectionId, 3).Count(&needDelivery)
  15. dao.Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ? AND free_stage = ?", param.SelectionId, 4).Count(&needReceive)
  16. dao.Db.Model(&entity.SelectionTaskInfo{}).Where("selection_id = ? AND free_stage = ?", param.SelectionId, 5).Count(&received)
  17. res["needDelivery"] = needDelivery
  18. res["needReceive"] = needReceive
  19. res["received"] = received
  20. return res
  21. }
  22. // 达人物流管理
  23. func (t TaskInfoService) LogisticsTalentList(param *vo.LogisticsTalentParam) (*vo.ResultVO, error) {
  24. if param.Page <= 0 {
  25. param.Page = 1
  26. }
  27. if param.PageSize <= 0 {
  28. param.PageSize = 10
  29. }
  30. var reLogisticsTalents []*vo.ReLogisticsTalent
  31. var total int64
  32. result := vo.ResultVO{
  33. Page: param.Page,
  34. PageSize: param.PageSize,
  35. Total: total,
  36. Data: reLogisticsTalents,
  37. }
  38. var projectTaskInfos []*entity.ProjectTaskInfo
  39. var err error
  40. projectId := param.ProjectId
  41. if param.Status == 1 { // 待发货
  42. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByTaskStage(projectId, 4, "", param.Page, param.PageSize, param.Nickname)
  43. } else if param.Status == 2 { // 待签收
  44. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByTaskStage(projectId, 5, param.DeliveryTime, param.Page, param.PageSize, param.Nickname)
  45. } else if param.Status == 3 { // 已签收
  46. projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByTaskStage(projectId, 6, "", param.Page, param.PageSize, param.Nickname)
  47. }
  48. if err != nil {
  49. return nil, err
  50. }
  51. for _, projectTaskInfo := range projectTaskInfos {
  52. // 获取达人信息
  53. talentInfo, err := dao.TalentInfoDao{}.SelectTalentInfo(projectTaskInfo.TalentID)
  54. if err != nil {
  55. return nil, err
  56. }
  57. regionName, err := dao.RegionInfoDao{}.SelectRegion(talentInfo.VisitStoreRegion)
  58. if err != nil {
  59. regionName = ""
  60. }
  61. taskLogistics, err := dao.TaskLogisticsDao{}.SelectTaskLogistics(projectTaskInfo.TaskID)
  62. if err != nil {
  63. return nil, err
  64. }
  65. talentPreview := &vo.TalentPreview{
  66. TalentId: projectTaskInfo.TalentID,
  67. TalentPhoto: talentInfo.Avatar,
  68. TalentName: talentInfo.TalentWxNickname,
  69. Account: "",
  70. Location: regionName,
  71. Gender: talentInfo.Sex,
  72. }
  73. reLogisticsTalent := &vo.ReLogisticsTalent{
  74. TalentPostAddrSnap: projectTaskInfo.TalentPostAddrSnap,
  75. ReTalentPreview: talentPreview,
  76. LogisticsId: taskLogistics.LogisticsID,
  77. CompanyName: taskLogistics.CompanyName,
  78. LogisticsNumber: taskLogistics.LogisticsNumber,
  79. Operator: "",
  80. //DeliveryTime: taskLogistics.DeliveryTime.Format("2006-01-02 15:04:05"),
  81. //SignedTime: taskLogistics.SignedTime.Format("2006-01-02 15:04:05"),
  82. }
  83. if param.Status == 2 {
  84. reLogisticsTalent.DeliveryTime = projectTaskInfo.DeliveryDate.Format("2006-01-02 15:04:05")
  85. }
  86. if param.Status == 3 {
  87. reLogisticsTalent.SignedTime = projectTaskInfo.SignedTime.Format("2006-01-02 15:04:05")
  88. }
  89. reLogisticsTalents = append(reLogisticsTalents, reLogisticsTalent)
  90. }
  91. result = vo.ResultVO{
  92. Page: param.Page,
  93. PageSize: param.PageSize,
  94. Total: total,
  95. Data: reLogisticsTalents,
  96. }
  97. return &result, nil
  98. }
  99. // 种草待发货、待签收、已签收统计
  100. func (t TaskInfoService) LogisticsTalentCount(param *vo.LogisticsTalentParam) map[string]int64 {
  101. res := make(map[string]int64)
  102. var needDelivery int64
  103. var needReceive int64
  104. var received int64
  105. dao.Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.ProjectId, 4).Count(&needDelivery)
  106. dao.Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.ProjectId, 5).Count(&needReceive)
  107. dao.Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? AND task_stage = ?", param.ProjectId, 6).Count(&received)
  108. res["needDelivery"] = needDelivery
  109. res["needReceive"] = needReceive
  110. res["received"] = received
  111. return res
  112. }
  113. func (t TaskInfoService) SelectionRewardCashDetail(param *vo.SelectionRewardCashParam) (*vo.ReSelectionRewardCash, error) {
  114. if param.Page == 0 {
  115. param.Page = 1
  116. }
  117. if param.PageSize == 0 {
  118. param.PageSize = 10
  119. }
  120. selectionInfo, err := dao.SelectionInfoDAO{}.GetSelectionInfoById(param.SelectionId)
  121. if err != nil {
  122. return nil, err
  123. }
  124. rewardPoolAmount := selectionInfo.EstimatedCost
  125. rewardPoolCashed := selectionInfo.TaskReward
  126. secTaskInfos, total, err1 := dao.SecTaskInfoDao{}.GetRewardDetailByRewardStage(param.SelectionId, 2, param.Order, param.Page, param.PageSize)
  127. if err1 != nil {
  128. return nil, err1
  129. }
  130. var talentRewardMsgs []vo.TalentRewardMsg
  131. for _, secTaskInfo := range secTaskInfos {
  132. talentInfo, _ := dao.TalentInfoDao{}.SelectTalentInfo(secTaskInfo.TalentID)
  133. talentRewardMsg := vo.TalentRewardMsg{
  134. PhotoUrl: talentInfo.Avatar,
  135. Nickname: talentInfo.TalentNickname,
  136. Account: talentInfo.TalentWxOpenid,
  137. Gender: talentInfo.Sex,
  138. OrderNum: secTaskInfo.SaleActual,
  139. CashTime: secTaskInfo.WithdrawDate.Format("2006-01-02 15:04:05"),
  140. }
  141. talentRewardMsgs = append(talentRewardMsgs, talentRewardMsg)
  142. }
  143. talentMsgList := vo.ResultVO{
  144. Page: param.Page,
  145. PageSize: param.PageSize,
  146. Total: total,
  147. Data: talentRewardMsgs,
  148. }
  149. reSelectionRewardCash := &vo.ReSelectionRewardCash{
  150. RewardPoolAmount: rewardPoolAmount,
  151. RewardPoolCashed: rewardPoolCashed,
  152. CashedRate: rewardPoolCashed / rewardPoolAmount,
  153. TalentNum: total,
  154. TalentMsgList: talentMsgList,
  155. }
  156. return reSelectionRewardCash, nil
  157. }