作者 陈志颖

fix:修复共创项目编号生成错误

... ... @@ -167,7 +167,7 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
"companyId": createCooperationProjectCommand.CompanyId,
})
if err2 != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
}
// 校验共创项目编号是否唯一
numberAvailable, _ := cooperationProjectDao.CheckProjectNumberAvailable(map[string]interface{}{
... ...
... ... @@ -144,6 +144,13 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
}
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
... ... @@ -151,12 +158,26 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
// 计算订单产品金额
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.Before(incentivesRule.DividendsIncentivesStageStart) && orderTime.After(incentivesRule.DividendsIncentivesStageEnd) {
ruleMatchedFlag = true
break
}
}
}
if !ruleMatchedFlag {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
OrderGoodId: 0,
OrderGoodAmount: orderGoodAmount,
... ... @@ -178,13 +199,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 新增分红订单
newDividendsOrder := &domain.DividendsOrder{
DividendsOrderNumber: dividendsOrderNumber,
... ... @@ -696,6 +710,19 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(dividendsOrder.OrderTime, 10, 64)
if err != nil {
row := &domain.ImportInfo{
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
GoodLine: map[int]interface{}{},
}
errorDataList = append(errorDataList, row)
continue
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 新增订单产品
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
... ... @@ -717,10 +744,23 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
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 {
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
}
// 校验产品关联合约的激励规则是否匹配订单时间
if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
if orderTime.Before(incentivesRule.DividendsIncentivesStageStart) && orderTime.After(incentivesRule.DividendsIncentivesStageEnd) {
ruleMatchedFlag = true
break
}
}
}
if !ruleMatchedFlag {
orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
}
}
orderGoods = append(orderGoods, &domain.OrderGood{
... ... @@ -753,19 +793,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
continue
}
// 订单时间转换
orderTimeInt, err := strconv.ParseInt(dividendsOrder.OrderTime, 10, 64)
if err != nil {
row := &domain.ImportInfo{
Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
GoodLine: map[int]interface{}{},
}
errorDataList = append(errorDataList, row)
continue
}
orderTime := utils.TransformTimestampToTime(orderTimeInt)
// 新增分红订单
newDividendsOrder := &domain.DividendsOrder{
DividendsOrderId: 0,
... ... @@ -1132,6 +1159,8 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
var orderGoods []*domain.OrderGood
var dividendsOrderAmount float64
for _, orderGood := range updateDividendsOrderCommand.OrderGoods {
// TODO 合约合法性校验,订单时间匹配规则校验,
// 产品ID类型转换
orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
if err3 != nil {
... ...
... ... @@ -23,7 +23,7 @@ func (dao *CooperationProjectDao) GenerateProjectNumber(queryOptions map[string]
query.Where("cooperation_project.created_at >= ?", todayZeroTime)
query.Where("cooperation_project.created_at < ?", nextDayZeroTime)
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId)
query = query.Where(`cooperation_project.company @> '{"companyId":"?"}'`, companyId)
}
if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
return "", err
... ...
... ... @@ -64,7 +64,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
if cooperationContract == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
}
// TODO 校验合约关联的项目是否已结束
// 获取共创项目
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
"cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
})
... ... @@ -75,7 +76,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber))
}
if orderGood.DividendsOrderNumber != "" {
// 校验合约关联的项目是否已结束
if cooperationProject.Status == 2 {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))
}
if orderGood.DividendsOrderNumber != "" { // 获取分红订单
// 获取分红订单
dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": orderGood.DividendsOrderNumber,
... ... @@ -88,6 +94,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
if dividendsOrder == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
}
// 匹配分红规则
var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {
... ...