package service

import (
	"encoding/json"
	"errors"
	"github.com/sirupsen/logrus"
	"reflect"
	"strings"
	"time"
	"youngee_b_api/app/dao"
	"youngee_b_api/app/entity"
	"youngee_b_api/app/service/review_service"
	"youngee_b_api/app/util"
	"youngee_b_api/app/vo"
)

type ProjectService struct{}

// 创建种草任务
func (s ProjectService) CreateProject(projectCreateParam *vo.ProjectCreateParam) (*string, error) {
	// a) 生成种草项目id
	projectId := strings.ReplaceAll(util.GenerateUUID(11), "-", "")
	// b) 查找关联商品信息
	product, err := dao.ProductDAO{}.GetProductByID(projectCreateParam.ProductId)
	if err != nil {
		return nil, err
	}
	if product == nil {
		return nil, errors.New("未找到关联商品")
	}
	productMainPhoto, _ := dao.ProductPhotoDAO{}.GetMainProductPhotoInfoByProductID(projectCreateParam.ProductId)
	productInfoToJson, _ := json.Marshal(product)
	productPhotosToJson, _ := json.Marshal(productMainPhoto)
	// d) 任务截止时间
	recruitDdl, err1 := time.ParseInLocation("2006-01-02 15:04:05", projectCreateParam.RecruitDdl, time.Local)
	if err1 != nil {
		return nil, errors.New("failed to parse recruitDdl")
	}
	// d)创建种草任务
	var operatorType int64
	if projectCreateParam.SubAccountId == 0 {
		operatorType = 1
	} else {
		operatorType = 2
	}

	// 获取定时任务配置id
	infoAutoTask := entity.InfoAutoTask{}
	infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(projectCreateParam.EnterpriseId)
	infoAutoDefault := entity.InfoAutoDefault{}
	infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(projectCreateParam.EnterpriseId)
	t := time.Now()
	if recruitDdl.Before(t) {
		return nil, errors.New("请修改截止时间")
	}
	newProject := entity.Project{
		ProjectStatus:    1,
		ProjectType:      projectCreateParam.ProjectType,
		ProjectId:        projectId,
		ProductID:        projectCreateParam.ProductId,
		ProductCategory:  product.ProductCategory,
		EnterpriseID:     projectCreateParam.EnterpriseId,
		SubAccountId:     projectCreateParam.SubAccountId,
		ProjectPlatform:  projectCreateParam.Platform,
		OperatorType:     operatorType,
		ProductSnap:      string(productInfoToJson),
		ProductPhotoSnap: string(productPhotosToJson),
		CreatedAt:        t,
		AutoTaskID:       infoAutoTask.AutoTaskID,
		AutoDefaultID:    infoAutoDefault.AutoDefaultID,
		ProjectName:      projectCreateParam.ProjectName,
		TalentType:       projectCreateParam.TalentType,
		RecruitDdl:       recruitDdl,
		ProjectForm:      projectCreateParam.ProjectForm,
		ContentType:      projectCreateParam.ContentType,
		ProjectDetail:    projectCreateParam.ProjectDetail,
		Tools:            projectCreateParam.Tools,
	}
	if projectCreateParam.ProjectType == 1 {
		newProject.ServiceChargeRate = projectCreateParam.ServiceChargeRate
	}
	err = dao.ProjectDAO{}.CreateProject(newProject)
	if err != nil {
		return nil, err
	}

	// 4. 更新选品brief和示例（种草任务补充信息）
	if projectCreateParam.ProjectBrief != nil {
		// 插入新的brief
		for _, v := range projectCreateParam.ProjectBrief {
			brief := entity.ProjectBrief{
				ProjectID: projectId,
				FileUid:   v.FileUid,
				FileName:  v.Name,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
			if err != nil {
				return nil, err
			}
		}
	}
	if projectCreateParam.ProjectMaterial != nil {
		// 插入新的示例
		for _, v := range projectCreateParam.ProjectMaterial {
			projectMaterial := entity.ProjectMaterial{
				ProjectID: projectId,
				FileUid:   v.FileUid,
				FileName:  v.Name,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
			if err != nil {
				return nil, err
			}
		}
	}
	// 更新公开种草任务的招募策略
	var totalRecruitNum int64
	var estimatedCost float64
	if projectCreateParam.RecruitStrategys != nil {
		// 2. 接收并创建新的招募策略
		if len(projectCreateParam.RecruitStrategys) != 0 {
			var recruits []entity.RecruitStrategy
			for _, strategy := range projectCreateParam.RecruitStrategys {
				if strategy.FeeForm == 2 {
					estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
				}
				recruitStrategy := entity.RecruitStrategy{
					FeeForm:       strategy.FeeForm,
					StrategyID:    strategy.StrategyID,
					FollowersLow:  strategy.FollowersLow,
					FollowersUp:   strategy.FollowersUp,
					RecruitNumber: strategy.RecruitNumber,
					ProjectID:     projectId,
					StrategyType:  1,
					ServiceRate:   projectCreateParam.ServiceChargeRate,
				}
				totalRecruitNum += strategy.RecruitNumber
				if strategy.FeeForm == 2 {
					recruitStrategy.Offer = strategy.Offer
					recruitStrategy.ServiceCharge = strategy.Offer * projectCreateParam.ServiceChargeRate * 0.01
					recruitStrategy.TOffer = strategy.Offer * (1 - projectCreateParam.ServiceChargeRate*0.01)
				}
				recruits = append(recruits, recruitStrategy)
			}
			err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
			if err != nil {
				return nil, err
			}
		}
	}
	_ = dao.ProjectDAO{}.UpdateProject(entity.Project{
		ProjectId:     projectId,
		EstimatedCost: estimatedCost,
	})

	return &projectId, nil
}

// 更新公开种草任务（招募要求、执行要求）
func (s ProjectService) UpdateProject(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
	// 1. 检查该项目id有无种草任务
	projectID := projectUpdateParam.ProjectID
	project, err := dao.ProjectDAO{}.GetProjectById(projectID)
	if err != nil {
		return nil, err
	}
	if project == nil {
		return nil, errors.New("种草项目不存在")
	}
	recruitDdl := time.Time{} //赋零值
	recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", projectUpdateParam.RecruitDdl, time.Local)
	if recruitDdl.Before(project.CreatedAt) {
		return nil, errors.New("请修改截止时间")
	}
	// 更新公开种草任务的招募策略
	var totalRecruitNum int64
	var estimatedCost float64
	if projectUpdateParam.RecruitStrategys != nil {
		// 1. 删除已有的招募策略
		err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(projectUpdateParam.ProjectID)
		if err != nil {
			return nil, err
		}
		// 2. 接收并创建新的招募策略
		if len(projectUpdateParam.RecruitStrategys) != 0 {
			var recruits []entity.RecruitStrategy
			for _, strategy := range projectUpdateParam.RecruitStrategys {
				if strategy.FeeForm == 2 {
					estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
				}
				recruitStrategy := entity.RecruitStrategy{
					FeeForm:       strategy.FeeForm,
					StrategyID:    strategy.StrategyID,
					FollowersLow:  strategy.FollowersLow,
					FollowersUp:   strategy.FollowersUp,
					RecruitNumber: strategy.RecruitNumber,
					ProjectID:     project.ProjectId,
					StrategyType:  1,
					ServiceRate:   project.ServiceChargeRate,
				}
				totalRecruitNum += strategy.RecruitNumber
				if strategy.FeeForm == 2 {
					recruitStrategy.Offer = strategy.Offer
					recruitStrategy.ServiceCharge = strategy.Offer * projectUpdateParam.ServiceChargeRate * 0.01
					recruitStrategy.TOffer = strategy.Offer * (1 - projectUpdateParam.ServiceChargeRate*0.01)
				}
				recruits = append(recruits, recruitStrategy)
			}
			err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
			if err != nil {
				return nil, err
			}
		}
	}
	// 2. 数据准备
	// a) 查找关联商品信息
	var productInfoToString string
	var productPhotosToString string
	if projectUpdateParam.ProductId != 0 {
		product, err := dao.ProductDAO{}.GetProductByID(projectUpdateParam.ProductId)
		if err != nil {
			return nil, err
		}
		if product == nil {
			return nil, errors.New("未找到关联商品")
		}
		productMainPhoto, _ := dao.ProductPhotoDAO{}.GetMainProductPhotoInfoByProductID(projectUpdateParam.ProductId)
		productInfoToJson, _ := json.Marshal(product)
		productInfoToString = string(productInfoToJson)
		productPhotosToJson, _ := json.Marshal(productMainPhoto)
		productPhotosToString = string(productPhotosToJson)
	}

	// d) 任务截止时间
	//// f) 更新选品状态
	//if projectUpdateParam.ProjectStatus != 2 && projectUpdateParam.ProjectStatus != 8 {
	//	projectUpdateParam.ProjectStatus = 1
	//}
	t := time.Now()
	updateProject := entity.Project{
		//ProjectStatus:     projectUpdateParam.ProjectStatus,
		ServiceChargeRate: projectUpdateParam.ServiceChargeRate,
		ProjectName:       projectUpdateParam.ProjectName,
		ProductID:         projectUpdateParam.ProductId,
		TalentType:        projectUpdateParam.TalentType,
		RecruitDdl:        recruitDdl,
		ProductSnap:       productInfoToString,
		ProductPhotoSnap:  productPhotosToString,
		UpdatedAt:         t,
		ProjectForm:       projectUpdateParam.ProjectForm,
		ContentType:       projectUpdateParam.ContentType,
		ProjectDetail:     projectUpdateParam.ProjectDetail,
		EstimatedCost:     estimatedCost,
	}
	//if projectUpdateParam.ProjectStatus == 2 {
	//	updateProject.SubmitAt = t
	//}
	// 合并传入参数和数据表中原记录，若传入参数字段值为空，则将字段赋值为原记录中值
	result := util.MergeStructValue(&updateProject, project)
	// 利用反射机制将interface类型转换为结构体类型
	v := reflect.ValueOf(&result).Elem()
	if v.Kind() == reflect.Struct {
		updateProject = v.Interface().(entity.Project)
		//fmt.Println(p)
	}
	// c) 计算预估成本（如果有）
	/*
		var estimatedCost float64
		if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
			estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
		}
		estimatedCostToString, _ := conv.String(estimatedCost)
		updateSelection.EstimatedCost = estimatedCostToString
	*/
	// 3. 更新选品
	err = dao.ProjectDAO{}.UpdateProject(updateProject)
	if err != nil {
		return nil, err
	}
	// 4. 更新选品brief和示例（种草任务补充信息）
	if projectUpdateParam.ProjectBrief != nil {
		// 删除已有brief
		err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(project.ProjectId)
		if err != nil {
			return nil, err
		}
		// 插入新的brief
		for _, v := range projectUpdateParam.ProjectBrief {
			brief := entity.ProjectBrief{
				ProjectID: project.ProjectId,
				FileUid:   v.FileUid,
				FileName:  v.Name,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
			if err != nil {
				return nil, err
			}
		}
	}

	if projectUpdateParam.ProjectMaterial != nil {
		// 删除已有示例
		err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(project.ProjectId)
		if err != nil {
			return nil, err
		}
		// 插入新的示例
		for _, v := range projectUpdateParam.ProjectMaterial {
			projectMaterial := entity.ProjectMaterial{
				ProjectID: project.ProjectId,
				FileUid:   v.FileUid,
				FileName:  v.Name,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
			if err != nil {
				return nil, err
			}
		}
	}

	return &updateProject.ProjectId, nil
}

// 更新定向种草任务（招募要求、执行要求）
func (s ProjectService) UpdateProjectTarget(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
	// 1. 检查该项目id有无种草任务
	projectID := projectUpdateParam.ProjectID
	project, err := dao.ProjectDAO{}.GetProjectById(projectID)
	if err != nil {
		return nil, err
	}
	if project == nil {
		return nil, errors.New("种草项目不存在")
	}
	println("更新定向种草任务的招募策略")
	// 更新定向种草任务的招募策略
	var totalRecruitNum int64
	var estimatedCost float64
	if projectUpdateParam.RecruitStrategys != nil {
		// 1. 删除已有的招募策略
		err = dao.RecruitStrategyDao{}.DeleteRecruitStrategyByProjectID(projectUpdateParam.ProjectID)
		if err != nil {
			return nil, err
		}
		// 2. 接收并创建新的招募策略
		if len(projectUpdateParam.RecruitStrategys) != 0 {
			var recruits []entity.RecruitStrategy
			for _, strategy := range projectUpdateParam.RecruitStrategys {
				if strategy.FeeForm == 2 {
					estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
				}
				recruitStrategy := entity.RecruitStrategy{
					FeeForm:       strategy.FeeForm,
					StrategyID:    strategy.StrategyID,
					FollowersLow:  strategy.FollowersLow,
					FollowersUp:   strategy.FollowersUp,
					RecruitNumber: strategy.RecruitNumber,
					ProjectID:     project.ProjectId,
					StrategyType:  1,
					ServiceRate:   project.ServiceChargeRate,
				}
				totalRecruitNum += strategy.RecruitNumber
				if strategy.FeeForm == 2 {
					recruitStrategy.Offer = strategy.Offer // 报价
				}
				recruits = append(recruits, recruitStrategy)
			}
			err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
			if err != nil {
				return nil, err
			}
		}
	}
	// 2. 数据准备
	// a) 查找关联商品信息
	var productInfoToString string
	var productPhotosToString string
	if projectUpdateParam.ProductId != 0 {
		product, err := dao.ProductDAO{}.GetProductByID(projectUpdateParam.ProductId)
		if err != nil {
			return nil, err
		}
		if product == nil {
			return nil, errors.New("未找到关联商品")
		}
		productMainPhoto, _ := dao.ProductPhotoDAO{}.GetMainProductPhotoInfoByProductID(projectUpdateParam.ProductId)
		productInfoToJson, _ := json.Marshal(product)
		productInfoToString = string(productInfoToJson)
		productPhotosToJson, _ := json.Marshal(productMainPhoto)
		productPhotosToString = string(productPhotosToJson)
	}

	// d) 任务截止时间
	recruitDdl := time.Time{} //赋零值
	recruitDdl, _ = time.ParseInLocation("2006-01-02 15:04:05", projectUpdateParam.RecruitDdl, time.Local)
	//// f) 更新选品状态
	//if projectUpdateParam.ProjectStatus != 2 && projectUpdateParam.ProjectStatus != 8 {
	//	projectUpdateParam.ProjectStatus = 1
	//}
	t := time.Now()
	updateProject := entity.Project{
		//ProjectStatus:    projectUpdateParam.ProjectStatus,
		ProjectName:      projectUpdateParam.ProjectName,
		ProductID:        projectUpdateParam.ProductId,
		TalentType:       projectUpdateParam.TalentType,
		RecruitDdl:       recruitDdl,
		ProductSnap:      productInfoToString,
		ProductPhotoSnap: productPhotosToString,
		CreatedAt:        project.CreatedAt,
		UpdatedAt:        t,
		ProjectForm:      projectUpdateParam.ProjectForm,
		ContentType:      projectUpdateParam.ContentType,
		ProjectDetail:    projectUpdateParam.ProjectDetail,
		Tools:            projectUpdateParam.Tools,
		EstimatedCost:    estimatedCost,
	}
	//if projectUpdateParam.ProjectStatus == 2 {
	//	updateProject.SubmitAt = t
	//}
	// 合并传入参数和数据表中原记录，若传入参数字段值为空，则将字段赋值为原记录中值
	result := util.MergeStructValue(&updateProject, project)
	// 利用反射机制将interface类型转换为结构体类型
	v := reflect.ValueOf(&result).Elem()
	if v.Kind() == reflect.Struct {
		updateProject = v.Interface().(entity.Project)
		//fmt.Println(p)
	}
	// c) 计算预估成本（如果有）
	/*
		var estimatedCost float64
		if conv.MustInt(updateSelection.TaskMode, 0) == 1 {
			estimatedCost = conv.MustFloat64(updateSelection.TaskReward, 0) * conv.MustFloat64(updateSelection.SampleNum, 0)
		}
		estimatedCostToString, _ := conv.String(estimatedCost)
		updateSelection.EstimatedCost = estimatedCostToString
	*/
	// 3. 更新选品
	err = dao.ProjectDAO{}.UpdateProject(updateProject)
	if err != nil {
		return nil, err
	}
	// 4. 更新选品brief和示例（种草任务补充信息）
	if projectUpdateParam.ProjectBrief != nil {
		// 删除已有brief
		err = dao.ProjectBriefDao{}.DeleteSecBriefBySelectionId(project.ProjectId)
		if err != nil {
			return nil, err
		}
		// 插入新的brief
		for _, v := range projectUpdateParam.ProjectBrief {
			brief := entity.ProjectBrief{
				ProjectID: project.ProjectId,
				FileUid:   v.FileUid,
				FileName:  v.Name,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
			if err != nil {
				return nil, err
			}
		}
	}
	if projectUpdateParam.ProjectMaterial != nil {
		// 删除已有示例
		err = dao.ProjectMaterialDao{}.DeleteProjectMaterialByProjectId(project.ProjectId)
		if err != nil {
			return nil, err
		}
		// 插入新的示例
		for _, v := range projectUpdateParam.ProjectMaterial {
			projectMaterial := entity.ProjectMaterial{
				ProjectID: project.ProjectId,
				FileUid:   v.FileUid,
				FileName:  v.Name,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
			if err != nil {
				return nil, err
			}
		}
	}

	return &updateProject.ProjectId, nil
}

// 种草任务预览
func (s ProjectService) GetProjectDetail(projectId string) (*vo.ReProjectDetail, error) {
	reProjectDetail := vo.ReProjectDetail{}
	project, err := dao.ProjectDAO{}.GetProjectById(projectId)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetProject error,err:%+v", err)
		return nil, err
	}
	reProjectDetail.ProjectName = project.ProjectName
	// 系统信息
	reProjectDetail.ProjectId = projectId
	reProjectDetail.ProjectStatus = project.ProjectStatus
	reProjectDetail.ProjectPlatform = project.ProjectPlatform
	reProjectDetail.CreatedAt = project.CreatedAt.Format("2006-01-02 15:04:05")
	if project.ProjectStatus < 6 {
		reProjectDetail.EstimatedCost = project.EstimatedCost
	} else {
		reProjectDetail.EstimatedCost = project.NeedPay
	}
	reProjectDetail.ServiceChargeRate = project.ServiceChargeRate
	var creatorName, phone string
	if project.SubAccountId == 0 {
		enterprise, err := dao.EnterpriseDao{}.GetEnterprise(project.EnterpriseID)
		if err == nil && enterprise != nil {
			creatorName = enterprise.BusinessName
			phone, err = dao.UserDao{}.GetPhoneByUserId(enterprise.UserId)
		}
	} else {
		subAccount, err := dao.SubAccountDao{}.GetSubAccount(project.SubAccountId)
		if err == nil && subAccount != nil {
			creatorName = subAccount.SubAccountName
			phone, err = dao.UserDao{}.GetPhoneByUserId(subAccount.UserId)
		}
	}
	reProjectDetail.CreatorName = creatorName
	reProjectDetail.Phone = phone
	// 关联商品
	var reProduct vo.ReProductPreview
	var product entity.Product
	var productMainPhoto entity.ProductPhoto
	err1 := json.Unmarshal([]byte(project.ProductSnap), &product)
	err2 := json.Unmarshal([]byte(project.ProductPhotoSnap), &productMainPhoto)
	if err1 == nil && err2 == nil {
		reProduct = vo.ReProductPreview{
			ProductID:       product.ProductID,
			ProductName:     product.ProductName,
			ProductType:     product.ProductType,
			ProductCategory: product.ProductCategory,
			ProductPrice:    product.ProductPrice,
			ProductDetail:   product.ProductDetail,
			CreatedAt:       product.CreatedAt.Format("2006-01-02 15:04:05"),
			PhotoUrl:        productMainPhoto.PhotoUrl,
		}
	}
	reProjectDetail.ProductInfo = &reProduct
	// 招募要求
	reProjectDetail.TalentType = project.TalentType
	reProjectDetail.RecruitDdl = project.RecruitDdl.Format("2006-01-02 15:04:05")
	reProjectDetail.ProjectForm = project.ProjectForm
	reProjectDetail.ContentType = project.ContentType
	reProjectDetail.ProjectDetail = project.ProjectDetail
	var recruitStrategysPreviews []*vo.RecruitStrategyPreview
	recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(projectId)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetRecruitStrategy error,err:%+v", err)
		return nil, err
	}
	for _, recruitStrategy := range recruitStrategys {
		recruitStrategysPreview := &vo.RecruitStrategyPreview{
			StrategyId:     recruitStrategy.StrategyID,
			FeeForm:        recruitStrategy.FeeForm,
			FollowersLow:   recruitStrategy.FollowersLow,
			FollowersUp:    recruitStrategy.FollowersUp,
			RecruitNumber:  recruitStrategy.RecruitNumber,
			Offer:          recruitStrategy.Offer,
			TOffer:         recruitStrategy.TOffer,
			ServiceCharge:  recruitStrategy.ServiceCharge,
			SelectedNumber: recruitStrategy.SelectedNumber,
			TotalOffer:     recruitStrategy.TotalOffer,
		}
		recruitStrategysPreviews = append(recruitStrategysPreviews, recruitStrategysPreview)
	}
	reProjectDetail.RecruitStrategys = recruitStrategysPreviews
	// 执行要求
	projectBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(projectId)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetProjectBriefInfo error,err:%+v", err)
		return nil, err
	}
	projectMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(projectId)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetprojectMaterialInfo error,err:%+v", err)
		return nil, err
	}
	reProjectDetail.ProjectBriefs = projectBriefInfos
	reProjectDetail.ProjectMaterials = projectMaterials
	reProjectDetail.Tools = project.Tools

	return &reProjectDetail, nil
}

// 复制种草任务
func (s ProjectService) CopyProject(param *vo.ProjectSearchParam) (*string, error) {
	projectOrigin, err := dao.ProjectDAO{}.GetProjectById(param.ProjectId)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetProject error,err:%+v", err)
		return nil, err
	}
	if projectOrigin == nil {
		return nil, errors.New("任务不存在")
	}
	projectIdOrigin := projectOrigin.ProjectId
	projectIdNew := strings.ReplaceAll(util.GenerateUUID(11), "-", "")
	t := time.Now()
	// 获取定时任务配置id
	infoAutoTask := entity.InfoAutoTask{}
	infoAutoTask = dao.InfoAutoTaskDao{}.GetAutoTaskLast(param.EnterpriseId)
	infoAutoDefault := entity.InfoAutoDefault{}
	infoAutoDefault = dao.InfoAutoDefaultDao{}.GetAutoDefaultLast(param.EnterpriseId)

	// 复制任务
	projectNew := entity.Project{
		ProjectStatus:     1,
		ProjectType:       projectOrigin.ProjectType,
		ProjectId:         projectIdNew,
		ProductID:         projectOrigin.ProductID,
		ProductCategory:   projectOrigin.ProductCategory,
		EnterpriseID:      param.EnterpriseId,
		SubAccountId:      param.SubAccountId,
		ProjectPlatform:   projectOrigin.ProjectPlatform,
		OperatorType:      projectOrigin.OperatorType,
		ProductSnap:       projectOrigin.ProductSnap,
		ProductPhotoSnap:  projectOrigin.ProductPhotoSnap,
		CreatedAt:         t,
		AutoTaskID:        infoAutoTask.AutoTaskID,
		AutoDefaultID:     infoAutoDefault.AutoDefaultID,
		ProjectName:       projectOrigin.ProjectName,
		TalentType:        projectOrigin.TalentType,
		RecruitDdl:        projectOrigin.RecruitDdl,
		ProjectForm:       projectOrigin.ProjectForm,
		ContentType:       projectOrigin.ContentType,
		ProjectDetail:     projectOrigin.ProjectDetail,
		Tools:             projectOrigin.Tools,
		ServiceChargeRate: projectOrigin.ServiceChargeRate,
		EstimatedCost:     projectOrigin.EstimatedCost,
	}
	err = dao.ProjectDAO{}.CreateProject(projectNew)
	if err != nil {
		return nil, err
	}

	// 更新选品brief和示例（种草任务补充信息）
	projectBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(projectIdOrigin)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetProjectBriefInfo error,err:%+v", err)
		return nil, err
	}
	if projectBriefInfos != nil {
		for _, v := range projectBriefInfos {
			brief := entity.ProjectBrief{
				ProjectID: projectIdNew,
				FileUid:   v.FileUid,
				FileName:  v.FileName,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectBriefDao{}.CreateProjectBrief(brief)
			if err != nil {
				return nil, err
			}
		}
	}
	projectMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(projectIdOrigin)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetprojectMaterialInfo error,err:%+v", err)
		return nil, err
	}
	if projectMaterials != nil {
		// 插入新的示例
		for _, v := range projectMaterials {
			projectMaterial := entity.ProjectMaterial{
				ProjectID: projectIdNew,
				FileUid:   v.FileUid,
				FileName:  v.FileName,
				FileUrl:   v.FileUrl,
				CreatedAt: time.Now(),
				Type:      v.Type,
			}
			err = dao.ProjectMaterialDao{}.CreateProjectMaterial(projectMaterial)
			if err != nil {
				return nil, err
			}
		}
	}
	// 更新种草任务的招募策略
	recruitStrategys, err := dao.RecruitStrategyDao{}.GetRecruitStrategyByProjectId(projectIdOrigin)
	if err != nil {
		logrus.Errorf("[projectDB service] call GetRecruitStrategy error,err:%+v", err)
		return nil, err
	}
	var totalRecruitNum int64
	var estimatedCost float64
	if recruitStrategys != nil {
		// 2. 接收并创建新的招募策略
		if len(recruitStrategys) != 0 {
			var recruits []entity.RecruitStrategy
			for _, strategy := range recruitStrategys {
				if strategy.FeeForm == 2 {
					estimatedCost += float64(strategy.RecruitNumber) * strategy.Offer
				}
				recruitStrategy := entity.RecruitStrategy{
					FeeForm:       strategy.FeeForm,
					StrategyID:    strategy.StrategyID,
					FollowersLow:  strategy.FollowersLow,
					FollowersUp:   strategy.FollowersUp,
					RecruitNumber: strategy.RecruitNumber,
					ProjectID:     projectIdNew,
					StrategyType:  strategy.StrategyType,
					ServiceRate:   strategy.ServiceRate,
					Offer:         strategy.Offer,
					ServiceCharge: strategy.ServiceCharge,
					TOffer:        strategy.TOffer,
				}
				totalRecruitNum += strategy.RecruitNumber
				recruits = append(recruits, recruitStrategy)
			}
			err = dao.RecruitStrategyDao{}.CreateRecruitStrategy(recruits)
			if err != nil {
				return nil, err
			}
		}
	}

	return &projectIdNew, nil
}

