fusenapi/model/gmodel/fs_refund_reason_logic.go

41 lines
1.0 KiB
Go
Raw Normal View History

2023-06-19 10:27:31 +00:00
package gmodel
2023-06-20 09:29:02 +00:00
2023-06-20 11:36:28 +00:00
import (
"context"
"gorm.io/gorm"
)
2023-06-20 09:29:02 +00:00
// TODO: 使用model的属性做你想做的
2023-06-20 11:36:28 +00:00
func (m *FsRefundReasonModel) Create(ctx context.Context, obj *FsRefundReason) error {
return m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
2023-06-20 11:52:38 +00:00
tx.Create(obj)
2023-06-20 11:36:28 +00:00
return nil
})
}
func (m *FsRefundReasonModel) Update(ctx context.Context, obj *FsRefundReason) error {
return m.db.WithContext(ctx).Model(obj).Where("`id` = ?", obj.Id).Updates(obj).Error
}
2023-06-20 09:29:02 +00:00
2023-06-20 11:36:28 +00:00
func (m *FsRefundReasonModel) UpdateByRefundReasonId(ctx context.Context, obj *FsRefundReason) error {
return m.db.WithContext(ctx).Model(obj).Where("`refund_reason_id` = ?", obj.RefundReasonId).Updates(obj).Error
2023-06-20 09:29:02 +00:00
}
2023-07-28 11:03:36 +00:00
func (m *FsRefundReasonModel) CreateOrUpdate(ctx context.Context, req *FsRefundReason) (resp *FsRefundReason, err error) {
rowBuilder := m.db.Table(m.name).WithContext(ctx)
if req.Id > 0 {
err = rowBuilder.Save(req).Error
} else {
err = rowBuilder.Create(req).Error
}
return req, err
}
func (m *FsRefundReasonModel) TableName() string {
return m.name
}