This commit is contained in:
laodaming
2023-07-14 16:48:04 +08:00
parent 3a6ab7a666
commit 0db42491ae
9 changed files with 202 additions and 11 deletions

View File

@@ -6,8 +6,12 @@ func (p *FsProductModel) FindOne(ctx context.Context, id int64) (resp *FsProduct
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
func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...string) (resp *FsProduct, err error) {
db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`sn` = ? ", sn)
if len(fields) != 0 {
db = db.Select(fields[0])
}
err = db.Take(&resp).Error
return resp, err
}
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {

View File

@@ -60,11 +60,15 @@ 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) {
func (d *FsProductModel3dModel) GetAllBySizeIdsTag(ctx context.Context, sizeIds []int64, tag int64, fields ...string) (resp []FsProductModel3d, err error) {
if len(sizeIds) == 0 {
return
}
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`size_id` in (?) and `tag` = ?", sizeIds, tag).Find(&resp).Error
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) {

View File

@@ -38,16 +38,19 @@ func (s *FsProductSizeModel) GetGroupProductSizeByStatus(ctx context.Context, pr
Find(&resp).Error
return resp, err
}
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, orderBy string, fields ...string) (resp []FsProductSize, err error) {
if len(productIds) == 0 {
return nil, nil
}
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`product_id` in(?) and `status` = ?", productIds, 1)
switch sort {
case "sort-asc":
db = db.Order("`sort` ASC")
case "sort-desc":
db = db.Order("`sort` DESC")
if len(fields) != 0 {
db = db.Select(fields[0])
}
switch orderBy {
case "":
db = db.Order("`id` ASC")
default:
db = db.Order(orderBy)
}
err = db.Find(&resp).Error
if err != nil {