order_v2.go
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package order
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/protocol"
"time"
)
// 订单统计
func StatisticsV2(header *protocol.RequestHeader, request *protocol.OrderStatisticsRequest) (rsp *protocol.OrderStatisticsResponse, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
OrderDao, _ = factory.CreateOrderBaseDao(transactionContext)
)
if err = transactionContext.StartTransaction(); err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
rsp = &protocol.OrderStatisticsResponse{}
//事业分红/业务分红
var total float64 //,developBonus,appBonus,careerBonus, businessBonus,
if bonus, e := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career)}); e == nil {
//careerBonus = bonus.Bonus
total += bonus.Bonus
}
calcOrderStatic := func(catId int, total float64) protocol.OrderStatic {
todayRealQuantity, todayRealMoney, _ := OrderDao.OrderStatics(&domain.OrderStaticQuery{
BeginTime: utils.GetDayBegin().Unix() * 1000,
EndTime: utils.GetDayEnd().Unix() * 1000,
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
PartnerCategoryId: catId,
})
cumulativeQuantity, cumulativeMoney, _ := OrderDao.OrderStatics(&domain.OrderStaticQuery{
EndTime: time.Now().Unix() * 1000,
OrderTypes: domain.UserOrderTypes(domain.Career),
PartnerId: request.PartnerId,
PartnerCategoryId: catId,
})
bonus, _ := OrderDao.OrderBonusStatics(domain.OrderBonusQuery{PartnerId: request.PartnerId, OrderTypes: domain.UserOrderTypes(domain.Career), PartnerCategoryId: catId})
var percent float64 = 0
if bonus.Bonus != 0 {
percent = utils.DecimalToNumber(bonus.Bonus * 100 / total)
}
return protocol.OrderStatic{
Percent: percent,
TodayRealQuantity: todayRealQuantity,
TodayRealMoney: utils.Decimal(todayRealMoney),
CumulativeQuantity: cumulativeQuantity,
CumulativeMoney: utils.Decimal(cumulativeMoney),
}
}
rsp.Career = calcOrderStatic(domain.Career, total)
rsp.Business = calcOrderStatic(domain.Business, total)
rsp.Develop = calcOrderStatic(domain.Develop, total)
rsp.App = calcOrderStatic(domain.App, total)
err = transactionContext.CommitTransaction()
return
}