37 lines
1.1 KiB
Go
Executable File
37 lines
1.1 KiB
Go
Executable File
package gmodel
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64) (resp []FsProductTemplateV2, err error) {
|
|
if len(productIds) == 0 {
|
|
return
|
|
}
|
|
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`product_id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|
|
func (t *FsProductTemplateV2Model) FindAllByIds(ctx context.Context, ids []int64) (resp []FsProductTemplateV2, err error) {
|
|
if len(ids) == 0 {
|
|
return
|
|
}
|
|
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", ids, 0, 1).Find(&resp).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|
|
func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp FsProductTemplateV2, err error) {
|
|
|
|
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` = ? and `is_del` = ? and `status` = ?", id, 0, 1).Find(&resp).Error
|
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
|
return FsProductTemplateV2{}, err
|
|
}
|
|
return resp, nil
|
|
}
|