作者 陈志颖

refactor:编辑分红订单增加校验

... ... @@ -26,7 +26,6 @@ type ApplyForCooperationCommand struct {
}
func (applyForCooperationCommand *ApplyForCooperationCommand) Valid(validation *validation.Validation) {
//validation.SetError("CustomValid", "未实现的自定义认证")
}
func (applyForCooperationCommand *ApplyForCooperationCommand) ValidateCommand() error {
... ...
... ... @@ -168,7 +168,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
// 校验产品关联合约的激励规则是否匹配订单时间
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
if orderTime.After(incentivesRule.DividendsIncentivesStageStart) && orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) {
if (orderTime.After(incentivesRule.DividendsIncentivesStageStart) || orderTime.Equal(incentivesRule.DividendsIncentivesStageStart)) && (orderTime.Before(incentivesRule.DividendsIncentivesStageEnd) || orderTime.Equal(incentivesRule.DividendsIncentivesStageEnd)) {
ruleMatchedFlag = true
break
}
... ... @@ -1156,20 +1156,68 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId)))
}
// 合约仓储初始化
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": updateDividendsOrderCommand.CompanyId,
"orgId": updateDividendsOrderCommand.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 dividendsOrderAmount float64
for _, orderGood := range updateDividendsOrderCommand.OrderGoods {
// TODO 合约合法性校验,订单时间匹配规则校验,
// 计算订单产品金额
orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
// 产品ID类型转换
orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
if err3 != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
}
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,
... ... @@ -1184,7 +1232,7 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
UpdatedAt: time.Now(),
})
// 计算分红订单金额
dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
}
if err := dividendsOrder.Update(tool_funs.SimpleStructToMap(updateDividendsOrderCommand)); err != nil {
... ...