statistics_company.go
12.4 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/json"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/cooperation/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_cooperation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
)
// 企业端统计
type CompanyStatisticsService struct {
}
// IndexStatistics 首页统计 (入口页面统计数据)
func (srv CompanyStatisticsService) IndexStatistics(cmd *command.IndexStatisticsCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
companyDividendsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CompanyDividendsStatistics, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"action": 1, //当前月
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
cooperationModeStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationModeStatistics, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
cooperationGoodsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationGoodsStatistics, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"rankType": 1, //月榜
"top": 5,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// 模式列表
var modeStatistics = struct {
TotalCooperationModeStatistics interface{} `json:"totalCooperationModeStatistics"`
CooperationModeStatistics interface{} `json:"cooperationModeStatistics"`
CooperationModes interface{} `json:"cooperationModes"`
}{}
err = json.UnmarshalFromString(json.MarshalToString(cooperationModeStatistics), &modeStatistics)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// 项目概览统计
contracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
PageNumber: 1,
PageSize: 1,
CompanyId: cmd.Operator.CompanyId,
OrgId: cmd.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
projects, err := gateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
PageNumber: 1,
PageSize: 1,
CompanyId: cmd.Operator.CompanyId,
OrgId: cmd.Operator.OrgId,
Status: 1,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
Limit: 1,
Offset: 0,
CompanyId: cmd.Operator.CompanyId,
OrganizationId: cmd.Operator.OrgId,
UserType: domain.UserTypeCooperation,
InEnableStatus: []int{domain.UserStatusEnable},
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var projectOverviewStatistics = map[string]interface{}{
"contractSum": contracts.Grid.Total,
"cooperationUserCount": users.Count,
"projectSum": projects.Total,
}
return map[string]interface{}{
"projectOverviewStatistics": projectOverviewStatistics,
"currentMonthDividendsStatistics": companyDividendsStatistics,
"cooperationModeStatistics": modeStatistics.CooperationModeStatistics,
"cooperationGoodsStatistics": cooperationGoodsStatistics,
"cooperationModes": modeStatistics.CooperationModes,
"totalCooperationModeStatistics": modeStatistics.TotalCooperationModeStatistics,
}, nil
}
// IndexStatistics 首页统计 (入口页面统计数据)
func (srv CompanyStatisticsService) IndexStatisticsBak(cmd *command.IndexStatisticsCommand) (interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
companyDividendsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CompanyDividendsStatistics, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"action": 1, //当前月
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
cooperationModeStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationModeStatistics, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
cooperationGoodsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationGoodsStatistics, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"rankType": 1, //月榜
"top": 5,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
// 模式列表
var modeStatistics []CooperationModeStatistics
var responseModeStatistics []CooperationModeStatistics
var modeNumbers []string
err = json.UnmarshalFromString(json.MarshalToString(cooperationModeStatistics), &modeStatistics)
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
for i := range modeStatistics {
modeNumbers = append(modeNumbers, modeStatistics[i].CooperationModeNumber)
}
var cooperationModes = make([]interface{}, 0)
models, err := gateway.CooperationModesSearch(allied_creation_cooperation.ReqCooperationModesSearch{
PageSize: domain.NormalQueryRowCount,
PageNumber: 1,
CompanyId: cmd.Operator.CompanyId,
OrgId: cmd.Operator.OrgId,
//CooperationModeNumbers: modeNumbers,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
mapModels := make(map[string]CooperationModeStatistics)
for i := range responseModeStatistics {
item := responseModeStatistics[i]
mapModels[item.CooperationModeNumber] = item
}
if len(models.List) > 0 {
for i := range models.List {
item := models.List[i]
if value, ok := mapModels[item.CooperationModeNumber]; !ok {
responseModeStatistics = append(responseModeStatistics, CooperationModeStatistics{
CooperationPeople: 0,
DividendsEstimate: 0,
OrderAmount: 0,
CooperationModeNumber: item.CooperationModeNumber,
SettlementAmount: 0,
})
} else {
responseModeStatistics = append(responseModeStatistics, value)
}
cooperationModes = append(cooperationModes, map[string]interface{}{
"cooperationModeId": item.CooperationModeId,
"cooperationModeName": item.CooperationModeName,
"cooperationModeNumber": item.CooperationModeNumber,
})
}
}
// 项目概览统计
contracts, err := gateway.CooperationContractSearch(allied_creation_cooperation.ReqCooperationContractSearch{
PageNumber: 1,
PageSize: 1,
CompanyId: cmd.Operator.CompanyId,
OrgId: cmd.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
projects, err := gateway.CooperationProjectsSearch(allied_creation_cooperation.ReqCooperationProjectSearch{
PageNumber: 1,
PageSize: 1,
CompanyId: cmd.Operator.CompanyId,
OrgId: cmd.Operator.OrgId,
Status: 1,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
users, err := gatewayUser.UserSearch(allied_creation_user.ReqUserSearch{
Limit: 1,
Offset: 0,
CompanyId: cmd.Operator.CompanyId,
OrganizationId: cmd.Operator.OrgId,
UserType: domain.UserTypeCooperation,
InEnableStatus: []int{domain.UserStatusEnable},
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var projectOverviewStatistics = map[string]interface{}{
"contractSum": contracts.Grid.Total,
"cooperationUserCount": users.Count,
"projectSum": projects.Total,
}
return map[string]interface{}{
"projectOverviewStatistics": projectOverviewStatistics,
"currentMonthDividendsStatistics": companyDividendsStatistics,
"cooperationModeStatistics": responseModeStatistics,
"cooperationGoodsStatistics": cooperationGoodsStatistics,
"cooperationModes": cooperationModes,
}, nil
}
// GoodsStatistics 产品统计排行榜 年月榜
func (srv CompanyStatisticsService) GoodsStatistics(cmd *command.GoodsStatisticsCommand) (int64, interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
cooperationGoodsStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationGoodsStatistics, map[string]interface{}{
"companyId": cmd.Operator.CompanyId,
"orgId": cmd.Operator.OrgId,
"rankType": cmd.RankingType, //当前月
"offset": cmd.PageNumber * cmd.PageSize,
"limit": cmd.PageSize,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return 0, cooperationGoodsStatistics, nil
}
// CooperationDividendsStatistics 公司共创人员列表
func (srv CompanyStatisticsService) CooperationDividendsStatistics(cmd *command.CooperationDividendsStatisticsCommand) (int64, interface{}, error) {
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
cooperationUsersStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CompanyCooperationUsersStatistics, map[string]interface{}{
"orgId": cmd.Operator.OrgId,
"offset": cmd.PageNumber * cmd.PageSize,
"limit": cmd.PageSize,
"sortByActuallyPaidAmount": cmd.SortByActuallyPaidAmount,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return 0, cooperationUsersStatistics, nil
}
// CooperationPersonStatistics 共创人明细员统计(共创人员明细)
func (srv CompanyStatisticsService) CooperationPersonStatistics(cmd *command.CooperationPersonStatisticsCommand) (interface{}, error) {
gatewayUser := allied_creation_user.NewHttplibAlliedCreationUser(
cmd.Operator)
user, err := gatewayUser.UserGet(allied_creation_user.ReqGetUser{
UserId: cmd.UserId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
gateway := allied_creation_cooperation.NewHttplibAlliedCreationCooperation(
cmd.Operator)
cooperationUserModeStatistics, err := gateway.CooperationStatistics(allied_creation_cooperation.CooperationUserModeStatistics, map[string]interface{}{
"userId": cmd.UserId,
"orgId": cmd.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var modeStatistics = struct {
CooperationTypes interface{} `json:"cooperationTypes"`
DividendsDetails interface{} `json:"dividendsDetails"`
OrderDetails interface{} `json:"orderDetails"`
}{}
if err := json.UnmarshalFromString(json.MarshalToString(cooperationUserModeStatistics), &modeStatistics); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var response = map[string]interface{}{
"userName": user.UserInfo.UserName,
"cooperationTime": user.CreatedAt.Unix() * 1000,
"cooperationTypes": modeStatistics.CooperationTypes,
"dividendsDetails": modeStatistics.DividendsDetails,
"orderDetails": modeStatistics.OrderDetails,
}
return map[string]interface{}{
"cooperationPersonStatistics": response,
}, nil
}
type CooperationModeStatistics struct {
// 共创人数
CooperationPeople float64 `json:"cooperationPeople"`
// 分红预算
DividendsEstimate float64 `json:"dividendsEstimate"`
// 订单金额
OrderAmount float64 `json:"orderAmount"`
// 共创模式编号
CooperationModeNumber string `json:"cooperationModeNumber"`
// 结算金额
SettlementAmount float64 `json:"settlementAmount"`
}