78 lines
2.6 KiB
Go
Executable File
78 lines
2.6 KiB
Go
Executable File
package gmodel
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp *FsProductModel3d, err error) {
|
|
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).First(&resp).Error
|
|
return resp, err
|
|
}
|
|
func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3d, err error) {
|
|
if len(ids) == 0 {
|
|
return
|
|
}
|
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
|
if len(fields) > 0 {
|
|
db = db.Select(fields[0])
|
|
}
|
|
err = db.Find(&resp).Error
|
|
return resp, err
|
|
}
|
|
func (d *FsProductModel3dModel) GetAllByIdsWithoutStatus(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3d, err error) {
|
|
if len(ids) == 0 {
|
|
return
|
|
}
|
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?)", ids)
|
|
if len(fields) > 0 {
|
|
db = db.Select(fields[0])
|
|
}
|
|
err = db.Find(&resp).Error
|
|
return resp, err
|
|
}
|
|
func (d *FsProductModel3dModel) GetAllByIdsTag(ctx context.Context, ids []int64, tag int64) (resp []FsProductModel3d, err error) {
|
|
if len(ids) == 0 {
|
|
return
|
|
}
|
|
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` in (?) and `status` = ? and `tag` = ?", ids, 1, tag).Find(&resp).Error
|
|
return resp, err
|
|
}
|
|
|
|
type Get3dModelsByParamReq struct {
|
|
Tag int64
|
|
ProductId int64
|
|
}
|
|
|
|
func (d *FsProductModel3dModel) Get3dModelsByParam(ctx context.Context, req Get3dModelsByParamReq) (resp []FsProductModel3d, err error) {
|
|
if req.ProductId == 0 && req.Tag == 0 {
|
|
return nil, nil
|
|
}
|
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`status` = ?", 1)
|
|
if req.ProductId > 0 {
|
|
db = db.Where("`product_id` =? ", req.ProductId)
|
|
}
|
|
if req.Tag > 0 {
|
|
db = db.Where("`tag` =? ", req.Tag)
|
|
}
|
|
err = db.Find(&resp).Error
|
|
return resp, err
|
|
}
|
|
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, fields ...string) (resp []FsProductModel3d, err error) {
|
|
if len(sizeIds) == 0 {
|
|
return
|
|
}
|
|
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ?", sizeIds, tag)
|
|
if len(fields) != 0 {
|
|
db = db.Select(fields[0])
|
|
}
|
|
err = db.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
|
|
}
|