work_space.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. package youngee_sectask_service
  2. import (
  3. "github.com/gogf/gf/frame/g"
  4. "github.com/gogf/gf/net/ghttp"
  5. "strconv"
  6. "youngmini_server/app/dao"
  7. "youngmini_server/app/model"
  8. "youngmini_server/app/model/youngee_talent_model"
  9. "youngmini_server/app/system/sectask"
  10. "youngmini_server/app/utils"
  11. )
  12. // 获取执行中选品任务列表service
  13. func GetExeSecTaskList(r *ghttp.Request) *TalentHttpResult {
  14. tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r)
  15. if err != nil {
  16. return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"}
  17. }
  18. taskStageKey := r.GetQueryInt("taskStage", 0)
  19. var whereCondition g.Map
  20. switch taskStageKey {
  21. case 4:
  22. // 获取 TaskStage >= 2 且 <= 10 的数据
  23. whereCondition = g.Map{
  24. dao.YounggeeSecTaskInfo.Columns.TalentId: tid,
  25. dao.YounggeeSecTaskInfo.Columns.TaskStage: g.Slice{2, 3, 4, 5, 6, 7, 8, 9, 10},
  26. }
  27. case 5:
  28. // 获取 TaskStage = 9 的数据
  29. whereCondition = g.Map{
  30. dao.YounggeeSecTaskInfo.Columns.TalentId: tid,
  31. dao.YounggeeSecTaskInfo.Columns.TaskStage: 9,
  32. }
  33. default:
  34. return &TalentHttpResult{Code: -2, Msg: "parse param error"}
  35. }
  36. // 获取任务列表
  37. //var taskList []*model.YounggeeSecTaskInfo
  38. var SecTask []*sectask.ListSecTaskSql
  39. err = g.Model(dao.YounggeeSecTaskInfo.Table).Where(whereCondition).Scan(&SecTask)
  40. if err != nil {
  41. return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
  42. }
  43. platformMap := make(map[string]model.InfoThirdPlatform)
  44. var platformInfo []*model.InfoThirdPlatform
  45. if len(SecTask) != 0 {
  46. err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  47. if err != nil {
  48. return &TalentHttpResult{Code: -1, Msg: "Get platform failed"}
  49. }
  50. for i, _ := range platformInfo {
  51. platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  52. }
  53. }
  54. // 为每个任务根据项目id查询项目名称和主图
  55. var taskBriefList []*youngee_talent_model.SecTaskInfoBrief
  56. for _, v := range SecTask {
  57. whereCondition = g.Map{
  58. dao.YounggeeSelectionInfo.Columns.SelectionId: v.SelectionId,
  59. }
  60. selectionInfo, err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition).One()
  61. if err != nil {
  62. return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"}
  63. }
  64. whereCondition = g.Map{
  65. dao.YoungeePlatformAccountInfo.Columns.PlatformId: selectionInfo[dao.YounggeeSelectionInfo.Columns.Platform],
  66. dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
  67. }
  68. account, err := g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition).One()
  69. if err != nil {
  70. return &TalentHttpResult{Code: -1, Msg: "Get account info failed"}
  71. }
  72. taskInfoBrief := &youngee_talent_model.SecTaskInfoBrief{
  73. TaskId: v.TaskId,
  74. PlatformIconUrl: platformMap[selectionInfo[dao.YounggeeSelectionInfo.Columns.Platform].String()].PlatformIcon,
  75. PlatformName: platformMap[selectionInfo[dao.YounggeeSelectionInfo.Columns.Platform].String()].PlatformName,
  76. PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(),
  77. SelectionName: selectionInfo[dao.YounggeeSelectionInfo.Columns.SelectionName].String(),
  78. ProductPhotoSnap: selectionInfo[dao.YounggeeSelectionInfo.Columns.ProductPhotoSnap].String(),
  79. TaskStatus: v.TaskStatus,
  80. TaskStage: v.TaskStage,
  81. AssignmentStatus: v.AssignmentStatus,
  82. TaskReward: v.TaskReward,
  83. TalentPayment: v.TalentPayment,
  84. SampleMode: v.SampleMode,
  85. TaskDdl: v.TaskDdl,
  86. }
  87. taskBriefList = append(taskBriefList, taskInfoBrief)
  88. }
  89. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList}
  90. }
  91. // 获取选品任务详情
  92. func GetSecTaskDetail(r *ghttp.Request) *TalentHttpResult {
  93. taskId := r.GetQueryInt("task_id", -1)
  94. var secTask *model.YounggeeSecTaskInfo
  95. err := g.Model(dao.YounggeeSecTaskInfo.Table).Where("task_id = ?", taskId).Scan(&secTask)
  96. if err != nil {
  97. g.Log().Error("Get selection task info failed: " + err.Error())
  98. return &TalentHttpResult{Code: -1, Msg: "Get task info failed"}
  99. }
  100. if secTask == nil {
  101. g.Log().Error("Get selection task info failed, The task does not exist.")
  102. return &TalentHttpResult{Code: -2, Msg: "Task Miss"}
  103. }
  104. var selectionDetail *youngee_talent_model.SelectionDetail
  105. err = g.Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", secTask.SelectionId).Scan(&selectionDetail)
  106. if err != nil {
  107. g.Log().Error("Get selection detail failed.")
  108. return &TalentHttpResult{Code: -3, Msg: "Get selection detail failed."}
  109. }
  110. var withdrawStatus = 1
  111. if secTask.SampleMode == 2 {
  112. var taskIncome *model.YounggeeTalentIncome
  113. err = g.Model(dao.YounggeeTalentIncome.Table).Where("sectask_id = ? and income_type = 3", taskId).Scan(&taskIncome)
  114. if err != nil {
  115. return &TalentHttpResult{Code: -3, Msg: "Get return income detail failed."}
  116. }
  117. if taskIncome != nil {
  118. withdrawStatus = taskIncome.WithdrawStatus + 1
  119. }
  120. }
  121. if secTask.TaskMode == 1 {
  122. var taskIncome *model.YounggeeTalentIncome
  123. err = g.Model(dao.YounggeeTalentIncome.Table).Where("sectask_id = ? and income_type = 4", taskId).Scan(&taskIncome)
  124. if err != nil {
  125. return &TalentHttpResult{Code: -3, Msg: "Get reward income detail failed."}
  126. }
  127. if taskIncome != nil && taskIncome.WithdrawStatus == 1 {
  128. withdrawStatus = 2
  129. }
  130. }
  131. taskDetail := &youngee_talent_model.SecTaskDetailResp{
  132. SecTaskInfo: secTask,
  133. SelectionDetail: selectionDetail,
  134. WithdrawStatus: withdrawStatus,
  135. }
  136. return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail}
  137. }