123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- 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/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"}
- }
- var taskStageList = [2]int{0, 8}
- taskStageKey := r.GetQueryInt("taskStage", 0)
- if taskStageKey == 0 {
- return &TalentHttpResult{Code: -2, Msg: "parse param error"}
- }
- taskStage := taskStageList[taskStageKey-3]
- // 获取任务列表
- var taskList []*model.YounggeeSecTaskInfo
- whereCondition := g.Map{
- dao.YounggeeSecTaskInfo.Columns.TalentId: tid,
- dao.YounggeeSecTaskInfo.Columns.TaskStage: taskStage,
- }
- err = g.Model(dao.YounggeeSecTaskInfo.Table).Where(whereCondition).Scan(&taskList)
- if err != nil {
- return &TalentHttpResult{Code: -1, Msg: "Get task list failed"}
- }
- platformMap := make(map[string]model.InfoThirdPlatform)
- var platformInfo []*model.InfoThirdPlatform
- if len(taskList) != 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 taskList {
- 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,
- }
- 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}
- }
|