作者 陈志颖

fix:金额激励分红预算

@@ -800,11 +800,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -800,11 +800,13 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
800 // 分离分红订单和退货单 800 // 分离分红订单和退货单
801 dividendsOrderNumbers := make([]string, 0) 801 dividendsOrderNumbers := make([]string, 0)
802 dividendsReturnedOrderNumbers := make([]string, 0) 802 dividendsReturnedOrderNumbers := make([]string, 0)
803 - for k, _ := range estimateSuccessfullyDividendsOrders {  
804 - if k[:2] == "RE" { // 分红退货单  
805 - dividendsReturnedOrderNumbers = append(dividendsReturnedOrderNumbers, k)  
806 - } else if k[:2] == "SL" { // 分红订单  
807 - dividendsOrderNumbers = append(dividendsOrderNumbers, k) 803 + if len(estimateSuccessfullyDividendsOrders) > 0 {
  804 + for k, _ := range estimateSuccessfullyDividendsOrders {
  805 + if k[:2] == "RE" { // 分红退货单
  806 + dividendsReturnedOrderNumbers = append(dividendsReturnedOrderNumbers, k)
  807 + } else if k[:2] == "SL" { // 分红订单
  808 + dividendsOrderNumbers = append(dividendsOrderNumbers, k)
  809 + }
808 } 810 }
809 } 811 }
810 812
@@ -819,33 +821,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -819,33 +821,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
819 } 821 }
820 822
821 // 查找分红订单 823 // 查找分红订单
822 - if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{  
823 - "dividendsOrderNumbers": dividendsOrderNumbers,  
824 - "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,  
825 - "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,  
826 - }); err != nil {  
827 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
828 - } else {  
829 - if countDividendsOrdersFound > 0 {  
830 - for i, dividendsOrderFound := range dividendsOrdersFound {  
831 - var dividendsGoodCount int  
832 - for _, orderGood := range dividendsOrderFound.Goods {  
833 - if orderGood.OrderGoodDividendsStatus == 2 {  
834 - dividendsGoodCount = dividendsGoodCount + 1 824 + if len(dividendsOrderNumbers) > 0 {
  825 + if countDividendsOrdersFound, dividendsOrdersFound, err := dividendsOrderRepository.Find(map[string]interface{}{
  826 + "dividendsOrderNumbers": dividendsOrderNumbers,
  827 + "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
  828 + "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
  829 + }); err != nil {
  830 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  831 + } else {
  832 + if countDividendsOrdersFound > 0 {
  833 + for i, dividendsOrderFound := range dividendsOrdersFound {
  834 + var dividendsGoodCount int
  835 + for _, orderGood := range dividendsOrderFound.Goods {
  836 + if orderGood.OrderGoodDividendsStatus == 2 {
  837 + dividendsGoodCount = dividendsGoodCount + 1
  838 + }
  839 + }
  840 + if dividendsGoodCount == len(dividendsOrderFound.Goods) { // 2已分红
  841 + dividendsOrdersFound[i].DividendStatus = 2
  842 + } else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsOrderFound.Goods) { // 3部分分红
  843 + dividendsOrdersFound[i].DividendStatus = 3
  844 + } else if dividendsGoodCount == 0 { // 1未分红
  845 + dividendsOrdersFound[i].DividendStatus = 1
835 } 846 }
836 } 847 }
837 - if dividendsGoodCount == len(dividendsOrderFound.Goods) { // 2已分红  
838 - dividendsOrdersFound[i].DividendStatus = 2  
839 - } else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsOrderFound.Goods) { // 3部分分红  
840 - dividendsOrdersFound[i].DividendStatus = 3  
841 - } else if dividendsGoodCount == 0 { // 1未分红  
842 - dividendsOrdersFound[i].DividendStatus = 1 848 + // 保存订单状态
  849 + if _, err6 := dividendsOrderRepository.UpdateMany(dividendsOrdersFound); err6 != nil {
  850 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
843 } 851 }
844 } 852 }
845 - // 保存订单状态  
846 - if _, err6 := dividendsOrderRepository.UpdateMany(dividendsOrdersFound); err6 != nil {  
847 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
848 - }  
849 } 853 }
850 } 854 }
851 855
@@ -860,33 +864,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -860,33 +864,35 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
860 } 864 }
861 865
862 // 查找分红退货单 866 // 查找分红退货单
863 - if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{  
864 - "dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,  
865 - "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,  
866 - "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,  
867 - }); err != nil {  
868 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
869 - } else {  
870 - if countDividendsReturnedOrdersFound > 0 {  
871 - for i, dividendsReturnedOrderFound := range dividendsReturnedOrdersFound {  
872 - var dividendsGoodCount int  
873 - for _, orderGood := range dividendsReturnedOrderFound.Goods {  
874 - if orderGood.OrderGoodDividendsStatus == 2 {  
875 - dividendsGoodCount = dividendsGoodCount + 1 867 + if len(dividendsReturnedOrderNumbers) > 0 {
  868 + if countDividendsReturnedOrdersFound, dividendsReturnedOrdersFound, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
  869 + "dividendsReturnedOrderNumbers": dividendsReturnedOrderNumbers,
  870 + "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId,
  871 + "orgId": confirmDividendsIncentivesEstimateCommand.OrgId,
  872 + }); err != nil {
  873 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  874 + } else {
  875 + if countDividendsReturnedOrdersFound > 0 {
  876 + for i, dividendsReturnedOrderFound := range dividendsReturnedOrdersFound {
  877 + var dividendsGoodCount int
  878 + for _, orderGood := range dividendsReturnedOrderFound.Goods {
  879 + if orderGood.OrderGoodDividendsStatus == 2 {
  880 + dividendsGoodCount = dividendsGoodCount + 1
  881 + }
  882 + }
  883 + if dividendsGoodCount == len(dividendsReturnedOrderFound.Goods) { // 2已分红
  884 + dividendsReturnedOrdersFound[i].DividendStatus = 2
  885 + } else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsReturnedOrderFound.Goods) { // 3部分分红
  886 + dividendsReturnedOrdersFound[i].DividendStatus = 3
  887 + } else if dividendsGoodCount == 0 { // 1未分红
  888 + dividendsReturnedOrdersFound[i].DividendStatus = 1
876 } 889 }
877 } 890 }
878 - if dividendsGoodCount == len(dividendsReturnedOrderFound.Goods) { // 2已分红  
879 - dividendsReturnedOrdersFound[i].DividendStatus = 2  
880 - } else if dividendsGoodCount > 0 && dividendsGoodCount < len(dividendsReturnedOrderFound.Goods) { // 3部分分红  
881 - dividendsReturnedOrdersFound[i].DividendStatus = 3  
882 - } else if dividendsGoodCount == 0 { // 1未分红  
883 - dividendsReturnedOrdersFound[i].DividendStatus = 1 891 + // 保存退货单状态
  892 + if _, err6 := dividendsReturnedOrderRepository.UpdateMany(dividendsReturnedOrdersFound); err6 != nil {
  893 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
884 } 894 }
885 } 895 }
886 - // 保存退货单状态  
887 - if _, err6 := dividendsReturnedOrderRepository.UpdateMany(dividendsReturnedOrdersFound); err6 != nil {  
888 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
889 - }  
890 } 896 }
891 } 897 }
892 898
@@ -63,7 +63,8 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -63,7 +63,8 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
63 if undertakerEstimated { 63 if undertakerEstimated {
64 return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红") 64 return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
65 } else { 65 } else {
66 - undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64() 66 + undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).
  67 + Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage)).Div(decimal.NewFromFloat(100)))).Float64()
67 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 68 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
68 DividendsUser: &domain.User{ 69 DividendsUser: &domain.User{
69 UserId: undertaker.UserId, 70 UserId: undertaker.UserId,