作者 陈志颖

feat:修改分红统计时间

... ... @@ -9,6 +9,7 @@ import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/company"
userx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/user"
"time"
)
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
log.Error(err)
return
}
if request.PageIndex == 0 {
rsp.Timestamp = time.Now().Unix() * 1000
}
if rsp.Partners == nil {
rsp.Partners = []struct{}{}
}
... ...
... ... @@ -24,13 +24,13 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
}()
// 事业分红统计-查询订单
_, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: request.PartnerId, EndTime: time.Now(), SortByCreateTime: domain.DESC, OrderTypes: domain.UserOrderTypes(domain.Career)}))
_, orderAll, e := OrderBaseResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: request.PartnerId, EndTime: time.Now(), SortBySalesTime: domain.DESC, OrderTypes: domain.UserOrderTypes(domain.Career)}))
if e != nil {
log.Error(e)
}
var orderBetween []*domain.OrderBase
for i := range orderAll {
if orderAll[i].CreateTime.Unix() >= (request.StartTime/1000) && orderAll[i].CreateTime.Unix() < (request.EndTime/1000) {
if orderAll[i].SaleDate.Unix() >= (request.StartTime/1000) && orderAll[i].SaleDate.Unix() < (request.EndTime/1000) {
orderBetween = append(orderBetween, orderAll[i])
}
}
... ... @@ -59,6 +59,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
Receivable: bonusAll.Receivable,
Quarters: bonusQuarters,
}
if request.PageIndex == 0 {
rsp.Timestamp = time.Now().Unix() * 1000
}
err = transactionContext.CommitTransaction()
return
... ... @@ -82,7 +85,7 @@ func QuartersBonusStatics(orders []*domain.OrderBase, action int) (bonus []proto
bonus = make([]protocol.Bonus, 4)
for i := range orders {
o := orders[i]
quarter := quarter(o.CreateTime)
quarter := quarter(o.SaleDate)
static := o.OrderBonusStatic()
bonus[quarter].Receivable = utils.Decimal(bonus[quarter].Receivable + static.OrderTotalReceivable())
bonus[quarter].Received = utils.Decimal(bonus[quarter].Received + static.OrderBonusReceive())
... ... @@ -124,17 +127,18 @@ func OrderList(header *protocol.RequestHeader, request *protocol.DividendOrdersR
rsp = &protocol.DividendOrdersResponse{List: make([]*protocol.DividendOrderListItem, 0)}
count, orders, err = OrderDao.DividendOrders(&domain.DividendOrdersQueryOption{
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
DetailAction: request.DetailAction,
DividendAction: request.DividendAction,
StartTime: request.StartTime,
EndTime: request.EndTime,
Offset: request.PageIndex * request.PageSize,
Limit: request.PageSize,
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
DetailAction: request.DetailAction,
DividendAction: request.DividendAction,
StartTime: request.StartTime,
EndTime: request.EndTime,
Offset: request.PageIndex * request.PageSize,
Limit: request.PageSize,
//SortByUpdateTime: domain.DESC,
SortByCreateTime: domain.DESC,
JoinWays: request.JoinWays,
//SortByCreateTime: domain.DESC,
SortBySalesTime: domain.DESC,
JoinWays: request.JoinWays,
})
if err != nil {
return
... ...
... ... @@ -159,6 +159,7 @@ type OrderQueryOption struct {
//IsDisable string `json:"isDisable,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
SortBySalesTime string `json:"sortBySalesTime,omitempty"`
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
PartnerCategoryId int `json:"partnerCategoryId,omitempty"`
... ... @@ -177,6 +178,7 @@ type DividendOrdersQueryOption struct {
Limit int `json:"limit,omitempty"`
SortByUpdateTime string `json:"sortByUpdateTime,omitempty"`
SortByCreateTime string `json:"sortByCreateTime,omitempty"`
SortBySalesTime string `json:"sortBySalesTime,omitempty"`
JoinWays []*company.JoinWays `json:"joinWays,omitempty"` // 合伙类型
}
... ...
... ... @@ -105,10 +105,10 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption
q.Where(`"order_base".partner_id=?`, option.PartnerId)
}
if option.StartTime > 0 {
q.Where(`"order_base".create_time >=?`, time.Unix(option.StartTime/1000, 0))
q.Where(`"order_base".sale_date >=?`, time.Unix(option.StartTime/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 len(option.JoinWays) > 0 {
var joinWays []int64
... ... @@ -150,6 +150,9 @@ func (dao *OrderBaseDao) DividendOrders(option *domain.DividendOrdersQueryOption
if len(option.SortByCreateTime) > 0 {
q.Order(fmt.Sprintf("order_base.create_time %v", option.SortByCreateTime))
}
if len(option.SortBySalesTime) > 0 {
q.Order(fmt.Sprintf("order_base.sale_date %v", option.SortBySalesTime))
}
count, err = q.Distinct().SelectAndCount()
for i := range orders {
var domainOrder *domain.OrderBase
... ...
... ... @@ -84,7 +84,8 @@ func (repository *OrderBaseRepository) Find(queryOptions map[string]interface{})
//SetWhere(`"order_base".is_disable = ?`, "isDisable").
SetLimit().
SetOrder(`order_base.create_time`, "sortByCreateTime").
SetOrder(`order_base.update_time`, "sortByUpdateTime")
SetOrder(`order_base.update_time`, "sortByUpdateTime").
SetOrder(`order_base.sale_date`, "sortBySalesTime")
if v, ok := queryOptions["orderTypes"]; ok {
query.Where(`"order_base".order_type in (?)`, pg.In(v))
}
... ...
... ... @@ -2,5 +2,6 @@ package company
type PartnersResponse struct {
// 唯一标识
Partners interface{} `json:"partners"`
Partners interface{} `json:"partners"`
Timestamp int64 `json:"timestamp"`
}
... ...
... ... @@ -14,9 +14,11 @@ type DividendStatisticsRequest struct {
//分红类型(0累计分红、1分红支出)
//DividendAction int `json:"dividendAction"`
PartnerId int64 `json:"partnerId"`
PageIndex int `json:"pageIndex"`
}
type DividendStatisticsResponse struct {
Statistics DividendStatistics `json:"statistics"`
Timestamp int64 `json:"timestamp"`
}
type DividendStatistics struct {
... ... @@ -41,7 +43,7 @@ type DividendOrdersRequest struct {
EndTime int64 `json:"endTime" valid:"Required"`
// 合作类型(空或不传,即所有类型)
JoinWays []*company.JoinWays `json:"joinWays"`
JoinWays []*company.JoinWays `json:"joinWays"`
PageIndex int `json:"pageIndex,omitempty"`
PageSize int `json:"pageSize,omitempty"`
... ...