...
|
...
|
@@ -38,6 +38,7 @@ func Detail(header *protocol.RequestHeader, request *protocol.OrderDetailRequest |
|
|
OrderStatus: orderStatus(order),
|
|
|
CreateTime: order.CreateTime.Unix() * 1000,
|
|
|
UpdateTime: order.UpdateTime.Unix() * 1000,
|
|
|
SalesTime: order.SaleDate.Unix() * 1000,
|
|
|
OrderDistrict: map[string]interface{}{"id": order.RegionInfo.RegionId, "name": order.RegionInfo.RegionName},
|
|
|
Customer: protocol.Customer{Uname: order.Buyer.BuyerName, Phone: order.Buyer.ContactInfo},
|
|
|
Products: orderProducts(order),
|
...
|
...
|
@@ -119,6 +120,13 @@ func orderTotalStatic(order *domain.OrderBase) interface{} { |
|
|
return item
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description // 订单统计
|
|
|
* @Date 18:14 2021/1/28
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
// 订单统计
|
|
|
func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) {
|
|
|
var (
|
...
|
...
|
@@ -126,15 +134,18 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic |
|
|
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
|
|
|
BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext)
|
|
|
)
|
|
|
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
rsp = &protocol.OrderStatisticsResponse{Statistics: &protocol.OrderStatics{}}
|
|
|
|
|
|
// 当天订单/累计订单
|
|
|
// 今日新增实发订单
|
|
|
if rsp.Statistics.TodayRealQuantity, rsp.Statistics.TodayRealMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
|
|
|
BeginTime: utils.GetDayBegin().Unix() * 1000,
|
|
|
EndTime: utils.GetDayEnd().Unix() * 1000,
|
...
|
...
|
@@ -143,19 +154,23 @@ func Statistics(header *protocol.RequestHeader, request *protocol.OrderStatistic |
|
|
}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 累计实发订单
|
|
|
if rsp.Statistics.CumulativeQuantity, rsp.Statistics.CumulativeMoney, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
|
|
|
EndTime: time.Now().Unix() * 1000,
|
|
|
//EndTime: time.Now().Unix() * 1000,
|
|
|
EndTime: utils.GetDayEnd().Unix() * 1000, // 累计到今天最后一刻
|
|
|
OrderTypes: domain.UserOrderTypes(domain.Career),
|
|
|
PartnerId: header.UserId,
|
|
|
}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
rsp.Statistics.TodayRealMoney = utils.Decimal(rsp.Statistics.TodayRealMoney)
|
|
|
rsp.Statistics.CumulativeMoney = utils.Decimal(rsp.Statistics.CumulativeMoney)
|
|
|
|
|
|
//事业分红/业务分红
|
|
|
var careerBonus, businessBonus, total float64 //,developBonus,appBonus
|
|
|
if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: header.UserId, OrderTypes: domain.UserOrderTypes(domain.Career)}); e == nil {
|
|
|
if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: header.UserId, OrderTypes: domain.UserOrderTypes(domain.Career), EndTime: utils.GetDayEnd().Unix() * 1000}); e == nil {
|
|
|
careerBonus = bonus.Bonus
|
|
|
total += careerBonus
|
|
|
}
|
...
|
...
|
@@ -195,20 +210,39 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r |
|
|
|
|
|
// 查询订单列表
|
|
|
queryOption := &domain.OrderQueryOption{
|
|
|
Limit: request.PageSize,
|
|
|
Offset: request.PageSize * request.PageIndex,
|
|
|
Limit: request.PageSize,
|
|
|
Offset: request.PageSize * request.PageIndex,
|
|
|
//SortByUpdateTime: domain.DESC,
|
|
|
SortByCreateTime: domain.DESC,
|
|
|
//SortByCreateTime: domain.DESC,
|
|
|
SortBySalesTime: domain.DESC,
|
|
|
PartnerId: request.PartnerId,
|
|
|
PartnerCategoryId: request.JoinWay,
|
|
|
OrderType: request.OrderType,
|
|
|
OrderTypes: request.OrderTypes,
|
|
|
}
|
|
|
if request.StartTime > 0 {
|
|
|
// 当月累计实发订单
|
|
|
d := time.Now()
|
|
|
if request.StartTime > 0 { // 开始时间处理
|
|
|
queryOption.BeginTime = time.Unix(request.StartTime/1000, 0)
|
|
|
} else { // 开始时间为0,默认从这个月初开始
|
|
|
queryOption.BeginTime = utils.GetFirstDateOfMonth(d)
|
|
|
}
|
|
|
if request.EndTime > 0 {
|
|
|
|
|
|
if request.EndTime > 0 { // 结束时间处理,判断时间是否超过今天
|
|
|
currentDayEnd := utils.GetDayEnd().Unix() * 1000
|
|
|
if request.EndTime >= currentDayEnd {
|
|
|
request.EndTime = currentDayEnd
|
|
|
}
|
|
|
queryOption.EndTime = time.Unix(request.EndTime/1000, 0)
|
|
|
} else { // 请求结束时间为0,默认到今天结束
|
|
|
//queryOption.EndTime = utils.GetNextMonthFirstDay(d)
|
|
|
queryOption.EndTime = utils.GetDayEnd()
|
|
|
}
|
|
|
|
|
|
// 今日新增实发订单
|
|
|
if request.IsToday {
|
|
|
queryOption.BeginTime = utils.GetZeroTime(d)
|
|
|
queryOption.EndTime = utils.GetNextDayZeroTime(d)
|
|
|
}
|
|
|
total, orders, _ = OrderRepository.Find(utils.ObjectJsonToMap(queryOption))
|
|
|
if len(orders) != 0 {
|
...
|
...
|
@@ -222,19 +256,21 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 【特殊处理1】 查询第0页时,需要查询累计实发订单数
|
|
|
// 【特殊处理1】 查询第0页时,需要查询累计实发订单数,并下发时间戳
|
|
|
if request.PageIndex == 0 {
|
|
|
var (
|
|
|
cumulativeQuantity int
|
|
|
)
|
|
|
cumulativeQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
|
|
|
EndTime: time.Now().Unix() * 1000,
|
|
|
EndTime: utils.GetDayEnd().Unix() * 1000,
|
|
|
OrderTypes: domain.UserOrderTypes(domain.Career),
|
|
|
PartnerId: request.PartnerId,
|
|
|
PartnerCategoryId: request.JoinWay,
|
|
|
})
|
|
|
rsp.Total = cumulativeQuantity
|
|
|
rsp.Timestamp = time.Now().Unix() * 1000
|
|
|
}
|
|
|
|
|
|
//【特殊处理2】 今天累计数量特殊处理 当前查询时间段内所有订单总数(复用rsp.Total字段)
|
|
|
if request.StartTime > 0 && request.EndTime > 0 {
|
|
|
zero := time.Time(xtime.XTime(time.Now()).DayBefore(0)).Unix()
|
...
|
...
|
@@ -243,23 +279,39 @@ func List(header *protocol.RequestHeader, request *protocol.OrderListRequest) (r |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 【特殊处理3】今日新增实发订单统计
|
|
|
if request.IsToday {
|
|
|
var (
|
|
|
todayQuantity int
|
|
|
)
|
|
|
todayQuantity, _, err = OrderDao.OrderStatics(&domain.OrderStaticQuery{
|
|
|
BeginTime: queryOption.BeginTime.Unix() * 1000,
|
|
|
EndTime: queryOption.EndTime.Unix() * 1000,
|
|
|
OrderTypes: domain.UserOrderTypes(domain.Career),
|
|
|
PartnerId: request.PartnerId,
|
|
|
PartnerCategoryId: request.JoinWay,
|
|
|
})
|
|
|
rsp.Total = todayQuantity
|
|
|
}
|
|
|
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
func DomainOrderToOrderListItem(order *domain.OrderBase) *protocol.OrderListItem {
|
|
|
bonusStatic := order.OrderBonusStatic()
|
|
|
return &protocol.OrderListItem{
|
|
|
Id: order.Id,
|
|
|
OrderType: order.OrderType,
|
|
|
OrderNo: order.OrderCode,
|
|
|
DeliveryNo: order.DeliveryCode,
|
|
|
OrderDistrict: map[string]interface{}{
|
|
|
"id": order.RegionInfo.RegionId,
|
|
|
Id: order.Id,
|
|
|
OrderType: order.OrderType,
|
|
|
OrderNo: order.OrderCode,
|
|
|
DeliveryNo: order.DeliveryCode,
|
|
|
OrderDistrict: map[string]interface{}{
|
|
|
"id": order.RegionInfo.RegionId,
|
|
|
"name": order.RegionInfo.RegionName,
|
|
|
},
|
|
|
OrderAmount: order.PlanOrderAmount,
|
|
|
UpdateTime: order.UpdateTime.Unix() * 1000,
|
|
|
MyDividend: bonusStatic.OrderTotalReceivable(),
|
|
|
IsRead: order.IsRead(),
|
|
|
OrderAmount: order.PlanOrderAmount,
|
|
|
UpdateTime: order.UpdateTime.Unix() * 1000,
|
|
|
SalesTime: order.SaleDate.Unix() * 1000,
|
|
|
MyDividend: bonusStatic.OrderTotalReceivable(),
|
|
|
IsRead: order.IsRead(),
|
|
|
}
|
|
|
} |
...
|
...
|
|