...
|
...
|
@@ -177,6 +177,17 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 取消分红预算领域服务初始化
|
|
|
var cancelDividendsEstimateService service.CancelDividendsEstimate
|
|
|
if value, err := factory.CreateCancelDividendsEstimateService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cancelDividendsEstimateService = value
|
|
|
}
|
|
|
|
|
|
// 分红预算仓储初始化
|
|
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
...
|
...
|
@@ -186,6 +197,8 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
|
|
|
// 获取当前被取消的分红预算单
|
|
|
dividendsEstimate, err := dividendsEstimateRepository.FindOne(map[string]interface{}{"dividendsEstimateId": cancelDividendsEstimateCommand.DividendsEstimateId})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
...
|
...
|
@@ -193,20 +206,42 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat |
|
|
if dividendsEstimate == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cancelDividendsEstimateCommand.DividendsEstimateId, 10)))
|
|
|
}
|
|
|
// TODO 校验是否能够取消
|
|
|
|
|
|
// 设置取消状态
|
|
|
cancelDividendsEstimateCommand.IsCanceled = true
|
|
|
if err := dividendsEstimate.Update(tool_funs.SimpleStructToMap(cancelDividendsEstimateCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
// 校验是否能够取消
|
|
|
if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红、退货冲销
|
|
|
if count, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum}); err2 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
|
|
}
|
|
|
if dividendsEstimate, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
|
|
|
if count, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumber": dividendsEstimate.CooperationContractNumber}); err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 取消分红预算
|
|
|
if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate([]int64{cancelDividendsEstimateCommand.DividendsEstimateId}, cancelDividendsEstimateCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsEstimate, nil
|
|
|
return dividendsEstimatesCanceled[1], nil
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -225,6 +260,17 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
// 取消分红预算领域服务初始化
|
|
|
var cancelDividendsEstimateService service.CancelDividendsEstimate
|
|
|
if value, err := factory.CreateCancelDividendsEstimateService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cancelDividendsEstimateService = value
|
|
|
}
|
|
|
|
|
|
// 分红预算仓储初始化
|
|
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
...
|
...
|
@@ -234,24 +280,58 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs |
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
dividendsEstimateIds, _ := utils.SliceAtoi(batchCancelEstimateCommand.DividendsEstimateIds)
|
|
|
|
|
|
// 分红预算ID类型转换
|
|
|
dividendsEstimateIds, err := utils.SliceAtoi(batchCancelEstimateCommand.DividendsEstimateIds)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红预算单参数转换错误")
|
|
|
}
|
|
|
|
|
|
// 获取分红预算
|
|
|
if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
|
|
|
"dividendsEstimateIds": dividendsEstimateIds,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for i, _ := range dividendsEstimates {
|
|
|
dividendsEstimates[i].IsCanceled = true
|
|
|
// 校验分红预算是否可以取消,已有相关分红预算单已结算,无法取消
|
|
|
for _, dividendsEstimate := range dividendsEstimates {
|
|
|
// 校验是否能够取消
|
|
|
if dividendsEstimate.DividendsType == domain.ORDER_DIVIDENDS || dividendsEstimate.DividendsType == domain.RETURN_WRITE_OFF { // 订单分红、退货冲销
|
|
|
if count, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{"orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum}); err2 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
|
|
}
|
|
|
dividendsEstimatesCanceled, err := dividendsEstimateRepository.UpdateMany(dividendsEstimates)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if dividendsEstimate.DividendsType == domain.MONEY_INCENTIVES { // 金额激励分红
|
|
|
if count, dividendsEstimatesRelative, err3 := dividendsEstimateRepository.Find(map[string]interface{}{"cooperationContractNumber": dividendsEstimate.CooperationContractNumber}); err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, dividendsEstimateRelative := range dividendsEstimatesRelative {
|
|
|
if dividendsEstimateRelative.DividendsAccountStatus == domain.ACCOUNTED {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "已有相关分红预算单已结算,无法取消")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 批量取消分红预算单
|
|
|
if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, batchCancelEstimateCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return dividendsEstimatesCanceled, nil
|
|
|
}
|
|
|
} else {
|
|
|
return map[string]interface{}{}, nil
|
|
|
}
|
...
|
...
|
|