// Code generated by goctl. DO NOT EDIT. package model import ( "context" "database/sql" "fmt" "strings" "github.com/zeromicro/go-zero/core/stores/builder" "github.com/zeromicro/go-zero/core/stores/sqlc" "github.com/zeromicro/go-zero/core/stores/sqlx" "github.com/zeromicro/go-zero/core/stringx" ) var ( fsProductPriceFieldNames = builder.RawFieldNames(&FsProductPrice{}) fsProductPriceRows = strings.Join(fsProductPriceFieldNames, ",") fsProductPriceRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductPriceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") fsProductPriceRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductPriceFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" ) type ( fsProductPriceModel interface { Insert(ctx context.Context, data *FsProductPrice) (sql.Result, error) FindOne(ctx context.Context, id int64) (*FsProductPrice, error) FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error) Update(ctx context.Context, data *FsProductPrice) error Delete(ctx context.Context, id int64) error GetPriceList(ctx context.Context, productIds []string) ([]GetPriceListRsp, error) } defaultFsProductPriceModel struct { conn sqlx.SqlConn table string } FsProductPrice struct { Id int64 `db:"id"` Sn string `db:"sn"` // 唯一编码 Title string `db:"title"` // 标题描述 ProductId int64 `db:"product_id"` // 产品ID MaterialId int64 `db:"material_id"` // 材质ID SizeId int64 `db:"size_id"` // 尺寸ID EachBoxNum int64 `db:"each_box_num"` // 每一箱的个数 EachBoxWeight float64 `db:"each_box_weight"` // 每一箱的重量 单位KG MinBuyNum int64 `db:"min_buy_num"` // 最少购买量 StepNum string `db:"step_num"` // 数量阶梯 eg:10,20,30 StepPrice string `db:"step_price"` // 价格阶梯 eg:100,50,25 Status int64 `db:"status"` // 是否可用 IsDefault int64 `db:"is_default"` // 是否默认 } ) func newFsProductPriceModel(conn sqlx.SqlConn) *defaultFsProductPriceModel { return &defaultFsProductPriceModel{ conn: conn, table: "`fs_product_price`", } } func (m *defaultFsProductPriceModel) Delete(ctx context.Context, id int64) error { query := fmt.Sprintf("delete from %s where `id` = ?", m.table) _, err := m.conn.ExecCtx(ctx, query, id) return err } func (m *defaultFsProductPriceModel) FindOne(ctx context.Context, id int64) (*FsProductPrice, error) { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductPriceRows, m.table) var resp FsProductPrice err := m.conn.QueryRowCtx(ctx, &resp, query, id) switch err { case nil: return &resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultFsProductPriceModel) FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error) { var resp FsProductPrice query := fmt.Sprintf("select %s from %s where `product_id` = ? and `material_id` = ? and `size_id` = ? limit 1", fsProductPriceRows, m.table) err := m.conn.QueryRowCtx(ctx, &resp, query, productId, materialId, sizeId) switch err { case nil: return &resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultFsProductPriceModel) Insert(ctx context.Context, data *FsProductPrice) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductPriceRowsExpectAutoSet) ret, err := m.conn.ExecCtx(ctx, query, data.Sn, data.Title, data.ProductId, data.MaterialId, data.SizeId, data.EachBoxNum, data.EachBoxWeight, data.MinBuyNum, data.StepNum, data.StepPrice, data.Status, data.IsDefault) return ret, err } func (m *defaultFsProductPriceModel) Update(ctx context.Context, newData *FsProductPrice) error { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductPriceRowsWithPlaceHolder) _, err := m.conn.ExecCtx(ctx, query, newData.Sn, newData.Title, newData.ProductId, newData.MaterialId, newData.SizeId, newData.EachBoxNum, newData.EachBoxWeight, newData.MinBuyNum, newData.StepNum, newData.StepPrice, newData.Status, newData.IsDefault, newData.Id) return err } type GetPriceListRsp struct { ProductId int64 `json:"product_id"` Price string `json:"price"` } func (m *defaultFsProductPriceModel) GetPriceList(ctx context.Context, productIds []string) (resp []GetPriceListRsp, err error) { query := fmt.Sprintf("select %s from %s where `product_id` in (?) and `status` = ? group by product_id", "product_id,group_concat(step_price) as price ", m.table) if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 1); err != nil { return nil, err } return } func (m *defaultFsProductPriceModel) tableName() string { return m.table }