作者 陈志颖

fix:优化合约仓储

@@ -308,7 +308,11 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -308,7 +308,11 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
308 } else { 308 } else {
309 cooperationModeRepository = value 309 cooperationModeRepository = value
310 } 310 }
311 - cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeNumber": createCooperationContractCommand.CooperationModeNumber}) 311 + cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{
  312 + "companyId": createCooperationContractCommand.CompanyId,
  313 + "orgId": createCooperationContractCommand.OrgId,
  314 + "cooperationModeNumber": createCooperationContractCommand.CooperationModeNumber,
  315 + })
312 if err != nil { 316 if err != nil {
313 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式不存在") 317 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式不存在")
314 } 318 }
@@ -752,29 +752,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -752,29 +752,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
752 countDividendsEstimate = countDividendsEstimate + 1 752 countDividendsEstimate = countDividendsEstimate + 1
753 753
754 dividendsEstimate = &domain.DividendsEstimate{ 754 dividendsEstimate = &domain.DividendsEstimate{
755 - DividendsEstimateId: 0,  
756 - DividendsAccountStatus: domain.TO_BE_ACCOUNT,  
757 - DividendsAmount: dividendsEstimateDetail.DividendsAmount,  
758 - DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,  
759 - DividendsEstimateTime: time.Now(),  
760 - DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,  
761 - DividendsType: domain.ORDER_DIVIDENDS,  
762 - DividendsTypeName: "订单分红",  
763 - OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,  
764 - CooperationContractNumber: orderGood.CooperationContractNumber,  
765 - DividendsUser: dividendsEstimateDetail.DividendsUser,  
766 - DividendsStage: dividendsEstimateDetail.DividendsStage,  
767 - Org: organization,  
768 - Company: company,  
769 - Operator: operator,  
770 - OperateTime: time.Time{},  
771 - IsCanceled: false,  
772 - CreatedAt: time.Now(),  
773 - DeletedAt: time.Time{},  
774 - UpdatedAt: time.Time{},  
775 - OrderGoodId: orderGood.OrderGoodId,  
776 - OrderGoodAmount: orderGood.OrderGoodAmount,  
777 - PaymentStatus: int32(1), 755 + DividendsEstimateId: 0,
  756 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  757 + DividendsAmount: dividendsEstimateDetail.DividendsAmount,
  758 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  759 + DividendsEstimateTime: time.Now(),
  760 + DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
  761 + DividendsType: domain.ORDER_DIVIDENDS,
  762 + DividendsTypeName: "订单分红",
  763 + OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber,
  764 + CooperationContractNumber: orderGood.CooperationContractNumber,
  765 + DividendsUser: dividendsEstimateDetail.DividendsUser,
  766 + DividendsStage: dividendsEstimateDetail.DividendsStage,
  767 + Org: organization,
  768 + Company: company,
  769 + Operator: operator,
  770 + OperateTime: time.Time{},
  771 + IsCanceled: false,
  772 + CreatedAt: time.Now(),
  773 + DeletedAt: time.Time{},
  774 + UpdatedAt: time.Time{},
  775 + OrderGoodId: orderGood.OrderGoodId,
  776 + OrderGoodAmount: orderGood.OrderGoodAmount,
  777 + PaymentStatus: int32(1),
  778 + CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
778 } 779 }
779 780
780 dividendsEstimates = append(dividendsEstimates, dividendsEstimate) 781 dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
@@ -806,29 +807,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -806,29 +807,30 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
806 countDividendsEstimate = countDividendsEstimate + 1 807 countDividendsEstimate = countDividendsEstimate + 1
807 808
808 dividendsEstimate = &domain.DividendsEstimate{ 809 dividendsEstimate = &domain.DividendsEstimate{
809 - DividendsEstimateId: 0,  
810 - DividendsAccountStatus: domain.TO_BE_ACCOUNT,  
811 - DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,  
812 - DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,  
813 - DividendsEstimateTime: time.Now(),  
814 - DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,  
815 - DividendsType: domain.RETURN_WRITE_OFF,  
816 - DividendsTypeName: "退货冲销",  
817 - OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,  
818 - CooperationContractNumber: orderGood.CooperationContractNumber,  
819 - DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,  
820 - DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,  
821 - Org: organization,  
822 - Company: company,  
823 - Operator: operator,  
824 - OperateTime: time.Time{},  
825 - IsCanceled: false,  
826 - CreatedAt: time.Now(),  
827 - DeletedAt: time.Time{},  
828 - UpdatedAt: time.Time{},  
829 - OrderGoodId: orderGood.OrderGoodId,  
830 - OrderGoodAmount: orderGood.OrderGoodAmount,  
831 - PaymentStatus: int32(1), 810 + DividendsEstimateId: 0,
  811 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  812 + DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount,
  813 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  814 + DividendsEstimateTime: time.Now(),
  815 + DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType,
  816 + DividendsType: domain.RETURN_WRITE_OFF,
  817 + DividendsTypeName: "退货冲销",
  818 + OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber,
  819 + CooperationContractNumber: orderGood.CooperationContractNumber,
  820 + DividendsUser: dividendsReturnedEstimateDetail.DividendsUser,
  821 + DividendsStage: dividendsReturnedEstimateDetail.DividendsStage,
  822 + Org: organization,
  823 + Company: company,
  824 + Operator: operator,
  825 + OperateTime: time.Time{},
  826 + IsCanceled: false,
  827 + CreatedAt: time.Now(),
  828 + DeletedAt: time.Time{},
  829 + UpdatedAt: time.Time{},
  830 + OrderGoodId: orderGood.OrderGoodId,
  831 + OrderGoodAmount: orderGood.OrderGoodAmount,
  832 + PaymentStatus: int32(1),
  833 + CooperationContractUndertakerId: dividendsReturnedEstimateDetail.CooperationContractUndertakerId,
832 } 834 }
833 835
834 dividendsEstimates = append(dividendsEstimates, dividendsEstimate) 836 dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
@@ -1148,27 +1150,28 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -1148,27 +1150,28 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
1148 dividendsAmount, _ := decimal.NewFromFloatWithExponent(dividendsEstimateDetail.DividendsAmount, -2).Float64() 1150 dividendsAmount, _ := decimal.NewFromFloatWithExponent(dividendsEstimateDetail.DividendsAmount, -2).Float64()
1149 1151
1150 dividendsEstimate := &domain.DividendsEstimate{ 1152 dividendsEstimate := &domain.DividendsEstimate{
1151 - DividendsEstimateId: 0,  
1152 - DividendsAccountStatus: domain.TO_BE_ACCOUNT,  
1153 - DividendsAmount: dividendsAmount,  
1154 - DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,  
1155 - DividendsEstimateTime: time.Now(),  
1156 - DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,  
1157 - DividendsType: domain.MONEY_INCENTIVES,  
1158 - DividendsTypeName: "金额激励",  
1159 - OrderOrReturnedOrderNum: "",  
1160 - CooperationContractNumber: cooperationContract.CooperationContractNumber,  
1161 - DividendsUser: dividendsEstimateDetail.DividendsUser,  
1162 - DividendsStage: dividendsEstimateDetail.DividendsStage,  
1163 - Org: organization,  
1164 - Company: company,  
1165 - Operator: nil,  
1166 - OperateTime: time.Time{},  
1167 - IsCanceled: false,  
1168 - CreatedAt: time.Now(),  
1169 - DeletedAt: time.Time{},  
1170 - UpdatedAt: time.Time{},  
1171 - PaymentStatus: int32(1), 1153 + DividendsEstimateId: 0,
  1154 + DividendsAccountStatus: domain.TO_BE_ACCOUNT,
  1155 + DividendsAmount: dividendsAmount,
  1156 + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber,
  1157 + DividendsEstimateTime: time.Now(),
  1158 + DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType,
  1159 + DividendsType: domain.MONEY_INCENTIVES,
  1160 + DividendsTypeName: "金额激励",
  1161 + OrderOrReturnedOrderNum: "",
  1162 + CooperationContractNumber: cooperationContract.CooperationContractNumber,
  1163 + DividendsUser: dividendsEstimateDetail.DividendsUser,
  1164 + DividendsStage: dividendsEstimateDetail.DividendsStage,
  1165 + Org: organization,
  1166 + Company: company,
  1167 + Operator: nil,
  1168 + OperateTime: time.Time{},
  1169 + IsCanceled: false,
  1170 + CreatedAt: time.Now(),
  1171 + DeletedAt: time.Time{},
  1172 + UpdatedAt: time.Time{},
  1173 + PaymentStatus: int32(1),
  1174 + CooperationContractUndertakerId: dividendsEstimateDetail.CooperationContractUndertakerId,
1172 } 1175 }
1173 1176
1174 dividendsEstimates = append(dividendsEstimates, dividendsEstimate) 1177 dividendsEstimates = append(dividendsEstimates, dividendsEstimate)
@@ -43,6 +43,8 @@ type DividendsEstimate struct { @@ -43,6 +43,8 @@ type DividendsEstimate struct {
43 OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"` 43 OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"`
44 // 共创项目合约编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001 44 // 共创项目合约编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001
45 CooperationContractNumber string `json:"cooperationContractNumber"` 45 CooperationContractNumber string `json:"cooperationContractNumber"`
  46 + // 共创合约承接人id
  47 + CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"`
46 // 分红用户(共创参与) 48 // 分红用户(共创参与)
47 DividendsUser *User `json:"dividendsUser"` 49 DividendsUser *User `json:"dividendsUser"`
48 // 分红阶段 50 // 分红阶段
@@ -8,13 +8,14 @@ import ( @@ -8,13 +8,14 @@ import (
8 ) 8 )
9 9
10 type DividendsEstimateDetail struct { 10 type DividendsEstimateDetail struct {
11 - DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)  
12 - DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 1承接人,2推荐人,3关联业务员  
13 - DividendsStage int32 `json:"dividendsStage"` // 分红阶段  
14 - DividendsAmount float64 `json:"dividendsAmount"` // 分红金额  
15 - OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号  
16 - IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功  
17 - Reason string `json:"reason"` // 错误原因 11 + DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户)
  12 + DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 1承接人,2推荐人,3关联业务员
  13 + DividendsStage int32 `json:"dividendsStage"` // 分红阶段
  14 + DividendsAmount float64 `json:"dividendsAmount"` // 分红金额
  15 + OrderOrReturnedOrderNumber string `json:"orderOrReturnedOrderNumber"` // 分红订单号或退货单号
  16 + IsSuccessfully bool `json:"isSuccessfully"` // 是否预算成功
  17 + Reason string `json:"reason"` // 错误原因
  18 + CooperationContractUndertakerId int64 `json:"cooperationContractUndertakerId"` // 承接人记录ID
18 } 19 }
19 20
20 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号 21 // GenerateSpecificDividendsEstimateNumber 批量生成自定义分红预算单号
@@ -2,7 +2,7 @@ package domain @@ -2,7 +2,7 @@ package domain
2 2
3 // Undertaker 共创合约承接方值对象 3 // Undertaker 共创合约承接方值对象
4 type Undertaker struct { 4 type Undertaker struct {
5 - // 承接人id 5 + // 承接人记录ID
6 UndertakerId int64 `json:"undertakerId,string"` 6 UndertakerId int64 `json:"undertakerId,string"`
7 // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员 7 // 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
8 UserId int64 `json:"userId,string"` 8 UserId int64 `json:"userId,string"`
@@ -20,6 +20,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -20,6 +20,7 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
20 var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 20 var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储
21 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 21 var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储
22 var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储 22 var orderGoodRepository domain.OrderGoodRepository // 订单产品仓储
  23 + //var cooperationContactRepository domain.CooperationContractRepository // 合约仓储
23 24
24 // 分红预算单仓储初始化 25 // 分红预算单仓储初始化
25 if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil { 26 if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
@@ -49,6 +50,13 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -49,6 +50,13 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
49 orderGoodRepository = repo 50 orderGoodRepository = repo
50 } 51 }
51 52
  53 + // 共创合约仓储初始化
  54 + //if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil {
  55 + // return nil, err
  56 + //} else {
  57 + // cooperationContactRepository = repo
  58 + //}
  59 +
52 // 获取分红预算单 60 // 获取分红预算单
53 if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{ 61 if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
54 "dividendsEstimateIds": dividendsEstimateIds, 62 "dividendsEstimateIds": dividendsEstimateIds,
@@ -61,18 +69,16 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -61,18 +69,16 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
61 for _, dividendsEstimate := range dividendsEstimates { 69 for _, dividendsEstimate := range dividendsEstimates {
62 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销 70 if dividendsEstimate.DividendsType == 1 || dividendsEstimate.DividendsType == 2 { // 1.订单分红 2.退货冲销
63 // 自定义查询 71 // 自定义查询
64 - queryOptions := make(map[string]interface{})  
65 -  
66 - queryOptions = map[string]interface{}{  
67 - "companyId": dividendsEstimate.Company.CompanyId,  
68 - "orgId": dividendsEstimate.Org.OrgId,  
69 - "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,  
70 - "dividendsParticipateTypes": []int32{1, 2, 3},  
71 - "offsetLimit": false,  
72 - "dividendsStage": dividendsEstimate.DividendsStage,  
73 - "dividendsTypes": []int32{1, 2},  
74 - }  
75 72
  73 + //queryOptions := map[string]interface{}{
  74 + // "companyId": dividendsEstimate.Company.CompanyId,
  75 + // "orgId": dividendsEstimate.Org.OrgId,
  76 + // "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  77 + // "dividendsParticipateTypes": []int32{1, 2, 3},
  78 + // "offsetLimit": false,
  79 + // "dividendsStage": dividendsEstimate.DividendsStage,
  80 + // "dividendsTypes": []int32{1, 2},
  81 + //}
76 //参与分红类型,1承接人,2推荐人,3关联业务员 82 //参与分红类型,1承接人,2推荐人,3关联业务员
77 //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单 83 //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
78 // queryOptions = map[string]interface{}{ 84 // queryOptions = map[string]interface{}{
@@ -107,7 +113,17 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -107,7 +113,17 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
107 //} 113 //}
108 114
109 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 115 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
110 - if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil { 116 + if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
  117 + "companyId": dividendsEstimate.Company.CompanyId,
  118 + "orgId": dividendsEstimate.Org.OrgId,
  119 + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum,
  120 + "dividendsParticipateTypes": []int32{1, 2, 3},
  121 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  122 + "offsetLimit": false,
  123 + "dividendsStage": dividendsEstimate.DividendsStage,
  124 + "dividendsTypes": []int32{1, 2},
  125 + "orderGoodId": dividendsEstimate.OrderGoodId,
  126 + }); err2 != nil {
111 return nil, err2 127 return nil, err2
112 } else { 128 } else {
113 if countRelative > 0 { 129 if countRelative > 0 {
@@ -125,19 +141,27 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -125,19 +141,27 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
125 } 141 }
126 } 142 }
127 } else if dividendsEstimate.DividendsType == 3 { // 3.金额激励 143 } else if dividendsEstimate.DividendsType == 3 { // 3.金额激励
128 - // 自定义查询  
129 - queryOptions := make(map[string]interface{})  
130 144
131 - queryOptions = map[string]interface{}{  
132 - "companyId": dividendsEstimate.Company.CompanyId,  
133 - "orgId": dividendsEstimate.Org.OrgId,  
134 - "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,  
135 - "dividendsParticipateTypes": []int32{1, 2, 3},  
136 - "offsetLimit": false,  
137 - "dividendsStage": dividendsEstimate.DividendsStage,  
138 - "dividendsType": int32(3),  
139 - } 145 + // 查询合约
  146 + //cooperationContract, err3 := cooperationContactRepository.FindOne(map[string]interface{}{
  147 + // "companyId": dividendsEstimate.Company.CompanyId,
  148 + // "orgId": dividendsEstimate.Org.OrgId,
  149 + // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  150 + //})
  151 + //if err3 != nil {
  152 + // return nil, err3
  153 + //}
140 154
  155 + // 自定义查询
  156 + //queryOptions := map[string]interface{}{
  157 + // "companyId": dividendsEstimate.Company.CompanyId,
  158 + // "orgId": dividendsEstimate.Org.OrgId,
  159 + // "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  160 + // "dividendsParticipateTypes": []int32{1, 2, 3},
  161 + // "offsetLimit": false,
  162 + // "dividendsStage": dividendsEstimate.DividendsStage,
  163 + // "dividendsType": int32(3),
  164 + //}
141 //参与分红类型,1承接人,2推荐人,3关联业务员 165 //参与分红类型,1承接人,2推荐人,3关联业务员
142 //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单 166 //if dividendsEstimate.DividendsParticipateType == 1 { // 当前取消的是承接人的分红预算单
143 // queryOptions = map[string]interface{}{ 167 // queryOptions = map[string]interface{}{
@@ -172,7 +196,16 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -172,7 +196,16 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
172 //} 196 //}
173 197
174 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单 198 // 根据当前分红预算单的分红订单号或退货单号获取相关的分红预算单
175 - if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(queryOptions); err2 != nil { 199 + if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{
  200 + "companyId": dividendsEstimate.Company.CompanyId,
  201 + "orgId": dividendsEstimate.Org.OrgId,
  202 + "cooperationContractNumber": dividendsEstimate.CooperationContractNumber,
  203 + "cooperationContractUndertakerId": dividendsEstimate.CooperationContractUndertakerId,
  204 + "dividendsParticipateTypes": []int32{1, 2, 3},
  205 + "offsetLimit": false,
  206 + "dividendsStage": dividendsEstimate.DividendsStage,
  207 + "dividendsType": int32(3),
  208 + }); err2 != nil {
176 return nil, err2 209 return nil, err2
177 } else { 210 } else {
178 if countRelative > 0 { 211 if countRelative > 0 {
@@ -180,9 +213,9 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst @@ -180,9 +213,9 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst
180 dividendsEstimatesRelative[i].IsCanceled = true 213 dividendsEstimatesRelative[i].IsCanceled = true
181 dividendsEstimatesRelative[i].Operator = operator 214 dividendsEstimatesRelative[i].Operator = operator
182 } 215 }
183 - dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)  
184 - if err3 != nil {  
185 - return nil, err3 216 + dividendsEstimatesRelativeCanceled, err4 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative)
  217 + if err4 != nil {
  218 + return nil, err4
186 } 219 }
187 dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...) 220 dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...)
188 } 221 }
@@ -243,11 +243,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -243,11 +243,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
243 Status: undertaker.Status, 243 Status: undertaker.Status,
244 Company: undertaker.Company, 244 Company: undertaker.Company,
245 }, 245 },
246 - DividendsParticipateType: domain.UNDERTAKER,  
247 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
248 - DividendsAmount: undertakerDividendsAmount,  
249 - OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,  
250 - IsSuccessfully: true, 246 + DividendsParticipateType: domain.UNDERTAKER,
  247 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  248 + DividendsAmount: undertakerDividendsAmount,
  249 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  250 + IsSuccessfully: true,
  251 + CooperationContractUndertakerId: undertaker.UndertakerId,
