pg_order_dao.go 1.4 KB
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
	}
}