sectask_service.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package sectask
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/gogf/gf/frame/g"
  6. "strconv"
  7. "youngmini_server/app/dao"
  8. "youngmini_server/app/model"
  9. )
  10. var service = new(secTaskService)
  11. type secTaskService struct {
  12. }
  13. func (s *secTaskService) List(ctx context.Context, listSecTaskReq *ListSecTaskReq, tid string) (res ListSecTaskRes, err error) {
  14. var taskStageList = g.Slice{}
  15. switch listSecTaskReq.TaskStage {
  16. case 1:
  17. taskStageList = g.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  18. break
  19. case 2:
  20. taskStageList = g.Slice{2, 3}
  21. break
  22. case 3:
  23. taskStageList = g.Slice{6, 7, 8}
  24. break
  25. case 4:
  26. taskStageList = g.Slice{5, 9, 10}
  27. break
  28. }
  29. whereCondition := g.Map{
  30. dao.YounggeeSecTaskInfo.Columns.TaskStage: taskStageList,
  31. dao.YounggeeSecTaskInfo.Columns.TalentId: tid,
  32. }
  33. err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Scan(&res.SecTask)
  34. if err != nil {
  35. return
  36. }
  37. res.Count = len(res.SecTask)
  38. platformMap := make(map[string]model.InfoThirdPlatform)
  39. platformInfo := []*model.InfoThirdPlatform{}
  40. if res.Count != 0 {
  41. err = g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  42. if err != nil {
  43. fmt.Println(err)
  44. return
  45. }
  46. for i, _ := range platformInfo {
  47. platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  48. }
  49. // 为每个任务根据项目id查询项目名称和主图
  50. for index, v := range res.SecTask {
  51. whereCondition1 := g.Map{
  52. dao.YounggeeSelectionInfo.Columns.SelectionId: v.SelectionId,
  53. }
  54. var selection *model.YounggeeSelectionInfo
  55. err = g.Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Scan(&selection)
  56. if err != nil || selection == nil {
  57. if err == nil {
  58. fmt.Println("没查到选品")
  59. } else {
  60. return
  61. }
  62. }
  63. whereCondition1 = g.Map{
  64. dao.YoungeePlatformAccountInfo.Columns.PlatformId: selection.Platform,
  65. dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
  66. }
  67. var account *model.YoungeePlatformAccountInfo
  68. err = g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition1).Scan(&account)
  69. if err != nil {
  70. fmt.Println(err)
  71. return
  72. }
  73. res.SecTask[index].PlatformIconUrl = platformMap[strconv.Itoa(selection.Platform)].PlatformIcon
  74. res.SecTask[index].PlatformName = platformMap[strconv.Itoa(selection.Platform)].PlatformName
  75. res.SecTask[index].PlatformNickName = account.PlatformNickname
  76. res.SecTask[index].SelectionName = selection.SelectionName
  77. res.SecTask[index].ProductPhotoSnap = selection.ProductPhotoSnap
  78. //fmt.Println("--------------res.SecTask[index]: ", res.SecTask[index])
  79. fmt.Println("--------------selection: ", selection)
  80. }
  81. }
  82. return
  83. }
  84. func UpdateStageAndStatus(ctx context.Context, updateStageReq *UpdateStageReq) (err error) {
  85. whereCondition := g.Map{
  86. dao.YounggeeSecTaskInfo.Columns.TaskId: updateStageReq.TaskId,
  87. }
  88. dataUpdate := g.Map{
  89. dao.YounggeeSecTaskInfo.Columns.TaskStage: updateStageReq.TaskStage,
  90. dao.YounggeeSecTaskInfo.Columns.AssignmentStatus: updateStageReq.AssignmentStatus,
  91. }
  92. _, err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Data(dataUpdate).Update()
  93. if err != nil {
  94. return
  95. }
  96. return
  97. }