enterprise/common/dao/approval_refund.go

67 lines
1.4 KiB
Go
Raw Normal View History

2023-08-13 21:24:54 +08:00
package dao
import (
"enterprise/common/model"
"gorm.io/gorm"
"time"
)
type ApprovalRefundDao struct {
}
func NewApprovalRefundDao() *ApprovalRefundDao {
return &ApprovalRefundDao{}
}
func (d *ApprovalRefundDao) TableName() string {
return "approval_refund"
}
func (d *ApprovalRefundDao) Create(o *model.ApprovalRefund) (int64, error) {
o.CreateTime = time.Now().Unix()
res := GetDB().Table(d.TableName()).Create(o)
return o.Id, res.Error
}
func (d *ApprovalRefundDao) Update(o *model.ApprovalRefund) error {
o.UpdateTime = time.Now().Unix()
tx := GetDB().Table(d.TableName())
res := tx.Save(o)
return res.Error
}
func (d *ApprovalRefundDao) Delete(id int64) error {
res := GetDB().Table(d.TableName()).Delete(&model.ApprovalRefund{}, id)
return res.Error
}
func (d *ApprovalRefundDao) Get(id int64) (*model.ApprovalRefund, error) {
var u model.ApprovalRefund
tx := GetDB().Table(d.TableName())
tx = tx.Where("id = ?", id)
res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound {
return nil, nil
}
if res.Error != nil {
return nil, res.Error
}
return &u, nil
}
func (d *ApprovalRefundDao) GetBySpNo(spNo string) (*model.ApprovalRefund, error) {
var u model.ApprovalRefund
tx := GetDB().Table(d.TableName())
tx = tx.Where("sp_no = ?", spNo)
res := tx.First(&u)
if res.Error == gorm.ErrRecordNotFound {
return nil, nil
}
if res.Error != nil {
return nil, res.Error
}
return &u, nil
}