package gmodel import ( "context" "fusenapi/utils/handler" "gorm.io/gorm" ) // TODO: 使用model的属性做你想做的 func (m *FsRefundReasonModel) Create(ctx context.Context, obj *FsRefundReason) error { return m.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error { tx.Create(obj) 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 } 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 } 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) 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 } func (m *FsRefundReasonModel) TableName() string { return m.name }