package service import ( "strconv" "time" "youngee_b_api/app/dao" "youngee_b_api/app/entity" "youngee_b_api/app/vo" ) type DefaultService struct{} // 违约管理——违约公开任务列表 func (s DefaultService) GetPublicDefaultList(param *vo.DefaultSearchParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO // 以下代码只考虑了种草 reTaskDefaultPublics, total, err := (&dao.ProjectDAO{}).GetProjectPublicList(param) if err != nil { return result, err } for i := range reTaskDefaultPublics { // 获取商品详情字段 var creatorName string var productName string var productPrice float64 var mainImage string if reTaskDefaultPublics[i].SubAccountId == 0 { enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reTaskDefaultPublics[i].EnterpriseId) if err == nil && enterprise != nil { creatorName = enterprise.BusinessName } } else { subAccount, err := dao.SubAccountDao{}.GetSubAccount(reTaskDefaultPublics[i].SubAccountId) if err == nil && subAccount != nil { creatorName = subAccount.SubAccountName } } product, err := dao.ProductDAO{}.GetProductByID(reTaskDefaultPublics[i].ProductId) if err == nil && product != nil { productName = product.ProductName productPrice = product.ProductPrice } mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reTaskDefaultPublics[i].ProductId) reTaskDefaultPublics[i].CreatorName = creatorName reTaskDefaultPublics[i].ProductName = productName reTaskDefaultPublics[i].ProductPrice = productPrice reTaskDefaultPublics[i].MainImage = mainImage // 获取未传数量字段 0-10分别表示未违约、脚本超时违约、脚本未上传违约、初稿超时违约、初稿未上传违约、链接超时违约、链接未上传违约、数据超时违约、数据未上传违约、解约待处理、解约 projectId := reTaskDefaultPublics[i].TaskId noSketchNum := dao.ProjectTaskInfoDao{}.CountByDefaultType(projectId, 4) noLinkNum := dao.ProjectTaskInfoDao{}.CountByDefaultType(projectId, 6) noDataNum := dao.ProjectTaskInfoDao{}.CountByDefaultType(projectId, 8) // 终止合作还是解约字段待确认 endCooperationNum := dao.ProjectTaskInfoDao{}.CountByTaskStage(projectId, 17) reTaskDefaultPublics[i].NoSketchNum = noSketchNum reTaskDefaultPublics[i].NoLinkNum = noLinkNum reTaskDefaultPublics[i].NoDataNum = noDataNum reTaskDefaultPublics[i].EndCooperationNum = endCooperationNum } result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: reTaskDefaultPublics, } return result, nil } // 违约管理——违约定向任务列表 func (s DefaultService) GetTargetDefaultList(param *vo.DefaultSearchParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO // 以下代码只考虑了种草 reTaskDefaultTargets, total, err := (&dao.ProjectDAO{}).GetProjectTargetList(param) if err != nil { return result, err } for i := range reTaskDefaultTargets { // 获取商品详情字段 var creatorName string var productName string var productPrice float64 var mainImage string if reTaskDefaultTargets[i].SubAccountId == 0 { enterprise, err := dao.EnterpriseDao{}.GetEnterprise(reTaskDefaultTargets[i].EnterpriseId) if err == nil && enterprise != nil { creatorName = enterprise.BusinessName } } else { subAccount, err := dao.SubAccountDao{}.GetSubAccount(reTaskDefaultTargets[i].SubAccountId) if err == nil && subAccount != nil { creatorName = subAccount.SubAccountName } } product, err := dao.ProductDAO{}.GetProductByID(reTaskDefaultTargets[i].ProductId) if err == nil && product != nil { productName = product.ProductName productPrice = product.ProductPrice } mainImage, err = dao.ProductPhotoDAO{}.GetMainPhotoByProductID(reTaskDefaultTargets[i].ProductId) reTaskDefaultTargets[i].CreatorName = creatorName reTaskDefaultTargets[i].ProductName = productName reTaskDefaultTargets[i].ProductPrice = productPrice reTaskDefaultTargets[i].MainImage = mainImage // 终止合作还是解约字段待确认 endCooperationNum := dao.ProjectTaskInfoDao{}.CountByTaskStage(reTaskDefaultTargets[i].TaskId, 17) reTaskDefaultTargets[i].EndCooperationNum = endCooperationNum } result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: reTaskDefaultTargets, } return result, nil } // 违约管理——公开任务-违约达人列表 func (s DefaultService) GetPublicDefaultTalentList(param *vo.DefaultSearchParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO var reTalentDefaults []*vo.ReTalentDefault // 以下代码只考虑了种草 var projectTaskInfos []entity.ProjectTaskInfo var total int64 var err error var cutRate int64 defaultType := param.DefaultType if defaultType == 1 { // 未传初稿 projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListBySketchDefault(param) autoDefaultId, _ := dao.ProjectDAO{}.GetAutoDefaultId(param.TaskId) cutRate = dao.InfoAutoDefaultDao{}.GetValueByIdFieldName(*autoDefaultId, "sketch_replace_not_upload") } else if defaultType == 2 { // 未发作品 projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByLinkDefault(param) autoDefaultId, _ := dao.ProjectDAO{}.GetAutoDefaultId(param.TaskId) cutRate = dao.InfoAutoDefaultDao{}.GetValueByIdFieldName(*autoDefaultId, "link_replace_not_upload") } else if defaultType == 3 { // 未传数据 projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByDataDefault(param) autoDefaultId, _ := dao.ProjectDAO{}.GetAutoDefaultId(param.TaskId) cutRate = dao.InfoAutoDefaultDao{}.GetValueByIdFieldName(*autoDefaultId, "data_replace_not_upload") } else if defaultType == 4 { // 终止合作 projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByTerminateDefault(param) } else if defaultType == 5 { // 已解约 projectTaskInfos, total, err = dao.ProjectTaskInfoDao{}.GetListByCancelDefault(param) } if err != nil { return result, err } for _, projectTaskInfo := range projectTaskInfos { talentId := projectTaskInfo.TalentID talentPhone, _ := dao.TalentInfoDao{}.SelectTalentPhone(talentId) platformKuaishouUserInfo, _ := dao.PlatformKuaishouUserInfoDao{}.SelectUserInfo(talentId) reTalentDefault := &vo.ReTalentDefault{ TalentId: talentId, TalentPhone: *talentPhone, TaskId: projectTaskInfo.TaskID, DraftFee: projectTaskInfo.DraftFee, OpenId: platformKuaishouUserInfo.OpenId, NickName: platformKuaishouUserInfo.NickName, HeadUri: platformKuaishouUserInfo.HeadUri, City: "-", } if defaultType == 1 { reTalentDefault.DefaultTime = projectTaskInfo.SketchMissingTime.Format("2006-01-02 15:04:05") reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount } else if defaultType == 2 { reTalentDefault.DefaultTime = projectTaskInfo.LinkMissingTime.Format("2006-01-02 15:04:05") reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount } else if defaultType == 3 { reTalentDefault.DefaultTime = projectTaskInfo.DataMissingTime.Format("2006-01-02 15:04:05") reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount } else if defaultType == 4 { reTalentDefault.DefaultTime = projectTaskInfo.TerminateTime.Format("2006-01-02 15:04:05") reTalentDefault.Reason = projectTaskInfo.TerminateReason terminateOperatorType := projectTaskInfo.TerminateOperatorType if terminateOperatorType == 1 { enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.TerminateOperator) reTalentDefault.OperatorName = enterprise.BusinessName } else if terminateOperatorType == 2 { operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64) subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId) reTalentDefault.OperatorName = subAccount.SubAccountName } else if terminateOperatorType == 3 { operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64) userName, _ := dao.UserDao{}.GetNameByUserId(operatorId) reTalentDefault.OperatorName = userName } } else if defaultType == 5 { reTalentDefault.DefaultTime = projectTaskInfo.CancelTime.Format("2006-01-02 15:04:05") reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount reTalentDefault.Reason = projectTaskInfo.CancelReason cancelOperatorType := projectTaskInfo.CancelOperatorType if cancelOperatorType == 1 { enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.CancelOperator) reTalentDefault.OperatorName = enterprise.BusinessName } else if cancelOperatorType == 2 { operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64) subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId) reTalentDefault.OperatorName = subAccount.SubAccountName } else if cancelOperatorType == 3 { operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64) userName, _ := dao.UserDao{}.GetNameByUserId(operatorId) reTalentDefault.OperatorName = userName } } reTalentDefaults = append(reTalentDefaults, reTalentDefault) } resultMap := make(map[string]interface{}) resultMap["cutRate"] = cutRate resultMap["reTalentDefaults"] = reTalentDefaults result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: resultMap, } return result, nil } // 违约管理——定向任务-违约达人列表 func (s DefaultService) GetTargetDefaultTalentList(param *vo.DefaultSearchParam) (vo.ResultVO, error) { if param.Page == 0 { param.Page = 1 } if param.PageSize == 0 { param.PageSize = 10 } var result vo.ResultVO var reTalentDefaults []*vo.ReTalentDefault // 以下代码只考虑了种草 var projectTaskInfos []entity.ProjectTaskInfo var total int64 var err error defaultType := param.DefaultType if defaultType == 4 { // 终止合作 projectTaskInfos, total, err = (&dao.ProjectTaskInfoDao{}).GetListByTerminateDefault(param) } else if defaultType == 5 { // 已解约 projectTaskInfos, total, err = (&dao.ProjectTaskInfoDao{}).GetListByCancelDefault(param) } if err != nil { return result, err } for _, projectTaskInfo := range projectTaskInfos { talentId := projectTaskInfo.TalentID talentPhone, _ := dao.TalentInfoDao{}.SelectTalentPhone(talentId) platformKuaishouUserInfo, _ := dao.PlatformKuaishouUserInfoDao{}.SelectUserInfo(talentId) reTalentDefault := &vo.ReTalentDefault{ TalentId: talentId, TalentPhone: *talentPhone, DraftFee: projectTaskInfo.DraftFee, OpenId: platformKuaishouUserInfo.OpenId, NickName: platformKuaishouUserInfo.NickName, HeadUri: platformKuaishouUserInfo.HeadUri, City: "-", } if defaultType == 4 { reTalentDefault.DefaultTime = projectTaskInfo.TerminateTime.Format("2006-01-02 15:04:05") reTalentDefault.Reason = projectTaskInfo.TerminateReason terminateOperatorType := projectTaskInfo.TerminateOperatorType if terminateOperatorType == 1 { enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.TerminateOperator) reTalentDefault.OperatorName = enterprise.BusinessName } else if terminateOperatorType == 2 { operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64) subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId) reTalentDefault.OperatorName = subAccount.SubAccountName } else if terminateOperatorType == 3 { operatorId, _ := strconv.ParseInt(projectTaskInfo.TerminateOperator, 10, 64) userName, _ := dao.UserDao{}.GetNameByUserId(operatorId) reTalentDefault.OperatorName = userName } } else if defaultType == 5 { reTalentDefault.DefaultTime = projectTaskInfo.CancelTime.Format("2006-01-02 15:04:05") reTalentDefault.SettleAmount = projectTaskInfo.SettleAmount cancelOperatorType := projectTaskInfo.CancelOperatorType if cancelOperatorType == 1 { enterprise, _ := dao.EnterpriseDao{}.GetEnterprise(projectTaskInfo.CancelOperator) reTalentDefault.OperatorName = enterprise.BusinessName } else if cancelOperatorType == 2 { operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64) subAccount, _ := dao.SubAccountDao{}.GetSubAccount(operatorId) reTalentDefault.OperatorName = subAccount.SubAccountName } else if cancelOperatorType == 3 { operatorId, _ := strconv.ParseInt(projectTaskInfo.CancelOperator, 10, 64) userName, _ := dao.UserDao{}.GetNameByUserId(operatorId) reTalentDefault.OperatorName = userName } } reTalentDefaults = append(reTalentDefaults, reTalentDefault) } result = vo.ResultVO{ Page: param.Page, PageSize: param.PageSize, Total: total, Data: reTalentDefaults, } return result, nil } // 违约管理——达人解约 func (s DefaultService) CancelTalent(param *vo.TalentCancelParam) error { updateData := map[string]interface{}{ "task_stage": 16, "settle_amount": param.RealPayment, "real_payment": param.RealPayment, "cancel_reason": param.CancelReason, "cancel_time": time.Now(), } err := dao.ProjectTaskInfoDao{}.UpdateField(param.TaskId, updateData) if err != nil { return err } return nil } // 违约管理——达人批量解约 func (s DefaultService) CancelTalentList(param *vo.TalentCancelParam) error { updateData := map[string]interface{}{ "task_stage": 16, "settle_amount": param.RealPayment, "real_payment": param.RealPayment, "cancel_reason": param.CancelReason, "cancel_time": time.Now(), } err := dao.ProjectTaskInfoDao{}.UpdateFieldBatch(param.TaskIds, updateData) if err != nil { return err } return nil }