// 种草提交审核
func (s ProjectService) ProjectToReview(projectUpdateParam *vo.ProjectUpdateParam) (*string, error) {
	projectId := projectUpdateParam.ProjectID

	project, err := dao.ProjectDAO{}.GetProjectById(projectId)
	if err != nil {
		logrus.Errorf("[projectInfoDB service] call GetProject error,err:%+v", err)
		return nil, err
	}

	projectName := project.ProjectName     // 任务标题
	projectDetail := project.ProjectDetail // 任务详情
	product, err := dao.ProductDAO{}.GetProductByID(project.ProductID)
	if err != nil {
		return nil, err
	}
	productName := product.ProductName     // 商品标题
	productDetail := product.ProductDetail // 卖点总结
	mainPhoto, err1 := dao.ProductPhotoDAO{}.GetMainPhotoByProductID(project.ProductID)
	if err1 != nil {
		return nil, err1
	}
	var images []string
	var videos []string
	var videoJobIds []string
	var documents []string
	var documentJobIds []string
	reviewService := review_service.GetConfig()

	productPhotos, err2 := dao.ProductPhotoDAO{}.GetProductPhotoByProductID(project.ProductID)
	if err2 != nil {
		return nil, err2
	}
	for _, productPhoto := range productPhotos {
		if productPhoto.Symbol == 2 || productPhoto.Symbol == 4 {
			images = append(images, productPhoto.PhotoUrl)
		} else if productPhoto.Symbol == 3 || productPhoto.Symbol == 5 {
			var videoJobId *string
			var reviewErr error
			i := 10
			for {
				videoJobId, reviewErr = reviewService.CheckVideo(productPhoto.PhotoUrl)
				if reviewErr == nil || i == 0 {
					break
				}
				i -= 1
			}
			if reviewErr != nil {
				return nil, reviewErr
			}
			videos = append(videos, productPhoto.PhotoUrl)
			videoJobIds = append(videoJobIds, *videoJobId)
		}
	}

	projectBriefInfos, err := dao.ProjectBriefDao{}.GetProjectBriefInfo(projectId)
	if err != nil {
		return nil, err
	}
	for _, projectBriefInfo := range projectBriefInfos {
		if projectBriefInfo.Type == 1 {
			images = append(images, projectBriefInfo.FileUrl)
		} else if projectBriefInfo.Type == 2 {
			var documentJobId *string
			var reviewErr error
			i := 10
			fileType := "pdf"
			parts := strings.Split(projectBriefInfo.FileName, ".")
			if len(parts) > 1 {
				fileType = parts[len(parts)-1]
			}
			for {
				documentJobId, reviewErr = reviewService.CheckDocument(projectBriefInfo.FileUrl, fileType)
				if reviewErr == nil || i == 0 {
					break
				}
				i -= 1
			}
			if reviewErr != nil {
				return nil, reviewErr
			}
			documents = append(documents, projectBriefInfo.FileUrl)
			documentJobIds = append(documentJobIds, *documentJobId)
		}
	}
	projectMaterials, err := dao.ProjectMaterialDao{}.GetProjectMaterialInfo(projectId)
	if err != nil {
		return nil, err
	}
	for _, projectMaterial := range projectMaterials {
		if projectMaterial.Type == 1 {
			images = append(images, projectMaterial.FileUrl)
		} else if projectMaterial.Type == 2 {
			var videoJobId *string
			var reviewErr error
			i := 10
			for {
				videoJobId, reviewErr = reviewService.CheckVideo(projectMaterial.FileUrl)
				if reviewErr == nil || i == 0 {
					break
				}
				i -= 1
			}
			if reviewErr != nil {
				return nil, reviewErr
			}
			videos = append(videos, projectMaterial.FileUrl)
			videoJobIds = append(videoJobIds, *videoJobId)
		}
	}

	newReviewProject := &entity.ReviewProject{
		ProjectID:      projectId,
		TaskName:       projectName,
		TaskDetail:     projectDetail,
		ProductName:    productName,
		ProductDetail:  productDetail,
		MainPhoto:      mainPhoto,
		Images:         strings.Join(images, ","),
		Videos:         strings.Join(videos, ","),
		Documents:      strings.Join(documents, ","),
		VideoJobIds:    strings.Join(videoJobIds, ","),
		DocumentJobIds: strings.Join(documentJobIds, ","),
		Status:         1,
	}
	err5 := dao.ProjectReviewDao{}.Create(newReviewProject)
	if err5 != nil {
		return nil, err5
	}

	t := time.Now()
	updateProject := entity.Project{
		ProjectId:     projectId,
		ProjectStatus: 2,
		SubmitAt:      t,
		UpdatedAt:     t,
	}
	err6 := dao.ProjectDAO{}.UpdateProject(updateProject)
	if err6 != nil {
		return nil, err
	}
	return &projectId, nil
}

