正在显示
4 个修改的文件
包含
34 行增加
和
10 行删除
@@ -32,14 +32,14 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis | @@ -32,14 +32,14 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis | ||
32 | t := time.Now() | 32 | t := time.Now() |
33 | last := time.Date(t.Year(), time.December, 31, 23, 59, 59, 0, time.Local) | 33 | last := time.Date(t.Year(), time.December, 31, 23, 59, 59, 0, time.Local) |
34 | first := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.Local) | 34 | first := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.Local) |
35 | - fmt.Print("First:", first, "\n") | ||
36 | - fmt.Print("Last:", last, "\n") | ||
37 | if request.StartTime == 0 { | 35 | if request.StartTime == 0 { |
38 | request.StartTime = first.Unix() * 1000 | 36 | request.StartTime = first.Unix() * 1000 |
39 | } | 37 | } |
40 | if request.EndTime == 0 { | 38 | if request.EndTime == 0 { |
41 | request.EndTime = last.Unix() * 1000 | 39 | request.EndTime = last.Unix() * 1000 |
42 | } | 40 | } |
41 | + fmt.Print("StartTime: ", request.StartTime, "\n") | ||
42 | + fmt.Print("EndTime: ", request.EndTime, "\n") | ||
43 | var orderBetween []*domain.OrderBase | 43 | var orderBetween []*domain.OrderBase |
44 | for i := range orderAll { | 44 | for i := range orderAll { |
45 | if orderAll[i].SaleDate.Unix() >= (request.StartTime/1000) && orderAll[i].SaleDate.Unix() < (request.EndTime/1000) { | 45 | if orderAll[i].SaleDate.Unix() >= (request.StartTime/1000) && orderAll[i].SaleDate.Unix() < (request.EndTime/1000) { |
@@ -206,20 +206,22 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r | @@ -206,20 +206,22 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r | ||
206 | OrderType: request.OrderType, | 206 | OrderType: request.OrderType, |
207 | OrderTypes: request.OrderTypes, | 207 | OrderTypes: request.OrderTypes, |
208 | } | 208 | } |
209 | + // 当月累计订单 | ||
210 | + d := time.Now() | ||
209 | if request.StartTime > 0 { | 211 | if request.StartTime > 0 { |
210 | queryOption.BeginTime = time.Unix(request.StartTime/1000, 0) | 212 | queryOption.BeginTime = time.Unix(request.StartTime/1000, 0) |
213 | + } else { | ||
214 | + queryOption.BeginTime = utils.GetFirstDateOfMonth(d) | ||
211 | } | 215 | } |
212 | if request.EndTime > 0 { | 216 | if request.EndTime > 0 { |
213 | queryOption.EndTime = time.Unix(request.EndTime/1000, 0) | 217 | queryOption.EndTime = time.Unix(request.EndTime/1000, 0) |
218 | + } else { | ||
219 | + queryOption.EndTime = utils.GetLastDateOfMonth(d) | ||
214 | } | 220 | } |
215 | // 今日订单 | 221 | // 今日订单 |
216 | if request.IsToday { | 222 | if request.IsToday { |
217 | - timeStr := time.Now().Format("2006-01-02") | ||
218 | - t, _ := time.Parse("2006-01-02", timeStr) | ||
219 | - beginTimeNum := t.Unix() | ||
220 | - endTimeNum := beginTimeNum + 86400 | ||
221 | - queryOption.BeginTime = time.Unix(beginTimeNum, 0) | ||
222 | - queryOption.EndTime = time.Unix(endTimeNum, 0) | 223 | + queryOption.BeginTime = utils.GetZeroTime(d) |
224 | + queryOption.EndTime = utils.GetEndTime(d) | ||
223 | } | 225 | } |
224 | total, orders, _ = OrderRepository.Find(utils.ObjectJsonToMap(queryOption)) | 226 | total, orders, _ = OrderRepository.Find(utils.ObjectJsonToMap(queryOption)) |
225 | if len(orders) != 0 { | 227 | if len(orders) != 0 { |
@@ -35,10 +35,10 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in | @@ -35,10 +35,10 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in | ||
35 | q.Where(`"order_base".order_type in (?)`, pg.In(option.OrderTypes)) | 35 | q.Where(`"order_base".order_type in (?)`, pg.In(option.OrderTypes)) |
36 | } | 36 | } |
37 | if option.BeginTime > 0 { | 37 | if option.BeginTime > 0 { |
38 | - q.Where(`"order_base".create_time >=?`, time.Unix(option.BeginTime/1000, 0)) | 38 | + q.Where(`"order_base".sale_date >=?`, time.Unix(option.BeginTime/1000, 0)) |
39 | } | 39 | } |
40 | if option.EndTime > 0 { | 40 | if option.EndTime > 0 { |
41 | - q.Where(`"order_base".create_time <?`, time.Unix(option.EndTime/1000, 0)) | 41 | + q.Where(`"order_base".sale_date <?`, time.Unix(option.EndTime/1000, 0)) |
42 | } | 42 | } |
43 | if option.PartnerCategoryId > 0 { | 43 | if option.PartnerCategoryId > 0 { |
44 | q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId) | 44 | q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId) |
@@ -13,3 +13,25 @@ func GetDayEnd() time.Time { | @@ -13,3 +13,25 @@ func GetDayEnd() time.Time { | ||
13 | nextDay := t.AddDate(0, 0, 1) | 13 | nextDay := t.AddDate(0, 0, 1) |
14 | return nextDay | 14 | return nextDay |
15 | } | 15 | } |
16 | + | ||
17 | +//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。 | ||
18 | +func GetFirstDateOfMonth(d time.Time) time.Time { | ||
19 | + d = d.AddDate(0, 0, -d.Day()+1) | ||
20 | + return GetZeroTime(d) | ||
21 | +} | ||
22 | + | ||
23 | +//获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。 | ||
24 | +func GetLastDateOfMonth(d time.Time) time.Time { | ||
25 | + d = GetFirstDateOfMonth(d).AddDate(0, 1, -1) | ||
26 | + return GetEndTime(d) | ||
27 | +} | ||
28 | + | ||
29 | +//获取某一天的0点时间 | ||
30 | +func GetZeroTime(d time.Time) time.Time { | ||
31 | + return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local) | ||
32 | +} | ||
33 | + | ||
34 | +//获取某一天的23点59分59秒 | ||
35 | +func GetEndTime(d time.Time) time.Time { | ||
36 | + return time.Date(d.Year(), d.Month(), d.Day(), 23, 59, 59, 0, time.Local) | ||
37 | +} |
-
请 注册 或 登录 后发表评论