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-08-03 09:37:25 +00:00
|
|
|
"fusenapi/utils/handlers"
|
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 {
|
2023-08-30 03:04:54 +00:00
|
|
|
return m.db.WithContext(ctx).Model(&FsRefundReason{}).Where("`id` = ?", obj.Id).Updates(obj).Error
|
2023-06-20 11:36:28 +00:00
|
|
|
}
|
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 {
|
2023-08-30 03:04:54 +00:00
|
|
|
return m.db.WithContext(ctx).Model(&FsRefundReason{}).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-08-10 11:08:06 +00:00
|
|
|
func (m *FsRefundReasonModel) RBCreateOrUpdate(ctx context.Context, req *FsRefundReason) (resp *FsRefundReason, err error) {
|
|
|
|
rowBuilder := m.db.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 {
|
2023-08-03 09:37:25 +00:00
|
|
|
rowBuilder = rowBuilder.Scopes(handlers.FilterData(filterMap))
|
2023-07-31 03:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-10 11:08:06 +00:00
|
|
|
func (m *FsRefundReasonModel) BuilderTrans(selectData []string) *gorm.DB {
|
|
|
|
var rowBuilder = m.db
|
|
|
|
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
|
|
|
|
}
|