package db

import (
	"context"
	"errors"
	"fmt"
	"github.com/issue9/conv"
	"github.com/sirupsen/logrus"
	"gorm.io/gorm"
	"strconv"
	"strings"
	"time"
	"youngee_b_api/model/gorm_model"
	"youngee_b_api/model/http_model"
)

func GetLocalRecruittime(ctx context.Context, request http_model.GetLocalRecruitTimeRequest) (*http_model.GetLocalRecruitTimeResponse, error) {
	db := GetReadDB(ctx)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).Find(&localinfo).Error
	var result http_model.GetLocalRecruitTimeResponse
	if err != nil {
		return &result, err
	}
	result.RecruitTime = localinfo.RecruitDdl.Format("2006-01-02 15:04:05")
	return &result, nil
}

func GetLocalTalentstatusCount(db *gorm.DB, request http_model.GetLocalTalentstatusNumRequest, status int) (int64, error) {
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_status = ?", request.ProjectId, status)

	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return 0, err
	}
	return total, nil
}

func GetLocalTalentstatusNumCount(ctx context.Context, request http_model.GetLocalTalentstatusNumRequest) (*http_model.GetLocalTalentstatusNumResponse, error) {
	db := GetReadDB(ctx)
	var unoperatenum, agreetalentnum, refusetalentnum int64
	unoperatenum, _ = GetLocalTalentstatusCount(db, request, 1)
	agreetalentnum, _ = GetLocalTalentstatusCount(db, request, 2)
	refusetalentnum, _ = GetLocalTalentstatusCount(db, request, 3)
	count := &http_model.GetLocalTalentstatusNumResponse{
		UnoperateTalentnum: unoperatenum,
		AgreeTalentnum:     agreetalentnum,
		RefuseTalentnum:    refusetalentnum,
	}
	return count, nil
}

func GetLocalTalentstatusNum(db *gorm.DB, request http_model.GetLocalTalentstatusCountRequest, status int) (int64, error) {
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_stage = ?", request.ProjectId, status)
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return 0, err
	}
	return total, nil
}

func GetLocalTalentstatusCountNum(ctx context.Context, request http_model.GetLocalTalentstatusCountRequest) (*http_model.GetLocalTalentstatusCountResponse, error) {
	db := GetReadDB(ctx)
	var unoperatenum, agreetalentnum, refusetalentnum int64
	unoperatenum, _ = GetLocalTalentstatusNum(db, request, request.TaskStage)
	agreetalentnum, _ = GetLocalTalentstatusNum(db, request, request.TaskStage+1)
	refusetalentnum, _ = GetLocalTalentstatusNum(db, request, request.TaskStage+2)
	count := &http_model.GetLocalTalentstatusCountResponse{
		UnoperateTalentnum: unoperatenum,
		AgreeTalentnum:     agreetalentnum,
		RefuseTalentnum:    refusetalentnum,
	}
	return count, nil
}

