This commit is contained in:
laodaming
2023-06-02 19:24:58 +08:00
parent 6c717ce30e
commit 92b29d8006
12 changed files with 609 additions and 17 deletions

View File

@@ -15,8 +15,8 @@ import (
)
var (
fsCanteenTypeFieldNames = builder.RawFieldNames(&FsCanteenType{})
fsCanteenTypeRows = strings.Join(fsCanteenTypeFieldNames, ",")
fsCanteenTypeFieldNames = builder.RawFieldNames(&FsCanteenType{})
fsCanteenTypeRows = strings.Join(fsCanteenTypeFieldNames, ",")
// fsCanteenTypeGetTypeRows = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`name`", "`sort`", "`created_at`", "`status`"), ",")
// fsCanteenTypeGetTypeRows = builder.RawFieldNames(&FsGetTypeCanteenType{})
fsCanteenTypeRowsExpectAutoSet = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
@@ -29,7 +29,7 @@ type (
FindOne(ctx context.Context, id int64) (*FsCanteenType, error)
Update(ctx context.Context, data *FsCanteenType) error
Delete(ctx context.Context, id int64) error
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
}
@@ -47,8 +47,8 @@ type (
}
FsGetTypeCanteenType struct {
Id int64 `db:"id" json:"key"` // ID
Name string `db:"name" json:"name"` // 餐厅名字
Id int64 `db:"id" json:"key"` // ID
Name string `db:"name" json:"name"` // 餐厅名字
}
)
@@ -80,7 +80,7 @@ func (m *defaultFsCanteenTypeModel) FindOne(ctx context.Context, id int64) (*FsC
}
func (m *defaultFsCanteenTypeModel) FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) {
query := fmt.Sprintf("select X.id,X.name from (select %s from %s where status = 1 order by sort desc) X", fsCanteenTypeRows, m.table)
var resp []*FsGetTypeCanteenType
err := m.conn.QueryRows(&resp, query)

View File

@@ -28,6 +28,7 @@ type (
FindOneBySn(ctx context.Context, sn string) (*FsProduct, error)
Update(ctx context.Context, data *FsProduct) error
Delete(ctx context.Context, id int64) error
GetProductListByConditions(ctx context.Context, productType int, isDel int, isShelf int, sort string) ([]FsProduct, error)
}
defaultFsProductModel struct {
@@ -121,6 +122,24 @@ func (m *defaultFsProductModel) Update(ctx context.Context, newData *FsProduct)
return err
}
func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, productType int, isDel int, isShelf 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 {
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, productType, isDel, isShelf)
if err != nil {
return nil, err
}
return
}
func (m *defaultFsProductModel) tableName() string {
return m.table
}