|
@@ -3,7 +3,10 @@ package db
|
|
|
import (
|
|
|
"context"
|
|
|
"errors"
|
|
|
+ "fmt"
|
|
|
+ "github.com/issue9/conv"
|
|
|
"github.com/sirupsen/logrus"
|
|
|
+ "github.com/tidwall/gjson"
|
|
|
"gorm.io/gorm"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -29,11 +32,28 @@ func GetSecTaskById(ctx context.Context, secTaskId string) (*gorm_model.Younggee
|
|
|
|
|
|
func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, searchValue string, pageSize, pageNum int64) ([]*http_model.SecTaskInfo, int64, error) {
|
|
|
db := GetReadDB(ctx)
|
|
|
- whereCondition := gorm_model.YounggeeSecTaskInfo{
|
|
|
- SelectionID: selectionId,
|
|
|
- TaskStatus: taskStatus,
|
|
|
+ var taskStages []int
|
|
|
+ switch taskStatus {
|
|
|
+ case 3:
|
|
|
+ taskStages = []int{3}
|
|
|
+ break
|
|
|
+ case 4:
|
|
|
+ taskStages = []int{4, 6, 7, 8, 9, 10}
|
|
|
+ break
|
|
|
+ case 6:
|
|
|
+ taskStages = []int{6}
|
|
|
+ break
|
|
|
+ case 7:
|
|
|
+ taskStages = []int{7, 8, 9, 10}
|
|
|
+ break
|
|
|
+ case 9:
|
|
|
+ taskStages = []int{9}
|
|
|
+ break
|
|
|
+ case 10:
|
|
|
+ taskStages = []int{10}
|
|
|
+ break
|
|
|
}
|
|
|
- db = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where(whereCondition)
|
|
|
+ db = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("selection_id = ? and task_stage in ?", selectionId, taskStages)
|
|
|
|
|
|
// 查询总数
|
|
|
var total int64
|
|
@@ -44,18 +64,24 @@ func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, sea
|
|
|
}
|
|
|
// 查询该页数据
|
|
|
limit := pageSize
|
|
|
- offset := pageSize * pageNum // assert pageNum start with 0
|
|
|
+ offset := pageSize * (pageNum - 1) // assert pageNum start with 0
|
|
|
err := db.Order("create_date desc").Limit(int(limit)).Offset(int(offset)).Find(&secTaskInfoList).Error
|
|
|
if err != nil {
|
|
|
logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
|
|
|
+ fmt.Println("secTaskInfoList:", secTaskInfoList)
|
|
|
newSecTaskInfoList := pack.GormSecTaskListToHttpSecTaskList(secTaskInfoList)
|
|
|
+ fmt.Println("newSecTaskInfoList:", newSecTaskInfoList)
|
|
|
+
|
|
|
+ for i, secTask := range newSecTaskInfoList {
|
|
|
+ newSecTaskInfoList[i].DetailAddr = GetRegion(ctx, secTask.RegionCode) + secTask.DetailAddr
|
|
|
+ }
|
|
|
var resSecTaskInfoList []*http_model.SecTaskInfo
|
|
|
if searchValue != "" {
|
|
|
for _, v := range newSecTaskInfoList {
|
|
|
- if strings.Contains(v.SelectionId, searchValue) {
|
|
|
+ if strings.Contains(v.SecTaskId, searchValue) {
|
|
|
resSecTaskInfoList = append(resSecTaskInfoList, v)
|
|
|
} else if strings.Contains(v.PlatformNickname, searchValue) {
|
|
|
resSecTaskInfoList = append(resSecTaskInfoList, v)
|
|
@@ -66,6 +92,7 @@ func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, sea
|
|
|
} else {
|
|
|
resSecTaskInfoList = newSecTaskInfoList
|
|
|
}
|
|
|
+ fmt.Println("resSecTaskInfoList: ", resSecTaskInfoList)
|
|
|
return resSecTaskInfoList, total, nil
|
|
|
}
|
|
|
|
|
@@ -73,7 +100,10 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
|
|
|
db := GetWriteDB(ctx)
|
|
|
// 1. 校验
|
|
|
var count int64
|
|
|
+ fmt.Println("task_ids: ", taskIds)
|
|
|
err := db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND task_stage = 3", taskIds).Count(&count).Error
|
|
|
+
|
|
|
+ fmt.Println("count: ", count)
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
@@ -83,13 +113,13 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
|
|
|
|
|
|
// 2. 查询任务对应达人id(用于生成达人消息)
|
|
|
var talentIds []string
|
|
|
- err = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ?", taskIds).Select("talent_id").Find(talentIds).Error
|
|
|
+ err = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ?", taskIds).Select("talent_id").Find(&talentIds).Error
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
|
// 3. 查询任务对应选品名称(用于生成达人消息)
|
|
|
var selection gorm_model.YounggeeSelectionInfo
|
|
|
- err = db.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id = ?", selectionId).Find(selection).Error
|
|
|
+ err = db.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id = ?", selectionId).Find(&selection).Error
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
@@ -99,10 +129,11 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
|
|
|
// 若选品不提供样品,则直接跳转执行阶段,否则进入发货阶段
|
|
|
if selection.SampleMode == 3 {
|
|
|
updateData := gorm_model.YounggeeSecTaskInfo{
|
|
|
- TaskStatus: 2,
|
|
|
- TaskStage: 6,
|
|
|
- SelectDate: time.Now(),
|
|
|
- LogisticsStatus: 1,
|
|
|
+ TaskStatus: 2,
|
|
|
+ TaskStage: 8,
|
|
|
+ SelectDate: time.Now(),
|
|
|
+ LogisticsStatus: 3,
|
|
|
+ AssignmentStatus: 1,
|
|
|
}
|
|
|
err = tx.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND task_stage = 3", taskIds).Updates(updateData).Error
|
|
|
if err != nil {
|
|
@@ -110,11 +141,10 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
|
|
|
}
|
|
|
} else {
|
|
|
updateData := gorm_model.YounggeeSecTaskInfo{
|
|
|
- TaskStatus: 2,
|
|
|
- TaskStage: 8,
|
|
|
- SelectDate: time.Now(),
|
|
|
- LogisticsStatus: 3,
|
|
|
- AssignmentStatus: 1,
|
|
|
+ TaskStatus: 2,
|
|
|
+ TaskStage: 6,
|
|
|
+ SelectDate: time.Now(),
|
|
|
+ LogisticsStatus: 1,
|
|
|
}
|
|
|
err = tx.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND task_stage = 3", taskIds).Updates(updateData).Error
|
|
|
if err != nil {
|
|
@@ -151,7 +181,7 @@ func RefuseSecTaskCoop(ctx context.Context, taskIds []string) (bool, error) {
|
|
|
|
|
|
// 查询任务对应达人id
|
|
|
var talentIds []string
|
|
|
- err = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ?", taskIds).Select("talent_id").Find(talentIds).Error
|
|
|
+ err = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ?", taskIds).Select("talent_id").Find(&talentIds).Error
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
@@ -189,3 +219,51 @@ func UpdateSecTask(ctx context.Context, updateData gorm_model.YounggeeSecTaskInf
|
|
|
}
|
|
|
return true, nil
|
|
|
}
|
|
|
+
|
|
|
+func GetSecTaskSettleList(ctx context.Context, secTaskList []*http_model.SecTaskInfo, selectionId string, taskStatus int) ([]*http_model.SecTaskInfo, error) {
|
|
|
+ db := GetWriteDB(ctx)
|
|
|
+ whereCondition := gorm_model.YounggeeSelectionInfo{
|
|
|
+ SelectionID: selectionId,
|
|
|
+ }
|
|
|
+ selectionInfo := gorm_model.YounggeeSelectionInfo{}
|
|
|
+ err := db.Model(gorm_model.YounggeeSelectionInfo{}).Where(whereCondition).Scan(&selectionInfo).Error
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取返现金额、悬赏金额
|
|
|
+ fmt.Println("selectionInfo.ProductSnap: ", selectionInfo.ProductSnap)
|
|
|
+ price := conv.MustString(gjson.Get(selectionInfo.ProductSnap, "ProductPrice"), "")
|
|
|
+ for i, _ := range secTaskList {
|
|
|
+ secTaskList[i].TaskReward = selectionInfo.TaskReward
|
|
|
+ secTaskList[i].ReturnMoney = price
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取作业信息
|
|
|
+ var taskIds []string
|
|
|
+ taskMap := make(map[string]*http_model.SecTaskInfo)
|
|
|
+ for _, secTask := range secTaskList {
|
|
|
+ taskIds = append(taskIds, secTask.SecTaskId)
|
|
|
+ taskMap[secTask.SecTaskId] = secTask
|
|
|
+ }
|
|
|
+
|
|
|
+ var assignmentInfos []gorm_model.YounggeeAssignmentInfo
|
|
|
+ err = db.Model(gorm_model.YounggeeAssignmentInfo{}).Where("task_id IN ?", taskIds).Find(&assignmentInfos).Error
|
|
|
+ if err != nil {
|
|
|
+ logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ assignmentMap := make(map[string]gorm_model.YounggeeAssignmentInfo)
|
|
|
+ for _, assignmentInfo := range assignmentInfos {
|
|
|
+ assignmentMap[assignmentInfo.TaskID] = assignmentInfo
|
|
|
+ }
|
|
|
+ // 融合信息
|
|
|
+ for i, secTask := range secTaskList {
|
|
|
+ taskID := secTask.SecTaskId
|
|
|
+ secTaskList[i].AssignmentLink = assignmentMap[taskID].LinkUrl
|
|
|
+ secTaskList[i].DataScreenshot = assignmentMap[taskID].PhotoUrl
|
|
|
+ secTaskList[i].CreateDate = conv.MustString(assignmentMap[taskID].CreateAt, "")
|
|
|
+ }
|
|
|
+
|
|
|
+ return secTaskList, nil
|
|
|
+}
|