正在显示
8 个修改的文件
包含
358 行增加
和
49 行删除
@@ -12,6 +12,7 @@ import ( | @@ -12,6 +12,7 @@ import ( | ||
12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" | 12 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory" |
13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | 13 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" |
14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" | 14 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" |
15 | + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" | ||
15 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" | 16 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" |
16 | "strconv" | 17 | "strconv" |
17 | "time" | 18 | "time" |
@@ -355,7 +356,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat | @@ -355,7 +356,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat | ||
355 | } | 356 | } |
356 | } | 357 | } |
357 | 358 | ||
358 | -// ConfirmDividendsIncentivesEstimate TODO 确定业绩激励分红预算 | 359 | +// ConfirmDividendsIncentivesEstimate 确定业绩激励分红预算 |
359 | func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) { | 360 | func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) { |
360 | if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil { | 361 | if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil { |
361 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 362 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
@@ -370,6 +371,47 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -370,6 +371,47 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
370 | defer func() { | 371 | defer func() { |
371 | _ = transactionContext.RollbackTransaction() | 372 | _ = transactionContext.RollbackTransaction() |
372 | }() | 373 | }() |
374 | + | ||
375 | + // 用户REST服务初始化 | ||
376 | + //var userService service.UserService | ||
377 | + //if value, err := factory.CreateUserService(map[string]interface{}{}); err != nil { | ||
378 | + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
379 | + //} else { | ||
380 | + // userService = value | ||
381 | + //} | ||
382 | + | ||
383 | + // 公司REST服务初始化 | ||
384 | + var companyService service.CompanyService | ||
385 | + if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil { | ||
386 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
387 | + } else { | ||
388 | + companyService = value | ||
389 | + } | ||
390 | + | ||
391 | + // 获取公司信息 | ||
392 | + var company *domain.Company | ||
393 | + if data, err := companyService.CompanyFrom(confirmDividendsIncentivesEstimateCommand.CompanyId); err != nil { | ||
394 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
395 | + } else { | ||
396 | + company = data | ||
397 | + } | ||
398 | + | ||
399 | + // 组织机构REST服务初始化 | ||
400 | + var organizationService service.OrgService | ||
401 | + if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil { | ||
402 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
403 | + } else { | ||
404 | + organizationService = value | ||
405 | + } | ||
406 | + | ||
407 | + // 获取组织机构信息 | ||
408 | + var organization *domain.Org | ||
409 | + if data, err := organizationService.OrgFrom(confirmDividendsIncentivesEstimateCommand.CompanyId, confirmDividendsIncentivesEstimateCommand.OrgId); err != nil { | ||
410 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
411 | + } else { | ||
412 | + organization = data | ||
413 | + } | ||
414 | + | ||
373 | // 分红订单仓储初始化 | 415 | // 分红订单仓储初始化 |
374 | var dividendsOrderRepository domain.DividendsOrderRepository | 416 | var dividendsOrderRepository domain.DividendsOrderRepository |
375 | if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{ | 417 | if value, err := factory.CreateDividendsOrderRepository(map[string]interface{}{ |
@@ -410,6 +452,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -410,6 +452,16 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
410 | dividendsEstimateRepository = value | 452 | dividendsEstimateRepository = value |
411 | } | 453 | } |
412 | 454 | ||
455 | + // 分红预算单DAO初始化 | ||
456 | + var dividendsEstimateDao *dao.DividendsEstimateDao | ||
457 | + if value, err := factory.CreateDividendsEstimateDao(map[string]interface{}{ | ||
458 | + "transactionContext": transactionContext, | ||
459 | + }); err != nil { | ||
460 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
461 | + } else { | ||
462 | + dividendsEstimateDao = value | ||
463 | + } | ||
464 | + | ||
413 | // 初始化确认业绩激励分红预算领域服务 | 465 | // 初始化确认业绩激励分红预算领域服务 |
414 | var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService | 466 | var confirmDividendsIncentivesEstimateService service.ConfirmDividendsIncentivesEstimateService |
415 | if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{ | 467 | if value, err := factory.CreateConfirmDividendsIncentivesEstimateService(map[string]interface{}{ |
@@ -439,29 +491,38 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -439,29 +491,38 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
439 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber)) | 491 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber)) |
440 | } | 492 | } |
441 | // 分红订单产品预算 | 493 | // 分红订单产品预算 |
442 | - if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { | 494 | + if dividendsEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { |
443 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 495 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
444 | } else { | 496 | } else { |
445 | - dividendsEstimate = &domain.DividendsEstimate{ | ||
446 | - DividendsEstimateId: 0, | ||
447 | - DividendsAccountStatus: 1, | ||
448 | - DividendsAmount: dividendsAmount, | ||
449 | - DividendsEstimateOrderNumber: "", | ||
450 | - DividendsEstimateTime: time.Time{}, | ||
451 | - DividendsParticipateType: 0, | ||
452 | - DividendsType: 0, | ||
453 | - OrderOrReturnedOrderNum: "", | ||
454 | - CooperationContractNumber: "", | ||
455 | - DividendsUser: nil, | ||
456 | - DividendsStage: 0, | ||
457 | - Org: nil, | ||
458 | - Company: nil, | ||
459 | - Operator: nil, | ||
460 | - OperateTime: time.Time{}, | ||
461 | - IsCanceled: false, | ||
462 | - CreatedAt: time.Time{}, | ||
463 | - DeletedAt: time.Time{}, | ||
464 | - UpdatedAt: time.Time{}, | 497 | + for _, dividendsEstimateDetail := range dividendsEstimateDetails { |
498 | + // 生成分红预算单号 | ||
499 | + dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber() | ||
500 | + if err != nil { | ||
501 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
502 | + } | ||
503 | + dividendsEstimate = &domain.DividendsEstimate{ | ||
504 | + DividendsEstimateId: 0, | ||
505 | + DividendsAccountStatus: domain.TO_BE_ACCOUNT, | ||
506 | + DividendsAmount: dividendsEstimateDetail.DividendsAmount, | ||
507 | + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber, | ||
508 | + DividendsEstimateTime: time.Now(), | ||
509 | + DividendsParticipateType: dividendsEstimateDetail.DividendsParticipateType, | ||
510 | + DividendsType: domain.ORDER_DIVIDENDS, | ||
511 | + DividendsTypeName: "订单分红", | ||
512 | + OrderOrReturnedOrderNum: orderGood.DividendsOrderNumber, | ||
513 | + CooperationContractNumber: orderGood.CooperationContractNumber, | ||
514 | + DividendsUser: dividendsEstimateDetail.DividendsUser, | ||
515 | + DividendsStage: dividendsEstimateDetail.DividendsStage, | ||
516 | + Org: organization, | ||
517 | + Company: company, | ||
518 | + Operator: nil, | ||
519 | + OperateTime: time.Time{}, | ||
520 | + IsCanceled: false, | ||
521 | + CreatedAt: time.Now(), | ||
522 | + DeletedAt: time.Time{}, | ||
523 | + UpdatedAt: time.Time{}, | ||
524 | + } | ||
525 | + dividendsEstimates = append(dividendsEstimates, dividendsEstimate) | ||
465 | } | 526 | } |
466 | } | 527 | } |
467 | } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单 | 528 | } else if orderGood.DividendsReturnedOrderNumber != "" { // 查询分红退货单 |
@@ -473,33 +534,41 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -473,33 +534,41 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
473 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) | 534 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) |
474 | } | 535 | } |
475 | // 分红退货单产品预算 | 536 | // 分红退货单产品预算 |
476 | - if dividendsAmount, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { | 537 | + if dividendsReturnedEstimateDetails, err := confirmDividendsIncentivesEstimateService.Confirm(orderGoods); err != nil { |
477 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 538 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
478 | } else { | 539 | } else { |
479 | - dividendsEstimate = &domain.DividendsEstimate{ | ||
480 | - DividendsEstimateId: 0, | ||
481 | - DividendsAccountStatus: 0, | ||
482 | - DividendsAmount: dividendsAmount, | ||
483 | - DividendsEstimateOrderNumber: "", | ||
484 | - DividendsEstimateTime: time.Time{}, | ||
485 | - DividendsParticipateType: 0, | ||
486 | - DividendsType: 0, | ||
487 | - OrderOrReturnedOrderNum: "", | ||
488 | - CooperationContractNumber: "", | ||
489 | - DividendsUser: nil, | ||
490 | - DividendsStage: 0, | ||
491 | - Org: nil, | ||
492 | - Company: nil, | ||
493 | - Operator: nil, | ||
494 | - OperateTime: time.Now(), | ||
495 | - IsCanceled: false, | ||
496 | - CreatedAt: time.Now(), | ||
497 | - DeletedAt: time.Time{}, | ||
498 | - UpdatedAt: time.Time{}, | 540 | + for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails { |
541 | + // 生成分红预算单号 | ||
542 | + dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber() | ||
543 | + if err != nil { | ||
544 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
545 | + } | ||
546 | + dividendsEstimate = &domain.DividendsEstimate{ | ||
547 | + DividendsEstimateId: 0, | ||
548 | + DividendsAccountStatus: domain.TO_BE_ACCOUNT, | ||
549 | + DividendsAmount: dividendsReturnedEstimateDetail.DividendsAmount, | ||
550 | + DividendsEstimateOrderNumber: dividendsEstimateOrderNumber, | ||
551 | + DividendsEstimateTime: time.Now(), | ||
552 | + DividendsParticipateType: dividendsReturnedEstimateDetail.DividendsParticipateType, | ||
553 | + DividendsType: domain.RETURN_WRITE_OFF, | ||
554 | + DividendsTypeName: "退货冲销", | ||
555 | + OrderOrReturnedOrderNum: orderGood.DividendsReturnedOrderNumber, | ||
556 | + CooperationContractNumber: orderGood.CooperationContractNumber, | ||
557 | + DividendsUser: dividendsReturnedEstimateDetail.DividendsUser, | ||
558 | + DividendsStage: dividendsReturnedEstimateDetail.DividendsStage, | ||
559 | + Org: organization, | ||
560 | + Company: company, | ||
561 | + Operator: nil, | ||
562 | + OperateTime: time.Now(), | ||
563 | + IsCanceled: false, | ||
564 | + CreatedAt: time.Now(), | ||
565 | + DeletedAt: time.Time{}, | ||
566 | + UpdatedAt: time.Time{}, | ||
567 | + } | ||
568 | + dividendsEstimates = append(dividendsEstimates, dividendsEstimate) | ||
499 | } | 569 | } |
500 | } | 570 | } |
501 | } | 571 | } |
502 | - dividendsEstimates = append(dividendsEstimates, dividendsEstimate) | ||
503 | } | 572 | } |
504 | var dividendsEstimatesSaved []*domain.DividendsEstimate | 573 | var dividendsEstimatesSaved []*domain.DividendsEstimate |
505 | for _, dividendsEstimate := range dividendsEstimates { | 574 | for _, dividendsEstimate := range dividendsEstimates { |
@@ -52,3 +52,11 @@ func CreateCreditAccountDao(options map[string]interface{}) (*dao.CreditAccountD | @@ -52,3 +52,11 @@ func CreateCreditAccountDao(options map[string]interface{}) (*dao.CreditAccountD | ||
52 | } | 52 | } |
53 | return dao.NewCreditAccountDao(transactionContext) | 53 | return dao.NewCreditAccountDao(transactionContext) |
54 | } | 54 | } |
55 | + | ||
56 | +func CreateDividendsEstimateDao(options map[string]interface{}) (*dao.DividendsEstimateDao, error) { | ||
57 | + var transactionContext *pg.TransactionContext | ||
58 | + if value, ok := options["transactionContext"]; ok { | ||
59 | + transactionContext = value.(*pg.TransactionContext) | ||
60 | + } | ||
61 | + return dao.NewDividendsEstimateDao(transactionContext) | ||
62 | +} |
@@ -14,11 +14,16 @@ const ( | @@ -14,11 +14,16 @@ const ( | ||
14 | MONEY_INCENTIVES // 金额激励 | 14 | MONEY_INCENTIVES // 金额激励 |
15 | ) | 15 | ) |
16 | 16 | ||
17 | +const ( | ||
18 | + TO_BE_ACCOUNT = iota + 1 // 待结算 | ||
19 | + ACCOUNTED // 已结算 | ||
20 | +) | ||
21 | + | ||
17 | // DividendsEstimate 分红预算实体 | 22 | // DividendsEstimate 分红预算实体 |
18 | type DividendsEstimate struct { | 23 | type DividendsEstimate struct { |
19 | // 承接人分红预算记录ID | 24 | // 承接人分红预算记录ID |
20 | DividendsEstimateId int64 `json:"dividendsEstimateId,string"` | 25 | DividendsEstimateId int64 `json:"dividendsEstimateId,string"` |
21 | - // 分红结算状态 | 26 | + // 分红结算状态,1待结算,2已结算 |
22 | DividendsAccountStatus int32 `json:"dividendsAccountStatus"` | 27 | DividendsAccountStatus int32 `json:"dividendsAccountStatus"` |
23 | // 分红金额 | 28 | // 分红金额 |
24 | DividendsAmount float64 `json:"dividendsAmount"` | 29 | DividendsAmount float64 `json:"dividendsAmount"` |
@@ -30,6 +35,8 @@ type DividendsEstimate struct { | @@ -30,6 +35,8 @@ type DividendsEstimate struct { | ||
30 | DividendsParticipateType int32 `json:"dividendsParticipateType"` | 35 | DividendsParticipateType int32 `json:"dividendsParticipateType"` |
31 | // 分红类型,1订单分红,2退货冲销,3金额激励 | 36 | // 分红类型,1订单分红,2退货冲销,3金额激励 |
32 | DividendsType int32 `json:"dividendsType"` | 37 | DividendsType int32 `json:"dividendsType"` |
38 | + // 分红类型名称 | ||
39 | + DividendsTypeName string `json:"dividendsTypeName"` | ||
33 | // 分红订单号或退货单号 | 40 | // 分红订单号或退货单号 |
34 | OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"` | 41 | OrderOrReturnedOrderNum string `json:"orderOrReturnedOrderNum"` |
35 | // 共创项目合约编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001 | 42 | // 共创项目合约编号,自生成,生成规则:XM+6位年月日+#+3位流水,例XM210601#001 |
@@ -5,7 +5,14 @@ import ( | @@ -5,7 +5,14 @@ import ( | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" |
6 | ) | 6 | ) |
7 | 7 | ||
8 | +type DividendsEstimateDetail struct { | ||
9 | + DividendsUser *domain.User `json:"dividendsUser"` // 共创参与(分红用户) | ||
10 | + DividendsParticipateType int32 `json:"dividendsParticipateType"` // 参与类型 | ||
11 | + DividendsStage int32 `json:"dividendsStage"` // 分红阶段 | ||
12 | + DividendsAmount float64 `json:"dividendsAmount"` // 分红金额 | ||
13 | +} | ||
14 | + | ||
8 | type ConfirmDividendsIncentivesEstimateService interface { | 15 | type ConfirmDividendsIncentivesEstimateService interface { |
9 | coreDomain.DomainEventPublisher | 16 | coreDomain.DomainEventPublisher |
10 | - Confirm(orderGoods []*domain.OrderGood) (float64, error) | 17 | + Confirm(orderGoods []*domain.OrderGood) ([]*DividendsEstimateDetail, error) |
11 | } | 18 | } |
@@ -2,9 +2,12 @@ package domain_service | @@ -2,9 +2,12 @@ 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" | ||
8 | ) | 11 | ) |
9 | 12 | ||
10 | type ConfirmDividendsIncentivesEstimateService struct { | 13 | type ConfirmDividendsIncentivesEstimateService struct { |
@@ -12,9 +15,215 @@ type ConfirmDividendsIncentivesEstimateService struct { | @@ -12,9 +15,215 @@ type ConfirmDividendsIncentivesEstimateService struct { | ||
12 | transactionContext *pgTransaction.TransactionContext | 15 | transactionContext *pgTransaction.TransactionContext |
13 | } | 16 | } |
14 | 17 | ||
15 | -// Confirm TODO 确认业绩分红预算 | ||
16 | -func (c ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) (float64, error) { | ||
17 | - panic("implement me") | 18 | +// Confirm 确认业绩分红预算 |
19 | +func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) ([]*service.DividendsEstimateDetail, error) { | ||
20 | + var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储 | ||
21 | + var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 | ||
22 | + var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 | ||
23 | + // 共创合约仓储初始化 | ||
24 | + if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil { | ||
25 | + return nil, err | ||
26 | + } else { | ||
27 | + cooperationContractRepository = repo | ||
28 | + } | ||
29 | + // 分红订单仓储初始化 | ||
30 | + if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil { | ||
31 | + return nil, err | ||
32 | + } else { | ||
33 | + dividendsOrderRepository = repo | ||
34 | + } | ||
35 | + // 分红退后单仓储初始化 | ||
36 | + if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil { | ||
37 | + return nil, err | ||
38 | + } else { | ||
39 | + dividendsReturnedOrderRepository = repo | ||
40 | + } | ||
41 | + var dividendsEstimateDetails []*service.DividendsEstimateDetail | ||
42 | + for _, orderGood := range orderGoods { | ||
43 | + // 获取合约 | ||
44 | + cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractNumber": orderGood.CooperationContractNumber}) | ||
45 | + if err != nil { | ||
46 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
47 | + } | ||
48 | + if cooperationContract == nil { | ||
49 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.CooperationContractNumber)) | ||
50 | + } | ||
51 | + if orderGood.DividendsOrderNumber != "" { | ||
52 | + // 获取分红订单 | ||
53 | + dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{ | ||
54 | + "dividendsOrderNumber": orderGood.DividendsOrderNumber, | ||
55 | + }) | ||
56 | + if err2 != nil { | ||
57 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
58 | + } | ||
59 | + if dividendsOrder == nil { | ||
60 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsOrderNumber)) | ||
61 | + } | ||
62 | + // 匹配分红规则 | ||
63 | + var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule | ||
64 | + for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules { | ||
65 | + if dividendsOrder.OrderTime.After(dividendsIncentivesRule.DividendsIncentivesStageStart) && dividendsOrder.OrderTime.Before(dividendsIncentivesRule.DividendsIncentivesStageEnd) { | ||
66 | + dividendsIncentivesRuleMatched = dividendsIncentivesRule | ||
67 | + break | ||
68 | + } | ||
69 | + } | ||
70 | + // 计算分红 | ||
71 | + for _, undertaker := range cooperationContract.Undertakers { | ||
72 | + // 添加承接人分红预算信息详情 | ||
73 | + undertakerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage | ||
74 | + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | ||
75 | + DividendsUser: &domain.User{ | ||
76 | + UserId: undertaker.UserId, | ||
77 | + UserBaseId: undertaker.UserBaseId, | ||
78 | + Org: undertaker.Org, | ||
79 | + Orgs: undertaker.Orgs, | ||
80 | + Department: undertaker.Department, | ||
81 | + Roles: undertaker.Roles, | ||
82 | + UserInfo: undertaker.UserInfo, | ||
83 | + UserType: undertaker.UserType, | ||
84 | + UserName: undertaker.UserName, | ||
85 | + UserPhone: undertaker.UserPhone, | ||
86 | + Status: undertaker.Status, | ||
87 | + Company: undertaker.Company, | ||
88 | + }, | ||
89 | + DividendsParticipateType: domain.UNDERTAKER, | ||
90 | + DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), | ||
91 | + DividendsAmount: undertakerDividendsAmount, | ||
92 | + }) | ||
93 | + // 添加推荐人分红预算信息详情 | ||
94 | + if undertaker.Referrer != nil { | ||
95 | + referrerDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.ReferrerPercentage | ||
96 | + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | ||
97 | + DividendsUser: &domain.User{ | ||
98 | + UserId: undertaker.Referrer.UserId, | ||
99 | + UserBaseId: undertaker.Referrer.UserBaseId, | ||
100 | + Org: undertaker.Referrer.Org, | ||
101 | + Orgs: undertaker.Referrer.Orgs, | ||
102 | + Department: undertaker.Referrer.Department, | ||
103 | + Roles: undertaker.Referrer.Roles, | ||
104 | + UserInfo: undertaker.Referrer.UserInfo, | ||
105 | + UserType: undertaker.Referrer.UserType, | ||
106 | + UserName: undertaker.Referrer.UserName, | ||
107 | + UserPhone: undertaker.Referrer.UserPhone, | ||
108 | + Company: undertaker.Referrer.Company, | ||
109 | + }, | ||
110 | + DividendsParticipateType: domain.REFERRER, | ||
111 | + DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), | ||
112 | + DividendsAmount: referrerDividendsAmount, | ||
113 | + }) | ||
114 | + } | ||
115 | + // 添加关联业务员分红预算信息详情 | ||
116 | + if undertaker.Salesman != nil { | ||
117 | + salesmanDividendsAmount := (orderGood.OrderGoodAmount - orderGood.OrderGoodExpense) * dividendsIncentivesRuleMatched.SalesmanPercentage | ||
118 | + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | ||
119 | + DividendsUser: &domain.User{ | ||
120 | + UserId: undertaker.Salesman.UserId, | ||
121 | + UserBaseId: undertaker.Salesman.UserBaseId, | ||
122 | + Org: undertaker.Salesman.Org, | ||
123 | + Orgs: undertaker.Salesman.Orgs, | ||
124 | + Department: undertaker.Salesman.Department, | ||
125 | + Roles: undertaker.Salesman.Roles, | ||
126 | + UserInfo: undertaker.Salesman.UserInfo, | ||
127 | + UserType: undertaker.Salesman.UserType, | ||
128 | + UserName: undertaker.Salesman.UserName, | ||
129 | + UserPhone: undertaker.Salesman.UserPhone, | ||
130 | + Company: undertaker.Salesman.Company, | ||
131 | + }, | ||
132 | + DividendsParticipateType: domain.SALESMAN, | ||
133 | + DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), | ||
134 | + DividendsAmount: salesmanDividendsAmount, | ||
135 | + }) | ||
136 | + } | ||
137 | + } | ||
138 | + } else if orderGood.DividendsReturnedOrderNumber != "" { // 获取分红退货单 | ||
139 | + dividendsReturnedOrder, err3 := dividendsReturnedOrderRepository.FindOne(map[string]interface{}{ | ||
140 | + "dividendsReturnedOrderNumber": orderGood.DividendsReturnedOrderNumber, | ||
141 | + }) | ||
142 | + if err3 != nil { | ||
143 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
144 | + } | ||
145 | + if dividendsReturnedOrder == nil { | ||
146 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", orderGood.DividendsReturnedOrderNumber)) | ||
147 | + } | ||
148 | + // 匹配分红规则 | ||
149 | + var dividendsIncentivesRuleMatched *domain.DividendsIncentivesRule | ||
150 | + for _, dividendsIncentivesRule := range cooperationContract.DividendsIncentivesRules { | ||
151 | + if dividendsReturnedOrder.OrderTime.After(dividendsIncentivesRule.DividendsIncentivesStageStart) && dividendsReturnedOrder.OrderTime.Before(dividendsIncentivesRule.DividendsIncentivesStageEnd) { | ||
152 | + dividendsIncentivesRuleMatched = dividendsIncentivesRule | ||
153 | + break | ||
154 | + } | ||
155 | + } | ||
156 | + // 计算分红 | ||
157 | + for _, undertaker := range cooperationContract.Undertakers { | ||
158 | + // 添加承接人分红退货预算信息详情 | ||
159 | + undertakerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage | ||
160 | + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | ||
161 | + DividendsUser: &domain.User{ | ||
162 | + UserId: undertaker.UserId, | ||
163 | + UserBaseId: undertaker.UserBaseId, | ||
164 | + Org: undertaker.Org, | ||
165 | + Orgs: undertaker.Orgs, | ||
166 | + Department: undertaker.Department, | ||
167 | + Roles: undertaker.Roles, | ||
168 | + UserInfo: undertaker.UserInfo, | ||
169 | + UserType: undertaker.UserType, | ||
170 | + UserName: undertaker.UserName, | ||
171 | + UserPhone: undertaker.UserPhone, | ||
172 | + Status: undertaker.Status, | ||
173 | + Company: undertaker.Company, | ||
174 | + }, | ||
175 | + DividendsParticipateType: domain.UNDERTAKER, | ||
176 | + DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), | ||
177 | + DividendsAmount: undertakerDividendsAmount, | ||
178 | + }) | ||
179 | + // 添加推荐人分红退货预算信息详情 | ||
180 | + if undertaker.Referrer != nil { | ||
181 | + referrerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage | ||
182 | + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | ||
183 | + DividendsUser: &domain.User{ | ||
184 | + UserId: undertaker.Referrer.UserId, | ||
185 | + UserBaseId: undertaker.Referrer.UserBaseId, | ||
186 | + Org: undertaker.Referrer.Org, | ||
187 | + Orgs: undertaker.Referrer.Orgs, | ||
188 | + Department: undertaker.Referrer.Department, | ||
189 | + Roles: undertaker.Referrer.Roles, | ||
190 | + UserInfo: undertaker.Referrer.UserInfo, | ||
191 | + UserType: undertaker.Referrer.UserType, | ||
192 | + UserName: undertaker.Referrer.UserName, | ||
193 | + UserPhone: undertaker.Referrer.UserPhone, | ||
194 | + Company: undertaker.Referrer.Company, | ||
195 | + }, | ||
196 | + DividendsParticipateType: domain.REFERRER, | ||
197 | + DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), | ||
198 | + DividendsAmount: referrerDividendsAmount, | ||
199 | + }) | ||
200 | + } | ||
201 | + // 添加关联业务员分红退货预算信息详情 | ||
202 | + if undertaker.Salesman != nil { | ||
203 | + salesmanDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage | ||
204 | + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | ||
205 | + DividendsUser: &domain.User{ | ||
206 | + UserId: undertaker.Salesman.UserId, | ||
207 | + UserBaseId: undertaker.Salesman.UserBaseId, | ||
208 | + Org: undertaker.Salesman.Org, | ||
209 | + Orgs: undertaker.Salesman.Orgs, | ||
210 | + Department: undertaker.Salesman.Department, | ||
211 | + Roles: undertaker.Salesman.Roles, | ||
212 | + UserInfo: undertaker.Salesman.UserInfo, | ||
213 | + UserType: undertaker.Salesman.UserType, | ||
214 | + UserName: undertaker.Salesman.UserName, | ||
215 | + UserPhone: undertaker.Salesman.UserPhone, | ||
216 | + Company: undertaker.Salesman.Company, | ||
217 | + }, | ||
218 | + DividendsParticipateType: domain.SALESMAN, | ||
219 | + DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), | ||
220 | + DividendsAmount: salesmanDividendsAmount, | ||
221 | + }) | ||
222 | + } | ||
223 | + } | ||
224 | + } | ||
225 | + } | ||
226 | + return dividendsEstimateDetails, nil | ||
18 | } | 227 | } |
19 | 228 | ||
20 | func NewConfirmDividendsIncentivesEstimateService(transactionContext *pgTransaction.TransactionContext) (*ConfirmDividendsIncentivesEstimateService, error) { | 229 | func NewConfirmDividendsIncentivesEstimateService(transactionContext *pgTransaction.TransactionContext) (*ConfirmDividendsIncentivesEstimateService, error) { |
@@ -21,6 +21,8 @@ type DividendsEstimate struct { | @@ -21,6 +21,8 @@ type DividendsEstimate struct { | ||
21 | DividendsParticipateType int32 `comment:"参与分红类型,1承接人,2推荐人,3关联业务员"` | 21 | DividendsParticipateType int32 `comment:"参与分红类型,1承接人,2推荐人,3关联业务员"` |
22 | // 分红类型,1订单分红,2退货冲销,3金额激励 | 22 | // 分红类型,1订单分红,2退货冲销,3金额激励 |
23 | DividendsType int32 `comment:"分红类型,1订单分红,2退货冲销,3金额激励"` | 23 | DividendsType int32 `comment:"分红类型,1订单分红,2退货冲销,3金额激励"` |
24 | + // 分红类型名称 | ||
25 | + DividendsTypeName string `comment:"分红类型名称"` | ||
24 | // 分红订单号或退货单号 | 26 | // 分红订单号或退货单号 |
25 | OrderOrReturnedOrderNum string `comment:"分红订单号或退货单号"` | 27 | OrderOrReturnedOrderNum string `comment:"分红订单号或退货单号"` |
26 | // 共创项目合约编号 | 28 | // 共创项目合约编号 |
@@ -14,6 +14,7 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel | @@ -14,6 +14,7 @@ func TransformToDividendsEstimateDomainModelFromPgModels(dividendsEstimateModel | ||
14 | DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime, | 14 | DividendsEstimateTime: dividendsEstimateModel.DividendsEstimateTime, |
15 | DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType, | 15 | DividendsParticipateType: dividendsEstimateModel.DividendsParticipateType, |
16 | DividendsType: dividendsEstimateModel.DividendsType, | 16 | DividendsType: dividendsEstimateModel.DividendsType, |
17 | + DividendsTypeName: dividendsEstimateModel.DividendsTypeName, | ||
17 | OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum, | 18 | OrderOrReturnedOrderNum: dividendsEstimateModel.OrderOrReturnedOrderNum, |
18 | CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber, | 19 | CooperationContractNumber: dividendsEstimateModel.CooperationContractNumber, |
19 | DividendsUser: dividendsEstimateModel.DividendsUser, | 20 | DividendsUser: dividendsEstimateModel.DividendsUser, |
@@ -35,6 +35,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | @@ -35,6 +35,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | ||
35 | "dividends_estimate_time", | 35 | "dividends_estimate_time", |
36 | "dividends_participate_type", | 36 | "dividends_participate_type", |
37 | "dividends_type", | 37 | "dividends_type", |
38 | + "dividends_type_name", | ||
38 | "order_or_returned_order_num", | 39 | "order_or_returned_order_num", |
39 | "cooperation_contract_number", | 40 | "cooperation_contract_number", |
40 | "dividends_user", | 41 | "dividends_user", |
@@ -70,6 +71,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | @@ -70,6 +71,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | ||
70 | ÷ndsEstimate.DividendsEstimateTime, | 71 | ÷ndsEstimate.DividendsEstimateTime, |
71 | ÷ndsEstimate.DividendsParticipateType, | 72 | ÷ndsEstimate.DividendsParticipateType, |
72 | ÷ndsEstimate.DividendsType, | 73 | ÷ndsEstimate.DividendsType, |
74 | + ÷ndsEstimate.DividendsTypeName, | ||
73 | ÷ndsEstimate.OrderOrReturnedOrderNum, | 75 | ÷ndsEstimate.OrderOrReturnedOrderNum, |
74 | ÷ndsEstimate.CooperationContractNumber, | 76 | ÷ndsEstimate.CooperationContractNumber, |
75 | ÷ndsEstimate.DividendsUser, | 77 | ÷ndsEstimate.DividendsUser, |
@@ -91,6 +93,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | @@ -91,6 +93,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | ||
91 | dividendsEstimate.DividendsEstimateTime, | 93 | dividendsEstimate.DividendsEstimateTime, |
92 | dividendsEstimate.DividendsParticipateType, | 94 | dividendsEstimate.DividendsParticipateType, |
93 | dividendsEstimate.DividendsType, | 95 | dividendsEstimate.DividendsType, |
96 | + dividendsEstimate.DividendsTypeName, | ||
94 | dividendsEstimate.OrderOrReturnedOrderNum, | 97 | dividendsEstimate.OrderOrReturnedOrderNum, |
95 | dividendsEstimate.CooperationContractNumber, | 98 | dividendsEstimate.CooperationContractNumber, |
96 | dividendsEstimate.DividendsUser, | 99 | dividendsEstimate.DividendsUser, |
@@ -116,6 +119,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | @@ -116,6 +119,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | ||
116 | ÷ndsEstimate.DividendsEstimateTime, | 119 | ÷ndsEstimate.DividendsEstimateTime, |
117 | ÷ndsEstimate.DividendsParticipateType, | 120 | ÷ndsEstimate.DividendsParticipateType, |
118 | ÷ndsEstimate.DividendsType, | 121 | ÷ndsEstimate.DividendsType, |
122 | + ÷ndsEstimate.DividendsTypeName, | ||
119 | ÷ndsEstimate.OrderOrReturnedOrderNum, | 123 | ÷ndsEstimate.OrderOrReturnedOrderNum, |
120 | ÷ndsEstimate.CooperationContractNumber, | 124 | ÷ndsEstimate.CooperationContractNumber, |
121 | ÷ndsEstimate.DividendsUser, | 125 | ÷ndsEstimate.DividendsUser, |
@@ -137,6 +141,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | @@ -137,6 +141,7 @@ func (repository *DividendsEstimateRepository) Save(dividendsEstimate *domain.Di | ||
137 | dividendsEstimate.DividendsEstimateTime, | 141 | dividendsEstimate.DividendsEstimateTime, |
138 | dividendsEstimate.DividendsParticipateType, | 142 | dividendsEstimate.DividendsParticipateType, |
139 | dividendsEstimate.DividendsType, | 143 | dividendsEstimate.DividendsType, |
144 | + dividendsEstimate.DividendsTypeName, | ||
140 | dividendsEstimate.OrderOrReturnedOrderNum, | 145 | dividendsEstimate.OrderOrReturnedOrderNum, |
141 | dividendsEstimate.CooperationContractNumber, | 146 | dividendsEstimate.CooperationContractNumber, |
142 | dividendsEstimate.DividendsUser, | 147 | dividendsEstimate.DividendsUser, |
@@ -169,6 +174,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []* | @@ -169,6 +174,7 @@ func (repository *DividendsEstimateRepository) UpdateMany(dividendsEstimates []* | ||
169 | DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime, | 174 | DividendsEstimateTime: dividendsEstimate.DividendsEstimateTime, |
170 | DividendsParticipateType: dividendsEstimate.DividendsParticipateType, | 175 | DividendsParticipateType: dividendsEstimate.DividendsParticipateType, |
171 | DividendsType: dividendsEstimate.DividendsType, | 176 | DividendsType: dividendsEstimate.DividendsType, |
177 | + DividendsTypeName: dividendsEstimate.DividendsTypeName, | ||
172 | OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum, | 178 | OrderOrReturnedOrderNum: dividendsEstimate.OrderOrReturnedOrderNum, |
173 | CooperationContractNumber: dividendsEstimate.CooperationContractNumber, | 179 | CooperationContractNumber: dividendsEstimate.CooperationContractNumber, |
174 | DividendsUser: dividendsEstimate.DividendsUser, | 180 | DividendsUser: dividendsEstimate.DividendsUser, |
-
请 注册 或 登录 后发表评论