作者 陈志颖

fix:删除分红退货单

@@ -449,14 +449,31 @@ func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.Divide @@ -449,14 +449,31 @@ func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.Divide
449 return dividendsOrder, err 449 return dividendsOrder, err
450 } else { 450 } else {
451 // 删除订单产品 451 // 删除订单产品
  452 + //var orderGoodModels []*models.OrderGood
  453 + //if _, err := tx.Model(&orderGoodModels).
  454 + // Where("company_id = ?", dividendsOrderModel.Company.CompanyId).
  455 + // Where("org_id = ?", dividendsOrderModel.Org.OrgId).
  456 + // Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil {
  457 + // return nil, err
  458 + //}
  459 +
  460 + // 删除订单产品
452 var orderGoodModels []*models.OrderGood 461 var orderGoodModels []*models.OrderGood
453 - if _, err := tx.Model(&orderGoodModels).  
454 - Where("company_id = ?", dividendsOrderModel.Company.CompanyId).  
455 - Where("org_id = ?", dividendsOrderModel.Org.OrgId).  
456 - Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).Delete(); err != nil { 462 + orderGoodQuery := tx.Model(&orderGoodModels)
  463 + if err := orderGoodQuery.
  464 + Where("company_id = ?", dividendsOrder.Company.CompanyId).
  465 + Where("org_id = ?", dividendsOrder.Org.OrgId).
  466 + Where("dividends_order_number = ?", dividendsOrder.DividendsOrderNumber).
  467 + Select(); err != nil {
  468 + return nil, err
  469 + } else {
  470 + if len(orderGoodModels) > 0 {
  471 + if _, err := tx.Model(&orderGoodModels).WherePK().Delete(); err != nil {
457 return nil, err 472 return nil, err
458 } 473 }
459 } 474 }
  475 + }
  476 + }
460 return dividendsOrder, nil 477 return dividendsOrder, nil
461 } 478 }
462 479
@@ -488,16 +488,33 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne @@ -488,16 +488,33 @@ func (repository *DividendsReturnedOrderRepository) BatchRemove(dividendsReturne
488 } else { 488 } else {
489 for _, dividendsReturnedOrder := range dividendsReturnedOrders { 489 for _, dividendsReturnedOrder := range dividendsReturnedOrders {
490 // 删除退货单产品 490 // 删除退货单产品
  491 + //var orderGoodModels []*models.OrderGood
  492 + //if _, err := tx.Model(&orderGoodModels).
  493 + // Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
  494 + // Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
  495 + // Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).
  496 + // Delete(); err != nil {
  497 + // return nil, err
  498 + //}
  499 +
  500 + // 删除分红退货单产品
491 var orderGoodModels []*models.OrderGood 501 var orderGoodModels []*models.OrderGood
492 - if _, err := tx.Model(&orderGoodModels). 502 + orderGoodQuery := tx.Model(&orderGoodModels)
  503 + if err := orderGoodQuery.
493 Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId). 504 Where("company_id = ?", dividendsReturnedOrder.Company.CompanyId).
494 Where("org_id = ?", dividendsReturnedOrder.Org.OrgId). 505 Where("org_id = ?", dividendsReturnedOrder.Org.OrgId).
495 Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber). 506 Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).
496 - Delete(); err != nil { 507 + Select(); err != nil {
  508 + return nil, err
  509 + } else {
  510 + if len(orderGoodModels) > 0 {
  511 + if _, err := tx.Model(&orderGoodModels).WherePK().Delete(); err != nil {
497 return nil, err 512 return nil, err
498 } 513 }
499 } 514 }
500 } 515 }
  516 + }
  517 + }
501 return dividendsReturnedOrders, nil 518 return dividendsReturnedOrders, nil
502 } 519 }
503 520