// 种草任务列表
func (s ProjectService) GetProjectTaskList(param *vo.ProjectSearchParam) (vo.ResultVO, error) {
	if param.Page == 0 {
		param.Page = 1
	}
	if param.PageSize == 0 {
		param.PageSize = 10
	}
	var result vo.ResultVO
	reProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetProjectPreviews(param)
	if err != nil {
		return result, err
	}
	for i := range reProjectTaskPreviews {
		var creatorName string
		var productName string
		var productPrice float64
		var mainImage string
		if reProjectTaskPreviews[i].SubAccountId == 0 {
			enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reProjectTaskPreviews[i].EnterpriseId)
			if err == nil && enterprise != nil {
				creatorName = enterprise.BusinessName
			}
		} else {
			subAccount, err := dao.SubAccountDao{}.GetSubAccount(reProjectTaskPreviews[i].SubAccountId)
			if err == nil && subAccount != nil {
				creatorName = subAccount.SubAccountName
			}
		}
		product, err := dao.ProductDAO{}.GetProductByID(reProjectTaskPreviews[i].ProductId)
		if err == nil && product != nil {
			productName = product.ProductName
			productPrice = product.ProductPrice
		}
		mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reProjectTaskPreviews[i].ProductId)
		reProjectTaskPreviews[i].CreatorName = creatorName
		reProjectTaskPreviews[i].ProductName = productName
		reProjectTaskPreviews[i].ProductPrice = productPrice
		reProjectTaskPreviews[i].MainImage = mainImage
	}
	result = vo.ResultVO{
		Page:     param.Page,
		PageSize: param.PageSize,
		Total:    total,
		Data:     reProjectTaskPreviews,
	}
	return result, nil
}

