Ohio-HYF hai 1 ano
pai
achega
648c518173

+ 45 - 0
db/logistics.go

@@ -249,3 +249,48 @@ func GetSpecialTaskLogisticsList(ctx context.Context, projectID string, pageSize
 	}
 	return newTaskLogisticss, totalTask, nil
 }
+
+func GetSecTaskLogisticsList(ctx context.Context, secTaskList []*http_model.SecTaskInfo, taskStage int, productType int) ([]*http_model.SecTaskInfo, error) {
+	db := GetReadDB(ctx)
+	if taskStage != 6 { // 已发货
+		// 查询youngee_task_logistics中物流信息
+		var taskIds []string
+		taskMap := make(map[string]*http_model.SecTaskInfo)
+		for _, secTask := range secTaskList {
+			taskIds = append(taskIds, secTask.SecTaskId)
+			taskMap[secTask.SecTaskId] = secTask
+		}
+
+		var logisticsInfos []gorm_model.YoungeeTaskLogistics
+		err := db.Model(gorm_model.YoungeeTaskLogistics{}).Where("task_id IN ?", taskIds).Find(&logisticsInfos).Error
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[GetProjectTaskList] error query mysql total, err:%+v", err)
+			return nil, err
+		}
+		logisticsMap := make(map[string]gorm_model.YoungeeTaskLogistics)
+		for _, logisticsInfo := range logisticsInfos {
+			logisticsMap[logisticsInfo.TaskID] = logisticsInfo
+		}
+		// 融合信息
+		for i, secTask := range secTaskList {
+			taskID := secTask.SecTaskId
+			secTaskList[i].CompanyName = logisticsMap[taskID].CompanyName
+			secTaskList[i].LogisticsNumber = logisticsMap[taskID].LogisticsNumber
+			secTaskList[i].ExplorestorePeriod = logisticsMap[taskID].ExplorestorePeriod
+			secTaskList[i].ExplorestoreStarttime = logisticsMap[taskID].ExplorestoreStarttime
+			secTaskList[i].ExplorestoreEndtime = logisticsMap[taskID].ExplorestoreEndtime
+		}
+	}
+
+	return secTaskList, nil
+}
+
+func GetLogistics(ctx context.Context, secTaskId string) (*gorm_model.YoungeeTaskLogistics, error) {
+	db := GetWriteDB(ctx)
+	logistics := gorm_model.YoungeeTaskLogistics{}
+	err := db.Model(gorm_model.YoungeeTaskLogistics{}).Where("task_id", secTaskId).First(&logistics).Error
+	if err != nil {
+		return nil, err
+	}
+	return &logistics, nil
+}

+ 35 - 0
db/message.go

@@ -9,6 +9,41 @@ import (
 	"github.com/sirupsen/logrus"
 )
 
