作者 陈志颖

fix:修复分红预算失败后继续更新产品分红状态问题

@@ -626,17 +626,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -626,17 +626,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
626 for _, orderGood := range orderGoods { 626 for _, orderGood := range orderGoods {
627 dividendsEstimate := &domain.DividendsEstimate{} 627 dividendsEstimate := &domain.DividendsEstimate{}
628 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 628 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
629 - //dividendsOrder, err3 := dividendsOrderRepository.FindOne(map[string]interface{}{  
630 - // "dividendsOrderNumber": orderGood.DividendsOrderNumber,  
631 - // "companyId": orderGood.CompanyId,  
632 - // "orgId": orderGood.OrgId,  
633 - //})  
634 - //if err3 != nil {  
635 - // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在")  
636 - //}  
637 - //if dividendsOrder == nil {  
638 - // return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))  
639 - //}  
640 // 分红订单产品预算 629 // 分红订单产品预算
641 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { 630 if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
642 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 631 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -753,21 +742,24 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -753,21 +742,24 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
753 } 742 }
754 743
755 // 获取订单产品 744 // 获取订单产品
756 - if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{  
757 - "orderGoodIds": orderGoodSavedIds,  
758 - }); err != nil {  
759 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
760 - } else {  
761 - if countOrderGood > 0 {  
762 - for i, _ := range orderGoodsFound {  
763 - orderGoodsFound[i].OrderGoodDividendsStatus = int32(2) // 已分红  
764 - }  
765 - if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {  
766 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error()) 745 + if len(orderGoodSavedIds) > 0 {
  746 + if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
  747 + "orderGoodIds": orderGoodSavedIds,
  748 + }); err != nil {
  749 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  750 + } else {
  751 + if countOrderGood > 0 {
  752 + for i, _ := range orderGoodsFound {
  753 + orderGoodsFound[i].OrderGoodDividendsStatus = int32(2) // 已分红
  754 + }
  755 + if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
  756 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
  757 + }
767 } 758 }
768 } 759 }
769 } 760 }
770 761
  762 + // 完成第一阶段事务提交
771 if err := transactionContext.CommitTransaction(); err != nil { 763 if err := transactionContext.CommitTransaction(); err != nil {
772 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 764 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
773 } 765 }
@@ -788,7 +780,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -788,7 +780,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
788 failedReasonStr = "无" 780 failedReasonStr = "无"
789 } 781 }
790 782
791 - // 开启薪事务 783 + // 开启第二阶段事务:处理订单和产品状态
792 newTransactionContext, err := factory.CreateTransactionContext(nil) 784 newTransactionContext, err := factory.CreateTransactionContext(nil)
793 if err != nil { 785 if err != nil {
794 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 786 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -893,6 +885,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -893,6 +885,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
893 } 885 }
894 } 886 }
895 887
  888 + // 完成第二阶段事务提交
896 if err := newTransactionContext.CommitTransaction(); err != nil { 889 if err := newTransactionContext.CommitTransaction(); err != nil {
897 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 890 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
898 } 891 }