fusenapi/model/gmodel/fs_refund_reason_logic.go

68 lines
1.7 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"
2023-07-31 03:32:40 +00:00
"fusenapi/utils/handler"
2023-06-20 11:36:28 +00:00
"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
}
2023-07-31 03:32:40 +00:00
func (m *FsRefundReasonModel) FindOneByQuery(ctx context.Context, rowBuilder *gorm.DB, filterMap map[string]string) (*FsRefundReason, error) {
var resp FsRefundReason
if filterMap != nil {
rowBuilder = rowBuilder.Scopes(handler.FilterData(filterMap))
}
result := rowBuilder.WithContext(ctx).Limit(1).Find(&resp)
if result.Error != nil {
return nil, result.Error
} else {
return &resp, nil
}
}
func (m *FsRefundReasonModel) RowSelectBuilder(selectData []string) *gorm.DB {
var rowBuilder = m.db.Table(m.name)
if selectData != nil {
rowBuilder = rowBuilder.Select(selectData)
} else {
rowBuilder = rowBuilder.Select("*")
}
return rowBuilder
}
2023-07-28 11:03:36 +00:00
func (m *FsRefundReasonModel) TableName() string {
return m.name
}