2023-06-16 07:11:37 +00:00
package gmodel
import (
"context"
)
func ( t * FsProductTemplateV2Model ) FindAllByProductIds ( ctx context . Context , productIds [ ] int64 ) ( resp [ ] FsProductTemplateV2 , err error ) {
if len ( productIds ) == 0 {
return
}
2023-06-19 04:23:02 +00:00
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`product_id` in (?) and `is_del` = ? and `status` = ?" , productIds , 0 , 1 ) . Find ( & resp ) . Error
2023-06-16 07:11:37 +00:00
if err != nil {
return nil , err
}
return
}
2023-06-19 04:23:02 +00:00
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
}
2023-07-04 08:48:56 +00:00
func ( t * FsProductTemplateV2Model ) FindAllByIdsWithoutStatus ( ctx context . Context , ids [ ] int64 , fields ... string ) ( resp [ ] FsProductTemplateV2 , err error ) {
2023-06-27 09:04:58 +00:00
if len ( ids ) == 0 {
return
}
2023-07-04 08:48:56 +00:00
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` in (?) " , ids )
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
2023-06-27 09:04:58 +00:00
}
2023-07-04 08:48:56 +00:00
err = db . Find ( & resp ) . Error
return resp , err
2023-06-27 09:04:58 +00:00
}
2023-06-20 09:28:28 +00:00
func ( t * FsProductTemplateV2Model ) FindOne ( ctx context . Context , id int64 ) ( resp * FsProductTemplateV2 , err error ) {
2023-06-19 04:23:02 +00:00
2023-06-19 06:47:54 +00:00
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` = ? " , id ) . Find ( & resp ) . Error
2023-06-20 09:28:28 +00:00
return resp , err
2023-06-19 04:23:02 +00:00
}
2023-06-20 11:56:18 +00:00
func ( t * FsProductTemplateV2Model ) FindByParam ( ctx context . Context , id int64 , modelId int64 , fields ... string ) ( resp * FsProductTemplateV2 , err error ) {
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` = ? and `model_id` = ?" , id , modelId )
if len ( fields ) != 0 {
db = db . Select ( fields [ 0 ] )
}
err = db . Take ( & resp ) . Error
return resp , err
}
2023-06-25 04:16:01 +00:00
func ( t * FsProductTemplateV2Model ) Update ( ctx context . Context , id int64 , data * FsProductTemplateV2 ) error {
return t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`id` = ? " , id ) . Updates ( & data ) . Error
}
2023-06-25 09:11:42 +00:00
func ( t * FsProductTemplateV2Model ) FindAllByModelIds ( ctx context . Context , modelIds [ ] int64 ) ( resp [ ] FsProductTemplateV2 , err error ) {
if len ( modelIds ) == 0 {
return
}
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` in (?) and `is_del` = ? and `status` = ?" , modelIds , 0 , 1 ) . Find ( & resp ) . Error
if err != nil {
return nil , err
}
return
}
2023-07-06 09:43:07 +00:00
func ( t * FsProductTemplateV2Model ) FindAllByProductIdModelIds ( ctx context . Context , modelIds [ ] int64 , productId int64 ) ( resp [ ] FsProductTemplateV2 , err error ) {
if len ( modelIds ) == 0 {
2023-07-04 08:48:56 +00:00
return
}
2023-07-06 09:55:59 +00:00
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` in (?) and `product_id` = ? " , modelIds , productId ) . Find ( & resp ) . Error
2023-07-06 09:43:07 +00:00
return resp , err
}
func ( t * FsProductTemplateV2Model ) FindOneByModelId ( ctx context . Context , modelId int64 ) ( resp * FsProductTemplateV2 , err error ) {
err = t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } ) . Where ( "`model_id` = ? " , modelId ) . Take ( & resp ) . Error
2023-07-04 08:48:56 +00:00
return resp , err
}
2023-07-11 03:28:57 +00:00
type GetProductTemplateListByParamsReq struct {
ProductIds [ ] int64
GroupBy string
OrderBy string
Fields string
Status * int64
}
func ( t * FsProductTemplateV2Model ) GetProductTemplateListByParams ( ctx context . Context , req GetProductTemplateListByParamsReq ) ( resp [ ] FsProductTemplateV2 , err error ) {
db := t . db . WithContext ( ctx ) . Model ( & FsProductTemplateV2 { } )
if len ( req . ProductIds ) > 0 {
db = db . Where ( "`product_id` in (?)" , req . ProductIds )
}
if req . GroupBy != "" {
db = db . Group ( req . GroupBy )
}
if req . OrderBy != "" {
db = db . Order ( req . OrderBy )
}
if req . Fields != "" {
db = db . Select ( req . Fields )
}
if req . Status != nil {
db = db . Where ( "`status` = ?" , req . Status )
}
err = db . Find ( & resp ) . Error
return resp , err
}