Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/allied-creat…
…ion-cooperation into dev
正在显示
25 个修改的文件
包含
412 行增加
和
94 行删除
@@ -17,6 +17,8 @@ type SearchCooperationApplicationQuery struct { | @@ -17,6 +17,8 @@ type SearchCooperationApplicationQuery struct { | ||
17 | ApplicantName string `cname:"申请人姓名" json:"applicantName,omitempty"` | 17 | ApplicantName string `cname:"申请人姓名" json:"applicantName,omitempty"` |
18 | // 共创申请审核状态,1待审核,2已同意,3已拒绝 | 18 | // 共创申请审核状态,1待审核,2已同意,3已拒绝 |
19 | CooperationApplicationStatus int32 `cname:"共创申请审核状态" json:"cooperationApplicationStatus,omitempty"` | 19 | CooperationApplicationStatus int32 `cname:"共创申请审核状态" json:"cooperationApplicationStatus,omitempty"` |
20 | + // 是否被取消标记 1正常,2取消,3所有 | ||
21 | + IsCanceled int32 `cname:"取消状态" json:"isCanceled,omitempty"` | ||
20 | // 页面大小 | 22 | // 页面大小 |
21 | PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"` | 23 | PageSize int64 `cname:"页面大小" json:"pageSize,omitempty"` |
22 | // 页面大小 | 24 | // 页面大小 |
@@ -205,6 +205,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop | @@ -205,6 +205,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop | ||
205 | if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil { | 205 | if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil { |
206 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 206 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
207 | } else { | 207 | } else { |
208 | + // 更新共创项目申请人计数 | ||
209 | + cooperationProject.ApplicantCount = cooperationProject.ApplicantCount + 1 | ||
210 | + if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil { | ||
211 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
212 | + } | ||
208 | if err := transactionContext.CommitTransaction(); err != nil { | 213 | if err := transactionContext.CommitTransaction(); err != nil { |
209 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 214 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
210 | } | 215 | } |
@@ -269,6 +274,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop | @@ -269,6 +274,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApprovalCoop | ||
269 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationApplicationId, 10))) | 274 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(cooperationApplicationId, 10))) |
270 | } | 275 | } |
271 | 276 | ||
277 | + // 校验共创申请是否已经审核过 | ||
278 | + if cooperationApplication.CooperationApplicationStatus != 1 { | ||
279 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "改申请已经审核过") | ||
280 | + } | ||
281 | + | ||
272 | if approvalCooperationApplicationCommand.Action == 1 { | 282 | if approvalCooperationApplicationCommand.Action == 1 { |
273 | cooperationApplication.CooperationApplicationStatus = 2 | 283 | cooperationApplication.CooperationApplicationStatus = 2 |
274 | } else if approvalCooperationApplicationCommand.Action == 2 { | 284 | } else if approvalCooperationApplicationCommand.Action == 2 { |
@@ -346,7 +356,12 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova | @@ -346,7 +356,12 @@ func (cooperationApplicationService *CooperationApplicationService) BatchApprova | ||
346 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 356 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
347 | } else { | 357 | } else { |
348 | if count > 0 { | 358 | if count > 0 { |
349 | - for i, _ := range cooperationApplications { | 359 | + for i, cooperationApplication := range cooperationApplications { |
360 | + // 校验共创申请是否已经审核过 | ||
361 | + if cooperationApplication.CooperationApplicationStatus != 1 { | ||
362 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "改申请已经审核过") | ||
363 | + } | ||
364 | + // 更新共创申请数据 | ||
350 | cooperationApplications[i].CooperationApplicationVerifyDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription | 365 | cooperationApplications[i].CooperationApplicationVerifyDescription = batchApprovalCooperationApplicationCommand.CooperationApplicationVerifyDescription |
351 | if batchApprovalCooperationApplicationCommand.Action == 1 { // 同意 | 366 | if batchApprovalCooperationApplicationCommand.Action == 1 { // 同意 |
352 | cooperationApplications[i].CooperationApplicationStatus = 2 | 367 | cooperationApplications[i].CooperationApplicationStatus = 2 |
@@ -421,7 +436,12 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr | @@ -421,7 +436,12 @@ func (cooperationApplicationService *CooperationApplicationService) OneClickAppr | ||
421 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 436 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
422 | } else { | 437 | } else { |
423 | if count > 0 { | 438 | if count > 0 { |
424 | - for i, _ := range cooperationApplications { | 439 | + for i, cooperationApplication := range cooperationApplications { |
440 | + // 校验共创申请是否已经审核过 | ||
441 | + if cooperationApplication.CooperationApplicationStatus != 1 { | ||
442 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "改申请已经审核过") | ||
443 | + } | ||
444 | + // 更新共创申请 | ||
425 | if oneClickApprovalCooperationApplicationCommand.Action == 1 { | 445 | if oneClickApprovalCooperationApplicationCommand.Action == 1 { |
426 | cooperationApplications[i].CooperationApplicationStatus = 2 | 446 | cooperationApplications[i].CooperationApplicationStatus = 2 |
427 | } else if oneClickApprovalCooperationApplicationCommand.Action == 2 { | 447 | } else if oneClickApprovalCooperationApplicationCommand.Action == 2 { |
@@ -784,8 +804,19 @@ func (cooperationApplicationService *CooperationApplicationService) CancelCooper | @@ -784,8 +804,19 @@ func (cooperationApplicationService *CooperationApplicationService) CancelCooper | ||
784 | defer func() { | 804 | defer func() { |
785 | _ = transactionContext.RollbackTransaction() | 805 | _ = transactionContext.RollbackTransaction() |
786 | }() | 806 | }() |
807 | + | ||
787 | //TODO 校验用户菜单模块权限 | 808 | //TODO 校验用户菜单模块权限 |
788 | 809 | ||
810 | + // 共创项目仓储初始化 | ||
811 | + var cooperationProjectRepository domain.CooperationProjectRepository | ||
812 | + if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{ | ||
813 | + "transactionContext": transactionContext, | ||
814 | + }); err != nil { | ||
815 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
816 | + } else { | ||
817 | + cooperationProjectRepository = value | ||
818 | + } | ||
819 | + | ||
789 | // 共创申请仓储初始化 | 820 | // 共创申请仓储初始化 |
790 | var cooperationApplicationRepository domain.CooperationApplicationRepository | 821 | var cooperationApplicationRepository domain.CooperationApplicationRepository |
791 | if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{ | 822 | if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{ |
@@ -811,13 +842,26 @@ func (cooperationApplicationService *CooperationApplicationService) CancelCooper | @@ -811,13 +842,26 @@ func (cooperationApplicationService *CooperationApplicationService) CancelCooper | ||
811 | }); err != nil { | 842 | }); err != nil { |
812 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | 843 | return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) |
813 | } | 844 | } |
814 | - if cooperationApplication, err := cooperationApplicationRepository.Save(cooperationApplication); err != nil { | 845 | + if cooperationApplicationSaved, err := cooperationApplicationRepository.Save(cooperationApplication); err != nil { |
815 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 846 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
816 | } else { | 847 | } else { |
848 | + // 获取共创项目 | ||
849 | + cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": cooperationApplicationSaved.CooperationProject.CooperationProjectId}) | ||
850 | + if err != nil { | ||
851 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目不存在") | ||
852 | + } | ||
853 | + if cooperationProject == nil { | ||
854 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", strconv.FormatInt(cooperationApplicationSaved.CooperationProject.CooperationProjectId, 10))) | ||
855 | + } | ||
856 | + // 更新共创项目申请统计 | ||
857 | + cooperationProject.ApplicantCount = cooperationProject.ApplicantCount - 1 | ||
858 | + if _, err := cooperationProjectRepository.Save(cooperationProject); err != nil { | ||
859 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
860 | + } | ||
817 | if err := transactionContext.CommitTransaction(); err != nil { | 861 | if err := transactionContext.CommitTransaction(); err != nil { |
818 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 862 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
819 | } | 863 | } |
820 | - return cooperationApplication, nil | 864 | + return cooperationApplicationSaved, nil |
821 | } | 865 | } |
822 | } | 866 | } |
823 | 867 |
@@ -17,6 +17,8 @@ type SearchCooperationContractQuery struct { | @@ -17,6 +17,8 @@ type SearchCooperationContractQuery struct { | ||
17 | CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber,omitempty"` | 17 | CooperationContractNumber string `cname:"共创合约编号" json:"cooperationContractNumber,omitempty"` |
18 | // 发起人姓名 | 18 | // 发起人姓名 |
19 | SponsorName string `cname:"发起人姓名" json:"sponsorName,omitempty"` | 19 | SponsorName string `cname:"发起人姓名" json:"sponsorName,omitempty"` |
20 | + // 激励类型 | ||
21 | + IncentivesType int32 `cname:"激励类型" json:"incentivesType,omitempty"` | ||
20 | // 公司ID,通过集成REST上下文获取 | 22 | // 公司ID,通过集成REST上下文获取 |
21 | CompanyId int64 `cname:"公司ID" json:"companyId"` | 23 | CompanyId int64 `cname:"公司ID" json:"companyId"` |
22 | // 组织机构ID | 24 | // 组织机构ID |
@@ -30,7 +32,6 @@ type SearchCooperationContractQuery struct { | @@ -30,7 +32,6 @@ type SearchCooperationContractQuery struct { | ||
30 | } | 32 | } |
31 | 33 | ||
32 | func (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) { | 34 | func (searchCooperationContractQuery *SearchCooperationContractQuery) Valid(validation *validation.Validation) { |
33 | - //validation.SetError("CustomValid", "未实现的自定义认证") | ||
34 | } | 35 | } |
35 | 36 | ||
36 | func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error { | 37 | func (searchCooperationContractQuery *SearchCooperationContractQuery) ValidateQuery() error { |
@@ -126,7 +126,9 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC | @@ -126,7 +126,9 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC | ||
126 | } | 126 | } |
127 | 127 | ||
128 | // 生成共创合约编号 | 128 | // 生成共创合约编号 |
129 | - contractNumber, err2 := cooperationContractDao.GenerateContractNumber() | 129 | + contractNumber, err2 := cooperationContractDao.GenerateContractNumber(map[string]interface{}{ |
130 | + "companyId": createCooperationContractCommand.CompanyId, | ||
131 | + }) | ||
130 | if err2 != nil { | 132 | if err2 != nil { |
131 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error()) | 133 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err2.Error()) |
132 | } | 134 | } |
@@ -134,7 +136,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC | @@ -134,7 +136,6 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC | ||
134 | // 校验共创合约编号是否唯一 | 136 | // 校验共创合约编号是否唯一 |
135 | numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{ | 137 | numberAvailable, _ := cooperationContractDao.CheckContractNumberAvailable(map[string]interface{}{ |
136 | "companyId": createCooperationContractCommand.CompanyId, | 138 | "companyId": createCooperationContractCommand.CompanyId, |
137 | - "orgId": createCooperationContractCommand.OrgId, | ||
138 | "cooperationContractNumber": contractNumber, | 139 | "cooperationContractNumber": contractNumber, |
139 | }) | 140 | }) |
140 | if !numberAvailable { | 141 | if !numberAvailable { |
@@ -1054,6 +1055,16 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | @@ -1054,6 +1055,16 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | ||
1054 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err16.Error()) | 1055 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err16.Error()) |
1055 | } | 1056 | } |
1056 | 1057 | ||
1058 | + var contractAttachments []*domain.Attachment | ||
1059 | + for _, attachment := range undertaker.ContractAttachment { | ||
1060 | + contractAttachments = append(contractAttachments, &domain.Attachment{ | ||
1061 | + FileType: attachment.FileType, | ||
1062 | + Name: attachment.Name, | ||
1063 | + Url: attachment.Url, | ||
1064 | + FileSize: attachment.FileSize, | ||
1065 | + }) | ||
1066 | + } | ||
1067 | + | ||
1057 | undertakers = append(undertakers, &domain.Undertaker{ | 1068 | undertakers = append(undertakers, &domain.Undertaker{ |
1058 | UndertakerId: undertakerId, | 1069 | UndertakerId: undertakerId, |
1059 | UserId: undertakerDomain.UserId, | 1070 | UserId: undertakerDomain.UserId, |
@@ -1069,7 +1080,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | @@ -1069,7 +1080,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | ||
1069 | Salesman: salesmanDomain, | 1080 | Salesman: salesmanDomain, |
1070 | Status: undertakerDomain.Status, | 1081 | Status: undertakerDomain.Status, |
1071 | Company: undertakerDomain.Company, | 1082 | Company: undertakerDomain.Company, |
1072 | - ContractAttachment: nil, | 1083 | + ContractAttachment: contractAttachments, |
1073 | }) | 1084 | }) |
1074 | } | 1085 | } |
1075 | // 更新承接人 | 1086 | // 更新承接人 |
@@ -1117,7 +1128,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | @@ -1117,7 +1128,7 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC | ||
1117 | MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage, | 1128 | MoneyIncentivesStage: moneyIncentivesRule.MoneyIncentivesStage, |
1118 | MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd, | 1129 | MoneyIncentivesStageEnd: moneyIncentivesRule.MoneyIncentivesStageEnd, |
1119 | MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart, | 1130 | MoneyIncentivesStageStart: moneyIncentivesRule.MoneyIncentivesStageStart, |
1120 | - MoneyIncentivesTime: time.Now(), | 1131 | + MoneyIncentivesTime: moneyIncentivesRule.MoneyIncentivesTime, |
1121 | ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage, | 1132 | ReferrerPercentage: moneyIncentivesRule.ReferrerPercentage, |
1122 | SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage, | 1133 | SalesmanPercentage: moneyIncentivesRule.SalesmanPercentage, |
1123 | Org: organization, | 1134 | Org: organization, |
@@ -163,7 +163,9 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro | @@ -163,7 +163,9 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro | ||
163 | cooperationProjectDao = value | 163 | cooperationProjectDao = value |
164 | } | 164 | } |
165 | // 生成共创项目编号 | 165 | // 生成共创项目编号 |
166 | - projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber() | 166 | + projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber(map[string]interface{}{ |
167 | + "companyId": createCooperationProjectCommand.CompanyId, | ||
168 | + }) | ||
167 | if err2 != nil { | 169 | if err2 != nil { |
168 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 170 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
169 | } | 171 | } |
@@ -145,7 +145,6 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | @@ -145,7 +145,6 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | ||
145 | } | 145 | } |
146 | 146 | ||
147 | // 预算明细 | 147 | // 预算明细 |
148 | - var creditAccounts []*domain.CreditAccount | ||
149 | var accountDetail []*domain.AccountDetail | 148 | var accountDetail []*domain.AccountDetail |
150 | var settlementAmount float64 | 149 | var settlementAmount float64 |
151 | for _, dividendsEstimate := range dividendsEstimates { | 150 | for _, dividendsEstimate := range dividendsEstimates { |
@@ -158,7 +157,9 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | @@ -158,7 +157,9 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | ||
158 | } | 157 | } |
159 | 158 | ||
160 | // 生成账期结算单号 | 159 | // 生成账期结算单号 |
161 | - creditAccountNumber, err12 := creditAccountDao.GenerateCreditAccountNumber() | 160 | + creditAccountNumber, err12 := creditAccountDao.GenerateCreditAccountNumber(map[string]interface{}{ |
161 | + "companyId": createCreditAccountCommand.CompanyId, | ||
162 | + }) | ||
162 | if err12 != nil { | 163 | if err12 != nil { |
163 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "生成账期结算单号错误") | 164 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "生成账期结算单号错误") |
164 | } | 165 | } |
@@ -179,7 +180,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | @@ -179,7 +180,7 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | ||
179 | Department: dividendsEstimates[0].DividendsUser.Department, | 180 | Department: dividendsEstimates[0].DividendsUser.Department, |
180 | Roles: dividendsEstimates[0].DividendsUser.Roles, | 181 | Roles: dividendsEstimates[0].DividendsUser.Roles, |
181 | UserInfo: dividendsEstimates[0].DividendsUser.UserInfo, | 182 | UserInfo: dividendsEstimates[0].DividendsUser.UserInfo, |
182 | - UserName: dividendsEstimates[0].DividendsUser.UserName, | 183 | + UserName: dividendsEstimates[0].DividendsUser.UserInfo.UserName, |
183 | UserPhone: dividendsEstimates[0].DividendsUser.UserPhone, | 184 | UserPhone: dividendsEstimates[0].DividendsUser.UserPhone, |
184 | UserType: dividendsEstimates[0].DividendsUser.UserType, | 185 | UserType: dividendsEstimates[0].DividendsUser.UserType, |
185 | Status: dividendsEstimates[0].DividendsUser.Status, | 186 | Status: dividendsEstimates[0].DividendsUser.Status, |
@@ -199,13 +200,19 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | @@ -199,13 +200,19 @@ func (creditAccountService *CreditAccountService) CreateCreditAccount(createCred | ||
199 | if creditAccount, err13 := creditAccountRepository.Save(newCreditAccount); err13 != nil { | 200 | if creditAccount, err13 := creditAccountRepository.Save(newCreditAccount); err13 != nil { |
200 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error()) | 201 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err13.Error()) |
201 | } else { | 202 | } else { |
202 | - creditAccounts = append(creditAccounts, creditAccount) | ||
203 | - } | ||
204 | - | ||
205 | - if err14 := transactionContext.CommitTransaction(); err14 != nil { | ||
206 | - return nil, application.ThrowError(application.TRANSACTION_ERROR, err14.Error()) | 203 | + // 变更分红预算单结算状态 |
204 | + for i, _ := range dividendsEstimates { | ||
205 | + dividendsEstimates[i].DividendsAccountStatus = 2 | ||
206 | + } | ||
207 | + _, err3 := dividendsEstimateRepository.UpdateMany(dividendsEstimates) | ||
208 | + if err3 != nil { | ||
209 | + return nil, err3 | ||
210 | + } | ||
211 | + if err14 := transactionContext.CommitTransaction(); err14 != nil { | ||
212 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err14.Error()) | ||
213 | + } | ||
214 | + return creditAccount, nil | ||
207 | } | 215 | } |
208 | - return creditAccounts, nil | ||
209 | } | 216 | } |
210 | } | 217 | } |
211 | 218 | ||
@@ -353,6 +360,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | @@ -353,6 +360,7 @@ func (creditAccountService *CreditAccountService) PayCreditAccount(payCreditAcco | ||
353 | if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil { | 360 | if creditAccountSaved, err4 := creditAccountRepository.Save(creditAccount); err4 != nil { |
354 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error()) | 361 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err4.Error()) |
355 | } else { | 362 | } else { |
363 | + // TODO 更新分红预算单结算状态(已支付) | ||
356 | if err3 := transactionContext.CommitTransaction(); err3 != nil { | 364 | if err3 := transactionContext.CommitTransaction(); err3 != nil { |
357 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error()) | 365 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err3.Error()) |
358 | } | 366 | } |
@@ -609,8 +609,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -609,8 +609,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
609 | }) | 609 | }) |
610 | } | 610 | } |
611 | 611 | ||
612 | - // 统计分红订单 | ||
613 | - var countDividendsOrders int32 | 612 | + // 统计成功预算的分红订单 |
613 | + var estimateSuccessfullyDividendsOrders map[string]int | ||
614 | + | ||
615 | + // 统计预算失败的分红订单 | ||
616 | + var estimateFailedDividendsOrders map[string]int | ||
614 | 617 | ||
615 | // 获取订单产品 | 618 | // 获取订单产品 |
616 | if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{ | 619 | if _, orderGoods, err := orderGoodRepository.Find(map[string]interface{}{ |
@@ -622,7 +625,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -622,7 +625,6 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
622 | // 统计当前分红预算单数 | 625 | // 统计当前分红预算单数 |
623 | count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ | 626 | count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ |
624 | "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId, | 627 | "companyId": confirmDividendsIncentivesEstimateCommand.CompanyId, |
625 | - "orgId": confirmDividendsIncentivesEstimateCommand.OrgId, | ||
626 | }) | 628 | }) |
627 | if err != nil { | 629 | if err != nil { |
628 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 630 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
@@ -694,7 +696,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -694,7 +696,11 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
694 | } else { | 696 | } else { |
695 | for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails { | 697 | for _, dividendsReturnedEstimateDetail := range dividendsReturnedEstimateDetails { |
696 | // 生成分红预算单号 | 698 | // 生成分红预算单号 |
697 | - dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber() | 699 | + dividendsEstimateOrderNumber, err := dividendsReturnedEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate) |
700 | + if err != nil { | ||
701 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
702 | + } | ||
703 | + countDividendsEstimate = countDividendsEstimate + 1 | ||
698 | if err != nil { | 704 | if err != nil { |
699 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 705 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
700 | } | 706 | } |
@@ -730,16 +736,17 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | @@ -730,16 +736,17 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent | ||
730 | log.Logger.Info("新增的分红预算单", map[string]interface{}{ | 736 | log.Logger.Info("新增的分红预算单", map[string]interface{}{ |
731 | "dividendsEstimates": dividendsEstimates, | 737 | "dividendsEstimates": dividendsEstimates, |
732 | }) | 738 | }) |
733 | - | ||
734 | if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil { | 739 | if dividendsEstimatesSaved, err := dividendsEstimateRepository.SaveMany(dividendsEstimates); err != nil { |
735 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 740 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
736 | } else { | 741 | } else { |
737 | if err := transactionContext.CommitTransaction(); err != nil { | 742 | if err := transactionContext.CommitTransaction(); err != nil { |
738 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 743 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
739 | } | 744 | } |
740 | - // TODO 分析成功和失败原因 | 745 | + // 分析成功和失败原因 |
741 | successfullyCount := len(dividendsEstimatesSaved) | 746 | successfullyCount := len(dividendsEstimatesSaved) |
742 | - return fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", countDividendsOrders, successfullyCount, 0, ""), nil | 747 | + return map[string]interface{}{ |
748 | + "report": fmt.Sprintf("已完成%d笔单订单分红预算,生成%d笔单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), ""), | ||
749 | + }, nil | ||
743 | } | 750 | } |
744 | } | 751 | } |
745 | } | 752 | } |
@@ -849,16 +856,22 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives | @@ -849,16 +856,22 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmMoneyIncentives | ||
849 | 856 | ||
850 | var dividendsEstimates []*domain.DividendsEstimate | 857 | var dividendsEstimates []*domain.DividendsEstimate |
851 | 858 | ||
859 | + // 统计当前分红预算单数 | ||
860 | + count, err := dividendsEstimateDao.CountDividendsEstimate(map[string]interface{}{ | ||
861 | + "companyId": confirmMoneyIncentivesEstimateCommand.CompanyId, | ||
862 | + }) | ||
863 | + var countDividendsEstimate int64 | ||
852 | // 共创合约预算 | 864 | // 共创合约预算 |
853 | if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil { | 865 | if dividendsEstimateDetails, err2 := confirmMoneyIncentivesEstimateService.Confirm(cooperationContract, confirmMoneyIncentivesEstimateCommand.DividendsIncentivesStage, undertakerUIDs); err2 != nil { |
854 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) | 866 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err2.Error()) |
855 | } else { | 867 | } else { |
856 | for _, dividendsEstimateDetail := range dividendsEstimateDetails { | 868 | for _, dividendsEstimateDetail := range dividendsEstimateDetails { |
857 | // 生成分红预算单号 | 869 | // 生成分红预算单号 |
858 | - dividendsEstimateOrderNumber, err := dividendsEstimateDao.GenerateDividendsEstimateNumber() | 870 | + dividendsEstimateOrderNumber, err := dividendsEstimateDetail.GenerateSpecificDividendsEstimateNumber(int64(count), countDividendsEstimate) |
859 | if err != nil { | 871 | if err != nil { |
860 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 872 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
861 | } | 873 | } |
874 | + countDividendsEstimate = countDividendsEstimate + 1 | ||
862 | dividendsEstimate := &domain.DividendsEstimate{ | 875 | dividendsEstimate := &domain.DividendsEstimate{ |
863 | DividendsEstimateId: 0, | 876 | DividendsEstimateId: 0, |
864 | DividendsAccountStatus: domain.TO_BE_ACCOUNT, | 877 | DividendsAccountStatus: domain.TO_BE_ACCOUNT, |
@@ -100,7 +100,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | @@ -100,7 +100,9 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | ||
100 | } | 100 | } |
101 | 101 | ||
102 | // 生成分红订单号 | 102 | // 生成分红订单号 |
103 | - dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber() | 103 | + dividendsOrderNumber, err := dividendsOrderDao.GenerateDividendsOrderNumber(map[string]interface{}{ |
104 | + "companyId": createDividendsOrderCommand.CompanyId, | ||
105 | + }) | ||
104 | if err != nil { | 106 | if err != nil { |
105 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 107 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
106 | } | 108 | } |
@@ -108,7 +110,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | @@ -108,7 +110,6 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | ||
108 | // 校验分红订单编号是否唯一 | 110 | // 校验分红订单编号是否唯一 |
109 | numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{ | 111 | numberAvailable, err := dividendsOrderDao.CheckDividendsOrderNumberAvailable(map[string]interface{}{ |
110 | "companyId": createDividendsOrderCommand.CompanyId, | 112 | "companyId": createDividendsOrderCommand.CompanyId, |
111 | - "orgId": createDividendsOrderCommand.OrgId, | ||
112 | "dividendsOrderNumber": dividendsOrderNumber, | 113 | "dividendsOrderNumber": dividendsOrderNumber, |
113 | }) | 114 | }) |
114 | if err != nil { | 115 | if err != nil { |
@@ -118,11 +119,44 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | @@ -118,11 +119,44 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | ||
118 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常") | 119 | return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增分红订单异常") |
119 | } | 120 | } |
120 | 121 | ||
122 | + // 合约仓储初始化 | ||
123 | + var cooperationContractRepository domain.CooperationContractRepository | ||
124 | + if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ | ||
125 | + "transactionContext": transactionContext, | ||
126 | + }); err != nil { | ||
127 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
128 | + } else { | ||
129 | + cooperationContractRepository = value | ||
130 | + } | ||
131 | + | ||
132 | + // 查找合约 | ||
133 | + var cooperationContractsMap map[string]*domain.CooperationContract | ||
134 | + if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | ||
135 | + "companyId": createDividendsOrderCommand.CompanyId, | ||
136 | + "orgId": createDividendsOrderCommand.OrgId, | ||
137 | + }); err != nil { | ||
138 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
139 | + } else { | ||
140 | + if count > 0 { | ||
141 | + for _, cooperationContract := range cooperationContracts { | ||
142 | + cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract | ||
143 | + } | ||
144 | + } | ||
145 | + } | ||
146 | + | ||
121 | // 新增订单产品 | 147 | // 新增订单产品 |
122 | var orderGoods []*domain.OrderGood | 148 | var orderGoods []*domain.OrderGood |
123 | var dividendsOrderAmount float64 | 149 | var dividendsOrderAmount float64 |
124 | for _, orderGood := range createDividendsOrderCommand.OrderGoods { | 150 | for _, orderGood := range createDividendsOrderCommand.OrderGoods { |
125 | - orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64() | 151 | + // 计算订单产品金额 |
152 | + orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64() | ||
153 | + | ||
154 | + // 校验共创合约 | ||
155 | + if orderGood.CooperationContractNumber != "" { | ||
156 | + if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 { | ||
157 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红订单产品不能关联金额激励规则") | ||
158 | + } | ||
159 | + } | ||
126 | orderGoods = append(orderGoods, &domain.OrderGood{ | 160 | orderGoods = append(orderGoods, &domain.OrderGood{ |
127 | OrderGoodId: 0, | 161 | OrderGoodId: 0, |
128 | OrderGoodAmount: orderGoodAmount, | 162 | OrderGoodAmount: orderGoodAmount, |
@@ -141,7 +175,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | @@ -141,7 +175,7 @@ func (dividendsOrderService *DividendsOrderService) CreateDividendsOrder(createD | ||
141 | UpdatedAt: time.Time{}, | 175 | UpdatedAt: time.Time{}, |
142 | }) | 176 | }) |
143 | // 计算分红订单金额 | 177 | // 计算分红订单金额 |
144 | - dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64() | 178 | + dividendsOrderAmount, _ = decimal.NewFromFloat(dividendsOrderAmount).Add(decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Sub(decimal.NewFromFloat(orderGood.OrderGoodExpense))).Float64() |
145 | } | 179 | } |
146 | 180 | ||
147 | // 订单时间转换 | 181 | // 订单时间转换 |
@@ -269,13 +303,20 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD | @@ -269,13 +303,20 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD | ||
269 | } | 303 | } |
270 | 304 | ||
271 | // 查找合约 | 305 | // 查找合约 |
272 | - _, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | 306 | + var cooperationContractsMap map[string]*domain.CooperationContract |
307 | + countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | ||
273 | "offsetLimit": false, | 308 | "offsetLimit": false, |
274 | "companyId": importDividendsOrderCommand.CompanyId, | 309 | "companyId": importDividendsOrderCommand.CompanyId, |
275 | "orgId": importDividendsOrderCommand.OrgId, | 310 | "orgId": importDividendsOrderCommand.OrgId, |
276 | }) | 311 | }) |
277 | if err != nil { | 312 | if err != nil { |
278 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 313 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
314 | + } else { | ||
315 | + if countContracts > 0 { | ||
316 | + for _, cooperationContract := range cooperationContracts { | ||
317 | + cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract | ||
318 | + } | ||
319 | + } | ||
279 | } | 320 | } |
280 | 321 | ||
281 | // 分红订单DAO初始化 | 322 | // 分红订单DAO初始化 |
@@ -673,7 +714,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD | @@ -673,7 +714,14 @@ func (dividendsOrderService *DividendsOrderService) ImportDividendsOrder(importD | ||
673 | } | 714 | } |
674 | 715 | ||
675 | // 计算产品金额 | 716 | // 计算产品金额 |
676 | - orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64() | 717 | + orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64() |
718 | + | ||
719 | + // 校验共创合约激励类型是否正确 | ||
720 | + if orderGood.CooperationContractNumber != "" { | ||
721 | + if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 { | ||
722 | + orderGoodErrMap[dividendsOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则") | ||
723 | + } | ||
724 | + } | ||
677 | 725 | ||
678 | orderGoods = append(orderGoods, &domain.OrderGood{ | 726 | orderGoods = append(orderGoods, &domain.OrderGood{ |
679 | OrderGoodId: 0, | 727 | OrderGoodId: 0, |
@@ -24,6 +24,8 @@ type OrderGoods struct { | @@ -24,6 +24,8 @@ type OrderGoods struct { | ||
24 | CooperationContractNumber string `cname:"关联的共创合约编号" json:"cooperationContractNumber"` | 24 | CooperationContractNumber string `cname:"关联的共创合约编号" json:"cooperationContractNumber"` |
25 | // 订单产品费用 | 25 | // 订单产品费用 |
26 | OrderGoodExpense float64 `cname:"订单产品费用" json:"orderGoodExpense"` | 26 | OrderGoodExpense float64 `cname:"订单产品费用" json:"orderGoodExpense"` |
27 | + //行号-错误信息返回 | ||
28 | + LineNumber int `json:"lineNumber"` | ||
27 | } | 29 | } |
28 | 30 | ||
29 | type CreateDividendsReturnedOrderCommand struct { | 31 | type CreateDividendsReturnedOrderCommand struct { |
@@ -99,7 +99,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | @@ -99,7 +99,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | ||
99 | } | 99 | } |
100 | 100 | ||
101 | // 生成分红订单号 | 101 | // 生成分红订单号 |
102 | - dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber() | 102 | + dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{ |
103 | + "companyId": createDividendsReturnedOrderCommand.CompanyId, | ||
104 | + }) | ||
103 | if err != nil { | 105 | if err != nil { |
104 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 106 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
105 | } | 107 | } |
@@ -121,7 +123,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | @@ -121,7 +123,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | ||
121 | // 校验分红退货单编号是否唯一 | 123 | // 校验分红退货单编号是否唯一 |
122 | numberAvailable, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{ | 124 | numberAvailable, err := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{ |
123 | "companyId": createDividendsReturnedOrderCommand.CompanyId, | 125 | "companyId": createDividendsReturnedOrderCommand.CompanyId, |
124 | - "orgId": createDividendsReturnedOrderCommand.OrgId, | ||
125 | "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber, | 126 | "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber, |
126 | }) | 127 | }) |
127 | if err != nil { | 128 | if err != nil { |
@@ -131,13 +132,46 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | @@ -131,13 +132,46 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) CreateDivide | ||
131 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在") | 132 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "分红退货单号已存在") |
132 | } | 133 | } |
133 | 134 | ||
135 | + // 合约仓储初始化 | ||
136 | + var cooperationContractRepository domain.CooperationContractRepository | ||
137 | + if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ | ||
138 | + "transactionContext": transactionContext, | ||
139 | + }); err != nil { | ||
140 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
141 | + } else { | ||
142 | + cooperationContractRepository = value | ||
143 | + } | ||
144 | + | ||
145 | + // 查找合约 | ||
146 | + var cooperationContractsMap map[string]*domain.CooperationContract | ||
147 | + if count, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | ||
148 | + "companyId": createDividendsReturnedOrderCommand.CompanyId, | ||
149 | + "orgId": createDividendsReturnedOrderCommand.OrgId, | ||
150 | + }); err != nil { | ||
151 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
152 | + } else { | ||
153 | + if count > 0 { | ||
154 | + for _, cooperationContract := range cooperationContracts { | ||
155 | + cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract | ||
156 | + } | ||
157 | + } | ||
158 | + } | ||
159 | + | ||
134 | // 退货金额 | 160 | // 退货金额 |
135 | var dividendsReturnedOrderRefund float64 | 161 | var dividendsReturnedOrderRefund float64 |
136 | 162 | ||
137 | - // 获取分红退货单产品 | 163 | + // 新增分红退货单产品 |
138 | var orderGoods []*domain.OrderGood | 164 | var orderGoods []*domain.OrderGood |
139 | for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods { | 165 | for _, orderGood := range createDividendsReturnedOrderCommand.OrderGoods { |
140 | - orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(float64(orderGood.OrderGoodQuantity))).Float64() | 166 | + // 退货产品金额计算 |
167 | + orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64() | ||
168 | + | ||
169 | + // 校验合约激励类型是否正确 | ||
170 | + if orderGood.CooperationContractNumber != "" { | ||
171 | + if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 { | ||
172 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则") | ||
173 | + } | ||
174 | + } | ||
141 | orderGoods = append(orderGoods, &domain.OrderGood{ | 175 | orderGoods = append(orderGoods, &domain.OrderGood{ |
142 | OrderGoodId: 0, | 176 | OrderGoodId: 0, |
143 | OrderGoodAmount: orderGoodAmount, | 177 | OrderGoodAmount: orderGoodAmount, |
@@ -321,6 +355,33 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | @@ -321,6 +355,33 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | ||
321 | dividendsReturnedOrderRepository = value | 355 | dividendsReturnedOrderRepository = value |
322 | } | 356 | } |
323 | 357 | ||
358 | + // 合约仓储初始化 | ||
359 | + var cooperationContractRepository domain.CooperationContractRepository | ||
360 | + if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{ | ||
361 | + "transactionContext": transactionContext, | ||
362 | + }); err != nil { | ||
363 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
364 | + } else { | ||
365 | + cooperationContractRepository = value | ||
366 | + } | ||
367 | + | ||
368 | + // 查找合约 | ||
369 | + var cooperationContractsMap map[string]*domain.CooperationContract | ||
370 | + countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{ | ||
371 | + "offsetLimit": false, | ||
372 | + "companyId": importDividendsReturnedOrderCommand.CompanyId, | ||
373 | + "orgId": importDividendsReturnedOrderCommand.OrgId, | ||
374 | + }) | ||
375 | + if err != nil { | ||
376 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
377 | + } else { | ||
378 | + if countContracts > 0 { | ||
379 | + for _, cooperationContract := range cooperationContracts { | ||
380 | + cooperationContractsMap[cooperationContract.CooperationContractNumber] = cooperationContract | ||
381 | + } | ||
382 | + } | ||
383 | + } | ||
384 | + | ||
324 | // 返回信息表头定义 | 385 | // 返回信息表头定义 |
325 | var tableHeader = map[string]interface{}{ | 386 | var tableHeader = map[string]interface{}{ |
326 | "failReason": "错误详情", | 387 | "failReason": "错误详情", |
@@ -664,7 +725,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | @@ -664,7 +725,9 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | ||
664 | // 批量导入创建退货单 | 725 | // 批量导入创建退货单 |
665 | for _, dividendsReturnedOrder := range createDividendsReturnedOrderCommands { | 726 | for _, dividendsReturnedOrder := range createDividendsReturnedOrderCommands { |
666 | // 生成退货订单号 | 727 | // 生成退货订单号 |
667 | - dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber() | 728 | + dividendsReturnedOrderNumber, err := dividendsReturnedOrderDao.GenerateDividendsReturnedOrderNumber(map[string]interface{}{ |
729 | + "companyId": importDividendsReturnedOrderCommand.CompanyId, | ||
730 | + }) | ||
668 | if err != nil { | 731 | if err != nil { |
669 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 732 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
670 | } | 733 | } |
@@ -672,7 +735,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | @@ -672,7 +735,6 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | ||
672 | // 校验退货订单编号是否唯一 | 735 | // 校验退货订单编号是否唯一 |
673 | numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{ | 736 | numberAvailable, err3 := dividendsReturnedOrderDao.CheckDividendsReturnedOrderNumberAvailable(map[string]interface{}{ |
674 | "companyId": importDividendsReturnedOrderCommand.CompanyId, | 737 | "companyId": importDividendsReturnedOrderCommand.CompanyId, |
675 | - "orgId": importDividendsReturnedOrderCommand.OrgId, | ||
676 | "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber, | 738 | "dividendsReturnedOrderNumber": dividendsReturnedOrderNumber, |
677 | }) | 739 | }) |
678 | if err3 != nil { | 740 | if err3 != nil { |
@@ -685,10 +747,32 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | @@ -685,10 +747,32 @@ func (dividendsReturnedOrderService *DividendsReturnedOrderService) ImportDivide | ||
685 | // 新增订单产品 | 747 | // 新增订单产品 |
686 | var orderGoods []*domain.OrderGood | 748 | var orderGoods []*domain.OrderGood |
687 | var dividendsReturnedOrderAmount float64 | 749 | var dividendsReturnedOrderAmount float64 |
688 | - for _, orderGood := range dividendsReturnedOrder.OrderGoods { | 750 | + orderGoodErrMap := make(map[int]interface{}, 0) |
751 | + for i, orderGood := range dividendsReturnedOrder.OrderGoods { | ||
752 | + // 校验共创合约是否合法 | ||
753 | + contractNumberExist := false | ||
754 | + for _, cooperationContract := range cooperationContracts { | ||
755 | + if orderGood.CooperationContractNumber == cooperationContract.CooperationContractNumber { | ||
756 | + contractNumberExist = true | ||
757 | + break | ||
758 | + } | ||
759 | + } | ||
760 | + if !contractNumberExist { | ||
761 | + orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, fmt.Sprintf("共创合约编号不存在:%s", err)) | ||
762 | + } | ||
763 | + | ||
764 | + // 计算产品金额 | ||
765 | + orderGoodAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodPrice).Mul(decimal.NewFromFloat(orderGood.OrderGoodQuantity)).Float64() | ||
766 | + | ||
767 | + // 校验合约激励类型是否正确 | ||
768 | + if orderGood.CooperationContractNumber != "" { | ||
769 | + if cooperationContractsMap[orderGood.CooperationContractNumber] != nil && cooperationContractsMap[orderGood.CooperationContractNumber].IncentivesType != 1 { | ||
770 | + orderGoodErrMap[dividendsReturnedOrder.OrderGoods[i].LineNumber] = application.ThrowError(application.INTERNAL_SERVER_ERROR, "退货单产品不能关联金额激励规则") | ||
771 | + } | ||
772 | + } | ||
689 | orderGoods = append(orderGoods, &domain.OrderGood{ | 773 | orderGoods = append(orderGoods, &domain.OrderGood{ |
690 | OrderGoodId: 0, | 774 | OrderGoodId: 0, |
691 | - OrderGoodAmount: orderGood.OrderGoodAmount, | 775 | + OrderGoodAmount: orderGoodAmount, |
692 | OrderGoodName: orderGood.OrderGoodName, | 776 | OrderGoodName: orderGood.OrderGoodName, |
693 | OrderGoodPrice: orderGood.OrderGoodPrice, | 777 | OrderGoodPrice: orderGood.OrderGoodPrice, |
694 | OrderGoodQuantity: orderGood.OrderGoodQuantity, | 778 | OrderGoodQuantity: orderGood.OrderGoodQuantity, |
@@ -26,7 +26,7 @@ type CooperationApplication struct { | @@ -26,7 +26,7 @@ type CooperationApplication struct { | ||
26 | CooperationProject *CooperationProject `json:"cooperationProject"` | 26 | CooperationProject *CooperationProject `json:"cooperationProject"` |
27 | // 数据所属组织机构 | 27 | // 数据所属组织机构 |
28 | Org *Org `json:"org"` | 28 | Org *Org `json:"org"` |
29 | - // 是否被取消标志位 | 29 | + // 是否被取消标志位 1未取消,2取消 |
30 | IsCanceled int32 `json:"isCanceled"` | 30 | IsCanceled int32 `json:"isCanceled"` |
31 | // 公司 | 31 | // 公司 |
32 | Company *Company `json:"company"` | 32 | Company *Company `json:"company"` |
@@ -22,7 +22,7 @@ type CooperationProject struct { | @@ -22,7 +22,7 @@ type CooperationProject struct { | ||
22 | CooperationMode *CooperationMode `json:"cooperationMode"` | 22 | CooperationMode *CooperationMode `json:"cooperationMode"` |
23 | // 共创项目发起部门 | 23 | // 共创项目发起部门 |
24 | Department *Department `json:"department"` | 24 | Department *Department `json:"department"` |
25 | - // 共创项目承接对象,1员工,2共创用户,3公开,可以多选 | 25 | + // 共创项目承接对象,1员工,2共创用户,4公开,可以多选 |
26 | CooperationProjectUndertakerTypes []int32 `json:"cooperationProjectUndertakerTypes"` | 26 | CooperationProjectUndertakerTypes []int32 `json:"cooperationProjectUndertakerTypes"` |
27 | // 数据所属组织机构 | 27 | // 数据所属组织机构 |
28 | Org *Org `json:"org"` | 28 | Org *Org `json:"org"` |
@@ -17,7 +17,7 @@ type CooperationContractDao struct { | @@ -17,7 +17,7 @@ type CooperationContractDao struct { | ||
17 | } | 17 | } |
18 | 18 | ||
19 | // GenerateContractNumber 生成共创合约编号 | 19 | // GenerateContractNumber 生成共创合约编号 |
20 | -func (dao *CooperationContractDao) GenerateContractNumber() (string, error) { | 20 | +func (dao *CooperationContractDao) GenerateContractNumber(queryOptions map[string]interface{}) (string, error) { |
21 | tx := dao.transactionContext.PgTx | 21 | tx := dao.transactionContext.PgTx |
22 | var cooperationContractModels []*models.CooperationContract | 22 | var cooperationContractModels []*models.CooperationContract |
23 | query := tx.Model(&cooperationContractModels) | 23 | query := tx.Model(&cooperationContractModels) |
@@ -26,16 +26,30 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) { | @@ -26,16 +26,30 @@ func (dao *CooperationContractDao) GenerateContractNumber() (string, error) { | ||
26 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) | 26 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) |
27 | query.Where("cooperation_contract.created_at >= ?", todayZeroTime) | 27 | query.Where("cooperation_contract.created_at >= ?", todayZeroTime) |
28 | query.Where("cooperation_contract.created_at < ?", nextDayZeroTime) | 28 | query.Where("cooperation_contract.created_at < ?", nextDayZeroTime) |
29 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
30 | + query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId) | ||
31 | + } | ||
29 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { | 32 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { |
30 | return "", err | 33 | return "", err |
31 | } else { | 34 | } else { |
32 | - countStr := fmt.Sprintf("%03d", count+1) | ||
33 | - timestamp := currentTime.Unix() | ||
34 | - timeNow := time.Unix(timestamp, 0) | ||
35 | - timeString := timeNow.Format("20060102") | ||
36 | - timeString = timeString[2:len(timeString)] | ||
37 | - contractNumber := "HY" + timeString + "#" + countStr | ||
38 | - return contractNumber, nil | 35 | + if count < 1000 { |
36 | + countStr := fmt.Sprintf("%03d", count+1) | ||
37 | + timestamp := currentTime.Unix() | ||
38 | + timeNow := time.Unix(timestamp, 0) | ||
39 | + timeString := timeNow.Format("20060102") | ||
40 | + timeString = timeString[2:len(timeString)] | ||
41 | + contractNumber := "HY" + timeString + "#" + countStr | ||
42 | + return contractNumber, nil | ||
43 | + } else { | ||
44 | + countStr := fmt.Sprintf("%d", count+1) | ||
45 | + timestamp := currentTime.Unix() | ||
46 | + timeNow := time.Unix(timestamp, 0) | ||
47 | + timeString := timeNow.Format("20060102") | ||
48 | + timeString = timeString[2:len(timeString)] | ||
49 | + dividendsOrderNumber := "HY" + timeString + "#" + countStr | ||
50 | + return dividendsOrderNumber, nil | ||
51 | + } | ||
52 | + | ||
39 | } | 53 | } |
40 | } | 54 | } |
41 | 55 |
@@ -13,7 +13,7 @@ type CooperationProjectDao struct { | @@ -13,7 +13,7 @@ type CooperationProjectDao struct { | ||
13 | } | 13 | } |
14 | 14 | ||
15 | // GenerateProjectNumber 生成共创项目编码 | 15 | // GenerateProjectNumber 生成共创项目编码 |
16 | -func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) { | 16 | +func (dao *CooperationProjectDao) GenerateProjectNumber(queryOptions map[string]interface{}) (string, error) { |
17 | tx := dao.transactionContext.PgTx | 17 | tx := dao.transactionContext.PgTx |
18 | var cooperationProjectModels []*models.CooperationProject | 18 | var cooperationProjectModels []*models.CooperationProject |
19 | query := tx.Model(&cooperationProjectModels) | 19 | query := tx.Model(&cooperationProjectModels) |
@@ -22,16 +22,29 @@ func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) { | @@ -22,16 +22,29 @@ func (dao *CooperationProjectDao) GenerateProjectNumber() (string, error) { | ||
22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) | 22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) |
23 | query.Where("cooperation_project.created_at >= ?", todayZeroTime) | 23 | query.Where("cooperation_project.created_at >= ?", todayZeroTime) |
24 | query.Where("cooperation_project.created_at < ?", nextDayZeroTime) | 24 | query.Where("cooperation_project.created_at < ?", nextDayZeroTime) |
25 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
26 | + query = query.Where(`cooperation_contract.company @> '{"companyId":"?"}'`, companyId) | ||
27 | + } | ||
25 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { | 28 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { |
26 | return "", err | 29 | return "", err |
27 | } else { | 30 | } else { |
28 | - countStr := fmt.Sprintf("%03d", count+1) | ||
29 | - timestamp := currentTime.Unix() | ||
30 | - timeNow := time.Unix(timestamp, 0) | ||
31 | - timeString := timeNow.Format("20060102") | ||
32 | - timeString = timeString[2:len(timeString)] | ||
33 | - contractNumber := "XM" + timeString + "#" + countStr | ||
34 | - return contractNumber, nil | 31 | + if count < 1000 { |
32 | + countStr := fmt.Sprintf("%03d", count+1) | ||
33 | + timestamp := currentTime.Unix() | ||
34 | + timeNow := time.Unix(timestamp, 0) | ||
35 | + timeString := timeNow.Format("20060102") | ||
36 | + timeString = timeString[2:len(timeString)] | ||
37 | + contractNumber := "XM" + timeString + "#" + countStr | ||
38 | + return contractNumber, nil | ||
39 | + } else { | ||
40 | + countStr := fmt.Sprintf("%d", count+1) | ||
41 | + timestamp := currentTime.Unix() | ||
42 | + timeNow := time.Unix(timestamp, 0) | ||
43 | + timeString := timeNow.Format("20060102") | ||
44 | + timeString = timeString[2:len(timeString)] | ||
45 | + contractNumber := "XM" + timeString + "#" + countStr | ||
46 | + return contractNumber, nil | ||
47 | + } | ||
35 | } | 48 | } |
36 | } | 49 | } |
37 | 50 |
@@ -13,7 +13,7 @@ type CreditAccountDao struct { | @@ -13,7 +13,7 @@ type CreditAccountDao struct { | ||
13 | } | 13 | } |
14 | 14 | ||
15 | // GenerateCreditAccountNumber 生成账期结算单号 | 15 | // GenerateCreditAccountNumber 生成账期结算单号 |
16 | -func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) { | 16 | +func (dao *CreditAccountDao) GenerateCreditAccountNumber(queryOptions map[string]interface{}) (string, error) { |
17 | tx := dao.transactionContext.PgTx | 17 | tx := dao.transactionContext.PgTx |
18 | var creditAccountModels []*models.CreditAccount | 18 | var creditAccountModels []*models.CreditAccount |
19 | query := tx.Model(&creditAccountModels) | 19 | query := tx.Model(&creditAccountModels) |
@@ -22,16 +22,29 @@ func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) { | @@ -22,16 +22,29 @@ func (dao *CreditAccountDao) GenerateCreditAccountNumber() (string, error) { | ||
22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) | 22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) |
23 | query.Where("credit_account.created_at >= ?", todayZeroTime) | 23 | query.Where("credit_account.created_at >= ?", todayZeroTime) |
24 | query.Where("credit_account.created_at < ?", nextDayZeroTime) | 24 | query.Where("credit_account.created_at < ?", nextDayZeroTime) |
25 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
26 | + query = query.Where(`credit_account.company @> '{"companyId":"?"}'`, companyId) | ||
27 | + } | ||
25 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { | 28 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { |
26 | return "", err | 29 | return "", err |
27 | } else { | 30 | } else { |
28 | - countStr := fmt.Sprintf("%03d", count+1) | ||
29 | - timestamp := currentTime.Unix() | ||
30 | - timeNow := time.Unix(timestamp, 0) | ||
31 | - timeString := timeNow.Format("20060102") | ||
32 | - timeString = timeString[2:len(timeString)] | ||
33 | - creditAccountNumber := "JS" + timeString + "#" + countStr | ||
34 | - return creditAccountNumber, nil | 31 | + if count < 1000 { |
32 | + countStr := fmt.Sprintf("%03d", count+1) | ||
33 | + timestamp := currentTime.Unix() | ||
34 | + timeNow := time.Unix(timestamp, 0) | ||
35 | + timeString := timeNow.Format("20060102") | ||
36 | + timeString = timeString[2:len(timeString)] | ||
37 | + creditAccountNumber := "JS" + timeString + "#" + countStr | ||
38 | + return creditAccountNumber, nil | ||
39 | + } else { | ||
40 | + countStr := fmt.Sprintf("%d", count+1) | ||
41 | + timestamp := currentTime.Unix() | ||
42 | + timeNow := time.Unix(timestamp, 0) | ||
43 | + timeString := timeNow.Format("20060102") | ||
44 | + timeString = timeString[2:len(timeString)] | ||
45 | + creditAccountNumber := "JS" + timeString + "#" + countStr | ||
46 | + return creditAccountNumber, nil | ||
47 | + } | ||
35 | } | 48 | } |
36 | } | 49 | } |
37 | 50 |
@@ -13,7 +13,7 @@ type DividendsEstimateDao struct { | @@ -13,7 +13,7 @@ type DividendsEstimateDao struct { | ||
13 | } | 13 | } |
14 | 14 | ||
15 | // GenerateDividendsEstimateNumber 生成分红预算单号 | 15 | // GenerateDividendsEstimateNumber 生成分红预算单号 |
16 | -func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, error) { | 16 | +func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber(queryOptions map[string]interface{}) (string, error) { |
17 | tx := dao.transactionContext.PgTx | 17 | tx := dao.transactionContext.PgTx |
18 | var dividendsEstimateModels []*models.DividendsEstimate | 18 | var dividendsEstimateModels []*models.DividendsEstimate |
19 | query := tx.Model(÷ndsEstimateModels) | 19 | query := tx.Model(÷ndsEstimateModels) |
@@ -22,16 +22,30 @@ func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, erro | @@ -22,16 +22,30 @@ func (dao *DividendsEstimateDao) GenerateDividendsEstimateNumber() (string, erro | ||
22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) | 22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) |
23 | query.Where("dividends_estimate.created_at >= ?", todayZeroTime) | 23 | query.Where("dividends_estimate.created_at >= ?", todayZeroTime) |
24 | query.Where("dividends_estimate.created_at < ?", nextDayZeroTime) | 24 | query.Where("dividends_estimate.created_at < ?", nextDayZeroTime) |
25 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
26 | + query = query.Where(`dividends_estimate.company @> '{"companyId":"?"}'`, companyId) | ||
27 | + } | ||
25 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { | 28 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { |
26 | return "", err | 29 | return "", err |
27 | } else { | 30 | } else { |
28 | - countStr := fmt.Sprintf("%03d", count+1) | ||
29 | - timestamp := currentTime.Unix() | ||
30 | - timeNow := time.Unix(timestamp, 0) | ||
31 | - timeString := timeNow.Format("20060102") | ||
32 | - timeString = timeString[2:len(timeString)] | ||
33 | - dividendsOrderNumber := "FH" + timeString + "#" + countStr | ||
34 | - return dividendsOrderNumber, nil | 31 | + if count < 1000 { |
32 | + countStr := fmt.Sprintf("%03d", count+1) | ||
33 | + timestamp := currentTime.Unix() | ||
34 | + timeNow := time.Unix(timestamp, 0) | ||
35 | + timeString := timeNow.Format("20060102") | ||
36 | + timeString = timeString[2:len(timeString)] | ||
37 | + dividendsOrderNumber := "FH" + timeString + "#" + countStr | ||
38 | + return dividendsOrderNumber, nil | ||
39 | + } else { | ||
40 | + countStr := fmt.Sprintf("%d", count+1) | ||
41 | + timestamp := currentTime.Unix() | ||
42 | + timeNow := time.Unix(timestamp, 0) | ||
43 | + timeString := timeNow.Format("20060102") | ||
44 | + timeString = timeString[2:len(timeString)] | ||
45 | + dividendsOrderNumber := "FH" + timeString + "#" + countStr | ||
46 | + return dividendsOrderNumber, nil | ||
47 | + } | ||
48 | + | ||
35 | } | 49 | } |
36 | } | 50 | } |
37 | 51 |
@@ -13,7 +13,7 @@ type DividendsOrderDao struct { | @@ -13,7 +13,7 @@ type DividendsOrderDao struct { | ||
13 | } | 13 | } |
14 | 14 | ||
15 | // GenerateDividendsOrderNumber 生成分红订单号 | 15 | // GenerateDividendsOrderNumber 生成分红订单号 |
16 | -func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) { | 16 | +func (dao *DividendsOrderDao) GenerateDividendsOrderNumber(queryOptions map[string]interface{}) (string, error) { |
17 | tx := dao.transactionContext.PgTx | 17 | tx := dao.transactionContext.PgTx |
18 | var dividendsOrderModels []*models.DividendsOrder | 18 | var dividendsOrderModels []*models.DividendsOrder |
19 | query := tx.Model(÷ndsOrderModels) | 19 | query := tx.Model(÷ndsOrderModels) |
@@ -22,6 +22,9 @@ func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) { | @@ -22,6 +22,9 @@ func (dao *DividendsOrderDao) GenerateDividendsOrderNumber() (string, error) { | ||
22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) | 22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) |
23 | query.Where("dividends_order.created_at >= ?", todayZeroTime) | 23 | query.Where("dividends_order.created_at >= ?", todayZeroTime) |
24 | query.Where("dividends_order.created_at < ?", nextDayZeroTime) | 24 | query.Where("dividends_order.created_at < ?", nextDayZeroTime) |
25 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
26 | + query = query.Where(`dividends_order.company @> '{"companyId":"?"}'`, companyId) | ||
27 | + } | ||
25 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { | 28 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { |
26 | return "", err | 29 | return "", err |
27 | } else { | 30 | } else { |
@@ -13,7 +13,7 @@ type DividendsReturnedOrderDao struct { | @@ -13,7 +13,7 @@ type DividendsReturnedOrderDao struct { | ||
13 | } | 13 | } |
14 | 14 | ||
15 | // GenerateDividendsReturnedOrderNumber 生成分红退货单号 | 15 | // GenerateDividendsReturnedOrderNumber 生成分红退货单号 |
16 | -func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (string, error) { | 16 | +func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber(queryOptions map[string]interface{}) (string, error) { |
17 | tx := dao.transactionContext.PgTx | 17 | tx := dao.transactionContext.PgTx |
18 | var dividendsReturnedOrderModels []*models.DividendsReturnedOrder | 18 | var dividendsReturnedOrderModels []*models.DividendsReturnedOrder |
19 | query := tx.Model(÷ndsReturnedOrderModels) | 19 | query := tx.Model(÷ndsReturnedOrderModels) |
@@ -22,6 +22,9 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (st | @@ -22,6 +22,9 @@ func (dao *DividendsReturnedOrderDao) GenerateDividendsReturnedOrderNumber() (st | ||
22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) | 22 | nextDayZeroTime := utils.GetNextDayZeroTime(currentTime) |
23 | query.Where("dividends_returned_order.created_at >= ?", todayZeroTime) | 23 | query.Where("dividends_returned_order.created_at >= ?", todayZeroTime) |
24 | query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime) | 24 | query.Where("dividends_returned_order.created_at < ?", nextDayZeroTime) |
25 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
26 | + query = query.Where(`dividends_returned_order.company @> '{"companyId":"?"}'`, companyId) | ||
27 | + } | ||
25 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { | 28 | if count, err := query.AllWithDeleted().SelectAndCount(); err != nil { |
26 | return "", err | 29 | return "", err |
27 | } else { | 30 | } else { |
@@ -50,6 +50,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | @@ -50,6 +50,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | ||
50 | for _, dividendsEstimate := range dividendsEstimates { | 50 | for _, dividendsEstimate := range dividendsEstimates { |
51 | // 根据当前分红预算单的分红订单号或退货单号获取分红预算单 | 51 | // 根据当前分红预算单的分红订单号或退货单号获取分红预算单 |
52 | if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{ | 52 | if countRelative, dividendsEstimatesRelative, err2 := dividendsEstimateRepository.Find(map[string]interface{}{ |
53 | + "companyId": dividendsEstimate.Company.CompanyId, | ||
54 | + "orgId": dividendsEstimate.Org.OrgId, | ||
53 | "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum, | 55 | "orderOrReturnedOrderNum": dividendsEstimate.OrderOrReturnedOrderNum, |
54 | }); err2 != nil { | 56 | }); err2 != nil { |
55 | return nil, err2 | 57 | return nil, err2 |
@@ -86,6 +88,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | @@ -86,6 +88,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | ||
86 | 88 | ||
87 | // 获取分红订单 | 89 | // 获取分红订单 |
88 | if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{ | 90 | if countDividendsOrder, orders, err4 := dividendsOrderRepository.Find(map[string]interface{}{ |
91 | + "companyId": dividendsEstimates[0].Company.CompanyId, | ||
92 | + "orgId": dividendsEstimates[0].Org.OrgId, | ||
89 | "dividendsOrderNumbers": orderNums, | 93 | "dividendsOrderNumbers": orderNums, |
90 | }); err4 != nil { | 94 | }); err4 != nil { |
91 | return nil, err4 | 95 | return nil, err4 |
@@ -103,6 +107,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | @@ -103,6 +107,8 @@ func (domainService *CancelDividendsEstimateService) CancelEstimate(dividendsEst | ||
103 | 107 | ||
104 | // 获取分红退货单 | 108 | // 获取分红退货单 |
105 | if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{ | 109 | if countDividendsReturnedOrder, returnedOrders, err5 := dividendsReturnedOrderRepository.Find(map[string]interface{}{ |
110 | + "companyId": dividendsEstimates[0].Company.CompanyId, | ||
111 | + "orgId": dividendsEstimates[0].Org.OrgId, | ||
106 | "dividendsReturnedOrderNumbers": returnedOrderNums, | 112 | "dividendsReturnedOrderNumbers": returnedOrderNums, |
107 | }); err5 != nil { | 113 | }); err5 != nil { |
108 | return nil, err5 | 114 | return nil, err5 |
@@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
5 | "github.com/linmadan/egglib-go/core/application" | 5 | "github.com/linmadan/egglib-go/core/application" |
6 | coreDomain "github.com/linmadan/egglib-go/core/domain" | 6 | coreDomain "github.com/linmadan/egglib-go/core/domain" |
7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 7 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
8 | + "github.com/shopspring/decimal" | ||
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | 9 | "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/domain/service" |
10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" | 11 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository" |
@@ -18,37 +19,62 @@ type ConfirmDividendsIncentivesEstimateService struct { | @@ -18,37 +19,62 @@ type ConfirmDividendsIncentivesEstimateService struct { | ||
18 | // Confirm 确认业绩分红预算 | 19 | // Confirm 确认业绩分红预算 |
19 | func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) ([]*service.DividendsEstimateDetail, error) { | 20 | func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoods []*domain.OrderGood) ([]*service.DividendsEstimateDetail, error) { |
20 | var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储 | 21 | var cooperationContractRepository domain.CooperationContractRepository // 共创合约仓储 |
22 | + var cooperationProjectRepository domain.CooperationProjectRepository // 共创项目仓储 | ||
21 | var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 | 23 | var dividendsOrderRepository domain.DividendsOrderRepository // 分红订单仓储 |
22 | var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 | 24 | var dividendsReturnedOrderRepository domain.DividendsReturnedOrderRepository // 分红退货单仓储 |
25 | + | ||
23 | // 共创合约仓储初始化 | 26 | // 共创合约仓储初始化 |
24 | if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil { | 27 | if repo, err := repository.NewCooperationContractRepository(domainService.transactionContext); err != nil { |
25 | return nil, err | 28 | return nil, err |
26 | } else { | 29 | } else { |
27 | cooperationContractRepository = repo | 30 | cooperationContractRepository = repo |
28 | } | 31 | } |
32 | + | ||
33 | + // 共创项目仓储初始化 | ||
34 | + if repo, err := repository.NewCooperationProjectRepository(domainService.transactionContext); err != nil { | ||
35 | + return nil, err | ||
36 | + } else { | ||
37 | + cooperationProjectRepository = repo | ||
38 | + } | ||
39 | + | ||
29 | // 分红订单仓储初始化 | 40 | // 分红订单仓储初始化 |
30 | if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil { | 41 | if repo, err := repository.NewDividendsOrderRepository(domainService.transactionContext); err != nil { |
31 | return nil, err | 42 | return nil, err |
32 | } else { | 43 | } else { |
33 | dividendsOrderRepository = repo | 44 | dividendsOrderRepository = repo |
34 | } | 45 | } |
46 | + | ||
35 | // 分红退货单仓储初始化 | 47 | // 分红退货单仓储初始化 |
36 | if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil { | 48 | if repo, err := repository.NewDividendsReturnedOrderRepository(domainService.transactionContext); err != nil { |
37 | return nil, err | 49 | return nil, err |
38 | } else { | 50 | } else { |
39 | dividendsReturnedOrderRepository = repo | 51 | dividendsReturnedOrderRepository = repo |
40 | } | 52 | } |
53 | + | ||
41 | // 确认业绩分红预算 | 54 | // 确认业绩分红预算 |
42 | var dividendsEstimateDetails []*service.DividendsEstimateDetail | 55 | var dividendsEstimateDetails []*service.DividendsEstimateDetail |
43 | for _, orderGood := range orderGoods { | 56 | for _, orderGood := range orderGoods { |
44 | // 获取合约 | 57 | // 获取合约 |
45 | - cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{"cooperationContractNumber": orderGood.CooperationContractNumber}) | 58 | + cooperationContract, err := cooperationContractRepository.FindOne(map[string]interface{}{ |
59 | + "cooperationContractNumber": orderGood.CooperationContractNumber, | ||
60 | + }) | ||
46 | if err != nil { | 61 | if err != nil { |
47 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 62 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
48 | } | 63 | } |
49 | if cooperationContract == nil { | 64 | if cooperationContract == nil { |
50 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber)) | 65 | return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创合约%s不存在", orderGood.CooperationContractNumber)) |
51 | } | 66 | } |
67 | + // TODO 校验合约关联的项目是否已结束 | ||
68 | + cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{ | ||
69 | + "cooperationProjectNumber": cooperationContract.CooperationProjectNumber, | ||
70 | + }) | ||
71 | + if err != nil { | ||
72 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
73 | + } | ||
74 | + if cooperationProject == nil { | ||
75 | + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("共创项目%s不存在", cooperationContract.CooperationProjectNumber)) | ||
76 | + } | ||
77 | + | ||
52 | if orderGood.DividendsOrderNumber != "" { | 78 | if orderGood.DividendsOrderNumber != "" { |
53 | // 获取分红订单 | 79 | // 获取分红订单 |
54 | dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{ | 80 | dividendsOrder, err2 := dividendsOrderRepository.FindOne(map[string]interface{}{ |
@@ -78,8 +104,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -78,8 +104,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
78 | if dividendsIncentivesRuleMatched != nil { | 104 | if dividendsIncentivesRuleMatched != nil { |
79 | for _, undertaker := range cooperationContract.Undertakers { | 105 | for _, undertaker := range cooperationContract.Undertakers { |
80 | // 添加承接人分红预算信息详情 | 106 | // 添加承接人分红预算信息详情 |
81 | - // TODO 使用decimal提高精度 | ||
82 | - undertakerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100 | 107 | + undertakerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.DividendsIncentivesPercentage).Div(decimal.NewFromFloat(100))).Float64() |
83 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 108 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
84 | DividendsUser: &domain.User{ | 109 | DividendsUser: &domain.User{ |
85 | UserId: undertaker.UserId, | 110 | UserId: undertaker.UserId, |
@@ -101,7 +126,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -101,7 +126,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
101 | }) | 126 | }) |
102 | // 添加推荐人分红预算信息详情 | 127 | // 添加推荐人分红预算信息详情 |
103 | if undertaker.Referrer != nil { | 128 | if undertaker.Referrer != nil { |
104 | - referrerDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100 | 129 | + referrerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64() |
105 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 130 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
106 | DividendsUser: &domain.User{ | 131 | DividendsUser: &domain.User{ |
107 | UserId: undertaker.Referrer.UserId, | 132 | UserId: undertaker.Referrer.UserId, |
@@ -123,7 +148,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -123,7 +148,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
123 | } | 148 | } |
124 | // 添加关联业务员分红预算信息详情 | 149 | // 添加关联业务员分红预算信息详情 |
125 | if undertaker.Salesman != nil { | 150 | if undertaker.Salesman != nil { |
126 | - salesmanDividendsAmount := orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100 | 151 | + salesmanDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64() |
127 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 152 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
128 | DividendsUser: &domain.User{ | 153 | DividendsUser: &domain.User{ |
129 | UserId: undertaker.Salesman.UserId, | 154 | UserId: undertaker.Salesman.UserId, |
@@ -166,7 +191,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -166,7 +191,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
166 | // 计算分红 | 191 | // 计算分红 |
167 | for _, undertaker := range cooperationContract.Undertakers { | 192 | for _, undertaker := range cooperationContract.Undertakers { |
168 | // 添加承接人分红退货预算信息详情 | 193 | // 添加承接人分红退货预算信息详情 |
169 | - undertakerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.DividendsIncentivesPercentage / 100 | 194 | + undertakerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.DividendsIncentivesPercentage).Div(decimal.NewFromFloat(100))).Float64() |
170 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 195 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
171 | DividendsUser: &domain.User{ | 196 | DividendsUser: &domain.User{ |
172 | UserId: undertaker.UserId, | 197 | UserId: undertaker.UserId, |
@@ -184,11 +209,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -184,11 +209,11 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
184 | }, | 209 | }, |
185 | DividendsParticipateType: domain.UNDERTAKER, | 210 | DividendsParticipateType: domain.UNDERTAKER, |
186 | DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, | 211 | DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, |
187 | - DividendsAmount: undertakerDividendsAmount, | 212 | + DividendsAmount: -undertakerDividendsAmount, |
188 | }) | 213 | }) |
189 | // 添加推荐人分红退货预算信息详情 | 214 | // 添加推荐人分红退货预算信息详情 |
190 | if undertaker.Referrer != nil { | 215 | if undertaker.Referrer != nil { |
191 | - referrerDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.ReferrerPercentage / 100 | 216 | + referrerDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64() |
192 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 217 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
193 | DividendsUser: &domain.User{ | 218 | DividendsUser: &domain.User{ |
194 | UserId: undertaker.Referrer.UserId, | 219 | UserId: undertaker.Referrer.UserId, |
@@ -205,12 +230,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -205,12 +230,12 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
205 | }, | 230 | }, |
206 | DividendsParticipateType: domain.REFERRER, | 231 | DividendsParticipateType: domain.REFERRER, |
207 | DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, | 232 | DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, |
208 | - DividendsAmount: referrerDividendsAmount, | 233 | + DividendsAmount: -referrerDividendsAmount, |
209 | }) | 234 | }) |
210 | } | 235 | } |
211 | // 添加关联业务员分红退货预算信息详情 | 236 | // 添加关联业务员分红退货预算信息详情 |
212 | if undertaker.Salesman != nil { | 237 | if undertaker.Salesman != nil { |
213 | - salesmanDividendsAmount := -orderGood.OrderGoodAmount * dividendsIncentivesRuleMatched.SalesmanPercentage / 100 | 238 | + salesmanDividendsAmount, _ := decimal.NewFromFloat(orderGood.OrderGoodAmount).Mul(decimal.NewFromFloat(dividendsIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64() |
214 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 239 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
215 | DividendsUser: &domain.User{ | 240 | DividendsUser: &domain.User{ |
216 | UserId: undertaker.Salesman.UserId, | 241 | UserId: undertaker.Salesman.UserId, |
@@ -227,7 +252,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | @@ -227,7 +252,7 @@ func (domainService *ConfirmDividendsIncentivesEstimateService) Confirm(orderGoo | ||
227 | }, | 252 | }, |
228 | DividendsParticipateType: domain.SALESMAN, | 253 | DividendsParticipateType: domain.SALESMAN, |
229 | DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, | 254 | DividendsStage: dividendsIncentivesRuleMatched.DividendsIncentivesStage, |
230 | - DividendsAmount: salesmanDividendsAmount, | 255 | + DividendsAmount: -salesmanDividendsAmount, |
231 | }) | 256 | }) |
232 | } | 257 | } |
233 | } | 258 | } |
@@ -4,6 +4,7 @@ import ( | @@ -4,6 +4,7 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | coreDomain "github.com/linmadan/egglib-go/core/domain" | 5 | coreDomain "github.com/linmadan/egglib-go/core/domain" |
6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" | 6 | pgTransaction "github.com/linmadan/egglib-go/transaction/pg" |
7 | + "github.com/shopspring/decimal" | ||
7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" | 8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain" |
8 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" | 9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service" |
9 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" | 10 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao" |
@@ -68,7 +69,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do | @@ -68,7 +69,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do | ||
68 | if undertakerEstimated { | 69 | if undertakerEstimated { |
69 | return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红") | 70 | return nil, fmt.Errorf("用户 " + undertaker.UserName + " 已分红") |
70 | } else { | 71 | } else { |
71 | - undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (1 - (moneyIncentivesRuleMatched.SalesmanPercentage+moneyIncentivesRuleMatched.ReferrerPercentage)/100) | 72 | + undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(1).Sub(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Add(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage))).Div(decimal.NewFromFloat(100))).Float64() |
72 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 73 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
73 | DividendsUser: &domain.User{ | 74 | DividendsUser: &domain.User{ |
74 | UserId: undertaker.UserId, | 75 | UserId: undertaker.UserId, |
@@ -103,7 +104,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do | @@ -103,7 +104,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do | ||
103 | if salesmanEstimated { | 104 | if salesmanEstimated { |
104 | return nil, fmt.Errorf("业务员 " + undertaker.Salesman.UserName + " 已分红") | 105 | return nil, fmt.Errorf("业务员 " + undertaker.Salesman.UserName + " 已分红") |
105 | } else { | 106 | } else { |
106 | - undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.SalesmanPercentage / 100) | 107 | + undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.SalesmanPercentage).Div(decimal.NewFromFloat(100))).Float64() |
107 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 108 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
108 | DividendsUser: &domain.User{ | 109 | DividendsUser: &domain.User{ |
109 | UserId: undertaker.Salesman.UserId, | 110 | UserId: undertaker.Salesman.UserId, |
@@ -139,8 +140,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do | @@ -139,8 +140,7 @@ func (domainService *ConfirmMoneyIncentivesEstimateService) Confirm(contract *do | ||
139 | if referrerEstimated { | 140 | if referrerEstimated { |
140 | return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红") | 141 | return nil, fmt.Errorf("推荐人 " + undertaker.Salesman.UserName + " 已分红") |
141 | } else { | 142 | } else { |
142 | - // TODO 使用decimal提高精度 | ||
143 | - undertakerDividendsAmount := moneyIncentivesRuleMatched.MoneyIncentivesAmount * (moneyIncentivesRuleMatched.ReferrerPercentage / 100) | 143 | + undertakerDividendsAmount, _ := decimal.NewFromFloat(moneyIncentivesRuleMatched.MoneyIncentivesAmount).Mul(decimal.NewFromFloat(moneyIncentivesRuleMatched.ReferrerPercentage).Div(decimal.NewFromFloat(100))).Float64() |
144 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ | 144 | dividendsEstimateDetails = append(dividendsEstimateDetails, &service.DividendsEstimateDetail{ |
145 | DividendsUser: &domain.User{ | 145 | DividendsUser: &domain.User{ |
146 | UserId: undertaker.Referrer.UserId, | 146 | UserId: undertaker.Referrer.UserId, |
@@ -248,6 +248,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string | @@ -248,6 +248,9 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string | ||
248 | if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { | 248 | if userBaseId, ok := queryOptions["userBaseId"]; ok && userBaseId.(int64) != 0 { |
249 | query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId) | 249 | query.Where(`(cooperation_application.cooperation_application_applicant->>'userBaseId' ='?')`, userBaseId) |
250 | } | 250 | } |
251 | + if isCanceled, ok := queryOptions["isCanceled"]; ok && isCanceled.(int32) != 3 { | ||
252 | + query.Where("is_canceled = ?", isCanceled) | ||
253 | + } | ||
251 | if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | 254 | if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { |
252 | query.Where("company->>'companyId' = '?'", companyId) | 255 | query.Where("company->>'companyId' = '?'", companyId) |
253 | } | 256 | } |
@@ -265,7 +268,7 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string | @@ -265,7 +268,7 @@ func (repository *CooperationApplicationRepository) Find(queryOptions map[string | ||
265 | if offsetLimitFlag { | 268 | if offsetLimitFlag { |
266 | query.SetOffsetAndLimit(20) | 269 | query.SetOffsetAndLimit(20) |
267 | } | 270 | } |
268 | - query.Where("is_canceled = ?", 1) | 271 | + |
269 | query.SetOrderDirect("cooperation_application_id", "DESC") | 272 | query.SetOrderDirect("cooperation_application_id", "DESC") |
270 | if count, err := query.SelectAndCount(); err != nil { | 273 | if count, err := query.SelectAndCount(); err != nil { |
271 | return 0, cooperationApplications, err | 274 | return 0, cooperationApplications, err |
@@ -1159,6 +1159,9 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in | @@ -1159,6 +1159,9 @@ func (repository *CooperationContractRepository) Find(queryOptions map[string]in | ||
1159 | if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 { | 1159 | if cooperationContractNumbers, ok := queryOptions["cooperationContractNumbers"]; ok && len(cooperationContractNumbers.([]string)) != 0 { |
1160 | query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers)) | 1160 | query.Where("cooperation_contract_number in (?)", pg.In(cooperationContractNumbers)) |
1161 | } | 1161 | } |
1162 | + if incentivesType, ok := queryOptions["incentivesType"]; ok && incentivesType.(int32) != 0 { | ||
1163 | + query.Where("incentives_type = ?", incentivesType) | ||
1164 | + } | ||
1162 | if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | 1165 | if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { |
1163 | query.Where("company->>'companyId' = '?'", companyId) | 1166 | query.Where("company->>'companyId' = '?'", companyId) |
1164 | } | 1167 | } |
@@ -211,6 +211,12 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string] | @@ -211,6 +211,12 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string] | ||
211 | if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" { | 211 | if cooperationProjectNumber, ok := queryOptions["cooperationProjectNumber"]; ok && cooperationProjectNumber != "" { |
212 | query.Where("cooperation_project.cooperation_project_number = ?", cooperationProjectNumber) | 212 | query.Where("cooperation_project.cooperation_project_number = ?", cooperationProjectNumber) |
213 | } | 213 | } |
214 | + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { | ||
215 | + query.Where("company->>'companyId' = '?'", companyId) | ||
216 | + } | ||
217 | + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 { | ||
218 | + query.Where("org->>'orgId' = '?'", orgId) | ||
219 | + } | ||
214 | if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 { | 220 | if cooperationProjectId, ok := queryOptions["cooperationProjectId"]; ok && cooperationProjectId.(int64) != 0 { |
215 | query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId) | 221 | query.Where("cooperation_project.cooperation_project_id = ?", cooperationProjectId) |
216 | } | 222 | } |
@@ -112,7 +112,7 @@ func (controller *CooperationContractController) SearchCooperationContract() { | @@ -112,7 +112,7 @@ func (controller *CooperationContractController) SearchCooperationContract() { | ||
112 | _ = controller.Unmarshal(searchCooperationContractQuery) | 112 | _ = controller.Unmarshal(searchCooperationContractQuery) |
113 | header := controller.GetRequestHeader(controller.Ctx) | 113 | header := controller.GetRequestHeader(controller.Ctx) |
114 | searchCooperationContractQuery.CompanyId = header.CompanyId | 114 | searchCooperationContractQuery.CompanyId = header.CompanyId |
115 | - searchCooperationContractQuery.OrgId = header.OrgId | 115 | + //searchCooperationContractQuery.OrgId = header.OrgId |
116 | searchCooperationContractQuery.UserId = header.UserId | 116 | searchCooperationContractQuery.UserId = header.UserId |
117 | searchCooperationContractQuery.UserBaseId = header.UserBaseId | 117 | searchCooperationContractQuery.UserBaseId = header.UserBaseId |
118 | data, err := cooperationContractService.SearchCooperationContract(searchCooperationContractQuery) | 118 | data, err := cooperationContractService.SearchCooperationContract(searchCooperationContractQuery) |
-
请 注册 或 登录 后发表评论