增加产品推荐接口

This commit is contained in:
laodaming
2023-06-06 18:17:03 +08:00
parent 4312d978fb
commit cf852c5a87
3 changed files with 44 additions and 38 deletions

View File

@@ -13,8 +13,8 @@ type (
// and implement the added methods in customFsProductModel.
FsProductModel interface {
fsProductModel
GetProductListByConditions(ctx context.Context, productType int, isDel int, isShelf int, sort string) ([]FsProduct, error)
GetAllProductList(ctx context.Context, isDel int, isShelf int, sort string) (resp []FsProduct, err error)
GetProductListByConditions(ctx context.Context, productType int, sort string) ([]FsProduct, error)
GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error)
}
customFsProductModel struct {
@@ -28,7 +28,7 @@ func NewFsProductModel(conn sqlx.SqlConn) FsProductModel {
defaultFsProductModel: newFsProductModel(conn),
}
}
func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, productType int, isDel int, isShelf int, sort string) (resp []FsProduct, err error) {
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` = ?",
fsProductRows, m.table)
switch sort {
@@ -39,24 +39,16 @@ 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, isDel, isShelf)
err = m.conn.QueryRowsCtx(ctx, &resp, query, productType, 0, 1)
if err != nil {
return nil, err
}
return
}
func (m *defaultFsProductModel) GetAllProductList(ctx context.Context, isDel int, isShelf int, sort string) (resp []FsProduct, err error) {
query := fmt.Sprintf("select %s from %s where `is_del` =? and `is_shelf` = ?",
func (m *defaultFsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
query := fmt.Sprintf("select %s from %s where `is_del` =? and `is_shelf` = ? order by RAND() limit ?",
fsProductRows, m.table)
switch sort {
case "sort-asc":
query = fmt.Sprintf("%s order by sort ASC", query)
case "sort-desc":
query = fmt.Sprintf("%s order by sort DESC", query)
default:
query = fmt.Sprintf("%s order by sort DESC", query)
}
err = m.conn.QueryRowsCtx(ctx, &resp, query, isDel, isShelf)
err = m.conn.QueryRowsCtx(ctx, &resp, query, 0, 1, limit)
if err != nil {
return nil, err
}