+// 通过secTaskId查询talentId,插入新消息
+func CreateMessageBySecTaskId(ctx context.Context, messageId int, messageType int, taskId string) error {
+	db := GetReadDB(ctx)
+	taskInfo := gorm_model.YounggeeSecTaskInfo{}
+	err := db.Model(gorm_model.YounggeeSecTaskInfo{}).Where("task_id = ?", taskId).Find(&taskInfo).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[CreateMessageByTask] error read mysql, err:%+v", err)
+		return err
+	}
+
+	db1 := GetReadDB(ctx)
+	var projectName string
+	err = db1.Model(gorm_model.YounggeeSelectionInfo{}).Select("selection_name").Where("selection_id = ?", taskInfo.SelectionID).Find(&projectName).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[CreateMessageByTask] error read mysql, err:%+v", err)
+		return err
+	}
+	messageInfo := gorm_model.YounggeeMessageInfo{
+		MessageID:   messageId,
+		MessageType: messageType,
+		CreatedAt:   time.Now(),
+		TalentID:    taskInfo.TalentID,
+		ProjectName: projectName,
+		IsReaded:    0,
+		IsDeleted:   0,
+	}
+	db2 := GetReadDB(ctx)
+	err = db2.Model(gorm_model.YounggeeMessageInfo{}).Create(&messageInfo).Error
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[CreateMessageByTask] error create mysql, err:%+v", err)
+		return err
+	}
+	return nil
+}
+
 // 通过taskId查询talentId,插入新消息
 func CreateMessageByTaskId(ctx context.Context, messageId int, messageType int, taskId string) error {
 	db := GetReadDB(ctx)

+ 36 - 2
db/operate.go

@@ -2,6 +2,7 @@ package db
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"log"
 	"reflect"
@@ -829,12 +830,45 @@ func GetAutoCaseCloseTask() error {
 		fmt.Println("自动审核数据:已更新taskInfo表,任务阶段为待传数据 及数据上传状态为已通过")
 	}
 
-	// 3). 更新recruitStrategy表
+	// 3). 创建任务收益并更新recruitStrategy表
 	for _, taskId := range taskIds {
-		// 更新招募策略
 		taskInfo := taskIdToTaskInfoMap[taskId]
 		dataInfo := taskIdToDataInfoMap[taskId]
 		db7 := GetReadDB(context.Background())
+
+		//查询project_info
+		projectInfo := gorm_model.ProjectInfo{}
+		err1 := db.Model(gorm_model.ProjectInfo{}).Where("project_id = ?", taskInfo.ProjectId).Scan(&projectInfo).Error
+		if err1 != nil {
+			log.Println("DB GetAutoCaseCloseTask error in data:", err)
+			return err1
+		}
+		// 2. 创建任务收益
+		var productStruct gorm_model.YounggeeProduct
+		if err = json.Unmarshal([]byte(projectInfo.ProductSnap), &productStruct); err != nil {
+			log.Println("DB GetAutoCaseCloseTask error in data:", err)
+			return err
+		}
+		t := time.Now()
+		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:       &t,
+			WithdrawAt:     nil,
+		}
+		err = CreateIncome(context.Background(), income, nil)
+		if err != nil {
+			log.Println("DB GetAutoCaseCloseTask error in data:", err)
+			return err
+		}
+
+		// 更新招募策略
 		db7 = db7.Model(gorm_model.RecruitStrategy{}).Where("project_id = ? and strategy_id = ?", taskInfo.ProjectId, taskInfo.StrategyId)
 		fansCount, _ := strconv.Atoi(conv.MustString(gjson.Get(taskInfo.TalentPlatformInfoSnap, "fans_count"), ""))
 		err = db7.Updates(map[string]interface{}{

+ 17 - 0
db/product.go

@@ -118,3 +118,20 @@ func GetProductPhotoInfoBySelectionId(ctx context.Context, selectionId string) (
 	}
 	return productPhotoInfo, nil
 }
+
+func GetProductType(ctx context.Context, selectionId string) (*int, error) {
+	db := GetReadDB(ctx)
+	var productId int
+	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Select("product_id").Where("selection_id = ?", selectionId).Find(&productId).Error
+	if err != nil || productId == 0 {
+		logrus.WithContext(ctx).Errorf("[GetProductType] error query mysql, err:%+v", err)
+		return nil, err
+	}
+	var productType int
+	err = db.Model(gorm_model.YounggeeProduct{}).Select("product_type").Where("product_id = ?", productId).Find(&productType).Error
+	if err != nil || productType == 0 {
+		logrus.WithContext(ctx).Errorf("[GetProductType] error query mysql, err:%+v", err)
+		return nil, err
+	}
+	return &productType, nil
+}

+ 96 - 18
db/sectask.go

@@ -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
+}

+ 12 - 0
db/selection.go

@@ -282,3 +282,15 @@ func DeleteSecExampleBySelectionId(ctx context.Context, selectionId string) erro
 	}
 	return nil
 }
+
+// 更新选品结算金额
+func UpdateSelectionSettleMoney(ctx context.Context, selectionID string, payMoney float64) (bool, error) {
+	db := GetReadDB(ctx)
+	err := db.Model(gorm_model.YounggeeSelectionInfo{}).Where("selection_id", selectionID).
+		Updates(map[string]interface{}{"settlement_amount": gorm.Expr("settlement_amount + ?", payMoney)}).Error
+	if err != nil {
+		return false, err
+	}
+
+	return true, nil
+}

+ 53 - 0
db/task.go