// 删除种草任务
func (s ProjectService) DeleteProject(projectId string) (*string, error) {
	res, err := dao.ProjectDAO{}.DeleteProject(projectId)
	if err != nil {
		logrus.Errorf("[projectDB service] call DeleteProject error,err:%+v", err)
		return res, err
	}
	return res, nil
}

// 结束种草任务
func (s ProjectService) CloseProject(projectId string) (string, error) {
	// 任务待办：待审核、待支付、达人未处理、初稿待审、链接待审、待结算  待发货、待签收  未传初稿、未发作品、未传数据
	// 合作待办：可邀约、邀约中、合作中
	project, err := dao.ProjectDAO{}.GetProjectById(projectId)
	if err != nil {
		return "0", err
	}
	if project == nil {
		return "0", errors.New("任务不存在")
	}
	var needProcess int64
	if project.ProjectStatus == 4 || project.ProjectStatus == 8 {
		// 达人未处理 or 物流待办 or 初稿待审、链接待审、待结算
		_ = dao.Db.Model(&entity.ProjectTaskInfo{}).Where("project_id = ? and (task_status = ? or task_stage < ?)", projectId, 1, 15).Count(&needProcess).Error // task_status=1待选
	}
	if project.ProjectStatus == 2 || project.ProjectStatus == 4 || needProcess > 0 {
		// 存在待办不可结束
		return "1", nil
	} else {
		err := dao.ProjectDAO{}.UpdateProject(entity.Project{
			ProjectId:     projectId,
			ProjectStatus: 10,
			UpdatedAt:     time.Now(),
		})
		return "0", err
	}
}

