|
@@ -30,7 +30,7 @@ func GetSecTaskById(ctx context.Context, secTaskId string) (*gorm_model.Younggee
|
|
|
return &secTaskInfo, nil
|
|
|
}
|
|
|
|
|
|
-func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, searchValue string, saleNumMin int, saleNumMax int, pageSize, pageNum int64) ([]*http_model.SecTaskInfo, int64, error) {
|
|
|
+func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, searchValue string, saleNumMin int, saleNumMax int, pageSize, pageNum int64, orderBy []string, orderDesc []int) ([]*http_model.SecTaskInfo, int64, error) {
|
|
|
db := GetReadDB(ctx)
|
|
|
// var taskStages []int
|
|
|
var freeStages []int
|
|
@@ -81,6 +81,32 @@ func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, sea
|
|
|
db = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("selection_id = ? and free_stage in ?", selectionId, freeStages)
|
|
|
}
|
|
|
|
|
|
+ // 动态排序逻辑
|
|
|
+ if len(orderBy) > 0 && len(orderDesc) > 0 && len(orderBy) == len(orderDesc) {
|
|
|
+ for i := 0; i < len(orderBy); i++ {
|
|
|
+ orderField := orderBy[i]
|
|
|
+ isDesc := orderDesc[i] == 1 // 1=降序,其他值=升序
|
|
|
+
|
|
|
+ switch orderField {
|
|
|
+ case "sale_num":
|
|
|
+ if isDesc {
|
|
|
+ db = db.Order("sale_num desc")
|
|
|
+ } else {
|
|
|
+ db = db.Order("sale_num asc")
|
|
|
+ }
|
|
|
+ case "fans_count":
|
|
|
+ if isDesc {
|
|
|
+ db = db.Order("fans_num desc")
|
|
|
+ } else {
|
|
|
+ db = db.Order("fans_num asc")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 默认排序
|
|
|
+ db = db.Order("sec_task_id desc")
|
|
|
+ }
|
|
|
+
|
|
|
// 查询总数
|
|
|
var total int64
|
|
|
var secTaskInfoList []*gorm_model.YounggeeSecTaskInfo
|
|
@@ -88,10 +114,11 @@ func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, sea
|
|
|
logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
|
|
|
return nil, 0, err
|
|
|
}
|
|
|
+
|
|
|
// 查询该页数据
|
|
|
limit := pageSize
|
|
|
offset := pageSize * (pageNum - 1) // assert pageNum start with 0
|
|
|
- err := db.Order("create_date desc").Limit(int(limit)).Offset(int(offset)).Find(&secTaskInfoList).Error
|
|
|
+ err := db.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
|
|
@@ -127,7 +154,7 @@ func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, sea
|
|
|
return nil, 0, selectionInfoErr
|
|
|
}
|
|
|
v.EnterpriseId = selectionInfo.EnterpriseID
|
|
|
- v.SubAccountId = 0
|
|
|
+ v.SubAccountId = selectionInfo.SubAccountId
|
|
|
}
|
|
|
|
|
|
// 按照saleMin和saleMax区间过滤
|
|
@@ -163,14 +190,23 @@ func GetSecTaskList(ctx context.Context, selectionId string, taskStatus int, sea
|
|
|
return resSecTaskInfoList, total, nil
|
|
|
}
|
|
|
|
|
|
-func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string) (bool, error) {
|
|
|
+func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string, enterpriseId string, subAccountId int) (bool, error) {
|
|
|
db := GetWriteDB(ctx)
|
|
|
// 1. 校验
|
|
|
var count int64
|
|
|
- fmt.Println("task_ids: ", taskIds)
|
|
|
+ //fmt.Println("task_ids: ", taskIds)
|
|
|
err := db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND free_stage = 1", taskIds).Count(&count).Error
|
|
|
|
|
|
- fmt.Println("count: ", count)
|
|
|
+ var chooseTalentUserId string
|
|
|
+ var chooseTalentUserType int
|
|
|
+ if subAccountId == 0 {
|
|
|
+ chooseTalentUserType = 1
|
|
|
+ chooseTalentUserId = enterpriseId
|
|
|
+ } else {
|
|
|
+ chooseTalentUserType = 2
|
|
|
+ chooseTalentUserId = conv.MustString(subAccountId)
|
|
|
+ }
|
|
|
+ //fmt.Println("count: ", count)
|
|
|
if err != nil {
|
|
|
return false, err
|
|
|
}
|
|
@@ -201,11 +237,13 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
|
|
|
// 若选品不提供样品,则直接跳转执行阶段,否则进入发货阶段
|
|
|
if selection.SampleMode == 3 {
|
|
|
updateData := gorm_model.YounggeeSecTaskInfo{
|
|
|
- TaskStatus: 2,
|
|
|
- TaskStage: 8,
|
|
|
- SelectDate: time.Now(),
|
|
|
- LogisticsStatus: 3,
|
|
|
- AssignmentStatus: 1,
|
|
|
+ ChooseTalentUserId: chooseTalentUserId,
|
|
|
+ ChooseTalentUserType: chooseTalentUserType,
|
|
|
+ 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 {
|
|
@@ -215,11 +253,13 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
|
|
|
} else {
|
|
|
// 免费领样
|
|
|
updateData := gorm_model.YounggeeSecTaskInfo{
|
|
|
- TaskStatus: 2,
|
|
|
- TaskStage: 6,
|
|
|
- SelectDate: time.Now(),
|
|
|
- LogisticsStatus: 1,
|
|
|
- FreeStage: 3,
|
|
|
+ ChooseTalentUserId: chooseTalentUserId,
|
|
|
+ ChooseTalentUserType: chooseTalentUserType,
|
|
|
+ TaskStatus: 2,
|
|
|
+ TaskStage: 6,
|
|
|
+ SelectDate: time.Now(),
|
|
|
+ LogisticsStatus: 1,
|
|
|
+ FreeStage: 3,
|
|
|
}
|
|
|
err = tx.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND free_stage = 1", taskIds).Updates(updateData).Error
|
|
|
if err != nil {
|
|
@@ -263,8 +303,17 @@ func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string)
|
|
|
return true, nil
|
|
|
}
|
|
|
|
|
|
-func RefuseSecTaskCoop(ctx context.Context, taskIds []string) (bool, error) {
|
|
|
+func RefuseSecTaskCoop(ctx context.Context, taskIds []string, enterpriseId string, subAccountId int) (bool, error) {
|
|
|
db := GetWriteDB(ctx)
|
|
|
+ var chooseTalentUserId string
|
|
|
+ var chooseTalentUserType int
|
|
|
+ if subAccountId == 0 {
|
|
|
+ chooseTalentUserType = 1
|
|
|
+ chooseTalentUserId = enterpriseId
|
|
|
+ } else {
|
|
|
+ chooseTalentUserType = 2
|
|
|
+ chooseTalentUserId = conv.MustString(subAccountId)
|
|
|
+ }
|
|
|
// 1. 校验
|
|
|
var count int64
|
|
|
err := db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND free_stage = 1", taskIds).Count(&count).Error
|
|
@@ -285,11 +334,13 @@ func RefuseSecTaskCoop(ctx context.Context, taskIds []string) (bool, error) {
|
|
|
err = db.Transaction(func(tx *gorm.DB) error {
|
|
|
// 2. 修改任务状态和任务阶段
|
|
|
updateData := gorm_model.YounggeeSecTaskInfo{
|
|
|
- TaskStatus: 3,
|
|
|
- TaskStage: 5,
|
|
|
- CompleteDate: time.Now(),
|
|
|
- CompleteStatus: 3,
|
|
|
- FreeStage: 2,
|
|
|
+ ChooseTalentUserId: chooseTalentUserId,
|
|
|
+ ChooseTalentUserType: chooseTalentUserType,
|
|
|
+ TaskStatus: 3,
|
|
|
+ TaskStage: 5,
|
|
|
+ CompleteDate: time.Now(),
|
|
|
+ CompleteStatus: 3,
|
|
|
+ FreeStage: 2,
|
|
|
}
|
|
|
err = tx.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND free_stage = 1", taskIds).Updates(updateData).Error
|
|
|
if err != nil {
|