作者 陈志颖

fix:增加删除订单时的校验

@@ -809,10 +809,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -809,10 +809,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
809 dividendsReturnedOrderNumbers := make([]string, 0) 809 dividendsReturnedOrderNumbers := make([]string, 0)
810 if len(estimateSuccessfullyDividendsOrders) > 0 { 810 if len(estimateSuccessfullyDividendsOrders) > 0 {
811 for k, _ := range estimateSuccessfullyDividendsOrders { 811 for k, _ := range estimateSuccessfullyDividendsOrders {
812 - if k[:2] == "RE" { // 分红退货单  
813 - dividendsReturnedOrderNumbers = append(dividendsReturnedOrderNumbers, k)  
814 - } else if k[:2] == "SL" { // 分红订单  
815 - dividendsOrderNumbers = append(dividendsOrderNumbers, k) 812 + if k != "" {
  813 + if k[:2] == "RE" { // 分红退货单
  814 + dividendsReturnedOrderNumbers = append(dividendsReturnedOrderNumbers, k)
  815 + } else if k[:2] == "SL" { // 分红订单
  816 + dividendsOrderNumbers = append(dividendsOrderNumbers, k)
  817 + }
816 } 818 }
817 } 819 }
818 } 820 }
@@ -1001,6 +1001,8 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1001,6 +1001,8 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1001 defer func() { 1001 defer func() {
1002 _ = transactionContext.RollbackTransaction() 1002 _ = transactionContext.RollbackTransaction()
1003 }() 1003 }()
  1004 +
  1005 + // 分红订单仓储初始化
1004 var dividendsOrderRepository domain.DividendsOrderRepository 1006 var dividendsOrderRepository domain.DividendsOrderRepository
1005 if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{ 1007 if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
1006 "transactionContext": transactionContext, 1008 "transactionContext": transactionContext,
@@ -1010,6 +1012,16 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1010,6 +1012,16 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1010 dividendsOrderRepository = value 1012 dividendsOrderRepository = value
1011 } 1013 }
1012 1014
  1015 + // 分红退货单仓储初始化
  1016 + var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
  1017 + if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
  1018 + "transactionContext": transactionContext,
  1019 + }); err != nil {
  1020 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1021 + } else {
  1022 + dividendsReturnedOrderRepository = value
  1023 + }
  1024 +
1013 dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds) 1025 dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
1014 if err != nil { 1026 if err != nil {
1015 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误") 1027 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误")
@@ -1020,6 +1032,22 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1020,6 +1032,22 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1020 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1032 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1021 } else { 1033 } else {
1022 if count > 0 { 1034 if count > 0 {
  1035 + // 校验分红订单是否有退货单关联
  1036 + for _, dividendsOrder := range dividendsOrders {
  1037 + if countReturnedOrder, dividendsReturnedOrders, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
  1038 + "dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
  1039 + "companyId": dividendsOrder.Company.CompanyId,
  1040 + "limit": 1,
  1041 + "offset": 0,
  1042 + }); err != nil {
  1043 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1044 + } else {
  1045 + if countReturnedOrder > 0 {
  1046 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsReturnedOrders[0].DividendsOrderNumber))
  1047 + }
  1048 + }
  1049 + }
  1050 +
1023 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders) 1051 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
1024 if err != nil { 1052 if err != nil {
1025 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 1053 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -1007,6 +1007,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) BatchRemoveD @@ -1007,6 +1007,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) BatchRemoveD
1007 defer func() { 1007 defer func() {
1008 _ = transactionContext.RollbackTransaction() 1008 _ = transactionContext.RollbackTransaction()
1009 }() 1009 }()
  1010 +
  1011 + // 分红退货单仓储初始化
1010 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository 1012 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
1011 if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{ 1013 if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
1012 "transactionContext": transactionContext, 1014 "transactionContext": transactionContext,