// 草稿箱——品牌种草
func (s ProjectService) GetProjectDraftList(param *vo.ProjectDraftParam) (vo.ResultVO, error) {
	if param.Page == 0 {
		param.Page = 1
	}
	if param.PageSize == 0 {
		param.PageSize = 10
	}
	var result vo.ResultVO
	reProjectTaskPreviews, total, err := (&dao.ProjectDAO{}).GetProjectDraftList(param)
	if err != nil {
		return result, err
	}
	for i := range reProjectTaskPreviews {
		var creatorName string
		var productName string
		var productPrice float64
		var mainImage string
		if reProjectTaskPreviews[i].SubAccountId == 0 {
			enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reProjectTaskPreviews[i].EnterpriseId)
			if err == nil && enterprise != nil {
				creatorName = enterprise.BusinessName
			}
		} else {
			subAccount, err := dao.SubAccountDao{}.GetSubAccount(reProjectTaskPreviews[i].SubAccountId)
			if err == nil && subAccount != nil {
				creatorName = subAccount.SubAccountName
			}
		}
		product, err := dao.ProductDAO{}.GetProductByID(reProjectTaskPreviews[i].ProductId)
		if err == nil && product != nil {
			productName = product.ProductName
			productPrice = product.ProductPrice
		}
		mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reProjectTaskPreviews[i].ProductId)
		reProjectTaskPreviews[i].CreatorName = creatorName
		reProjectTaskPreviews[i].ProductName = productName
		reProjectTaskPreviews[i].ProductPrice = productPrice
		reProjectTaskPreviews[i].MainImage = mainImage
	}
	result = vo.ResultVO{
		Page:     param.Page,
		PageSize: param.PageSize,
		Total:    total,
		Data:     reProjectTaskPreviews,
	}
	return result, nil
}

