作者 陈志颖

fix:分红订单删除校验

@@ -1096,6 +1096,16 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1096,6 +1096,16 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1096 dividendsReturnedOrderRepository = value 1096 dividendsReturnedOrderRepository = value
1097 } 1097 }
1098 1098
  1099 + // 分红预算单仓储初始化
  1100 + var dividendsEstimateRepository domain.DividendsEstimateRepository
  1101 + if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
  1102 + "transactionContext": transactionContext,
  1103 + }); err != nil {
  1104 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1105 + } else {
  1106 + dividendsEstimateRepository = value
  1107 + }
  1108 +
1099 dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds) 1109 dividendsOrderIds, err := utils.SliceAtoi(batchRemoveDividendsOrderCommand.DividendsOrderIds)
1100 if err != nil { 1110 if err != nil {
1101 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误") 1111 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单ID类型错误")
@@ -1120,9 +1130,22 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba @@ -1120,9 +1130,22 @@ func (dividendsOrderService *DividendsOrderService) BatchRemoveDividendsOrder(ba
1120 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber)) 1130 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的退货单,不可删除", dividendsOrder.DividendsOrderNumber))
1121 } 1131 }
1122 } 1132 }
1123 - }  
1124 1133
1125 - // TODO 校验分红订单是否有分红预算 1134 + // 校验分红订单是否有分红预算
  1135 + if countRelative, _, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
  1136 + "companyId": dividendsOrder.Company.CompanyId,
  1137 + "orgId": dividendsOrder.Org.OrgId,
  1138 + "orderOrReturnedOrderNum": dividendsOrder.DividendsOrderNumber,
  1139 + "offsetLimit": false,
  1140 + "isCanceled": false,
  1141 + }); err2 != nil {
  1142 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
  1143 + } else {
  1144 + if countRelative > 0 {
  1145 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("分红订单%s有关联的预算单,不可删除", dividendsOrder.DividendsOrderNumber))
  1146 + }
  1147 + }
  1148 + }
1126 1149
1127 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders) 1150 dividendsOrdersRemoved, err := dividendsOrderRepository.BatchRemove(dividendsOrders)
1128 if err != nil { 1151 if err != nil {
@@ -42,7 +42,7 @@ type DividendsEstimate struct { @@ -42,7 +42,7 @@ type DividendsEstimate struct {
42 // 操作时间 42 // 操作时间
43 OperateTime time.Time `comment:"操作时间"` 43 OperateTime time.Time `comment:"操作时间"`
44 // 取消状态 44 // 取消状态
45 - IsCanceled bool `comment:"取消状态"` 45 + IsCanceled bool `comment:"取消状态" pg:",use_zero,default:false"`
46 // 产品ID 46 // 产品ID
47 OrderGoodId int64 `comment:"产品ID"` 47 OrderGoodId int64 `comment:"产品ID"`
48 // 创建时间 48 // 创建时间
@@ -346,6 +346,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -346,6 +346,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
346 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 346 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
347 query.Where("company->>'companyId' = '?'", companyId) 347 query.Where("company->>'companyId' = '?'", companyId)
348 } 348 }
  349 + if isCanceled, ok := queryOptions["isCanceled"]; ok {
  350 + query.Where("is_canceled = ?", isCanceled.(bool))
  351 + }
349 if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 { 352 if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
350 query.Where("org->>'orgId' = '?'", orgId) 353 query.Where("org->>'orgId' = '?'", orgId)
351 } 354 }
@@ -535,6 +535,9 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string @@ -535,6 +535,9 @@ func (repository *DividendsReturnedOrderRepository) Find(queryOptions map[string
535 if dividendsReturnedOrderIds, ok := queryOptions["dividendsReturnedOrderIds"]; ok && len(dividendsReturnedOrderIds.([]int64)) > 0 { 535 if dividendsReturnedOrderIds, ok := queryOptions["dividendsReturnedOrderIds"]; ok && len(dividendsReturnedOrderIds.([]int64)) > 0 {
536 query.Where("dividends_returned_order_id IN (?)", pg.In(dividendsReturnedOrderIds.([]int64))) 536 query.Where("dividends_returned_order_id IN (?)", pg.In(dividendsReturnedOrderIds.([]int64)))
537 } 537 }
  538 + if dividendsOrderNumber, ok := queryOptions["dividendsOrderNumber"]; ok && dividendsOrderNumber != "" {
  539 + query.Where("dividends_order_number = ?", dividendsOrderNumber)
  540 + }
538 if dividendsReturnedOrderNumber, ok := queryOptions["dividendsReturnedOrderNumber"]; ok && dividendsReturnedOrderNumber != "" { 541 if dividendsReturnedOrderNumber, ok := queryOptions["dividendsReturnedOrderNumber"]; ok && dividendsReturnedOrderNumber != "" {
539 query.Where("dividends_returned_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsReturnedOrderNumber)) 542 query.Where("dividends_returned_order_number ilike ?", fmt.Sprintf("%%%s%%", dividendsReturnedOrderNumber))
540 } 543 }