作者 陈志颖

fix:修复订单以及分红统计时间范围

@@ -230,13 +230,13 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r @@ -230,13 +230,13 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r
230 if request.EndTime > 0 { 230 if request.EndTime > 0 {
231 queryOption.EndTime = time.Unix(request.EndTime/1000, 0) 231 queryOption.EndTime = time.Unix(request.EndTime/1000, 0)
232 } else { 232 } else {
233 - queryOption.EndTime = utils.GetLastDateOfMonth(d) 233 + queryOption.EndTime = utils.GetNextMonthFirstDay(d)
234 } 234 }
235 235
236 // 今日新增实发订单 236 // 今日新增实发订单
237 if request.IsToday { 237 if request.IsToday {
238 queryOption.BeginTime = utils.GetZeroTime(d) 238 queryOption.BeginTime = utils.GetZeroTime(d)
239 - queryOption.EndTime = utils.GetEndTime(d) 239 + queryOption.EndTime = utils.GetNextDayZeroTime(d)
240 } 240 }
241 total, orders, _ = OrderRepository.Find(utils.ObjectJsonToMap(queryOption)) 241 total, orders, _ = OrderRepository.Find(utils.ObjectJsonToMap(queryOption))
242 if len(orders) != 0 { 242 if len(orders) != 0 {
@@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
9 - "time"  
10 ) 9 )
11 10
12 // 订单统计 11 // 订单统计
@@ -25,7 +24,7 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist @@ -25,7 +24,7 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist
25 24
26 //事业分红/业务分红 25 //事业分红/业务分红
27 var total float64 26 var total float64
28 - if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career)}); e == nil { 27 + if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career), EndTime: utils.GetDayEnd().Unix() * 1000}); e == nil {
29 total += bonus.Bonus 28 total += bonus.Bonus
30 } 29 }
31 calcOrderStatic := func(catId int, total float64) protocol.OrderStatic { 30 calcOrderStatic := func(catId int, total float64) protocol.OrderStatic {
@@ -37,12 +36,13 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist @@ -37,12 +36,13 @@ func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatist
37 PartnerCategoryId: catId, 36 PartnerCategoryId: catId,
38 }) 37 })
39 cumulativeQuantity, cumulativeMoney, _ := OrderDao.OrderStatics(&domain.OrderStaticQuery{ 38 cumulativeQuantity, cumulativeMoney, _ := OrderDao.OrderStatics(&domain.OrderStaticQuery{
40 - EndTime: time.Now().Unix() * 1000, 39 + //EndTime: time.Now().Unix() * 1000,
  40 + EndTime: utils.GetDayEnd().Unix() * 1000,
41 OrderTypes: domain.UserOrderTypes(domain.Career), 41 OrderTypes: domain.UserOrderTypes(domain.Career),
42 PartnerId: request.PartnerId, 42 PartnerId: request.PartnerId,
43 PartnerCategoryId: catId, 43 PartnerCategoryId: catId,
44 }) 44 })
45 - bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: catId}) 45 + bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: catId, EndTime: utils.GetDayEnd().Unix() * 1000})
46 var percent float64 = 0 46 var percent float64 = 0
47 if bonus.Bonus != 0 { 47 if bonus.Bonus != 0 {
48 percent = utils.DecimalToNumber(bonus.Bonus * 100 / total) 48 percent = utils.DecimalToNumber(bonus.Bonus * 100 / total)
@@ -32,6 +32,7 @@ type OrderBonusQuery struct { @@ -32,6 +32,7 @@ type OrderBonusQuery struct {
32 OrderType int `json:"orderType,omitempty"` 32 OrderType int `json:"orderType,omitempty"`
33 OrderTypes []int `json:"orderTypes,omitempty"` 33 OrderTypes []int `json:"orderTypes,omitempty"`
34 PartnerCategoryId int `json:"partnerCategoryId,omitempty"` //订单所属类型 34 PartnerCategoryId int `json:"partnerCategoryId,omitempty"` //订单所属类型
  35 + EndTime int64 `json:"endTime,omitempty"`
35 //IsGroupByPartnerCategoryId bool `json:"isGroupByPartnerCategoryId,omitempty"` 36 //IsGroupByPartnerCategoryId bool `json:"isGroupByPartnerCategoryId,omitempty"`
36 } 37 }
37 38
@@ -82,6 +82,9 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d @@ -82,6 +82,9 @@ func (dao *OrderBaseDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp d
82 if option.PartnerCategoryId > 0 { 82 if option.PartnerCategoryId > 0 {
83 q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId) 83 q.Where(`"order_base".partner_category @>'{"id":?}'`, option.PartnerCategoryId)
84 } 84 }
  85 + if option.EndTime > 0 {
  86 + q.Where(`"order_base".sale_date <?`, time.Unix(option.EndTime/1000, 0))
  87 + }
85 //if option.IsGroupByPartnerCategoryId{ 88 //if option.IsGroupByPartnerCategoryId{
86 // q.Group(`partner_category`) 89 // q.Group(`partner_category`)
87 //} 90 //}
@@ -21,9 +21,9 @@ func GetFirstDateOfMonth(d time.Time) time.Time { @@ -21,9 +21,9 @@ func GetFirstDateOfMonth(d time.Time) time.Time {
21 } 21 }
22 22
23 //获取传入的时间所在月份的最后一天,即某月最后一天的23:59:59。如传入time.Now(), 返回当前月份的最后一天的23:59:59。 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) 24 +func GetNextMonthFirstDay(d time.Time) time.Time {
  25 + d = GetFirstDateOfMonth(d).AddDate(0, 1, 0)
  26 + return GetZeroTime(d)
27 } 27 }
28 28
29 //获取某一天的0点时间 29 //获取某一天的0点时间
@@ -32,6 +32,6 @@ func GetZeroTime(d time.Time) time.Time { @@ -32,6 +32,6 @@ func GetZeroTime(d time.Time) time.Time {
32 } 32 }
33 33
34 //获取某一天的23点59分59秒 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) 35 +func GetNextDayZeroTime(d time.Time) time.Time {
  36 + return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, 1)
37 } 37 }