作者 陈志颖

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

... ... @@ -809,10 +809,12 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
dividendsReturnedOrderNumbers := make([]string, 0)
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)
if k != "" {
if k[:2] == "RE" { // 分红退货单
dividendsReturnedOrderNumbers = append(dividendsReturnedOrderNumbers, k)
} else if k[:2] == "SL" { // 分红订单
dividendsOrderNumbers = append(dividendsOrderNumbers, k)
}
}
}
}
... ...
... ... @@ -1001,6 +1001,8 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 分红订单仓储初始化
var dividendsOrderRepository domain.DividendsOrderRepository
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -1010,6 +1012,16 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
dividendsOrderRepository = value
}
// 分红退货单仓储初始化
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
dividendsReturnedOrderRepository = value
}
dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误")
... ... @@ -1020,6 +1032,22 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
// 校验分红订单是否有退货单关联
for _, dividendsOrder := range dividendsOrders {
if countReturnedOrder, dividendsReturnedOrders, err := dividendsReturnedOrderRepository.Find(map[string]interface{}{
"dividendsOrderNumber": dividendsOrder.DividendsOrderNumber,
"companyId": dividendsOrder.Company.CompanyId,
"limit": 1,
"offset": 0,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if countReturnedOrder > 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsReturnedOrders[0].DividendsOrderNumber))
}
}
}
dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -1007,6 +1007,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) BatchRemoveD
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 分红退货单仓储初始化
var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository
if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ...