浏览代码

Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	handler/selection_detail.go
#	service/selection.go
yuliang1112 1 年之前
父节点
当前提交
c30934dedc
共有 41 个文件被更改,包括 1912 次插入147 次删除
  1. 2 10
      db/message.go
  2. 35 0
      db/product.go
  3. 191 0
      db/sectask.go
  4. 29 0
      db/sectask_logistics.go
  5. 76 40
      db/selection.go
  6. 23 0
      db/talent_income.go
  7. 52 1
      db/task.go
  8. 1 0
      go.mod
  9. 2 0
      go.sum
  10. 60 0
      handler/CreateSecTaskLogistics.go
  11. 62 0
      handler/CreateSelection.go
  12. 61 0
      handler/GetSecTaskList.go
  13. 61 0
      handler/PassSecTaskCoop.go
  14. 62 0
      handler/PaySelection.go
  15. 61 0
      handler/RefuseSecTaskCoop.go
  16. 62 0
      handler/SettleSecTask.go
  17. 60 0
      handler/UpdateSecTaskLogistics.go
  18. 62 0
      handler/UpdateSelection.go
  19. 4 4
      handler/selection_detail.go
  20. 2 2
      handler/selection_find_all.go
  21. 29 0
      model/gorm_model/talent_income.go
  22. 24 0
      model/http_model/CreateSecTaskLogistics.go
  23. 20 0
      model/http_model/CreateSelection.go
  24. 38 0
      model/http_model/GetSecTaskList.go
  25. 19 0
      model/http_model/PassSecTaskCoop.go
  26. 20 0
      model/http_model/PaySelection.go
  27. 18 0
      model/http_model/RefuseSecTaskCoop.go
  28. 22 0
      model/http_model/SettleSecTask.go
  29. 25 0
      model/http_model/UpdateSecTaskLogistics.go
  30. 47 0
      model/http_model/UpdateSelection.go
  31. 10 10
      model/http_model/logistics_create.go
  32. 30 0
      pack/sec_task_list.go
  33. 12 3
      route/init.go
  34. 67 13
      service/project_pay.go
  35. 106 0
      service/sectask_service/logistics.go
  36. 1 0
      service/sectask_service/recruit.go
  37. 188 0
      service/sectask_service/sectask.go
  38. 0 64
      service/selection.go
  39. 230 0
      service/selection_service/selection.go
  40. 22 0
      util/structFunc.go
  41. 16 0
      util/uuid.go

+ 2 - 10
db/message.go

@@ -46,15 +46,8 @@ func CreateMessageByTaskId(ctx context.Context, messageId int, messageType int,
 }
 }
 
 
 // 插入新消息
 // 插入新消息
-func CreateMessage(ctx context.Context, messageId int, messageType int, talentId string, projectId string) error {
+func CreateMessage(ctx context.Context, messageId int, messageType int, talentId string, projectName string) error {
 	db := GetReadDB(ctx)
 	db := GetReadDB(ctx)
-	var projectName string
-	err := db.Model(gorm_model.ProjectInfo{}).Select("project_name").Where("project_id = ?", projectId).Find(&projectName).Error
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[CreateMessageByTask] error read mysql, err:%+v", err)
-		return err
-	}
-
 	messageInfo := gorm_model.YounggeeMessageInfo{
 	messageInfo := gorm_model.YounggeeMessageInfo{
 		MessageID:   messageId,
 		MessageID:   messageId,
 		MessageType: messageType,
 		MessageType: messageType,
@@ -64,8 +57,7 @@ func CreateMessage(ctx context.Context, messageId int, messageType int, talentId
 		IsReaded:    0,
 		IsReaded:    0,
 		IsDeleted:   0,
 		IsDeleted:   0,
 	}
 	}
-	db1 := GetReadDB(ctx)
-	err = db1.Model(gorm_model.YounggeeMessageInfo{}).Create(&messageInfo).Error
+	err := db.Model(gorm_model.YounggeeMessageInfo{}).Create(&messageInfo).Error
 	if err != nil {
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[CreateMessageByTask] error create mysql, err:%+v", err)
 		logrus.WithContext(ctx).Errorf("[CreateMessageByTask] error create mysql, err:%+v", err)
 		return err
 		return err

+ 35 - 0
db/product.go

@@ -2,6 +2,7 @@ package db
 
 
 import (
 import (
 	"context"
 	"context"
+	"github.com/sirupsen/logrus"
 	"youngee_b_api/model/gorm_model"
 	"youngee_b_api/model/gorm_model"
 
 
 	"gorm.io/gorm"
 	"gorm.io/gorm"
@@ -62,3 +63,37 @@ func GetProductIDByName(ctx context.Context, brandName string, productName strin
 	}
 	}
 	return &product.ProductID, nil
 	return &product.ProductID, nil
 }
 }
+
+func GetProductInfoBySelectionId(ctx context.Context, selectionId string) (*gorm_model.YounggeeProduct, error) {
+	db := GetReadDB(ctx)
+	productId := 0
+	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Select("product_id").Where("selection_id = ?", selectionId).Find(&productId).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
+		return nil, err
+	}
+	productInfo := gorm_model.YounggeeProduct{}
+	err = db.Model(gorm_model.YounggeeProduct{}).Where("product_id = ?", productId).Find(&productInfo).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
+		return nil, err
+	}
+	return &productInfo, nil
+}
+
+func GetProductPhotoInfoBySelectionId(ctx context.Context, selectionId string) ([]*gorm_model.YounggeeProductPhoto, error) {
+	db := GetReadDB(ctx)
+	productId := 0
+	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Select("product_id").Where("selection_id = ?", selectionId).Find(&productId).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
+		return nil, err
+	}
+	var productPhotoInfo []*gorm_model.YounggeeProductPhoto
+	err = db.Model(gorm_model.YounggeeProductPhoto{}).Where("product_id = ?", productId).Find(&productPhotoInfo).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
+		return nil, err
+	}
+	return productPhotoInfo, nil
+}

+ 191 - 0
db/sectask.go

