pg_employee_dao.go 722 字节
package dao

import (
	"fmt"
	"github.com/go-pg/pg"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)

type EmployeeDao struct {
	transactionContext *pgTransaction.TransactionContext
}

func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
	tx := dao.transactionContext.PgTx
	_, err := tx.QueryOne(
		pg.Scan(),
		"UPDATE employees SET su_money=su_money+? WHERE uid=?",
		suMoney, uid)
	return err
}

func NewEmployeeDao(transactionContext *pgTransaction.TransactionContext) (*EmployeeDao, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &EmployeeDao{
			transactionContext: transactionContext,
		}, nil
	}
}