...
|
...
|
@@ -168,11 +168,25 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide |
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
|
|
|
|
|
|
// 校验合约激励类型是否正确
|
|
|
ruleMatchedFlag := false
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
|
|
|
}
|
|
|
// 校验产品关联合约的激励规则是否匹配订单时间
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
|
|
|
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
|
|
|
if (orderTime.After(incentivesRule.DividendsIncentivesStageStart) || orderTime.Equal(incentivesRule.DividendsIncentivesStageStart)) && (orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) || orderTime.Equal(incentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
ruleMatchedFlag = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !ruleMatchedFlag {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
OrderGoodId: 0,
|
|
|
OrderGoodAmount: orderGoodAmount,
|
...
|
...
|
@@ -190,7 +204,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide |
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
})
|
|
|
dividendsReturnedOrderRefund, _ = decimal.NewFromFloat(dividendsReturnedOrderRefund).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity)))).Float64()
|
|
|
// 计算退货订单金额
|
|
|
dividendsReturnedOrderRefund, _ = decimal.NewFromFloat(dividendsReturnedOrderRefund).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity))).Float64()
|
|
|
}
|
|
|
|
|
|
newDividendsReturnedOrder := &domain.DividendsReturnedOrder{
|
...
|
...
|
@@ -1105,6 +1120,32 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsReturnedOrderCommand.DividendsReturnedOrderId)))
|
|
|
}
|
|
|
|
|
|
// 合约仓储初始化
|
|
|
var cooperationContractRepository domain.CooperationContractRepository
|
|
|
if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationContractRepository = value
|
|
|
}
|
|
|
|
|
|
// 查找合约
|
|
|
cooperationContractsMap := make(map[string]*domain.CooperationContract)
|
|
|
if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
|
|
|
"offsetLimit": false,
|
|
|
"companyId": updateDividendsReturnedOrderCommand.CompanyId,
|
|
|
"orgId": updateDividendsReturnedOrderCommand.OrgId,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
if count > 0 {
|
|
|
for _, cooperationContract := range cooperationContracts {
|
|
|
cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取订单产品
|
|
|
var orderGoods []*domain.OrderGood
|
|
|
var dividendsReturnedOrderAmount float64
|
...
|
...
|
@@ -1114,9 +1155,33 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide |
|
|
if err3 != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
|
|
|
}
|
|
|
|
|
|
// 退货产品金额计算
|
|
|
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
|
|
|
|
|
|
// 校验合约激励类型是否正确
|
|
|
ruleMatchedFlag := false
|
|
|
if orderGood.CooperationContractNumber != "" {
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
|
|
|
}
|
|
|
// 校验产品关联合约的激励规则是否匹配订单时间
|
|
|
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
|
|
|
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
|
|
|
if (orderTime.After(incentivesRule.DividendsIncentivesStageStart) || orderTime.Equal(incentivesRule.DividendsIncentivesStageStart)) && (orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) || orderTime.Equal(incentivesRule.DividendsIncentivesStageEnd)) {
|
|
|
ruleMatchedFlag = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if !ruleMatchedFlag {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
orderGoods = append(orderGoods, &domain.OrderGood{
|
|
|
OrderGoodId: orderGoodId,
|
|
|
OrderGoodAmount: orderGood.OrderGoodAmount,
|
|
|
OrderGoodAmount: orderGoodAmount,
|
|
|
OrderGoodName: orderGood.OrderGoodName,
|
|
|
OrderGoodPrice: orderGood.OrderGoodPrice,
|
|
|
OrderGoodQuantity: orderGood.OrderGoodQuantity,
|
...
|
...
|
@@ -1130,7 +1195,7 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide |
|
|
UpdatedAt: time.Now(),
|
|
|
})
|
|
|
// 计算分红退货单金额
|
|
|
dividendsReturnedOrderAmount = dividendsReturnedOrderAmount + orderGood.OrderGoodAmount
|
|
|
dividendsReturnedOrderAmount, _ = decimal.NewFromFloat(dividendsReturnedOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodAmount)).Float64()
|
|
|
}
|
|
|
|
|
|
if err := dividendsReturnedOrder.Update(tool_funs.SimpleStructToMap(updateDividendsReturnedOrderCommand)); err != nil {
|
...
|
...
|
|