fix
This commit is contained in:
@@ -71,8 +71,15 @@ func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (res
|
||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context,ids []int64, limit int) (resp []FsProduct, err error) {
|
||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).
|
||||
Where("`id` in (?) and `is_del` =? and `is_shelf` = ?", ids,0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
|
||||
func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context,ids []int64, limit int,fields ...string) (resp []FsProduct, err error) {
|
||||
if len(ids) == 0{
|
||||
return
|
||||
}
|
||||
db := p.db.WithContext(ctx).Model(&FsProduct{}).
|
||||
Where("`id` in (?) and `is_del` =? and `is_shelf` = ?", ids,0, 1).Order("RAND()").Limit(limit)
|
||||
if len(fields) != 0{
|
||||
db = db.Select(fields[0])
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp,err
|
||||
}
|
||||
@@ -72,3 +72,39 @@ func (t *FsProductTemplateV2Model) FindOneByModelId(ctx context.Context, modelId
|
||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` = ? ", modelId).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
type GetProductTemplateListByParamsReq struct {
|
||||
ProductIds []int64
|
||||
GroupBy string
|
||||
OrderBy string
|
||||
Fields string
|
||||
SortNeq *int64
|
||||
TitleKeyword 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.SortNeq != nil{
|
||||
db = db.Where("`sort` != ?",req.SortNeq)
|
||||
}
|
||||
if req.TitleKeyword != ""{
|
||||
db = db.Where("title like ?",`%`+req.TitleKeyword+`%`)
|
||||
}
|
||||
if req.Status != nil{
|
||||
db = db.Where("`status` = ?",req.Status)
|
||||
}
|
||||
err = db.Find(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
Reference in New Issue
Block a user