Merge branch 'dev-chenzhiying' into dev
正在显示
8 个修改的文件
包含
152 行增加
和
4 行删除
@@ -44,6 +44,7 @@ type DividendsOrder struct { | @@ -44,6 +44,7 @@ type DividendsOrder struct { | ||
44 | 44 | ||
45 | type DividendsOrderRepository interface { | 45 | type DividendsOrderRepository interface { |
46 | Save(dividendsOrder *DividendsOrder) (*DividendsOrder, error) | 46 | Save(dividendsOrder *DividendsOrder) (*DividendsOrder, error) |
47 | + UpdateMany(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error) | ||
47 | Remove(dividendsOrder *DividendsOrder) (*DividendsOrder, error) | 48 | Remove(dividendsOrder *DividendsOrder) (*DividendsOrder, error) |
48 | BatchRemove(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error) | 49 | BatchRemove(dividendsOrders []*DividendsOrder) ([]*DividendsOrder, error) |
49 | FindOne(queryOptions map[string]interface{}) (*DividendsOrder, error) | 50 | FindOne(queryOptions map[string]interface{}) (*DividendsOrder, error) |
@@ -48,6 +48,7 @@ type DividendsReturnedOrder struct { | @@ -48,6 +48,7 @@ type DividendsReturnedOrder struct { | ||
48 | 48 | ||
49 | type DividendsReturnedOrderRepository interface { | 49 | type DividendsReturnedOrderRepository interface { |
50 | Save(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error) | 50 | Save(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error) |
51 | + UpdateMany(dividendsReturnedOrder []*DividendsReturnedOrder) ([]*DividendsReturnedOrder, error) | ||
51 | Remove(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error) | 52 | Remove(dividendsReturnedOrder *DividendsReturnedOrder) (*DividendsReturnedOrder, error) |
52 | BatchRemove(dividendsReturnedOrders []*DividendsReturnedOrder) ([]*DividendsReturnedOrder, error) | 53 | BatchRemove(dividendsReturnedOrders []*DividendsReturnedOrder) ([]*DividendsReturnedOrder, error) |
53 | FindOne(queryOptions map[string]interface{}) (*DividendsReturnedOrder, error) | 54 | FindOne(queryOptions map[string]interface{}) (*DividendsReturnedOrder, error) |
@@ -7,5 +7,5 @@ import ( | @@ -7,5 +7,5 @@ import ( | ||
7 | 7 | ||
8 | type CancelDividendsEstimate interface { | 8 | type CancelDividendsEstimate interface { |
9 | coreDomain.DomainEventPublisher | 9 | coreDomain.DomainEventPublisher |
10 | - CancelEstimate(dividendsEstimateId int64, operatorId int64) ([]*domain.DividendsEstimate, error) | 10 | + CancelEstimate(dividendsEstimateIds []int64, operatorId int64) ([]*domain.DividendsEstimate, error) |
11 | } | 11 | } |
@@ -2,9 +2,13 @@ package domain_service | @@ -2,9 +2,13 @@ package domain_service | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/linmadan/egglib-go/core/application" | ||
5 | coreDomain "github.com/linmadan/egglib-go/core/domain" | 6 | coreDomain "github.com/linmadan/egglib-go/core/domain" |
6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
7 | "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/domain/service" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | ||
8 | ) | 12 | ) |
9 | 13 | ||
10 | type CancelDividendsEstimateService struct { | 14 | type CancelDividendsEstimateService struct { |
@@ -12,7 +16,126 @@ type CancelDividendsEstimateService struct { | @@ -12,7 +16,126 @@ type CancelDividendsEstimateService struct { | ||
12 | transactionContext *pgTransaction.TransactionContext | 16 | transactionContext *pgTransaction.TransactionContext |
13 | } | 17 | } |
14 | 18 | ||
15 | -func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEstimateId int64, operatorId int64) ([]*domain.DividendsEstimate, error) { | 19 | +func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEstimateIds []int64, operatorId int64) ([]*domain.DividendsEstimate, error) { |
20 | + var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储 | ||
21 | + var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 | ||
22 | + var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 | ||
23 | + var userService service.UserService // 用户服务 | ||
24 | + | ||
25 | + // 分红预算单仓储初始化 | ||
26 | + if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil { | ||
27 | + return nil, err | ||
28 | + } else { | ||
29 | + dividendsEstimateRepository = repo | ||
30 | + } | ||
31 | + // 分红订单仓储初始化 | ||
32 | + if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil { | ||
33 | + return nil, err | ||
34 | + } else { | ||
35 | + dividendsOrderRepository = repo | ||
36 | + } | ||
37 | + // 分红退后单仓储初始化 | ||
38 | + if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil { | ||
39 | + return nil, err | ||
40 | + } else { | ||
41 | + dividendsReturnedOrderRepository = repo | ||
42 | + } | ||
43 | + // 用户服务初始化 | ||
44 | + if value, err := NewUserService(); err != nil { | ||
45 | + userService = value | ||
46 | + } | ||
47 | + | ||
48 | + // 获取操作人 | ||
49 | + var operator *domain.User | ||
50 | + if data, err := userService.OperatorFrom(0, 0, operatorId); err != nil { | ||
51 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
52 | + } else { | ||
53 | + operator = data | ||
54 | + } | ||
55 | + | ||
56 | + // 获取分红预算单 | ||
57 | + if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{ | ||
58 | + "dividendsEstimateIds": dividendsEstimateIds, | ||
59 | + }); err != nil { | ||
60 | + return nil, err | ||
61 | + } else { | ||
62 | + if count > 0 { | ||
63 | + var dividendsEstimatesCanceled []*domain.DividendsEstimate | ||
64 | + var orderOrReturnOrderNums []string | ||
65 | + for _, dividendsEstimate := range dividendsEstimates { | ||
66 | + // 根据当前分红预算单的分红订单号或退货单号获取分红预算单 | ||
67 | + if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{ | ||
68 | + "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum, | ||
69 | + }); err2 != nil { | ||
70 | + return nil, err2 | ||
71 | + } else { | ||
72 | + if countRelative > 0 { | ||
73 | + for i, _ := range dividendsEstimatesRelative { | ||
74 | + dividendsEstimatesRelative[i].IsCanceled = true | ||
75 | + dividendsEstimatesRelative[i].Operator = operator | ||
76 | + // 获取相关订单/退货单号 | ||
77 | + orderOrReturnOrderNums = append(orderOrReturnOrderNums, dividendsEstimatesRelative[i].OrderOrReturnedOrderNum) | ||
78 | + } | ||
79 | + dividendsEstimatesRelativeCanceled, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimatesRelative) | ||
80 | + if err3 != nil { | ||
81 | + return nil, err3 | ||
82 | + } | ||
83 | + dividendsEstimatesCanceled = append(dividendsEstimatesCanceled, dividendsEstimatesRelativeCanceled...) | ||
84 | + } | ||
85 | + } | ||
86 | + } | ||
87 | + | ||
88 | + // 分红订单或分红退货单状态变更 | ||
89 | + var orderNums []string | ||
90 | + var returnedOrderNums []string | ||
91 | + | ||
92 | + // 订单/退货单号数组去重 | ||
93 | + orderOrReturnOrderNumsWithoutDup := utils.RemoveDuplication(orderOrReturnOrderNums) | ||
94 | + for _, orderNullNum := range orderOrReturnOrderNumsWithoutDup { | ||
95 | + if orderNullNum[0:2] == "RE" { // 分红退后单 | ||
96 | + returnedOrderNums = append(returnedOrderNums, orderNullNum) | ||
97 | + } else if orderNullNum[0:2] == "FH" { // 分红订单 | ||
98 | + orderNums = append(orderNums, orderNullNum) | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + // 获取分红订单 | ||
103 | + if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{ | ||
104 | + "dividendsOrderNumbers": orderNums, | ||
105 | + }); err4 != nil { | ||
106 | + return nil, err4 | ||
107 | + } else { | ||
108 | + if countDividendsOrder > 0 { | ||
109 | + for i, _ := range orders { | ||
110 | + orders[i].DividendStatus = 1 | ||
111 | + } | ||
112 | + // 保存订单状态 | ||
113 | + if _, err6 := dividendsOrderRepository.UpdateMany(orders); err6 != nil { | ||
114 | + return nil, err6 | ||
115 | + } | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + // 获取分红退货单 | ||
120 | + if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{ | ||
121 | + "dividendsReturnedOrderNumbers": returnedOrderNums, | ||
122 | + }); err5 != nil { | ||
123 | + return nil, err5 | ||
124 | + } else { | ||
125 | + if countDividendsReturnedOrder > 0 { | ||
126 | + for i, _ := range returnedOrders { | ||
127 | + returnedOrders[i].DividendStatus = 1 | ||
128 | + } | ||
129 | + // 保存退货单状态 | ||
130 | + if _, err7 := dividendsReturnedOrderRepository.UpdateMany(returnedOrders); err7 != nil { | ||
131 | + return nil, err7 | ||
132 | + } | ||
133 | + } | ||
134 | + } | ||
135 | + | ||
136 | + return dividendsEstimatesCanceled, nil | ||
137 | + } | ||
138 | + } | ||
16 | return nil, nil | 139 | return nil, nil |
17 | } | 140 | } |
18 | 141 |
@@ -32,12 +32,13 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -32,12 +32,13 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
32 | } else { | 32 | } else { |
33 | dividendsOrderRepository = repo | 33 | dividendsOrderRepository = repo |
34 | } | 34 | } |
35 | - // 分红退后单仓储初始化 | 35 | + // 分红退货单仓储初始化 |
36 | if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil { | 36 | if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil { |
37 | return nil, err | 37 | return nil, err |
38 | } else { | 38 | } else { |
39 | dividendsReturnedOrderRepository = repo | 39 | dividendsReturnedOrderRepository = repo |
40 | } | 40 | } |
41 | + // 确认业绩分红预算 | ||
41 | var dividendsEstimateDetails []*service.DividendsEstimateDetail | 42 | var dividendsEstimateDetails []*service.DividendsEstimateDetail |
42 | for _, orderGood := range orderGoods { | 43 | for _, orderGood := range orderGoods { |
43 | // 获取合约 | 44 | // 获取合约 |
@@ -251,6 +251,10 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | @@ -251,6 +251,10 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | ||
251 | return dividendsOrder, nil | 251 | return dividendsOrder, nil |
252 | } | 252 | } |
253 | 253 | ||
254 | +func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) { | ||
255 | + panic("implement me") | ||
256 | +} | ||
257 | + | ||
254 | func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.DividendsOrder) (*domain.DividendsOrder, error) { | 258 | func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.DividendsOrder) (*domain.DividendsOrder, error) { |
255 | tx := repository.transactionContext.PgTx | 259 | tx := repository.transactionContext.PgTx |
256 | dividendsOrderModel := new(models.DividendsOrder) | 260 | dividendsOrderModel := new(models.DividendsOrder) |
@@ -263,6 +263,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | @@ -263,6 +263,10 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | ||
263 | return dividendsReturnedOrder, nil | 263 | return dividendsReturnedOrder, nil |
264 | } | 264 | } |
265 | 265 | ||
266 | +func (repository *DividendsReturnedOrderRepository) UpdateMany(dividendsReturnedOrder []*domain.DividendsReturnedOrder) ([]*domain.DividendsReturnedOrder, error) { | ||
267 | + panic("implement me") | ||
268 | +} | ||
269 | + | ||
266 | func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrder *domain.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) { | 270 | func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrder *domain.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) { |
267 | tx := repository.transactionContext.PgTx | 271 | tx := repository.transactionContext.PgTx |
268 | dividendsReturnedOrderModel := new(models.DividendsReturnedOrder) | 272 | dividendsReturnedOrderModel := new(models.DividendsReturnedOrder) |
@@ -96,7 +96,21 @@ func NumberToCNNumber(num int) string { | @@ -96,7 +96,21 @@ func NumberToCNNumber(num int) string { | ||
96 | chinese = copyChinese | 96 | chinese = copyChinese |
97 | } | 97 | } |
98 | } | 98 | } |
99 | - | ||
100 | return "第" + chinese + "阶段" | 99 | return "第" + chinese + "阶段" |
100 | +} | ||
101 | 101 | ||
102 | +// RemoveDuplication 数组去重 | ||
103 | +func RemoveDuplication(arr []string) []string { | ||
104 | + set := make(map[string]struct{}, len(arr)) | ||
105 | + j := 0 | ||
106 | + for _, v := range arr { | ||
107 | + _, ok := set[v] | ||
108 | + if ok { | ||
109 | + continue | ||
110 | + } | ||
111 | + set[v] = struct{}{} | ||
112 | + arr[j] = v | ||
113 | + j++ | ||
114 | + } | ||
115 | + return arr[:j] | ||
102 | } | 116 | } |
-
请 注册 或 登录 后发表评论