作者 yangfu

Merge branch 'test' of http://gitlab.fjmaimaimai.com/allied-creation/allied-crea…

…tion-cooperation into test
@@ -26,6 +26,8 @@ type OneClickApprovalCooperationApplicationCommand struct { @@ -26,6 +26,8 @@ type OneClickApprovalCooperationApplicationCommand struct {
26 CooperationApplicationStatus int32 `cname:"共创申请审核状态" json:"cooperationApplicationStatus"` 26 CooperationApplicationStatus int32 `cname:"共创申请审核状态" json:"cooperationApplicationStatus"`
27 // 查询限制 27 // 查询限制
28 OffsetLimit bool `cname:"查询限制" json:"offsetLimit"` 28 OffsetLimit bool `cname:"查询限制" json:"offsetLimit"`
  29 + // 是否取消标志
  30 + IsCanceled int32 `cname:"是否删除" json:"isCanceled"`
29 } 31 }
30 32
31 func (oneClickApprovalCooperationApplicationCommand *OneClickApprovalCooperationApplicationCommand) Valid(validation *validation.Validation) { 33 func (oneClickApprovalCooperationApplicationCommand *OneClickApprovalCooperationApplicationCommand) Valid(validation *validation.Validation) {
@@ -445,7 +445,7 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr @@ -445,7 +445,7 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr
445 // 获取审核人 445 // 获取审核人
446 var verifier *domain.User 446 var verifier *domain.User
447 if data, err := userService.UserFrom(oneClickApprovalCooperationApplicationCommand.CompanyId, oneClickApprovalCooperationApplicationCommand.OrgId, oneClickApprovalCooperationApplicationCommand.UserId); err != nil { 447 if data, err := userService.UserFrom(oneClickApprovalCooperationApplicationCommand.CompanyId, oneClickApprovalCooperationApplicationCommand.OrgId, oneClickApprovalCooperationApplicationCommand.UserId); err != nil {
448 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败") 448 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取审核人失败")
449 } else { 449 } else {
450 verifier = data 450 verifier = data
451 } 451 }
@@ -453,6 +453,10 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr @@ -453,6 +453,10 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr
453 // 查询共创申请 453 // 查询共创申请
454 oneClickApprovalCooperationApplicationCommand.CooperationApplicationStatus = 1 // 待审核 454 oneClickApprovalCooperationApplicationCommand.CooperationApplicationStatus = 1 // 待审核
455 oneClickApprovalCooperationApplicationCommand.OffsetLimit = false 455 oneClickApprovalCooperationApplicationCommand.OffsetLimit = false
  456 + oneClickApprovalCooperationApplicationCommand.IsCanceled = int32(1)
  457 + oneClickApprovalCooperationApplicationCommand.UserBaseId = 0
  458 + oneClickApprovalCooperationApplicationCommand.UserId = 0
  459 +
456 if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(oneClickApprovalCooperationApplicationCommand)); err != nil { 460 if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(oneClickApprovalCooperationApplicationCommand)); err != nil {
457 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 461 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
458 } else { 462 } else {
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" 9 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log"
11 ) 12 )
12 13
13 type CancelDividendsEstimateService struct { 14 type CancelDividendsEstimateService struct {
@@ -21,6 +22,12 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -21,6 +22,12 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
21 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 22 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
22 var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储 23 var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储
23 24
  25 + type orderGoodInfo struct {
  26 + OrderGoodId int64
  27 + CompanyId int64
  28 + OrgId int64
  29 + }
  30 +
24 // 分红预算单仓储初始化 31 // 分红预算单仓储初始化
25 if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil { 32 if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
26 return nil, err 33 return nil, err
@@ -60,6 +67,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -60,6 +67,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
60 var dividendsEstimatesCanceled []*domain.DividendsEstimate 67 var dividendsEstimatesCanceled []*domain.DividendsEstimate
61 var orderOrReturnOrderNums []string 68 var orderOrReturnOrderNums []string
62 var orderGoodIds []int64 69 var orderGoodIds []int64
  70 + orderGoodMaps := make(map[string][]int64, 0)
63 for _, dividendsEstimate := range dividendsEstimates { 71 for _, dividendsEstimate := range dividendsEstimates {
64 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销 72 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
65 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 73 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
@@ -83,6 +91,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -83,6 +91,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
83 // 获取相关订单/退货单号 91 // 获取相关订单/退货单号
84 orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum) 92 orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
85 orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId) 93 orderGoodIds = append(orderGoodIds, dividendsEstimatesRelative[i].OrderGoodId)
  94 + orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum] = append(orderGoodMaps[dividendsEstimatesRelative[i].OrderOrReturnedOrderNum], dividendsEstimatesRelative[i].OrderGoodId)
86 } 95 }
87 dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative) 96 dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
88 if err3 != nil { 97 if err3 != nil {
@@ -151,18 +160,19 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -151,18 +160,19 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
151 }); err4 != nil { 160 }); err4 != nil {
152 return nil, err4 161 return nil, err4
153 } else { 162 } else {
154 - // orderGoodIds去重  
155 - newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)  
156 if countDividendsOrder > 0 { 163 if countDividendsOrder > 0 {
157 for i, order := range orders { 164 for i, order := range orders {
  165 + // 取消分红的订单产品
  166 + newOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[order.DividendsOrderNumber])
158 var goodIds []int64 167 var goodIds []int64
159 for _, good := range order.Goods { 168 for _, good := range order.Goods {
160 if good.OrderGoodDividendsStatus == 2 { 169 if good.OrderGoodDividendsStatus == 2 {
161 goodIds = append(goodIds, good.OrderGoodId) 170 goodIds = append(goodIds, good.OrderGoodId)
162 } 171 }
163 } 172 }
164 - // goodIds去重 173 + // goodIds去重
165 newGoodIds := utils.RemoveDuplicationInt64(goodIds) 174 newGoodIds := utils.RemoveDuplicationInt64(goodIds)
  175 + log.Logger.Info("")
166 if len(newGoodIds) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红 176 if len(newGoodIds) == len(newOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,订单分红状态变更为未分红
167 orders[i].DividendStatus = 1 177 orders[i].DividendStatus = 1
168 } else if len(newGoodIds) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红 178 } else if len(newGoodIds) > len(newOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,订单分红状态变更为部分分红
@@ -216,21 +226,21 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -216,21 +226,21 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
216 }); err5 != nil { 226 }); err5 != nil {
217 return nil, err5 227 return nil, err5
218 } else { 228 } else {
219 - // orderGoodIds去重  
220 - newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodIds)  
221 -  
222 if countDividendsReturnedOrder > 0 { 229 if countDividendsReturnedOrder > 0 {
223 for i, returnedOrder := range returnedOrders { 230 for i, returnedOrder := range returnedOrders {
224 - goods := make([]*domain.OrderGood, 0) 231 + // 已取消的退货单产品
  232 + newReturnedOrderGoodIds := utils.RemoveDuplicationInt64(orderGoodMaps[returnedOrder.DividendsReturnedOrderNumber])
  233 + var goodIds []int64
225 for _, good := range returnedOrder.Goods { 234 for _, good := range returnedOrder.Goods {
226 if good.OrderGoodDividendsStatus == 2 { 235 if good.OrderGoodDividendsStatus == 2 {
227 - goods = append(goods, good) 236 + goodIds = append(goodIds, good.OrderGoodId)
228 } 237 }
229 } 238 }
230 -  
231 - if len(goods) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红 239 + // goodIds去重
  240 + newGoodIds := utils.RemoveDuplicationInt64(goodIds)
  241 + if len(newGoodIds) == len(newReturnedOrderGoodIds) { // 1.已分红的产品数量等于取消的产品数量,退货单分红状态变更为未分红
232 returnedOrders[i].DividendStatus = 1 242 returnedOrders[i].DividendStatus = 1
233 - } else if len(goods) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红 243 + } else if len(newGoodIds) > len(newReturnedOrderGoodIds) { // 3.已分红的产品数量大于被取消分红的产品数量,退货单分红状态变更为部分分红
234 returnedOrders[i].DividendStatus = 3 244 returnedOrders[i].DividendStatus = 3
235 } 245 }
236 returnedOrders[i].DividendStatus = returnedOrder.DividendStatus 246 returnedOrders[i].DividendStatus = returnedOrder.DividendStatus