credit_accounts_company.go
9.3 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
237
238
239
package service
import (
"github.com/linmadan/egglib-go/utils/json"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
)
// CompanyCreditAccountService 企业端账期结算
type CompanyCreditAccountService struct {
}
// CreditAccountSearch 企业的账期结算列表
func (srv CompanyCreditAccountService) CreditAccountSearch(cmd *command.CreditAccountSearchCommand) (int64, interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"userId": cmd.Operator.UserId,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var items = make([]*dto.CreditAccountItem, 0)
if len(cooperationContractNumbers) == 0 {
return 0, items, nil
}
resultMenu, err := gateway.CreditAccountsSearch(allied_creation_cooperation.ReqCreditAccountsSearch{
PageNumber: cmd.PageNumber + 1, //手机序号从0开始的
PageSize: cmd.PageSize,
PaymentStatus: cmd.PaymentStatus,
OrgId: cmd.Operator.OrgId,
CooperationContractNumbers: cooperationContractNumbers,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
for i := 0; i < len(resultMenu.Grid.List); i++ {
items = append(items, dto.ToCreditAccountItem(&resultMenu.Grid.List[i]))
}
return int64(len(items)), items, nil
}
// CreditAccountGet 企业的账期结算明细
func (srv CompanyCreditAccountService) CreditAccountGet(cmd *command.CreditAccountGetCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
credit, err := gateway.CreditAccountGet(allied_creation_cooperation.ReqCreditAccountGet{
CreditAccountId: cmd.CreditAccountId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
ret := map[string]interface{}{
"creditAccount": dto.ToCreditAccountItem(&credit.CreditAccount),
"dividendsEstimate": credit.CreditAccount.AccountDetail,
}
return ret, nil
}
// CreditAccountDelete 企业的账期结算删除
func (srv CompanyCreditAccountService) CreditAccountDelete(cmd *command.CreditAccountGetCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
resultMenu, err := gateway.CreditAccountRemove(allied_creation_cooperation.ReqCreditAccountRemove{
CreditAccountId: cmd.CreditAccountId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return resultMenu, nil
}
// CreditAccountPay 企业的账期结算支付
func (srv CompanyCreditAccountService) CreditAccountPay(cmd *command.CreditAccountPayCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
resultMenu, err := gateway.CreditAccountsPay(allied_creation_cooperation.ReqCreditAccountsPay{
CreditAccountId: cmd.CreditAccountId,
ActuallyPaidAmount: cmd.ActuallyPaidAmount,
Remarks: cmd.Remarks,
PaymentDocumentAttachment: cmd.Attachment,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return resultMenu, nil
}
// CreditAccountPaySearch 企业分红结算支付记录
func (srv CompanyCreditAccountService) CreditAccountPaySearch(cmd *command.CreditAccountPaySearchCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"userId": cmd.Operator.UserId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var items = make([]*dto.CreditAccountItem, 0)
if len(cooperationContractNumbers) == 0 {
return items, nil
}
var beginTime, endTime time.Time
if cmd.BeginTime > 0 {
beginTime = time.Unix(cmd.BeginTime/1000, 0)
}
if cmd.EndTime > 0 {
endTime = time.Unix(cmd.EndTime/1000, 0)
}
req := allied_creation_cooperation.ReqCreditAccountsSearch{
PageNumber: cmd.PageNumber + 1, //手机序号从0开始的
PageSize: cmd.PageSize,
PaymentStatus: 2,
OrgId: cmd.Operator.OrgId,
BeginTime: beginTime,
EndTime: endTime,
CooperationContractNumbers: cooperationContractNumbers,
}
resultMenu, err := gateway.CreditAccountsSearch(req)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
queryOptions := map[string]interface{}{
"orgId": cmd.Operator.OrgId,
"cooperationContractNumbers": cooperationContractNumbers,
}
if cmd.BeginTime > 0 {
queryOptions["beginTime"] = beginTime
}
if cmd.EndTime > 0 {
queryOptions["endTime"] = endTime
}
// 2.分红统计
dividendStatisticsResult, err := gateway.CooperationStatistics(allied_creation_cooperation.CreditAccountStatistics, queryOptions)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
type AnnualDividend struct {
Total float64 `json:"total"`
Accounting float64 `json:"accounting"`
Accounted float64 `json:"accounted"`
Paid float64 `json:"paid"`
Unpaid float64 `json:"unpaid"`
}
var annualDividend = &AnnualDividend{}
if err := json.UnmarshalFromString(json.MarshalToString(dividendStatisticsResult), annualDividend); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
//var items = make([]*dto.CreditAccountItem, 0)
for i := 0; i < len(resultMenu.Grid.List); i++ {
items = append(items, dto.ToCreditAccountItem(&resultMenu.Grid.List[i]))
}
return map[string]interface{}{
"grid": map[string]interface{}{
"list": items,
"sum": annualDividend.Paid,
},
}, nil
}
// PaymentHistoryStatistics 支付历史统计
func (srv CompanyCreditAccountService) PaymentHistoryStatistics(cmd *command.CreditAccountPaySearchCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
var response = struct {
RankItems interface{} `json:"rankItems"`
TotalPaymentAmount interface{} `json:"totalPaymentAmount"`
}{}
cooperationContractNumbers, err := gateway.RelevantCooperationContractNumbers(allied_creation_cooperation.RelevantCooperationContractNumbers, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"userId": cmd.Operator.UserId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if len(cooperationContractNumbers) == 0 {
return response, nil
}
queryOptions := map[string]interface{}{
"userId": cmd.Operator.UserId,
"orgId": cmd.Operator.OrgId,
"offset": cmd.PageNumber * cmd.PageSize,
"limit": cmd.PageSize,
"sortByActuallyPaidAmount": 2,
}
if cmd.BeginTime > 0 {
queryOptions["beginTime"] = time.Unix(cmd.BeginTime/1000, 0)
}
if cmd.EndTime > 0 {
queryOptions["endTime"] = time.Unix(cmd.EndTime/1000, 0)
}
cooperationUsersStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CompanyPaymentHistoryStatistics, queryOptions)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
queryOptions["cooperationContractNumbers"] = cooperationContractNumbers
creditAccountStatistics, err := gateway.CreditAccountStatistics(allied_creation_cooperation.CreditAccountStatistics, queryOptions)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
response.RankItems = cooperationUsersStatistics
response.TotalPaymentAmount = creditAccountStatistics.Paid
return response, nil
}
// PaymentHistoryHistogramStatistics 支付历史统计-直方图
func (srv CompanyCreditAccountService) PaymentHistoryHistogramStatistics(cmd *command.CreditAccountPaySearchCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
paymentHistoryHistogramStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.PaymentHistoryHistogramStatistics, map[string]interface{}{
"orgId": cmd.Operator.OrgId,
"userId": cmd.Operator.UserId,
"beginTime": time.Unix(cmd.BeginTime/1000, 0),
"endTime": time.Unix(cmd.EndTime/1000, 0),
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return paymentHistoryHistogramStatistics, nil
}