@@ -0,0 +1,191 @@
+package db
+
+import (
+	"context"
+	"errors"
+	"github.com/sirupsen/logrus"
+	"gorm.io/gorm"
+	"strings"
+	"time"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/pack"
+)
+
+func GetSecTaskById(ctx context.Context, secTaskId string) (*gorm_model.YounggeeSecTaskInfo, error) {
+	db := GetWriteDB(ctx)
+	secTaskInfo := gorm_model.YounggeeSecTaskInfo{}
+	whereCondition := gorm_model.YounggeeSecTaskInfo{TaskID: secTaskId}
+	result := db.Where(&whereCondition).First(&secTaskInfo)
+	if result.Error != nil {
+		if errors.Is(result.Error, gorm.ErrRecordNotFound) {
+			return nil, nil
+		} else {
+			return nil, result.Error
+		}
+	}
+	return &secTaskInfo, nil
+}
+
+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,
+	}
+	db = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where(whereCondition)
+
+	// 查询总数
+	var total int64
+	var secTaskInfoList []*gorm_model.YounggeeSecTaskInfo
+	if err := db.Count(&total).Error; err != nil {
+		logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
+		return nil, 0, err
+	}
+	// 查询该页数据
+	limit := pageSize
+	offset := pageSize * pageNum // 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
+	}
+
+	newSecTaskInfoList := pack.GormSecTaskListToHttpSecTaskList(secTaskInfoList)
+	var resSecTaskInfoList []*http_model.SecTaskInfo
+	if searchValue != "" {
+		for _, v := range newSecTaskInfoList {
+			if strings.Contains(v.SelectionId, searchValue) {
+				resSecTaskInfoList = append(resSecTaskInfoList, v)
+			} else if strings.Contains(v.PlatformNickname, searchValue) {
+				resSecTaskInfoList = append(resSecTaskInfoList, v)
+			} else {
+				total--
+			}
+		}
+	} else {
+		resSecTaskInfoList = newSecTaskInfoList
+	}
+	return resSecTaskInfoList, total, nil
+}
+
+func PassSecTaskCoop(ctx context.Context, selectionId string, taskIds []string) (bool, error) {
+	db := GetWriteDB(ctx)
+	// 1. 校验
+	var count int64
+	err := db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND task_stage = 3", taskIds).Count(&count).Error
+	if err != nil {
+		return false, err
+	}
+	if int64(len(taskIds)) == 0 || count != int64(len(taskIds)) {
+		return false, errors.New("任务id有误")
+	}
+
+	// 2. 查询任务对应达人id(用于生成达人消息)
+	var talentIds []string
+	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
+	if err != nil {
+		return false, err
+	}
+
+	err = db.Transaction(func(tx *gorm.DB) error {
+		// 2. 修改任务状态和任务阶段
+		// 若选品不提供样品,则直接跳转执行阶段,否则进入发货阶段
+		if selection.SampleMode == 3 {
+			updateData := gorm_model.YounggeeSecTaskInfo{
+				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 {
+				return err
+			}
+		} else {
+			updateData := gorm_model.YounggeeSecTaskInfo{
+				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 {
+				return err
+			}
+		}
+		// 3. 生成达人消息
+		for _, talendId := range talentIds {
+			err = CreateMessage(ctx, 1, 1, talendId, selection.SelectionName)
+			if err != nil {
+				return err
+			}
+		}
+		// 返回 nil 提交事务
+		return nil
+	})
+	if err != nil {
+		return false, err
+	}
+	return true, nil
+}
+
+func RefuseSecTaskCoop(ctx context.Context, taskIds []string) (bool, error) {
+	db := GetWriteDB(ctx)
+	// 1. 校验
+	var count int64
+	err := db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND task_stage = 3", taskIds).Count(&count).Error
+	if err != nil {
+		return false, err
+	}
+	if count != int64(len(taskIds)) {
+		return false, errors.New("任务id有误")
+	}
+
+	// 查询任务对应达人id
+	var talentIds []string
+	err = db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ?", taskIds).Select("talent_id").Find(talentIds).Error
+	if err != nil {
+		return false, err
+	}
+
+	err = db.Transaction(func(tx *gorm.DB) error {
+		// 2. 修改任务状态和任务阶段
+		updateData := gorm_model.YounggeeSecTaskInfo{
+			TaskStatus:     3,
+			TaskStage:      5,
+			CompleteDate:   time.Now(),
+			CompleteStatus: 3,
+		}
+		err = tx.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id IN ? AND task_stage = 3", taskIds).Updates(updateData).Error
+		if err != nil {
+			return err
+		}
+
+		// 返回 nil 提交事务
+		return nil
+	})
+	if err != nil {
+		return false, err
+	}
+	return true, nil
+}
+
+func UpdateSecTask(ctx context.Context, updateData gorm_model.YounggeeSecTaskInfo) (bool, error) {
+	db := GetWriteDB(ctx)
+	whereCondition := gorm_model.YounggeeSecTaskInfo{
+		TaskID: updateData.TaskID,
+	}
+	err := db.Where(whereCondition).Updates(&updateData).Error
+	if err != nil {
+		return false, err
+	}
+	return true, nil
+}

+ 29 - 0
db/sectask_logistics.go

@@ -0,0 +1,29 @@
+package db
+
+import (
+	"context"
+	"youngee_b_api/model/gorm_model"
+)
+
+func CreateSecTaskLogistics(ctx context.Context, logistics gorm_model.YoungeeTaskLogistics) (*int64, error) {
+	db := GetWriteDB(ctx)
+	err := db.Create(&logistics).Error
+	if err != nil {
+		return nil, err
+	}
+
+	return &logistics.LogisticsID, nil
+}
+
+func UpdateSecTaskLogistics(ctx context.Context, updateData gorm_model.YoungeeTaskLogistics) (*int64, error) {
+	db := GetWriteDB(ctx)
+	whereCondition := gorm_model.YoungeeTaskLogistics{
+		LogisticsID: updateData.LogisticsID,
+	}
+	err := db.Where(whereCondition).Updates(&updateData).Error
+	if err != nil {
+		return nil, err
+	}
+
+	return &updateData.LogisticsID, nil
+}

+ 76 - 40
db/selection.go

@@ -2,8 +2,10 @@ package db
 
 
 import (
 import (
 	"context"
 	"context"
+	"errors"
 	"fmt"
 	"fmt"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
+	"gorm.io/gorm"
 	"reflect"
 	"reflect"
 	"strings"
 	"strings"
 	"youngee_b_api/model/common_model"
 	"youngee_b_api/model/common_model"
@@ -11,6 +13,25 @@ import (
 	"youngee_b_api/util"
 	"youngee_b_api/util"
 )
 )
 
 
+func CreateSelection(ctx context.Context, selectionInfo gorm_model.YounggeeSelectionInfo) error {
+	db := GetWriteDB(ctx)
+	err := db.Create(&selectionInfo).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+func UpdateSelection(ctx context.Context, selectionInfo gorm_model.YounggeeSelectionInfo) error {
+	db := GetWriteDB(ctx)
+	whereCondition := gorm_model.YounggeeSelectionInfo{SelectionID: selectionInfo.SelectionID}
+	err := db.Model(&gorm_model.YounggeeSelectionInfo{}).Where(whereCondition).Updates(selectionInfo).Error
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 func DeleteSelection(ctx context.Context, SelectionId string) error {
 func DeleteSelection(ctx context.Context, SelectionId string) error {
 	db := GetReadDB(ctx)
 	db := GetReadDB(ctx)
 	err := db.Where("selection_id = ?", SelectionId).Delete(&gorm_model.YounggeeSelectionInfo{}).Error
 	err := db.Where("selection_id = ?", SelectionId).Delete(&gorm_model.YounggeeSelectionInfo{}).Error
@@ -20,6 +41,36 @@ func DeleteSelection(ctx context.Context, SelectionId string) error {
 	return nil
 	return nil
 }
 }
 
 
+func GetSelectionById(ctx context.Context, selectionId string) (*gorm_model.YounggeeSelectionInfo, error) {
+	db := GetWriteDB(ctx)
+	selectionInfo := gorm_model.YounggeeSelectionInfo{}
+	whereCondition := gorm_model.YounggeeSelectionInfo{SelectionID: selectionId}
+	result := db.Where(&whereCondition).First(&selectionInfo)
+	if result.Error != nil {
+		if errors.Is(result.Error, gorm.ErrRecordNotFound) {
+			return nil, nil
+		} else {
+			return nil, result.Error
+		}
+	}
+	return &selectionInfo, nil
+}
+
+func GetSelectionByEnterpiseIdAndProductId(ctx context.Context, enterpriseId string, productId int) (*gorm_model.YounggeeSelectionInfo, error) {
+	db := GetWriteDB(ctx)
+	selectionInfo := gorm_model.YounggeeSelectionInfo{}
+	whereCondition := gorm_model.YounggeeSelectionInfo{EnterpriseID: enterpriseId, ProductID: productId}
+	result := db.Where(&whereCondition).First(&selectionInfo)
+	if result.Error != nil {
+		if errors.Is(result.Error, gorm.ErrRecordNotFound) {
+			return nil, nil
+		} else {
+			return nil, result.Error
+		}
+	}
+	return &selectionInfo, nil
+}
+
 func GetSelectionList(ctx context.Context, enterpriseID string, pageSize, pageNum int64, conditions *common_model.SelectionConditions) ([]*gorm_model.YounggeeSelectionInfo, int64, error) {
 func GetSelectionList(ctx context.Context, enterpriseID string, pageSize, pageNum int64, conditions *common_model.SelectionConditions) ([]*gorm_model.YounggeeSelectionInfo, int64, error) {
 	db := GetReadDB(ctx)
 	db := GetReadDB(ctx)
 	db = db.Debug().Model(gorm_model.YounggeeSelectionInfo{}).Where("enterprise_id = ?", enterpriseID)
 	db = db.Debug().Model(gorm_model.YounggeeSelectionInfo{}).Where("enterprise_id = ?", enterpriseID)
@@ -81,17 +132,6 @@ func GetSelectionList(ctx context.Context, enterpriseID string, pageSize, pageNu
 	return newSelectionInfos, total, nil
 	return newSelectionInfos, total, nil
 }
 }
 
 
-func GetSelectionInfo(ctx context.Context, selectionId string) (*gorm_model.YounggeeSelectionInfo, error) {
-	db := GetReadDB(ctx)
-	selectionInfo := gorm_model.YounggeeSelectionInfo{}
-	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id = ?", selectionId).Find(&selectionInfo).Error
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetSelectionList] error query mysql total, err:%+v", err)
-		return nil, err
-	}
-	return &selectionInfo, nil
-}
-
 func GetSelectionBriefInfo(ctx context.Context, selectionId string) ([]*gorm_model.YounggeeSecBrief, error) {
 func GetSelectionBriefInfo(ctx context.Context, selectionId string) ([]*gorm_model.YounggeeSecBrief, error) {
 	db := GetReadDB(ctx)
 	db := GetReadDB(ctx)
 	var selectionBriefInfos []*gorm_model.YounggeeSecBrief
 	var selectionBriefInfos []*gorm_model.YounggeeSecBrief
@@ -114,36 +154,32 @@ func GetSelectionExampleInfo(ctx context.Context, selectionId string) ([]*gorm_m
 	return selectionExampleInfos, nil
 	return selectionExampleInfos, nil
 }
 }
 
 
-func GetProductInfo(ctx context.Context, selectionId string) (*gorm_model.YounggeeProduct, error) {
-	db := GetReadDB(ctx)
-	productId := 0
-	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Select("product_id").Where("selection_id = ?", selectionId).Find(&productId).Error
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
-		return nil, err
-	}
-	productInfo := gorm_model.YounggeeProduct{}
-	err = db.Model(gorm_model.YounggeeProduct{}).Where("product_id = ?", productId).Find(&productInfo).Error
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
-		return nil, err
-	}
-	return &productInfo, nil
-}
+func PaySelection(ctx context.Context, enterpriseId string, payMoney float64, selectionId string) error {
+	db := GetWriteDB(ctx)
+	err := db.Transaction(func(tx *gorm.DB) error {
+		// 1. 冻结账户余额
+		whereCondition := gorm_model.Enterprise{
+			EnterpriseID: enterpriseId,
+		}
+		updateData := map[string]interface{}{
+			"frozen_balance":    gorm.Expr("frozen_balance + ?", payMoney),
+			"available_balance": gorm.Expr("available_balance - ?", payMoney)}
+		if err := tx.Model(gorm_model.Enterprise{}).Where(whereCondition).Updates(updateData).Error; err != nil {
+			return err
+		}
 
 
-func GetProductPhotoInfo(ctx context.Context, selectionId string) ([]*gorm_model.YounggeeProductPhoto, error) {
-	db := GetReadDB(ctx)
-	productId := 0
-	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Select("product_id").Where("selection_id = ?", selectionId).Find(&productId).Error
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
-		return nil, err
-	}
-	var productPhotoInfo []*gorm_model.YounggeeProductPhoto
-	err = db.Model(gorm_model.YounggeeProductPhoto{}).Where("product_id = ?", productId).Find(&productPhotoInfo).Error
+		// 2. 更新选品项目状态
+		whereCondition1 := gorm_model.YounggeeSelectionInfo{SelectionID: selectionId, SelectionStatus: 4}
+		updateData1 := gorm_model.YounggeeSelectionInfo{SelectionStatus: 6}
+		if err := tx.Model(gorm_model.YounggeeSelectionInfo{}).Where(whereCondition1).Updates(updateData1).Error; err != nil {
+			return err
+		}
+
+		// 返回 nil 提交事务
+		return nil
+	})
 	if err != nil {
 	if err != nil {
-		logrus.WithContext(ctx).Errorf("[GetProductInfo] error query mysql, err:%+v", err)
-		return nil, err
+		return err
 	}
 	}
-	return productPhotoInfo, nil
+	return nil
 }
 }

+ 23 - 0
db/talent_income.go

@@ -0,0 +1,23 @@
+package db
+
+import (
+	"context"
+	"gorm.io/gorm"
+	"youngee_b_api/model/gorm_model"
+)
+
+func CreateIncome(ctx context.Context, income gorm_model.YounggeeTalentIncome, tx *gorm.DB) error {
+	if tx != nil {
+		err := tx.Create(&income).Error
+		if err != nil {
+			return err
+		}
+	} else {
+		db := GetWriteDB(ctx)
+		err := db.Create(&income).Error
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}

+ 52 - 1
db/task.go

@@ -2,6 +2,7 @@ package db
 
 
 import (
 import (
 	"context"
 	"context"
+	"encoding/json"
 	"fmt"
 	"fmt"
 	"reflect"
 	"reflect"
 	"strconv"
 	"strconv"
@@ -161,7 +162,6 @@ func SetTaskFinish(ctx context.Context, TaskIDs []string) error {
 		return err
 		return err
 	}
 	}
 
 
-	// 2. 修改招募策略表,更新粉丝量、播放量、点赞数、收藏数、评论数、总支付、结案数量
 	for _, v := range TaskIDs {
 	for _, v := range TaskIDs {
 		// 查询task_info
 		// 查询task_info
 		db = GetReadDB(ctx)
 		db = GetReadDB(ctx)
@@ -171,6 +171,13 @@ func SetTaskFinish(ctx context.Context, TaskIDs []string) error {
 			logrus.WithContext(ctx).Errorf("[Task db] Find YoungeeTaskInfo error,err:%+v", err)
 			logrus.WithContext(ctx).Errorf("[Task db] Find YoungeeTaskInfo error,err:%+v", err)
 			return err1
 			return err1
 		}
 		}
+		//查询project_info
+		projectInfo := gorm_model.ProjectInfo{}
+		err1 = db.Model(gorm_model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectID).Scan(&projectInfo).Error
+		if err1 != nil {
+			logrus.WithContext(ctx).Errorf("[Task db] Find ProjectInfo error,err:%+v", err)
+			return err1
+		}
 		// 查询data_info
 		// 查询data_info
 		db = GetReadDB(ctx)
 		db = GetReadDB(ctx)
 		dataInfo := gorm_model.YounggeeDataInfo{}
 		dataInfo := gorm_model.YounggeeDataInfo{}
@@ -180,6 +187,30 @@ func SetTaskFinish(ctx context.Context, TaskIDs []string) error {
 			return err1
 			return err1
 		}
 		}
 
 
+		// 2. 创建任务收益
+		var productStruct gorm_model.YounggeeProduct
+		if err = json.Unmarshal([]byte(projectInfo.ProductSnap), &productStruct); err != nil {
+			fmt.Println("Error:", err)
+			return err
+		}
+		income := gorm_model.YounggeeTalentIncome{
+			TalentID:       taskInfo.TalentID,
+			ProjectID:      taskInfo.ProjectID,
+			SectaskID:      taskInfo.TaskID,
+			BrandName:      productStruct.BrandName,
+			TaskName:       projectInfo.ProjectName,
+			Income:         strconv.FormatFloat(taskInfo.SettleAmount, 'f', 10, 32),
+			IncomeType:     1,
+			WithdrawStatus: 1,
+			IncomeAt:       time.Now(),
+		}
+		err = CreateIncome(ctx, income, nil)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
+			return err
+		}
+
+		// 3. 修改招募策略表,更新粉丝量、播放量、点赞数、收藏数、评论数、总支付、结案数量
 		// 更新招募策略
 		// 更新招募策略
 		db = GetReadDB(ctx)
 		db = GetReadDB(ctx)
 		db = db.Model(gorm_model.RecruitStrategy{}).Where("project_id = ? and strategy_id = ?", taskInfo.ProjectID, taskInfo.StrategyID)
 		db = db.Model(gorm_model.RecruitStrategy{}).Where("project_id = ? and strategy_id = ?", taskInfo.ProjectID, taskInfo.StrategyID)
@@ -327,3 +358,23 @@ func GetTaskIds(ctx context.Context, projectId string) ([]string, error) {
 
 
 	return taskIds, nil
 	return taskIds, nil
 }
 }
+
+func UpdateTask(ctx context.Context, updateData gorm_model.YoungeeTaskInfo, tx *gorm.DB) (bool, error) {
+	db := GetWriteDB(ctx)
+	whereCondition := gorm_model.YoungeeTaskInfo{
+		TaskID: updateData.TaskID,
+	}
+	if tx != nil {
+		err := tx.Where(whereCondition).Updates(&updateData).Error
+		if err != nil {
+			return false, err
+		}
+	} else {
+		err := db.Where(whereCondition).Updates(&updateData).Error
+		if err != nil {
+			return false, err
+		}
+	}
+
+	return true, nil
+}

+ 1 - 0
go.mod

@@ -9,6 +9,7 @@ require (
 )
 )
 
 
 require (
 require (
+	github.com/caixw/lib.go v0.0.0-20141220110639-1781da9139e0
 	github.com/go-openapi/swag v0.21.1 // indirect
 	github.com/go-openapi/swag v0.21.1 // indirect
 	github.com/go-playground/validator/v10 v10.10.1 // indirect
 	github.com/go-playground/validator/v10 v10.10.1 // indirect
 	github.com/go-redis/redis/v8 v8.11.5
 	github.com/go-redis/redis/v8 v8.11.5

+ 2 - 0
go.sum

@@ -11,6 +11,8 @@ github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3
 github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
 github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
 github.com/agiledragon/gomonkey/v2 v2.3.1 h1:k+UnUY0EMNYUFUAQVETGY9uUTxjMdnUkP0ARyJS1zzs=
 github.com/agiledragon/gomonkey/v2 v2.3.1 h1:k+UnUY0EMNYUFUAQVETGY9uUTxjMdnUkP0ARyJS1zzs=
 github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
 github.com/agiledragon/gomonkey/v2 v2.3.1/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
+github.com/caixw/lib.go v0.0.0-20141220110639-1781da9139e0 h1:MnIURgMAFAMyxAHu8h2TbnjxMMd7SKVCPyTZz5EfwNA=
+github.com/caixw/lib.go v0.0.0-20141220110639-1781da9139e0/go.mod h1:hQL8hyiiVE/BSo7gh13njx+DpvoPh/yE8/BkKKc62RA=
 github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
 github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
 github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
 github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
 github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=

+ 60 - 0
handler/CreateSecTaskLogistics.go

@@ -0,0 +1,60 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/sectask_service"
+	"youngee_b_api/util"
+
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+)
+
+func WrapCreateSecTaskLogisticsHandler(ctx *gin.Context) {
+	handler := newCreateSecTaskLogisticsHandler(ctx)
+	baseRun(handler)
+}
+
+type CreateSecTaskLogistics struct {
+	ctx  *gin.Context
+	req  *http_model.CreateSecTaskLogisticsRequest
+	resp *http_model.CommonResponse
+}
+
+func (c CreateSecTaskLogistics) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c CreateSecTaskLogistics) getResponse() interface{} {
+	return c.resp
+}
+
+func (c CreateSecTaskLogistics) getRequest() interface{} {
+	return c.req
+}
+
+func (c CreateSecTaskLogistics) run() {
+	data := http_model.CreateSecTaskLogisticsRequest{}
+	data = *c.req
+	res, err := sectask_service.Logistics.Create(c.ctx, data)
+	if err != nil {
+		logrus.Errorf("[CreateSecTaskLogistics] call CreateSecTaskLogistics err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("CreateSecTaskLogistics fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功添加发货信息"
+	c.resp.Data = res
+}
+
+func (c CreateSecTaskLogistics) checkParam() error {
+	return nil
+}
+
+func newCreateSecTaskLogisticsHandler(ctx *gin.Context) *CreateSecTaskLogistics {
+	return &CreateSecTaskLogistics{
+		ctx:  ctx,
+		req:  http_model.NewCreateSecTaskLogisticsRequest(),
+		resp: http_model.NewCreateSecTaskLogisticsResponse(),
+	}
+}

+ 62 - 0
handler/CreateSelection.go

@@ -0,0 +1,62 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/selection_service"
+	"youngee_b_api/util"
+)
+
+func WrapCreateSelectionHandler(ctx *gin.Context) {
+	handler := newCreateSelectionHandler(ctx)
+	baseRun(handler)
+}
+
+type CreateSelection struct {
+	ctx  *gin.Context
+	req  *http_model.CreateSelectionRequest
+	resp *http_model.CommonResponse
+}
+
+func (c CreateSelection) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c CreateSelection) getResponse() interface{} {
+	return c.resp
+}
+
+func (c CreateSelection) getRequest() interface{} {
+	return c.req
+}
+
+func (c CreateSelection) run() {
+	data := http_model.CreateSelectionRequest{}
+	data = *c.req
+	auth := middleware.GetSessionAuth(c.ctx)
+	enterpriseID := auth.EnterpriseID
+	res, err := selection_service.Selection.Create(c.ctx, data, enterpriseID)
+	if err != nil {
+		logrus.Errorf("[CreateSelection] call CreateSelection err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("CreateSelection fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功创建选品"
+	c.resp.Data = res
+}
+
+func (c CreateSelection) checkParam() error {
+	return nil
+}
+
+func newCreateSelectionHandler(ctx *gin.Context) *CreateSelection {
+	return &CreateSelection{
+		ctx:  ctx,
+		req:  http_model.NewCreateSelectionRequest(),
+		resp: http_model.NewCreateSelectionResponse(),
+	}
+}

+ 61 - 0
handler/GetSecTaskList.go

@@ -0,0 +1,61 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/sectask_service"
+	"youngee_b_api/util"
+)
+
+func WrapGetSecTaskListHandler(ctx *gin.Context) {
+	handler := newGetSecTaskListHandler(ctx)
+	baseRun(handler)
+}
+
+type GetSecTaskList struct {
+	ctx  *gin.Context
+	req  *http_model.GetSecTaskListRequest
+	resp *http_model.CommonResponse
+}
+
+func (c GetSecTaskList) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c GetSecTaskList) getResponse() interface{} {
+	return c.resp
+}
+
+func (c GetSecTaskList) getRequest() interface{} {
+	return c.req
+}
+
+func (c GetSecTaskList) run() {
+	data := http_model.GetSecTaskListRequest{}
+	data = *c.req
+	//auth := middleware.GetSessionAuth(c.ctx)
+	//enterpriseID := auth.EnterpriseID
+	res, err := sectask_service.SelectionTask.GetList(c.ctx, data)
+	if err != nil {
+		logrus.Errorf("[GetSecTaskList] call GetSecTaskList err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("GetSecTaskList fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功查询选品任务"
+	c.resp.Data = res
+}
+
+func (c GetSecTaskList) checkParam() error {
+	return nil
+}
+
+func newGetSecTaskListHandler(ctx *gin.Context) *GetSecTaskList {
+	return &GetSecTaskList{
+		ctx:  ctx,
+		req:  http_model.NewGetSecTaskListRequest(),
+		resp: http_model.NewGetSecTaskListResponse(),
+	}
+}

+ 61 - 0
handler/PassSecTaskCoop.go

@@ -0,0 +1,61 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/sectask_service"
+	"youngee_b_api/util"
+)
+
+func WrapPassSecTaskCoopHandler(ctx *gin.Context) {
+	handler := newPassSecTaskCoopHandler(ctx)
+	baseRun(handler)
+}
+
+type PassSecTaskCoop struct {
+	ctx  *gin.Context
+	req  *http_model.PassSecTaskCoopRequest
+	resp *http_model.CommonResponse
+}
+
+func (c PassSecTaskCoop) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c PassSecTaskCoop) getResponse() interface{} {
+	return c.resp
+}
+
+func (c PassSecTaskCoop) getRequest() interface{} {
+	return c.req
+}
+
+func (c PassSecTaskCoop) run() {
+	data := http_model.PassSecTaskCoopRequest{}
+	data = *c.req
+	//auth := middleware.GetSessionAuth(c.ctx)
+	//enterpriseID := auth.EnterpriseID
+	res, err := sectask_service.SelectionTask.PassCoop(c.ctx, data)
+	if err != nil {
+		logrus.Errorf("[PassSecTaskCoop] call PassSecTaskCoop err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("PassSecTaskCoop fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功合作选品任务"
+	c.resp.Data = res
+}
+
+func (c PassSecTaskCoop) checkParam() error {
+	return nil
+}
+
+func newPassSecTaskCoopHandler(ctx *gin.Context) *PassSecTaskCoop {
+	return &PassSecTaskCoop{
+		ctx:  ctx,
+		req:  http_model.NewPassSecTaskCoopRequest(),
+		resp: http_model.NewPassSecTaskCoopResponse(),
+	}
+}

+ 62 - 0
handler/PaySelection.go

@@ -0,0 +1,62 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/selection_service"
+	"youngee_b_api/util"
+)
+
+func WrapPaySelectionHandler(ctx *gin.Context) {
+	handler := newPaySelectionHandler(ctx)
+	baseRun(handler)
+}
+
+type PaySelection struct {
+	ctx  *gin.Context
+	req  *http_model.PaySelectionRequest
+	resp *http_model.CommonResponse
+}
+
+func (c PaySelection) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c PaySelection) getResponse() interface{} {
+	return c.resp
+}
+
+func (c PaySelection) getRequest() interface{} {
+	return c.req
+}
+
+func (c PaySelection) run() {
+	data := http_model.PaySelectionRequest{}
+	data = *c.req
+	auth := middleware.GetSessionAuth(c.ctx)
+	enterpriseID := auth.EnterpriseID
+	res, err := selection_service.Selection.Pay(c.ctx, data, enterpriseID)
+	if err != nil {
+		logrus.Errorf("[PaySelection] call PaySelection err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("PaySelection fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "支付成功"
+	c.resp.Data = res
+}
+
+func (c PaySelection) checkParam() error {
+	return nil
+}
+
+func newPaySelectionHandler(ctx *gin.Context) *PaySelection {
+	return &PaySelection{
+		ctx:  ctx,
+		req:  http_model.NewPaySelectionRequest(),
+		resp: http_model.NewPaySelectionResponse(),
+	}
+}

+ 61 - 0
handler/RefuseSecTaskCoop.go

@@ -0,0 +1,61 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/sectask_service"
+	"youngee_b_api/util"
+)
+
+func WrapRefuseSecTaskCoopHandler(ctx *gin.Context) {
+	handler := newRefuseSecTaskCoopHandler(ctx)
+	baseRun(handler)
+}
+
+type RefuseSecTaskCoop struct {
+	ctx  *gin.Context
+	req  *http_model.RefuseSecTaskCoopRequest
+	resp *http_model.CommonResponse
+}
+
+func (c RefuseSecTaskCoop) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c RefuseSecTaskCoop) getResponse() interface{} {
+	return c.resp
+}
+
+func (c RefuseSecTaskCoop) getRequest() interface{} {
+	return c.req
+}
+
+func (c RefuseSecTaskCoop) run() {
+	data := http_model.RefuseSecTaskCoopRequest{}
+	data = *c.req
+	//auth := middleware.GetSessionAuth(c.ctx)
+	//enterpriseID := auth.EnterpriseID
+	res, err := sectask_service.SelectionTask.RefuseCoop(c.ctx, data)
+	if err != nil {
+		logrus.Errorf("[RefuseSecTaskCoop] call RefuseSecTaskCoop err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("RefuseSecTaskCoop fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功拒绝选品任务"
+	c.resp.Data = res
+}
+
+func (c RefuseSecTaskCoop) checkParam() error {
+	return nil
+}
+
+func newRefuseSecTaskCoopHandler(ctx *gin.Context) *RefuseSecTaskCoop {
+	return &RefuseSecTaskCoop{
+		ctx:  ctx,
+		req:  http_model.NewRefuseSecTaskCoopRequest(),
+		resp: http_model.NewRefuseSecTaskCoopResponse(),
+	}
+}

+ 62 - 0
handler/SettleSecTask.go

@@ -0,0 +1,62 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/sectask_service"
+	"youngee_b_api/util"
+
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+)
+
+func WrapSettleSecTaskHandler(ctx *gin.Context) {
+	handler := newSettleSecTaskHandler(ctx)
+	baseRun(handler)
+}
+
+type SettleSecTask struct {
+	ctx  *gin.Context
+	req  *http_model.SettleSecTaskRequest
+	resp *http_model.CommonResponse
+}
+
+func (c SettleSecTask) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c SettleSecTask) getResponse() interface{} {
+	return c.resp
+}
+
+func (c SettleSecTask) getRequest() interface{} {
+	return c.req
+}
+
+func (c SettleSecTask) run() {
+	enterpriseID := middleware.GetSessionAuth(c.ctx).EnterpriseID
+	data := http_model.SettleSecTaskRequest{}
+	data = *c.req
+	res, err := sectask_service.SelectionTask.Settle(c.ctx, enterpriseID, data)
+	if err != nil {
+		logrus.Errorf("[SettleSecTask] call SettleSecTask err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("SettleSecTask fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功添加发货信息"
+	c.resp.Data = res
+}
+
+func (c SettleSecTask) checkParam() error {
+	return nil
+}
+
+func newSettleSecTaskHandler(ctx *gin.Context) *SettleSecTask {
+	return &SettleSecTask{
+		ctx:  ctx,
+		req:  http_model.NewSettleSecTaskRequest(),
+		resp: http_model.NewSettleSecTaskResponse(),
+	}
+}

+ 60 - 0
handler/UpdateSecTaskLogistics.go

@@ -0,0 +1,60 @@
+package handler
+
+import (
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/sectask_service"
+	"youngee_b_api/util"
+
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+)
+
+func WrapUpdateSecTaskLogisticsHandler(ctx *gin.Context) {
+	handler := newUpdateSecTaskLogisticsHandler(ctx)
+	baseRun(handler)
+}
+
+type UpdateSecTaskLogistics struct {
+	ctx  *gin.Context
+	req  *http_model.UpdateSecTaskLogisticsRequest
+	resp *http_model.CommonResponse
+}
+
+func (c UpdateSecTaskLogistics) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c UpdateSecTaskLogistics) getResponse() interface{} {
+	return c.resp
+}
+
+func (c UpdateSecTaskLogistics) getRequest() interface{} {
+	return c.req
+}
+
+func (c UpdateSecTaskLogistics) run() {
+	data := http_model.UpdateSecTaskLogisticsRequest{}
+	data = *c.req
+	res, err := sectask_service.Logistics.Update(c.ctx, data)
+	if err != nil {
+		logrus.Errorf("[UpdateSecTaskLogistics] call UpdateSecTaskLogistics err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("UpdateSecTaskLogistics fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功添加发货信息"
+	c.resp.Data = res
+}
+
+func (c UpdateSecTaskLogistics) checkParam() error {
+	return nil
+}
+
+func newUpdateSecTaskLogisticsHandler(ctx *gin.Context) *UpdateSecTaskLogistics {
+	return &UpdateSecTaskLogistics{
+		ctx:  ctx,
+		req:  http_model.NewUpdateSecTaskLogisticsRequest(),
+		resp: http_model.NewUpdateSecTaskLogisticsResponse(),
+	}
+}

+ 62 - 0
handler/UpdateSelection.go

@@ -0,0 +1,62 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service/selection_service"
+	"youngee_b_api/util"
+)
+
+func WrapUpdateSelectionHandler(ctx *gin.Context) {
+	handler := newUpdateSelectionHandler(ctx)
+	baseRun(handler)
+}
+
+type UpdateSelection struct {
+	ctx  *gin.Context
+	req  *http_model.UpdateSelectionRequest
+	resp *http_model.CommonResponse
+}
+
+func (c UpdateSelection) getContext() *gin.Context {
+	return c.ctx
+}
+
+func (c UpdateSelection) getResponse() interface{} {
+	return c.resp
+}
+
+func (c UpdateSelection) getRequest() interface{} {
+	return c.req
+}
+
+func (c UpdateSelection) run() {
+	data := http_model.UpdateSelectionRequest{}
+	data = *c.req
+	auth := middleware.GetSessionAuth(c.ctx)
+	enterpriseID := auth.EnterpriseID
+	res, err := selection_service.Selection.Update(c.ctx, data, enterpriseID)
+	if err != nil {
+		logrus.Errorf("[UpdateSelection] call UpdateSelection err:%+v\n", err)
+		util.HandlerPackErrorResp(c.resp, consts.ErrorInternal, "")
+		logrus.Info("UpdateSelection fail,req:%+v", c.req)
+		return
+	}
+	c.resp.Message = "成功创建选品"
+	c.resp.Data = res
+}
+
+func (c UpdateSelection) checkParam() error {
+	return nil
+}
+
+func newUpdateSelectionHandler(ctx *gin.Context) *UpdateSelection {
+	return &UpdateSelection{
+		ctx:  ctx,
+		req:  http_model.NewUpdateSelectionRequest(),
+		resp: http_model.NewUpdateSelectionResponse(),
+	}
+}

+ 4 - 4
handler/selection_detail.go

@@ -1,12 +1,12 @@
 package handler
 package handler
 
 
 import (
 import (
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/gin-gonic/gin"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 	"youngee_b_api/consts"
 	"youngee_b_api/consts"
+	"youngee_b_api/middleware"
 	"youngee_b_api/model/http_model"
 	"youngee_b_api/model/http_model"
-	"youngee_b_api/service"
+	"youngee_b_api/service/selection_service"
 	"youngee_b_api/util"
 	"youngee_b_api/util"
 )
 )
 
 
@@ -34,8 +34,8 @@ func (s SelectionDetailHandler) getRequest() interface{} {
 }
 }
 
 
 func (s SelectionDetailHandler) run() {
 func (s SelectionDetailHandler) run() {
-	fmt.Println("SelectionId:", s.req.SelectionId)
-	res, err := service.Selection.GetSelectionDetail(s.ctx, s.req.SelectionId)
+	enterpriseID := middleware.GetSessionAuth(s.ctx).EnterpriseID
+	res, err := selection_service.Selection.GetSelectionDetail(s.ctx, s.req.SelectionId, enterpriseID)
 	if err != nil {
 	if err != nil {
 		logrus.Errorf("[GetSelectionDetail] call Show err:%+v\n", err)
 		logrus.Errorf("[GetSelectionDetail] call Show err:%+v\n", err)
 		util.HandlerPackErrorResp(s.resp, consts.ErrorInternal, "")
 		util.HandlerPackErrorResp(s.resp, consts.ErrorInternal, "")

+ 2 - 2
handler/selection_find_all.go

@@ -9,7 +9,7 @@ import (
 	"youngee_b_api/middleware"
 	"youngee_b_api/middleware"
 	"youngee_b_api/model/http_model"
 	"youngee_b_api/model/http_model"
 	"youngee_b_api/pack"
 	"youngee_b_api/pack"
-	"youngee_b_api/service"
+	"youngee_b_api/service/selection_service"
 	"youngee_b_api/util"
 	"youngee_b_api/util"
 )
 )
 
 
@@ -39,7 +39,7 @@ func (f FindAllSelectionHandler) getRequest() interface{} {
 func (f FindAllSelectionHandler) run() {
 func (f FindAllSelectionHandler) run() {
 	enterpriseID := middleware.GetSessionAuth(f.ctx).EnterpriseID
 	enterpriseID := middleware.GetSessionAuth(f.ctx).EnterpriseID
 	condition := pack.HttpFindAllSelectionRequestToCondition(f.req)
 	condition := pack.HttpFindAllSelectionRequestToCondition(f.req)
-	data, err := service.Selection.GetAllSelection(f.ctx, enterpriseID, f.req.PageSize, f.req.PageNum, condition)
+	data, err := selection_service.Selection.GetAllSelection(f.ctx, enterpriseID, f.req.PageSize, f.req.PageNum, condition)
 	if err != nil {
 	if err != nil {
 		logrus.WithContext(f.ctx).Errorf("[FindAllSelectionHandler] error GetAllSelection, err:%+v", err)
 		logrus.WithContext(f.ctx).Errorf("[FindAllSelectionHandler] error GetAllSelection, err:%+v", err)
 		util.HandlerPackErrorResp(f.resp, consts.ErrorInternal, consts.DefaultToast)
 		util.HandlerPackErrorResp(f.resp, consts.ErrorInternal, consts.DefaultToast)

+ 29 - 0
model/gorm_model/talent_income.go

@@ -0,0 +1,29 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+import (
+"time"
+)
+
+type YounggeeTalentIncome struct {
+	ID             int       `gorm:"column:id;primary_key"`  // 递增id
+	TalentID       string    `gorm:"column:talent_id"`       // 达人id,对应youngee_talent_info中id字段
+	ProjectID      string    `gorm:"column:project_id"`      // 项目id
+	SelectionID    string    `gorm:"column:selection_id"`    // 选品id
+	TaskID         string    `gorm:"column:task_id"`         // 任务id
+	SectaskID      string    `gorm:"column:sectask_id"`      // 选品任务id
+	BrandName      string    `gorm:"column:brand_name"`      // 品牌名称
+	TaskName       string    `gorm:"column:task_name"`       // 任务名称
+	TeamID         string    `gorm:"column:team_id"`         // young之团id
+	Income         string    `gorm:"column:income"`          // 收益金额
+	IncomeType     int       `gorm:"column:income_type"`     // 收益类型,1-4分别表示任务收益、开团收益、样品返现、悬赏收益
+	WithdrawStatus int       `gorm:"column:withdraw_status"` // 提现状态,1-3分别表示可提现、提现中、已提现
+	IncomeAt       time.Time `gorm:"column:income_at"`       // 收益产生时间
+	WithdrawAt     time.Time `gorm:"column:withdraw_at"`     // 提现时间
+}
+
+func (m *YounggeeTalentIncome) TableName() string {
+	return "younggee_talent_income"
+}
+
+

+ 24 - 0
model/http_model/CreateSecTaskLogistics.go

@@ -0,0 +1,24 @@
+package http_model
+
+type CreateSecTaskLogisticsRequest struct {
+	TaskID                string `json:"task_id"`                // 任务id
+	CompanyName           string `json:"company_name"`           // 实物商品-物流公司名称
+	LogisticsNumber       string `json:"logistics_number"`       // 实物商品-物流单号
+	ExplorestoreStarttime string `json:"explorestore_starttime"` // 线下探店-探店开始时间
+	ExplorestoreEndtime   string `json:"explorestore_endtime"`   // 线下探店-探店结束时间
+	ExplorestorePeriod    string `json:"explorestore_period"`    // 线下探店-探店持续时间
+	ThingsType            int    `json:"things_type"`            // 产品类型 1:实物, 3:线下探店
+}
+
+type CreateSecTaskLogisticsData struct {
+}
+
+func NewCreateSecTaskLogisticsRequest() *CreateSecTaskLogisticsRequest {
+	return new(CreateSecTaskLogisticsRequest)
+}
+
+func NewCreateSecTaskLogisticsResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(CreateSecTaskLogisticsData)
+	return resp
+}

+ 20 - 0
model/http_model/CreateSelection.go

@@ -0,0 +1,20 @@
+package http_model
+
+type CreateSelectionRequest struct {
+	Platform  string `json:"platform"`
+	ProductId string `json:"product_id"`
+}
+
+type CreateSelectionData struct {
+	SelectionId string `json:"selection_id"`
+}
+
+func NewCreateSelectionRequest() *CreateSelectionRequest {
+	return new(CreateSelectionRequest)
+}
+
+func NewCreateSelectionResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(CreateSelectionData)
+	return resp
+}

+ 38 - 0
model/http_model/GetSecTaskList.go

@@ -0,0 +1,38 @@
+package http_model
+
+import (
+	"time"
+)
+
+type GetSecTaskListRequest struct {
+	PageSize      int64  `json:"page_size"`
+	PageNum       int64  `json:"page_num"`
+	SelectionId   string `json:"selection_id"`
+	SecTaskStatus int    `json:"sec_task_status"`
+	SearchValue   string `json:"search_value"`
+}
+
+type GetSecTaskListData struct {
+	SecTaskList []*SecTaskInfo `json:"sec_task_list"`
+	Total       string         `json:"total"`
+}
+
+type SecTaskInfo struct {
+	SelectionId        string    `json:"selection_id"`
+	PlatformNickname   string    `json:"platform_nickname"`                            // 帐号昵称
+	FansCount          string    `json:"fans_count"`                                   // 粉丝数
+	HomePageCaptureUrl string    `json:"home_page_capture_url"`                        // 主页截图链接
+	HomePageUrl        string    `json:"home_page_url"`                                // 主页链接
+	CreateDate         time.Time `json:"column:create_date;default:CURRENT_TIMESTAMP"` // 创建时间
+	SelectDate         time.Time `json:"column:select_date"`                           // 反选时间
+}
+
+func NewGetSecTaskListRequest() *GetSecTaskListRequest {
+	return new(GetSecTaskListRequest)
+}
+
+func NewGetSecTaskListResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(GetSecTaskListData)
+	return resp
+}

+ 19 - 0
model/http_model/PassSecTaskCoop.go

@@ -0,0 +1,19 @@
+package http_model
+
+type PassSecTaskCoopRequest struct {
+	SelectionId string   `json:"selection_id"`
+	TaskIds     []string `json:"task_ids"`
+}
+
+type PassSecTaskCoopData struct {
+}
+
+func NewPassSecTaskCoopRequest() *PassSecTaskCoopRequest {
+	return new(PassSecTaskCoopRequest)
+}
+
+func NewPassSecTaskCoopResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(PassSecTaskCoopData)
+	return resp
+}

+ 20 - 0
model/http_model/PaySelection.go

@@ -0,0 +1,20 @@
+package http_model
+
+type PaySelectionRequest struct {
+	PayMoney    float64 `json:"pay_money"`
+	SelectionId string  `json:"selection_id"`
+}
+
+type PaySelectionData struct {
+	SelectionId string `json:"selection_id"`
+}
+
+func NewPaySelectionRequest() *PaySelectionRequest {
+	return new(PaySelectionRequest)
+}
+
+func NewPaySelectionResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(PaySelectionData)
+	return resp
+}

+ 18 - 0
model/http_model/RefuseSecTaskCoop.go

@@ -0,0 +1,18 @@
+package http_model
+
+type RefuseSecTaskCoopRequest struct {
+	TaskIds []string `json:"task_ids"`
+}
+
+type RefuseSecTaskCoopData struct {
+}
+
+func NewRefuseSecTaskCoopRequest() *RefuseSecTaskCoopRequest {
+	return new(RefuseSecTaskCoopRequest)
+}
+
+func NewRefuseSecTaskCoopResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(RefuseSecTaskCoopData)
+	return resp
+}

+ 22 - 0
model/http_model/SettleSecTask.go

@@ -0,0 +1,22 @@
+package http_model
+
+type SettleSecTaskRequest struct {
+	SelectionID   string `json:"selection_id"`    // 选品项目id
+	TaskID        string `json:"task_id"`         // 任务id
+	IsReturnMoney int    `json:"is_return_money"` //是否返回样品钱
+	IsPayReward   int    `json:"is_pay_reward"`   //是否给悬赏金
+	TotalPayMoney string `json:"total_pay_money"` //合计结算金额
+}
+
+type SettleSecTaskData struct {
+}
+
+func NewSettleSecTaskRequest() *SettleSecTaskRequest {
+	return new(SettleSecTaskRequest)
+}
+
+func NewSettleSecTaskResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(SettleSecTaskData)
+	return resp
+}

+ 25 - 0
model/http_model/UpdateSecTaskLogistics.go

@@ -0,0 +1,25 @@
+package http_model
+
+type UpdateSecTaskLogisticsRequest struct {
+	TaskID                string `json:"task_id"`                // 任务id
+	LogisticsId           int64  `json:"logistics_id"`           // 物流信息id
+	CompanyName           string `json:"company_name"`           // 实物商品-物流公司名称
+	LogisticsNumber       string `json:"logistics_number"`       // 实物商品-物流单号
+	ExplorestoreStarttime string `json:"explorestore_starttime"` // 线下探店-探店开始时间
+	ExplorestoreEndtime   string `json:"explorestore_endtime"`   // 线下探店-探店结束时间
+	ExplorestorePeriod    string `json:"explorestore_period"`    // 线下探店-探店持续时间
+	ThingsType            int    `json:"things_type"`            // 产品类型 1:实物, 3:线下探店
+}
+
+type UpdateSecTaskLogisticsData struct {
+}
+
+func NewUpdateSecTaskLogisticsRequest() *UpdateSecTaskLogisticsRequest {
+	return new(UpdateSecTaskLogisticsRequest)
+}
+
+func NewUpdateSecTaskLogisticsResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(UpdateSecTaskLogisticsData)
+	return resp
+}

+ 47 - 0
model/http_model/UpdateSelection.go

@@ -0,0 +1,47 @@
+package http_model
+
+type UpdateSelectionRequest struct {
+	SelectionID     string            `json:"selection_id"` // 选品项目id
+	Platform        string            `json:"platform"`
+	ProductId       int               `json:"product_id"`
+	ContentType     int               `json:"content_type"`
+	TaskMode        int               `json:"task_mode"`
+	SampleNum       int               `json:"sample_num"`  // 样品数量
+	RemainNum       int               `json:"remain_num"`  // 剩余数量
+	TaskReward      float64           `json:"task_reward"` // 任务悬赏
+	TaskDdl         string            `json:"task_ddl"`
+	SampleMode      int               `json:"sample_mode"`
+	CommissionRate  int               `json:"commission_rate"`
+	ProductUrl      string            `json:"product_url"`
+	SampleCondition string            `json:"sample_condition"`
+	RewardCondition string            `json:"reward_condition"` // 返现悬赏条件
+	SecBrief        []*SecBriefInfo   `json:"sec_brief"`
+	SecExample      []*SecExampleInfo `json:"sec_example"`
+	Detail          string            `json:"detail"`
+}
+
+type SecBriefInfo struct {
+	FileUrl  string `json:"file_url"`
+	FileUid  string `json:"file_uid"`
+	FileName string `json:"file_name"`
+}
+
+type SecExampleInfo struct {
+	FileUrl  string `json:"file_url"`
+	FileUid  string `json:"file_uid"`
+	FileName string `json:"file_name"`
+}
+
+type UpdateSelectionData struct {
+	SelectionId string `json:"selection_id"`
+}
+
+func NewUpdateSelectionRequest() *UpdateSelectionRequest {
+	return new(UpdateSelectionRequest)
+}
+
+func NewUpdateSelectionResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(UpdateSelectionData)
+	return resp
+}

+ 10 - 10
model/http_model/logistics_create.go

@@ -1,18 +1,18 @@
 package http_model
 package http_model
 
 
 type CreateLogisticsRequest struct {
 type CreateLogisticsRequest struct {
-	StrategyID            int64     `json:"strategy_id"`             //招募策略id
-	LogisticsID           int64     `json:"logistics_id"`            // 货物-id
-	CompanyName           string    `json:"company_name"`            // 实物商品-物流公司名称
-	LogisticsNumber       string    `json:"logistics_number"`        // 实物商品-物流单号
+	StrategyID            int64  `json:"strategy_id"`             //招募策略id
+	LogisticsID           int64  `json:"logistics_id"`            // 货物-id
+	CompanyName           string `json:"company_name"`            // 实物商品-物流公司名称
+	LogisticsNumber       string `json:"logistics_number"`        // 实物商品-物流单号
 	ExplorestoreStarttime string `json:"explorestore_starttime"`  // 线下探店-探店开始时间
 	ExplorestoreStarttime string `json:"explorestore_starttime"`  // 线下探店-探店开始时间
 	ExplorestoreEndtime   string `json:"explorestore_endtime"`    // 线下探店-探店结束时间
 	ExplorestoreEndtime   string `json:"explorestore_endtime"`    // 线下探店-探店结束时间
-	ExplorestorePeriod    string    `json:"explorestore_period"`     // 线下探店-探店持续时间
-	CouponCodeInformation string    `json:"coupon_code_information"` // 虚拟产品-券码信息
-	TaskID                string    `json:"task_id"`                 // 任务id
-	DeliveryTime          string    `json:"delivery_time"`           // 发货时间
-	ThingsType            int       `json:"things_type"`             //产品类型 1:实物, 2:虚拟产品,3:线下探店
-	IsUpdate              int       `json:"is_update"`               //更新标志位 0:不更新 1:更新
+	ExplorestorePeriod    string `json:"explorestore_period"`     // 线下探店-探店持续时间
+	CouponCodeInformation string `json:"coupon_code_information"` // 虚拟产品-券码信息
+	TaskID                string `json:"task_id"`                 // 任务id
+	DeliveryTime          string `json:"delivery_time"`           // 发货时间
+	ThingsType            int    `json:"things_type"`             //产品类型 1:实物, 2:虚拟产品,3:线下探店
+	IsUpdate              int    `json:"is_update"`               //更新标志位 0:不更新 1:更新
 }
 }
 
 
 type CreateLogisticsData struct {
 type CreateLogisticsData struct {

+ 30 - 0
pack/sec_task_list.go

@@ -0,0 +1,30 @@
+package pack
+
+import (
+	"github.com/tidwall/gjson"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+
+	"github.com/caixw/lib.go/conv"
+)
+
+func GormSecTaskListToHttpSecTaskList(secTaskList []*gorm_model.YounggeeSecTaskInfo) []*http_model.SecTaskInfo {
+	var resTaskTaskList []*http_model.SecTaskInfo
+	for _, secTask := range secTaskList {
+		secTaskH := GormSecTaskToHttpSecTask(secTask)
+		resTaskTaskList = append(resTaskTaskList, secTaskH)
+	}
+	return resTaskTaskList
+}
+
+func GormSecTaskToHttpSecTask(secTask *gorm_model.YounggeeSecTaskInfo) *http_model.SecTaskInfo {
+	TalentPlatformInfoSnap := secTask.TalentPlatformInfoSnap
+	return &http_model.SecTaskInfo{
+		PlatformNickname:   conv.MustString(gjson.Get(TalentPlatformInfoSnap, "platform_nickname"), ""),
+		FansCount:          conv.MustString(gjson.Get(TalentPlatformInfoSnap, "fans_count"), ""),
+		HomePageCaptureUrl: conv.MustString(gjson.Get(TalentPlatformInfoSnap, "home_page_capture_url"), ""),
+		HomePageUrl:        conv.MustString(gjson.Get(TalentPlatformInfoSnap, "home_page_url"), ""),
+		CreateDate:         secTask.CreateDate,
+		SelectDate:         secTask.SelectDate,
+	}
+}

+ 12 - 3
route/init.go

@@ -138,8 +138,17 @@ func InitRoute(r *gin.Engine) {
 	s := r.Group("/youngee/s")
 	s := r.Group("/youngee/s")
 	{
 	{
 		s.Use(middleware.LoginAuthMiddleware)
 		s.Use(middleware.LoginAuthMiddleware)
-		s.POST("/selection/delete", handler.WrapDeleteSelectionHandler)   //删除选品
-		s.POST("/selection/findAll", handler.WrapFindAllSelectionHandler) //选品列表
-		s.POST("/selection/detail", handler.WrapSelectionDetailHandler)   //选品详情
+		s.POST("/selection/delete", handler.WrapDeleteSelectionHandler)                       //删除选品
+		s.POST("/selection/findAll", handler.WrapFindAllSelectionHandler)                     //选品列表
+		s.POST("/selection/detail", handler.WrapSelectionDetailHandler)                       //选品详情
+		s.POST("/selection/create", handler.WrapCreateSelectionHandler)                       // 创建选品
+		s.POST("/selection/update", handler.WrapUpdateSelectionHandler)                       // 更新选品
+		s.POST("/selection/pay", handler.WrapPaySelectionHandler)                             // 支付选品项目
+		s.POST("/selection/task/list", handler.WrapGetSecTaskListHandler)                     // 查询选品的任务列表
+		s.POST("/selection/task/coop/pass", handler.WrapPassSecTaskCoopHandler)               // 同意任务合作
+		s.POST("/selection/task/coop/refuse", handler.WrapRefuseSecTaskCoopHandler)           // 拒绝任务合作
+		s.POST("/selection/task/logistics/create", handler.WrapCreateSecTaskLogisticsHandler) // 上传物流信息
+		s.POST("/selection/task/logistics/update", handler.WrapUpdateSecTaskLogisticsHandler) // 修改物流信息
+		s.POST("/selection/task/settle", handler.WrapSettleSecTaskHandler)                    // 结算
 	}
 	}
 }
 }

+ 67 - 13
service/project_pay.go

@@ -2,15 +2,18 @@ package service
 
 
 import (
 import (
 	"context"
 	"context"
+	"encoding/json"
 	"errors"
 	"errors"
 	"fmt"
 	"fmt"
-	"github.com/gin-gonic/gin"
-	"gorm.io/gorm"
+	"strconv"
 	"time"
 	"time"
 	"youngee_b_api/db"
 	"youngee_b_api/db"
 	"youngee_b_api/model/gorm_model"
 	"youngee_b_api/model/gorm_model"
 	"youngee_b_api/model/http_model"
 	"youngee_b_api/model/http_model"
 
 
+	"github.com/gin-gonic/gin"
+	"gorm.io/gorm"
+
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 )
 )
 
 
@@ -101,8 +104,21 @@ func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequ
 func (p *projectPay) SpecialSettlePay(ctx *gin.Context, req *http_model.SpecialSettlePayRequest) error {
 func (p *projectPay) SpecialSettlePay(ctx *gin.Context, req *http_model.SpecialSettlePayRequest) error {
 	DB := db.GetReadDB(ctx)
 	DB := db.GetReadDB(ctx)
 	err := DB.Transaction(func(tx *gorm.DB) error {
 	err := DB.Transaction(func(tx *gorm.DB) error {
+		projectInfo := gorm_model.ProjectInfo{}
+		err := tx.Model(&gorm_model.ProjectInfo{}).Where("project_id = ?", req.ProjectID).First(&projectInfo).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
+			return err
+		}
+		task := gorm_model.YoungeeTaskInfo{}
+		err = tx.Model(&gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", req.TaskId).First(&task).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
+			return err
+		}
+		// 校验账户余额是否充足
 		var balance float64
 		var balance float64
-		err := tx.Model(&gorm_model.Enterprise{}).Select("balance").Where("enterprise_id = ?", req.EnterPriseId).Find(&balance).Error
+		err = tx.Model(&gorm_model.Enterprise{}).Select("balance").Where("enterprise_id = ?", req.EnterPriseId).Find(&balance).Error
 		if err != nil {
 		if err != nil {
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			return err
 			return err
@@ -111,26 +127,63 @@ func (p *projectPay) SpecialSettlePay(ctx *gin.Context, req *http_model.SpecialS
 		if balance < realPay {
 		if balance < realPay {
 			return errors.New("余额不足")
 			return errors.New("余额不足")
 		}
 		}
-
+		// 增加项目支付金额
 		err = tx.Model(&gorm_model.ProjectInfo{}).Where("project_id = ?", req.ProjectID).
 		err = tx.Model(&gorm_model.ProjectInfo{}).Where("project_id = ?", req.ProjectID).
 			Updates(map[string]interface{}{"payment_amount": gorm.Expr("payment_amount + ?", req.Amount)}).Error
 			Updates(map[string]interface{}{"payment_amount": gorm.Expr("payment_amount + ?", req.Amount)}).Error
 		if err != nil {
 		if err != nil {
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			return err
 			return err
 		}
 		}
-
-		err = tx.Model(&gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", req.TaskId).Updates(gorm_model.YoungeeTaskInfo{
-			TaskReward:     req.Amount,
-			SettleAmount:   req.Amount,
-			AllPayment:     req.Amount,
-			RealPayment:    req.Amount,
-			SettleStatus:   2,
-			WithdrawStatus: 2,
-		}).Error
+		// 旧:更新专项任务收益
+		// err = tx.Model(&gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", req.TaskId).Updates(gorm_model.YoungeeTaskInfo{
+		// 	TaskReward:     req.Amount,
+		// 	SettleAmount:   req.Amount,
+		// 	AllPayment:     req.Amount,
+		// 	RealPayment:    req.Amount,
+		// 	SettleStatus:   2,
+		// 	WithdrawStatus: 2,
+		// }).Error
+		// if err != nil {
+		// 	logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
+		// 	return err
+		// }
+		// 新:创建专项任务收益,更新任务阶段
+		updateTaskData := gorm_model.YoungeeTaskInfo{
+			TaskReward:   req.Amount,
+			SettleAmount: req.Amount,
+			AllPayment:   req.Amount,
+			RealPayment:  req.Amount,
+			TaskID:       req.TaskId,
+			SettleStatus: 2,
+		}
+		_, err = db.UpdateTask(ctx, updateTaskData, tx)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
+			return err
+		}
+		var productInfo gorm_model.YounggeeProduct
+		if err = json.Unmarshal([]byte(projectInfo.ProductSnap), &productInfo); err != nil {
+			fmt.Println("Error:", err)
+			return err
+		}
+		income := gorm_model.YounggeeTalentIncome{
+			TalentID:       task.TalentID,
+			ProjectID:      task.ProjectID,
+			SectaskID:      task.TaskID,
+			BrandName:      productInfo.BrandName,
+			TaskName:       projectInfo.ProjectName,
+			Income:         strconv.FormatFloat(req.Amount, 'f', 10, 32),
+			IncomeType:     1,
+			WithdrawStatus: 1,
+			IncomeAt:       time.Now(),
+		}
+		err = db.CreateIncome(ctx, income, tx)
 		if err != nil {
 		if err != nil {
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			return err
 			return err
 		}
 		}
+
+		// 扣除企业账户余额
 		err = tx.Model(&gorm_model.Enterprise{}).Where("enterprise_id = ?", req.EnterPriseId).
 		err = tx.Model(&gorm_model.Enterprise{}).Where("enterprise_id = ?", req.EnterPriseId).
 			Updates(map[string]interface{}{"balance": gorm.Expr("balance - ?", realPay), "available_balance": gorm.Expr("available_balance - ?", realPay),
 			Updates(map[string]interface{}{"balance": gorm.Expr("balance - ?", realPay), "available_balance": gorm.Expr("available_balance - ?", realPay),
 				"updated_at": time.Now()}).Error
 				"updated_at": time.Now()}).Error
@@ -144,6 +197,7 @@ func (p *projectPay) SpecialSettlePay(ctx *gin.Context, req *http_model.SpecialS
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			return err
 			return err
 		}
 		}
+		// 增加达人收益
 		err = tx.Model(&gorm_model.YoungeeTalentInfo{}).Where("id = ?", talentId).
 		err = tx.Model(&gorm_model.YoungeeTalentInfo{}).Where("id = ?", talentId).
 			Updates(map[string]interface{}{"income": gorm.Expr("income + ?", req.Amount), "canwithdraw": gorm.Expr("canwithdraw + ?", req.Amount)}).Error
 			Updates(map[string]interface{}{"income": gorm.Expr("income + ?", req.Amount), "canwithdraw": gorm.Expr("canwithdraw + ?", req.Amount)}).Error
 		if err != nil {
 		if err != nil {

+ 106 - 0
service/sectask_service/logistics.go

@@ -0,0 +1,106 @@
+package sectask_service
+
+import (
+	"context"
+	"github.com/sirupsen/logrus"
+	"time"
+	"youngee_b_api/db"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+)
+
+var Logistics *logistics
+
+type logistics struct {
+}
+
+func (*logistics) Create(ctx context.Context, request http_model.CreateSecTaskLogisticsRequest) (*http_model.CreateSecTaskLogisticsData, error) {
+	ThingsType := request.ThingsType
+	newLogistics := gorm_model.YoungeeTaskLogistics{
+		TaskID:                request.TaskID,
+		ThingsType:            int64(ThingsType),
+		ExplorestoreStarttime: time.Now(),
+		ExplorestoreEndtime:   time.Now(),
+		DeliveryTime:          time.Now(),
+	}
+	//实物
+	if ThingsType == 1 {
+		newLogistics.CompanyName = request.CompanyName
+		newLogistics.LogisticsNumber = request.LogisticsNumber
+		newLogistics.DeliveryTime = time.Now()
+	} else if ThingsType == 3 {
+		ExplorestoreStarttime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreStarttime, time.Local)
+		ExplorestoreEndtime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreEndtime, time.Local)
+		newLogistics.ExplorestoreStarttime = ExplorestoreStarttime
+		newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
+	}
+
+	_, err := db.CreateSecTaskLogistics(ctx, newLogistics)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[newLogistics service] call CreatenewLogistics error,err:%+v", err)
+		return nil, err
+	}
+
+	// 修改task_info中发货时间、任务阶段
+	updatdSecTask := gorm_model.YounggeeSecTaskInfo{
+		TaskID:          request.TaskID,
+		LogisticsStatus: 2,
+		TaskStage:       7,
+		DeliveryDate:    time.Now(),
+	}
+	_, err = db.UpdateSecTask(ctx, updatdSecTask)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask logistics service] call UpdateSecTask error,err:%+v", err)
+		return nil, err
+	}
+
+	// 记录任务日志-发货
+	err = db.CreateTaskLog(ctx, newLogistics.TaskID, "发货时间")
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateTaskLog error,err:%+v", err)
+		return nil, err
+	}
+
+	err = db.CreateMessageByTaskId(ctx, 8, 2, newLogistics.TaskID)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateMessageByTaskId error,err:%+v", err)
+		return nil, err
+	}
+
+	data := http_model.CreateSecTaskLogisticsData{}
+
+	return &data, nil
+}
+
+func (*logistics) Update(ctx context.Context, request http_model.UpdateSecTaskLogisticsRequest) (*http_model.UpdateSecTaskLogisticsData, error) {
+	ThingsType := request.ThingsType
+	newLogistics := gorm_model.YoungeeTaskLogistics{
+		LogisticsID:           request.LogisticsId,
+		TaskID:                request.TaskID,
+		ThingsType:            int64(ThingsType),
+		ExplorestoreStarttime: time.Now(),
+		ExplorestoreEndtime:   time.Now(),
+		DeliveryTime:          time.Now(),
+	}
+	//实物
+	if ThingsType == 1 {
+		newLogistics.CompanyName = request.CompanyName
+		newLogistics.LogisticsNumber = request.LogisticsNumber
+		newLogistics.DeliveryTime = time.Now()
+	} else if ThingsType == 3 {
+		ExplorestoreStarttime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreStarttime, time.Local)
+		ExplorestoreEndtime, _ := time.ParseInLocation("2006-01-02 15:04:05", request.ExplorestoreEndtime, time.Local)
+		newLogistics.ExplorestoreStarttime = ExplorestoreStarttime
+		newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
+	}
+
+	_, err := db.UpdateSecTaskLogistics(ctx, newLogistics)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
+		return nil, err
+	}
+
+	data := http_model.UpdateSecTaskLogisticsData{}
+
+	return &data, nil
+}

+ 1 - 0
service/sectask_service/recruit.go

@@ -0,0 +1 @@
+package sectask_service

+ 188 - 0
service/sectask_service/sectask.go

@@ -0,0 +1,188 @@
+package sectask_service
+
+import (
+	"context"
+	"encoding/json"
+	"errors"
+	"fmt"
+	"github.com/issue9/conv"
+	"github.com/sirupsen/logrus"
+	"strconv"
+	"time"
+	"youngee_b_api/db"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+)
+
+var SelectionTask *selectionTask
+
+type selectionTask struct {
+}
+
+func (*selectionTask) GetList(ctx context.Context, request http_model.GetSecTaskListRequest) (*http_model.GetSecTaskListData, error) {
+	secTaskList, total, err := db.GetSecTaskList(ctx, request.SelectionId, request.SecTaskStatus, request.SearchValue, request.PageSize, request.PageNum)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetAllSelection error,err:%+v", err)
+		return nil, err
+	}
+
+	selectionListData := http_model.GetSecTaskListData{
+		Total:       conv.MustString(total, ""),
+		SecTaskList: secTaskList,
+	}
+
+	return &selectionListData, nil
+}
+
+func (*selectionTask) PassCoop(ctx context.Context, request http_model.PassSecTaskCoopRequest) (*http_model.PassSecTaskCoopData, error) {
+
+	_, err := db.PassSecTaskCoop(ctx, request.SelectionId, request.TaskIds)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call PassCoop error,err:%+v", err)
+		return nil, err
+	}
+
+	selectionListData := http_model.PassSecTaskCoopData{}
+
+	return &selectionListData, nil
+}
+
+func (*selectionTask) RefuseCoop(ctx context.Context, request http_model.RefuseSecTaskCoopRequest) (*http_model.RefuseSecTaskCoopData, error) {
+
+	_, err := db.RefuseSecTaskCoop(ctx, request.TaskIds)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call RefuseCoop error,err:%+v", err)
+		return nil, err
+	}
+
+	selectionListData := http_model.RefuseSecTaskCoopData{}
+
+	return &selectionListData, nil
+}
+
+func (*selectionTask) Settle(ctx context.Context, entersizeId string, request http_model.SettleSecTaskRequest) (*http_model.SettleSecTaskData, error) {
+	// 1. 解析request data
+	var returnMoney float64 = 0.0
+	var rewardMoney float64 = 0.0
+	payMoney, err := strconv.ParseFloat(request.TotalPayMoney, 64)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call strconv.ParseFloat() error,err:%+v", err)
+		return nil, err
+	}
+	// 2. 校验:任务是否正常(处于待结算阶段);企业账户可用余额是否充足;若返现则校验达人是否垫付买样;若有悬赏金额则校验是否为悬赏任务
+	// 1) 校验企业账户余额是否充足
+	entersize, err := db.GetEnterpriseByEnterpriseID(ctx, entersizeId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetEnterpriseByEnterpriseID error,err:%+v", err)
+		return nil, err
+	}
+	if entersize.AvailableBalance < payMoney {
+		return nil, errors.New("账户余额不足")
+	}
+	// 2) 若返现则校验达人是否垫付买样;若有悬赏金额则校验是否为悬赏任务
+	selection, err := db.GetSelectionById(ctx, request.SelectionID)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetSelectionById error,err:%+v", err)
+		return nil, err
+	}
+	if selection.SampleMode != 2 && request.IsReturnMoney == 1 {
+		return nil, errors.New("免费领养任务不能返样品钱")
+	}
+	if selection.TaskMode != 1 && request.IsPayReward == 1 {
+		return nil, errors.New("非悬赏任务不能支付悬赏")
+	}
+	// 3) 校验任务是否处于待结算阶段
+	secTask, err := db.GetSecTaskById(ctx, request.TaskID)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetSecTaskById error,err:%+v", err)
+		return nil, err
+	}
+	if secTask.TaskStage != 9 && secTask.TaskStatus != 2 {
+		return nil, errors.New("该任务暂不可结算")
+	}
+
+	var product gorm_model.YounggeeProduct
+	if err = json.Unmarshal([]byte(selection.ProductSnap), &product); err != nil {
+		fmt.Println("Error:", err)
+		return nil, err
+	}
+	// 4) 校验结算金额计算是否正确
+	if request.IsReturnMoney == 1 {
+		returnMoney = product.ProductPrice
+	}
+	if request.IsPayReward == 1 {
+		rewardMoney, err = strconv.ParseFloat(selection.TaskReward, 64)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[sectask_service service] call strconv.ParseFloat() error,err:%+v", err)
+			return nil, err
+		}
+	}
+	if rewardMoney+returnMoney != payMoney {
+		return nil, errors.New("结算金额有误")
+	}
+	// 3. 扣除企业账户余额
+	_, err = db.UpdateEnterpriseBalance(ctx, entersizeId, 0, -payMoney, payMoney)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call UpdateEnterpriseBalance error,err:%+v", err)
+		return nil, err
+	}
+
+	// 4. 更新选品任务阶段
+	updateSecTaskData := gorm_model.YounggeeSecTaskInfo{
+		TaskID:           request.TaskID,
+		TaskStage:        10,
+		AssignmentStatus: 5,
+		CompleteDate:     time.Now(),
+	}
+	_, err = db.UpdateSecTask(ctx, updateSecTaskData)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call UpdateSecTask error,err:%+v", err)
+		return nil, err
+	}
+	// 5. 添加任务日志和达人消息
+	// 6. 创建选品收益记录
+	// 返现收益
+	if request.IsReturnMoney == 1 {
+		income := gorm_model.YounggeeTalentIncome{
+			TalentID:       secTask.TalentID,
+			SelectionID:    secTask.SelectionID,
+			SectaskID:      secTask.TaskID,
+			BrandName:      product.BrandName,
+			TaskName:       selection.SelectionName,
+			Income:         strconv.FormatFloat(returnMoney, 'f', 10, 32),
+			IncomeType:     1,
+			WithdrawStatus: 1,
+			IncomeAt:       time.Now(),
+		}
+		err = db.CreateIncome(ctx, income, nil)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[sectask_service service] call CreateIncome error,err:%+v", err)
+			return nil, err
+		}
+	}
+	// 悬赏收益
+	if request.IsPayReward == 1 {
+		income := gorm_model.YounggeeTalentIncome{
+			TalentID:       secTask.TalentID,
+			SelectionID:    secTask.SelectionID,
+			SectaskID:      secTask.TaskID,
+			BrandName:      product.BrandName,
+			TaskName:       selection.SelectionName,
+			Income:         strconv.FormatFloat(rewardMoney, 'f', 10, 32),
+			IncomeType:     1,
+			WithdrawStatus: 1,
+			IncomeAt:       time.Now(),
+		}
+		err = db.CreateIncome(ctx, income, nil)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[sectask_service service] call CreateIncome error,err:%+v", err)
+			return nil, err
+		}
+	}
+
+	// 7. 若有young之团存在,则为young之团创建收益
+
+	settleSecTaskData := http_model.SettleSecTaskData{}
+
+	return &settleSecTaskData, nil
+}