func GetLocallifetaskList(ctx context.Context, request http_model.GetLocalTaskListRequest) (*http_model.GetLocalTaskListData, error) {
	db := GetReadDB(ctx)
	var projecrtaskinfo []gorm_model.YoungeeLocalTaskInfo
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_status = ?", request.ProjectId, request.CoopType)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).First(&localinfo).Error
	if err != nil {
		return &http_model.GetLocalTaskListData{}, err
	}
	// 构建查询条件
	if request.FeeFrom != nil {
		query = query.Where("fee_form = ?", request.FeeFrom)
	}
	if request.Type != nil {
		switch *request.Type {
		case 1:
			query = query.Where("supplier_id = 0 AND supplier_status = 0")
		case 2:
			query = query.Where("supplier_id !=0 AND supplier_status = 2")
		}
	}
	if request.Others != "" {
		query = query.Where("talent_name LIKE ? OR s_operate_name LIKE ?", "%"+request.Others+"%", "%"+request.Others+"%")
	}
	if request.TalentFromList != "" {
		provinceList := strings.Split(request.TalentFromList, ",")                // 解析传入的省份列表
		query = query.Where("SUBSTRING_INDEX(city, ' ', 1) IN (?)", provinceList) // 提取城市字段中的省份并进行匹配
	}
	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return nil, err
	}

	// 添加分页逻辑
	pageSize := request.PageSize
	if pageSize == 0 {
		pageSize = 10
	}
	pageNum := request.PageNum
	if pageNum == 0 {
		pageNum = 1
	}
	offset := (pageNum - 1) * pageSize
	// 处理多字段排序逻辑
	if len(request.SortField) > 0 && len(request.SortOrder) > 0 && len(request.SortField) == len(request.SortOrder) {
		for i := 0; i < len(request.SortField); i++ {
			field := request.SortField[i]
			order := request.SortOrder[i]
			switch field {
			case "fansnum":
				if order == "asc" {
					query = query.Order("fans_num asc")
				} else {
					query = query.Order("fans_num desc")
				}
			case "voteavg":
				if order == "asc" {
					query = query.Order("vote_avg asc")
				} else {
					query = query.Order("vote_avg desc")
				}
			case "commentavg":
				if order == "asc" {
					query = query.Order("commit_avg asc")
				} else {
					query = query.Order("commit_avg desc")
				}
			case "collectnum":
				if order == "asc" {
					query = query.Order("collect_num asc")
				} else {
					query = query.Order("collect_num desc")
				}
			}
		}
	} else {
		// Default sorting if no valid sort parameters
		query = query.Order("task_status asc").Order("task_stage asc")
	}
	// 执行分页查询
	if err := query.Offset(offset).Limit(pageSize).Find(&projecrtaskinfo).Error; err != nil {
		return nil, err
	}
	taskInfoPointers := make([]*http_model.LocaLTaskInfo, 0, len(projecrtaskinfo))
	for _, task := range projecrtaskinfo {
		var Time time.Time
		switch request.CoopType {
		case 1:
			Time = task.CreateDate
		case 2:
			Time = task.SelectDate //2 signedtime
		case 3:
			Time = task.CompleteDate
		}
		var listtime, stageintro string
		switch task.TaskStage {
		case 4:
			{
				listtime = task.SelectDate.Format("2006-01-02 15:04:05")
				stageintro = "执行开始时间"
			}
		case 5:
			{
				listtime = task.ReserveTime.Format("2006-01-02 15:04:05")
				stageintro = "达人探店时间预约申请时间"
			}
		case 6:
			{
				listtime = task.ExploreTime.Format("2006-01-02 15:04:05")
				stageintro = "达人探店时间预约申请时间"
			}
		case 9:
			{
				listtime = task.CurBreakAt.Format("2006-01-02 15:04:05")
				stageintro = "初稿上传截止时间"
			}
		case 10:
			{
				var sketchinfo gorm_model.YounggeeSketchInfo
				err := db.Model(&gorm_model.YounggeeSketchInfo{}).Where("task_id = ? and is_review = 0", task.TaskId).First(&sketchinfo).Error
				if err != nil {
					return nil, err
				}
				listtime = sketchinfo.SubmitAt.Format("2006-01-02 15:04:05")
				stageintro = "达人上传初稿时间" //
			}
		case 11:
			{
				listtime = task.CurBreakAt.Format("2006-01-02 15:04:05")
				stageintro = " 链接上传截止时间"
			}
		case 12:
			{
				var linkinfo gorm_model.YounggeeLinkInfo
				err := db.Model(&gorm_model.YounggeeLinkInfo{}).Where("task_id = ? and is_review = 0", task.TaskId).First(&linkinfo).Error
				if err != nil {
					return nil, err
				}
				listtime = linkinfo.SubmitAt.Format("2006-01-02 15:04:05")
				stageintro = "达人上传链接时间"
			}
		case 13:
			{
				listtime = task.CurBreakAt.Format("2006-01-02 15:04:05")
				stageintro = "数据待传截止时间"
			}
		case 14:
			{
				var datainfo gorm_model.YounggeeDataInfo
				err := db.Model(&gorm_model.YounggeeDataInfo{}).Where("task_id = ? and is_review = 0", task.TaskId).First(&datainfo).Error
				if err != nil {
					return nil, err
				}
				listtime = datainfo.SubmitAt.Format("2006-01-02 15:04:05")
				stageintro = "品牌最晚结算时间"
			}
		case 15:
			{
				listtime = task.CompleteDate.Format("2006-01-02 15:04:05")
				stageintro = "品牌结算时间"
			}
		case 16:
			{
				listtime = task.CancelTime.Format("2006-01-02 15:04:05")
				stageintro = "解约时间"
			}
		}
		boperator := getBOperator(db, task.BOperator, task.BOperatorType)
		nickname, headurl, gender, fans, voteavg := getTalentinfo(db, task.TalentId)
		Iscoop := getIscoop(db, task.TalentId, request.EnterPriseId)
		s_type, s_name := stype(db, task.SupplierId, task.SupplierStatus, localinfo.LocalType)
		response := &http_model.LocaLTaskInfo{
			TaskId:             task.TaskId,
			ProjectId:          task.LocalId,
			TalentId:           task.TalentId,
			FansNum:            fans,
			DraftFee:           task.DraftFee,
			Voteavg:            voteavg,
			FeeFrom:            task.FeeForm,
			TaskStage:          task.TaskStage,
			Commentavg:         0,
			CollectNum:         0,
			CurrentDefaultType: task.CurDefaultType,
			From:               determineFrom(task.SupplierId, task.SupplierStatus),
			SType:              s_type,
			SName:              s_name,
			Boperator:          boperator,
			CreateAt:           Time.Format("2006-01-02 15:04:05"),
			NickName:           nickname,
			HeadUrl:            headurl,
			ISCoop:             Iscoop,
			Gender:             gender,
			Sprojectid:         task.SLocalLifeId,
			City:               task.City,
			StageIntro:         stageintro,
			ListTime:           listtime,
		}
		taskInfoPointers = append(taskInfoPointers, response)
	}

	return &http_model.GetLocalTaskListData{
		TaskList: taskInfoPointers,
		Total:    conv.MustString(total, ""),
	}, nil
}

