作者 陈志颖

fix:修复累计订单时间选择问题

... ... @@ -32,14 +32,14 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
t := time.Now()
last := time.Date(t.Year(), time.December, 31, 23, 59, 59, 0, time.Local)
first := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.Local)
fmt.Print("First:", first, "\n")
fmt.Print("Last:", last, "\n")
if request.StartTime == 0 {
request.StartTime = first.Unix() * 1000
}
if request.EndTime == 0 {
request.EndTime = last.Unix() * 1000
}
fmt.Print("StartTime: ", request.StartTime, "\n")
fmt.Print("EndTime: ", request.EndTime, "\n")
var orderBetween []*domain.OrderBase
for i := range orderAll {
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
OrderType: request.OrderType,
OrderTypes: request.OrderTypes,
}
// 当月累计订单
d := time.Now()
if request.StartTime > 0 {
queryOption.BeginTime = time.Unix(request.StartTime/1000, 0)
} else {
queryOption.BeginTime = utils.GetFirstDateOfMonth(d)
}
if request.EndTime > 0 {
queryOption.EndTime = time.Unix(request.EndTime/1000, 0)
} else {
queryOption.EndTime = utils.GetLastDateOfMonth(d)
}
// 今日订单
if request.IsToday {
timeStr := time.Now().Format("2006-01-02")
t, _ := time.Parse("2006-01-02", timeStr)
beginTimeNum := t.Unix()
endTimeNum := beginTimeNum + 86400
queryOption.BeginTime = time.Unix(beginTimeNum, 0)
queryOption.EndTime = time.Unix(endTimeNum, 0)
queryOption.BeginTime = utils.GetZeroTime(d)
queryOption.EndTime = utils.GetEndTime(d)
}
total, orders, _ = OrderRepository.Find(utils.ObjectJsonToMap(queryOption))
if len(orders) != 0 {
... ...
... ... @@ -35,10 +35,10 @@ func (dao *OrderBaseDao) OrderStatics(option *domain.OrderStaticQuery) (count in
q.Where(`"order_base".order_type in (?)`, pg.In(option.OrderTypes))
}
if option.BeginTime > 0 {
q.Where(`"order_base".create_time >=?`, time.Unix(option.BeginTime/1000, 0))
q.Where(`"order_base".sale_date >=?`, time.Unix(option.BeginTime/1000, 0))
}
if option.EndTime > 0 {
q.Where(`"order_base".create_time <?`, time.Unix(option.EndTime/1000, 0))
q.Where(`"order_base".sale_date <?`, time.Unix(option.EndTime/1000, 0))
}
if option.PartnerCategoryId > 0 {
q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId)
... ...
... ... @@ -13,3 +13,25 @@ func GetDayEnd() time.Time {
nextDay := t.AddDate(0, 0, 1)
return nextDay
}
//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。
func GetFirstDateOfMonth(d time.Time) time.Time {
d = d.AddDate(0, 0, -d.Day()+1)
return GetZeroTime(d)
}
//获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。
func GetLastDateOfMonth(d time.Time) time.Time {
d = GetFirstDateOfMonth(d).AddDate(0, 1, -1)
return GetEndTime(d)
}
//获取某一天的0点时间
func GetZeroTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local)
}
//获取某一天的23点59分59秒
func GetEndTime(d time.Time) time.Time {
return time.Date(d.Year(), d.Month(), d.Day(), 23, 59, 59, 0, time.Local)
}
... ...