pg_business_bonus_dao.go
1.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
package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
"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"
)
type BusinessBonusDao struct {
transactionContext *transaction.TransactionContext
}
//订单分红统计
func (dao *BusinessBonusDao) OrderBonusStatics(option domain.OrderBonusQuery) (rsp domain.OrderBonusResponse, err error) {
rsp = domain.OrderBonusResponse{}
if option.PartnerId == 0 && option.CompanyId == 0 && len(option.InPartnerIds) == 0 {
return
}
tx := dao.transactionContext.PgTx
q := tx.Model(new(models.BusinessBonus))
q.ColumnExpr("count(*) count")
q.ColumnExpr("sum(bonus) bonus")
q.ColumnExpr("sum(bonus_expense) bonus_expense")
if option.PartnerId > 0 {
q.Where(`"business_bonus".partner_info_id =?`, option.PartnerId)
}
if option.CompanyId > 0 {
q.Where(`"business_bonus".company_id =?`, option.CompanyId)
}
if option.IsDisable > 0 {
q.Where(`"business_bonus".is_disable =?`, option.IsDisable)
}
if len(option.InPartnerIds) > 0 {
q.Where(`"business_bonus".partner_info_id in (?)`, pg.In(option.InPartnerIds))
}
err = q.Select(&rsp.Total, &rsp.Bonus, &rsp.BonusExpense)
return
}
func NewBusinessBonusDao(transactionContext *transaction.TransactionContext) (*BusinessBonusDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &BusinessBonusDao{
transactionContext: transactionContext,
}, nil
}
}