|
@@ -2,6 +2,9 @@ package domain_service |
|
@@ -2,6 +2,9 @@ package domain_service |
|
2
|
|
2
|
|
|
3
|
import (
|
3
|
import (
|
|
4
|
"fmt"
|
4
|
"fmt"
|
|
|
|
5
|
+ "github.com/beego/beego/v2/core/validation"
|
|
|
|
6
|
+ "github.com/linmadan/egglib-go/utils/json"
|
|
|
|
7
|
+ "github.com/linmadan/egglib-go/utils/tool_funs"
|
|
5
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
|
7
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
@@ -12,32 +15,44 @@ import ( |
|
@@ -12,32 +15,44 @@ import ( |
|
12
|
|
15
|
|
|
13
|
// rankType 排行榜类型,1月榜,2年榜 3总榜,默认展示年榜
|
16
|
// rankType 排行榜类型,1月榜,2年榜 3总榜,默认展示年榜
|
|
14
|
// top 排名前n个
|
17
|
// top 排名前n个
|
|
15
|
-func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(companyId, orgId int64, rankType int, top int) ([]*domain.CooperationGoodsStatisticsDto, error) {
|
18
|
+func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationGoodsStatisticsDto, error) {
|
|
16
|
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
|
19
|
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
|
|
17
|
- queryOptions := make(map[string]interface{})
|
|
|
|
18
|
- queryOptions["companyId"] = companyId
|
|
|
|
19
|
- queryOptions["orgId"] = orgId
|
20
|
+ // 参数验证
|
|
|
|
21
|
+ var request = struct {
|
|
|
|
22
|
+ CompanyId int64 `json:"companyId" valid:"Required"`
|
|
|
|
23
|
+ OrgId int64 `json:"orgId" valid:"Required"`
|
|
|
|
24
|
+ RankType int `json:"rankType" valid:"Required"`
|
|
|
|
25
|
+ Top int `json:"top" valid:"Required"`
|
|
|
|
26
|
+ }{}
|
|
|
|
27
|
+ if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
|
28
|
+ return nil, err
|
|
|
|
29
|
+ }
|
|
|
|
30
|
+ queryOptions = tool_funs.SimpleStructToMap(&request)
|
|
|
|
31
|
+
|
|
20
|
y := time.Now().Year()
|
32
|
y := time.Now().Year()
|
|
21
|
m := time.Now().Month()
|
33
|
m := time.Now().Month()
|
|
22
|
var beginTime, endTime time.Time
|
34
|
var beginTime, endTime time.Time
|
|
23
|
- if rankType == 1 { //1月榜
|
35
|
+ if request.RankType == 1 { //1月榜
|
|
24
|
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
|
36
|
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
|
|
25
|
endTime = beginTime.AddDate(0, 1, 0)
|
37
|
endTime = beginTime.AddDate(0, 1, 0)
|
|
26
|
- queryOptions["beginTime"] = beginTime
|
|
|
|
27
|
- queryOptions["endTime"] = endTime
|
|
|
|
28
|
- } else if rankType == 2 { //2年榜
|
38
|
+ queryOptions["beginTime"] = beginTime.Format(time.RFC3339)
|
|
|
|
39
|
+ queryOptions["endTime"] = endTime.Format(time.RFC3339)
|
|
|
|
40
|
+ } else if request.RankType == 2 { //2年榜
|
|
29
|
beginTime = time.Date(y, 1, 1, 0, 0, 0, 0, time.Local)
|
41
|
beginTime = time.Date(y, 1, 1, 0, 0, 0, 0, time.Local)
|
|
30
|
endTime = beginTime.AddDate(1, 0, 0)
|
42
|
endTime = beginTime.AddDate(1, 0, 0)
|
|
31
|
- queryOptions["beginTime"] = beginTime
|
|
|
|
32
|
- queryOptions["endTime"] = endTime
|
43
|
+ queryOptions["beginTime"] = beginTime.Format(time.RFC3339)
|
|
|
|
44
|
+ queryOptions["endTime"] = endTime.Format(time.RFC3339)
|
|
33
|
}
|
45
|
}
|
|
34
|
- if top > 0 {
|
|
|
|
35
|
- queryOptions["limit"] = top
|
46
|
+ if request.Top > 0 {
|
|
|
|
47
|
+ queryOptions["limit"] = request.Top
|
|
36
|
}
|
48
|
}
|
|
37
|
goods, err := orderGoodDao.CooperationGoodsStatistics(queryOptions)
|
49
|
goods, err := orderGoodDao.CooperationGoodsStatistics(queryOptions)
|
|
38
|
if err != nil {
|
50
|
if err != nil {
|
|
39
|
return nil, err
|
51
|
return nil, err
|
|
40
|
}
|
52
|
}
|
|
|
|
53
|
+ if len(goods) == 0 {
|
|
|
|
54
|
+ goods = make([]*domain.CooperationGoodsStatisticsDto, 0)
|
|
|
|
55
|
+ }
|
|
41
|
|
56
|
|
|
42
|
// 2.计算百分比
|
57
|
// 2.计算百分比
|
|
43
|
var totalAmount float64
|
58
|
var totalAmount float64
|
|
@@ -54,16 +69,25 @@ func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(companyId, o |
|
@@ -54,16 +69,25 @@ func (ptr *CooperationStatisticsService) CooperationGoodsStatistics(companyId, o |
|
54
|
// CooperationModeStatistics 企业-共创模式统计
|
69
|
// CooperationModeStatistics 企业-共创模式统计
|
|
55
|
//
|
70
|
//
|
|
56
|
// p1 p1_desc
|
71
|
// p1 p1_desc
|
|
57
|
-func (ptr *CooperationStatisticsService) CooperationModeStatistics(companyId, orgId int64) ([]*domain.CooperationModeStatisticsDto, error) {
|
72
|
+func (ptr *CooperationStatisticsService) CooperationModeStatistics(queryOptions map[string]interface{}) ([]*domain.CooperationModeStatisticsDto, error) {
|
|
58
|
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
|
73
|
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
|
|
59
|
- queryOptions := make(map[string]interface{})
|
|
|
|
60
|
- queryOptions["companyId"] = companyId
|
|
|
|
61
|
- queryOptions["orgId"] = orgId
|
74
|
+ // 参数验证
|
|
|
|
75
|
+ var request = struct {
|
|
|
|
76
|
+ CompanyId int64 `json:"companyId" valid:"Required"`
|
|
|
|
77
|
+ OrgId int64 `json:"orgId" valid:"Required"`
|
|
|
|
78
|
+ }{}
|
|
|
|
79
|
+ if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
|
80
|
+ return nil, err
|
|
|
|
81
|
+ }
|
|
|
|
82
|
+ queryOptions = tool_funs.SimpleStructToMap(&request)
|
|
62
|
|
83
|
|
|
63
|
modeStatistics, err := orderGoodDao.CooperationModeStatistics(queryOptions)
|
84
|
modeStatistics, err := orderGoodDao.CooperationModeStatistics(queryOptions)
|
|
64
|
if err != nil {
|
85
|
if err != nil {
|
|
65
|
return nil, err
|
86
|
return nil, err
|
|
66
|
}
|
87
|
}
|
|
|
|
88
|
+ if len(modeStatistics) == 0 {
|
|
|
|
89
|
+ modeStatistics = make([]*domain.CooperationModeStatisticsDto, 0)
|
|
|
|
90
|
+ }
|
|
67
|
|
91
|
|
|
68
|
return modeStatistics, nil
|
92
|
return modeStatistics, nil
|
|
69
|
}
|
93
|
}
|
|
@@ -71,14 +95,22 @@ func (ptr *CooperationStatisticsService) CooperationModeStatistics(companyId, or |
|
@@ -71,14 +95,22 @@ func (ptr *CooperationStatisticsService) CooperationModeStatistics(companyId, or |
|
71
|
// DividendsStatistics 分红统计
|
95
|
// DividendsStatistics 分红统计
|
|
72
|
//
|
96
|
//
|
|
73
|
// action 1:当前月
|
97
|
// action 1:当前月
|
|
74
|
-func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(companyId, orgId int64, action int) (interface{}, error) {
|
98
|
+func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
|
99
|
+ // 参数验证
|
|
|
|
100
|
+ var request = struct {
|
|
|
|
101
|
+ CompanyId int64 `json:"companyId" valid:"Required"`
|
|
|
|
102
|
+ OrgId int64 `json:"orgId" valid:"Required"`
|
|
|
|
103
|
+ Action int `json:"action" valid:"Required"`
|
|
|
|
104
|
+ }{}
|
|
|
|
105
|
+ if err := LoadQueryObject(queryOptions, &request); err != nil {
|
|
|
|
106
|
+ return nil, err
|
|
|
|
107
|
+ }
|
|
|
|
108
|
+ queryOptions = tool_funs.SimpleStructToMap(&request)
|
|
|
|
109
|
+
|
|
75
|
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
|
110
|
orderGoodDao, _ := dao.NewOrderGoodDao(ptr.transactionContext)
|
|
76
|
- queryOptions := make(map[string]interface{})
|
|
|
|
77
|
- queryOptions["companyId"] = companyId
|
|
|
|
78
|
- queryOptions["orgId"] = orgId
|
|
|
|
79
|
var beginTime, endTime time.Time
|
111
|
var beginTime, endTime time.Time
|
|
80
|
var res = make(map[string]interface{})
|
112
|
var res = make(map[string]interface{})
|
|
81
|
- if action == 1 {
|
113
|
+ if request.Action == 1 {
|
|
82
|
y := time.Now().Year()
|
114
|
y := time.Now().Year()
|
|
83
|
m := time.Now().Month()
|
115
|
m := time.Now().Month()
|
|
84
|
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
|
116
|
beginTime = time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
|
|
@@ -86,18 +118,18 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(companyId, o |
|
@@ -86,18 +118,18 @@ func (ptr *CooperationStatisticsService) CompanyDividendsStatistics(companyId, o |
|
86
|
queryOptions["beginTime"] = beginTime
|
118
|
queryOptions["beginTime"] = beginTime
|
|
87
|
queryOptions["endTime"] = endTime
|
119
|
queryOptions["endTime"] = endTime
|
|
88
|
}
|
120
|
}
|
|
89
|
- totalDividends, err := orderGoodDao.DividendsStatistics(queryOptions)
|
121
|
+ totalDividends, err := orderGoodDao.CompanyDividendsStatistics(queryOptions)
|
|
90
|
if err != nil {
|
122
|
if err != nil {
|
|
91
|
return nil, err
|
123
|
return nil, err
|
|
92
|
}
|
124
|
}
|
|
93
|
- res["creditAccount"] = totalDividends.DividendsEstimate
|
|
|
|
94
|
- res["orderAmount"] = totalDividends.OrderAmount
|
|
|
|
95
|
-
|
|
|
|
96
|
queryOptions["paymentStatus"] = 2
|
125
|
queryOptions["paymentStatus"] = 2
|
|
97
|
- dividendsEstimate, err := orderGoodDao.DividendsStatistics(queryOptions)
|
126
|
+ dividendsEstimate, err := orderGoodDao.CompanyDividendsStatistics(queryOptions)
|
|
98
|
if err != nil {
|
127
|
if err != nil {
|
|
99
|
return nil, err
|
128
|
return nil, err
|
|
100
|
}
|
129
|
}
|
|
|
|
130
|
+
|
|
|
|
131
|
+ res["creditAccount"] = totalDividends.DividendsEstimate
|
|
|
|
132
|
+ res["orderAmount"] = totalDividends.OrderAmount
|
|
101
|
res["dividendsEstimate"] = dividendsEstimate.DividendsEstimate
|
133
|
res["dividendsEstimate"] = dividendsEstimate.DividendsEstimate
|
|
102
|
return res, nil
|
134
|
return res, nil
|
|
103
|
}
|
135
|
}
|
|
@@ -115,6 +147,13 @@ func LoadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[s |
|
@@ -115,6 +147,13 @@ func LoadQueryOptions(queryOption map[string]interface{}, keys ...string) (map[s |
|
115
|
return res, nil
|
147
|
return res, nil
|
|
116
|
}
|
148
|
}
|
|
117
|
|
149
|
|
|
|
|
150
|
+func LoadQueryObject(queryOption map[string]interface{}, obj interface{}) error {
|
|
|
|
151
|
+ json.UnmarshalFromString(json.MarshalToString(queryOption), obj)
|
|
|
|
152
|
+ validation := validation.Validation{}
|
|
|
|
153
|
+ _, err := validation.Valid(obj)
|
|
|
|
154
|
+ return err
|
|
|
|
155
|
+}
|
|
|
|
156
|
+
|
|
118
|
type item struct {
|
157
|
type item struct {
|
|
119
|
key string
|
158
|
key string
|
|
120
|
val interface{}
|
159
|
val interface{}
|