@@ -2,6 +2,7 @@ package db
 
 import (
 	"context"
+	"encoding/json"
 	"fmt"
 	"reflect"
 	"strconv"
@@ -235,6 +236,13 @@ func SetTaskFinish(ctx context.Context, TaskIDs []string) error {
 			logrus.WithContext(ctx).Errorf("[Task db] Find YoungeeTaskInfo error,err:%+v", err)
 			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
 		db = GetReadDB(ctx)
 		dataInfo := gorm_model.YounggeeDataInfo{}
@@ -244,6 +252,31 @@ func SetTaskFinish(ctx context.Context, TaskIDs []string) error {
 			return err1
 		}
 
+		// 2. 创建任务收益
+		var productStruct gorm_model.YounggeeProduct
+		if err = json.Unmarshal([]byte(projectInfo.ProductSnap), &productStruct); err != nil {
+			fmt.Println("Error:", err)
+			return err
+		}
+		t := time.Now()
+		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:       &t,
+			WithdrawAt:     nil,
+		}
+		err = CreateIncome(ctx, income, nil)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
+			return err
+		}
+
 		// 更新招募策略
 		db = GetReadDB(ctx)
 		db = db.Model(gorm_model.RecruitStrategy{}).Where("project_id = ? and strategy_id = ?", taskInfo.ProjectId, taskInfo.StrategyId)