+ 0 - 64
service/selection.go

@@ -1,64 +0,0 @@
-package service
-
-import (
-	"context"
-	"github.com/gin-gonic/gin"
-	"github.com/issue9/conv"
-	"github.com/sirupsen/logrus"
-	"youngee_b_api/db"
-	"youngee_b_api/model/common_model"
-	"youngee_b_api/model/http_model"
-	"youngee_b_api/pack"
-)
-
-var Selection *selection
-
-type selection struct {
-}
-
-func (s *selection) GetAllSelection(ctx context.Context, enterpriseID string, pageSize, pageNum int64, conditions *common_model.SelectionConditions) (*http_model.SelectionData, error) {
-	SelectionList, total, err := db.GetSelectionList(ctx, enterpriseID, pageSize, pageNum, conditions)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selection service] call GetAllSelection error,err:%+v", err)
-		return nil, err
-	}
-	SelectionListData := new(http_model.SelectionData)
-	SelectionListData.SelectionInfo = pack.MGormSelectionToHttpSelectionPreview(SelectionList)
-	SelectionListData.Total = conv.MustString(total)
-	return SelectionListData, nil
-}
-
-func (s *selection) GetSelectionDetail(ctx *gin.Context, selectionId string) (*http_model.SelectionDetail, error) {
-	selectionDetail := http_model.SelectionDetail{}
-	selectionInfo, err := db.GetSelectionInfo(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selection service] call GetSelectionInfo error,err:%+v", err)
-		return nil, err
-	}
-	selectionBriefInfo, err := db.GetSelectionBriefInfo(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selection service] call GetSelectionBriefInfo error,err:%+v", err)
-		return nil, err
-	}
-	selectionExampleInfo, err := db.GetSelectionExampleInfo(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selection service] call GetSelectionExampleInfo error,err:%+v", err)
-		return nil, err
-	}
-	productInfo, err := db.GetProductInfo(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selection service] call GetProductInfo error,err:%+v", err)
-		return nil, err
-	}
-	productPhotoInfo, err := db.GetProductPhotoInfo(ctx, selectionId)
-	if err != nil {
-		logrus.WithContext(ctx).Errorf("[selection service] call GetProductPhotoInfo error,err:%+v", err)
-		return nil, err
-	}
-	selectionDetail.SelectionBrief = selectionBriefInfo
-	selectionDetail.SelectionInfo = selectionInfo
-	selectionDetail.SelectionExample = selectionExampleInfo
-	selectionDetail.ProductInfo = productInfo
-	selectionDetail.ProductPhotoInfo = productPhotoInfo
-	return &selectionDetail, nil
-}

