作者 陈志颖

feat:修改分红统计时间

@@ -9,6 +9,7 @@ import ( @@ -9,6 +9,7 @@ import (
9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
10 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company" 10 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company"
11 userx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/user" 11 userx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/user"
  12 + "time"
12 ) 13 )
13 14
14 func PartnersV2(header *protocol.RequestHeader, request *protocolx.PartnersRequest) (rsp *protocolx.PartnersResponse, err error) { 15 func PartnersV2(header *protocol.RequestHeader, request *protocolx.PartnersRequest) (rsp *protocolx.PartnersResponse, err error) {
@@ -27,6 +28,9 @@ func PartnersV2(header *protocol.RequestHeader, request *protocolx.PartnersReque @@ -27,6 +28,9 @@ func PartnersV2(header *protocol.RequestHeader, request *protocolx.PartnersReque
27 log.Error(err) 28 log.Error(err)
28 return 29 return
29 } 30 }
  31 + if request.PageIndex == 0 {
  32 + rsp.Timestamp = time.Now().Unix() * 1000
  33 + }
30 if rsp.Partners == nil { 34 if rsp.Partners == nil {
31 rsp.Partners = []struct{}{} 35 rsp.Partners = []struct{}{}
32 } 36 }
@@ -24,13 +24,13 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis @@ -24,13 +24,13 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
24 }() 24 }()
25 25
26 // 事业分红统计-查询订单 26 // 事业分红统计-查询订单
27 - _, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: request.PartnerId, EndTime: time.Now(), SortByCreateTime: domain.DESC, OrderTypes: domain.UserOrderTypes(domain.Career)})) 27 + _, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: request.PartnerId, EndTime: time.Now(), SortBySalesTime: domain.DESC, OrderTypes: domain.UserOrderTypes(domain.Career)}))
28 if e != nil { 28 if e != nil {
29 log.Error(e) 29 log.Error(e)
30 } 30 }
31 var orderBetween []*domain.OrderBase 31 var orderBetween []*domain.OrderBase
32 for i := range orderAll { 32 for i := range orderAll {
33 - if orderAll[i].CreateTime.Unix() >= (request.StartTime/1000) && orderAll[i].CreateTime.Unix() < (request.EndTime/1000) { 33 + if orderAll[i].SaleDate.Unix() >= (request.StartTime/1000) && orderAll[i].SaleDate.Unix() < (request.EndTime/1000) {
34 orderBetween = append(orderBetween, orderAll[i]) 34 orderBetween = append(orderBetween, orderAll[i])
35 } 35 }
36 } 36 }
@@ -59,6 +59,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis @@ -59,6 +59,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
59 Receivable: bonusAll.Receivable, 59 Receivable: bonusAll.Receivable,
60 Quarters: bonusQuarters, 60 Quarters: bonusQuarters,
61 } 61 }
  62 + if request.PageIndex == 0 {
  63 + rsp.Timestamp = time.Now().Unix() * 1000
  64 + }
