作者 yangfu

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

…tion-cooperation into test
@@ -281,8 +281,22 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -281,8 +281,22 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
281 cooperationApplicationRepository = value 281 cooperationApplicationRepository = value
282 } 282 }
283 283
  284 + var getCooperationProjectQuerySpecific *query.GetCooperationProjectQuery
  285 + if getCooperationProjectQuery.CooperationProjectId != 0 { // 根据ID查询
  286 + getCooperationProjectQuerySpecific = &query.GetCooperationProjectQuery{
  287 + CooperationProjectId: getCooperationProjectQuery.CooperationProjectId,
  288 + CooperationProjectNumber: "",
  289 + CompanyId: 0,
  290 + OrgId: 0,
  291 + UserId: 0,
  292 + UserBaseId: 0,
  293 + }
  294 + } else if getCooperationProjectQuery.CooperationProjectNumber != "" { // 根据编号查询
  295 + getCooperationProjectQuerySpecific = getCooperationProjectQuery
  296 + }
  297 +
284 // 获取共创项目 298 // 获取共创项目
285 - cooperationProject, err := cooperationProjectRepository.FindOne(tool_funs.SimpleStructToMap(getCooperationProjectQuery)) 299 + cooperationProject, err := cooperationProjectRepository.FindOne(tool_funs.SimpleStructToMap(getCooperationProjectQuerySpecific))
286 if err != nil { 300 if err != nil {
287 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 301 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
288 } 302 }
@@ -306,8 +320,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -306,8 +320,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
306 gotUser, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{ 320 gotUser, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
307 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber, 321 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
308 "user": true, 322 "user": true,
309 - "companyId": getCooperationProjectQuery.CompanyId,  
310 - "orgId": getCooperationProjectQuery.OrgId, 323 + "companyId": cooperationProject.Company.CompanyId,
  324 + "orgId": cooperationProject.Org.OrgId,
311 }) 325 })
312 if err != nil { 326 if err != nil {
313 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 327 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -320,8 +334,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -320,8 +334,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
320 gotPartner, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{ 334 gotPartner, err := cooperationProjectDao.CheckUndertakerTypesUncheckedAvailable(map[string]interface{}{
321 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber, 335 "cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
322 "partner": true, 336 "partner": true,
323 - "companyId": getCooperationProjectQuery.CompanyId,  
324 - "orgId": getCooperationProjectQuery.OrgId, 337 + "companyId": cooperationProject.Company.CompanyId,
  338 + "orgId": cooperationProject.Org.OrgId,
325 }) 339 })
326 if err != nil { 340 if err != nil {
327 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 341 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -337,6 +351,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -337,6 +351,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
337 351
338 // 返回所有员工类型的申请通过人 352 // 返回所有员工类型的申请通过人
339 applicants := make([]*domain.User, 0) 353 applicants := make([]*domain.User, 0)
  354 +
340 // 获取当前项目的所有申请 355 // 获取当前项目的所有申请
341 if countApplication, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{ 356 if countApplication, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{
342 "cooperationProjectNumberExact": cooperationProject.CooperationProjectNumber, 357 "cooperationProjectNumberExact": cooperationProject.CooperationProjectNumber,
@@ -157,6 +157,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred @@ -157,6 +157,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred
157 OrderGoodAmount: dividendsEstimate.OrderGoodAmount, 157 OrderGoodAmount: dividendsEstimate.OrderGoodAmount,
158 CooperationContractNumber: dividendsEstimate.CooperationContractNumber, 158 CooperationContractNumber: dividendsEstimate.CooperationContractNumber,
159 }) 159 })
  160 +
160 settlementAmount = settlementAmount + dividendsEstimate.DividendsAmount 161 settlementAmount = settlementAmount + dividendsEstimate.DividendsAmount
161 162
162 goodAmountCount = goodAmountCount + dividendsEstimate.OrderGoodAmount 163 goodAmountCount = goodAmountCount + dividendsEstimate.OrderGoodAmount
@@ -30,6 +30,10 @@ type SearchMoneyIncentivesEstimateQuery struct { @@ -30,6 +30,10 @@ type SearchMoneyIncentivesEstimateQuery struct {
30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"` 30 PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"`
31 // 激励方式 31 // 激励方式
32 IncentivesType int32 `cname:"激励方式" json:"incentivesType,omitempty"` 32 IncentivesType int32 `cname:"激励方式" json:"incentivesType,omitempty"`
  33 + // 合约状态,1正常,2暂停
  34 + Status int32 `cname:"合约状态" json:"status,omitempty"`
  35 + // 查询限制
  36 + OffsetLimit bool `json:"offsetLimit,omitempty"`
33 } 37 }
34 38
35 func (searchMoneyIncentivesEstimateQuery *SearchMoneyIncentivesEstimateQuery) Valid(validation *validation.Validation) { 39 func (searchMoneyIncentivesEstimateQuery *SearchMoneyIncentivesEstimateQuery) Valid(validation *validation.Validation) {
@@ -1380,6 +1380,8 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1380,6 +1380,8 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1380 1380
1381 // 查找共创合约 1381 // 查找共创合约
1382 searchMoneyIncentivesEstimateQuery.IncentivesType = 2 1382 searchMoneyIncentivesEstimateQuery.IncentivesType = 2
  1383 + searchMoneyIncentivesEstimateQuery.Status = 1
  1384 + searchMoneyIncentivesEstimateQuery.OffsetLimit = false
1383 if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(searchMoneyIncentivesEstimateQuery)); err != nil { 1385 if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(searchMoneyIncentivesEstimateQuery)); err != nil {
1384 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1386 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1385 } else { 1387 } else {
@@ -1387,15 +1389,19 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1387,15 +1389,19 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1387 for _, cooperationContract := range cooperationContracts { 1389 for _, cooperationContract := range cooperationContracts {
1388 // 阶段承接人map 1390 // 阶段承接人map
1389 stageUndertakerMap := make(map[int32][]*domain.Undertaker) 1391 stageUndertakerMap := make(map[int32][]*domain.Undertaker)
  1392 +
1390 // 阶段承接人列表 1393 // 阶段承接人列表
1391 stageAndUndertaker := make([]*dto.StageAndUndertaker, 0) 1394 stageAndUndertaker := make([]*dto.StageAndUndertaker, 0)
  1395 +
1392 // 初始化阶段承接人map 1396 // 初始化阶段承接人map
1393 for _, rule := range cooperationContract.MoneyIncentivesRules { 1397 for _, rule := range cooperationContract.MoneyIncentivesRules {
1394 stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0) 1398 stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0)
1395 } 1399 }
  1400 +
1396 log.Logger.Info("阶段承接人map初始化", map[string]interface{}{ 1401 log.Logger.Info("阶段承接人map初始化", map[string]interface{}{
1397 "stageUndertakerMap": stageUndertakerMap, 1402 "stageUndertakerMap": stageUndertakerMap,
1398 }) 1403 })
  1404 +
1399 // 获取承接人 1405 // 获取承接人
1400 for _, undertaker := range cooperationContract.Undertakers { 1406 for _, undertaker := range cooperationContract.Undertakers {
1401 // 查询承接人分红预算单 1407 // 查询承接人分红预算单
@@ -1404,6 +1410,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1404,6 +1410,7 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1404 "companyId": cooperationContract.Company.CompanyId, 1410 "companyId": cooperationContract.Company.CompanyId,
1405 "orgId": cooperationContract.Org.OrgId, 1411 "orgId": cooperationContract.Org.OrgId,
1406 "dividendsUserId": undertaker.UserId, 1412 "dividendsUserId": undertaker.UserId,
  1413 + "offsetLimit": false,
1407 }); err != nil { 1414 }); err != nil {
1408 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1415 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1409 } else { 1416 } else {
@@ -1413,16 +1420,20 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1413,16 +1420,20 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1413 stageUndertakerMap[dividendsEstimate.DividendsStage] = append(stageUndertakerMap[dividendsEstimate.DividendsStage], undertaker) 1420 stageUndertakerMap[dividendsEstimate.DividendsStage] = append(stageUndertakerMap[dividendsEstimate.DividendsStage], undertaker)
1414 } 1421 }
1415 } 1422 }
  1423 + break
1416 } else if countDividendsEstimates == 0 { // 未分红,可以加入任意阶段进行金额激励 1424 } else if countDividendsEstimates == 0 { // 未分红,可以加入任意阶段进行金额激励
1417 for i, _ := range stageUndertakerMap { 1425 for i, _ := range stageUndertakerMap {
1418 stageUndertakerMap[i] = append(stageUndertakerMap[i], undertaker) 1426 stageUndertakerMap[i] = append(stageUndertakerMap[i], undertaker)
1419 } 1427 }
  1428 + break
1420 } 1429 }
1421 } 1430 }
1422 } 1431 }
  1432 +
1423 log.Logger.Info("阶段承接人map", map[string]interface{}{ 1433 log.Logger.Info("阶段承接人map", map[string]interface{}{
1424 "stageUndertakerMap": stageUndertakerMap, 1434 "stageUndertakerMap": stageUndertakerMap,
1425 }) 1435 })
  1436 +
1426 for k, v := range stageUndertakerMap { 1437 for k, v := range stageUndertakerMap {
1427 stageAndUndertaker = append(stageAndUndertaker, &dto.StageAndUndertaker{ 1438 stageAndUndertaker = append(stageAndUndertaker, &dto.StageAndUndertaker{
1428 Stage: k, 1439 Stage: k,
@@ -1431,10 +1442,22 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1431,10 +1442,22 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1431 } 1442 }
1432 1443
1433 moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{} 1444 moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{}
1434 - if err := moneyIncentivesEstimateDto.LoadDto(cooperationContract, stageAndUndertaker); err != nil {  
1435 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1445 +
  1446 + // 判断当前合约的承接人是否全部分红
  1447 + allEstimate := true
  1448 + for i, _ := range stageUndertakerMap {
  1449 + if len(stageUndertakerMap[i]) > 0 {
  1450 + allEstimate = false
  1451 + break
  1452 + }
  1453 + }
  1454 +
  1455 + if !allEstimate {
  1456 + if err := moneyIncentivesEstimateDto.LoadDto(cooperationContract, stageAndUndertaker); err != nil {
  1457 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1458 + }
  1459 + moneyIncentivesEstimateDtos = append(moneyIncentivesEstimateDtos, moneyIncentivesEstimateDto)
1436 } 1460 }
1437 - moneyIncentivesEstimateDtos = append(moneyIncentivesEstimateDtos, moneyIncentivesEstimateDto)  
1438 } 1461 }
1439 1462
1440 if err := transactionContext.CommitTransaction(); err != nil { 1463 if err := transactionContext.CommitTransaction(); err != nil {
@@ -1122,8 +1122,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide @@ -1122,8 +1122,16 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide
1122 } 1122 }
1123 orderTime := utils.TransformTimestampToTime(orderTimeInt) 1123 orderTime := utils.TransformTimestampToTime(orderTimeInt)
1124 1124
  1125 + // 退货单ID类型转换
  1126 + dividendsReturnedOrderId, err := strconv.ParseInt(updateDividendsReturnedOrderCommand.DividendsReturnedOrderId, 10, 64)
  1127 + if err != nil {
  1128 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单ID类型错误")
  1129 + }
  1130 +
1125 // 获取分红退货单 1131 // 获取分红退货单
1126 - dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId}) 1132 + dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{
  1133 + "dividendsReturnedOrderId": dividendsReturnedOrderId,
  1134 + })
1127 if err != nil { 1135 if err != nil {
1128 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 1136 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
1129 } 1137 }
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 9
10 type DividendsEstimateDetail struct { 10 type DividendsEstimateDetail struct {
11 DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户) 11 DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
12 - DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 12 + DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 1承接人,2推荐人,3关联业务员
13 DividendsStage int32 `json:"dividendsStage"` // 分红阶段 13 DividendsStage int32 `json:"dividendsStage"` // 分红阶段
14 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额 14 DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
15 OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号 15 OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
@@ -60,26 +60,52 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -60,26 +60,52 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
60 var dividendsEstimatesCanceled []*domain.DividendsEstimate 60 var dividendsEstimatesCanceled []*domain.DividendsEstimate
61 var orderOrReturnOrderNums []string 61 var orderOrReturnOrderNums []string
62 for _, dividendsEstimate := range dividendsEstimates { 62 for _, dividendsEstimate := range dividendsEstimates {
63 - // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单  
64 - if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{  
65 - "companyId": dividendsEstimate.Company.CompanyId,  
66 - "orgId": dividendsEstimate.Org.OrgId,  
67 - "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
68 - }); err2 != nil {  
69 - return nil, err2  
70 - } else {  
71 - if countRelative > 0 {  
72 - for i, _ := range dividendsEstimatesRelative {  
73 - dividendsEstimatesRelative[i].IsCanceled = true  
74 - dividendsEstimatesRelative[i].Operator = operator  
75 - // 获取相关订单/退货单号  
76 - orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum) 63 + if dividendsEstimate.DividendsType != 3 { // 非金额激励分红预算单处理
  64 + // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
  65 + if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
  66 + "companyId": dividendsEstimate.Company.CompanyId,
  67 + "orgId": dividendsEstimate.Org.OrgId,
  68 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  69 + "offsetLimit": false,
  70 + }); err2 != nil {
  71 + return nil, err2
  72 + } else {
  73 + if countRelative > 0 {
  74 + for i, _ := range dividendsEstimatesRelative {
  75 + dividendsEstimatesRelative[i].IsCanceled = true
  76 + dividendsEstimatesRelative[i].Operator = operator
  77 + // 获取相关订单/退货单号
  78 + orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum)
  79 + }
  80 + dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
  81 + if err3 != nil {
  82 + return nil, err3
  83 + }
  84 + dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
77 } 85 }
78 - dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)  
79 - if err3 != nil {  
80 - return nil, err3 86 + }
  87 + } else if dividendsEstimate.DividendsType == 3 {
  88 + // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
  89 + if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
  90 + "companyId": dividendsEstimate.Company.CompanyId,
  91 + "orgId": dividendsEstimate.Org.OrgId,
  92 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  93 + "dividendsType": int32(3),
  94 + "offsetLimit": false,
  95 + }); err2 != nil {
  96 + return nil, err2
  97 + } else {
  98 + if countRelative > 0 {
  99 + for i, _ := range dividendsEstimatesRelative {
  100 + dividendsEstimatesRelative[i].IsCanceled = true
  101 + dividendsEstimatesRelative[i].Operator = operator
  102 + }
  103 + dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
  104 + if err3 != nil {
  105 + return nil, err3
  106 + }
  107 + dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
81 } 108 }
82 - dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)  
83 } 109 }
84 } 110 }
85 } 111 }
@@ -88,98 +114,107 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -88,98 +114,107 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
88 var orderNums []string 114 var orderNums []string
89 var returnedOrderNums []string 115 var returnedOrderNums []string
90 116
91 - // 订单/退货单号数组去重  
92 - orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)  
93 - for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {  
94 - if orderNullNum[:2] == "RE" { // 分红退后单  
95 - returnedOrderNums = append(returnedOrderNums, orderNullNum)  
96 - } else if orderNullNum[:2] == "SL" { // 分红订单  
97 - orderNums = append(orderNums, orderNullNum) 117 + if len(orderOrReturnOrderNums) > 0 {
  118 + // 订单/退货单号数组去重
  119 + orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums)
  120 + for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup {
  121 + if orderNullNum[:2] == "RE" { // 分红退后单
  122 + returnedOrderNums = append(returnedOrderNums, orderNullNum)
  123 + } else if orderNullNum[:2] == "SL" { // 分红订单
  124 + orderNums = append(orderNums, orderNullNum)
  125 + }
98 } 126 }
99 - }  
100 127
101 - // 获取分红订单  
102 - if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{  
103 - "companyId": dividendsEstimates[0].Company.CompanyId,  
104 - "orgId": dividendsEstimates[0].Org.OrgId,  
105 - "dividendsOrderNumbers": orderNums,  
106 - }); err4 != nil {  
107 - return nil, err4  
108 - } else {  
109 - if countDividendsOrder > 0 {  
110 - for i, _ := range orders {  
111 - orders[i].DividendStatus = 1  
112 - }  
113 - // 保存订单状态  
114 - if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {  
115 - return nil, err6  
116 - }  
117 - // 获取订单编号  
118 - ordersNumbers := make([]string, 0)  
119 - for _, order := range orders {  
120 - ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)  
121 - }  
122 - // 获取分红订单产品并更新产品状态  
123 - if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{  
124 - "orderNumbers": ordersNumbers,  
125 - "companyId": dividendsEstimates[0].Company.CompanyId,  
126 - "orgId": dividendsEstimates[0].Org.OrgId,  
127 - }); err != nil {  
128 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 128 + // 获取分红订单并更新分红订单产品的状态
  129 + if len(orderNums) > 0 {
  130 + if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{
  131 + "companyId": dividendsEstimates[0].Company.CompanyId,
  132 + "orgId": dividendsEstimates[0].Org.OrgId,
  133 + "dividendsOrderNumbers": orderNums,
  134 + }); err4 != nil {
  135 + return nil, err4
129 } else { 136 } else {
130 - if countOrderGood > 0 {  
131 - for i, _ := range orderGoodsFound {  
132 - orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红 137 + if countDividendsOrder > 0 {
  138 + for i, _ := range orders {
  139 + orders[i].DividendStatus = 1
  140 + }
  141 + // 保存订单状态
  142 + if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil {
  143 + return nil, err6
  144 + }
  145 + // 获取订单编号
  146 + ordersNumbers := make([]string, 0)
  147 + for _, order := range orders {
  148 + ordersNumbers = append(ordersNumbers, order.DividendsOrderNumber)
133 } 149 }
134 - if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {  
135 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error()) 150 + // 获取分红订单产品并更新产品状态
  151 + if len(ordersNumbers) > 0 {
  152 + if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
  153 + "orderNumbers": ordersNumbers,
  154 + "companyId": dividendsEstimates[0].Company.CompanyId,
  155 + "orgId": dividendsEstimates[0].Org.OrgId,
  156 + }); err != nil {
  157 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  158 + } else {
  159 + if countOrderGood > 0 {
  160 + for i, _ := range orderGoodsFound {
  161 + orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
  162 + }
  163 + if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
  164 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
  165 + }
  166 + }
  167 + }
136 } 168 }
137 } 169 }
138 } 170 }
139 } 171 }
140 - }  
141 172
142 - // 获取分红退货单  
143 - if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{  
144 - "companyId": dividendsEstimates[0].Company.CompanyId,  
145 - "orgId": dividendsEstimates[0].Org.OrgId,  
146 - "dividendsReturnedOrderNumbers": returnedOrderNums,  
147 - }); err5 != nil {  
148 - return nil, err5  
149 - } else {  
150 - if countDividendsReturnedOrder > 0 {  
151 - for i, _ := range returnedOrders {  
152 - returnedOrders[i].DividendStatus = 1  
153 - }  
154 - // 保存退货单状态  
155 - if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {  
156 - return nil, err7  
157 - }  
158 - // 获取订单编号  
159 - returnedOrdersNumbers := make([]string, 0)  
160 - for _, returnedOrder := range returnedOrders {  
161 - returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)  
162 - }  
163 - // 获取退货单产品并更新产品状态  
164 - if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{  
165 - "returnedOrderNumbers": returnedOrdersNumbers,  
166 - "companyId": dividendsEstimates[0].Company.CompanyId,  
167 - "orgId": dividendsEstimates[0].Org.OrgId,  
168 - }); err != nil {  
169 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 173 + // 获取分红退货单并更新订单产品的状态
  174 + if len(returnedOrderNums) > 0 {
  175 + if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{
  176 + "companyId": dividendsEstimates[0].Company.CompanyId,
  177 + "orgId": dividendsEstimates[0].Org.OrgId,
  178 + "dividendsReturnedOrderNumbers": returnedOrderNums,
  179 + }); err5 != nil {
  180 + return nil, err5
170 } else { 181 } else {
171 - if countOrderGood > 0 {  
172 - for i, _ := range orderGoodsFound {  
173 - orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红 182 + if countDividendsReturnedOrder > 0 {
  183 + for i, _ := range returnedOrders {
  184 + returnedOrders[i].DividendStatus = 1
  185 + }
  186 + // 保存退货单状态
  187 + if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil {
  188 + return nil, err7
174 } 189 }
175 - if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {  
176 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error()) 190 + // 获取订单编号
  191 + returnedOrdersNumbers := make([]string, 0)
  192 + for _, returnedOrder := range returnedOrders {
  193 + returnedOrdersNumbers = append(returnedOrdersNumbers, returnedOrder.DividendsReturnedOrderNumber)
  194 + }
  195 + // 获取退货单产品并更新产品状态
  196 + if len(returnedOrdersNumbers) > 0 {
  197 + if countOrderGood, orderGoodsFound, err := orderGoodRepository.Find(map[string]interface{}{
  198 + "returnedOrderNumbers": returnedOrdersNumbers,
  199 + "companyId": dividendsEstimates[0].Company.CompanyId,
  200 + "orgId": dividendsEstimates[0].Org.OrgId,
  201 + }); err != nil {
  202 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  203 + } else {
  204 + if countOrderGood > 0 {
  205 + for i, _ := range orderGoodsFound {
  206 + orderGoodsFound[i].OrderGoodDividendsStatus = int32(1) // 待分红
  207 + }
  208 + if _, err6 := orderGoodRepository.UpdateMany(orderGoodsFound); err6 != nil {
  209 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err6.Error())
  210 + }
  211 + }
  212 + }
177 } 213 }
178 } 214 }
179 } 215 }
180 } 216 }
181 } 217 }
182 -  
183 return dividendsEstimatesCanceled, nil 218 return dividendsEstimatesCanceled, nil
184 } 219 }
185 } 220 }
@@ -44,7 +44,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -44,7 +44,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
44 44
45 // 判断金额激励阶段是否合法 45 // 判断金额激励阶段是否合法
46 currentTime := time.Now() 46 currentTime := time.Now()
47 - if currentTime.Before(moneyIncentivesRuleMatched.MoneyIncentivesStageStart) { 47 + if currentTime.Before(moneyIncentivesRuleMatched.MoneyIncentivesTime) {
48 return nil, fmt.Errorf("还未到分红时间") 48 return nil, fmt.Errorf("还未到分红时间")
49 } 49 }
50 50
@@ -61,7 +61,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -61,7 +61,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
61 return nil, err 61 return nil, err
62 } 62 }
63 if undertakerEstimated { 63 if undertakerEstimated {
64 - return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红") 64 + return nil, fmt.Errorf("承接人 " + undertaker.UserName + " 已分红")
65 } else { 65 } else {
66 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Float64() 66 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Float64()
67 //Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage)).Div(decimal.NewFromFloat(100)))).Float64() 67 //Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage)).Div(decimal.NewFromFloat(100)))).Float64()
@@ -80,7 +80,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -80,7 +80,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
80 Status: undertaker.Status, 80 Status: undertaker.Status,
81 Company: undertaker.Company, 81 Company: undertaker.Company,
82 }, 82 },
83 - DividendsParticipateType: domain.MONEY_INCENTIVES, 83 + DividendsParticipateType: 1,
84 DividendsStage: stage, 84 DividendsStage: stage,
85 DividendsAmount: undertakerDividendsAmount, 85 DividendsAmount: undertakerDividendsAmount,
86 }) 86 })
@@ -114,7 +114,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -114,7 +114,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
114 UserPhone: undertaker.Salesman.UserPhone, 114 UserPhone: undertaker.Salesman.UserPhone,
115 Company: undertaker.Salesman.Company, 115 Company: undertaker.Salesman.Company,
116 }, 116 },
117 - DividendsParticipateType: domain.MONEY_INCENTIVES, 117 + DividendsParticipateType: 3,
118 DividendsStage: stage, 118 DividendsStage: stage,
119 DividendsAmount: undertakerDividendsAmount, 119 DividendsAmount: undertakerDividendsAmount,
120 }) 120 })
@@ -122,7 +122,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -122,7 +122,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
122 122
123 } 123 }
124 124
125 - // 判断关联业务员在当前阶段是否已经分红 125 + // 判断推荐人在当前阶段是否已经分红
126 if undertaker.Referrer != nil { 126 if undertaker.Referrer != nil {
127 referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{ 127 referrerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
128 "undertakerUid": undertaker.Referrer.UserId, 128 "undertakerUid": undertaker.Referrer.UserId,
@@ -133,7 +133,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -133,7 +133,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
133 return nil, err 133 return nil, err
134 } 134 }
135 if referrerEstimated { 135 if referrerEstimated {
136 - return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红") 136 + return nil, fmt.Errorf("推荐人 " + undertaker.Referrer.UserName + " 已分红")
137 } else { 137 } else {
138 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64() 138 undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64()
139 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 139 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
@@ -150,7 +150,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -150,7 +150,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
150 UserPhone: undertaker.Referrer.UserPhone, 150 UserPhone: undertaker.Referrer.UserPhone,
151 Company: undertaker.Referrer.Company, 151 Company: undertaker.Referrer.Company,
152 }, 152 },
153 - DividendsParticipateType: domain.MONEY_INCENTIVES, 153 + DividendsParticipateType: 2,
154 DividendsStage: stage, 154 DividendsStage: stage,
155 DividendsAmount: undertakerDividendsAmount, 155 DividendsAmount: undertakerDividendsAmount,
156 }) 156 })
@@ -308,6 +308,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -308,6 +308,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
308 if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 { 308 if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
309 query.Where("cooperation_contract_number in (?)", pg.In(v)) 309 query.Where("cooperation_contract_number in (?)", pg.In(v))
310 } 310 }
  311 + if cooperationContractNumber, ok := queryOptions["cooperationContractNumber"]; ok && cooperationContractNumber != "" {
  312 + query.Where("cooperation_contract_number = ?", cooperationContractNumber)
  313 + }
311 if dividendsUserId, ok := queryOptions["dividendsUserId"]; ok && dividendsUserId.(int64) != 0 { 314 if dividendsUserId, ok := queryOptions["dividendsUserId"]; ok && dividendsUserId.(int64) != 0 {
312 query.Where(`dividends_user @> '{"uid":"?"}'`, dividendsUserId) 315 query.Where(`dividends_user @> '{"uid":"?"}'`, dividendsUserId)
313 } 316 }