Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson
2023-06-05 19:27:46 +08:00
10 changed files with 304 additions and 52 deletions

24
model/fsproductmodelmodel.go Executable file
View File

@@ -0,0 +1,24 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ FsProductModelModel = (*customFsProductModelModel)(nil)
type (
// FsProductModelModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsProductModelModel.
FsProductModelModel interface {
fsProductModelModel
}
customFsProductModelModel struct {
*defaultFsProductModelModel
}
)
// NewFsProductModelModel returns a model for the database table.
func NewFsProductModelModel(conn sqlx.SqlConn) FsProductModelModel {
return &customFsProductModelModel{
defaultFsProductModelModel: newFsProductModelModel(conn),
}
}

108
model/fsproductmodelmodel_gen.go Executable file
View File

@@ -0,0 +1,108 @@
// 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 (
fsProductModelFieldNames = builder.RawFieldNames(&FsProductModel{})
fsProductModelRows = strings.Join(fsProductModelFieldNames, ",")
fsProductModelRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductModelFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsProductModelRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductModelFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
fsProductModelModel interface {
Insert(ctx context.Context, data *FsProductModel) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsProductModel, error)
Update(ctx context.Context, data *FsProductModel) error
Delete(ctx context.Context, id int64) error
ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) ([]FsProductModel, error)
}
defaultFsProductModelModel struct {
conn sqlx.SqlConn
table string
}
FsProductModel struct {
Id int64 `db:"id"`
ProductId sql.NullInt64 `db:"product_id"` // 产品ID
Tag int64 `db:"tag"` // 类别1模型2配件3场景
Title string `db:"title"` // 标题
Name string `db:"name"` // 详情页展示名称
ModelInfo string `db:"model_info"` // 模型详情
MaterialId int64 `db:"material_id"` // 材质ID
SizeId int64 `db:"size_id"` // 尺寸ID
Sort int64 `db:"sort"` // 排序
Light sql.NullInt64 `db:"light"` // 灯光组
LightList sql.NullString `db:"light_list"` // 灯光备选项
PartId sql.NullInt64 `db:"part_id"` // 配件选项id配件就是模型的id
PartList sql.NullString `db:"part_list"` // 配件备选项
Status int64 `db:"status"` // 状态位 显示 删除
Ctime int64 `db:"ctime"` // 添加时间
OptionTemplate sql.NullInt64 `db:"option_template"` // 配件绑定的公共模板
Price int64 `db:"price"` // 仅配件用,配件的价格, 单位:美分
Sku string `db:"sku"` // sku
}
)
func newFsProductModelModel(conn sqlx.SqlConn) *defaultFsProductModelModel {
return &defaultFsProductModelModel{
conn: conn,
table: "`fs_product_model`",
}
}
func (m *defaultFsProductModelModel) 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 *defaultFsProductModelModel) FindOne(ctx context.Context, id int64) (*FsProductModel, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductModelRows, m.table)
var resp FsProductModel
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 *defaultFsProductModelModel) Insert(ctx context.Context, data *FsProductModel) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductModelRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.Tag, data.Title, data.Name, data.ModelInfo, data.MaterialId, data.SizeId, data.Sort, data.Light, data.LightList, data.PartId, data.PartList, data.Status, data.Ctime, data.OptionTemplate, data.Price, data.Sku)
return ret, err
}
func (m *defaultFsProductModelModel) Update(ctx context.Context, data *FsProductModel) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductModelRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.Tag, data.Title, data.Name, data.ModelInfo, data.MaterialId, data.SizeId, data.Sort, data.Light, data.LightList, data.PartId, data.PartList, data.Status, data.Ctime, data.OptionTemplate, data.Price, data.Sku, data.Id)
return err
}
func (m *defaultFsProductModelModel) ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel, err error) {
query := fmt.Sprintf("select %s from %s where `size_id` in (?) and `tag` = ?", fsProductModelRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(sizeIds, ","), tag)
if err != nil {
return nil, err
}
return
}
func (m *defaultFsProductModelModel) tableName() string {
return m.table
}

View File

@@ -27,7 +27,8 @@ type (
FindOne(ctx context.Context, id int64) (*FsProductTemplateV2, error)
Update(ctx context.Context, data *FsProductTemplateV2) error
Delete(ctx context.Context, id int64) error
FindAllByCondition(ctx context.Context, productIds []string, isDel int, status int) ([]FsProductTemplateV2, error)
FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error)
FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error)
}
defaultFsProductTemplateV2Model struct {
@@ -93,9 +94,22 @@ func (m *defaultFsProductTemplateV2Model) Update(ctx context.Context, data *FsPr
_, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.ModelId, data.Title, data.Name, data.CoverImg, data.TemplateInfo, data.MaterialImg, data.Sort, data.LogoWidth, data.LogoHeight, data.IsPublic, data.Status, data.Ctime, data.Tag, data.IsDel, data.Id)
return err
}
func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string, isDel int, status int) (resp []FsProductTemplateV2, err error) {
func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) {
query := fmt.Sprintf("select %s from %s where `id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table)
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), isDel, status); err != nil {
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 0, 1); err != nil {
return nil, err
}
return
}
func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) {
query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `product_id` = ? and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table)
switch sort {
case 1:
query = fmt.Sprintf("%s order by `sort` ASC")
case 2:
query = fmt.Sprintf("%s order by `sort` DESC")
}
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), productId, 0, 1); err != nil {
return nil, err
}
return