|
|
package dividend
|
|
|
|
|
|
import (
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
//分红统计
|
|
|
func DividendStatistics(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsResponse, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
OrderResponsitory, _ = factory.CreateOrderRepository(transactionContext)
|
|
|
beginTime = time.Unix(request.StartTime/1000, 0)
|
|
|
endTime = time.Unix(request.EndTime/1000, 0)
|
|
|
)
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
if err != nil {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}
|
|
|
}()
|
|
|
_, orderAll, e := OrderResponsitory.Find(utils.ObjectJsonToMap(domain.OrderQueryOption{PartnerId: header.UserId, EndTime: time.Now(), SortByCreateTime: domain.DESC}))
|
|
|
if e != nil {
|
|
|
log.Error(e, beginTime, endTime)
|
|
|
}
|
|
|
var orderBetween []*domain.Order
|
|
|
for i := range orderAll {
|
|
|
if orderAll[i].CreateAt.After(beginTime) && orderAll[i].CreateAt.Before(endTime) {
|
|
|
orderBetween = append(orderBetween, orderAll[i])
|
|
|
}
|
|
|
}
|
|
|
bonusAll := AllBonusStatics(orderAll, request.DividendAction)
|
|
|
bonusQuarters := QuartersBonusStatics(orderBetween, request.DividendAction)
|
|
|
rsp = &protocol.DividendStatisticsResponse{}
|
|
|
rsp.Statistics = protocol.DividendStatistics{
|
|
|
Received: bonusAll.Received,
|
|
|
Outstanding: bonusAll.Outstanding,
|
|
|
Quarters: bonusQuarters,
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//累计分红
|
|
|
func AllBonusStatics(orders []*domain.Order, action int) (bonus protocol.Bonus) {
|
|
|
bonus = protocol.Bonus{}
|
|
|
for i := range orders {
|
|
|
o := orders[i]
|
|
|
if action == protocol.BonusTotal {
|
|
|
bonus.Received += o.OrderBonusReceive()
|
|
|
bonus.Outstanding += o.OrderBonusWait()
|
|
|
}
|
|
|
if action == protocol.BonusOutstanding {
|
|
|
bonus.Outstanding += o.OrderBonusOutstanding()
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//订单-季度分红统计
|
|
|
func QuartersBonusStatics(orders []*domain.Order, action int) (bonus []protocol.Bonus) {
|
|
|
bonus = make([]protocol.Bonus, 4)
|
|
|
for i := range orders {
|
|
|
o := orders[i]
|
|
|
quarter := o.CreateAt.Month() / 4
|
|
|
if action == protocol.BonusTotal {
|
|
|
bonus[quarter].Received += o.OrderBonusReceive()
|
|
|
bonus[quarter].Outstanding += o.OrderBonusWait()
|
|
|
}
|
|
|
if action == protocol.BonusOutstanding {
|
|
|
bonus[quarter].Outstanding += o.OrderBonusOutstanding()
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//分红订单
|
|
|
func DividendOrders(header *protocol.RequestHeader, request *protocol.DividendOrdersRequest) (rsp *protocol.DividendOrdersResponse, err error) {
|
|
|
var ()
|
|
|
rsp = &protocol.DividendOrdersResponse{}
|
|
|
return
|
|
|
} |
...
|
...
|
|