pg_order_dao.go
1.3 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
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"time"
)
type OrderDao struct {
transactionContext *transaction.TransactionContext
}
func (dao *OrderDao) OrderStatics(option *domain.OrderStaticQuery) (count int, amount float64, err error) {
tx := dao.transactionContext.PgTx
order := new(models.Order)
q := tx.Model(order)
q.ColumnExpr("count(*) count")
q.ColumnExpr("sum(order_amount) total_order_amount")
if option.PartnerId > 0 {
q.Where(`"order".partner_id =?`, option.PartnerId)
}
if option.OrderType > 0 {
q.Where(`"order".order_type =?`, option.OrderType)
}
if option.OrderStatus > 0 {
q.Where(`"order".order_status =?`, option.OrderStatus)
}
if option.BeginTime > 0 {
q.Where(`"order".create_at >=?`, time.Unix(option.BeginTime/1000, 0))
}
if option.EndTime > 0 {
q.Where(`"order".create_at <?`, time.Unix(option.EndTime/1000, 0))
}
err = q.Select(&count, &amount)
return
}
func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderDao{
transactionContext: transactionContext,
}, nil
}
}