+ 230 - 0
service/selection_service/selection.go

@@ -0,0 +1,230 @@
+package selection_service
+
+import (
+	"context"
+	"encoding/json"
+	"errors"
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	"reflect"
+	"time"
+	"youngee_b_api/db"
+	"youngee_b_api/model/common_model"
+	"youngee_b_api/model/gorm_model"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/pack"
+	"youngee_b_api/util"
+
+	"github.com/caixw/lib.go/conv"
+)
+
+var Selection *selection
+
+type selection struct {
+}
+
+func (*selection) Create(ctx context.Context, request http_model.CreateSelectionRequest, enterpriseId string) (*http_model.CreateSelectionData, error) {
+	// 1. 检查该企业id和商品id有无选品
+	selectionInfo, err := db.GetSelectionByEnterpiseIdAndProductId(ctx, enterpriseId, conv.MustInt(request.ProductId, 0))
+	if err != nil {
+		return nil, err
+	}
+	if selectionInfo != nil {
+		return nil, errors.New("该商品下选品已存在")
+	}
+
+	// 2. 数据准备
+	// a) 生成选品id
+	selectionId := util.GetSelectionID()
+	// b) 查找关联商品信息
+	product, err := db.GetProductByID(ctx, conv.MustInt64(request.ProductId, 0))
+	if err != nil {
+		return nil, err
+	}
+	productPhotos, err := db.GetProductPhotoByProductID(ctx, conv.MustInt64(request.ProductId, 0))
+	productInfoToJson, _ := json.Marshal(product)
+	productPhotosToJson, _ := json.Marshal(productPhotos)
+	// c) 选品名称
+	selectionName := product.BrandName + "-" + product.ProductName
+
+	// 3. 创建选品
+	newSelection := gorm_model.YounggeeSelectionInfo{
+		SelectionID:      selectionId,
+		SelectionName:    selectionName,
+		ProductID:        conv.MustInt(request.ProductId, 0),
+		EnterpriseID:     enterpriseId,
+		Platform:         conv.MustInt(request.Platform, 0),
+		ProductSnap:      string(productInfoToJson),
+		ProductPhotoSnap: string(productPhotosToJson),
+		CreatedAt:        time.Now(),
+	}
+	err = db.CreateSelection(ctx, newSelection)
+	if err != nil {
+		return nil, err
+	}
+
+	res := &http_model.CreateSelectionData{
+		SelectionId: selectionId,
+	}
+	return res, nil
+}
+
+func (*selection) Update(ctx context.Context, request http_model.UpdateSelectionRequest, enterpriseId string) (*http_model.UpdateSelectionData, error) {
+	// 1. 检查该企业id和商品id有无选品
+	selectionInfo, err := db.GetSelectionByEnterpiseIdAndProductId(ctx, enterpriseId, conv.MustInt(request.ProductId, 0))
+	if err != nil {
+		return nil, err
+	}
+	if selectionInfo == nil {
+		return nil, errors.New("选品不存在")
+	}
+
+	// 2. 数据准备
+	// a) 查找关联商品信息
+	product, err := db.GetProductByID(ctx, conv.MustInt64(request.ProductId, 0))
+	if err != nil {
+		return nil, err
+	}
+	productPhotos, err := db.GetProductPhotoByProductID(ctx, conv.MustInt64(request.ProductId, 0))
+	productInfoToJson, _ := json.Marshal(product)
+	productPhotosToJson, _ := json.Marshal(productPhotos)
+	// b) 选品名称
+	selectionName := product.BrandName + "-" + product.ProductName
+	// c) 计算预估成本(如果有)
+	var estimatedCost float64
+	if conv.MustInt(request.TaskMode, 0) == 1 {
+		estimatedCost = conv.MustFloat64(request.TaskReward, 0) * conv.MustFloat64(request.SampleNum, 0)
+	}
+	estimatedCostToString, _ := conv.String(estimatedCost)
+	// d) 任务截止时间
+	taskDdl := time.Time{} //赋零值
+	if request.TaskDdl != "" {
+		taskDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", request.TaskDdl, time.Local)
+	}
+
+	updateSelection := gorm_model.YounggeeSelectionInfo{
+		SelectionID:      request.SelectionID,
+		SelectionName:    selectionName,
+		EnterpriseID:     enterpriseId,
+		ProductID:        conv.MustInt(request.ProductId, 0),
+		ContentType:      conv.MustInt(request.ContentType, 0),
+		SelectionStatus:  1,
+		TaskMode:         conv.MustInt(request.TaskMode, 0),
+		Platform:         conv.MustInt(request.Platform, 0),
+		SampleMode:       conv.MustInt(request.SampleMode, 0),
+		ProductUrl:       request.ProductUrl,
+		SampleNum:        conv.MustInt(request.SampleNum, 0),
+		RemainNum:        conv.MustInt(request.SampleNum, 0),
+		CommissionRate:   conv.MustInt(request.CommissionRate, 0),
+		EstimatedCost:    estimatedCostToString,
+		SampleCondition:  request.SampleCondition,
+		RewardCondition:  request.RewardCondition,
+		TaskDdl:          taskDdl,
+		Detail:           request.Detail,
+		ProductSnap:      string(productInfoToJson),
+		ProductPhotoSnap: string(productPhotosToJson),
+		CreatedAt:        selectionInfo.CreatedAt,
+		UpdatedAt:        time.Now(),
+		SubmitAt:         time.Now(),
+	}
+	// 合并传入参数和数据表中原记录,若传入参数字段值为空,则将字段赋值为原记录中值
+	result := util.MergeStructValue(&updateSelection, &selectionInfo)
+	// 利用反射机制将interface类型转换为结构体类型
+	v := reflect.ValueOf(result).Elem()
+	if v.Kind() == reflect.Struct {
+		updateSelection = v.Interface().(gorm_model.YounggeeSelectionInfo)
+		//fmt.Println(p)
+	}
+
+	// 3. 更新选品
+	err = db.UpdateSelection(ctx, updateSelection)
+	if err != nil {
+		return nil, err
+	}
+
+	res := &http_model.UpdateSelectionData{
+		SelectionId: updateSelection.SelectionID,
+	}
+	return res, nil
+}
+
+func (*selection) Pay(ctx context.Context, request http_model.PaySelectionRequest, enterpriseId string) (*http_model.PaySelectionData, error) {
+	// 校验
+	// 1. 账户余额是否足够
+	enterprise, err := db.GetEnterpriseByEnterpriseID(ctx, enterpriseId)
+	if err != nil {
+		return nil, err
+	}
+	if enterprise.AvailableBalance < request.PayMoney {
+		return nil, errors.New("账户余额不足")
+	}
+	// 2. 选品项目状态是否正确
+	selectionInfo, err := db.GetSelectionById(ctx, request.SelectionId)
+	if err != nil {
+		return nil, err
+	}
+	if selectionInfo == nil {
+		return nil, errors.New("选品不存在")
+	}
+	if selectionInfo.SelectionStatus != 4 {
+		return nil, errors.New("选品状态有误")
+	}
+
+	// 支付
+	err = db.PaySelection(ctx, enterpriseId, request.PayMoney, request.SelectionId)
+	if err != nil {
+		return nil, err
+	}
+
+	res := &http_model.PaySelectionData{
+		SelectionId: request.SelectionId,
+	}
+	return res, nil
+}
+
+func (s *selection) GetAllSelection(ctx context.Context, enterpriseID string, pageSize, pageNum int64, conditions *common_model.SelectionConditions) (*http_model.SelectionData, error) {
+	SelectionList, total, err := db.GetSelectionList(ctx, enterpriseID, pageSize, pageNum, conditions)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetAllSelection error,err:%+v", err)
+		return nil, err
+	}
+	SelectionListData := new(http_model.SelectionData)
+	SelectionListData.SelectionInfo = pack.MGormSelectionToHttpSelectionPreview(SelectionList)
+	SelectionListData.Total = conv.MustString(total, "")
+	return SelectionListData, nil
+}
+
+func (s *selection) GetSelectionDetail(ctx *gin.Context, selectionId, enterpriseID string) (*http_model.SelectionDetail, error) {
+	selectionDetail := http_model.SelectionDetail{}
+	selectionInfo, err := db.GetSelectionById(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionInfo error,err:%+v", err)
+		return nil, err
+	}
+	selectionBriefInfo, err := db.GetSelectionBriefInfo(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionBriefInfo error,err:%+v", err)
+		return nil, err
+	}
+	selectionExampleInfo, err := db.GetSelectionExampleInfo(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetSelectionExampleInfo error,err:%+v", err)
+		return nil, err
+	}
+	productInfo, err := db.GetProductInfoBySelectionId(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductInfo error,err:%+v", err)
+		return nil, err
+	}
+	productPhotoInfo, err := db.GetProductPhotoInfoBySelectionId(ctx, selectionId)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[selectionDB service] call GetProductPhotoInfo error,err:%+v", err)
+		return nil, err
+	}
+	selectionDetail.SelectionBrief = selectionBriefInfo
+	selectionDetail.SelectionInfo = selectionInfo
+	selectionDetail.SelectionExample = selectionExampleInfo
+	selectionDetail.ProductInfo = productInfo
+	selectionDetail.ProductPhotoInfo = productPhotoInfo
+	return &selectionDetail, nil
+}

