This commit is contained in:
laodaming 2023-06-06 11:14:13 +08:00
parent 0ce9c3d8c2
commit 25418e7be5
5 changed files with 54 additions and 61 deletions

View File

@ -1,6 +1,6 @@
-- fusentest.fs_product_model definition
CREATE TABLE `fs_product_model` (
CREATE TABLE `fs_product_model3d` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`product_id` int(10) unsigned DEFAULT NULL COMMENT '产品ID',
`tag` tinyint(1) NOT NULL DEFAULT '1' COMMENT '类别1模型2配件3场景',

24
model/fsproductmodel3dmodel.go Executable file
View File

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

View File

@ -15,27 +15,27 @@ import (
)
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`"), "=?,") + "=?"
fsProductModel3dFieldNames = builder.RawFieldNames(&FsProductModel3d{})
fsProductModel3dRows = strings.Join(fsProductModel3dFieldNames, ",")
fsProductModel3dRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductModel3dFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsProductModel3dRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductModel3dFieldNames, "`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
fsProductModel3dModel interface {
Insert(ctx context.Context, data *FsProductModel3d) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsProductModel3d, error)
Update(ctx context.Context, data *FsProductModel3d) error
Delete(ctx context.Context, id int64) error
ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) ([]FsProductModel, error)
ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error)
}
defaultFsProductModelModel struct {
defaultFsProductModel3dModel struct {
conn sqlx.SqlConn
table string
}
FsProductModel struct {
FsProductModel3d struct {
Id int64 `db:"id"`
ProductId sql.NullInt64 `db:"product_id"` // 产品ID
Tag int64 `db:"tag"` // 类别1模型2配件3场景
@ -57,22 +57,22 @@ type (
}
)
func newFsProductModelModel(conn sqlx.SqlConn) *defaultFsProductModelModel {
return &defaultFsProductModelModel{
func newFsProductModel3dModel(conn sqlx.SqlConn) *defaultFsProductModel3dModel {
return &defaultFsProductModel3dModel{
conn: conn,
table: "`fs_product_model`",
table: "`fs_product_model3d`",
}
}
func (m *defaultFsProductModelModel) Delete(ctx context.Context, id int64) error {
func (m *defaultFsProductModel3dModel) 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
func (m *defaultFsProductModel3dModel) FindOne(ctx context.Context, id int64) (*FsProductModel3d, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductModel3dRows, m.table)
var resp FsProductModel3d
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
@ -84,25 +84,25 @@ func (m *defaultFsProductModelModel) FindOne(ctx context.Context, id int64) (*Fs
}
}
func (m *defaultFsProductModelModel) Insert(ctx context.Context, data *FsProductModel) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductModelRowsExpectAutoSet)
func (m *defaultFsProductModel3dModel) Insert(ctx context.Context, data *FsProductModel3d) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductModel3dRowsExpectAutoSet)
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)
func (m *defaultFsProductModel3dModel) Update(ctx context.Context, data *FsProductModel3d) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductModel3dRowsWithPlaceHolder)
_, 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)
func (m *defaultFsProductModel3dModel) ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error) {
query := fmt.Sprintf("select %s from %s where `size_id` in (?) and `tag` = ?", fsProductModel3dRows, 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 {
func (m *defaultFsProductModel3dModel) tableName() string {
return m.table
}

View File

@ -1,24 +0,0 @@
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),
}
}

View File

@ -2,16 +2,9 @@ package logic
import (
"context"
"errors"
"fmt"
"fusenapi/model"
"fusenapi/product/internal/svc"
"fusenapi/product/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"strings"
"github.com/zeromicro/go-zero/core/logx"
)
@ -32,7 +25,7 @@ func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// 获取产品详情
func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response) {
//校验前台登录情况
if loginInfo.UserId == 0 {
/*if loginInfo.UserId == 0 {
return &types.Response{Code: 402, Message: "please sign in"}
}
req.Pid = strings.Trim(req.Pid, " ")
@ -69,8 +62,8 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login
sizeIds = append(sizeIds, fmt.Sprintf("%d", v.Id))
}
//获取这些尺寸下的模型数据
productModelModel := model.NewFsProductModelModel(l.svcCtx.MysqlConn)
models, err := productModelModel.ListBySizeIdsTag(l.ctx, sizeIds, 1)
productModel3dModel := model.NewFsProductModel3dModel(l.svcCtx.MysqlConn)
models, err := productModel3dModel.ListBySizeIdsTag(l.ctx, sizeIds, 1)
if err != nil {
logx.Error(err)
return &types.Response{Code: 510, Message: "failed to get product models"}
@ -90,6 +83,6 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login
templateModelIds := make([]string, 0, len(templateV2List))
for _, v := range templateV2List {
templateModelIds = append(templateModelIds, fmt.Sprintf("%d", v.ModelId))
}
}*/
return
}