func PassLocalTaskCoop(ctx context.Context, req http_model.PasslocalTaskCoopRequest) (bool, error) {
	db := GetReadDB(ctx)
	var count int64

	err := db.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id IN ? AND task_stage = 1", req.TaskIds).Count(&count).Error

	if err != nil {
		return false, err
	}
	if int64(len(req.TaskIds)) == 0 || count != int64(len(req.TaskIds)) {
		return false, errors.New("任务id有误")
	}

	// 2. 查询任务对应达人id（用于生成达人消息）
	var talentIds []string
	err = db.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id IN ?", req.TaskIds).Select("talent_id").Find(&talentIds).Error
	if err != nil {
		return false, err
	}

	// 3. 查询任务对应project名称（用于生成达人消息）
	var project gorm_model.YounggeeLocalLifeInfo
	err = db.Model(gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", req.ProjectId).Find(&project).Error
	if err != nil {
		return false, err
	}

	var taskstages int
	if project.TaskForm == 1 {
		taskstages = 4
	} else {
		taskstages = 9
	}

	nextstage := [6]int{0, 0, 0, 0, 0, 0} // 数组长度为6，表示6种工具 4,9,11,13
	if req.IsSpecial == 1 {
		toolList := strings.Split(project.Tools, ",")
		for _, tool := range toolList {
			// 将 tool 转换为整数
			if t, err := strconv.Atoi(tool); err == nil && t >= 0 && t <= len(nextstage) {
				nextstage[t-1] = 1
			}
		}
		fmt.Println(nextstage)
		for i := 1; i < len(nextstage); i++ { // 从位置1开始
			if nextstage[i] == 1 {
				switch i {
				case 1:
					taskstages = 4
				case 2:
					taskstages = 9
				case 3:
					taskstages = 11
				case 4:
					taskstages = 13
				case 5:
					taskstages = 15
				}
				break
			}
		}
	}

	var opid string
	var optype int
	switch req.OperateType {
	case 3:
		{
			opid = req.EnterpriseId
			optype = 1
		}
	case 4:
		{
			opid = req.OperatorId
			optype = 2
		}
	}
	//4.根据达人来源改变状态、阶段、数目
	var tasks []gorm_model.YoungeeLocalTaskInfo
	err = db.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id IN ? AND task_stage = 1", req.TaskIds).Find(&tasks).Error
	if err != nil {
		return false, err
	}
	err = db.Transaction(func(tx *gorm.DB) error {
		// 2. 修改任务状态和任务阶段
		for _, taskInfo := range tasks {
			if taskInfo.SupplierId != 0 && taskInfo.SupplierStatus == 2 { //服务商招募数量+1
				updateData := gorm_model.YoungeeLocalTaskInfo{
					TaskStage:     taskstages,
					TaskStatus:    2,
					UpdateAt:      time.Now(),
					BOperator:     opid,
					BOperatorType: optype,
					SelectDate:    time.Now(),
				}
				err = tx.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id = ? AND task_stage = 1", taskInfo.TaskId).Updates(updateData).Error
				if err != nil {
					return err
				}

				//project招募数+1,预估成本+服务商价格
				var projectinfo gorm_model.YounggeeLocalLifeInfo
				err = db.Model(gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", req.ProjectId).Find(&projectinfo).Error
				if err != nil {
					return err
				}
				projectinfo.RecruitNum += 1
				projectinfo.NeedPay += taskInfo.SupportFee
				err = tx.Model(gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ? ", req.ProjectId).Updates(projectinfo).Error
				if err != nil {
					return err
				}
				//服务商s_project已招募人数+1改成s_locallife
				var sprojectinfo gorm_model.YounggeeSProjectInfo
				err = db.Model(gorm_model.YounggeeSProjectInfo{}).Where(" s_project_id =?", taskInfo.SLocalLifeId).Find(&sprojectinfo).Error
				if err != nil {
					return err
				}
				sprojectinfo.RecruitNum += 1
				fmt.Println("......", projectinfo.RecruitNum)
				err = tx.Model(gorm_model.YounggeeSProjectInfo{}).Where(" s_project_id =?", taskInfo.SLocalLifeId).Updates(sprojectinfo).Error
				if err != nil {
					return err
				} //

			}

			//if project.TaskForm != 1 { //素材分发
			//	var draft_default gorm_model.InfoAutoTask
			//	err = db.Model(gorm_model.InfoAutoTask{}).Where("auto_task_id = ?", project.AutoTaskId).Find(&draft_default).Error
			//	if err != nil {
			//		return err
			//	}
			//	duration := time.Duration(draft_default.DraftDefault) * time.Hour
			//	upbreakdate := gorm_model.YoungeeLocalTaskInfo{
			//		CurBreakAt: time.Now().Add(duration),
			//	}
			//	err = tx.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id = ? ", taskInfo.TaskId).Updates(upbreakdate).Error
			//	if err != nil {
			//		return err
			//	}
			//}

			if taskInfo.SupplierId == 0 && taskInfo.SupplierStatus == 0 { //来源于公海
				updateData := gorm_model.YoungeeLocalTaskInfo{
					TaskStage:     taskstages,
					TaskStatus:    2,
					UpdateAt:      time.Now(),
					BOperator:     opid,
					BOperatorType: optype,
					SelectDate:    time.Now(),
				}
				err = tx.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id = ? AND task_stage = 1", taskInfo.TaskId).Updates(updateData).Error
				if err != nil {
					return err
				}

				//project招募数+1
				var projectinfo gorm_model.YounggeeLocalLifeInfo
				err = db.Model(gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", req.ProjectId).Find(&projectinfo).Error
				if err != nil {
					return err
				}
				projectinfo.RecruitNum += 1
				projectinfo.NeedPay += taskInfo.SupportFee
				err = tx.Model(gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ? ", req.ProjectId).Updates(projectinfo).Error
				if err != nil {
					return err
				}
			}

		}
		// 4. 生成达人消息
		for _, talendId := range talentIds {
			err = CreateMessage(ctx, 1, 1, talendId, project.LocalName)
			if err != nil {
				return err
			}
		}
		// 返回 nil 提交事务
		return nil
	})
	if err != nil {
		return false, err
	}
	return true, nil
}

func RefuseLocalTaskCoop(ctx context.Context, req http_model.RefuselocalTaskCoopRequest) (bool, error) {
	db := GetWriteDB(ctx)
	// 1. 校验
	var count int64
	err := db.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id IN ? AND task_stage = 1", req.TaskIds).Count(&count).Error
	if err != nil {
		return false, err
	}
	if count != int64(len(req.TaskIds)) {
		return false, errors.New("任务id有误")
	}

	var opid string
	var optype int
	switch req.OperateType {
	case 3:
		{
			opid = req.EnterpriseId
			optype = 1
		}
	case 4:
		{
			opid = req.OperatorId
			optype = 2
		}
	}

	// 2. 查询任务对应达人id（用于生成达人消息）
	var talentIds []string
	err = db.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id IN ?", req.TaskIds).Select("talent_id").Find(&talentIds).Error
	if err != nil {
		return false, err
	}

	var tasks []gorm_model.YoungeeLocalTaskInfo
	err = db.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id IN ? AND task_stage = 1", req.TaskIds).Find(&tasks).Error

	err = db.Transaction(func(tx *gorm.DB) error {
		// 2. 修改任务状态和任务阶段
		for _, taskInfo := range tasks {
			updateData := gorm_model.YoungeeLocalTaskInfo{
				TaskStage:     3,
				TaskStatus:    3,
				UpdateAt:      time.Now(),
				BOperator:     opid,
				BOperatorType: optype,
				CompleteDate:  time.Now(),
			}
			err = tx.Model(gorm_model.YoungeeLocalTaskInfo{}).Where("task_id = ? AND task_stage = 1", taskInfo.TaskId).Updates(updateData).Error
		}
		if err != nil {
			return err
		}

		// 返回 nil 提交事务
		return nil
	})
	if err != nil {
		return false, err
	}
	return true, nil
}

func GetLocallifeData(ctx context.Context, req http_model.LocallifeDataRequest) (http_model.LocallifeDataResponse, error) {
	db := GetReadDB(ctx)
	var projectInfo gorm_model.YounggeeLocalLifeInfo
	// 查询项目基本信息
	if err := db.Where("local_id = ?", req.LocallifeId).First(&projectInfo).Error; err != nil {
		logrus.WithContext(ctx).Errorf("[Locallife db] GetLocallifeData error, err: %+v", err)
		return http_model.LocallifeDataResponse{}, err
	}
	fmt.Println("projectInfo---", projectInfo.LocalId)
	var projectTasks []gorm_model.YoungeeLocalTaskInfo
	if err := db.Where("local_id = ? AND task_status = ?", req.LocallifeId, 2).Find(&projectTasks).Error; err != nil {
		return http_model.LocallifeDataResponse{}, err
	}

	var totalTasks int64
	if err := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_status = ?", req.LocallifeId, 2).Count(&totalTasks).Error; err != nil {
		return http_model.LocallifeDataResponse{}, err
	}

	// 初始化统计数据
	dateStats := make(map[string]int)
	fansCounts := map[int64]int{0: 0, 1: 0, 2: 0, 3: 0}
	feeCounts := map[int]int{1: 0, 2: 0, 3: 0}
	startDate := *projectInfo.CreatedAt
	endDate := time.Now()

	// 填充日期统计
	for d := startDate; d.Before(endDate) || d.Equal(endDate); d = d.Add(24 * time.Hour) {
		dateStats[d.Format("2006-01-02")] = 0
	}

	var totalCost float64
	var totalFans int
	var serverTaskCount float64
	var maleCount int64

	// 处理每个任务
	for _, task := range projectTasks {
		totalCost += task.DraftFee
		var talentInfo gorm_model.YoungeeTalentInfo

		// 查询达人信息
		if err := db.Where("id = ?", task.TalentId).First(&talentInfo).Error; err != nil {
			logrus.WithContext(ctx).Errorf("[Locallife db] GetLocallifeData error, err: %+v", err)
			return http_model.LocallifeDataResponse{}, err
		}

		// 统计性别
		if talentInfo.Sex == 1 {
			maleCount++
		}
		totalFans += task.FansNum

		// 统计来自服务商的任务
		if task.SupplierId != 0 && task.SupplierStatus == 2 {
			serverTaskCount++
		}

		// 稿费形式统计
		feeCounts[task.FeeForm]++

		// 统计粉丝数
		switch {
		case task.FansNum < 10000:
			fansCounts[0]++
		case task.FansNum < 100000:
			fansCounts[1]++
		case task.FansNum < 1000000:
			fansCounts[2]++
		default:
			fansCounts[3]++
		}

		SelectDate := task.SelectDate.Format("2006-01-02")
		if _, exists := dateStats[SelectDate]; exists {
			dateStats[SelectDate]++
		}
	}

	// 计算平均值
	var avgFansNum int
	if totalTasks > 0 {
		avgFansNum = totalFans / int(totalTasks)
	} else {
		avgFansNum = 0
	}

	var fromType float64
	if totalTasks > 0 {
		fromType = serverTaskCount / float64(totalTasks)
	} else {
		fromType = 0
	}

	var manRatio float64
	if totalTasks > 0 {
		manRatio = float64(maleCount) / float64(totalTasks)
	} else {
		manRatio = 0
	}
	// 构建响应
	res := http_model.LocallifeDataResponse{
		Recruittime: *projectInfo.PassAt,
		RecruitDDl:  *projectInfo.RecruitDdl,
		AgreeNum:    projectInfo.RecruitNum,
		ApplyNum:    projectInfo.ApplyNum,
		DraftFee:    totalCost,
		AvgFansNum:  avgFansNum,
		FromType:    fromType,
		ManRatio:    manRatio,
		DateStats:   dateStats,
		FeeMap:      feeCounts,
		FansMap:     fansCounts,
	}
	return res, nil
}

func GetLocalPreSketchList(ctx context.Context, request http_model.LocalPreSketchListRequest) (*http_model.GetLocalSketchTaskListData, error) {
	db := GetReadDB(ctx)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).First(&localinfo).Error
	if err != nil {
		return &http_model.GetLocalSketchTaskListData{}, err
	}
	var projecrtaskinfo []gorm_model.YoungeeLocalTaskInfo
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_stage = ?", request.ProjectId, request.ScriptStatus)
	if request.Others != "" {
		query = query.Where("talent_name LIKE ? OR s_operate_name LIKE ?", "%"+request.Others+"%", "%"+request.Others+"%")
	}
	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return nil, err
	}

	// 添加分页逻辑
	pageSize := request.PageSize
	if pageSize == 0 {
		pageSize = 10
	}
	pageNum := request.PageNum
	if pageNum == 0 {
		pageNum = 1
	}
	offset := (pageNum - 1) * pageSize
	// 执行分页查询

	// 处理多字段排序逻辑
	if len(request.SortField) > 0 && len(request.SortOrder) > 0 && len(request.SortField) == len(request.SortOrder) {
		for i := 0; i < len(request.SortField); i++ {
			field := request.SortField[i]
			order := request.SortOrder[i]
			switch field {
			case "fansnum":
				if order == "asc" {
					query = query.Order("fans_num asc")
				} else {
					query = query.Order("fans_num desc")
				}
			case "voteavg":
				if order == "asc" {
					query = query.Order("vote_avg asc")
				} else {
					query = query.Order("vote_avg desc")
				}
			case "commentavg":
				if order == "asc" {
					query = query.Order("commit_avg asc")
				} else {
					query = query.Order("commit_avg desc")
				}
			case "collectnum":
				if order == "asc" {
					query = query.Order("view_num asc")
				} else {
					query = query.Order("view_num desc")
				}
			}
		}
	} else {
		// Default sorting if no valid sort parameters
		query = query.Order("task_status asc").Order("task_stage asc")
	}

	if err := query.Offset(offset).Limit(pageSize).Find(&projecrtaskinfo).Error; err != nil {
		return nil, err
	}
	taskInfoPointers := make([]*http_model.LocalTasksketchInfo, 0, len(projecrtaskinfo))

	for _, task := range projecrtaskinfo {
		nickname, headurl, gender, fans, voteavg := getTalentinfo(db, task.TalentId)
		Iscoop := getIscoop(db, task.TalentId, request.EnterpriseId)
		s_type, s_name := stype(db, task.SupplierId, task.SupplierStatus, localinfo.LocalType)
		taskinfo := &http_model.LocaLTaskInfo{
			TaskId:             task.TaskId,
			ProjectId:          task.LocalId,
			TalentId:           task.TalentId,
			FansNum:            fans,
			DraftFee:           task.DraftFee,
			Voteavg:            voteavg,
			FeeFrom:            task.FeeForm,
			TaskStage:          task.TaskStage,
			Commentavg:         0,
			CurrentDefaultType: task.CurDefaultType,
			From:               determineFrom(task.SupplierId, task.SupplierStatus),
			SType:              s_type,
			SName:              s_name,
			NickName:           nickname,
			HeadUrl:            headurl,
			Gender:             gender,
			CollectNum:         0,
			ISCoop:             Iscoop,
			City:               task.City,
		}
		response := &http_model.LocalTasksketchInfo{
			Task: taskinfo,
			DDl:  task.CurBreakAt.Format("2006-01-02 15:04:05"),
		}
		taskInfoPointers = append(taskInfoPointers, response)

	}
	return &http_model.GetLocalSketchTaskListData{
		TasksketchList: taskInfoPointers,
		Total:          conv.MustString(total, ""),
	}, nil
}

func GetLocalSketchList(ctx context.Context, request http_model.LocalTasksketchlistRequest) (*http_model.GetsketchlocaltaskListData, error) {
	db := GetReadDB(ctx)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).First(&localinfo).Error
	if err != nil {
		return &http_model.GetsketchlocaltaskListData{}, err
	}
	var projecrtaskinfo []gorm_model.YoungeeLocalTaskInfo
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_stage = ?", request.ProjectId, request.ScriptStatus)

	if request.Others != "" {
		query = query.Where("talent_name LIKE ? OR s_operate_name LIKE ?", "%"+request.Others+"%", "%"+request.Others+"%")
	}

	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return nil, err
	}

	// 添加分页逻辑
	pageSize := request.PageSize
	if pageSize == 0 {
		pageSize = 10
	}
	pageNum := request.PageNum
	if pageNum == 0 {
		pageNum = 1
	}
	offset := (pageNum - 1) * pageSize
	// 执行分页查询
	// 处理多字段排序逻辑
	if len(request.SortField) > 0 && len(request.SortOrder) > 0 && len(request.SortField) == len(request.SortOrder) {
		for i := 0; i < len(request.SortField); i++ {
			field := request.SortField[i]
			order := request.SortOrder[i]
			switch field {
			case "fansnum":
				if order == "asc" {
					query = query.Order("fans_num asc")
				} else {
					query = query.Order("fans_num desc")
				}
			case "voteavg":
				if order == "asc" {
					query = query.Order("vote_avg asc")
				} else {
					query = query.Order("vote_avg desc")
				}
			case "commentavg":
				if order == "asc" {
					query = query.Order("commit_avg asc")
				} else {
					query = query.Order("commit_avg desc")
				}
			case "collectnum":
				if order == "asc" {
					query = query.Order("view_num asc")
				} else {
					query = query.Order("view_num desc")
				}
			}
		}
	} else {
		// Default sorting if no valid sort parameters
		query = query.Order("task_status asc").Order("task_stage asc")
	}
	if err := query.Offset(offset).Limit(pageSize).Find(&projecrtaskinfo).Error; err != nil {
		return nil, err
	}
	taskInfoPointers := make([]*http_model.LocalTasksketchinfo, 0, len(projecrtaskinfo))
	for _, task := range projecrtaskinfo {
		nickname, headurl, gender, fans, voteavg := getTalentinfo(db, task.TalentId)
		s_type, s_name := stype(db, task.SupplierId, task.SupplierStatus, localinfo.LocalType)
		taskinfo := &http_model.LocaLTaskInfo{
			TaskId:             task.TaskId,
			ProjectId:          task.LocalId,
			TalentId:           task.TalentId,
			FansNum:            fans,
			DraftFee:           task.DraftFee,
			Voteavg:            voteavg,
			FeeFrom:            task.FeeForm,
			TaskStage:          task.TaskStage,
			Commentavg:         0,
			CollectNum:         0,
			CurrentDefaultType: task.CurDefaultType,
			SType:              s_type,
			SName:              s_name,
			From:               determineFrom(task.SupplierId, task.SupplierStatus),
			NickName:           nickname,
			Gender:             gender,
			HeadUrl:            headurl,
			City:               task.City,
		}
		var sketchinfo gorm_model.YounggeeSketchInfo
		switch request.ScriptStatus {
		case 10:
			err := db.Model(&gorm_model.YounggeeSketchInfo{}).Where("task_id = ? and is_review = 0 ", task.TaskId).First(&sketchinfo).Error
			if err != nil {
				return nil, err
			}
		case 11:
			err := db.Model(&gorm_model.YounggeeSketchInfo{}).Where("task_id = ? and is_ok = 1", task.TaskId).First(&sketchinfo).Error
			if err != nil {
				return nil, err
			}
		}
		boperator := getBOperator(db, task.BOperator, task.BOperatorType)
		response := &http_model.LocalTasksketchinfo{
			Task:       taskinfo,
			SketchId:   sketchinfo.SketchID,
			SubmitAt:   sketchinfo.SubmitAt.Format("2006-01-02 15:04:05"),
			AgreeAt:    sketchinfo.AgreeAt.Format("2006-01-02 15:04:05"),
			SketchType: sketchinfo.Type,
			Operator:   boperator,
		}
		taskInfoPointers = append(taskInfoPointers, response)

	}
	return &http_model.GetsketchlocaltaskListData{
		LocalTasksketchList: taskInfoPointers,
		Total:               conv.MustString(total, ""),
	}, nil
}

