作者 陈志颖

refactor:优化分红预算提示信息

... ... @@ -10,7 +10,7 @@ import (
type ApplyForCooperationCommand struct {
// 共创申请描述附件
CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment" valid:"Required"`
CooperationApplicationAttachment []*domain.Attachment `cname:"共创申请描述附件" json:"cooperationApplicationAttachment"`
// 共创申请描述
CooperationApplicationDescription string `cname:"共创申请描述" json:"cooperationApplicationDescription,omitempty"`
// 申请人ID
... ...
... ... @@ -546,25 +546,25 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
operator = data
}
// 分红订单仓储初始化
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsOrderRepository = value
}
//// 分红订单仓储初始化
//var dividendsOrderRepository domain.DividendsOrderRepository
//if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// dividendsOrderRepository = value
//}
// 分红退货单仓储初始化
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsReturnedOrderRepository = value
}
//var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
//if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
// "transactionContext": transactionContext,
//}); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//} else {
// dividendsReturnedOrderRepository = value
//}
// 订单产品仓储初始化
var orderGoodRepository domain.OrderGoodRepository
... ... @@ -610,10 +610,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 统计成功预算的分红订单
var estimateSuccessfullyDividendsOrders map[string]int
estimateSuccessfullyDividendsOrders := make(map[string]string)
// 统计预算失败的分红订单
var estimateFailedDividendsOrders map[string]int
estimateFailedDividendsOrders := make(map[string]string)
// 获取订单产品
if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{
... ... @@ -621,7 +621,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
var dividendsEstimates []*domain.DividendsEstimate
dividendsEstimates := make([]*domain.DividendsEstimate, 0)
// 统计当前分红预算单数
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
... ... @@ -633,102 +633,116 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
for _, orderGood := range orderGoods {
dividendsEstimate := &domain.DividendsEstimate{}
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
}
//dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{
// "dividendsOrderNumber": orderGood.DividendsOrderNumber,
// "companyId": orderGood.CompanyId,
// "orgId": orderGood.OrgId,
//})
//if err3 != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
//}
//if dividendsOrder == nil {
// return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
//}
// 分红订单产品预算
if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsEstimateDetail := range dividendsEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.ORDER_DIVIDENDS,
DividendsTypeName: "订单分红",
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
if dividendsEstimateDetail.IsSuccessfully {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 记录成功的订单号
estimateSuccessfullyDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.OrderOrReturnedOrderNumber
// 统计分红预算单数目
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
DividendsType: domain.ORDER_DIVIDENDS,
DividendsTypeName: "订单分红",
OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsEstimateDetail.DividendsUser,
DividendsStage: dividendsEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
} else {
// 记录失败的订单号和原因s
estimateFailedDividendsOrders[dividendsEstimateDetail.OrderOrReturnedOrderNumber] = dividendsEstimateDetail.Reason
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
}
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if dividendsReturnedOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红退货单%s不存在", orderGood.DividendsReturnedOrderNumber))
}
// 分红退货单产品预算
if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
countDividendsEstimate = countDividendsEstimate + 1
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
DividendsType: domain.RETURN_WRITE_OFF,
DividendsTypeName: "退货冲销",
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
if dividendsReturnedEstimateDetail.IsSuccessfully {
// 生成分红预算单号
dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 记录成功的退货单号
estimateSuccessfullyDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber
// 统计生成的预算单数量
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate = &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
DividendsEstimateTime: time.Now(),
DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
DividendsType: domain.RETURN_WRITE_OFF,
DividendsTypeName: "退货冲销",
OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
CooperationContractNumber: orderGood.CooperationContractNumber,
DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
Org: organization,
Company: company,
Operator: operator,
OperateTime: time.Time{},
IsCanceled: false,
CreatedAt: time.Now(),
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
OrderGoodId: orderGood.OrderGoodId,
OrderGoodAmount: orderGood.OrderGoodAmount,
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
} else {
// 记录失败的退货单号和原因
estimateFailedDividendsOrders[dividendsReturnedEstimateDetail.OrderOrReturnedOrderNumber] = dividendsReturnedEstimateDetail.Reason
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
}
}
... ... @@ -744,8 +758,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 分析成功和失败原因
successfullyCount := len(dividendsEstimatesSaved)
// 错误原因收集,返回第一个可能的原因
var failedReason []string
for _, v := range estimateFailedDividendsOrders {
failedReason = append(failedReason, v)
}
return map[string]interface{}{
"report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), ""),
"report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReason[0]),
}, nil
}
}
... ... @@ -842,11 +861,20 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
dividendsEstimateRepository = value
}
cooperationContractId, _ := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
undertakerUIDs, _ := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
cooperationContractId, err := strconv.ParseInt(confirmMoneyIncentivesEstimateCommand.CooperationContractId, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "合约编号类型错误:"+err.Error())
}
undertakerUIDs, err := utils.SliceAtoi(confirmMoneyIncentivesEstimateCommand.UndertakerUids)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人UID类型错误:"+err.Error())
}
// 获取共创合约
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractId": cooperationContractId})
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
"cooperationContractId": cooperationContractId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -860,7 +888,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{
"companyId": confirmMoneyIncentivesEstimateCommand.CompanyId,
})
// 分红预算单统计
var countDividendsEstimate int64
// 共创合约预算
if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
... ... @@ -871,7 +902,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 统计生成的预算单数目
countDividendsEstimate = countDividendsEstimate + 1
dividendsEstimate := &domain.DividendsEstimate{
DividendsEstimateId: 0,
DividendsAccountStatus: domain.TO_BE_ACCOUNT,
... ... @@ -894,6 +928,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
DeletedAt: time.Time{},
UpdatedAt: time.Time{},
}
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
}
dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates)
... ...
... ... @@ -8,10 +8,13 @@ import (
)
type DividendsEstimateDetail struct {
DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型
DividendsStage int32 `json:"dividendsStage"` // 分红阶段
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型
DividendsStage int32 `json:"dividendsStage"` // 分红阶段
DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
Reason string `json:"reason"` // 错误原因
}
// GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
... ...
... ... @@ -2,7 +2,6 @@ package domain_service
import (
"fmt"
"github.com/linmadan/egglib-go/core/application"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/shopspring/decimal"
... ... @@ -57,29 +56,84 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
// 获取合约
cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{
"cooperationContractNumber": orderGood.CooperationContractNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
IsSuccessfully: false,
Reason: "共创合约错误",
})
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
IsSuccessfully: false,
Reason: "共创合约" + orderGood.CooperationContractNumber + "不存在",
})
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
}
// 获取共创项目
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
"cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
"companyId": cooperationContract.Company.CompanyId,
"orgId": cooperationContract.Org.OrgId,
"notPause": true,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
IsSuccessfully: false,
Reason: "共创项目" + orderGood.CooperationContractNumber + "查询错误",
})
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber))
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
IsSuccessfully: false,
Reason: "共创项目" + orderGood.CooperationContractNumber + "已结束或不存在",
})
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber))
}
// 校验合约关联的项目是否已结束
if cooperationProject.Status == 2 {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))
}
//if cooperationProject.Status == 2 {
// dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
// DividendsUser: nil,
// DividendsParticipateType: 0,
// DividendsStage: 0,
// DividendsAmount: 0,
// OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
// IsSuccessfully: false,
// Reason: "共创项目" + orderGood.CooperationContractNumber + "已结束",
// })
// continue
// //return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))
//}
if orderGood.DividendsOrderNumber != "" { // 获取分红订单
// 获取分红订单
... ... @@ -89,10 +143,30 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
"orgId": orderGood.OrgId,
})
if err2 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
IsSuccessfully: false,
Reason: "分红订单" + orderGood.DividendsOrderNumber + "查询错误",
})
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")
}
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
IsSuccessfully: false,
Reason: "分红订单" + orderGood.DividendsOrderNumber + "不存在",
})
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
}
// 匹配分红规则
... ... @@ -104,7 +178,17 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
}
}
if dividendsIncentivesRuleMatched == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "未匹配到分红规则")
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsOrderNumber,
IsSuccessfully: false,
Reason: "未匹配到分红规则",
})
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, "未匹配到分红规则")
}
// 计算分红
... ... @@ -127,9 +211,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Status: undertaker.Status,
Company: undertaker.Company,
},
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: undertakerDividendsAmount,
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
})
// 添加推荐人分红预算信息详情
if undertaker.Referrer != nil {
... ... @@ -148,9 +234,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: referrerDividendsAmount,
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
})
}
// 添加关联业务员分红预算信息详情
... ... @@ -170,22 +258,46 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Salesman.UserPhone,
Company: undertaker.Salesman.Company,
},
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: salesmanDividendsAmount,
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: salesmanDividendsAmount,
OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
IsSuccessfully: true,
})
}
}
}
} else if orderGood.DividendsReturnedOrderNumber != "" { // 获取分红退货单
} else if orderGood.DividendsReturnedOrderNumber != "" { // 获取退货单
dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber,
"companyId": orderGood.CompanyId,
"orgId": orderGood.OrgId,
})
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单不存在")
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
IsSuccessfully: false,
Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
})
continue
//return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单不存在")
}
if dividendsReturnedOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: nil,
DividendsParticipateType: 0,
DividendsStage: 0,
DividendsAmount: 0,
OrderOrReturnedOrderNumber: orderGood.DividendsReturnedOrderNumber,
IsSuccessfully: false,
Reason: "退货单" + orderGood.DividendsReturnedOrderNumber + "不存在",
})
continue
//return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
}
// 匹配分红规则
var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
... ... @@ -214,9 +326,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
Status: undertaker.Status,
Company: undertaker.Company,
},
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -undertakerDividendsAmount,
DividendsParticipateType: domain.UNDERTAKER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -undertakerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
IsSuccessfully: true,
})
// 添加推荐人分红退货预算信息详情
if undertaker.Referrer != nil {
... ... @@ -235,9 +349,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Referrer.UserPhone,
Company: undertaker.Referrer.Company,
},
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -referrerDividendsAmount,
DividendsParticipateType: domain.REFERRER,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -referrerDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
IsSuccessfully: true,
})
}
// 添加关联业务员分红退货预算信息详情
... ... @@ -257,9 +373,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
UserPhone: undertaker.Salesman.UserPhone,
Company: undertaker.Salesman.Company,
},
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -salesmanDividendsAmount,
DividendsParticipateType: domain.SALESMAN,
DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
DividendsAmount: -salesmanDividendsAmount,
OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber,
IsSuccessfully: true,
})
}
}
... ...
... ... @@ -17,16 +17,8 @@ type ConfirmMoneyIncentivesEstimateService struct {
}
func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) {
//var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储
var dividendsEstimateDao *dao.DividendsEstimateDao // 分红预算DAO
// 分红预算单仓储初始化
//if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
// return nil, err
//} else {
// dividendsEstimateRepository = repo
//}
// 分红预算DAO初始化
if estimateDao, err := dao.NewDividendsEstimateDao(domainService.transactionContext); err != nil {
return nil, err
... ...
... ... @@ -220,6 +220,9 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 {
query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId)
}
if notPause, ok := queryOptions["notPause"]; ok && notPause.(bool) != false {
query.Where("status <> ?", 2)
}
if err := query.First(); err != nil {
if err.Error() == "pg: no rows in result set" {
return nil, fmt.Errorf("共创项目不存在")
... ...
... ... @@ -195,18 +195,21 @@ func (repository *DividendsEstimateRepository) SaveMany(dividendsEstimates []*do
UpdatedAt: dividendsEstimate.UpdatedAt,
})
}
if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
return nil, err
}
var dividendsEstimatesSaved []*domain.DividendsEstimate
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return dividendsEstimates, err
} else {
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
if len(dividendsEstimateModels) > 0 {
if _, err := tx.Model(&dividendsEstimateModels).Insert(); err != nil {
return nil, err
}
var dividendsEstimatesSaved []*domain.DividendsEstimate
for _, dividendsEstimateModel := range dividendsEstimateModels {
if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil {
return dividendsEstimates, err
} else {
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimate)
}
}
return dividendsEstimatesSaved, nil
}
return dividendsEstimatesSaved, nil
return nil, nil
}
func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []*domain.DividendsEstimate) ([]*domain.DividendsEstimate, error) {
... ...