54 lines
1.7 KiB
Go
Executable File
54 lines
1.7 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"strings"
|
|
)
|
|
|
|
var _ FsProductSizeModel = (*customFsProductSizeModel)(nil)
|
|
|
|
type (
|
|
// FsProductSizeModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customFsProductSizeModel.
|
|
FsProductSizeModel interface {
|
|
fsProductSizeModel
|
|
CountByStatus(ctx context.Context, status int) (total int, err error)
|
|
FindAllByProductIds(ctx context.Context, productIds []string, sort int) (resp []FsProductSize, err error)
|
|
}
|
|
|
|
customFsProductSizeModel struct {
|
|
*defaultFsProductSizeModel
|
|
}
|
|
)
|
|
|
|
// NewFsProductSizeModel returns a model for the database table.
|
|
func NewFsProductSizeModel(conn sqlx.SqlConn) FsProductSizeModel {
|
|
return &customFsProductSizeModel{
|
|
defaultFsProductSizeModel: newFsProductSizeModel(conn),
|
|
}
|
|
}
|
|
func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) {
|
|
query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table)
|
|
err = m.conn.QueryRowCtx(ctx, &total, query, status)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return
|
|
}
|
|
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, strings.Join(productIds, ","), 1)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return
|
|
}
|