func GetLocalPreLinkList(ctx context.Context, request http_model.LocalPreLinkListRequest) (*http_model.GetLocalPreLinkListData, error) {
	db := GetReadDB(ctx)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).First(&localinfo).Error
	if err != nil {
		return &http_model.GetLocalPreLinkListData{}, err
	}
	var projecrtaskinfo []gorm_model.YoungeeLocalTaskInfo
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_stage = ?", request.ProjectId, request.LinkStatus)

	if request.Others != "" {
		query = query.Where("talent_name LIKE ? OR s_operate_name LIKE ?", "%"+request.Others+"%", "%"+request.Others+"%")
	}

	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return nil, err
	}

	// 添加分页逻辑
	pageSize := request.PageSize
	if pageSize == 0 {
		pageSize = 10
	}
	pageNum := request.PageNum
	if pageNum == 0 {
		pageNum = 1
	}
	offset := (pageNum - 1) * pageSize
	// 执行分页查询
	// 处理多字段排序逻辑
	if len(request.SortField) > 0 && len(request.SortOrder) > 0 && len(request.SortField) == len(request.SortOrder) {
		for i := 0; i < len(request.SortField); i++ {
			field := request.SortField[i]
			order := request.SortOrder[i]
			switch field {
			case "fansnum":
				if order == "asc" {
					query = query.Order("fans_num asc")
				} else {
					query = query.Order("fans_num desc")
				}
			case "voteavg":
				if order == "asc" {
					query = query.Order("vote_avg asc")
				} else {
					query = query.Order("vote_avg desc")
				}
			case "commentavg":
				if order == "asc" {
					query = query.Order("commit_avg asc")
				} else {
					query = query.Order("commit_avg desc")
				}
			case "collectnum":
				if order == "asc" {
					query = query.Order("view_num asc")
				} else {
					query = query.Order("view_num desc")
				}
			}
		}
	} else {
		// Default sorting if no valid sort parameters
		query = query.Order("task_status asc").Order("task_stage asc")
	}
	if err := query.Offset(offset).Limit(pageSize).Find(&projecrtaskinfo).Error; err != nil {
		return nil, err
	}
	taskInfoPointers := make([]*http_model.LocalTasklinkinfo, 0, len(projecrtaskinfo))
	for _, task := range projecrtaskinfo {
		nickname, headurl, gender, fans, voteavg := getTalentinfo(db, task.TalentId)
		Iscoop := getIscoop(db, task.TalentId, request.EnterpriseId)
		s_type, s_name := stype(db, task.SupplierId, task.SupplierStatus, localinfo.LocalType)
		taskinfo := &http_model.LocaLTaskInfo{
			TaskId:             task.TaskId,
			ProjectId:          task.LocalId,
			TalentId:           task.TalentId,
			FansNum:            fans,
			DraftFee:           task.DraftFee,
			Voteavg:            voteavg,
			FeeFrom:            task.FeeForm,
			TaskStage:          task.TaskStage,
			Commentavg:         0,
			CollectNum:         0,
			CurrentDefaultType: task.CurDefaultType,
			From:               determineFrom(task.SupplierId, task.SupplierStatus),
			SType:              s_type,
			SName:              s_name,
			NickName:           nickname,
			HeadUrl:            headurl,
			Gender:             gender,
			ISCoop:             Iscoop,
			City:               task.City,
		}
		response := &http_model.LocalTasklinkinfo{
			Task: taskinfo,
			DDl:  task.CurBreakAt.Format("2006-01-02 15:04:05"),
		}
		taskInfoPointers = append(taskInfoPointers, response)

	}
	return &http_model.GetLocalPreLinkListData{
		TasklinkList: taskInfoPointers,
		Total:        conv.MustString(total, ""),
	}, nil
}

