作者 陈志颖

Merge branch 'dev-chenzhiying' into dev

@@ -15,7 +15,7 @@ type CreateDividendsIncentivesRulesCommand struct { @@ -15,7 +15,7 @@ type CreateDividendsIncentivesRulesCommand struct {
15 ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"` 15 ReferrerPercentage float64 `cname:"推荐人抽成" json:"referrerPercentage"`
16 SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"` 16 SalesmanPercentage float64 `cname:"业务员抽成" json:"salesmanPercentage"`
17 DividendsIncentivesPercentage float64 `cname:"分红规则激励百分点" json:"dividendsIncentivesPercentage"` 17 DividendsIncentivesPercentage float64 `cname:"分红规则激励百分点" json:"dividendsIncentivesPercentage"`
18 - DividendsIncentivesStage int `cname:"分红激励阶段" json:"dividendsIncentivesStage"` 18 + DividendsIncentivesStage int32 `cname:"分红激励阶段" json:"dividendsIncentivesStage"`
19 DividendsIncentivesStageEnd time.Time `cname:"" json:"dividendsIncentivesStageEnd"` 19 DividendsIncentivesStageEnd time.Time `cname:"" json:"dividendsIncentivesStageEnd"`
20 DividendsIncentivesStageStart time.Time `cname:"" json:"dividendsIncentivesStageStart"` 20 DividendsIncentivesStageStart time.Time `cname:"" json:"dividendsIncentivesStageStart"`
21 } 21 }
@@ -23,8 +23,8 @@ type CreateDividendsIncentivesRulesCommand struct { @@ -23,8 +23,8 @@ type CreateDividendsIncentivesRulesCommand struct {
23 type CreateMoneyIncentivesRulesCommand struct { 23 type CreateMoneyIncentivesRulesCommand struct {
24 MoneyIncentivesRuleId string `cname:"" json:"moneyIncentivesRuleId,string"` 24 MoneyIncentivesRuleId string `cname:"" json:"moneyIncentivesRuleId,string"`
25 CooperationContractNumber string `cname:"" json:"cooperationContractNumber"` 25 CooperationContractNumber string `cname:"" json:"cooperationContractNumber"`
26 - MoneyIncentivesAmount int `cname:"" json:"moneyIncentivesAmount"`  
27 - MoneyIncentivesStage int `cname:"" json:"moneyIncentivesStage"` 26 + MoneyIncentivesAmount float64 `cname:"" json:"moneyIncentivesAmount"`
  27 + MoneyIncentivesStage int32 `cname:"" json:"moneyIncentivesStage"`
28 MoneyIncentivesStageEnd time.Time `cname:"" json:"moneyIncentivesStageEnd"` 28 MoneyIncentivesStageEnd time.Time `cname:"" json:"moneyIncentivesStageEnd"`
29 MoneyIncentivesStageStart time.Time `cname:"" json:"moneyIncentivesStageStart"` 29 MoneyIncentivesStageStart time.Time `cname:"" json:"moneyIncentivesStageStart"`
30 MoneyIncentivesTime time.Time `cname:"" json:"moneyIncentivesTime"` 30 MoneyIncentivesTime time.Time `cname:"" json:"moneyIncentivesTime"`
@@ -33,7 +33,7 @@ type CreateMoneyIncentivesRulesCommand struct { @@ -33,7 +33,7 @@ type CreateMoneyIncentivesRulesCommand struct {
33 } 33 }
34 34
35 type CreateUndertakersCommand struct { 35 type CreateUndertakersCommand struct {
36 - UndertakerId int64 `cname:"承接人ID" json:"relevantId"` 36 + UndertakerId string `cname:"承接人ID" json:"relevantId"`
37 UserId string `cname:"承接人UID" json:"userId"` 37 UserId string `cname:"承接人UID" json:"userId"`
38 ContractAttachment []struct { 38 ContractAttachment []struct {
39 FileType string `cname:"文件类型" json:"fileType"` 39 FileType string `cname:"文件类型" json:"fileType"`
@@ -106,7 +106,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -106,7 +106,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
106 // 生成共创合约编号 106 // 生成共创合约编号
107 contractNumber, err2 := cooperationContractDao.GenerateContractNumber() 107 contractNumber, err2 := cooperationContractDao.GenerateContractNumber()
108 if err2 != nil { 108 if err2 != nil {
109 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 109 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error())
110 } 110 }
111 // 校验共创合约编号是否唯一 111 // 校验共创合约编号是否唯一
112 numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{ 112 numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{
@@ -209,7 +209,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -209,7 +209,7 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
209 ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage, 209 ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
210 SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage, 210 SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
211 DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage, 211 DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
212 - DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage), 212 + DividendsIncentivesStage: dividendsIncentivesRule.DividendsIncentivesStage,
213 DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd, 213 DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd,
214 DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart, 214 DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart,
215 Org: organization, 215 Org: organization,
@@ -226,8 +226,8 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -226,8 +226,8 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
226 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{ 226 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
227 MoneyIncentivesRuleId: 0, 227 MoneyIncentivesRuleId: 0,
228 CooperationContractNumber: contractNumber, 228 CooperationContractNumber: contractNumber,
229 - MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),  
230 - MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage), 229 + MoneyIncentivesAmount: moneyIncentivesRule.MoneyIncentivesAmount,
  230 + MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage,
231 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd, 231 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
232 MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart, 232 MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
233 MoneyIncentivesTime: time.Now(), 233 MoneyIncentivesTime: time.Now(),
@@ -780,8 +780,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -780,8 +780,12 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
780 } 780 }
781 } 781 }
782 782
  783 + undertakerId, err3 := strconv.ParseInt(undertaker.UndertakerId, 10, 64)
  784 + if err3 != nil {
  785 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err3.Error())
  786 + }
783 undertakers = append(undertakers, &domain.Undertaker{ 787 undertakers = append(undertakers, &domain.Undertaker{
784 - UndertakerId: undertaker.UndertakerId, 788 + UndertakerId: undertakerId,
785 UserId: undertakerDomain.UserId, 789 UserId: undertakerDomain.UserId,
786 CooperationContractNumber: cooperationContract.CooperationContractNumber, 790 CooperationContractNumber: cooperationContract.CooperationContractNumber,
787 UserBaseId: undertakerDomain.UserBaseId, 791 UserBaseId: undertakerDomain.UserBaseId,
@@ -804,14 +808,17 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -804,14 +808,17 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
804 // 获取分红规则列表 808 // 获取分红规则列表
805 var dividendsIncentivesRules []*domain.DividendsIncentivesRule 809 var dividendsIncentivesRules []*domain.DividendsIncentivesRule
806 for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules { 810 for _, dividendsIncentivesRule := range updateCooperationContractCommand.DividendsIncentivesRules {
807 - dividendsIncentivesRuleId, _ := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64) 811 + dividendsIncentivesRuleId, err2 := strconv.ParseInt(dividendsIncentivesRule.DividendsIncentivesRuleId, 10, 64)
  812 + if err2 != nil {
  813 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
  814 + }
808 dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{ 815 dividendsIncentivesRules = append(dividendsIncentivesRules, &domain.DividendsIncentivesRule{
809 DividendsIncentivesRuleId: dividendsIncentivesRuleId, 816 DividendsIncentivesRuleId: dividendsIncentivesRuleId,
810 CooperationContractNumber: cooperationContract.CooperationContractNumber, 817 CooperationContractNumber: cooperationContract.CooperationContractNumber,
811 ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage, 818 ReferrerPercentage: dividendsIncentivesRule.ReferrerPercentage,
812 SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage, 819 SalesmanPercentage: dividendsIncentivesRule.SalesmanPercentage,
813 DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage, 820 DividendsIncentivesPercentage: dividendsIncentivesRule.DividendsIncentivesPercentage,
814 - DividendsIncentivesStage: int64(dividendsIncentivesRule.DividendsIncentivesStage), 821 + DividendsIncentivesStage: dividendsIncentivesRule.DividendsIncentivesStage,
815 DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd, 822 DividendsIncentivesStageEnd: dividendsIncentivesRule.DividendsIncentivesStageEnd,
816 DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart, 823 DividendsIncentivesStageStart: dividendsIncentivesRule.DividendsIncentivesStageStart,
817 Org: organization, 824 Org: organization,
@@ -827,12 +834,15 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -827,12 +834,15 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
827 // 获取金额激励规则列表 834 // 获取金额激励规则列表
828 var moneyIncentivesRules []*domain.MoneyIncentivesRule 835 var moneyIncentivesRules []*domain.MoneyIncentivesRule
829 for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules { 836 for _, moneyIncentivesRule := range updateCooperationContractCommand.MoneyIncentivesRules {
830 - moneyIncentivesRuleId, _ := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64) 837 + moneyIncentivesRuleId, err4 := strconv.ParseInt(moneyIncentivesRule.MoneyIncentivesRuleId, 10, 64)
  838 + if err4 != nil {
  839 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error())
  840 + }
831 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{ 841 moneyIncentivesRules = append(moneyIncentivesRules, &domain.MoneyIncentivesRule{
832 MoneyIncentivesRuleId: moneyIncentivesRuleId, 842 MoneyIncentivesRuleId: moneyIncentivesRuleId,
833 CooperationContractNumber: cooperationContract.CooperationContractNumber, 843 CooperationContractNumber: cooperationContract.CooperationContractNumber,
834 - MoneyIncentivesAmount: float64(moneyIncentivesRule.MoneyIncentivesAmount),  
835 - MoneyIncentivesStage: int64(moneyIncentivesRule.MoneyIncentivesStage), 844 + MoneyIncentivesAmount: moneyIncentivesRule.MoneyIncentivesAmount,
  845 + MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage,
836 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd, 846 MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd,
837 MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart, 847 MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart,
838 MoneyIncentivesTime: time.Now(), 848 MoneyIncentivesTime: time.Now(),
@@ -641,7 +641,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives @@ -641,7 +641,7 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives
641 } 641 }
642 642
643 // 共创合约预算 643 // 共创合约预算
644 - if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, int64(confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage), undertakerUIDs); err2 != nil { 644 + if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil {
645 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) 645 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error())
646 } else { 646 } else {
647 if err3 := transactionContext.CommitTransaction(); err3 != nil { 647 if err3 := transactionContext.CommitTransaction(); err3 != nil {
@@ -17,7 +17,7 @@ type DividendsIncentivesRule struct { @@ -17,7 +17,7 @@ type DividendsIncentivesRule struct {
17 // 分红规则激励百分点 17 // 分红规则激励百分点
18 DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"` 18 DividendsIncentivesPercentage float64 `json:"dividendsIncentivesPercentage"`
19 // 分红规则激励阶段,阶段返回时需要转换为中文数字 19 // 分红规则激励阶段,阶段返回时需要转换为中文数字
20 - DividendsIncentivesStage int64 `json:"dividendsIncentivesStage"` 20 + DividendsIncentivesStage int32 `json:"dividendsIncentivesStage"`
21 // 分红激励规则阶段中文表示 21 // 分红激励规则阶段中文表示
22 DividendsIncentivesStageCN string `json:"dividendsIncentivesStageCN"` 22 DividendsIncentivesStageCN string `json:"dividendsIncentivesStageCN"`
23 // 分红规则激励阶段结束 23 // 分红规则激励阶段结束
@@ -69,7 +69,7 @@ func (dividendsIncentivesRule *DividendsIncentivesRule) Update(data map[string]i @@ -69,7 +69,7 @@ func (dividendsIncentivesRule *DividendsIncentivesRule) Update(data map[string]i
69 dividendsIncentivesRule.DividendsIncentivesPercentage = dividendsIncentivesPercentage.(float64) 69 dividendsIncentivesRule.DividendsIncentivesPercentage = dividendsIncentivesPercentage.(float64)
70 } 70 }
71 if dividendsIncentivesStage, ok := data["dividendsIncentivesStage"]; ok { 71 if dividendsIncentivesStage, ok := data["dividendsIncentivesStage"]; ok {
72 - dividendsIncentivesRule.DividendsIncentivesStage = dividendsIncentivesStage.(int64) 72 + dividendsIncentivesRule.DividendsIncentivesStage = dividendsIncentivesStage.(int32)
73 } 73 }
74 if dividendsIncentivesStageEnd, ok := data["dividendsIncentivesStageEnd"]; ok { 74 if dividendsIncentivesStageEnd, ok := data["dividendsIncentivesStageEnd"]; ok {
75 dividendsIncentivesRule.DividendsIncentivesStageEnd = dividendsIncentivesStageEnd.(time.Time) 75 dividendsIncentivesRule.DividendsIncentivesStageEnd = dividendsIncentivesStageEnd.(time.Time)
@@ -13,7 +13,7 @@ type MoneyIncentivesRule struct { @@ -13,7 +13,7 @@ type MoneyIncentivesRule struct {
13 // 激励金额 13 // 激励金额
14 MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"` 14 MoneyIncentivesAmount float64 `json:"moneyIncentivesAmount"`
15 // 金额激励阶段,阶段返回时需要转换为中文数字 15 // 金额激励阶段,阶段返回时需要转换为中文数字
16 - MoneyIncentivesStage int64 `json:"moneyIncentivesStage"` 16 + MoneyIncentivesStage int32 `json:"moneyIncentivesStage"`
17 // 金额激励规则阶段中文表示 17 // 金额激励规则阶段中文表示
18 MoneyIncentivesStageCN string `json:"moneyIncentivesStageCN"` 18 MoneyIncentivesStageCN string `json:"moneyIncentivesStageCN"`
19 // 金额激励阶段有效期结束 19 // 金额激励阶段有效期结束
@@ -65,7 +65,7 @@ func (moneyIncentivesRule *MoneyIncentivesRule) Update(data map[string]interface @@ -65,7 +65,7 @@ func (moneyIncentivesRule *MoneyIncentivesRule) Update(data map[string]interface
65 moneyIncentivesRule.MoneyIncentivesAmount = moneyIncentivesAmount.(float64) 65 moneyIncentivesRule.MoneyIncentivesAmount = moneyIncentivesAmount.(float64)
66 } 66 }
67 if moneyIncentivesStage, ok := data["moneyIncentivesStage"]; ok { 67 if moneyIncentivesStage, ok := data["moneyIncentivesStage"]; ok {
68 - moneyIncentivesRule.MoneyIncentivesStage = moneyIncentivesStage.(int64) 68 + moneyIncentivesRule.MoneyIncentivesStage = moneyIncentivesStage.(int32)
69 } 69 }
70 if moneyIncentivesStageEnd, ok := data["moneyIncentivesStageEnd"]; ok { 70 if moneyIncentivesStageEnd, ok := data["moneyIncentivesStageEnd"]; ok {
71 moneyIncentivesRule.MoneyIncentivesStageEnd = moneyIncentivesStageEnd.(time.Time) 71 moneyIncentivesRule.MoneyIncentivesStageEnd = moneyIncentivesStageEnd.(time.Time)
@@ -7,5 +7,5 @@ import ( @@ -7,5 +7,5 @@ import (
7 7
8 type ConfirmMoneyIncentivesEstimateService interface { 8 type ConfirmMoneyIncentivesEstimateService interface {
9 coreDomain.DomainEventPublisher 9 coreDomain.DomainEventPublisher
10 - Confirm(contract *domain.CooperationContract, stage int64, undertakerUIDs []int64) ([]*DividendsEstimateDetail, error) 10 + Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*DividendsEstimateDetail, error)
11 } 11 }
@@ -53,6 +53,28 @@ func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(quer @@ -53,6 +53,28 @@ func (dao *DividendsEstimateDao) CheckDividendsEstimateOrderNumberAvailable(quer
53 return !ok, err 53 return !ok, err
54 } 54 }
55 55
  56 +// UserEstimated 判断金额激励用户是否已分红(已生成分红预算单)
  57 +func (dao *DividendsEstimateDao) UserEstimated(queryOptions map[string]interface{}) (bool, error) {
  58 + tx := dao.transactionContext.PgTx
  59 + var dividendsEstimateModels []*models.DividendsEstimate
  60 + query := tx.Model(&dividendsEstimateModels)
  61 + if undertakerUid, ok := queryOptions["undertakerUid"]; ok && undertakerUid.(int64) != 0 {
  62 + query = query.Where(`dividends_estimate.dividends_user @> '{"userId":"?"}'`, undertakerUid)
  63 + }
  64 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  65 + query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId)
  66 + }
  67 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  68 + query = query.Where(`dividends_estimate.org @> '{"orgId":"?"}'`, orgId)
  69 + }
  70 + // 非取消的分红预算单
  71 + query.Where("dividends_estimate.is_canceled = ?", false)
  72 + // 过滤出金额激励
  73 + query.Where("dividends_estimate.dividends_type = ?", 3)
  74 + ok, err := query.Exists()
  75 + return ok, err
  76 +}
  77 +
56 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) { 78 func NewDividendsEstimateDao(transactionContext *pgTransaction.TransactionContext) (*DividendsEstimateDao, error) {
57 if transactionContext == nil { 79 if transactionContext == nil {
58 return nil, fmt.Errorf("transactionContext参数不能为空") 80 return nil, fmt.Errorf("transactionContext参数不能为空")
@@ -88,7 +88,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -88,7 +88,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
88 Company: undertaker.Company, 88 Company: undertaker.Company,
89 }, 89 },
90 DividendsParticipateType: domain.UNDERTAKER, 90 DividendsParticipateType: domain.UNDERTAKER,
91 - DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), 91 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
92 DividendsAmount: undertakerDividendsAmount, 92 DividendsAmount: undertakerDividendsAmount,
93 }) 93 })
94 // 添加推荐人分红预算信息详情 94 // 添加推荐人分红预算信息详情
@@ -109,7 +109,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -109,7 +109,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
109 Company: undertaker.Referrer.Company, 109 Company: undertaker.Referrer.Company,
110 }, 110 },
111 DividendsParticipateType: domain.REFERRER, 111 DividendsParticipateType: domain.REFERRER,
112 - DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), 112 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
113 DividendsAmount: referrerDividendsAmount, 113 DividendsAmount: referrerDividendsAmount,
114 }) 114 })
115 } 115 }
@@ -131,7 +131,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -131,7 +131,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
131 Company: undertaker.Salesman.Company, 131 Company: undertaker.Salesman.Company,
132 }, 132 },
133 DividendsParticipateType: domain.SALESMAN, 133 DividendsParticipateType: domain.SALESMAN,
134 - DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), 134 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
135 DividendsAmount: salesmanDividendsAmount, 135 DividendsAmount: salesmanDividendsAmount,
136 }) 136 })
137 } 137 }
@@ -175,7 +175,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -175,7 +175,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
175 Company: undertaker.Company, 175 Company: undertaker.Company,
176 }, 176 },
177 DividendsParticipateType: domain.UNDERTAKER, 177 DividendsParticipateType: domain.UNDERTAKER,
178 - DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), 178 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
179 DividendsAmount: undertakerDividendsAmount, 179 DividendsAmount: undertakerDividendsAmount,
180 }) 180 })
181 // 添加推荐人分红退货预算信息详情 181 // 添加推荐人分红退货预算信息详情
@@ -196,7 +196,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -196,7 +196,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
196 Company: undertaker.Referrer.Company, 196 Company: undertaker.Referrer.Company,
197 }, 197 },
198 DividendsParticipateType: domain.REFERRER, 198 DividendsParticipateType: domain.REFERRER,
199 - DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), 199 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
200 DividendsAmount: referrerDividendsAmount, 200 DividendsAmount: referrerDividendsAmount,
201 }) 201 })
202 } 202 }
@@ -218,7 +218,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo @@ -218,7 +218,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo
218 Company: undertaker.Salesman.Company, 218 Company: undertaker.Salesman.Company,
219 }, 219 },
220 DividendsParticipateType: domain.SALESMAN, 220 DividendsParticipateType: domain.SALESMAN,
221 - DividendsStage: int32(dividendsIncentivesRuleMatched.DividendsIncentivesStage), 221 + DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage,
222 DividendsAmount: salesmanDividendsAmount, 222 DividendsAmount: salesmanDividendsAmount,
223 }) 223 })
224 } 224 }
@@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
9 "time" 10 "time"
10 ) 11 )
11 12
@@ -14,9 +15,28 @@ type ConfirmMoneyIncentivesEstimateService struct { @@ -14,9 +15,28 @@ type ConfirmMoneyIncentivesEstimateService struct {
14 transactionContext *pgTransaction.TransactionContext 15 transactionContext *pgTransaction.TransactionContext
15 } 16 }
16 17
17 -func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int64, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) { 18 +func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *domain.CooperationContract, stage int32, undertakerUIDs []int64) ([]*service.DividendsEstimateDetail, error) {
  19 + //var dividendsEstimateRepository domain.DividendsEstimateRepository // 分红预算单仓储
  20 + var dividendsEstimateDao *dao.DividendsEstimateDao // 分红预算DAO
  21 +
  22 + // 分红预算单仓储初始化
  23 + //if repo, err := repository.NewDividendsEstimateRepository(domainService.transactionContext); err != nil {
  24 + // return nil, err
  25 + //} else {
  26 + // dividendsEstimateRepository = repo
  27 + //}
  28 +
  29 + // 分红预算DAO初始化
  30 + if estimateDao, err := dao.NewDividendsEstimateDao(domainService.transactionContext); err != nil {
  31 + return nil, err
  32 + } else {
  33 + dividendsEstimateDao = estimateDao
  34 + }
  35 +
  36 + // 金额激励详情
18 var dividendsEstimateDetails []*service.DividendsEstimateDetail 37 var dividendsEstimateDetails []*service.DividendsEstimateDetail
19 - // 获取金额激励规则 38 +
  39 + // 匹配金额激励规则
20 var moneyIncentivesRuleMatched *domain.MoneyIncentivesRule 40 var moneyIncentivesRuleMatched *domain.MoneyIncentivesRule
21 for _, moneyIncentivesRule := range contract.MoneyIncentivesRules { 41 for _, moneyIncentivesRule := range contract.MoneyIncentivesRules {
22 if moneyIncentivesRule.MoneyIncentivesStage == stage { 42 if moneyIncentivesRule.MoneyIncentivesStage == stage {
@@ -24,12 +44,83 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do @@ -24,12 +44,83 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do
24 break 44 break
25 } 45 }
26 } 46 }
27 - // 判断分红阶段时间 47 +
  48 + // 判断金额激励阶段是否合法
28 currentTime := time.Now() 49 currentTime := time.Now()
29 if moneyIncentivesRuleMatched.MoneyIncentivesStageStart.After(currentTime) { 50 if moneyIncentivesRuleMatched.MoneyIncentivesStageStart.After(currentTime) {
30 return nil, fmt.Errorf("还未到分红时间") 51 return nil, fmt.Errorf("还未到分红时间")
31 } 52 }
32 - // TODO 判断承接人在当前阶段是否已经分红 53 +
  54 + // 金额激励预算
  55 + for _, undertaker := range contract.Undertakers {
  56 + // 判断承接人在当前阶段是否已经分红
  57 + undertakerEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  58 + "undertakerUid": undertaker,
  59 + "companyId": contract.Company.CompanyId,
  60 + "orgId": contract.Org.OrgId,
  61 + })
  62 + if err != nil {
  63 + return nil, err
  64 + }
  65 + if undertakerEstimated {
  66 + return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
  67 + } else {
  68 + undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (1 - (moneyIncentivesRuleMatched.SalesmanPercentage+moneyIncentivesRuleMatched.ReferrerPercentage)/100)
  69 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  70 + DividendsUser: &domain.User{
  71 + UserId: undertaker.UserId,
  72 + UserBaseId: undertaker.UserBaseId,
  73 + Org: undertaker.Org,
  74 + Orgs: undertaker.Orgs,
  75 + Department: undertaker.Department,
  76 + Roles: undertaker.Roles,
  77 + UserInfo: undertaker.UserInfo,
  78 + UserType: undertaker.UserType,
  79 + UserName: undertaker.UserName,
  80 + UserPhone: undertaker.UserPhone,
  81 + Status: undertaker.Status,
  82 + Company: undertaker.Company,
  83 + },
  84 + DividendsParticipateType: domain.MONEY_INCENTIVES,
  85 + DividendsStage: stage,
  86 + DividendsAmount: undertakerDividendsAmount,
  87 + })
  88 + }
  89 + // 判断业务员在当前阶段是否已经分红
  90 + salesmanEstimated, err := dividendsEstimateDao.UserEstimated(map[string]interface{}{
  91 + "undertakerUid": undertaker.Salesman.UserId,
  92 + "companyId": contract.Company.CompanyId,
  93 + "orgId": contract.Org.OrgId,
  94 + })
  95 + if err != nil {
  96 + return nil, err
  97 + }
  98 + if salesmanEstimated {
  99 + return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红")
  100 + } else {
  101 + undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (1 - (moneyIncentivesRuleMatched.SalesmanPercentage+moneyIncentivesRuleMatched.ReferrerPercentage)/100)
  102 + dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{
  103 + DividendsUser: &domain.User{
  104 + UserId: undertaker.UserId,
  105 + UserBaseId: undertaker.UserBaseId,
  106 + Org: undertaker.Org,
  107 + Orgs: undertaker.Orgs,
  108 + Department: undertaker.Department,
  109 + Roles: undertaker.Roles,
  110 + UserInfo: undertaker.UserInfo,
  111 + UserType: undertaker.UserType,
  112 + UserName: undertaker.UserName,
  113 + UserPhone: undertaker.UserPhone,
  114 + Status: undertaker.Status,
  115 + Company: undertaker.Company,
  116 + },
  117 + DividendsParticipateType: domain.MONEY_INCENTIVES,
  118 + DividendsStage: stage,
  119 + DividendsAmount: undertakerDividendsAmount,
  120 + })
  121 + }
  122 + // 判断关联业务员在当前阶段是否已经分红
  123 + }