// 达人内容类型
func (p ProjectService) GetTalentCategory() ([]vo.ReTalentCategory, error) {
	var reTalentCategories []vo.ReTalentCategory
	talentCategory, err := dao.TalentInfoDao{}.GetTalentCategory()
	if err != nil {
		return nil, err
	}
	for _, category := range talentCategory {
		reTalentCategory := vo.ReTalentCategory{
			ID:       category.ID,
			Category: category.Category,
		}
		reTalentCategories = append(reTalentCategories, reTalentCategory)
	}
	return reTalentCategories, nil
}

// 种草任务待办
func (p ProjectService) GetTaskToDo(enterpriseId string, subAccountId int64, taskType int64) (map[string]map[string]int64, error) {
	res := make(map[string]map[string]int64)
	redbook, err1 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 1, taskType)
	if err1 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err1)
		return res, err1
	}
	douyin, err2 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 2, taskType)
	if err2 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err2)
		return res, err2
	}
	kuaishou, err3 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 4, taskType)
	if err3 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err3)
		return res, err3
	}
	weibo, err4 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 3, taskType)
	if err4 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err4)
		return res, err4
	}
	bilibili, err5 := dao.ProjectDAO{}.GetProjectToDo(enterpriseId, subAccountId, 5, taskType)
	if err5 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err5)
		return res, err5
	}
	all := make(map[string]int64)
	all["needReview"] = redbook["needReview"] + douyin["needReview"] + kuaishou["needReview"] + weibo["needReview"] + bilibili["needReview"]
	all["needPay"] = redbook["needPay"] + douyin["needPay"] + kuaishou["needPay"] + weibo["needPay"] + bilibili["needPay"]
	all["needProcess"] = redbook["needProcess"] + douyin["needProcess"] + kuaishou["needProcess"] + weibo["needProcess"] + bilibili["needProcess"]
	all["needCheck"] = redbook["needCheck"] + douyin["needCheck"] + kuaishou["needCheck"] + weibo["needCheck"] + bilibili["needCheck"]
	all["needQuality"] = redbook["needQuality"] + douyin["needQuality"] + kuaishou["needQuality"] + weibo["needQuality"] + bilibili["needQuality"]
	all["needCalculate"] = redbook["needCalculate"] + douyin["needCalculate"] + kuaishou["needCalculate"] + weibo["needCalculate"] + bilibili["needCalculate"]
	res["redbook"] = redbook
	res["douyin"] = douyin
	res["kuaishou"] = kuaishou
	res["weibo"] = weibo
	res["bilibili"] = bilibili
	res["all"] = all

	return res, nil
}

