work_space.go 5.1 KB

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