...
|
...
|
@@ -3,10 +3,12 @@ package service |
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
|
|
|
"github.com/linmadan/egglib-go/utils/tool_funs"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/command"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/dto"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/dividendsEstimate/query"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/event/subscriber"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
...
|
...
|
@@ -368,10 +370,151 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// 分红订单仓储初始化
|
|
|
var dividendsOrderRepository domain.DividendsOrderRepository
|
|
|
if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
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
|
|
|
}
|
|
|
|
|
|
// 订单产品仓储初始化
|
|
|
var orderGoodRepository domain.OrderGoodRepository
|
|
|
if value, err := factory.CreateOrderGoodRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
orderGoodRepository = value
|
|
|
}
|
|
|
|
|
|
// 分红预算仓储初始化
|
|
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimateRepository = value
|
|
|
}
|
|
|
|
|
|
// 初始化确认业绩激励分红预算领域服务
|
|
|
var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService
|
|
|
if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
confirmDividendsIncentivesEstimateService = value
|
|
|
_ = confirmDividendsIncentivesEstimateService.Subscribe(&subscriber.DividendsEstimateSubscriber{
|
|
|
TransactionContext: transactionContext.(*pgTransaction.TransactionContext),
|
|
|
})
|
|
|
}
|
|
|
|
|
|
// 获取订单产品
|
|
|
if _, orderGoods, err := orderGoodRepository.Find(tool_funs.SimpleStructToMap(confirmDividendsIncentivesEstimateCommand)); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
var dividendsEstimates []*domain.DividendsEstimate
|
|
|
for _, orderGood := range orderGoods {
|
|
|
dividendsEstimate := &domain.DividendsEstimate{}
|
|
|
if orderGood.DividendsOrderNumber != "" { // 查询分红订单
|
|
|
dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderNumber": orderGood.DividendsOrderNumber})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsOrder == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber))
|
|
|
}
|
|
|
// 分红订单产品预算
|
|
|
if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: 0,
|
|
|
DividendsAmount: dividendsAmount,
|
|
|
DividendsEstimateOrderNumber: "",
|
|
|
DividendsEstimateTime: time.Time{},
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsType: 0,
|
|
|
OrderOrReturnedOrderNum: "",
|
|
|
CooperationContractNumber: "",
|
|
|
DividendsUser: nil,
|
|
|
DividendsStage: 0,
|
|
|
Org: nil,
|
|
|
Company: nil,
|
|
|
Operator: nil,
|
|
|
OperateTime: time.Time{},
|
|
|
IsCanceled: false,
|
|
|
CreatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
}
|
|
|
} else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单
|
|
|
dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber})
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
}
|
|
|
if dividendsReturnedOrder == nil {
|
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber))
|
|
|
}
|
|
|
// 分红退货单产品预算
|
|
|
if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimate = &domain.DividendsEstimate{
|
|
|
DividendsEstimateId: 0,
|
|
|
DividendsAccountStatus: 0,
|
|
|
DividendsAmount: dividendsAmount,
|
|
|
DividendsEstimateOrderNumber: "",
|
|
|
DividendsEstimateTime: time.Time{},
|
|
|
DividendsParticipateType: 0,
|
|
|
DividendsType: 0,
|
|
|
OrderOrReturnedOrderNum: "",
|
|
|
CooperationContractNumber: "",
|
|
|
DividendsUser: nil,
|
|
|
DividendsStage: 0,
|
|
|
Org: nil,
|
|
|
Company: nil,
|
|
|
Operator: nil,
|
|
|
OperateTime: time.Time{},
|
|
|
IsCanceled: false,
|
|
|
CreatedAt: time.Time{},
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
|
|
|
}
|
|
|
var dividendsEstimatesSaved []*domain.DividendsEstimate
|
|
|
for _, dividendsEstimate := range dividendsEstimates {
|
|
|
if dividendsEstimateSaved, err := dividendsEstimateRepository.Save(dividendsEstimate); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
dividendsEstimatesSaved = append(dividendsEstimatesSaved, dividendsEstimateSaved)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return nil, nil
|
|
|
return dividendsEstimatesSaved, nil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// ConfirmMoneyIncentivesEstimate TODO 确定金额激励分红预算
|
...
|
...
|
@@ -410,6 +553,7 @@ func (dividendsEstimateService *DividendsEstimateService) GetDividendsEstimate(g |
|
|
defer func() {
|
|
|
_ = transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// 分红预算单仓储初始化
|
|
|
var dividendsEstimateRepository domain.DividendsEstimateRepository
|
|
|
if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
...
|
...
|
|