|
|
1
|
+package dividend
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "time"
|
|
|
6
|
+
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
|
|
|
10
|
+ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
|
|
11
|
+ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
|
|
|
12
|
+)
|
|
|
13
|
+
|
|
|
14
|
+// 分红统计
|
|
|
15
|
+func StatisticsV2(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsV2Response, err error) {
|
|
|
16
|
+ var (
|
|
|
17
|
+ transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
18
|
+ OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
|
|
|
19
|
+ )
|
|
|
20
|
+ if err = transactionContext.StartTransaction(); err != nil {
|
|
|
21
|
+ return nil, err
|
|
|
22
|
+ }
|
|
|
23
|
+ defer func() {
|
|
|
24
|
+ transactionContext.RollbackTransaction()
|
|
|
25
|
+ }()
|
|
|
26
|
+
|
|
|
27
|
+ // 事业分红统计-查询订单
|
|
|
28
|
+ _, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(
|
|
|
29
|
+ domain.OrderQueryOption{
|
|
|
30
|
+ PartnerId: request.PartnerId,
|
|
|
31
|
+ EndTime: utils.GetDayEnd(),
|
|
|
32
|
+ SortBySalesTime: domain.DESC,
|
|
|
33
|
+ OrderTypes: domain.UserOrderTypes(domain.Career),
|
|
|
34
|
+ }))
|
|
|
35
|
+ if e != nil {
|
|
|
36
|
+ log.Error(e)
|
|
|
37
|
+ }
|
|
|
38
|
+ err = transactionContext.CommitTransaction()
|
|
|
39
|
+ if e != nil {
|
|
|
40
|
+ return nil, err
|
|
|
41
|
+ }
|
|
|
42
|
+ //获取营销年
|
|
|
43
|
+ t := time.Now()
|
|
|
44
|
+ var last time.Time
|
|
|
45
|
+ var first time.Time
|
|
|
46
|
+ boundDate := time.Date(t.Year(), time.March, 31, 23, 59, 59, 0, time.Local) // 营销年界限
|
|
|
47
|
+ fmt.Println("营销年界限:", boundDate)
|
|
|
48
|
+ if t.Before(boundDate) || t.Equal(boundDate) {
|
|
|
49
|
+ first = time.Date(t.Year()-1, time.April, 1, 0, 0, 0, 0, time.Local)
|
|
|
50
|
+ last = time.Date(t.Year(), time.March, 31, 23, 59, 59, 0, time.Local)
|
|
|
51
|
+ } else if t.After(boundDate) {
|
|
|
52
|
+ first = time.Date(t.Year(), time.April, 1, 0, 0, 0, 0, time.Local)
|
|
|
53
|
+ last = time.Date(t.Year()+1, time.March, 31, 23, 59, 59, 0, time.Local)
|
|
|
54
|
+ }
|
|
|
55
|
+ fmt.Println("当前营销年起始:", first, last)
|
|
|
56
|
+ // 请求开始时间和结束时间都为0时,默认从营销年开始统计
|
|
|
57
|
+ if request.StartTime == 0 && request.EndTime == 0 {
|
|
|
58
|
+ request.StartTime = first.Unix() * 1000
|
|
|
59
|
+ request.EndTime = last.Unix() * 1000
|
|
|
60
|
+ } else if request.StartTime > 0 && request.EndTime > 0 { // 判断结束时间是否超过今天,超过今天的结束时间到今天为止
|
|
|
61
|
+ currentDayEnd := utils.GetDayEnd().Unix() * 1000
|
|
|
62
|
+ if request.EndTime >= currentDayEnd {
|
|
|
63
|
+ request.EndTime = currentDayEnd
|
|
|
64
|
+ }
|
|
|
65
|
+ }
|
|
|
66
|
+
|
|
|
67
|
+ fmt.Println("StartTime: ", request.StartTime)
|
|
|
68
|
+ fmt.Println("EndTime: ", request.EndTime)
|
|
|
69
|
+
|
|
|
70
|
+ var orderBetween []*domain.OrderBase
|
|
|
71
|
+ for i := range orderAll {
|
|
|
72
|
+ if orderAll[i].SaleDate.Unix() >= (request.StartTime/1000) && orderAll[i].SaleDate.Unix() < (request.EndTime/1000) {
|
|
|
73
|
+ orderBetween = append(orderBetween, orderAll[i])
|
|
|
74
|
+ }
|
|
|
75
|
+ }
|
|
|
76
|
+ //0:全部分类,
|
|
|
77
|
+ //Career int = 1 //事业
|
|
|
78
|
+ //Business int = 2 //业务
|
|
|
79
|
+ //Develop int = 3 //研发
|
|
|
80
|
+ //App int = 4 //业务产品-应用
|
|
|
81
|
+ //累计分红
|
|
|
82
|
+ var (
|
|
|
83
|
+ bonusAll protocol.Bonus
|
|
|
84
|
+ bonusAllCareer protocol.Bonus
|
|
|
85
|
+ bonusAllBusiness protocol.Bonus
|
|
|
86
|
+ bonusAllDevelop protocol.Bonus
|
|
|
87
|
+ bonusAllApp protocol.Bonus
|
|
|
88
|
+ )
|
|
|
89
|
+ for _, val := range orderAll {
|
|
|
90
|
+ static := val.OrderBonusStatic()
|
|
|
91
|
+ bonusAll.Received = utils.Decimal(bonusAll.Received + static.OrderBonusReceive())
|
|
|
92
|
+ bonusAll.Outstanding = utils.Decimal(bonusAll.Outstanding + static.OrderBonusWait())
|
|
|
93
|
+ bonusAll.Receivable = utils.Decimal(bonusAll.Receivable + static.OrderTotalReceivable())
|
|
|
94
|
+ if val.PartnerCategory == nil {
|
|
|
95
|
+ continue
|
|
|
96
|
+ }
|
|
|
97
|
+ switch val.PartnerCategory.Id {
|
|
|
98
|
+ case int64(domain.Career):
|
|
|
99
|
+ bonusAllCareer.Received = utils.Decimal(bonusAllCareer.Received + static.OrderBonusReceive())
|
|
|
100
|
+ bonusAllCareer.Outstanding = utils.Decimal(bonusAllCareer.Outstanding + static.OrderBonusWait())
|
|
|
101
|
+ bonusAllCareer.Receivable = utils.Decimal(bonusAllCareer.Receivable + static.OrderTotalReceivable())
|
|
|
102
|
+ case int64(domain.Business):
|
|
|
103
|
+ bonusAllBusiness.Received = utils.Decimal(bonusAllBusiness.Received + static.OrderBonusReceive())
|
|
|
104
|
+ bonusAllBusiness.Outstanding = utils.Decimal(bonusAllBusiness.Outstanding + static.OrderBonusWait())
|
|
|
105
|
+ bonusAllBusiness.Receivable = utils.Decimal(bonusAllBusiness.Receivable + static.OrderTotalReceivable())
|
|
|
106
|
+ case int64(domain.App):
|
|
|
107
|
+ bonusAllApp.Received = utils.Decimal(bonusAllApp.Received + static.OrderBonusReceive())
|
|
|
108
|
+ bonusAllApp.Outstanding = utils.Decimal(bonusAllApp.Outstanding + static.OrderBonusWait())
|
|
|
109
|
+ bonusAllApp.Receivable = utils.Decimal(bonusAllApp.Receivable + static.OrderTotalReceivable())
|
|
|
110
|
+ case int64(domain.Develop):
|
|
|
111
|
+ bonusAllDevelop.Received = utils.Decimal(bonusAllDevelop.Received + static.OrderBonusReceive())
|
|
|
112
|
+ bonusAllDevelop.Outstanding = utils.Decimal(bonusAllDevelop.Outstanding + static.OrderBonusWait())
|
|
|
113
|
+ bonusAllDevelop.Receivable = utils.Decimal(bonusAllDevelop.Receivable + static.OrderTotalReceivable())
|
|
|
114
|
+ }
|
|
|
115
|
+ }
|
|
|
116
|
+ //0:全部分类,
|
|
|
117
|
+ //Career int = 1 //事业
|
|
|
118
|
+ //Business int = 2 //业务
|
|
|
119
|
+ //Develop int = 3 //研发
|
|
|
120
|
+ //App int = 4 //业务产品-应用
|
|
|
121
|
+ //季度分红
|
|
|
122
|
+ var (
|
|
|
123
|
+ bonusQuarters = [4]protocol.Bonus{}
|
|
|
124
|
+ bonusQuartersCareer = [4]protocol.Bonus{}
|
|
|
125
|
+ bonusQuartersBusiness = [4]protocol.Bonus{}
|
|
|
126
|
+ bonusQuartersDevelop = [4]protocol.Bonus{}
|
|
|
127
|
+ bonusQuartersApp = [4]protocol.Bonus{}
|
|
|
128
|
+ )
|
|
|
129
|
+ //月度分红
|
|
|
130
|
+ var (
|
|
|
131
|
+ bonusMonths = [12]protocol.Bonus{}
|
|
|
132
|
+ bonusMonthsCareer = [12]protocol.Bonus{}
|
|
|
133
|
+ bonusMonthsBusiness = [12]protocol.Bonus{}
|
|
|
134
|
+ bonusMonthsDevelop = [12]protocol.Bonus{}
|
|
|
135
|
+ bonusMonthsApp = [12]protocol.Bonus{}
|
|
|
136
|
+ )
|
|
|
137
|
+ var (
|
|
|
138
|
+ quarterNum int // 对应季度在数组中的位置
|
|
|
139
|
+ monthNum int //对应月份在数组中的位置
|
|
|
140
|
+ )
|
|
|
141
|
+ for _, val := range orderBetween {
|
|
|
142
|
+ quarterNum = quarter(val.SaleDate)
|
|
|
143
|
+ monthNum = int(val.SaleDate.Month()) - 1
|
|
|
144
|
+ static := val.OrderBonusStatic()
|
|
|
145
|
+ bonusQuarters[quarterNum].Receivable = utils.Decimal(bonusQuarters[quarterNum].Receivable + static.OrderTotalReceivable())
|
|
|
146
|
+ bonusQuarters[quarterNum].Received = utils.Decimal(bonusQuarters[quarterNum].Received + static.OrderBonusReceive())
|
|
|
147
|
+ bonusQuarters[quarterNum].Outstanding = utils.Decimal(bonusQuarters[quarterNum].Outstanding + static.OrderBonusWait())
|
|
|
148
|
+
|
|
|
149
|
+ bonusMonths[monthNum].Receivable = utils.Decimal(bonusMonths[monthNum].Receivable + static.OrderTotalReceivable())
|
|
|
150
|
+ bonusMonths[monthNum].Received = utils.Decimal(bonusMonths[monthNum].Received + static.OrderBonusReceive())
|
|
|
151
|
+ bonusMonths[monthNum].Outstanding = utils.Decimal(bonusMonths[monthNum].Outstanding + static.OrderBonusWait())
|
|
|
152
|
+ if val.PartnerCategory == nil {
|
|
|
153
|
+ continue
|
|
|
154
|
+ }
|
|
|
155
|
+ // 分类合并计数
|
|
|
156
|
+ switch val.PartnerCategory.Id {
|
|
|
157
|
+ case int64(domain.Career):
|
|
|
158
|
+ bonusQuartersCareer[quarterNum].Receivable = utils.Decimal(bonusQuartersCareer[quarterNum].Receivable + static.OrderTotalReceivable())
|
|
|
159
|
+ bonusQuartersCareer[quarterNum].Received = utils.Decimal(bonusQuartersCareer[quarterNum].Received + static.OrderBonusReceive())
|
|
|
160
|
+ bonusQuartersCareer[quarterNum].Outstanding = utils.Decimal(bonusQuartersCareer[quarterNum].Outstanding + static.OrderBonusWait())
|
|
|
161
|
+
|
|
|
162
|
+ bonusMonthsCareer[monthNum].Receivable = utils.Decimal(bonusMonthsCareer[monthNum].Receivable + static.OrderTotalReceivable())
|
|
|
163
|
+ bonusMonthsCareer[monthNum].Received = utils.Decimal(bonusMonthsCareer[monthNum].Received + static.OrderBonusReceive())
|
|
|
164
|
+ bonusMonthsCareer[monthNum].Outstanding = utils.Decimal(bonusMonthsCareer[monthNum].Outstanding + static.OrderBonusWait())
|
|
|
165
|
+ case int64(domain.Business):
|
|
|
166
|
+ bonusQuartersBusiness[quarterNum].Receivable = utils.Decimal(bonusQuartersBusiness[quarterNum].Receivable + static.OrderTotalReceivable())
|
|
|
167
|
+ bonusQuartersBusiness[quarterNum].Received = utils.Decimal(bonusQuartersBusiness[quarterNum].Received + static.OrderBonusReceive())
|
|
|
168
|
+ bonusQuartersBusiness[quarterNum].Outstanding = utils.Decimal(bonusQuartersBusiness[quarterNum].Outstanding + static.OrderBonusWait())
|
|
|
169
|
+
|
|
|
170
|
+ bonusMonthsBusiness[monthNum].Receivable = utils.Decimal(bonusMonthsBusiness[monthNum].Receivable + static.OrderTotalReceivable())
|
|
|
171
|
+ bonusMonthsBusiness[monthNum].Received = utils.Decimal(bonusMonthsBusiness[monthNum].Received + static.OrderBonusReceive())
|
|
|
172
|
+ bonusMonthsBusiness[monthNum].Outstanding = utils.Decimal(bonusMonthsBusiness[monthNum].Outstanding + static.OrderBonusWait())
|
|
|
173
|
+ case int64(domain.App):
|
|
|
174
|
+ bonusQuartersApp[quarterNum].Receivable = utils.Decimal(bonusQuartersApp[quarterNum].Receivable + static.OrderTotalReceivable())
|
|
|
175
|
+ bonusQuartersApp[quarterNum].Received = utils.Decimal(bonusQuartersApp[quarterNum].Received + static.OrderBonusReceive())
|
|
|
176
|
+ bonusQuartersApp[quarterNum].Outstanding = utils.Decimal(bonusQuartersApp[quarterNum].Outstanding + static.OrderBonusWait())
|
|
|
177
|
+
|
|
|
178
|
+ bonusMonthsApp[monthNum].Receivable = utils.Decimal(bonusMonthsApp[monthNum].Receivable + static.OrderTotalReceivable())
|
|
|
179
|
+ bonusMonthsApp[monthNum].Received = utils.Decimal(bonusMonthsApp[monthNum].Received + static.OrderBonusReceive())
|
|
|
180
|
+ bonusMonthsApp[monthNum].Outstanding = utils.Decimal(bonusMonthsApp[monthNum].Outstanding + static.OrderBonusWait())
|
|
|
181
|
+ case int64(domain.Develop):
|
|
|
182
|
+ bonusQuartersDevelop[quarterNum].Receivable = utils.Decimal(bonusQuartersDevelop[quarterNum].Receivable + static.OrderTotalReceivable())
|
|
|
183
|
+ bonusQuartersDevelop[quarterNum].Received = utils.Decimal(bonusQuartersDevelop[quarterNum].Received + static.OrderBonusReceive())
|
|
|
184
|
+ bonusQuartersDevelop[quarterNum].Outstanding = utils.Decimal(bonusQuartersDevelop[quarterNum].Outstanding + static.OrderBonusWait())
|
|
|
185
|
+
|
|
|
186
|
+ bonusMonthsDevelop[monthNum].Receivable = utils.Decimal(bonusMonthsDevelop[monthNum].Receivable + static.OrderTotalReceivable())
|
|
|
187
|
+ bonusMonthsDevelop[monthNum].Received = utils.Decimal(bonusMonthsDevelop[monthNum].Received + static.OrderBonusReceive())
|
|
|
188
|
+ bonusMonthsDevelop[monthNum].Outstanding = utils.Decimal(bonusMonthsDevelop[monthNum].Outstanding + static.OrderBonusWait())
|
|
|
189
|
+ }
|
|
|
190
|
+ }
|
|
|
191
|
+ // 整理输出数据
|
|
|
192
|
+ rsp = &protocol.DividendStatisticsV2Response{
|
|
|
193
|
+ Statistics: protocol.DividendStatistics{
|
|
|
194
|
+ Received: bonusAll.Received,
|
|
|
195
|
+ Outstanding: bonusAll.Outstanding,
|
|
|
196
|
+ Receivable: bonusAll.Receivable,
|
|
|
197
|
+ Quarters: bonusQuarters,
|
|
|
198
|
+ Months: bonusMonths,
|
|
|
199
|
+ },
|
|
|
200
|
+ StatisticsCareer: protocol.DividendStatistics{
|
|
|
201
|
+ Received: bonusAllCareer.Receivable,
|
|
|
202
|
+ Outstanding: bonusAllCareer.Outstanding,
|
|
|
203
|
+ Receivable: bonusAllCareer.Receivable,
|
|
|
204
|
+ Quarters: bonusQuartersCareer,
|
|
|
205
|
+ Months: bonusMonthsCareer,
|
|
|
206
|
+ },
|
|
|
207
|
+ StatisticsBusiness: protocol.DividendStatistics{
|
|
|
208
|
+ Received: bonusAllBusiness.Receivable,
|
|
|
209
|
+ Outstanding: bonusAllBusiness.Outstanding,
|
|
|
210
|
+ Receivable: bonusAllBusiness.Receivable,
|
|
|
211
|
+ Quarters: bonusQuartersBusiness,
|
|
|
212
|
+ Months: bonusMonthsBusiness,
|
|
|
213
|
+ },
|
|
|
214
|
+ StatisticsDevelop: protocol.DividendStatistics{
|
|
|
215
|
+ Received: bonusAllDevelop.Received,
|
|
|
216
|
+ Outstanding: bonusAllDevelop.Outstanding,
|
|
|
217
|
+ Receivable: bonusAllDevelop.Receivable,
|
|
|
218
|
+ Quarters: bonusQuartersDevelop,
|
|
|
219
|
+ Months: bonusMonthsDevelop,
|
|
|
220
|
+ },
|
|
|
221
|
+ StatisticsApp: protocol.DividendStatistics{
|
|
|
222
|
+ Received: bonusAllApp.Received,
|
|
|
223
|
+ Outstanding: bonusAllApp.Outstanding,
|
|
|
224
|
+ Receivable: bonusAllApp.Receivable,
|
|
|
225
|
+ Quarters: bonusQuartersApp,
|
|
|
226
|
+ Months: bonusMonthsApp,
|
|
|
227
|
+ },
|
|
|
228
|
+ Timestamp: 0,
|
|
|
229
|
+ }
|
|
|
230
|
+ rsp.Timestamp = time.Now().Unix() * 1000
|
|
|
231
|
+
|
|
|
232
|
+ return
|
|
|
233
|
+} |