251 }) 252 })
252 } 253 }
253 254
@@ -269,11 +270,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -269,11 +270,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
269 UserPhone: undertaker.Referrer.UserPhone, 270 UserPhone: undertaker.Referrer.UserPhone,
270 Company: undertaker.Referrer.Company, 271 Company: undertaker.Referrer.Company,
271 }, 272 },
272 - DividendsParticipateType: domain.REFERRER,  
273 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
274 - DividendsAmount: referrerDividendsAmount,  
275 - OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,  
276 - IsSuccessfully: true, 273 + DividendsParticipateType: domain.REFERRER,
  274 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  275 + DividendsAmount: referrerDividendsAmount,
  276 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  277 + IsSuccessfully: true,
  278 + CooperationContractUndertakerId: undertaker.UndertakerId,
277 }) 279 })
278 } 280 }
279 } 281 }
@@ -295,11 +297,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -295,11 +297,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
295 UserPhone: undertaker.Salesman.UserPhone, 297 UserPhone: undertaker.Salesman.UserPhone,
296 Company: undertaker.Salesman.Company, 298 Company: undertaker.Salesman.Company,
297 }, 299 },
298 - DividendsParticipateType: domain.SALESMAN,  
299 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
300 - DividendsAmount: salesmanDividendsAmount,  
301 - OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,  
302 - IsSuccessfully: true, 300 + DividendsParticipateType: domain.SALESMAN,
  301 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  302 + DividendsAmount: salesmanDividendsAmount,
  303 + OrderOrReturnedOrderNumber: dividendsOrder.DividendsOrderNumber,
  304 + IsSuccessfully: true,
  305 + CooperationContractUndertakerId: undertaker.UndertakerId,
