pg_order_dao.go
1.4 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
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["id"]; ok {
q.Where("id = ?", v)
}
_, err = q.Update()
return
}
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 NewOrderDao(transactionContext *transaction.TransactionContext) (*OrderDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &OrderDao{
transactionContext: transactionContext,
}, nil
}
}