pg_order_dao.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package dao
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type OrderDao struct {
transactionContext *transaction.TransactionContext
}
func (dao *OrderDao) Update(options map[string]interface{}) (err error) {
tx := dao.transactionContext.PgTx
order := new(models.Order)
q := tx.Model(order)
if v, ok := options["orderPaymentAmount"]; ok {
q.Set("order_payment_amount = ?", v)
}
if v, ok := options["bonusStatus"]; ok {
q.Set("bonus_status = ?", v)
}
if v, ok := options["id"]; ok {
q.Where("id = ?", v)
}
_, err = q.Update()
return
}
func (dao *OrderDao) OrderCodeIsExist(code string, orderType int) (bool, error) {
tx := dao.transactionContext.PgDd
ok, err := tx.Model(new(models.Order)).
Where("order_code=?", code).
Where("order_type=?", orderType).
Exists()
return ok, err
}
func (dao *OrderDao) GetOrderBaseInfo(id int64) (data map[string]interface{}, err error) {
tx := dao.transactionContext.PgTx
order := new(models.Order)
data = make(map[string]interface{})
q := tx.Model(order)
q.Column("partner_id", "partner_bonus_percent", "order_payment_amount", "buyer")
q.Where("id = ?", id)
err = q.Select()
if err == nil {
data["PartnerId"] = order.PartnerId
data["PartnerBonusPercent"] = order.PartnerBonusPercent
data["OrderPaymentAmount"] = order.OrderPaymentAmount
data["Buyer"] = order.Buyer
}
return
}
func (dao *OrderDao) GetDividendOrders(options map[string]interface{}) (count int, orders []*models.Order, err error) {
tx := dao.transactionContext.PgTx
//Order:=new(models.Order)
q := tx.Model(&orders)
q.ColumnExpr(`"order".*`, `partner_info.partner_name`)
q.Relation("PartnerInfo")
if v, ok := options["orderCode"]; ok && len(v.(string)) > 0 {
q.Where(`"order".order_code like ?`, fmt.Sprintf("%%%v%%", v))
}
if v, ok := options["orderType"]; ok {
q.Where(`"order".order_type=?`, v)
}
if v, ok := options["partnerId"]; ok && v.(int) > 0 {
q.Where(`"order".partner_id =?`, v)
}
if v, ok := options["offset"]; ok {
q.Offset(v.(int))
}
if v, ok := options["limit"]; ok {
q.Limit(v.(int))
}
count, err = q.SelectAndCount()
return
}
func NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderDao{
transactionContext: transactionContext,
}, nil
}
}