303 }) 306 })
304 } 307 }
305 } 308 }
@@ -364,11 +367,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -364,11 +367,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
364 Status: undertaker.Status, 367 Status: undertaker.Status,
365 Company: undertaker.Company, 368 Company: undertaker.Company,
366 }, 369 },
367 - DividendsParticipateType: domain.UNDERTAKER,  
368 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
369 - DividendsAmount: -undertakerDividendsAmount,  
370 - OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,  
371 - IsSuccessfully: true, 370 + DividendsParticipateType: domain.UNDERTAKER,
  371 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  372 + DividendsAmount: -undertakerDividendsAmount,
  373 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
  374 + IsSuccessfully: true,
  375 + CooperationContractUndertakerId: undertaker.UndertakerId,
372 }) 376 })
373 } 377 }
374 378
@@ -390,11 +394,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -390,11 +394,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
390 UserPhone: undertaker.Referrer.UserPhone, 394 UserPhone: undertaker.Referrer.UserPhone,
391 Company: undertaker.Referrer.Company, 395 Company: undertaker.Referrer.Company,
392 }, 396 },
393 - DividendsParticipateType: domain.REFERRER,  
394 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
395 - DividendsAmount: -referrerDividendsAmount,  
396 - OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,  
397 - IsSuccessfully: true, 397 + DividendsParticipateType: domain.REFERRER,
  398 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  399 + DividendsAmount: -referrerDividendsAmount,
  400 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
  401 + IsSuccessfully: true,
  402 + CooperationContractUndertakerId: undertaker.UndertakerId,