// 寄样物流任务待办
func (p ProjectService) GetLogisticsToDo(enterpriseId string, subAccountId int64) (map[string]map[string]int64, error) {
	res := make(map[string]map[string]int64)
	redbook, err1 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 1)
	if err1 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err1)
		return res, err1
	}
	douyin, err2 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 2)
	if err2 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err2)
		return res, err2
	}
	kuaishou, err3 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 4)
	if err3 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err3)
		return res, err3
	}
	weibo, err4 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 3)
	if err4 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err4)
		return res, err4
	}
	bilibili, err5 := dao.ProjectDAO{}.GetLogisticsToDo(enterpriseId, subAccountId, 5)
	if err5 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err5)
		return res, err5
	}
	all := make(map[string]int64)
	all["needDelivery"] = redbook["needDelivery"] + douyin["needDelivery"] + kuaishou["needDelivery"] + weibo["needDelivery"] + bilibili["needDelivery"]
	all["needReceive"] = redbook["needReceive"] + douyin["needReceive"] + kuaishou["needReceive"] + weibo["needReceive"] + bilibili["needReceive"]
	res["redbook"] = redbook
	res["douyin"] = douyin
	res["kuaishou"] = kuaishou
	res["weibo"] = weibo
	res["bilibili"] = bilibili
	res["all"] = all

	return res, nil
}

