作者 陈志颖

fix:金额激励分红预算

... ... @@ -800,11 +800,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
// 分离分红订单和退货单
dividendsOrderNumbers := make([]string, 0)
dividendsReturnedOrderNumbers := make([]string, 0)
for k, _ := range estimateSuccessfullyDividendsOrders {
if k[:2] == "RE" { // 分红退货单
dividendsReturnedOrderNumbers = append(dividendsReturnedOrderNumbers, k)
} else if k[:2] == "SL" { // 分红订单
dividendsOrderNumbers = append(dividendsOrderNumbers, k)
if len(estimateSuccessfullyDividendsOrders) > 0 {
for k, _ := range estimateSuccessfullyDividendsOrders {
if k[:2] == "RE" { // 分红退货单
dividendsReturnedOrderNumbers = append(dividendsReturnedOrderNumbers, k)
} else if k[:2] == "SL" { // 分红订单
dividendsOrderNumbers = append(dividendsOrderNumbers, k)
}
}
}
... ... @@ -819,33 +821,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 查找分红订单
if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
"dividendsOrderNumbers": dividendsOrderNumbers,
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countDividendsOrdersFound > 0 {
for i, dividendsOrderFound := range dividendsOrdersFound {
var dividendsGoodCount int
for _, orderGood := range dividendsOrderFound.Goods {
if orderGood.OrderGoodDividendsStatus == 2 {
dividendsGoodCount = dividendsGoodCount + 1
if len(dividendsOrderNumbers) > 0 {
if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
"dividendsOrderNumbers": dividendsOrderNumbers,
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countDividendsOrdersFound > 0 {
for i, dividendsOrderFound := range dividendsOrdersFound {
var dividendsGoodCount int
for _, orderGood := range dividendsOrderFound.Goods {
if orderGood.OrderGoodDividendsStatus == 2 {
dividendsGoodCount = dividendsGoodCount + 1
}
}
if dividendsGoodCount == len(dividendsOrderFound.Goods) { // 2已分红
dividendsOrdersFound[i].DividendStatus = 2
} else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsOrderFound.Goods) { // 3部分分红
dividendsOrdersFound[i].DividendStatus = 3
} else if dividendsGoodCount == 0 { // 1未分红
dividendsOrdersFound[i].DividendStatus = 1
}
}
if dividendsGoodCount == len(dividendsOrderFound.Goods) { // 2已分红
dividendsOrdersFound[i].DividendStatus = 2
} else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsOrderFound.Goods) { // 3部分分红
dividendsOrdersFound[i].DividendStatus = 3
} else if dividendsGoodCount == 0 { // 1未分红
dividendsOrdersFound[i].DividendStatus = 1
// 保存订单状态
if _, err6 := dividendsOrderRepository.UpdateMany(dividendsOrdersFound); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 保存订单状态
if _, err6 := dividendsOrderRepository.UpdateMany(dividendsOrdersFound); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
... ... @@ -860,33 +864,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
}
// 查找分红退货单
if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countDividendsReturnedOrdersFound > 0 {
for i, dividendsReturnedOrderFound := range dividendsReturnedOrdersFound {
var dividendsGoodCount int
for _, orderGood := range dividendsReturnedOrderFound.Goods {
if orderGood.OrderGoodDividendsStatus == 2 {
dividendsGoodCount = dividendsGoodCount + 1
if len(dividendsReturnedOrderNumbers) > 0 {
if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
"companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
"orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countDividendsReturnedOrdersFound > 0 {
for i, dividendsReturnedOrderFound := range dividendsReturnedOrdersFound {
var dividendsGoodCount int
for _, orderGood := range dividendsReturnedOrderFound.Goods {
if orderGood.OrderGoodDividendsStatus == 2 {
dividendsGoodCount = dividendsGoodCount + 1
}
}
if dividendsGoodCount == len(dividendsReturnedOrderFound.Goods) { // 2已分红
dividendsReturnedOrdersFound[i].DividendStatus = 2
} else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsReturnedOrderFound.Goods) { // 3部分分红
dividendsReturnedOrdersFound[i].DividendStatus = 3
} else if dividendsGoodCount == 0 { // 1未分红
dividendsReturnedOrdersFound[i].DividendStatus = 1
}
}
if dividendsGoodCount == len(dividendsReturnedOrderFound.Goods) { // 2已分红
dividendsReturnedOrdersFound[i].DividendStatus = 2
} else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsReturnedOrderFound.Goods) { // 3部分分红
dividendsReturnedOrdersFound[i].DividendStatus = 3
} else if dividendsGoodCount == 0 { // 1未分红
dividendsReturnedOrdersFound[i].DividendStatus = 1
// 保存退货单状态
if _, err6 := dividendsReturnedOrderRepository.UpdateMany(dividendsReturnedOrdersFound); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
// 保存退货单状态
if _, err6 := dividendsReturnedOrderRepository.UpdateMany(dividendsReturnedOrdersFound); err6 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
... ...
... ... @@ -63,7 +63,8 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
if undertakerEstimated {
return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
} else {
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64()
undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).
Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage)).Div(decimal.NewFromFloat(100)))).Float64()
dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
DividendsUser: &domain.User{
UserId: undertaker.UserId,
... ...