398 }) 403 })
399 } 404 }
400 } 405 }
@@ -417,11 +422,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -417,11 +422,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
417 UserPhone: undertaker.Salesman.UserPhone, 422 UserPhone: undertaker.Salesman.UserPhone,
418 Company: undertaker.Salesman.Company, 423 Company: undertaker.Salesman.Company,
419 }, 424 },
420 - DividendsParticipateType: domain.SALESMAN,  
421 - DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,  
422 - DividendsAmount: -salesmanDividendsAmount,  
423 - OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,  
424 - IsSuccessfully: true, 425 + DividendsParticipateType: domain.SALESMAN,
  426 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
  427 + DividendsAmount: -salesmanDividendsAmount,
  428 + OrderOrReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber,
  429 + IsSuccessfully: true,
  430 + CooperationContractUndertakerId: undertaker.UndertakerId,
425 }) 431 })
426 } 432 }
427 433
@@ -64,7 +64,6 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -64,7 +64,6 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
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()  
68 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ 67 dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
69 DividendsUser: &domain.User{ 68 DividendsUser: &domain.User{
70 UserId: undertaker.UserId, 69 UserId: undertaker.UserId,
@@ -80,9 +79,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -80,9 +79,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
80 Status: undertaker.Status, 79 Status: undertaker.Status,
81 Company: undertaker.Company, 80 Company: undertaker.Company,
82 }, 81 },
83 - DividendsParticipateType: 1,  
84 - DividendsStage: stage,  
85 - DividendsAmount: undertakerDividendsAmount, 82 + DividendsParticipateType: 1,
  83 + DividendsStage: stage,
  84 + DividendsAmount: undertakerDividendsAmount,
  85 + CooperationContractUndertakerId: undertaker.UndertakerId,
