作者 陈志颖

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

@@ -167,7 +167,7 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro @@ -167,7 +167,7 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
167 "companyId": createCooperationProjectCommand.CompanyId, 167 "companyId": createCooperationProjectCommand.CompanyId,
168 }) 168 })
169 if err2 != nil { 169 if err2 != nil {
170 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 170 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
171 } 171 }
172 // 校验共创项目编号是否唯一 172 // 校验共创项目编号是否唯一
173 numberAvailable, _ := cooperationProjectDao.CheckProjectNumberAvailable(map[string]interface{}{ 173 numberAvailable, _ := cooperationProjectDao.CheckProjectNumberAvailable(map[string]interface{}{
@@ -144,6 +144,13 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -144,6 +144,13 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
144 } 144 }
145 } 145 }
146 146
  147 + // 订单时间转换
  148 + orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)
  149 + if err != nil {
  150 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")
  151 + }
  152 + orderTime := utils.TransformTimestampToTime(orderTimeInt)
  153 +
147 // 新增订单产品 154 // 新增订单产品
148 var orderGoods []*domain.OrderGood 155 var orderGoods []*domain.OrderGood
149 var dividendsOrderAmount float64 156 var dividendsOrderAmount float64
@@ -151,12 +158,26 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -151,12 +158,26 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
151 // 计算订单产品金额 158 // 计算订单产品金额
152 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64() 159 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
153 160
154 - // 校验共创合约 161 + ruleMatchedFlag := false
155 if orderGood.CooperationContractNumber != "" { 162 if orderGood.CooperationContractNumber != "" {
  163 + // 校验共创合约激励类型是否正确
156 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 { 164 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
157 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则") 165 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则")
158 } 166 }
  167 + // 校验产品关联合约的激励规则是否匹配订单时间
  168 + if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
  169 + for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
  170 + if orderTime.Before(incentivesRule.DividendsIncentivesStageStart) && orderTime.After(incentivesRule.DividendsIncentivesStageEnd) {
  171 + ruleMatchedFlag = true
  172 + break
  173 + }
  174 + }
159 } 175 }
  176 + if !ruleMatchedFlag {
  177 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
  178 + }
  179 + }
  180 +