@@ -329,3 +362,23 @@ func GetTaskIds(ctx context.Context, projectId string) ([]string, error) {
 
 	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 - 1
go.mod

@@ -16,7 +16,7 @@ require (
 	github.com/GUAIK-ORG/go-snowflake v0.0.0-20200116064823-220c4260e85f
 	github.com/go-redis/redis/v8 v8.11.5
 	github.com/google/uuid v1.3.0
-	github.com/issue9/conv v1.3.4
+	github.com/issue9/conv v1.2.1
 	github.com/robfig/cron/v3 v3.0.0
 	github.com/tidwall/gjson v1.14.3
 	github.com/wechatpay-apiv3/wechatpay-go v0.2.15

+ 4 - 4
go.sum

@@ -61,10 +61,10 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
 github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
 github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
-github.com/issue9/assert/v3 v3.0.4 h1:WsYZQ6PQmM/pGFrbkn5GIXjWeVZHv+wcl2829UTX1Qc=
-github.com/issue9/assert/v3 v3.0.4/go.mod h1:yft/uaskRpwQTyBT3n1zRl91SR1wNlO4fLZHzOa4bdM=
-github.com/issue9/conv v1.3.4 h1:v1j/p1lVNW4u1yrbUxxNCb61iTFnF86s+KAwS65MsBs=
-github.com/issue9/conv v1.3.4/go.mod h1:TXM2DyyJhzZMSwp9cxwFW/OhP5JRVZPMg5XE8OMzwUY=
+github.com/issue9/assert v1.4.1 h1:gUtOpMTeaE4JTe9kACma5foOHBvVt1p5XTFrULDwdXI=
+github.com/issue9/assert v1.4.1/go.mod h1:Yktk83hAVl1SPSYtd9kjhBizuiBIqUQyj+D5SE2yjVY=
+github.com/issue9/conv v1.2.1 h1:bSRC6p0eSJqwtnN2yk04ct4F556y8i+TdiUiBvN+KdA=
+github.com/issue9/conv v1.2.1/go.mod h1:rxUsUvpb1/3rZt0Uf/UtEC6BogEO2BV3bCWbh2DORp8=
 github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
 github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
 github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas=

+ 27 - 0
model/gorm_model/assignment.go

@@ -0,0 +1,27 @@
+// Code generated by sql2gorm. DO NOT EDIT.
+package gorm_model
+
+import (
+"time"
+)
+
+type YounggeeAssignmentInfo struct {
+	AssignmentID  int       `gorm:"column:assignment_id;primary_key;AUTO_INCREMENT"` // 作业id,递增
+	TaskID        string    `gorm:"column:task_id"`                                  // 任务id
+	LinkUrl       string    `gorm:"column:link_url"`                                 // 作业连接
+	PhotoUrl      string    `gorm:"column:photo_url"`                                // 作业截图
+	ReviseOpinion string    `gorm:"column:revise_opinion"`                           // 审核意见
+	IsSubmit      int       `gorm:"column:is_submit"`                                // 是否提交
+	IsReview      int       `gorm:"column:is_review;default:0"`                      // 是否审核
+	IsOk          int       `gorm:"column:is_ok"`                                    // 是否合格
+	CreateAt      time.Time `gorm:"column:create_at"`                                // 创建时间
+	SubmitAt      time.Time `gorm:"column:submit_at"`                                // 提交时间
+	AgreeAt       time.Time `gorm:"column:agree_at"`                                 // 同意时间
+	RejectAt      time.Time `gorm:"column:reject_at"`                                // 驳回时间
+}
+
+func (m *YounggeeAssignmentInfo) TableName() string {
+	return "younggee_assignment_info"
+}
+
+

+ 2 - 2
model/gorm_model/talent_income.go

@@ -18,8 +18,8 @@ type YounggeeTalentIncome struct {
 	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"`     // 提现时间
+	IncomeAt       *time.Time `gorm:"column:income_at"`       // 收益产生时间
+	WithdrawAt     *time.Time `gorm:"column:withdraw_at"`     // 提现时间
 }
 
 func (m *YounggeeTalentIncome) TableName() string {

+ 24 - 10
model/http_model/GetSecTaskListRequest.go

@@ -1,8 +1,6 @@
 package http_model
 
-import (
-	"time"
-)
+import "time"
 
 type GetSecTaskListRequest struct {
 	PageSize      int64  `json:"page_size"`
@@ -10,6 +8,7 @@ type GetSecTaskListRequest struct {
 	SelectionId   string `json:"selection_id"`
 	SecTaskStatus int    `json:"sec_task_status"`
 	SearchValue   string `json:"search_value"`
+	Type          int    `json:"type"` // 查询类型,1、2、3分别表示确定达人查询、发货管理查询、结算管理查询
 }
 
 type GetSecTaskListData struct {
@@ -18,13 +17,28 @@ type GetSecTaskListData struct {
 }
 
 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"`                           // 反选时间
+	SecTaskId             string    `json:"sec_task_id"`
+	PlatformNickname      string    `json:"platform_nickname"`     // 帐号昵称
+	FansCount             string    `json:"fans_count"`            // 粉丝数
+	HomePageCaptureUrl    string    `json:"home_page_capture_url"` // 主页截图链接
+	HomePageUrl           string    `json:"home_page_url"`         // 主页链接
+	RegionCode            int       `json:"region_code"`
+	DetailAddr            string    `json:"detail_addr"`            // 物流信息
+	CompanyName           string    `json:"company_name"`           // 物流公司
+	LogisticsNumber       string    `json:"logistics_number"`       // 物流单号
+	ExplorestoreStarttime time.Time `json:"explorestore_starttime"` // 线下探店-探店开始时间
+	ExplorestoreEndtime   time.Time `json:"explorestore_endtime"`   // 线下探店-探店结束时间
+	ExplorestorePeriod    string    `json:"explorestore_period"`    // 线下探店-探店持续时间
+	DataScreenshot        string    `json:"data_screenshot"`        // 数据截图
+	AssignmentLink        string    `json:"assignment_link"`        // 作业链接
+	ReturnMoney           string    `json:"return_money"`           // 返现
+	TaskReward            string    `json:"task_reward"`            // 悬赏金
+	IsPayReward           int       `json:"is_pay_reward"`          // 是否给悬赏金
+	IsPayPayment          int       `json:"is_pay_payment"`         // 是否返现
+	CreateDate            string    `json:"create_date"`            // 创建时间
+	SelectDate            string    `json:"select_date"`            // 反选时间
+	DeliveryDate          string    `json:"delivery_date"`          // 发货时间
+	CompleteDate          string    `json:"complete_date"`          // 结算时间
 }
 
 func NewGetSecTaskListRequest() *GetSecTaskListRequest {

+ 11 - 2
pack/sec_task_list.go

@@ -2,6 +2,7 @@ package pack
 
 import (
 	"github.com/tidwall/gjson"
+	"strconv"
 	"youngee_m_api/model/gorm_model"
 	"youngee_m_api/model/http_model"
 
@@ -19,12 +20,20 @@ func GormSecTaskListToHttpSecTaskList(secTaskList []*gorm_model.YounggeeSecTaskI
 
 func GormSecTaskToHttpSecTask(secTask *gorm_model.YounggeeSecTaskInfo) *http_model.SecTaskInfo {
 	TalentPlatformInfoSnap := secTask.TalentPlatformInfoSnap
+	regionCode, _ := strconv.Atoi(conv.MustString(gjson.Get(secTask.TalentPostAddrSnap, "region_code"), ""))
 	return &http_model.SecTaskInfo{
+		SecTaskId:          secTask.TaskID,
 		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,
+		RegionCode:         regionCode,
+		DetailAddr:         conv.MustString(gjson.Get(secTask.TalentPostAddrSnap, "detail_addr"), "") + " " + conv.MustString(gjson.Get(secTask.TalentPostAddrSnap, "receiver_name"), "") + " " + conv.MustString(gjson.Get(secTask.TalentPostAddrSnap, "phone_number"), ""),
+		CreateDate:         conv.MustString(secTask.CreateDate, ""),
+		SelectDate:         conv.MustString(secTask.SelectDate, ""),
+		DeliveryDate:       conv.MustString(secTask.DeliveryDate, ""),
+		CompleteDate:       conv.MustString(secTask.CompleteDate, ""),
+		IsPayReward:        secTask.IsPayReward,
+		IsPayPayment:       secTask.IsPayPayment,
 	}
 }

+ 1 - 1
route/init.go

@@ -191,7 +191,7 @@ func InitRoute(r *gin.Engine) {
 	s := r.Group("/youngee/m/selection")
 	{
 		//s.Use(middleware.LoginAuthMiddleware)
-		//s.Use(middleware.LoginAuthMiddleware)
+		s.Use(middleware.LoginAuthMiddleware)
 		s.GET("/reviewnumber", handler.WrapSelectionReviewNumberHandler)            //查询选品待审核的数量
 		s.POST("/delete", handler.WrapDeleteSelectionHandler)                       //删除选品
 		s.POST("/findAll", handler.WrapFindAllSelectionHandler)                     //选品列表

+ 58 - 6
service/project_pay.go

@@ -2,10 +2,12 @@ package service
 
 import (
 	"context"
+	"encoding/json"
 	"errors"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"gorm.io/gorm"
+	"strconv"
 	"time"
 	"youngee_m_api/db"
 	"youngee_m_api/model/gorm_model"
@@ -19,9 +21,9 @@ var ProjectPay *projectPay
 type projectPay struct {
 }
 
-func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequest, enterpriseID string) (*int64, error) {
+func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequest, enterpriseId string) (*int64, error) {
 	// 修改企业账户金额
-	balance, err := db.UpdateEnterpriseBalance(ctx, enterpriseID, 0, -projectPay.PaySum, projectPay.PaySum)
+	balance, err := db.UpdateEnterpriseBalance(ctx, enterpriseId, 0, -projectPay.PaySum, projectPay.PaySum)
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[projectPay service] call UpdateEnterpriseBalance error,err:%+v", err)
 		return nil, err
@@ -35,7 +37,7 @@ func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequ
 	}
 
 	// 插入支付记录
-	recordId, err1 := db.CreatePayRecord(ctx, enterpriseID, projectPay.PaySum, *balance, 2, projectPay.ProjectID)
+	recordId, err1 := db.CreatePayRecord(ctx, enterpriseId, projectPay.PaySum, *balance, 2, projectPay.ProjectID)
 	if err1 != nil {
 		logrus.WithContext(ctx).Errorf("[projectPay service] call CreatePayRecord error,err:%+v", err)
 		return nil, err1
@@ -79,8 +81,21 @@ func (*projectPay) Pay(ctx context.Context, projectPay http_model.ProjectPayRequ
 func (p *projectPay) SpecialSettlePay(ctx *gin.Context, req *http_model.SpecialSettlePayRequest) error {
 	DB := db.GetReadDB(ctx)
 	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
-		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 {
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			return err
@@ -97,13 +112,50 @@ func (p *projectPay) SpecialSettlePay(ctx *gin.Context, req *http_model.SpecialS
 			return err
 		}
 
-		err = tx.Model(&gorm_model.YoungeeTaskInfo{}).Where("task_id = ?", req.TaskId).Updates(gorm_model.YoungeeTaskInfo{
+		//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,
+		//}).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,
-		}).Error
+		}
+		_, 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
+		}
+		t := time.Now()
+		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:       &t,
+			WithdrawAt:     nil,
+		}
+		err = db.CreateIncome(ctx, income, tx)
 		if err != nil {
 			logrus.WithContext(ctx).Errorf("[projectPay service] call SpecialSettlePay error,err:%+v", err)
 			return err

+ 60 - 6
service/sec_task.go

@@ -20,12 +20,47 @@ type selectionTask struct {
 }
 
 func (*selectionTask) GetList(ctx context.Context, request http_model.GetSecTaskListRequest) (*http_model.GetSecTaskListData, error) {
+	// sec_task:任务id、帐号昵称、粉丝数、收货地址、主页截图、主页链接、确认时间、申请时间、结算时间
+	// youngee_task_logistics: 物流公司、物流单号、发货时间、探店时间
+	// younggee_assignment_info:数据截图、作业链接
+	// selection_info: 返现金额、悬赏金额
+	// 1. 根据选品任务阶段、账号昵称or任务id查询任务基本信息(包括任务id、账号昵称、粉丝数、主页截图、主页链接、申请时间)
 	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)
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call GetSecTaskList error,err:%+v", err)
 		return nil, err
 	}
 
+	// 2. 根据不同查询类型查询补充信息
+	switch request.Type {
+	case 1: // 确定达人查询
+		// 确定达人不需要额外信息
+		break
+	case 2: // 发货管理查询 youngee_task_logistics
+		//发货管理根据任务阶段和商品类型查询物流信息
+		// 查询商品类型
+		product, err := db.GetProductType(ctx, request.SelectionId)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[sectask_service service] call GetAllSelection error,err:%+v", err)
+			return nil, err
+		}
+		secTaskList, err = db.GetSecTaskLogisticsList(ctx, secTaskList, request.SecTaskStatus, *product)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[sectask_service service] call GetSecTaskLogisticsList error,err:%+v", err)
+			return nil, err
+		}
+		break
+	case 3: // 结算管理查询 younggee_assignment_info
+		secTaskList, err = db.GetSecTaskSettleList(ctx, secTaskList, request.SelectionId, request.SecTaskStatus)
+		if err != nil {
+			logrus.WithContext(ctx).Errorf("[sectask_service service] call GetSecTaskSettleList error,err:%+v", err)
+			return nil, err
+		}
+		break
+	default: // 参数有误
+		break
+	}
+
 	selectionListData := http_model.GetSecTaskListData{
 		Total:       conv.MustString(total, ""),
 		SecTaskList: secTaskList,
@@ -120,10 +155,11 @@ func (*selectionTask) Settle(ctx context.Context, entersizeId string, request ht
 	if rewardMoney+returnMoney != payMoney {
 		return nil, errors.New("结算金额有误")
 	}
-	// 3. 扣除企业账户余额
-	_, err = db.UpdateEnterpriseBalance(ctx, entersizeId, 0, -payMoney, payMoney)
+
+	// 3. 更新选品结算金额
+	_, err = db.UpdateSelectionSettleMoney(ctx, selection.SelectionID, payMoney)
 	if err != nil {
-		logrus.WithContext(ctx).Errorf("[sectask_service service] call UpdateEnterpriseBalance error,err:%+v", err)
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call UpdateSelectionSettleMoney error,err:%+v", err)
 		return nil, err
 	}
 
@@ -132,6 +168,8 @@ func (*selectionTask) Settle(ctx context.Context, entersizeId string, request ht
 		TaskID:           request.TaskID,
 		TaskStage:        10,
 		AssignmentStatus: 5,
+		IsPayReward:      request.IsPayReward,
+		IsPayPayment:     request.IsReturnMoney,
 		CompleteDate:     time.Now(),
 	}
 	_, err = db.UpdateSecTask(ctx, updateSecTaskData)
@@ -139,9 +177,23 @@ func (*selectionTask) Settle(ctx context.Context, entersizeId string, request ht
 		logrus.WithContext(ctx).Errorf("[sectask_service service] call UpdateSecTask error,err:%+v", err)
 		return nil, err
 	}
+
 	// 5. 添加任务日志和达人消息
+	err = db.CreateTaskLog(ctx, request.TaskID, "结算时间")
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call CreateTaskLog error,err:%+v", err)
+		return nil, err
+	}
+
+	err = db.CreateMessageBySecTaskId(ctx, 5, 1, request.TaskID)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[sectask_service service] call CreateMessageBySecTaskId error,err:%+v", err)
+		return nil, err
+	}
+
 	// 6. 创建选品收益记录
 	// 返现收益
+	t := time.Now()
 	if request.IsReturnMoney == 1 {
 		income := gorm_model.YounggeeTalentIncome{
 			TalentID:       secTask.TalentID,
@@ -152,7 +204,8 @@ func (*selectionTask) Settle(ctx context.Context, entersizeId string, request ht
 			Income:         strconv.FormatFloat(returnMoney, 'f', 10, 32),
 			IncomeType:     1,
 			WithdrawStatus: 1,
-			IncomeAt:       time.Now(),
+			IncomeAt:       &t,
+			WithdrawAt:     nil,
 		}
 		err = db.CreateIncome(ctx, income, nil)
 		if err != nil {
@@ -171,7 +224,8 @@ func (*selectionTask) Settle(ctx context.Context, entersizeId string, request ht
 			Income:         strconv.FormatFloat(rewardMoney, 'f', 10, 32),
 			IncomeType:     1,
 			WithdrawStatus: 1,
-			IncomeAt:       time.Now(),
+			IncomeAt:       &t,
+			WithdrawAt:     nil,
 		}
 		err = db.CreateIncome(ctx, income, nil)
 		if err != nil {

+ 11 - 5
service/sec_task_logistics.go

@@ -45,7 +45,7 @@ func (*secLogistics) Create(ctx context.Context, request http_model.CreateSecTas
 	updatdSecTask := gorm_model.YounggeeSecTaskInfo{
 		TaskID:          request.TaskID,
 		LogisticsStatus: 2,
-		TaskStage:       7,
+		TaskStage:       8,
 		DeliveryDate:    time.Now(),
 	}
 	_, err = db.UpdateSecTask(ctx, updatdSecTask)
@@ -54,14 +54,14 @@ func (*secLogistics) Create(ctx context.Context, request http_model.CreateSecTas
 		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)
+	err = db.CreateMessageBySecTaskId(ctx, 8, 2, newLogistics.TaskID)
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[newLogistics service] call CreateMessageByTaskId error,err:%+v", err)
 		return nil, err
@@ -74,8 +74,14 @@ func (*secLogistics) Create(ctx context.Context, request http_model.CreateSecTas
 
 func (*secLogistics) Update(ctx context.Context, request http_model.UpdateSecTaskLogisticsRequest) (*http_model.UpdateSecTaskLogisticsData, error) {
 	ThingsType := request.ThingsType
+	// 根据任务查询物流id
+	logisticsInfo, err := db.GetLogistics(ctx, request.TaskID)
+	if err != nil {
+		logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
+		return nil, err
+	}
 	newLogistics := gorm_model.YoungeeTaskLogistics{
-		LogisticsID:           request.LogisticsId,
+		LogisticsID:           logisticsInfo.LogisticsID,
 		TaskID:                request.TaskID,
 		ThingsType:            int64(ThingsType),
 		ExplorestoreStarttime: time.Now(),
@@ -94,7 +100,7 @@ func (*secLogistics) Update(ctx context.Context, request http_model.UpdateSecTas
 		newLogistics.ExplorestoreEndtime = ExplorestoreEndtime
 	}
 
-	_, err := db.UpdateSecTaskLogistics(ctx, newLogistics)
+	_, err = db.UpdateSecTaskLogistics(ctx, newLogistics)
 	if err != nil {
 		logrus.WithContext(ctx).Errorf("[newLogistics service] call UpdatenewLogistics error,err:%+v", err)
 		return nil, err