86 }) 86 })
87 } 87 }
88 88
@@ -114,9 +114,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -114,9 +114,10 @@ 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: 3,  
118 - DividendsStage: stage,  
119 - DividendsAmount: undertakerDividendsAmount, 117 + DividendsParticipateType: 3,
  118 + DividendsStage: stage,
  119 + DividendsAmount: undertakerDividendsAmount,
  120 + CooperationContractUndertakerId: undertaker.UndertakerId,
120 }) 121 })
121 } 122 }
122 123
@@ -150,9 +151,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -150,9 +151,10 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
150 UserPhone: undertaker.Referrer.UserPhone, 151 UserPhone: undertaker.Referrer.UserPhone,
151 Company: undertaker.Referrer.Company, 152 Company: undertaker.Referrer.Company,
152 }, 153 },
153 - DividendsParticipateType: 2,  
154 - DividendsStage: stage,  
155 - DividendsAmount: undertakerDividendsAmount, 154 + DividendsParticipateType: 2,
  155 + DividendsStage: stage,
  156 + DividendsAmount: undertakerDividendsAmount,
  157 + CooperationContractUndertakerId: undertaker.UndertakerId,
156 }) 158 })
157 } 159 }
158 } 160 }
@@ -29,6 +29,8 @@ type DividendsEstimate struct { @@ -29,6 +29,8 @@ type DividendsEstimate struct {
29 OrderOrReturnedOrderNum string `comment:"分红订单号或退货单号"` 29 OrderOrReturnedOrderNum string `comment:"分红订单号或退货单号"`
30 // 共创项目合约编号 30 // 共创项目合约编号
31 CooperationContractNumber string `comment:"共创项目合约编号"` 31 CooperationContractNumber string `comment:"共创项目合约编号"`
  32 + // 共创合约承接人id
  33 + CooperationContractUndertakerId int64 `comment:"共创合约承接人ID"`
32 // 分红用户 34 // 分红用户
33 DividendsUser *domain.User `comment:"分红用户"` 35 DividendsUser *domain.User `comment:"分红用户"`
34 // 分红阶段 36 // 分红阶段
@@ -9,27 +9,28 @@ import ( @@ -9,27 +9,28 @@ import (
9 func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel *models.DividendsEstimate) (*domain.DividendsEstimate, error) { 9 func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel *models.DividendsEstimate) (*domain.DividendsEstimate, error) {
10 dividendsAmount, _ := decimal.NewFromFloatWithExponent(dividendsEstimateModel.DividendsAmount, -2).Float64() 10 dividendsAmount, _ := decimal.NewFromFloatWithExponent(dividendsEstimateModel.DividendsAmount, -2).Float64()
11 return &domain.DividendsEstimate{ 11 return &domain.DividendsEstimate{
12 - DividendsEstimateId: dividendsEstimateModel.DividendsEstimateId,  
13 - DividendsAccountStatus: dividendsEstimateModel.DividendsAccountStatus,  
14 - PaymentStatus: dividendsEstimateModel.PaymentStatus,  
15 - DividendsAmount: dividendsAmount,  
16 - DividendsEstimateOrderNumber: dividendsEstimateModel.DividendsEstimateOrderNumber,  
17 - DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime,  
18 - DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType,  
19 - DividendsType: dividendsEstimateModel.DividendsType,  
20 - DividendsTypeName: dividendsEstimateModel.DividendsTypeName,  
21 - OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum,  
22 - CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber,  
23 - DividendsUser: dividendsEstimateModel.DividendsUser,  
24 - DividendsStage: dividendsEstimateModel.DividendsStage,  
25 - Org: dividendsEstimateModel.Org,  
26 - Company: dividendsEstimateModel.Company,  
27 - Operator: dividendsEstimateModel.Operator,  
28 - OperateTime: dividendsEstimateModel.OperateTime,  
29 - IsCanceled: dividendsEstimateModel.IsCanceled,  
30 - OrderGoodId: dividendsEstimateModel.OrderGoodId,  
31 - CreatedAt: dividendsEstimateModel.CreatedAt,  
32 - DeletedAt: dividendsEstimateModel.DeletedAt,  
33 - UpdatedAt: dividendsEstimateModel.UpdatedAt, 12 + DividendsEstimateId: dividendsEstimateModel.DividendsEstimateId,
  13 + DividendsAccountStatus: dividendsEstimateModel.DividendsAccountStatus,
  14 + PaymentStatus: dividendsEstimateModel.PaymentStatus,
  15 + DividendsAmount: dividendsAmount,
  16 + DividendsEstimateOrderNumber: dividendsEstimateModel.DividendsEstimateOrderNumber,
  17 + DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime,
  18 + DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType,
  19 + DividendsType: dividendsEstimateModel.DividendsType,
  20 + DividendsTypeName: dividendsEstimateModel.DividendsTypeName,
  21 + OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum,
  22 + CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber,
  23 + CooperationContractUndertakerId: dividendsEstimateModel.CooperationContractUndertakerId,
  24 + DividendsUser: dividendsEstimateModel.DividendsUser,
  25 + DividendsStage: dividendsEstimateModel.DividendsStage,
  26 + Org: dividendsEstimateModel.Org,
  27 + Company: dividendsEstimateModel.Company,
  28 + Operator: dividendsEstimateModel.Operator,
  29 + OperateTime: dividendsEstimateModel.OperateTime,
  30 + IsCanceled: dividendsEstimateModel.IsCanceled,
  31 + OrderGoodId: dividendsEstimateModel.OrderGoodId,
  32 + CreatedAt: dividendsEstimateModel.CreatedAt,
  33 + DeletedAt: dividendsEstimateModel.DeletedAt,
  34 + UpdatedAt: dividendsEstimateModel.UpdatedAt,
34 }, nil 35 }, nil
35 } 36 }
@@ -824,13 +824,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai @@ -824,13 +824,13 @@ func (repository *CooperationContractRepository) Save(cooperationContract *domai
824 } 824 }
825 } 825 }
826 // 返回新增的合约 826 // 返回新增的合约
827 - cooperationContractSaved, err := repository.FindOne(map[string]interface{}{  
828 - "cooperationContractId": cooperationContract.CooperationContractId,  
829 - })  
830 - if err != nil {  
831 - return nil, err  
832 - }  
833 - return cooperationContractSaved, nil 827 + //cooperationContractSaved, err := repository.FindOne(map[string]interface{}{
  828 + // "cooperationContractId": cooperationContract.CooperationContractId,
  829 + //})
  830 + //if err != nil {
  831 + // return nil, err
  832 + //}
  833 + return cooperationContract, nil
