Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…
…ion-cooperation into dev
正在显示
12 个修改的文件
包含
191 行增加
和
45 行删除
@@ -147,12 +147,14 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | @@ -147,12 +147,14 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | ||
147 | // 预算明细 | 147 | // 预算明细 |
148 | var creditAccounts []*domain.CreditAccount | 148 | var creditAccounts []*domain.CreditAccount |
149 | var accountDetail []*domain.AccountDetail | 149 | var accountDetail []*domain.AccountDetail |
150 | + var settlementAmount float64 | ||
150 | for _, dividendsEstimate := range dividendsEstimates { | 151 | for _, dividendsEstimate := range dividendsEstimates { |
151 | accountDetail = append(accountDetail, &domain.AccountDetail{ | 152 | accountDetail = append(accountDetail, &domain.AccountDetail{ |
152 | DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber, | 153 | DividendsEstimateOrderNumber: dividendsEstimate.DividendsEstimateOrderNumber, |
153 | DividendsType: dividendsEstimate.DividendsType, | 154 | DividendsType: dividendsEstimate.DividendsType, |
154 | DividendsAmount: dividendsEstimate.DividendsAmount, | 155 | DividendsAmount: dividendsEstimate.DividendsAmount, |
155 | }) | 156 | }) |
157 | + settlementAmount = settlementAmount + dividendsEstimate.DividendsAmount | ||
156 | } | 158 | } |
157 | 159 | ||
158 | // 生成账期结算单号 | 160 | // 生成账期结算单号 |
@@ -167,7 +169,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | @@ -167,7 +169,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | ||
167 | CreditAccountOrderNum: creditAccountNumber, | 169 | CreditAccountOrderNum: creditAccountNumber, |
168 | PaymentStatus: 1, | 170 | PaymentStatus: 1, |
169 | PaymentTime: time.Time{}, | 171 | PaymentTime: time.Time{}, |
170 | - SettlementAmount: dividendsEstimates[0].DividendsAmount, | 172 | + SettlementAmount: settlementAmount, |
171 | SettlementTime: time.Now(), | 173 | SettlementTime: time.Now(), |
172 | Participator: &domain.Participator{ // 共创参与 | 174 | Participator: &domain.Participator{ // 共创参与 |
173 | UserId: dividendsEstimates[0].DividendsUser.UserId, | 175 | UserId: dividendsEstimates[0].DividendsUser.UserId, |
@@ -183,7 +185,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | @@ -183,7 +185,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | ||
183 | Status: dividendsEstimates[0].DividendsUser.Status, | 185 | Status: dividendsEstimates[0].DividendsUser.Status, |
184 | Company: dividendsEstimates[0].DividendsUser.Company, | 186 | Company: dividendsEstimates[0].DividendsUser.Company, |
185 | }, | 187 | }, |
186 | - AccountDetail: accountDetail, | 188 | + AccountDetail: accountDetail, // 结算明细,多笔分红预算单 |
187 | PaymentDocumentAttachment: nil, | 189 | PaymentDocumentAttachment: nil, |
188 | Org: organization, | 190 | Org: organization, |
189 | Company: company, | 191 | Company: company, |
@@ -318,8 +320,11 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | @@ -318,8 +320,11 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | ||
318 | defer func() { | 320 | defer func() { |
319 | _ = transactionContext.RollbackTransaction() | 321 | _ = transactionContext.RollbackTransaction() |
320 | }() | 322 | }() |
323 | + | ||
321 | // 参数类型转换 | 324 | // 参数类型转换 |
322 | creditAccountId, _ := strconv.ParseInt(payCreditAccountCommand.CreditAccountId, 10, 64) | 325 | creditAccountId, _ := strconv.ParseInt(payCreditAccountCommand.CreditAccountId, 10, 64) |
326 | + | ||
327 | + // 账期结算仓储初始化 | ||
323 | var creditAccountRepository domain.CreditAccountRepository | 328 | var creditAccountRepository domain.CreditAccountRepository |
324 | if value, err1 := factory.CreateCreditAccountRepository(map[string]interface{}{ | 329 | if value, err1 := factory.CreateCreditAccountRepository(map[string]interface{}{ |
325 | "transactionContext": transactionContext, | 330 | "transactionContext": transactionContext, |
@@ -328,6 +333,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | @@ -328,6 +333,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | ||
328 | } else { | 333 | } else { |
329 | creditAccountRepository = value | 334 | creditAccountRepository = value |
330 | } | 335 | } |
336 | + | ||
331 | // 获取待支付的账期结算单 | 337 | // 获取待支付的账期结算单 |
332 | creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": creditAccountId}) | 338 | creditAccount, err := creditAccountRepository.FindOne(map[string]interface{}{"creditAccountId": creditAccountId}) |
333 | if err != nil { | 339 | if err != nil { |
@@ -339,8 +345,11 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | @@ -339,8 +345,11 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | ||
339 | if err2 := creditAccount.Update(tool_funs.SimpleStructToMap(payCreditAccountCommand)); err2 != nil { | 345 | if err2 := creditAccount.Update(tool_funs.SimpleStructToMap(payCreditAccountCommand)); err2 != nil { |
340 | return nil, application.ThrowError(application.BUSINESS_ERROR, err2.Error()) | 346 | return nil, application.ThrowError(application.BUSINESS_ERROR, err2.Error()) |
341 | } | 347 | } |
342 | - // 支付状态设置 | 348 | + |
349 | + // 支付更新设置 | ||
343 | creditAccount.PaymentStatus = 2 | 350 | creditAccount.PaymentStatus = 2 |
351 | + creditAccount.PaymentTime = time.Now() | ||
352 | + | ||
344 | if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil { | 353 | if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil { |
345 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error()) | 354 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error()) |
346 | } else { | 355 | } else { |
@@ -188,6 +188,22 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat | @@ -188,6 +188,22 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat | ||
188 | cancelDividendsEstimateService = value | 188 | cancelDividendsEstimateService = value |
189 | } | 189 | } |
190 | 190 | ||
191 | + // 用户REST服务初始化 | ||
192 | + var userService service.UserService | ||
193 | + if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil { | ||
194 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
195 | + } else { | ||
196 | + userService = value | ||
197 | + } | ||
198 | + | ||
199 | + // 获取操作人 | ||
200 | + var operator *domain.User | ||
201 | + if data, err := userService.OperatorFrom(cancelDividendsEstimateCommand.CompanyId, cancelDividendsEstimateCommand.OrgId, cancelDividendsEstimateCommand.UserId); err != nil { | ||
202 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取操作人失败") | ||
203 | + } else { | ||
204 | + operator = data | ||
205 | + } | ||
206 | + | ||
191 | // 分红预算仓储初始化 | 207 | // 分红预算仓储初始化 |
192 | var dividendsEstimateRepository domain.DividendsEstimateRepository | 208 | var dividendsEstimateRepository domain.DividendsEstimateRepository |
193 | if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{ | 209 | if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{ |
@@ -235,7 +251,7 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat | @@ -235,7 +251,7 @@ func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimat | ||
235 | } | 251 | } |
236 | 252 | ||
237 | // 取消分红预算 | 253 | // 取消分红预算 |
238 | - if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate([]int64{cancelDividendsEstimateCommand.DividendsEstimateId}, cancelDividendsEstimateCommand.UserId); err != nil { | 254 | + if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate([]int64{cancelDividendsEstimateCommand.DividendsEstimateId}, operator); err != nil { |
239 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 255 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
240 | } else { | 256 | } else { |
241 | if err := transactionContext.CommitTransaction(); err != nil { | 257 | if err := transactionContext.CommitTransaction(); err != nil { |
@@ -271,6 +287,22 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs | @@ -271,6 +287,22 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs | ||
271 | cancelDividendsEstimateService = value | 287 | cancelDividendsEstimateService = value |
272 | } | 288 | } |
273 | 289 | ||
290 | + // 用户REST服务初始化 | ||
291 | + var userService service.UserService | ||
292 | + if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil { | ||
293 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
294 | + } else { | ||
295 | + userService = value | ||
296 | + } | ||
297 | + | ||
298 | + // 获取操作人 | ||
299 | + var operator *domain.User | ||
300 | + if data, err := userService.OperatorFrom(batchCancelEstimateCommand.CompanyId, batchCancelEstimateCommand.OrgId, batchCancelEstimateCommand.UserId); err != nil { | ||
301 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取操作人失败") | ||
302 | + } else { | ||
303 | + operator = data | ||
304 | + } | ||
305 | + | ||
274 | // 分红预算仓储初始化 | 306 | // 分红预算仓储初始化 |
275 | var dividendsEstimateRepository domain.DividendsEstimateRepository | 307 | var dividendsEstimateRepository domain.DividendsEstimateRepository |
276 | if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{ | 308 | if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{ |
@@ -324,7 +356,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs | @@ -324,7 +356,7 @@ func (dividendsEstimateService *DividendsEstimateService) BatchCancelDividendsEs | ||
324 | } | 356 | } |
325 | } | 357 | } |
326 | // 批量取消分红预算单 | 358 | // 批量取消分红预算单 |
327 | - if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, batchCancelEstimateCommand.UserId); err != nil { | 359 | + if dividendsEstimatesCanceled, err := cancelDividendsEstimateService.CancelEstimate(dividendsEstimateIds, operator); err != nil { |
328 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 360 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
329 | } else { | 361 | } else { |
330 | if err := transactionContext.CommitTransaction(); err != nil { | 362 | if err := transactionContext.CommitTransaction(); err != nil { |
@@ -629,10 +629,13 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD | @@ -629,10 +629,13 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD | ||
629 | // 获取分红订单 | 629 | // 获取分红订单 |
630 | dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": updateDividendsOrderCommand.DividendsOrderId}) | 630 | dividendsOrder, err := dividendsOrderRepository.FindOne(map[string]interface{}{"dividendsOrderId": updateDividendsOrderCommand.DividendsOrderId}) |
631 | if err != nil { | 631 | if err != nil { |
632 | - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 632 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单不存在") |
633 | + } | ||
634 | + if dividendsOrder == nil { | ||
635 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId))) | ||
633 | } | 636 | } |
634 | 637 | ||
635 | - // 新增订单产品 | 638 | + // 获取订单产品 |
636 | var orderGoods []*domain.OrderGood | 639 | var orderGoods []*domain.OrderGood |
637 | var dividendsOrderAmount float64 | 640 | var dividendsOrderAmount float64 |
638 | for _, orderGood := range updateDividendsOrderCommand.OrderGoods { | 641 | for _, orderGood := range updateDividendsOrderCommand.OrderGoods { |
@@ -660,9 +663,6 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD | @@ -660,9 +663,6 @@ func (dividendsOrderService *DividendsOrderService) UpdateDividendsOrder(updateD | ||
660 | dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount | 663 | dividendsOrderAmount = dividendsOrderAmount + orderGood.OrderGoodAmount |
661 | } | 664 | } |
662 | 665 | ||
663 | - if dividendsOrder == nil { | ||
664 | - return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsOrderCommand.DividendsOrderId))) | ||
665 | - } | ||
666 | if err := dividendsOrder.Update(tool_funs.SimpleStructToMap(updateDividendsOrderCommand)); err != nil { | 666 | if err := dividendsOrder.Update(tool_funs.SimpleStructToMap(updateDividendsOrderCommand)); err != nil { |
667 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 667 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
668 | } | 668 | } |
@@ -9,6 +9,8 @@ import ( | @@ -9,6 +9,8 @@ import ( | ||
9 | ) | 9 | ) |
10 | 10 | ||
11 | type OrderGoods struct { | 11 | type OrderGoods struct { |
12 | + // 退货单产品ID | ||
13 | + OrderGoodId string `json:"orderGoodId"` | ||
12 | // 订单产品金额 | 14 | // 订单产品金额 |
13 | OrderGoodAmount float64 `cname:"订单产品金额" json:"orderGoodAmount"` | 15 | OrderGoodAmount float64 `cname:"订单产品金额" json:"orderGoodAmount"` |
14 | // 订单产品名称 | 16 | // 订单产品名称 |
@@ -2,11 +2,9 @@ package command | @@ -2,11 +2,9 @@ package command | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | + "github.com/beego/beego/v2/core/validation" | ||
5 | "reflect" | 6 | "reflect" |
6 | "strings" | 7 | "strings" |
7 | - "time" | ||
8 | - | ||
9 | - "github.com/beego/beego/v2/core/validation" | ||
10 | ) | 8 | ) |
11 | 9 | ||
12 | type UpdateDividendsReturnedOrderCommand struct { | 10 | type UpdateDividendsReturnedOrderCommand struct { |
@@ -21,7 +19,7 @@ type UpdateDividendsReturnedOrderCommand struct { | @@ -21,7 +19,7 @@ type UpdateDividendsReturnedOrderCommand struct { | ||
21 | // 备注 | 19 | // 备注 |
22 | Remarks string `cname:"备注" json:"remarks" valid:"Required"` | 20 | Remarks string `cname:"备注" json:"remarks" valid:"Required"` |
23 | // 退货日期 | 21 | // 退货日期 |
24 | - DividendsReturnedDate time.Time `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"` | 22 | + DividendsReturnedDate string `cname:"退货日期" json:"dividendsReturnedDate" valid:"Required"` |
25 | // 退货区域 | 23 | // 退货区域 |
26 | RegionName string `cname:"退货区域" json:"regionName,omitempty"` | 24 | RegionName string `cname:"退货区域" json:"regionName,omitempty"` |
27 | // 订单产品列表 | 25 | // 订单产品列表 |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" |
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" |
13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" |
14 | + "strconv" | ||
14 | "time" | 15 | "time" |
15 | ) | 16 | ) |
16 | 17 | ||
@@ -543,6 +544,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide | @@ -543,6 +544,8 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide | ||
543 | defer func() { | 544 | defer func() { |
544 | _ = transactionContext.RollbackTransaction() | 545 | _ = transactionContext.RollbackTransaction() |
545 | }() | 546 | }() |
547 | + | ||
548 | + // 分红退货单仓储初始化 | ||
546 | var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository | 549 | var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository |
547 | if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{ | 550 | if value, err := factory.CreateDividendsReturnedOrderRepository(map[string]interface{}{ |
548 | "transactionContext": transactionContext, | 551 | "transactionContext": transactionContext, |
@@ -551,6 +554,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide | @@ -551,6 +554,15 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide | ||
551 | } else { | 554 | } else { |
552 | dividendsReturnedOrderRepository = value | 555 | dividendsReturnedOrderRepository = value |
553 | } | 556 | } |
557 | + | ||
558 | + // 退货单时间转换 | ||
559 | + dividendsReturnedDateInt, err := strconv.ParseInt(updateDividendsReturnedOrderCommand.DividendsReturnedDate, 10, 64) | ||
560 | + if err != nil { | ||
561 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "订单时间错误") | ||
562 | + } | ||
563 | + dividendsReturnedDate := utils.TransformTimestampToTime(dividendsReturnedDateInt) | ||
564 | + | ||
565 | + // 获取分红退货单 | ||
554 | dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId}) | 566 | dividendsReturnedOrder, err := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{"dividendsReturnedOrderId": updateDividendsReturnedOrderCommand.DividendsReturnedOrderId}) |
555 | if err != nil { | 567 | if err != nil { |
556 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 568 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
@@ -558,16 +570,51 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide | @@ -558,16 +570,51 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) UpdateDivide | ||
558 | if dividendsReturnedOrder == nil { | 570 | if dividendsReturnedOrder == nil { |
559 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsReturnedOrderCommand.DividendsReturnedOrderId))) | 571 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateDividendsReturnedOrderCommand.DividendsReturnedOrderId))) |
560 | } | 572 | } |
573 | + | ||
574 | + // 获取订单产品 | ||
575 | + var orderGoods []*domain.OrderGood | ||
576 | + var dividendsReturnedOrderAmount float64 | ||
577 | + for _, orderGood := range updateDividendsReturnedOrderCommand.OrderGoods { | ||
578 | + // 产品ID类型转换 | ||
579 | + orderGoodId, err3 := strconv.ParseInt(orderGood.OrderGoodId, 10, 64) | ||
580 | + if err3 != nil { | ||
581 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error()) | ||
582 | + } | ||
583 | + orderGoods = append(orderGoods, &domain.OrderGood{ | ||
584 | + OrderGoodId: orderGoodId, | ||
585 | + OrderGoodAmount: orderGood.OrderGoodAmount, | ||
586 | + OrderGoodName: orderGood.OrderGoodName, | ||
587 | + OrderGoodPrice: orderGood.OrderGoodPrice, | ||
588 | + OrderGoodQuantity: orderGood.OrderGoodQuantity, | ||
589 | + DividendsOrderNumber: "", | ||
590 | + DividendsReturnedOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber, | ||
591 | + CooperationContractNumber: orderGood.CooperationContractNumber, | ||
592 | + OrderGoodExpense: orderGood.OrderGoodExpense, | ||
593 | + OrgId: updateDividendsReturnedOrderCommand.OrgId, | ||
594 | + CompanyId: updateDividendsReturnedOrderCommand.CompanyId, | ||
595 | + CreatedAt: time.Time{}, | ||
596 | + UpdatedAt: time.Now(), | ||
597 | + }) | ||
598 | + // 计算分红退货单金额 | ||
599 | + dividendsReturnedOrderAmount = dividendsReturnedOrderAmount + orderGood.OrderGoodAmount | ||
600 | + } | ||
601 | + | ||
561 | if err := dividendsReturnedOrder.Update(tool_funs.SimpleStructToMap(updateDividendsReturnedOrderCommand)); err != nil { | 602 | if err := dividendsReturnedOrder.Update(tool_funs.SimpleStructToMap(updateDividendsReturnedOrderCommand)); err != nil { |
562 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 603 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
563 | } | 604 | } |
564 | - if dividendsReturnedOrder, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); err != nil { | 605 | + |
606 | + dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate | ||
607 | + dividendsReturnedOrder.DividendsReturnedOrderRefund = dividendsReturnedOrderAmount | ||
608 | + dividendsReturnedOrder.Goods = orderGoods | ||
609 | + | ||
610 | + // 保存分红退货单更新 | ||
611 | + if dividendsReturnedOrderSaved, err := dividendsReturnedOrderRepository.Save(dividendsReturnedOrder); err != nil { | ||
565 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 612 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
566 | } else { | 613 | } else { |
567 | if err := transactionContext.CommitTransaction(); err != nil { | 614 | if err := transactionContext.CommitTransaction(); err != nil { |
568 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 615 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
569 | } | 616 | } |
570 | - return dividendsReturnedOrder, nil | 617 | + return dividendsReturnedOrderSaved, nil |
571 | } | 618 | } |
572 | } | 619 | } |
573 | 620 |
@@ -72,9 +72,6 @@ func (dividendsReturnedOrder *DividendsReturnedOrder) Update(data map[string]int | @@ -72,9 +72,6 @@ func (dividendsReturnedOrder *DividendsReturnedOrder) Update(data map[string]int | ||
72 | if dividendsReturnedCustomerName, ok := data["dividendsReturnedCustomerName"]; ok { | 72 | if dividendsReturnedCustomerName, ok := data["dividendsReturnedCustomerName"]; ok { |
73 | dividendsReturnedOrder.DividendsReturnedCustomerName = dividendsReturnedCustomerName.(string) | 73 | dividendsReturnedOrder.DividendsReturnedCustomerName = dividendsReturnedCustomerName.(string) |
74 | } | 74 | } |
75 | - if dividendsReturnedDate, ok := data["dividendsReturnedDate"]; ok { | ||
76 | - dividendsReturnedOrder.DividendsReturnedDate = dividendsReturnedDate.(time.Time) | ||
77 | - } | ||
78 | if regionNumber, ok := data["regionNumber"]; ok { | 75 | if regionNumber, ok := data["regionNumber"]; ok { |
79 | dividendsReturnedOrder.Region.RegionNumber = regionNumber.(string) | 76 | dividendsReturnedOrder.Region.RegionNumber = regionNumber.(string) |
80 | } | 77 | } |
@@ -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(dividendsEstimateIds []int64, operatorId int64) ([]*domain.DividendsEstimate, error) | 10 | + CancelEstimate(dividendsEstimateIds []int64, operator *domain.User) ([]*domain.DividendsEstimate, error) |
11 | } | 11 | } |
@@ -2,11 +2,9 @@ package domain_service | @@ -2,11 +2,9 @@ package domain_service | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | - "github.com/linmadan/egglib-go/core/application" | ||
6 | coreDomain "github.com/linmadan/egglib-go/core/domain" | 5 | coreDomain "github.com/linmadan/egglib-go/core/domain" |
7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | 7 | "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" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" |
11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" |
12 | ) | 10 | ) |
@@ -16,11 +14,10 @@ type CancelDividendsEstimateService struct { | @@ -16,11 +14,10 @@ type CancelDividendsEstimateService struct { | ||
16 | transactionContext *pgTransaction.TransactionContext | 14 | transactionContext *pgTransaction.TransactionContext |
17 | } | 15 | } |
18 | 16 | ||
19 | -func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEstimateIds []int64, operatorId int64) ([]*domain.DividendsEstimate, error) { | 17 | +func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEstimateIds []int64, operator *domain.User) ([]*domain.DividendsEstimate, error) { |
20 | var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储 | 18 | var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储 |
21 | var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 | 19 | var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 |
22 | var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 | 20 | var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 |
23 | - var userService service.UserService // 用户服务 | ||
24 | 21 | ||
25 | // 分红预算单仓储初始化 | 22 | // 分红预算单仓储初始化 |
26 | if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil { | 23 | if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil { |
@@ -40,18 +37,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | @@ -40,18 +37,6 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | ||
40 | } else { | 37 | } else { |
41 | dividendsReturnedOrderRepository = repo | 38 | dividendsReturnedOrderRepository = repo |
42 | } | 39 | } |
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 | 40 | ||
56 | // 获取分红预算单 | 41 | // 获取分红预算单 |
57 | if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{ | 42 | if count, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{ |
@@ -232,7 +232,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []* | @@ -232,7 +232,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []* | ||
232 | if _, err := tx.Model(÷ndsEstimateModels).WherePK().Update(); err != nil { | 232 | if _, err := tx.Model(÷ndsEstimateModels).WherePK().Update(); err != nil { |
233 | return nil, err | 233 | return nil, err |
234 | } | 234 | } |
235 | - dividendsEstimatesUpdated := []*domain.DividendsEstimate{} | 235 | + var dividendsEstimatesUpdated []*domain.DividendsEstimate |
236 | for _, dividendsEstimateModel := range dividendsEstimateModels { | 236 | for _, dividendsEstimateModel := range dividendsEstimateModels { |
237 | if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil { | 237 | if dividendsEstimate, err := transform.TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel); err != nil { |
238 | return dividendsEstimates, err | 238 | return dividendsEstimates, err |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | "github.com/go-pg/pg/v10" | 5 | "github.com/go-pg/pg/v10" |
6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | 6 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" |
7 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/log" | ||
7 | "time" | 8 | "time" |
8 | 9 | ||
9 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" | 10 | "github.com/linmadan/egglib-go/persistent/pg/sqlbuilder" |
@@ -208,15 +209,20 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | @@ -208,15 +209,20 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | ||
208 | OrgId: goodDomain.OrgId, | 209 | OrgId: goodDomain.OrgId, |
209 | CompanyId: goodDomain.CompanyId, | 210 | CompanyId: goodDomain.CompanyId, |
210 | OrderGoodDividendsStatus: goodDomain.OrderGoodDividendsStatus, | 211 | OrderGoodDividendsStatus: goodDomain.OrderGoodDividendsStatus, |
211 | - CreatedAt: time.Time{}, | 212 | + CreatedAt: time.Now(), |
212 | DeletedAt: time.Time{}, | 213 | DeletedAt: time.Time{}, |
213 | - UpdatedAt: time.Now(), | 214 | + UpdatedAt: time.Time{}, |
214 | }) | 215 | }) |
215 | } | 216 | } |
216 | // 添加分红订单产品 | 217 | // 添加分红订单产品 |
218 | + log.Logger.Info("待添加的分红订单产品", map[string]interface{}{ | ||
219 | + "orderGoodsToAddModels": orderGoodsToAddModels, | ||
220 | + }) | ||
221 | + if len(orderGoodsToAddModels) > 0 { | ||
217 | if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil { | 222 | if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil { |
218 | return nil, err | 223 | return nil, err |
219 | } | 224 | } |
225 | + } | ||
220 | 226 | ||
221 | // 待更新或者删除的ids | 227 | // 待更新或者删除的ids |
222 | var orderGoodIdsToUpdateOrDelete []int64 | 228 | var orderGoodIdsToUpdateOrDelete []int64 |
@@ -234,9 +240,14 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | @@ -234,9 +240,14 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | ||
234 | } | 240 | } |
235 | } | 241 | } |
236 | } | 242 | } |
243 | + log.Logger.Info("待更新的分红订单产品", map[string]interface{}{ | ||
244 | + "orderGoodModelsToUpdate": orderGoodModelsToUpdate, | ||
245 | + }) | ||
246 | + if len(orderGoodModelsToUpdate) > 0 { | ||
237 | if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil { | 247 | if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil { |
238 | return nil, err | 248 | return nil, err |
239 | } | 249 | } |
250 | + } | ||
240 | 251 | ||
241 | // 待删除的分红订单产品id | 252 | // 待删除的分红订单产品id |
242 | orderGoodIdsToDelete := utils.Difference(orderGoodIdsFetched, orderGoodIdsToUpdateOrDelete) | 253 | orderGoodIdsToDelete := utils.Difference(orderGoodIdsFetched, orderGoodIdsToUpdateOrDelete) |
@@ -248,15 +259,46 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | @@ -248,15 +259,46 @@ func (repository *DividendsOrderRepository) Save(dividendsOrder *domain.Dividend | ||
248 | } | 259 | } |
249 | } | 260 | } |
250 | } | 261 | } |
251 | - if _, err := tx.Model(&orderGoodModelsToDelete).WherePK().Delete(); err != nil { | 262 | + log.Logger.Info("待删除的订单产品", map[string]interface{}{ |
263 | + "orderGoodModelsToDelete": orderGoodModelsToDelete, | ||
264 | + }) | ||
265 | + if len(orderGoodModelsToDelete) > 0 { | ||
266 | + if _, err := tx.Model(&orderGoodModelsToDelete).Delete(); err != nil { | ||
252 | return nil, err | 267 | return nil, err |
253 | } | 268 | } |
254 | } | 269 | } |
270 | + } | ||
255 | return dividendsOrder, nil | 271 | return dividendsOrder, nil |
256 | } | 272 | } |
257 | 273 | ||
258 | func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) { | 274 | func (repository *DividendsOrderRepository) UpdateMany(dividendsOrders []*domain.DividendsOrder) ([]*domain.DividendsOrder, error) { |
259 | - panic("implement me") | 275 | + tx := repository.transactionContext.PgTx |
276 | + var dividendsOrderModels []*models.DividendsOrder | ||
277 | + for _, dividendsOrder := range dividendsOrders { | ||
278 | + dividendsOrderModels = append(dividendsOrderModels, &models.DividendsOrder{ | ||
279 | + DividendsOrderId: dividendsOrder.DividendsOrderId, | ||
280 | + DividendsOrderNumber: dividendsOrder.DividendsOrderNumber, | ||
281 | + DividendsOriginalOrderNum: dividendsOrder.DividendsOriginalOrderNum, | ||
282 | + DividendsOrderAmount: dividendsOrder.DividendsOrderAmount, | ||
283 | + OrderTime: dividendsOrder.OrderTime, | ||
284 | + DividendTime: dividendsOrder.DividendTime, | ||
285 | + DividendStatus: dividendsOrder.DividendStatus, | ||
286 | + Region: dividendsOrder.Region, | ||
287 | + CustomerName: dividendsOrder.CustomerName, | ||
288 | + Org: dividendsOrder.Org, | ||
289 | + Company: dividendsOrder.Company, | ||
290 | + CreatedAt: dividendsOrder.CreatedAt, | ||
291 | + DeletedAt: dividendsOrder.DeletedAt, | ||
292 | + UpdatedAt: time.Now(), | ||
293 | + OperateTime: dividendsOrder.OperateTime, | ||
294 | + Operator: dividendsOrder.Operator, | ||
295 | + Remarks: dividendsOrder.Remarks, | ||
296 | + }) | ||
297 | + } | ||
298 | + if _, err := tx.Model(÷ndsOrderModels).WherePK().Update(); err != nil { | ||
299 | + return nil, err | ||
300 | + } | ||
301 | + return dividendsOrders, nil | ||
260 | } | 302 | } |
261 | 303 | ||
262 | func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.DividendsOrder) (*domain.DividendsOrder, error) { | 304 | func (repository *DividendsOrderRepository) Remove(dividendsOrder *domain.DividendsOrder) (*domain.DividendsOrder, error) { |
@@ -181,7 +181,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | @@ -181,7 +181,7 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | ||
181 | // 获取分红退货订单产品 | 181 | // 获取分红退货订单产品 |
182 | var orderGoodsFetched []*models.OrderGood | 182 | var orderGoodsFetched []*models.OrderGood |
183 | orderGoodsQuery := tx.Model(&orderGoodsFetched) | 183 | orderGoodsQuery := tx.Model(&orderGoodsFetched) |
184 | - if err := orderGoodsQuery.Where("dividends_return_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Select(); err != nil { | 184 | + if err := orderGoodsQuery.Where("dividends_returned_order_number = ?", dividendsReturnedOrder.DividendsReturnedOrderNumber).Select(); err != nil { |
185 | return nil, err | 185 | return nil, err |
186 | } | 186 | } |
187 | 187 | ||
@@ -224,9 +224,11 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | @@ -224,9 +224,11 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | ||
224 | }) | 224 | }) |
225 | } | 225 | } |
226 | // 添加分红退货订单产品 | 226 | // 添加分红退货订单产品 |
227 | + if len(orderGoodsToAddModels) > 0 { | ||
227 | if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil { | 228 | if _, err := tx.Model(&orderGoodsToAddModels).Insert(); err != nil { |
228 | return nil, err | 229 | return nil, err |
229 | } | 230 | } |
231 | + } | ||
230 | 232 | ||
231 | // 待更新或者删除的ids | 233 | // 待更新或者删除的ids |
232 | var orderGoodIdsToUpdateOrDelete []int64 | 234 | var orderGoodIdsToUpdateOrDelete []int64 |
@@ -244,9 +246,11 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | @@ -244,9 +246,11 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | ||
244 | } | 246 | } |
245 | } | 247 | } |
246 | } | 248 | } |
249 | + if len(orderGoodModelsToUpdate) > 0 { | ||
247 | if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil { | 250 | if _, err := tx.Model(&orderGoodModelsToUpdate).WherePK().Update(); err != nil { |
248 | return nil, err | 251 | return nil, err |
249 | } | 252 | } |
253 | + } | ||
250 | 254 | ||
251 | // 待删除的分红退货订单产品id | 255 | // 待删除的分红退货订单产品id |
252 | orderGoodIdsToDelete := utils.Difference(orderGoodIdsFetched, orderGoodIdsToUpdateOrDelete) | 256 | orderGoodIdsToDelete := utils.Difference(orderGoodIdsFetched, orderGoodIdsToUpdateOrDelete) |
@@ -258,15 +262,45 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | @@ -258,15 +262,45 @@ func (repository *DividendsReturnedOrderRepository) Save(dividendsReturnedOrder | ||
258 | } | 262 | } |
259 | } | 263 | } |
260 | } | 264 | } |
261 | - if _, err := tx.Model(&orderGoodModelsToDelete).WherePK().Delete(); err != nil { | 265 | + if len(orderGoodModelsToDelete) > 0 { |
266 | + if _, err := tx.Model(&orderGoodModelsToDelete).Delete(); err != nil { | ||
262 | return nil, err | 267 | return nil, err |
263 | } | 268 | } |
264 | } | 269 | } |
270 | + } | ||
265 | return dividendsReturnedOrder, nil | 271 | return dividendsReturnedOrder, nil |
266 | } | 272 | } |
267 | 273 | ||
268 | -func (repository *DividendsReturnedOrderRepository) UpdateMany(dividendsReturnedOrder []*domain.DividendsReturnedOrder) ([]*domain.DividendsReturnedOrder, error) { | ||
269 | - panic("implement me") | 274 | +func (repository *DividendsReturnedOrderRepository) UpdateMany(dividendsReturnedOrders []*domain.DividendsReturnedOrder) ([]*domain.DividendsReturnedOrder, error) { |
275 | + tx := repository.transactionContext.PgTx | ||
276 | + var dividendsReturnedOrderModels []*models.DividendsReturnedOrder | ||
277 | + for _, dividendsReturnedOrder := range dividendsReturnedOrders { | ||
278 | + dividendsReturnedOrderModels = append(dividendsReturnedOrderModels, &models.DividendsReturnedOrder{ | ||
279 | + DividendsReturnedOrderId: dividendsReturnedOrder.DividendsReturnedOrderId, | ||
280 | + DividendsReturnedOrderNumber: dividendsReturnedOrder.DividendsOrderNumber, | ||
281 | + DividendsReturnedOrderRefund: dividendsReturnedOrder.DividendsReturnedOrderRefund, | ||
282 | + OriginalOrderNum: dividendsReturnedOrder.OriginalOrderNum, | ||
283 | + DividendsOrderNumber: dividendsReturnedOrder.DividendsReturnedOrderNumber, | ||
284 | + DividendsReturnedCustomerName: dividendsReturnedOrder.DividendsReturnedCustomerName, | ||
285 | + OrderTime: dividendsReturnedOrder.OrderTime, | ||
286 | + DividendsReturnedDate: dividendsReturnedOrder.DividendsReturnedDate, | ||
287 | + Region: dividendsReturnedOrder.Region, | ||
288 | + Remarks: dividendsReturnedOrder.Remarks, | ||
289 | + DividendStatus: dividendsReturnedOrder.DividendStatus, | ||
290 | + DividendTime: dividendsReturnedOrder.DividendTime, | ||
291 | + Org: dividendsReturnedOrder.Org, | ||
292 | + Company: dividendsReturnedOrder.Company, | ||
293 | + CreatedAt: dividendsReturnedOrder.CreatedAt, | ||
294 | + DeletedAt: dividendsReturnedOrder.DeletedAt, | ||
295 | + UpdatedAt: time.Now(), | ||
296 | + Operator: dividendsReturnedOrder.Operator, | ||
297 | + OperateTime: dividendsReturnedOrder.OperateTime, | ||
298 | + }) | ||
299 | + } | ||
300 | + if _, err := tx.Model(÷ndsReturnedOrderModels).WherePK().Update(); err != nil { | ||
301 | + return nil, err | ||
302 | + } | ||
303 | + return dividendsReturnedOrders, nil | ||
270 | } | 304 | } |
271 | 305 | ||
272 | func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrder *domain.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) { | 306 | func (repository *DividendsReturnedOrderRepository) Remove(dividendsReturnedOrder *domain.DividendsReturnedOrder) (*domain.DividendsReturnedOrder, error) { |
-
请 注册 或 登录 后发表评论