33 return dividendsEstimateDetails, nil 124 return dividendsEstimateDetails, nil
34 } 125 }
35 126
@@ -18,7 +18,7 @@ type DividendsIncentivesRule struct { @@ -18,7 +18,7 @@ type DividendsIncentivesRule struct {
18 // 分红规则激励百分点 18 // 分红规则激励百分点
19 DividendsIncentivesPercentage float64 `comment:"分红规则激励百分点"` 19 DividendsIncentivesPercentage float64 `comment:"分红规则激励百分点"`
20 // 分红规则激励阶段,阶段返回时需要转换为中文数字 20 // 分红规则激励阶段,阶段返回时需要转换为中文数字
21 - DividendsIncentivesStage int64 `comment:"分红规则激励阶段,阶段返回时需要转换为中文数字"` 21 + DividendsIncentivesStage int32 `comment:"分红规则激励阶段,阶段返回时需要转换为中文数字"`
22 // 分红规则激励阶段结束 22 // 分红规则激励阶段结束
23 DividendsIncentivesStageEnd time.Time `comment:"分红规则激励阶段结束"` 23 DividendsIncentivesStageEnd time.Time `comment:"分红规则激励阶段结束"`
24 // 分红规则激励阶段开始 24 // 分红规则激励阶段开始
@@ -14,7 +14,7 @@ type MoneyIncentivesRule struct { @@ -14,7 +14,7 @@ type MoneyIncentivesRule struct {
14 // 激励金额 14 // 激励金额
15 MoneyIncentivesAmount float64 `comment:"激励金额"` 15 MoneyIncentivesAmount float64 `comment:"激励金额"`
16 // 金额激励阶段,阶段返回时需要转换为中文数字 16 // 金额激励阶段,阶段返回时需要转换为中文数字
17 - MoneyIncentivesStage int64 `comment:"金额激励阶段,阶段返回时需要转换为中文数字"` 17 + MoneyIncentivesStage int32 `comment:"金额激励阶段,阶段返回时需要转换为中文数字"`
18 // 金额激励阶段有效期结束 18 // 金额激励阶段有效期结束
19 MoneyIncentivesStageEnd time.Time `comment:"金额激励阶段有效期结束"` 19 MoneyIncentivesStageEnd time.Time `comment:"金额激励阶段有效期结束"`
20 // 金额激励阶段有效期开始 20 // 金额激励阶段有效期开始