834 } 834 }
835 835
836 func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) { 836 func (repository *CooperationContractRepository) UpdateOne(cooperationContract *domain.CooperationContract) (*domain.CooperationContract, error) {
@@ -325,6 +325,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -325,6 +325,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
325 if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 { 325 if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
326 query.Where("cooperation_contract_number in (?)", pg.In(v)) 326 query.Where("cooperation_contract_number in (?)", pg.In(v))
327 } 327 }
  328 + if cooperationContractUndertakerId, ok := queryOptions["cooperationContractUndertakerId"]; ok && cooperationContractUndertakerId.(int64) != 0 {
  329 + query.Where("cooperation_contract_undertaker_id = ?", cooperationContractUndertakerId)
  330 + }
328 if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 { 331 if dividendsParticipateType, ok := queryOptions["dividendsParticipateType"]; ok && dividendsParticipateType.(int32) != 0 {
329 query.Where("dividends_participate_type = ?", dividendsParticipateType) 332 query.Where("dividends_participate_type = ?", dividendsParticipateType)
330 } 333 }
@@ -340,6 +343,10 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -340,6 +343,10 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
340 if dividendsUserId, ok := queryOptions["dividendsUserId"]; ok && dividendsUserId.(int64) != 0 { 343 if dividendsUserId, ok := queryOptions["dividendsUserId"]; ok && dividendsUserId.(int64) != 0 {
341 query.Where(`dividends_user @> '{"userId":"?"}'`, dividendsUserId) 344 query.Where(`dividends_user @> '{"userId":"?"}'`, dividendsUserId)
342 } 345 }
  346 + if dividendsUserIds, ok := queryOptions["dividendsUserIds"]; ok && len(dividendsUserIds.([]int64)) > 0 {
  347 + newDividendsUserIds := utils.SliceItoa(dividendsUserIds.([]int64))
  348 + query.Where("dividends_user->>'userId' in (?)", pg.In(newDividendsUserIds))
  349 + }
343 if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { 350 if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 {
344 query.Where(`dividends_user @> '{"userBaseId":"?"}'`, userBaseId) 351 query.Where(`dividends_user @> '{"userBaseId":"?"}'`, userBaseId)
345 } 352 }