func GetLocalLinkList(ctx context.Context, request http_model.LocalTaskLinklistRequest) (*http_model.GetLocalTaskLinkListData, error) {
	db := GetReadDB(ctx)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).First(&localinfo).Error
	if err != nil {
		return &http_model.GetLocalTaskLinkListData{}, err
	}
	var projecrtaskinfo []gorm_model.YoungeeLocalTaskInfo
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_stage = ?", request.ProjectId, request.LinkStatus)

	if request.Others != "" {
		query = query.Where("talent_name LIKE ? OR s_operate_name LIKE ?", "%"+request.Others+"%", "%"+request.Others+"%")
	}

	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return nil, err
	}

	// 添加分页逻辑
	pageSize := request.PageSize
	if pageSize == 0 {
		pageSize = 10
	}
	pageNum := request.PageNum
	if pageNum == 0 {
		pageNum = 1
	}
	offset := (pageNum - 1) * pageSize
	// 执行分页查询
	// 处理多字段排序逻辑
	if len(request.SortField) > 0 && len(request.SortOrder) > 0 && len(request.SortField) == len(request.SortOrder) {
		for i := 0; i < len(request.SortField); i++ {
			field := request.SortField[i]
			order := request.SortOrder[i]
			switch field {
			case "fansnum":
				if order == "asc" {
					query = query.Order("fans_num asc")
				} else {
					query = query.Order("fans_num desc")
				}
			case "voteavg":
				if order == "asc" {
					query = query.Order("vote_avg asc")
				} else {
					query = query.Order("vote_avg desc")
				}
			case "commentavg":
				if order == "asc" {
					query = query.Order("commit_avg asc")
				} else {
					query = query.Order("commit_avg desc")
				}
			case "collectnum":
				if order == "asc" {
					query = query.Order("view_num asc")
				} else {
					query = query.Order("view_num desc")
				}
			}
		}
	} else {
		// Default sorting if no valid sort parameters
		query = query.Order("task_status asc").Order("task_stage asc")
	}
	if err := query.Offset(offset).Limit(pageSize).Find(&projecrtaskinfo).Error; err != nil {
		return nil, err
	}
	taskInfoPointers := make([]*http_model.LocalTaskLinkinfo, 0, len(projecrtaskinfo))
	for _, task := range projecrtaskinfo {
		nickname, headurl, gender, fans, voteavg := getTalentinfo(db, task.TalentId)
		Iscoop := getIscoop(db, task.TalentId, request.EnterpriseId)
		s_type, s_name := stype(db, task.SupplierId, task.SupplierStatus, localinfo.LocalType)
		taskinfo := &http_model.LocaLTaskInfo{
			TaskId:             task.TaskId,
			ProjectId:          task.LocalId,
			TalentId:           task.TalentId,
			FansNum:            fans,
			DraftFee:           task.DraftFee,
			Voteavg:            voteavg,
			FeeFrom:            task.FeeForm,
			TaskStage:          task.TaskStage,
			Commentavg:         0,
			CollectNum:         0,
			CurrentDefaultType: task.CurDefaultType,
			From:               determineFrom(task.SupplierId, task.SupplierStatus),
			SType:              s_type,
			SName:              s_name,
			NickName:           nickname,
			HeadUrl:            headurl,
			Gender:             gender,
			ISCoop:             Iscoop,
			City:               task.City,
		}
		var linkinfo gorm_model.YounggeeLinkInfo
		switch request.LinkStatus {
		case "12":
			err := db.Model(&gorm_model.YounggeeLinkInfo{}).Where("task_id = ? and is_review = 0 ", task.TaskId).First(&linkinfo).Error
			if err != nil {
				return nil, err
			}
		case "13":
			err := db.Model(&gorm_model.YounggeeLinkInfo{}).Where("task_id = ? and is_ok = 1", task.TaskId).First(&linkinfo).Error
			if err != nil {
				return nil, err
			}
		}
		boperator := getBOperator(db, task.BOperator, task.BOperatorType)
		response := &http_model.LocalTaskLinkinfo{
			Task:     taskinfo,
			LinkId:   linkinfo.LinkID,
			SubmitAt: linkinfo.SubmitAt.Format("2006-01-02 15:04:05"),
			AgreeAt:  linkinfo.AgreeAt.Format("2006-01-02 15:04:05"),
			LinkUrl:  linkinfo.LinkUrl,
			PhotoUrl: linkinfo.PhotoUrl,
			Operator: boperator,
		}
		taskInfoPointers = append(taskInfoPointers, response)

	}
	return &http_model.GetLocalTaskLinkListData{
		LocalTaskLinklist: taskInfoPointers,
		Total:             conv.MustString(total, ""),
	}, nil
}

