dividends_estimate.go
11.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsEstimate/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsEstimate/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/web/dividendsEstimate/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)
// 分红预算管理
type DividendsEstimateService struct {
}
//piliao 取消分红预算
func (dividendsEstimateService *DividendsEstimateService) CancelDividendsEstimate(cancelDividendsEstimateCommand *command.CancelDividendsEstimateCommand) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(cancelDividendsEstimateCommand.Operator)
_, err := creationCooperationGateway.DividendsEstimatesBatchCancel(allied_creation_cooperation.ReqDividendsEstimateBatchCancel{
DividendsEstimateIds: cancelDividendsEstimateCommand.DividendsEstimateId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cancelDividendsEstimateCommand, nil
}
// 确定预算业绩分红激励
func (dividendsEstimateService *DividendsEstimateService) EstimateDividendsIncentives(estimateDividendsIncentivesCommand *command.EstimateDividendsIncentivesCommand) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
estimateDividendsIncentivesCommand.Operator)
result, err := creationCooperationGateway.DividendsEstimateDividendsIncentives(allied_creation_cooperation.ReqDividendsEstimateDividendsIncentives{
OrderGoodIds: estimateDividendsIncentivesCommand.OrderGoodIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
respData := map[string]string{
"result": result.Report,
}
return respData, nil
}
// 确定预算金额激励分红
func (dividendsEstimateService *DividendsEstimateService) EstimateMoneyIncentives(estimateMoneyIncentivesCommand *command.EstimateMoneyIncentivesCommand) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
estimateMoneyIncentivesCommand.Operator)
result, err := creationCooperationGateway.DividendsEstimatesEstimateMoneys(allied_creation_cooperation.ReqDividendsEstimateMoneyIncentives{
CooperationContractId: estimateMoneyIncentivesCommand.CooperationContractId,
DividendsIncentivesStage: estimateMoneyIncentivesCommand.DividendsIncentivesStage,
UndertakerUids: estimateMoneyIncentivesCommand.UndertakerUids,
Action: estimateMoneyIncentivesCommand.CmdType,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
data := []map[string]interface{}{}
for i := range result {
item := map[string]interface{}{
"userId": result[i].DividendsUser.UserId,
"userName": result[i].DividendsUser.UserInfo.UserName,
"dividendsAmount": result[i].DividendsAmount,
}
data = append(data, item)
}
returnData := map[string]interface{}{
"list": data,
}
return returnData, nil
}
// 查询分红预算单列表
func (dividendsEstimateService *DividendsEstimateService) SearchDividendsEstimate(searchDividendsEstimateQuery *query.SearchDividendsEstimateQuery) (
int, interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
searchDividendsEstimateQuery.Operator)
result, err := creationCooperationGateway.DividendsEstimatesSearch(allied_creation_cooperation.ReqDividendsEstimateSearch{
DividendsEstimateOrderNumber: searchDividendsEstimateQuery.DividendsEstimateOrderNumber, //承接人分红预算单号
DividendsType: searchDividendsEstimateQuery.DividendsType, //分红类型,1订单分红,2退货冲销,3金额激励
PageNumber: searchDividendsEstimateQuery.PageNumber,
PageSize: searchDividendsEstimateQuery.PageSize,
CompanyId: searchDividendsEstimateQuery.Operator.CompanyId,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
items := []dto.DividendsEstimateItem{}
for _, v := range result.Grid.List {
item := dto.DividendsEstimateItem{
DividendsEstimateId: v.DividendsEstimateId,
DividendsAccountStatus: v.DividendsAccountStatus,
DividendsAmount: v.DividendsAmount,
DividendsEstimateOrderNumber: v.DividendsEstimateOrderNumber,
DividendsEstimateTime: v.DividendsEstimateTime.UnixNano() / 1e6,
DividendsParticipateType: v.DividendsParticipateType,
DividendsType: v.DividendsType,
OrderOrReturnedOrderNum: v.OrderOrReturnedOrderNum,
CooperationProjectNumber: v.CooperationProjectNumber,
CooperationContractNumber: v.CooperationContractNumber,
DividendsIncentivesStage: v.DividendsStage,
IsCanceled: v.IsCanceled,
AuthFlag: v.Org.OrgId == int(searchDividendsEstimateQuery.Operator.OrgId),
}
item.DividendsUser.Phone = v.DividendsUser.UserInfo.UserPhone
item.DividendsUser.UsersName = v.DividendsUser.UserInfo.UserName
item.DividendsUser.UsersId = v.DividendsUser.UserId
item.DividendsUser.UserBaseId = v.DividendsUser.UserBaseId
item.DividendsUser.UserType = v.DividendsUser.UserType
item.Org.OrgId = v.Org.OrgId
item.Org.OrgName = v.Org.OrgName
items = append(items, item)
}
return result.Grid.Total, items, nil
}
// 查询业绩分红
func (dividendsEstimateService *DividendsEstimateService) SearchDividendsIncentives(searchDividendsIncentivesQuery *query.SearchDividendsIncentivesQuery) (
int, interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
searchDividendsIncentivesQuery.Operator)
result, err := creationCooperationGateway.DividendsEstimateSearchDividends(
allied_creation_cooperation.ReqDividendsEstimateSearchDividend{
PageNumber: searchDividendsIncentivesQuery.PageNumber,
PageSize: searchDividendsIncentivesQuery.PageSize,
CooperationContractNumber: searchDividendsIncentivesQuery.CooperationContractNumber,
OrderOrReturnedOrderNum: searchDividendsIncentivesQuery.OrderOrReturnedOrderNum,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
listdata := []dto.DividendsEstimateDividendItem{}
for _, v := range result.List {
item := dto.DividendsEstimateDividendItem{
OrderGoodId: v.OrderGoodId,
OrderGoodName: v.OrderGoodName,
CooperationContractNumber: v.CooperationContractNumber,
CustomerName: v.CustomerName,
DividendsIncentivesAmount: v.OrderAmount,
OrderOrReturnedOrderNum: v.OrderNumber,
OriginalOrderNum: v.OriginalOrderNum,
RegionName: v.RegionName,
}
item.OrderTime = v.OrderDate.UnixNano() / 1e6
listdata = append(listdata, item)
}
return result.Total, listdata, nil
}
// 查询金额激励分红
func (dividendsEmmateService *DividendsEstimateService) SearchMoneyIncentives(searchMoneyIncentivesQuery *query.SearchMoneyIncentivesQuery) (
int, interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
searchMoneyIncentivesQuery.Operator)
result, err := creationCooperationGateway.DividendsEstimatesSearchMoney(allied_creation_cooperation.ReqDividendsEstimateSearchMoney{
PageNumber: searchMoneyIncentivesQuery.PageNumber,
PageSize: searchMoneyIncentivesQuery.PageSize,
CooperationContractName: searchMoneyIncentivesQuery.CooperationContractName,
DepartmentName: searchMoneyIncentivesQuery.DepartmentName,
})
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
dataList := dto.ToDividendsEstimateMoneyItem(result)
return result.Grid.Total, dataList, nil
}
func NewDividendsEstimateService(options map[string]interface{}) *DividendsEstimateService {
newDividendsEstimateService := &DividendsEstimateService{}
return newDividendsEstimateService
}
func (dividendsEmmateService *DividendsEstimateService) MoneyIncentivesSelector(queryParam *query.MoneyIncentiveSelectorQuery) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
queryParam.Operator)
resultContract, err := creationCooperationGateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
CooperationContractNumber: queryParam.CooperationContractNumber,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if len(resultContract.Grid.List) == 0 {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "未找到对应的合约数据")
}
contractData := resultContract.Grid.List[0]
resultDividendsEstimate, err := creationCooperationGateway.DividendsEstimatesSearch(allied_creation_cooperation.ReqDividendsEstimateSearch{
CooperationContractNumber: queryParam.CooperationContractNumber,
DividendsType: 3,
CompanyId: queryParam.Operator.CompanyId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
rules := []dto.MoneyIncentivesRule{}
for _, v := range contractData.MoneyIncentivesRules {
r := dto.MoneyIncentivesRule{
MoneyIncentivesStage: v.MoneyIncentivesStage,
MoneyIncentivesStageStart: int(v.MoneyIncentivesTime.UnixNano() / 1e6),
}
rules = append(rules, r)
}
contractUndertaker := []dto.ContractUndertaker{}
for _, v := range contractData.Undertakers {
ruleStage := []int{}
for _, vv := range resultDividendsEstimate.Grid.List {
if v.UserId == vv.DividendsUser.UserId {
ruleStage = append(ruleStage, vv.DividendsStage)
}
}
temp := dto.ContractUndertaker{
UserId: v.UserId,
UsersName: v.UserInfo.UserName,
ContractIncentivesRules: ruleStage,
}
contractUndertaker = append(contractUndertaker, temp)
}
data := map[string]interface{}{
"contractUndertaker": contractUndertaker,
"moneyIncentivesRule": rules,
}
return data, nil
}
//ConfimDividendsEstimate 确定分红预算
func (dividendsEstimateService *DividendsEstimateService) ConfimDividendsEstimate(confimDividendsEstimateCommand *command.ConfimDividendsEstimateCommand) (interface{}, error) {
creationCooperationGateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(confimDividendsEstimateCommand.Operator)
result, err := creationCooperationGateway.CreditAccountsAdd(allied_creation_cooperation.ReqCreditAccountsAdd{
DividendsEstimateIds: confimDividendsEstimateCommand.DividendsEstimateId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}