This commit is contained in:
laodaming
2023-07-04 16:48:56 +08:00
parent 7e9cdbfb57
commit 31d22cda63
13 changed files with 590 additions and 14 deletions

View File

@@ -3,7 +3,11 @@ package gmodel
import "context"
func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct, err error) {
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? and `is_del` =? and `is_shelf` = ? and `status` =?", id, 0, 1, 1).First(&resp).Error
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` = ? ", id).First(&resp).Error
return resp, err
}
func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string) (resp *FsProduct, err error) {
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`sn` = ? ", sn).Take(&resp).Error
return resp, err
}
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {

View File

@@ -3,6 +3,9 @@ package gmodel
import "context"
func (l *FsProductModel3dLightModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsProductModel3dLight, err error) {
if len(ids) == 0 {
return
}
err = l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?) and `status` = ?", ids, 1).Find(&resp).Error
return resp, err
}
@@ -17,3 +20,14 @@ func (l *FsProductModel3dLightModel) Create(ctx context.Context, data *FsProduct
func (l *FsProductModel3dLightModel) Update(ctx context.Context, id int64, data *FsProductModel3dLight) error {
return l.db.WithContext(ctx).Where("`id` = ?", id).Updates(data).Error
}
func (l *FsProductModel3dLightModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3dLight, err error) {
if len(ids) == 0 {
return
}
db := l.db.WithContext(ctx).Model(&FsProductModel3dLight{}).Where("`id` in (?)", ids)
if len(fields) != 0 {
db = db.Select(fields[0])
}
err = db.Find(&resp).Error
return resp, err
}

View File

@@ -60,3 +60,14 @@ func (d *FsProductModel3dModel) Get3dModelsByParam(ctx context.Context, req Get3
func (d *FsProductModel3dModel) Update(ctx context.Context, id int64, data *FsProductModel3d) error {
return d.db.WithContext(ctx).Where("`id` = ? ", id).Updates(&data).Error
}
func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds []int64, tag int64) (resp []FsProductModel3d, err error) {
if len(sizeIds) == 0 {
return
}
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ?", sizeIds, 1, tag).Find(&resp).Error
return resp, err
}
func (d *FsProductModel3dModel) GetAll(ctx context.Context) (resp []FsProductModel3d, err error) {
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Find(&resp).Error
return resp, err
}

View File

@@ -75,3 +75,17 @@ func (c *FsProductSizeModel) GetAllSelectIdAndCapacityByIds(ctx context.Context,
err = c.db.WithContext(ctx).Where("id IN ?", sizeIds).Select("id", "capacity").Find(&sizes).Error
return sizes, err
}
func (s *FsProductSizeModel) GetAllByStatus(ctx context.Context, status int64, sortType int, fields ...string) (resp []FsProductSize, err error) {
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where(" `status` = ?", status)
if len(fields) > 0 {
db = db.Select(fields[0])
}
switch sortType {
case 1:
db = db.Order("`sort` ASC")
case 2:
db = db.Order("`sort` DESC")
}
err = db.Find(&resp).Error
return resp, err
}

View File

@@ -24,15 +24,16 @@ func (t *FsProductTemplateV2Model) FindAllByIds(ctx context.Context, ids []int64
}
return
}
func (t *FsProductTemplateV2Model) FindAllByIdsWithoutStatus(ctx context.Context, ids []int64) (resp []FsProductTemplateV2, err error) {
func (t *FsProductTemplateV2Model) FindAllByIdsWithoutStatus(ctx context.Context, ids []int64, fields ...string) (resp []FsProductTemplateV2, err error) {
if len(ids) == 0 {
return
}
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) ", ids).Find(&resp).Error
if err != nil {
return nil, err
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) ", ids)
if len(fields) != 0 {
db = db.Select(fields[0])
}
return
err = db.Find(&resp).Error
return resp, err
}
func (t *FsProductTemplateV2Model) FindOne(ctx context.Context, id int64) (resp *FsProductTemplateV2, err error) {
@@ -60,3 +61,10 @@ func (t *FsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelI
}
return
}
func (t *FsProductTemplateV2Model) FindAllByProductIdModelIds(ctx context.Context, ids []int64, productId int64) (resp []FsProductTemplateV2, err error) {
if len(ids) == 0 {
return
}
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `product_id` ", ids, productId).Find(&resp).Error
return resp, err
}

View File

@@ -13,10 +13,14 @@ func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTa
return
}
err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` in(?) and `status` = ?", ids, 1).Find(&resp).Error
if err != nil {
return nil, err
return resp, err
}
func (t *FsTagsModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64) (resp []FsTags, err error) {
if len(ids) == 0 {
return
}
return
err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` in(?)", ids).Find(&resp).Error
return resp, err
}
func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) {
err = t.db.Model(&FsTags{}).Where("`level` = ? and `status` = ?", level, 1).Find(&resp).Error