func GetLocalPreDataList(ctx context.Context, request http_model.LocalPreDataListRequest) (*http_model.GetLocalPreDataListData, error) {
	db := GetReadDB(ctx)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).First(&localinfo).Error
	if err != nil {
		return &http_model.GetLocalPreDataListData{}, err
	}
	var projecrtaskinfo []gorm_model.YoungeeLocalTaskInfo
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_stage = ?", request.ProjectId, request.DataStatus)
	if request.Others != "" {
		query = query.Where("talent_name LIKE ? OR s_operate_name LIKE ?", "%"+request.Others+"%", "%"+request.Others+"%")
	}
	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return nil, err
	}

	// 添加分页逻辑
	pageSize := request.PageSize
	if pageSize == 0 {
		pageSize = 10
	}
	pageNum := request.PageNum
	if pageNum == 0 {
		pageNum = 1
	}
	offset := (pageNum - 1) * pageSize
	// 执行分页查询
	// 处理多字段排序逻辑
	if len(request.SortField) > 0 && len(request.SortOrder) > 0 && len(request.SortField) == len(request.SortOrder) {
		for i := 0; i < len(request.SortField); i++ {
			field := request.SortField[i]
			order := request.SortOrder[i]
			switch field {
			case "fansnum":
				if order == "asc" {
					query = query.Order("fans_num asc")
				} else {
					query = query.Order("fans_num desc")
				}
			case "voteavg":
				if order == "asc" {
					query = query.Order("vote_avg asc")
				} else {
					query = query.Order("vote_avg desc")
				}
			case "commentavg":
				if order == "asc" {
					query = query.Order("commit_avg asc")
				} else {
					query = query.Order("commit_avg desc")
				}
			case "collectnum":
				if order == "asc" {
					query = query.Order("view_num asc")
				} else {
					query = query.Order("view_num desc")
				}
			}
		}
	} else {
		// Default sorting if no valid sort parameters
		query = query.Order("task_status asc").Order("task_stage asc")
	}
	if err := query.Offset(offset).Limit(pageSize).Find(&projecrtaskinfo).Error; err != nil {
		return nil, err
	}
	taskInfoPointers := make([]*http_model.LocalTaskdatainfo, 0, len(projecrtaskinfo))
	for _, task := range projecrtaskinfo {
		nickname, headurl, gender, fans, voteavg := getTalentinfo(db, task.TalentId)
		Iscoop := getIscoop(db, task.TalentId, request.EnterpriseId)
		s_type, s_name := stype(db, task.SupplierId, task.SupplierStatus, localinfo.LocalType)
		taskinfo := &http_model.LocaLTaskInfo{
			TaskId:             task.TaskId,
			ProjectId:          task.LocalId,
			TalentId:           task.TalentId,
			FansNum:            fans,
			DraftFee:           task.DraftFee,
			Voteavg:            voteavg,
			FeeFrom:            task.FeeForm,
			TaskStage:          task.TaskStage,
			Commentavg:         0,
			CollectNum:         0,
			CurrentDefaultType: task.CurDefaultType,
			From:               determineFrom(task.SupplierId, task.SupplierStatus),
			SType:              s_type,
			SName:              s_name,
			NickName:           nickname,
			HeadUrl:            headurl,
			Gender:             gender,
			ISCoop:             Iscoop,
			City:               task.City,
		}
		response := &http_model.LocalTaskdatainfo{
			Task: taskinfo,
			DDl:  task.CurBreakAt.Format("2006-01-02 15:04:05"),
		}
		taskInfoPointers = append(taskInfoPointers, response)

	}
	return &http_model.GetLocalPreDataListData{
		TaskdataList: taskInfoPointers,
		Total:        conv.MustString(total, ""),
	}, nil
}