62 65
63 err = transactionContext.CommitTransaction() 66 err = transactionContext.CommitTransaction()
64 return 67 return
@@ -82,7 +85,7 @@ func QuartersBonusStatics(orders []*domain.OrderBase, action int) (bonus []proto @@ -82,7 +85,7 @@ func QuartersBonusStatics(orders []*domain.OrderBase, action int) (bonus []proto
82 bonus = make([]protocol.Bonus, 4) 85 bonus = make([]protocol.Bonus, 4)
83 for i := range orders { 86 for i := range orders {
84 o := orders[i] 87 o := orders[i]
85 - quarter := quarter(o.CreateTime) 88 + quarter := quarter(o.SaleDate)
86 static := o.OrderBonusStatic() 89 static := o.OrderBonusStatic()
87 bonus[quarter].Receivable = utils.Decimal(bonus[quarter].Receivable + static.OrderTotalReceivable()) 90 bonus[quarter].Receivable = utils.Decimal(bonus[quarter].Receivable + static.OrderTotalReceivable())
88 bonus[quarter].Received = utils.Decimal(bonus[quarter].Received + static.OrderBonusReceive()) 91 bonus[quarter].Received = utils.Decimal(bonus[quarter].Received + static.OrderBonusReceive())
@@ -124,17 +127,18 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR @@ -124,17 +127,18 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
124 rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)} 127 rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
125 128
126 count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{ 129 count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{
127 - OrderTypes: domain.UserOrderTypes(domain.Career),  
128 - PartnerId: request.PartnerId,  
129 - DetailAction: request.DetailAction,  
130 - DividendAction: request.DividendAction,  
131 - StartTime: request.StartTime,  
132 - EndTime: request.EndTime,  
133 - Offset: request.PageIndex * request.PageSize,  
134 - Limit: request.PageSize, 130 + OrderTypes: domain.UserOrderTypes(domain.Career),
  131 + PartnerId: request.PartnerId,
  132 + DetailAction: request.DetailAction,
  133 + DividendAction: request.DividendAction,
  134 + StartTime: request.StartTime,
  135 + EndTime: request.EndTime,
  136 + Offset: request.PageIndex * request.PageSize,
  137 + Limit: request.PageSize,
135 //SortByUpdateTime: domain.DESC, 138 //SortByUpdateTime: domain.DESC,
136 - SortByCreateTime: domain.DESC,  
137 - JoinWays: request.JoinWays, 139 + //SortByCreateTime: domain.DESC,
  140 + SortBySalesTime: domain.DESC,
  141 + JoinWays: request.JoinWays,
138 }) 142 })
139 if err != nil { 143 if err != nil {
140 return 144 return
@@ -159,6 +159,7 @@ type OrderQueryOption struct { @@ -159,6 +159,7 @@ type OrderQueryOption struct {
159 //IsDisable string `json:"isDisable,omitempty"` 159 //IsDisable string `json:"isDisable,omitempty"`
160 SortByCreateTime string `json:"sortByCreateTime,omitempty"` 160 SortByCreateTime string `json:"sortByCreateTime,omitempty"`
161 SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` 161 SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
  162 + SortBySalesTime string `json:"sortBySalesTime,omitempty"`
162 Offset int `json:"offset,omitempty"` 163 Offset int `json:"offset,omitempty"`
163 Limit int `json:"limit,omitempty"` 164 Limit int `json:"limit,omitempty"`
164 PartnerCategoryId int `json:"partnerCategoryId,omitempty"` 165 PartnerCategoryId int `json:"partnerCategoryId,omitempty"`
@@ -177,6 +178,7 @@ type DividendOrdersQueryOption struct { @@ -177,6 +178,7 @@ type DividendOrdersQueryOption struct {
177 Limit int `json:"limit,omitempty"` 178 Limit int `json:"limit,omitempty"`
178 SortByUpdateTime string `json:"sortByUpdateTime,omitempty"` 179 SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
179 SortByCreateTime string `json:"sortByCreateTime,omitempty"` 180 SortByCreateTime string `json:"sortByCreateTime,omitempty"`
  181 + SortBySalesTime string `json:"sortBySalesTime,omitempty"`
180 JoinWays []*company.JoinWays `json:"joinWays,omitempty"` // 合伙类型 182 JoinWays []*company.JoinWays `json:"joinWays,omitempty"` // 合伙类型
181 } 183 }
182 184
@@ -105,10 +105,10 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption @@ -105,10 +105,10 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption
105 q.Where(`"order_base".partner_id=?`, option.PartnerId) 105 q.Where(`"order_base".partner_id=?`, option.PartnerId)
106 } 106 }
107 if option.StartTime > 0 { 107 if option.StartTime > 0 {
108 - q.Where(`"order_base".create_time >=?`, time.Unix(option.StartTime/1000, 0)) 108 + q.Where(`"order_base".sale_date >=?`, time.Unix(option.StartTime/1000, 0))
109 } 109 }
110 if option.EndTime > 0 { 110 if option.EndTime > 0 {
111 - q.Where(`"order_base".create_time <?`, time.Unix(option.EndTime/1000, 0)) 111 + q.Where(`"order_base".sale_date <?`, time.Unix(option.EndTime/1000, 0))
112 } 112 }
113 if len(option.JoinWays) > 0 { 113 if len(option.JoinWays) > 0 {
114 var joinWays []int64 114 var joinWays []int64
@@ -150,6 +150,9 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption @@ -150,6 +150,9 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption
150 if len(option.SortByCreateTime) > 0 { 150 if len(option.SortByCreateTime) > 0 {
151 q.Order(fmt.Sprintf("order_base.create_time %v", option.SortByCreateTime)) 151 q.Order(fmt.Sprintf("order_base.create_time %v", option.SortByCreateTime))
152 } 152 }
  153 + if len(option.SortBySalesTime) > 0 {
  154 + q.Order(fmt.Sprintf("order_base.sale_date %v", option.SortBySalesTime))
  155 + }
153 count, err = q.Distinct().SelectAndCount() 156 count, err = q.Distinct().SelectAndCount()
154 for i := range orders { 157 for i := range orders {
155 var domainOrder *domain.OrderBase 158 var domainOrder *domain.OrderBase
@@ -84,7 +84,8 @@ func (repository *OrderBaseRepository) Find(queryOptions map[string]interface{}) @@ -84,7 +84,8 @@ func (repository *OrderBaseRepository) Find(queryOptions map[string]interface{})
84 //SetWhere(`"order_base".is_disable = ?`, "isDisable"). 84 //SetWhere(`"order_base".is_disable = ?`, "isDisable").
85 SetLimit(). 85 SetLimit().
86 SetOrder(`order_base.create_time`, "sortByCreateTime"). 86 SetOrder(`order_base.create_time`, "sortByCreateTime").
87 - SetOrder(`order_base.update_time`, "sortByUpdateTime") 87 + SetOrder(`order_base.update_time`, "sortByUpdateTime").
  88 + SetOrder(`order_base.sale_date`, "sortBySalesTime")
88 if v, ok := queryOptions["orderTypes"]; ok { 89 if v, ok := queryOptions["orderTypes"]; ok {
89 query.Where(`"order_base".order_type in (?)`, pg.In(v)) 90 query.Where(`"order_base".order_type in (?)`, pg.In(v))
90 } 91 }
@@ -2,5 +2,6 @@ package company @@ -2,5 +2,6 @@ package company
2 2
3 type PartnersResponse struct { 3 type PartnersResponse struct {
4 // 唯一标识 4 // 唯一标识
5 - Partners interface{} `json:"partners"` 5 + Partners interface{} `json:"partners"`
  6 + Timestamp int64 `json:"timestamp"`
6 } 7 }
@@ -14,9 +14,11 @@ type DividendStatisticsRequest struct { @@ -14,9 +14,11 @@ type DividendStatisticsRequest struct {
14 //分红类型(0累计分红、1分红支出) 14 //分红类型(0累计分红、1分红支出)
15 //DividendAction int `json:"dividendAction"` 15 //DividendAction int `json:"dividendAction"`
16 PartnerId int64 `json:"partnerId"` 16 PartnerId int64 `json:"partnerId"`
  17 + PageIndex int `json:"pageIndex"`
17 } 18 }
18 type DividendStatisticsResponse struct { 19 type DividendStatisticsResponse struct {
19 Statistics DividendStatistics `json:"statistics"` 20 Statistics DividendStatistics `json:"statistics"`
  21 + Timestamp int64 `json:"timestamp"`
20 } 22 }
21 23
22 type DividendStatistics struct { 24 type DividendStatistics struct {
@@ -41,7 +43,7 @@ type DividendOrdersRequest struct { @@ -41,7 +43,7 @@ type DividendOrdersRequest struct {
41 EndTime int64 `json:"endTime" valid:"Required"` 43 EndTime int64 `json:"endTime" valid:"Required"`
42 44
43 // 合作类型(空或不传,即所有类型) 45 // 合作类型(空或不传,即所有类型)
44 - JoinWays []*company.JoinWays `json:"joinWays"` 46 + JoinWays []*company.JoinWays `json:"joinWays"`
45 47
46 PageIndex int `json:"pageIndex,omitempty"` 48 PageIndex int `json:"pageIndex,omitempty"`
47 PageSize int `json:"pageSize,omitempty"` 49 PageSize int `json:"pageSize,omitempty"`