+ 22 - 0
util/structFunc.go

@@ -0,0 +1,22 @@
+package util
+
+import "reflect"
+
+/*
+	合并两个结构体的值,遍历结构体s1,若s1中某字段值为空,则将s2该字段的值赋给s1,否则不变
+	参数:interface{} -> &struct, 结构体指针
+	返回值:interface{} -> &struct, 结构体指针
+*/
+func MergeStructValue(s1 interface{}, s2 interface{}) interface{} {
+	v1 := reflect.ValueOf(s1).Elem()
+	v2 := reflect.ValueOf(s2).Elem()
+	for i := 0; i < v1.NumField(); i++ {
+		field := v1.Field(i)
+		name := v1.Type().Field(i).Name
+		if field.Interface() == reflect.Zero(field.Type()).Interface() {
+			v1.FieldByName(name).Set(v2.FieldByName(name))
+		}
+	}
+
+	return v1
+}

+ 16 - 0
util/uuid.go

@@ -3,6 +3,9 @@ package util
 import (
 import (
 	"github.com/GUAIK-ORG/go-snowflake/snowflake"
 	"github.com/GUAIK-ORG/go-snowflake/snowflake"
 	"github.com/google/uuid"
 	"github.com/google/uuid"
+	"github.com/issue9/conv"
+	"math/rand"
+	"time"
 )
 )
 
 
 var snowflakeInstance *snowflake.Snowflake
 var snowflakeInstance *snowflake.Snowflake
@@ -20,3 +23,16 @@ func GetUUID() string {
 func GetSnowflakeID() int64 {
 func GetSnowflakeID() int64 {
 	return snowflakeInstance.NextVal()
 	return snowflakeInstance.NextVal()
 }
 }
+
+func GetSelectionID() string {
+	rand.Seed(time.Now().UnixNano())
+	td := conv.MustString(time.Now().Day())
+	for {
+		if len(td) == 3 {
+			break
+		}
+		td = "0" + td
+	}
+	selectionId := conv.MustString(time.Now().Year())[2:] + td + conv.MustString(rand.Intn(100000-10000)+10000)
+	return selectionId
+}