fix
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ FsProductModel = (*customFsProductModel)(nil)
|
||||
@@ -13,7 +14,7 @@ type (
|
||||
// and implement the added methods in customFsProductModel.
|
||||
FsProductModel interface {
|
||||
fsProductModel
|
||||
GetProductListByConditions(ctx context.Context, productType int, sort string) ([]FsProduct, error)
|
||||
GetProductListByConditions(ctx context.Context, productTypes []string, sort string) ([]FsProduct, error)
|
||||
GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error)
|
||||
}
|
||||
|
||||
@@ -28,8 +29,8 @@ func NewFsProductModel(conn sqlx.SqlConn) FsProductModel {
|
||||
defaultFsProductModel: newFsProductModel(conn),
|
||||
}
|
||||
}
|
||||
func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, productType int, sort string) (resp []FsProduct, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `type` = ? and `is_del` =? and `is_shelf` = ?",
|
||||
func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, productTypes []string, sort string) (resp []FsProduct, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `type` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?",
|
||||
fsProductRows, m.table)
|
||||
switch sort {
|
||||
case "sort-asc":
|
||||
@@ -39,7 +40,7 @@ func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context,
|
||||
default:
|
||||
query = fmt.Sprintf("%s order by sort DESC", query)
|
||||
}
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, productType, 0, 1)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productTypes, ","), 0, 1, 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ type (
|
||||
// and implement the added methods in customFsProductPriceModel.
|
||||
FsProductPriceModel interface {
|
||||
fsProductPriceModel
|
||||
GetPriceList(ctx context.Context, productIds []string) ([]GetPriceListRsp, error)
|
||||
GetPriceListByProductIds(ctx context.Context, productIds []string) (resp []GetPriceListRsp, err error)
|
||||
GetPriceListBySizeIds(ctx context.Context, sizeIds []string) (resp []FsProductPrice, err error)
|
||||
FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error)
|
||||
}
|
||||
|
||||
@@ -36,7 +37,7 @@ type GetPriceListRsp struct {
|
||||
Price string `json:"price"`
|
||||
}
|
||||
|
||||
func (m *defaultFsProductPriceModel) GetPriceList(ctx context.Context, productIds []string) (resp []GetPriceListRsp, err error) {
|
||||
func (m *defaultFsProductPriceModel) GetPriceListByProductIds(ctx context.Context, productIds []string) (resp []GetPriceListRsp, err error) {
|
||||
if len(productIds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -59,3 +60,14 @@ func (m *defaultFsProductPriceModel) FindOneByProductIdMaterialIdSizeId(ctx cont
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []string) (resp []FsProductPrice, err error) {
|
||||
if len(sizeIds) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
query := fmt.Sprintf("select %s from %s where `size_id` in (?) and `status` = ? ", fsProductPriceRows, m.table)
|
||||
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(sizeIds, ","), 1); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ FsProductSizeModel = (*customFsProductSizeModel)(nil)
|
||||
@@ -14,7 +15,7 @@ type (
|
||||
FsProductSizeModel interface {
|
||||
fsProductSizeModel
|
||||
CountByStatus(ctx context.Context, status int) (total int, err error)
|
||||
FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error)
|
||||
FindAllByProductIds(ctx context.Context, productIds []string, sort int) (resp []FsProductSize, err error)
|
||||
}
|
||||
|
||||
customFsProductSizeModel struct {
|
||||
@@ -36,15 +37,15 @@ func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status in
|
||||
}
|
||||
return
|
||||
}
|
||||
func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, m.table)
|
||||
func (m *defaultFsProductSizeModel) FindAllByProductIds(ctx context.Context, productIds []string, sort int) (resp []FsProductSize, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_id` in(?) and `status` = ? ", fsProductSizeRows, m.table)
|
||||
switch sort {
|
||||
case 1:
|
||||
query = fmt.Sprintf("%s order by `sort` ASC", query)
|
||||
case 2:
|
||||
query = fmt.Sprintf("%s order by `sort` DESC", query)
|
||||
}
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, status)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ FsTagsModel = (*customFsTagsModel)(nil)
|
||||
|
||||
@@ -9,6 +13,7 @@ type (
|
||||
// and implement the added methods in customFsTagsModel.
|
||||
FsTagsModel interface {
|
||||
fsTagsModel
|
||||
ListAllByLevelStatus(ctx context.Context, level int, status int) (resp []FsTags, err error)
|
||||
}
|
||||
|
||||
customFsTagsModel struct {
|
||||
@@ -22,3 +27,12 @@ func NewFsTagsModel(conn sqlx.SqlConn) FsTagsModel {
|
||||
defaultFsTagsModel: newFsTagsModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsTagsModel) ListAllByLevelStatus(ctx context.Context, level int, status int) (resp []FsTags, err error) {
|
||||
query := fmt.Sprintf("select %s from %s where `level` = ? and `status` = ?", fsTagsRows, m.table)
|
||||
err = m.conn.QueryRowsCtx(ctx, &resp, query, level, status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user