func GetLocalDataList(ctx context.Context, request http_model.LocalTaskDatalistRequest) (*http_model.GetLocalTaskDatalistData, error) {
	db := GetReadDB(ctx)
	var localinfo gorm_model.YounggeeLocalLifeInfo
	err := db.Model(&gorm_model.YounggeeLocalLifeInfo{}).Where("local_id = ?", request.ProjectId).First(&localinfo).Error
	if err != nil {
		return &http_model.GetLocalTaskDatalistData{}, err
	}
	var projecrtaskinfo []gorm_model.YoungeeLocalTaskInfo
	query := db.Model(&gorm_model.YoungeeLocalTaskInfo{}).Where("local_id = ? AND task_stage = ?", request.ProjectId, request.DataStatus)

	if request.Others != "" {
		query = query.Where("talent_name LIKE ? OR s_operate_name LIKE ?", "%"+request.Others+"%", "%"+request.Others+"%")
	}

	// 计算总数
	var total int64
	if err := query.Count(&total).Error; err != nil {
		return nil, err
	}

	// 添加分页逻辑
	pageSize := request.PageSize
	if pageSize == 0 {
		pageSize = 10
	}
	pageNum := request.PageNum
	if pageNum == 0 {
		pageNum = 1
	}
	offset := (pageNum - 1) * pageSize
	// 执行分页查询
	// 处理多字段排序逻辑
	if len(request.SortField) > 0 && len(request.SortOrder) > 0 && len(request.SortField) == len(request.SortOrder) {
		for i := 0; i < len(request.SortField); i++ {
			field := request.SortField[i]
			order := request.SortOrder[i]
			switch field {
			case "fansnum":
				if order == "asc" {
					query = query.Order("fans_num asc")
				} else {
					query = query.Order("fans_num desc")
				}
			case "voteavg":
				if order == "asc" {
					query = query.Order("vote_avg asc")
				} else {
					query = query.Order("vote_avg desc")
				}
			case "commentavg":
				if order == "asc" {
					query = query.Order("commit_avg asc")
				} else {
					query = query.Order("commit_avg desc")
				}
			case "collectnum":
				if order == "asc" {
					query = query.Order("view_num asc")
				} else {
					query = query.Order("view_num desc")
				}
			}
		}
	} else {
		// Default sorting if no valid sort parameters
		query = query.Order("task_status asc").Order("task_stage asc")
	}
	if err := query.Offset(offset).Limit(pageSize).Find(&projecrtaskinfo).Error; err != nil {
		return nil, err
	}
	taskInfoPointers := make([]*http_model.LocalTaskDatainfo, 0, len(projecrtaskinfo))
	for _, task := range projecrtaskinfo {
		nickname, headurl, gender, fans, voteavg := getTalentinfo(db, task.TalentId)
		Iscoop := getIscoop(db, task.TalentId, request.EnterpriseId)
		s_type, s_name := stype(db, task.SupplierId, task.SupplierStatus, localinfo.LocalType)
		taskinfo := &http_model.LocaLTaskInfo{
			TaskId:             task.TaskId,
			ProjectId:          task.LocalId,
			TalentId:           task.TalentId,
			FansNum:            fans,
			DraftFee:           task.DraftFee,
			Voteavg:            voteavg,
			FeeFrom:            task.FeeForm,
			TaskStage:          task.TaskStage,
			Commentavg:         0,
			CollectNum:         0,
			CurrentDefaultType: task.CurDefaultType,
			From:               determineFrom(task.SupplierId, task.SupplierStatus),
			SType:              s_type,
			SName:              s_name,
			NickName:           nickname,
			HeadUrl:            headurl,
			Gender:             gender,
			ISCoop:             Iscoop,
			City:               task.City,
		}
		var datainfo gorm_model.YounggeeDataInfo
		switch request.DataStatus {
		case "12":
			err := db.Model(&gorm_model.YounggeeDataInfo{}).Where("task_id = ? and is_review = 0 ", task.TaskId).First(&datainfo).Error
			if err != nil {
				return nil, err
			}
		case "13":
			err := db.Model(&gorm_model.YounggeeDataInfo{}).Where("task_id = ? and is_ok = 1", task.TaskId).First(&datainfo).Error
			if err != nil {
				return nil, err
			}
		}
		boperator := getBOperator(db, task.BOperator, task.BOperatorType)
		response := &http_model.LocalTaskDatainfo{
			Task:          taskinfo,
			DataId:        datainfo.DataID,
			SubmitAt:      datainfo.SubmitAt.Format("2006-01-02 15:04:05"),
			AgreeAt:       datainfo.AgreeAt.Format("2006-01-02 15:04:05"),
			PhotoUrl:      datainfo.PhotoUrl,
			PlayNumber:    datainfo.PlayNumber,
			LikeNumber:    datainfo.LikeNumber,
			CollectNumber: datainfo.CollectNumber,
			CommentNumber: datainfo.CommentNumber,
			SettleAmount:  task.SettleAmount,
			Breakrate:     task.SketchBreakRate + task.LinkBreakRate + task.DataBreakRate,
			Operator:      boperator,
		}
		taskInfoPointers = append(taskInfoPointers, response)

	}
	return &http_model.GetLocalTaskDatalistData{
		LocalTaskDatalist: taskInfoPointers,
		Total:             conv.MustString(total, ""),
	}, nil
}