160 orderGoods = append(orderGoods, &domain.OrderGood{ 181 orderGoods = append(orderGoods, &domain.OrderGood{
161 OrderGoodId: 0, 182 OrderGoodId: 0,
162 OrderGoodAmount: orderGoodAmount, 183 OrderGoodAmount: orderGoodAmount,
@@ -178,13 +199,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD @@ -178,13 +199,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD
178 dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64() 199 dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64()
179 } 200 }
180 201
181 - // 订单时间转换  
182 - orderTimeInt, err := strconv.ParseInt(createDividendsOrderCommand.OrderTime, 10, 64)  
183 - if err != nil {  
184 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误")  
185 - }  
186 - orderTime := utils.TransformTimestampToTime(orderTimeInt)  
187 -  
188 // 新增分红订单 202 // 新增分红订单
189 newDividendsOrder := &domain.DividendsOrder{ 203 newDividendsOrder := &domain.DividendsOrder{
190 DividendsOrderNumber: dividendsOrderNumber, 204 DividendsOrderNumber: dividendsOrderNumber,
@@ -696,6 +710,19 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -696,6 +710,19 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
696 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 710 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
697 } 711 }
698 712
  713 + // 订单时间转换
  714 + orderTimeInt, err := strconv.ParseInt(dividendsOrder.OrderTime, 10, 64)
  715 + if err != nil {
  716 + row := &domain.ImportInfo{
  717 + Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),
  718 + LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行
  719 + GoodLine: map[int]interface{}{},
  720 + }
  721 + errorDataList = append(errorDataList, row)
  722 + continue
  723 + }
  724 + orderTime := utils.TransformTimestampToTime(orderTimeInt)
  725 +
699 // 新增订单产品 726 // 新增订单产品
700 var orderGoods []*domain.OrderGood 727 var orderGoods []*domain.OrderGood
701 var dividendsOrderAmount float64 728 var dividendsOrderAmount float64
@@ -717,10 +744,23 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -717,10 +744,23 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
717 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64() 744 orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64()
718 745
719 // 校验共创合约激励类型是否正确 746 // 校验共创合约激励类型是否正确
  747 + ruleMatchedFlag := false
720 if orderGood.CooperationContractNumber != "" { 748 if orderGood.CooperationContractNumber != "" {
721 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 { 749 if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 {
722 orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则") 750 orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则")
723 } 751 }
  752 + // 校验产品关联合约的激励规则是否匹配订单时间
  753 + if cooperationContractsMap[orderGood.CooperationContractNumber] != nil {
  754 + for _, incentivesRule := range cooperationContractsMap[orderGood.CooperationContractNumber].DividendsIncentivesRules {
  755 + if orderTime.Before(incentivesRule.DividendsIncentivesStageStart) && orderTime.After(incentivesRule.DividendsIncentivesStageEnd) {
  756 + ruleMatchedFlag = true
  757 + break
  758 + }
  759 + }
  760 + }
  761 + if !ruleMatchedFlag {
  762 + orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间无法匹配分红激励规则,请重新选择")
  763 + }
724 } 764 }
725 765
726 orderGoods = append(orderGoods, &domain.OrderGood{ 766 orderGoods = append(orderGoods, &domain.OrderGood{
@@ -753,19 +793,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD @@ -753,19 +793,6 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD
753 continue 793 continue
754 } 794 }
755 795
756 - // 订单时间转换  
757 - orderTimeInt, err := strconv.ParseInt(dividendsOrder.OrderTime, 10, 64)  
758 - if err != nil {  
759 - row := &domain.ImportInfo{  
760 - Error: application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("订单日期转换错误:%s", err)),  
761 - LineNumbers: dividendsOrder.LineNumbers, // 错误影响的行  
762 - GoodLine: map[int]interface{}{},  
763 - }  
764 - errorDataList = append(errorDataList, row)  
765 - continue  
766 - }  
767 - orderTime := utils.TransformTimestampToTime(orderTimeInt)  
768 -  
769 // 新增分红订单 796 // 新增分红订单
770 newDividendsOrder := &domain.DividendsOrder{ 797 newDividendsOrder := &domain.DividendsOrder{
771 DividendsOrderId: 0, 798 DividendsOrderId: 0,
@@ -1132,6 +1159,8 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD @@ -1132,6 +1159,8 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD
1132 var orderGoods []*domain.OrderGood 1159 var orderGoods []*domain.OrderGood
1133 var dividendsOrderAmount float64 1160 var dividendsOrderAmount float64
1134 for _, orderGood := range updateDividendsOrderCommand.OrderGoods { 1161 for _, orderGood := range updateDividendsOrderCommand.OrderGoods {
  1162 + // TODO 合约合法性校验,订单时间匹配规则校验,
  1163 +
1135 // 产品ID类型转换 1164 // 产品ID类型转换
1136 orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64) 1165 orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64)
1137 if err3 != nil { 1166 if err3 != nil {
@@ -23,7 +23,7 @@ func (dao *CooperationProjectDao) GenerateProjectNumber(queryOptions map[string] @@ -23,7 +23,7 @@ func (dao *CooperationProjectDao) GenerateProjectNumber(queryOptions map[string]
23 query.Where("cooperation_project.created_at >= ?", todayZeroTime) 23 query.Where("cooperation_project.created_at >= ?", todayZeroTime)
24 query.Where("cooperation_project.created_at < ?", nextDayZeroTime) 24 query.Where("cooperation_project.created_at < ?", nextDayZeroTime)
25 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 25 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
26 - query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId) 26 + query = query.Where(`cooperation_project.company @> '{"companyId":"?"}'`, companyId)
27 } 27 }
28 if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { 28 if count, err := query.AllWithDeleted().SelectAndCount(); err != nil {
29 return "", err 29 return "", err
@@ -64,7 +64,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -64,7 +64,8 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
64 if cooperationContract == nil { 64 if cooperationContract == nil {
65 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber)) 65 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber))
66 } 66 }
67 - // TODO 校验合约关联的项目是否已结束 67 +
  68 + // 获取共创项目
68 cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{ 69 cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
69 "cooperationProjectNumber": cooperationContract.CooperationProjectNumber, 70 "cooperationProjectNumber": cooperationContract.CooperationProjectNumber,
70 }) 71 })
@@ -75,7 +76,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -75,7 +76,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
75 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber)) 76 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber))
76 } 77 }
77 78
78 - if orderGood.DividendsOrderNumber != "" { 79 + // 校验合约关联的项目是否已结束
  80 + if cooperationProject.Status == 2 {
  81 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s已结束", cooperationContract.CooperationProjectNumber))
  82 + }
  83 +
  84 + if orderGood.DividendsOrderNumber != "" { // 获取分红订单
79 // 获取分红订单 85 // 获取分红订单
80 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{ 86 dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{
81 "dividendsOrderNumber": orderGood.DividendsOrderNumber, 87 "dividendsOrderNumber": orderGood.DividendsOrderNumber,
@@ -88,6 +94,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -88,6 +94,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
88 if dividendsOrder == nil { 94 if dividendsOrder == nil {
89 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber)) 95 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("分红订单%s不存在", orderGood.DividendsOrderNumber))
90 } 96 }
  97 +
91 // 匹配分红规则 98 // 匹配分红规则
92 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule 99 var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule
93 for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules { 100 for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules {