sectask_service.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. //"youngmini_server/app/model/youngee_talent_model"
  10. _ "youngmini_server/app/model/youngee_talent_model"
  11. )
  12. var service = new(secTaskService)
  13. type secTaskService struct {
  14. }
  15. func (s *secTaskService) List(ctx context.Context, listSecTaskReq *ListSecTaskReq, tid string) (res ListSecTaskRes, err error) {
  16. var taskStageList = g.Slice{}
  17. switch listSecTaskReq.TaskStage {
  18. case 1:
  19. taskStageList = g.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  20. break
  21. case 2:
  22. taskStageList = g.Slice{2, 3}
  23. break
  24. case 3:
  25. taskStageList = g.Slice{6, 7, 8}
  26. break
  27. case 4:
  28. taskStageList = g.Slice{5, 9, 10}
  29. break
  30. }
  31. //根据达人id和任务阶段筛选,含任务信息。
  32. whereCondition := g.Map{
  33. dao.YounggeeSecTaskInfo.Columns.TaskStage: taskStageList,
  34. dao.YounggeeSecTaskInfo.Columns.TalentId: tid,
  35. }
  36. err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Scan(&res.SecTask)
  37. if err != nil {
  38. return
  39. }
  40. res.Count = len(res.SecTask)
  41. //键为字符串类型,值为model.InfoThirdPlatform类型
  42. platformMap := make(map[string]model.InfoThirdPlatform)
  43. platformInfo := []*model.InfoThirdPlatform{}
  44. if res.Count != 0 {
  45. err = g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo)
  46. if err != nil {
  47. fmt.Println(err)
  48. return
  49. }
  50. //以便后续根据平台ID快速检索和访问平台信息。
  51. //strconv.Itoa用于将int转为字符串
  52. //ListSecTaskSql中定义了平台表中的属性
  53. for i, _ := range platformInfo {
  54. platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i]
  55. }
  56. // 为每个任务根据项目id查询项目名称和主图
  57. for index, v := range res.SecTask {
  58. whereCondition1 := g.Map{
  59. dao.YounggeeSelectionInfo.Columns.SelectionId: v.SelectionId,
  60. }
  61. var selection *model.YounggeeSelectionInfo
  62. err = g.Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Scan(&selection)
  63. if err != nil || selection == nil {
  64. if err == nil {
  65. fmt.Println("没查到选品")
  66. } else {
  67. return
  68. }
  69. }
  70. whereCondition1 = g.Map{
  71. dao.YoungeePlatformAccountInfo.Columns.PlatformId: selection.Platform,
  72. dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId,
  73. }
  74. var account *model.YoungeePlatformAccountInfo
  75. err = g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition1).Scan(&account)
  76. if err != nil {
  77. fmt.Println(err)
  78. return
  79. }
  80. res.SecTask[index].PlatformIconUrl = platformMap[strconv.Itoa(selection.Platform)].PlatformIcon
  81. res.SecTask[index].PlatformName = platformMap[strconv.Itoa(selection.Platform)].PlatformName
  82. res.SecTask[index].PlatformNickName = account.PlatformNickname
  83. res.SecTask[index].SelectionName = selection.SelectionName
  84. res.SecTask[index].ProductPhotoSnap = selection.ProductPhotoSnap
  85. res.SecTask[index].TaskDdl = selection.TaskDdl
  86. //res.SecTask[index].YounggeeProductPhoto = ProductPhoto
  87. //代替商品照片快照
  88. //fmt.Println("--------------res.SecTask[index]: ", res.SecTask[index])
  89. fmt.Println("--------------selection: ", selection)
  90. }
  91. }
  92. return
  93. }
  94. func UpdateStageAndStatus(ctx context.Context, updateStageReq *UpdateStageReq) (err error) {
  95. whereCondition := g.Map{
  96. dao.YounggeeSecTaskInfo.Columns.TaskId: updateStageReq.TaskId,
  97. }
  98. dataUpdate := g.Map{
  99. dao.YounggeeSecTaskInfo.Columns.TaskStage: updateStageReq.TaskStage,
  100. dao.YounggeeSecTaskInfo.Columns.AssignmentStatus: updateStageReq.AssignmentStatus,
  101. }
  102. fmt.Println("------>", dataUpdate)
  103. _, err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Data(dataUpdate).Update()
  104. if err != nil {
  105. return
  106. }
  107. return
  108. }