package sectask import ( "context" "fmt" "github.com/gogf/gf/frame/g" "strconv" "youngmini_server/app/dao" "youngmini_server/app/model" ) var service = new(secTaskService) type secTaskService struct { } func (s *secTaskService) List(ctx context.Context, listSecTaskReq *ListSecTaskReq, tid string) (res ListSecTaskRes, err error) { var taskStageList = g.Slice{} switch listSecTaskReq.TaskStage { case 1: taskStageList = g.Slice{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} break case 2: taskStageList = g.Slice{2, 3} break case 3: taskStageList = g.Slice{6, 7, 8} break case 4: taskStageList = g.Slice{5, 9, 10} break } whereCondition := g.Map{ dao.YounggeeSecTaskInfo.Columns.TaskStage: taskStageList, dao.YounggeeSecTaskInfo.Columns.TalentId: tid, } err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Scan(&res.SecTask) if err != nil { return } res.Count = len(res.SecTask) platformMap := make(map[string]model.InfoThirdPlatform) platformInfo := []*model.InfoThirdPlatform{} if res.Count != 0 { err = g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo) if err != nil { fmt.Println(err) return } for i, _ := range platformInfo { platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i] } // 为每个任务根据项目id查询项目名称和主图 for index, v := range res.SecTask { whereCondition1 := g.Map{ dao.YounggeeSelectionInfo.Columns.SelectionId: v.SelectionId, } var selection *model.YounggeeSelectionInfo err = g.Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition1).Scan(&selection) if err != nil || selection == nil { if err == nil { fmt.Println("没查到选品") } else { return } } whereCondition1 = g.Map{ dao.YoungeePlatformAccountInfo.Columns.PlatformId: selection.Platform, dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId, } var account *model.YoungeePlatformAccountInfo err = g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition1).Scan(&account) if err != nil { fmt.Println(err) return } res.SecTask[index].PlatformIconUrl = platformMap[strconv.Itoa(selection.Platform)].PlatformIcon res.SecTask[index].PlatformName = platformMap[strconv.Itoa(selection.Platform)].PlatformName res.SecTask[index].PlatformNickName = account.PlatformNickname res.SecTask[index].SelectionName = selection.SelectionName res.SecTask[index].ProductPhotoSnap = selection.ProductPhotoSnap //fmt.Println("--------------res.SecTask[index]: ", res.SecTask[index]) fmt.Println("--------------selection: ", selection) } } return } func UpdateStageAndStatus(ctx context.Context, updateStageReq *UpdateStageReq) (err error) { whereCondition := g.Map{ dao.YounggeeSecTaskInfo.Columns.TaskId: updateStageReq.TaskId, } dataUpdate := g.Map{ dao.YounggeeSecTaskInfo.Columns.TaskStage: updateStageReq.TaskStage, dao.YounggeeSecTaskInfo.Columns.AssignmentStatus: updateStageReq.AssignmentStatus, } _, err = dao.YounggeeSecTaskInfo.Ctx(ctx).Where(whereCondition).Data(dataUpdate).Update() if err != nil { return } return }