package youngee_sectask_service import ( "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" "strconv" "youngmini_server/app/dao" "youngmini_server/app/model" "youngmini_server/app/model/youngee_talent_model" "youngmini_server/app/system/sectask" "youngmini_server/app/utils" ) // 获取执行中选品任务列表service func GetExeSecTaskList(r *ghttp.Request) *TalentHttpResult { tid, err := utils.SessionTalentInfo.GetTalentIdFromSession(r) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get talent info failed"} } taskStageKey := r.GetQueryInt("taskStage", 0) var whereCondition g.Map switch taskStageKey { case 4: // 获取 TaskStage >= 2 且 <= 10 的数据 whereCondition = g.Map{ dao.YounggeeSecTaskInfo.Columns.TalentId: tid, dao.YounggeeSecTaskInfo.Columns.TaskStage: g.Slice{2, 3, 4, 5, 6, 7, 8, 9, 10}, } case 5: // 获取 TaskStage = 9 的数据 whereCondition = g.Map{ dao.YounggeeSecTaskInfo.Columns.TalentId: tid, dao.YounggeeSecTaskInfo.Columns.TaskStage: 9, } default: return &TalentHttpResult{Code: -2, Msg: "parse param error"} } // 获取任务列表 //var taskList []*model.YounggeeSecTaskInfo var SecTask []*sectask.ListSecTaskSql err = g.Model(dao.YounggeeSecTaskInfo.Table).Where(whereCondition).Scan(&SecTask) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get task list failed"} } platformMap := make(map[string]model.InfoThirdPlatform) var platformInfo []*model.InfoThirdPlatform if len(SecTask) != 0 { err := g.Model(dao.InfoThirdPlatform.Table).Scan(&platformInfo) if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get platform failed"} } for i, _ := range platformInfo { platformMap[strconv.Itoa(platformInfo[i].PlatformId)] = *platformInfo[i] } } // 为每个任务根据项目id查询项目名称和主图 var taskBriefList []*youngee_talent_model.SecTaskInfoBrief for _, v := range SecTask { whereCondition = g.Map{ dao.YounggeeSelectionInfo.Columns.SelectionId: v.SelectionId, } selectionInfo, err := g.Model(dao.YounggeeSelectionInfo.Table).Where(whereCondition).One() if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get fullproject info failed"} } whereCondition = g.Map{ dao.YoungeePlatformAccountInfo.Columns.PlatformId: selectionInfo[dao.YounggeeSelectionInfo.Columns.Platform], dao.YoungeePlatformAccountInfo.Columns.TalentId: v.TalentId, } account, err := g.Model(dao.YoungeePlatformAccountInfo.Table).Where(whereCondition).One() if err != nil { return &TalentHttpResult{Code: -1, Msg: "Get account info failed"} } taskInfoBrief := &youngee_talent_model.SecTaskInfoBrief{ TaskId: v.TaskId, PlatformIconUrl: platformMap[selectionInfo[dao.YounggeeSelectionInfo.Columns.Platform].String()].PlatformIcon, PlatformName: platformMap[selectionInfo[dao.YounggeeSelectionInfo.Columns.Platform].String()].PlatformName, PlatformNickName: account[dao.YoungeePlatformAccountInfo.Columns.PlatformNickname].String(), SelectionName: selectionInfo[dao.YounggeeSelectionInfo.Columns.SelectionName].String(), ProductPhotoSnap: selectionInfo[dao.YounggeeSelectionInfo.Columns.ProductPhotoSnap].String(), TaskStatus: v.TaskStatus, TaskStage: v.TaskStage, AssignmentStatus: v.AssignmentStatus, TaskReward: v.TaskReward, TalentPayment: v.TalentPayment, SampleMode: v.SampleMode, TaskDdl: v.TaskDdl, } taskBriefList = append(taskBriefList, taskInfoBrief) } return &TalentHttpResult{Code: 0, Msg: "success", Data: taskBriefList} } // 获取选品任务详情 func GetSecTaskDetail(r *ghttp.Request) *TalentHttpResult { taskId := r.GetQueryInt("task_id", -1) var secTask *model.YounggeeSecTaskInfo err := g.Model(dao.YounggeeSecTaskInfo.Table).Where("task_id = ?", taskId).Scan(&secTask) if err != nil { g.Log().Error("Get selection task info failed: " + err.Error()) return &TalentHttpResult{Code: -1, Msg: "Get task info failed"} } if secTask == nil { g.Log().Error("Get selection task info failed, The task does not exist.") return &TalentHttpResult{Code: -2, Msg: "Task Miss"} } var selectionDetail *youngee_talent_model.SelectionDetail err = g.Model(youngee_talent_model.SelectionDetail{}).WithAll().Where("selection_id", secTask.SelectionId).Scan(&selectionDetail) if err != nil { g.Log().Error("Get selection detail failed.") return &TalentHttpResult{Code: -3, Msg: "Get selection detail failed."} } var withdrawStatus = 1 if secTask.SampleMode == 2 { var taskIncome *model.YounggeeTalentIncome err = g.Model(dao.YounggeeTalentIncome.Table).Where("sectask_id = ? and income_type = 3", taskId).Scan(&taskIncome) if err != nil { return &TalentHttpResult{Code: -3, Msg: "Get return income detail failed."} } if taskIncome != nil { withdrawStatus = taskIncome.WithdrawStatus + 1 } } if secTask.TaskMode == 1 { var taskIncome *model.YounggeeTalentIncome err = g.Model(dao.YounggeeTalentIncome.Table).Where("sectask_id = ? and income_type = 4", taskId).Scan(&taskIncome) if err != nil { return &TalentHttpResult{Code: -3, Msg: "Get reward income detail failed."} } if taskIncome != nil && taskIncome.WithdrawStatus == 1 { withdrawStatus = 2 } } taskDetail := &youngee_talent_model.SecTaskDetailResp{ SecTaskInfo: secTask, SelectionDetail: selectionDetail, WithdrawStatus: withdrawStatus, } return &TalentHttpResult{Code: 0, Msg: "success", Data: taskDetail} }