...
|
...
|
@@ -60,26 +60,52 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
|
var dividendsEstimatesCanceled []*domain.DividendsEstimate
|
|
|
var orderOrReturnOrderNums []string
|
|
|
for _, dividendsEstimate := range dividendsEstimates {
|
|
|
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
|
|
|
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
"companyId": dividendsEstimate.Company.CompanyId,
|
|
|
"orgId": dividendsEstimate.Org.OrgId,
|
|
|
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
|
|
|
}); err2 != nil {
|
|
|
return nil, err2
|
|
|
} else {
|
|
|
if countRelative > 0 {
|
|
|
for i, _ := range dividendsEstimatesRelative {
|
|
|
dividendsEstimatesRelative[i].IsCanceled = true
|
|
|
dividendsEstimatesRelative[i].Operator = operator
|
|
|
// 获取相关订单/退货单号
|
|
|
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
|
|
|
if dividendsEstimate.DividendsType != 3 { // 非金额激励分红预算单处理
|
|
|
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
|
|
|
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
"companyId": dividendsEstimate.Company.CompanyId,
|
|
|
"orgId": dividendsEstimate.Org.OrgId,
|
|
|
"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
|
|
|
"offsetLimit": false,
|
|
|
}); err2 != nil {
|
|
|
return nil, err2
|
|
|
} else {
|
|
|
if countRelative > 0 {
|
|
|
for i, _ := range dividendsEstimatesRelative {
|
|
|
dividendsEstimatesRelative[i].IsCanceled = true
|
|
|
dividendsEstimatesRelative[i].Operator = operator
|
|
|
// 获取相关订单/退货单号
|
|
|
orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
|
|
|
}
|
|
|
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
|
|
|
if err3 != nil {
|
|
|
return nil, err3
|
|
|
}
|
|
|
dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
|
|
|
}
|
|
|
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
|
|
|
if err3 != nil {
|
|
|
return nil, err3
|
|
|
}
|
|
|
} else if dividendsEstimate.DividendsType == 3 {
|
|
|
// 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
|
|
|
if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
"companyId": dividendsEstimate.Company.CompanyId,
|
|
|
"orgId": dividendsEstimate.Org.OrgId,
|
|
|
"cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
|
|
|
"dividendsType": int32(3),
|
|
|
"offsetLimit": false,
|
|
|
}); err2 != nil {
|
|
|
return nil, err2
|
|
|
} else {
|
|
|
if countRelative > 0 {
|
|
|
for i, _ := range dividendsEstimatesRelative {
|
|
|
dividendsEstimatesRelative[i].IsCanceled = true
|
|
|
dividendsEstimatesRelative[i].Operator = operator
|
|
|
}
|
|
|
dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
|
|
|
if err3 != nil {
|
|
|
return nil, err3
|
|
|
}
|
|
|
dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
|
|
|
}
|
|
|
dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -88,98 +114,107 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst |
|
|
var orderNums []string
|
|
|
var returnedOrderNums []string
|
|
|
|
|
|
// 订单/退货单号数组去重
|
|
|
orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
|
|
|
for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {
|
|
|
if orderNullNum[:2] == "RE" { // 分红退后单
|
|
|
returnedOrderNums = append(returnedOrderNums, orderNullNum)
|
|
|
} else if orderNullNum[:2] == "SL" { // 分红订单
|
|
|
orderNums = append(orderNums, orderNullNum)
|
|
|
if len(orderOrReturnOrderNums) > 0 {
|
|
|
// 订单/退货单号数组去重
|
|
|
orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
|
|
|
for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {
|
|
|
if orderNullNum[:2] == "RE" { // 分红退后单
|
|
|
returnedOrderNums = append(returnedOrderNums, orderNullNum)
|
|
|
} else if orderNullNum[:2] == "SL" { // 分红订单
|
|
|
orderNums = append(orderNums, orderNullNum)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取分红订单
|
|
|
if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
"dividendsOrderNumbers": orderNums,
|
|
|
}); err4 != nil {
|
|
|
return nil, err4
|
|
|
} else {
|
|
|
if countDividendsOrder > 0 {
|
|
|
for i, _ := range orders {
|
|
|
orders[i].DividendStatus = 1
|
|
|
}
|
|
|
// 保存订单状态
|
|
|
if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
|
|
|
return nil, err6
|
|
|
}
|
|
|
// 获取订单编号
|
|
|
ordersNumbers := make([]string, 0)
|
|
|
for _, order := range orders {
|
|
|
ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)
|
|
|
}
|
|
|
// 获取分红订单产品并更新产品状态
|
|
|
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
"orderNumbers": ordersNumbers,
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// 获取分红订单并更新分红订单产品的状态
|
|
|
if len(orderNums) > 0 {
|
|
|
if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
"dividendsOrderNumbers": orderNums,
|
|
|
}); err4 != nil {
|
|
|
return nil, err4
|
|
|
} else {
|
|
|
if countOrderGood > 0 {
|
|
|
for i, _ := range orderGoodsFound {
|
|
|
orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
|
|
if countDividendsOrder > 0 {
|
|
|
for i, _ := range orders {
|
|
|
orders[i].DividendStatus = 1
|
|
|
}
|
|
|
// 保存订单状态
|
|
|
if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
|
|
|
return nil, err6
|
|
|
}
|
|
|
// 获取订单编号
|
|
|
ordersNumbers := make([]string, 0)
|
|
|
for _, order := range orders {
|
|
|
ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)
|
|
|
}
|
|
|
if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
// 获取分红订单产品并更新产品状态
|
|
|
if len(ordersNumbers) > 0 {
|
|
|
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
"orderNumbers": ordersNumbers,
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if countOrderGood > 0 {
|
|
|
for i, _ := range orderGoodsFound {
|
|
|
orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
|
|
}
|
|
|
if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取分红退货单
|
|
|
if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
"dividendsReturnedOrderNumbers": returnedOrderNums,
|
|
|
}); err5 != nil {
|
|
|
return nil, err5
|
|
|
} else {
|
|
|
if countDividendsReturnedOrder > 0 {
|
|
|
for i, _ := range returnedOrders {
|
|
|
returnedOrders[i].DividendStatus = 1
|
|
|
}
|
|
|
// 保存退货单状态
|
|
|
if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
|
|
|
return nil, err7
|
|
|
}
|
|
|
// 获取订单编号
|
|
|
returnedOrdersNumbers := make([]string, 0)
|
|
|
for _, returnedOrder := range returnedOrders {
|
|
|
returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)
|
|
|
}
|
|
|
// 获取退货单产品并更新产品状态
|
|
|
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
"returnedOrderNumbers": returnedOrdersNumbers,
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
// 获取分红退货单并更新订单产品的状态
|
|
|
if len(returnedOrderNums) > 0 {
|
|
|
if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
"dividendsReturnedOrderNumbers": returnedOrderNums,
|
|
|
}); err5 != nil {
|
|
|
return nil, err5
|
|
|
} else {
|
|
|
if countOrderGood > 0 {
|
|
|
for i, _ := range orderGoodsFound {
|
|
|
orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
|
|
if countDividendsReturnedOrder > 0 {
|
|
|
for i, _ := range returnedOrders {
|
|
|
returnedOrders[i].DividendStatus = 1
|
|
|
}
|
|
|
// 保存退货单状态
|
|
|
if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
|
|
|
return nil, err7
|
|
|
}
|
|
|
if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
// 获取订单编号
|
|
|
returnedOrdersNumbers := make([]string, 0)
|
|
|
for _, returnedOrder := range returnedOrders {
|
|
|
returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)
|
|
|
}
|
|
|
// 获取退货单产品并更新产品状态
|
|
|
if len(returnedOrdersNumbers) > 0 {
|
|
|
if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
|
|
|
"returnedOrderNumbers": returnedOrdersNumbers,
|
|
|
"companyId": dividendsEstimates[0].Company.CompanyId,
|
|
|
"orgId": dividendsEstimates[0].Org.OrgId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if countOrderGood > 0 {
|
|
|
for i, _ := range orderGoodsFound {
|
|
|
orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
|
|
|
}
|
|
|
if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return dividendsEstimatesCanceled, nil
|
|
|
}
|
|
|
}
|
...
|
...
|
|