package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"net/http"
	"youngee_b_api/app/service"
	"youngee_b_api/app/vo"
)

type TaskController struct{}

type SelectionDetailParam struct {
	SelectionId string `json:"selection_id"`
	//EnterpriseId string `json:"enterprise_id"`
	//SubAccountId int    `json:"sub_account_id"`
}

type ProjectDetailParam struct {
	ProjectId string `json:"project_id"`
	//EnterpriseId string `json:"enterprise_id"`
	//SubAccountId int    `json:"sub_account_id"`
}

type LocalLifeDetailParam struct {
	LocalLifeId string `json:"local_id"`
	//EnterpriseId string `json:"enterprise_id"`
	//SubAccountId int    `json:"sub_account_id"`
}

// 关联商品-已有商品展示
func (t TaskController) GetAllProduct(c *gin.Context) {
	search := vo.GetAllProductParam{}
	err := c.BindJSON(&search)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	var result vo.ResultVO
	result, err = service.ProductService{}.GetTaskProductsByUserId(search)
	if err != nil {
		logrus.Errorf("[GetAllProduct] call GetAllProduct err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, result)
	return
}

// 关联商品-新建商品
func (t TaskController) CreateProduct(c *gin.Context) {
	data := &vo.ProductCreateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	productId, err := service.ProductService{}.CreateProduct(data)
	if err != nil {
		if err.Error() == "该快手商品已存在！" {
			returnError(c, 30010, err.Error())
			return
		}
		if err.Error() == "商品主图不能为空！" {
			returnError(c, 30020, err.Error())
			return
		}
		logrus.Errorf("[CreateProduct] call CreateProduct err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]int64)
	resultMap["productId"] = productId
	returnSuccess(c, 20000, resultMap)
}

// 关联商品-完成关联创建带货任务
func (t TaskController) CreateSelection(c *gin.Context) {
	data := &vo.SelectionInfoCreateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	selectionId, err := service.SelectionInfoService{}.CreateSelectionInfo(data)
	if err != nil {
		logrus.Errorf("[CreateSelection] call CreateSelection err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["selectionId"] = *selectionId
	returnSuccess(c, 20000, resultMap)
}

// 更新带货任务（样品奖励、补充信息）
func (t TaskController) UpdateSelection(c *gin.Context) {
	data := &vo.SelectionInfoUpdateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	selectionId, err := service.SelectionInfoService{}.UpdateSelectionInfo(data)
	if err != nil {
		logrus.Errorf("[UpdateSelection] call UpdateSelection err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["selectionId"] = *selectionId
	returnSuccess(c, 20000, resultMap)
}

// 电商带货任务预览
func (t TaskController) GetSelectionDetail(c *gin.Context) {
	data := &SelectionDetailParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.SelectionInfoService{}.GetSelectionDetail(data.SelectionId)
	if err != nil {
		logrus.Errorf("[GetSelectionDetail] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, res)
}

// 电商带货复制任务
func (t TaskController) CopySelection(c *gin.Context) {
	data := &vo.SelectionSearchParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.SelectionInfoService{}.CopySelection(data)
	if err != nil {
		if err.Error() == "任务不存在" {
			returnError(c, 30000, err.Error())
			return
		}
		logrus.Errorf("[CopySelection] call CopySelection err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["selectionId"] = *res
	returnSuccess(c, 20000, res)
}

// 电商带货提交审核
func (t TaskController) SelectionToReview(c *gin.Context) {
	data := &vo.SelectionInfoUpdateParam{}
	err := c.BindJSON(data)
	if err != nil || data.SelectionID == "" {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	selectionId, err := service.SelectionInfoService{}.SelectionToReview(data)
	if err != nil {
		logrus.Errorf("[SelectionToReview] call SelectionToReview err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["selectionId"] = *selectionId
	returnSuccess(c, 20000, resultMap)
}

// 电商带货任务列表
func (t TaskController) SelectionTaskList(c *gin.Context) {
	param := &vo.SelectionSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.SelectionInfoService{}.GetSelectionTaskList(param)
	if err != nil {
		logrus.Errorf("[SelectionTaskList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, res)
}

// 删除带货任务
func (t TaskController) SelectionDel(c *gin.Context) {
	param := &vo.SelectionSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	selectionId, err := service.SelectionInfoService{}.DeleteSelection(param.SelectionId)
	if err != nil {
		logrus.Errorf("[SelectionDel] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["selectionId"] = *selectionId
	returnSuccess(c, 20000, resultMap)
}

// 结束带货任务
func (t TaskController) SelectionClose(c *gin.Context) {
	param := &vo.SelectionSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	todo, err1 := service.SelectionInfoService{}.CloseSelection(param.SelectionId)
	if err1 != nil {
		logrus.Errorf("[CloseSelection] call CloseSelection err:%+v\n", err1)
		returnError(c, 40000, err1.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["selectionId"] = param.SelectionId
	resultMap["todo"] = todo
	returnSuccess(c, 20000, resultMap)
}

// 电商带货选达人角标 未处理、同意合作、拒绝合作
func (t TaskController) SelectionTalentCount(c *gin.Context) {
	param := &vo.SelectionSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res := service.SelectionInfoService{}.SelectionTalentCount(param.SelectionId)

	returnSuccess(c, 20000, res)
}

// 创建种草任务
func (t TaskController) CreateProject(c *gin.Context) {
	data := &vo.ProjectCreateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	projectId, err := service.ProjectService{}.CreateProject(data)
	if err != nil {
		logrus.Errorf("[CreateProject] call CreateProject err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["projectId"] = *projectId
	returnSuccess(c, 20000, resultMap)
}

// 更新种草任务
func (t TaskController) UpdateProject(c *gin.Context) {
	data := &vo.ProjectUpdateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	projectId, err := service.ProjectService{}.UpdateProject(data)
	if err != nil {
		logrus.Errorf("[UpdateProject] call UpdateProject err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["projectId"] = *projectId
	returnSuccess(c, 20000, resultMap)
}

// 更新定向种草任务
func (t TaskController) UpdateProjectTarget(c *gin.Context) {
	data := &vo.ProjectUpdateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	projectId, err := service.ProjectService{}.UpdateProjectTarget(data)
	if err != nil {
		logrus.Errorf("[UpdateProject] call UpdateProject err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["projectId"] = *projectId
	returnSuccess(c, 20000, resultMap)
}

// 种草任务预览
func (t TaskController) GetProjectDetail(c *gin.Context) {
	data := &ProjectDetailParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.ProjectService{}.GetProjectDetail(data.ProjectId)
	if err != nil {
		logrus.Errorf("[GetProjectDetail] call GetProjectDetail err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 种草复制任务
func (t TaskController) CopyProject(c *gin.Context) {
	data := &vo.ProjectSearchParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	projectId, err := service.ProjectService{}.CopyProject(data)
	if err != nil {
		if err.Error() == "任务不存在" {
			returnError(c, 30000, err.Error())
			return
		}
		logrus.Errorf("[CopyProject] call CopyProject err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["projectId"] = *projectId
	returnSuccess(c, 20000, resultMap)
}

// 种草提交审核
func (t TaskController) ProjectToReview(c *gin.Context) {
	data := &vo.ProjectUpdateParam{}
	err := c.BindJSON(data)
	if err != nil || data.ProjectID == "" {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	projectId, err := service.ProjectService{}.ProjectToReview(data)
	if err != nil {
		logrus.Errorf("[ProjectToReview] call ProjectToReview err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["projectId"] = *projectId
	returnSuccess(c, 20000, resultMap)
}

// 种草任务列表
func (t TaskController) ProjectTaskList(c *gin.Context) {
	param := &vo.ProjectSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.ProjectService{}.GetProjectTaskList(param)
	if err != nil {
		logrus.Errorf("[ProjectTaskList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 删除种草任务
func (t TaskController) ProjectDel(c *gin.Context) {
	param := &vo.ProjectSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	projectId, err := service.ProjectService{}.DeleteProject(param.ProjectId)
	if err != nil {
		logrus.Errorf("[ProjectDel] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["projectId"] = *projectId
	returnSuccess(c, 20000, resultMap)
}

// 结束种草任务
func (t TaskController) ProjectClose(c *gin.Context) {
	param := &vo.ProjectSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	todo, err1 := service.ProjectService{}.CloseProject(param.ProjectId)
	if err1 != nil {
		logrus.Errorf("[CloseProject] call CloseProject err:%+v\n", err1)
		returnError(c, 40000, err1.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["projectId"] = param.ProjectId
	resultMap["todo"] = todo
	returnSuccess(c, 20000, resultMap)
}

// 草稿箱——电商带货
func (t TaskController) GetSelectionDraftList(c *gin.Context) {
	param := &vo.SelectionDraftParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.SelectionInfoService{}.GetSelectionDraftList(param)
	if err != nil {
		logrus.Errorf("[SelectionTaskList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 草稿箱——品牌种草
func (t TaskController) GetProjectDraftList(c *gin.Context) {
	param := &vo.ProjectDraftParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.ProjectService{}.GetProjectDraftList(param)
	if err != nil {
		logrus.Errorf("[ProjectTaskList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 草稿箱——本地生活
func (t TaskController) GetLocalLifeDraftList(c *gin.Context) {
	param := &vo.LocalDraftParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.LocalLifeService{}.GetLocalLifeDraftList(param)
	if err != nil {
		logrus.Errorf("[LocalLifeTaskList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 违约管理——违约公开任务列表
func (t TaskController) GetPublicDefaultList(c *gin.Context) {
	param := &vo.DefaultSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.DefaultService{}.GetPublicDefaultList(param)
	if err != nil {
		logrus.Errorf("[GetPublicDefaultList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 违约管理——违约定向任务列表
func (t TaskController) GetTargetDefaultList(c *gin.Context) {
	param := &vo.DefaultSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.DefaultService{}.GetTargetDefaultList(param)
	if err != nil {
		logrus.Errorf("[GetTargetDefaultList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 违约管理——公开任务-违约达人列表
func (t TaskController) GetPublicDefaultTalentList(c *gin.Context) {
	param := &vo.DefaultSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.DefaultService{}.GetPublicDefaultTalentList(param)
	if err != nil {
		logrus.Errorf("[GetPublicDefaultTalentList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 违约管理——公开任务-违约达人列表角标
func (t TaskController) GetPublicDefaultTalentCount(c *gin.Context) {
	param := &vo.DefaultSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, _ := service.DefaultService{}.GetPublicDefaultTalentCount(param)

	returnSuccess(c, 20000, res)
}

// 违约管理——定向任务-违约达人列表
func (t TaskController) GetTargetDefaultTalentList(c *gin.Context) {
	param := &vo.DefaultSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.DefaultService{}.GetTargetDefaultTalentList(param)
	if err != nil {
		logrus.Errorf("[GetTargetDefaultTalentList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 违约管理——达人解约
func (t TaskController) CancelTalent(c *gin.Context) {
	param := &vo.TalentCancelParam{}
	err := c.BindJSON(param)
	if err != nil || param.TaskId == "" {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	err = service.DefaultService{}.CancelTalent(param)
	if err != nil {
		logrus.Errorf("[CancelTalent] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["taskId"] = param.TaskId
	returnSuccess(c, 20000, resultMap)
}

// 违约管理——达人批量解约
func (t TaskController) CancelTalentList(c *gin.Context) {
	param := &vo.TalentCancelParam{}
	err := c.BindJSON(param)
	if err != nil || param.TaskIds == nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	err = service.DefaultService{}.CancelTalentList(param)
	if err != nil {
		logrus.Errorf("[CancelTalentList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string][]string)
	resultMap["taskIds"] = param.TaskIds
	returnSuccess(c, 20000, resultMap)
}

// 服务商合作-服务商列表
func (o TaskController) GetSupplierInTargetTaskList(c *gin.Context) {
	param := &vo.SupplierSearchInTargetTaskParam{}
	err := c.BindJSON(param)
	if err != nil || "" == param.EnterpriseId {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err1 := service.CooperationService{}.GetSupplierInTargetTaskList(param)
	if err1 != nil {
		logrus.Errorf("[GetSuplierList] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, result)
}

// 服务商合作-服务商列表角标
func (t TaskController) GetSupplierInTargetCount(c *gin.Context) {
	param := &vo.SupplierSearchInTargetTaskParam{}
	err := c.BindJSON(param)
	if err != nil || "" == param.EnterpriseId {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res := service.CooperationService{}.GetSupplierInTargetCount(param)

	returnSuccess(c, 20000, res)
}

// 服务商合作-邀约合作
func (o TaskController) InviteSupplier(c *gin.Context) {
	param := &vo.SupplierInviteInTargetTaskParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	err1 := service.CooperationService{}.InviteSupplierInTargetTask(param)
	if err1 != nil {
		logrus.Errorf("[InviteSupplier] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, nil)
}

// 门店类目
func (t TaskController) GetStoreCategory(c *gin.Context) {
	res, err := service.StoreService{}.GetStoreCategory()
	if err != nil {
		logrus.Errorf("[GetStoreCategory] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, res)
}

// 达人内容类型
func (t TaskController) GetTalentCategory(c *gin.Context) {
	res, err := service.ProjectService{}.GetTalentCategory()
	if err != nil {
		logrus.Errorf("[GetTalentCategory] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, res)
}

// 关联门店-已有门店展示
func (t TaskController) GetAllStore(c *gin.Context) {
	search := vo.GetAllStoreParam{}
	err := c.BindJSON(&search)
	if err != nil || search.EnterpriseId == "" {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	var result vo.ResultVO
	result, err = service.StoreService{}.GetStoresByEnterpriseId(search)
	if err != nil {
		logrus.Errorf("[GetAllStore] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, result)
}

// 关联门店-新建门店
func (t TaskController) CreateStore(c *gin.Context) {
	param := &vo.StoreCreateParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	storeId, err := service.StoreService{}.CreateStore(param)
	if err != nil {
		logrus.Errorf("[CreateStore] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]int64)
	resultMap["storeId"] = storeId
	returnSuccess(c, 20000, resultMap)
}

// 门店团购列表
func (t TaskController) GetAllTeamBuying(c *gin.Context) {
	search := vo.GetAllTeamBuyingParam{}
	err := c.BindJSON(&search)
	if err != nil || search.StoreId == 0 {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	var result vo.ResultVO
	result, err = service.TeamBuyingService{}.GetTeamBuyingsByStoreId(search)
	if err != nil {
		logrus.Errorf("[GetAllTeamBuying] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, result)
}

// 新建团购
func (t TaskController) CreateTeamBuying(c *gin.Context) {
	param := &vo.TeamBuyingCreateParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	teamBuyingId, err := service.TeamBuyingService{}.CreateTeamBuying(param)
	if err != nil {
		logrus.Errorf("[CreateTeamBuying] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]int64)
	resultMap["teamBuyingId"] = teamBuyingId
	returnSuccess(c, 20000, resultMap)
}

// 创建本地生活任务
func (t TaskController) CreateLocalLife(c *gin.Context) {
	data := &vo.LocalCreateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	localId, err := service.LocalLifeService{}.CreateLocalLife(data)
	if err != nil {
		logrus.Errorf("[CreateLocalLife] call CreateLocalLife err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["localId"] = *localId
	returnSuccess(c, 20000, resultMap)
}

// 更新本地生活任务
func (t TaskController) UpdateLocalLife(c *gin.Context) {
	data := &vo.LocalUpdateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	localId, err := service.LocalLifeService{}.UpdateLocal(data)
	if err != nil {
		logrus.Errorf("[UpdateLocalLife] call UpdateLocalLife err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["localId"] = *localId
	returnSuccess(c, 20000, resultMap)
}

// 更新定向本地生活任务
func (t TaskController) UpdateLocalLifeTarget(c *gin.Context) {
	data := &vo.LocalUpdateParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	localId, err := service.LocalLifeService{}.UpdateLocalTarget(data)
	if err != nil {
		logrus.Errorf("[UpdateLocalLifeTarget] call UpdateLocalLifeTarget err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["localId"] = *localId
	returnSuccess(c, 20000, resultMap)
}

// 本地生活任务预览
func (t TaskController) GetLocalLifeDetail(c *gin.Context) {
	param := &LocalLifeDetailParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.LocalLifeService{}.GetLocalLifeDetail(param.LocalLifeId)
	if err != nil {
		logrus.Errorf("[GetLocalLifeDetail] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 本地生活复制任务
func (t TaskController) CopyLocalLife(c *gin.Context) {
	data := &vo.LocalSearchParam{}
	err := c.BindJSON(data)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	localId, err := service.LocalLifeService{}.CopyLocalLife(data)
	if err != nil {
		if err.Error() == "任务不存在" {
			returnError(c, 30000, err.Error())
			return
		}
		logrus.Errorf("[CreateLocalLife] call CreateLocalLife err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["localId"] = *localId
	returnSuccess(c, 20000, resultMap)
}

// 本地生活提交审核
func (t TaskController) LocalLifeToReview(c *gin.Context) {
	data := &vo.LocalUpdateParam{}
	err := c.BindJSON(data)
	if err != nil || data.LocalID == "" {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	localId, err := service.LocalLifeService{}.LocalLifeToReview(data)
	if err != nil {
		logrus.Errorf("[ProjectToReview] call ProjectToReview err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["localId"] = *localId
	returnSuccess(c, 20000, resultMap)
}

// 带货待发货、待签收、已签收统计
func (t TaskController) LogisticsSelectionTalentCount(c *gin.Context) {
	param := &vo.LogisticsSelectionTalentParam{}
	err := c.BindJSON(param)
	if err != nil || "" == param.SelectionId {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res := service.TaskInfoService{}.LogisticsSelectionTalentCount(param)

	returnSuccess(c, 20000, res)
}

// 种草达人物流列表
func (t TaskController) LogisticsTalentList(c *gin.Context) {
	param := &vo.LogisticsTalentParam{}
	err := c.BindJSON(param)
	if err != nil || "" == param.ProjectId {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.TaskInfoService{}.LogisticsTalentList(param)
	if err != nil {
		logrus.Errorf("[LogisticsTalentList] call LogisticsTalentList err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 导出种草达人物流数据
func (t TaskController) LogisticsExport(c *gin.Context) {
	param := &vo.LogisticsTalentParam{}
	err := c.BindJSON(param)
	if err != nil || "" == param.ProjectId {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	f, err := service.TaskInfoService{}.LogisticsExport(param)
	if err != nil {
		logrus.Errorf("[LogisticsExport] call LogisticsExport err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	// 设置响应头，提示浏览器下载
	c.Header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
	c.Header("Content-Disposition", "attachment; filename=export_data.xlsx")
	c.Header("File-Name", "export_data.xlsx")
	c.Header("Content-Transfer-Encoding", "binary")
	c.Header("Expires", "0")
	// 将生成的 Excel 文件写入响应体
	if err := f.Write(c.Writer); err != nil {
		c.String(http.StatusInternalServerError, "导出失败: %s", err.Error())
		returnError(c, 40000, "导出失败")
	}
	_ = f.Close()
	returnSuccess(c, 20000, nil)
}

// 种草待发货、待签收、已签收统计
func (t TaskController) LogisticsTalentCount(c *gin.Context) {
	param := &vo.LogisticsTalentParam{}
	err := c.BindJSON(param)
	if err != nil || "" == param.ProjectId {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res := service.TaskInfoService{}.LogisticsTalentCount(param)

	returnSuccess(c, 20000, res)
}

// 本地生活列表
func (t TaskController) LocalLifeTaskList(c *gin.Context) {
	param := &vo.LocalSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.LocalLifeService{}.GetLocalLifeTaskList(param)
	if err != nil {
		logrus.Errorf("[LocalLifeTaskList] call GetLocalLifeTaskList err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}

	returnSuccess(c, 20000, res)
}

// 删除本地生活任务
func (t TaskController) LocalLifeDel(c *gin.Context) {
	param := &vo.LocalSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	localId, err := service.LocalLifeService{}.DeleteLocalLife(param.LocalId)
	if err != nil {
		logrus.Errorf("[DeleteLocalLife] call DeleteLocalLife err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["localId"] = *localId
	returnSuccess(c, 20000, resultMap)
}

// 结束本地生活任务
func (t TaskController) LocalLifeClose(c *gin.Context) {
	param := &vo.LocalSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	todo, err1 := service.LocalLifeService{}.CloseLocalLife(param.LocalId)
	if err1 != nil {
		logrus.Errorf("[CloseLocalLife] call CloseLocalLife err:%+v\n", err1)
		returnError(c, 40000, err1.Error())
		return
	}
	resultMap := make(map[string]string)
	resultMap["localId"] = param.LocalId
	resultMap["todo"] = todo
	returnSuccess(c, 20000, resultMap)
}

// 探店本地生活列表
func (t TaskController) StoreExploreList(c *gin.Context) {
	param := &vo.LocalSearchParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.LocalLifeService{}.GetStoreExploreList(param)
	if err != nil {
		logrus.Errorf("[StoreExploreList] call StoreExploreList err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, res)
}

// 探店达人详情
func (t TaskController) StoreExploreInfo(c *gin.Context) {
	param := &vo.StoreExploreParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.LocalLifeService{}.GetStoreExploreInfo(param)
	if err != nil {
		logrus.Errorf("[StoreExploreInfo] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, res)
}

// 探店达人列表角标
func (t TaskController) StoreExploreInfoCount(c *gin.Context) {
	param := &vo.StoreExploreParam{}
	err := c.BindJSON(param)
	if err != nil || "" == param.LocalLifeId {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res := service.LocalLifeService{}.StoreExploreInfoCount(param)

	returnSuccess(c, 20000, res)
}

// 探店终止合作
func (t TaskController) StoreExploreOver(c *gin.Context) {
	param := &vo.LocalTalentOperateParam{}
	err := c.BindJSON(param)
	if err != nil || param.TaskId == "" {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	res, err := service.LocalLifeService{}.StoreExploreOver(param)
	if err != nil {
		logrus.Errorf("[StoreExploreOver] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, res)
}

// 预约时间批量同意/驳回
func (t TaskController) StoreExploreOperate(c *gin.Context) {
	param := &vo.LocalTalentOperateParam{}
	err := c.BindJSON(param)
	if err != nil || param.TaskIds == nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	err = service.LocalLifeService{}.StoreExploreOperate(param)
	if err != nil {
		logrus.Errorf("[StoreExploreOperate] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	returnSuccess(c, 20000, nil)
}

// 电商带货看数据-达人数据
func (t TaskController) TalentDataDetail(c *gin.Context) {
	param := &vo.SelectionShowDataParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err := service.ViewDataService{}.SelectionTalentDataDetail(param)
	if err != nil {
		logrus.Errorf("[TalentDataDetail] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]vo.ReSelectionTalentData)
	resultMap["dataInfo"] = result
	returnSuccess(c, 20000, resultMap)
}

// 电商带货看数据-领样数据
func (t TaskController) SampleDataDetail(c *gin.Context) {
	param := &vo.SelectionShowDataParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err := service.ViewDataService{}.SelectionSampleDataDetail(param)
	if err != nil {
		logrus.Errorf("[SampleDataDetail] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]vo.ReSelectionSampleData)
	resultMap["dataInfo"] = result
	returnSuccess(c, 20000, resultMap)
}

// 电商带货看数据-带货数据
func (t TaskController) SelectionDataDetail(c *gin.Context) {
	param := &vo.SelectionShowDataParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err := service.ViewDataService{}.SelectionDataDetail(param)
	if err != nil {
		logrus.Errorf("[SelectionDataDetail] call Show err:%+v\n", err)
		returnError(c, 40000, err.Error())
		return
	}
	resultMap := make(map[string]vo.ReSelectionData)
	resultMap["dataInfo"] = result
	returnSuccess(c, 20000, resultMap)
}

// 电商带货执行中-悬赏兑现
func (t TaskController) SelectionRewardCash(c *gin.Context) {
	param := &vo.SelectionRewardCashParam{}
	err := c.BindJSON(param)
	if err != nil {
		logrus.Errorf("Request bind err:%+v\n", err)
		returnError(c, 40000, "Parameter Error: "+err.Error())
		return
	}
	result, err1 := service.TaskInfoService{}.SelectionRewardCashDetail(param)
	if err1 != nil {
		logrus.Errorf("[SelectionRewardCash] call Show err:%+v\n", err)
		returnError(c, 40000, err1.Error())
		return
	}
	returnSuccess(c, 20000, result)
}
