statistics_company.go
6.9 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
package service
import (
"fmt"
"math/rand"
"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/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"
)
// 企业端统计 【25%】
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())
}
// 模式列表
models, err := gateway.CooperationModeList(allied_creation_cooperation.ReqCooperationModeList{
PageSize: 20,
PageNumber: 1,
CompanyId: cmd.Operator.CompanyId,
OrgId: cmd.Operator.OrgId,
UserId: cmd.Operator.UserId,
UserBaseId: cmd.Operator.UserBaseId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
var cooperationModes []interface{}
for i := range models.List {
item := models.List[i]
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,
})
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,
})
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": cooperationModeStatistics,
"cooperationGoodsStatistics": cooperationGoodsStatistics,
"cooperationModes": cooperationModes,
}, nil
}
// GoodsStatistics TODO:产品统计排行榜 年月榜
func (srv CompanyStatisticsService) GoodsStatistics(cmd *command.GoodsStatisticsCommand) (int64, interface{}, error) {
//type rankItem struct {
// GoodAmount float64 `json:"goodAmount"`
// GoodName string `json:"goodName"`
// GoodRatio float64 `json:"goodRatio"`
// Rank int `json:"rank"`
//}
//var items []rankItem
//for i := 0; i < 5; i++ {
// item := rankItem{
// GoodAmount: 2000,
// GoodName: fmt.Sprintf("商品%v", rand.Intn(100)),
// GoodRatio: 20,
// Rank: i + 1,
// }
// items = append(items, item)
//}
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,
"top": 100,
})
if err != nil {
return 0, nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return 0, cooperationGoodsStatistics, nil
}
// CooperationDividendsStatistics TODO:公司共创人员列表
func (srv CompanyStatisticsService) CooperationDividendsStatistics(userMenusCommand *command.CooperationDividendsStatisticsCommand) (int64, interface{}, error) {
type cooperationDividendItem struct {
CooperationTime int64 `json:"cooperationTime"`
DividendsOrderAmount float64 `json:"dividendsOrderAmount"`
ActuallyPaidAmount float64 `json:"actuallyPaidAmount"`
UnPaidAmount float64 `json:"unPaidAmount"`
Participator struct {
UserType int `json:"userType"`
UserInfo struct {
// 用户姓名
UserName string `json:"userName,omitempty"`
// 手机号码
UserPhone string `json:"userPhone,omitempty"`
// 头像
//Avatar string `json:"avatar,omitempty"`
// 邮箱
//Email string `json:"email,omitempty"`
} `json:"userInfo"`
} `json:"participator"` // 参与人
}
var results []cooperationDividendItem
for i := 0; i < 5; i++ {
item := cooperationDividendItem{
CooperationTime: time.Now().Unix() * 1000,
DividendsOrderAmount: 6000,
ActuallyPaidAmount: 5000,
UnPaidAmount: 1000,
}
item.Participator.UserInfo.UserName = fmt.Sprintf("用户%v", rand.Intn(100))
results = append(results, item)
}
return 5, results, nil
}
// CooperationPersonStatistics TODO:共创人员统计(共创人员明细)
func (srv CompanyStatisticsService) CooperationPersonStatistics(userMenusCommand *command.CooperationPersonStatisticsCommand) (interface{}, error) {
return map[string]interface{}{}, nil
}