// 违约管理任务待办
func (p ProjectService) GetDefaultToDo(enterpriseId string, subAccountId int64, taskType int64) (map[string]map[string]int64, error) {
	res := make(map[string]map[string]int64)
	redbook, err1 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 1, taskType)
	if err1 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err1)
		return res, err1
	}
	douyin, err2 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 2, taskType)
	if err2 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err2)
		return res, err2
	}
	kuaishou, err3 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 4, taskType)
	if err3 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err3)
		return res, err3
	}
	weibo, err4 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 3, taskType)
	if err4 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err4)
		return res, err4
	}
	bilibili, err5 := dao.ProjectDAO{}.GetDefaultToDo(enterpriseId, subAccountId, 5, taskType)
	if err5 != nil {
		logrus.Errorf("[GetProjectToDo service] call GetProjectToDo error,err:%+v", err5)
		return res, err5
	}
	all := make(map[string]int64)
	all["noSketch"] = redbook["noSketch"] + douyin["noSketch"] + kuaishou["noSketch"] + weibo["noSketch"] + bilibili["noSketch"]
	all["noWork"] = redbook["noWork"] + douyin["noWork"] + kuaishou["noWork"] + weibo["noWork"] + bilibili["noWork"]
	all["noData"] = redbook["noData"] + douyin["noData"] + kuaishou["noData"] + weibo["noData"] + bilibili["noData"]
	all["cooperateOver"] = redbook["cooperateOver"] + douyin["cooperateOver"] + kuaishou["cooperateOver"] + weibo["cooperateOver"] + bilibili["cooperateOver"]
	res["redbook"] = redbook
	res["douyin"] = douyin
	res["kuaishou"] = kuaishou
	res["weibo"] = weibo
	res["bilibili"] = bilibili
	res["all"] = all

	return res, nil
}

// 合作待办-任务邀约
func (p ProjectService) GetTaskInviteToDo(enterpriseId string, subAccountId int64) (map[string]map[string]int64, error) {
	res := make(map[string]map[string]int64)
	redbook, err1 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 1)
	if err1 != nil {
		logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err1)
		return res, err1
	}
	douyin, err2 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 2)
	if err2 != nil {
		logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err2)
		return res, err2
	}
	kuaishou, err3 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 4)
	if err3 != nil {
		logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err3)
		return res, err3
	}
	weibo, err4 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 3)
	if err4 != nil {
		logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err4)
		return res, err4
	}
	bilibili, err5 := dao.ProjectDAO{}.GetTaskInviteToDo(enterpriseId, subAccountId, 5)
	if err5 != nil {
		logrus.Errorf("[GetTaskInviteToDo service] call GetTaskInviteToDo error,err:%+v", err5)
		return res, err5
	}
	all := make(map[string]int64)
	all["availInvitationNum"] = redbook["availInvitationNum"] + douyin["availInvitationNum"] + kuaishou["availInvitationNum"] + weibo["availInvitationNum"] + bilibili["availInvitationNum"]
	all["invitingNum"] = redbook["invitingNum"] + douyin["invitingNum"] + kuaishou["invitingNum"] + weibo["invitingNum"] + bilibili["invitingNum"]
	all["cooperatingNum"] = redbook["cooperatingNum"] + douyin["cooperatingNum"] + kuaishou["cooperatingNum"] + weibo["cooperatingNum"] + bilibili["cooperatingNum"]
	res["redbook"] = redbook
	res["douyin"] = douyin
	res["kuaishou"] = kuaishou
	res["weibo"] = weibo
	res["bilibili"] = bilibili
	res["all"] = all

	return res, nil
}
