Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
0ce9c3d8c2
24
ddl/fs_product_model.sql
Normal file
24
ddl/fs_product_model.sql
Normal file
|
@ -0,0 +1,24 @@
|
|||
-- fusentest.fs_product_model definition
|
||||
|
||||
CREATE TABLE `fs_product_model` (
|
||||
`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:场景)',
|
||||
`title` varchar(255) NOT NULL COMMENT '标题',
|
||||
`name` varchar(255) DEFAULT '' COMMENT '详情页展示名称',
|
||||
`model_info` varchar(3000) NOT NULL COMMENT '模型详情',
|
||||
`material_id` tinyint(3) unsigned NOT NULL COMMENT '材质ID',
|
||||
`size_id` int(10) unsigned NOT NULL COMMENT '尺寸ID',
|
||||
`sort` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT '排序',
|
||||
`light` int(10) DEFAULT NULL COMMENT '灯光组',
|
||||
`light_list` varchar(255) DEFAULT NULL COMMENT '灯光备选项',
|
||||
`part_id` int(10) DEFAULT NULL COMMENT '配件选项id(配件就是模型的id)',
|
||||
`part_list` varchar(255) DEFAULT NULL COMMENT '配件备选项',
|
||||
`status` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '状态位 显示 删除',
|
||||
`ctime` int(10) unsigned NOT NULL COMMENT '添加时间',
|
||||
`option_template` int(10) DEFAULT NULL COMMENT '配件绑定的公共模板',
|
||||
`price` int(10) NOT NULL DEFAULT '0' COMMENT '仅配件用,配件的价格, 单位:美分',
|
||||
`sku` varchar(255) NOT NULL DEFAULT '' COMMENT 'sku',
|
||||
PRIMARY KEY (`id`) USING BTREE,
|
||||
KEY `product_id` (`product_id`) USING BTREE
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=215 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='产品模型表';
|
24
model/fsproductmodelmodel.go
Executable file
24
model/fsproductmodelmodel.go
Executable 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
108
model/fsproductmodelmodel_gen.go
Executable 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
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -1,32 +1,39 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/utils/auth"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/product/internal/logic"
|
||||
"fusenapi/product/internal/svc"
|
||||
"fusenapi/product/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 获取产品详情
|
||||
func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
//检测登录权限
|
||||
//用户登录信息
|
||||
userInfo := auth.CheckAuth(r)
|
||||
var req types.GetProductInfoReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewGetProductInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetProductInfo(&req, userInfo)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
resp := l.GetProductInfo(&req, userInfo)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,40 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fusenapi/utils/auth"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/product/internal/logic"
|
||||
"fusenapi/product/internal/svc"
|
||||
"fusenapi/product/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
// 获取产品列表
|
||||
func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
//检测登录权限
|
||||
//用户登录信息
|
||||
userInfo := auth.CheckAuth(r)
|
||||
var req types.GetProductListReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, types.Response{Code: 500, Message: err.Error()})
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewGetProductListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetProductList(&req, userInfo)
|
||||
if err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, types.Response{Code: 500, Message: err.Error()})
|
||||
} else {
|
||||
resp := l.GetProductList(&req, userInfo)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,14 +5,13 @@ import (
|
|||
"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"
|
||||
|
||||
"fusenapi/product/internal/svc"
|
||||
"fusenapi/product/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
|
@ -31,10 +30,10 @@ func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
|||
}
|
||||
|
||||
// 获取产品详情
|
||||
func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response, err error) {
|
||||
func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, loginInfo auth.UserInfo) (resp *types.Response) {
|
||||
//校验前台登录情况
|
||||
if loginInfo.UserId == 0 {
|
||||
return &types.Response{Code: 402, Message: "please sign in"}, nil
|
||||
return &types.Response{Code: 402, Message: "please sign in"}
|
||||
}
|
||||
req.Pid = strings.Trim(req.Pid, " ")
|
||||
req.ClientNo = strings.Trim(req.ClientNo, " ")
|
||||
|
@ -46,28 +45,51 @@ func (l *GetProductInfoLogic) GetProductInfo(req *types.GetProductInfoReq, login
|
|||
productInfo, err := productModel.FindOneBySn(l.ctx, req.Pid)
|
||||
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "failed to get product info"}, nil
|
||||
return &types.Response{Code: 510, Message: "failed to get product info"}
|
||||
}
|
||||
if productInfo == nil {
|
||||
return &types.Response{Code: 510, Message: "product not found"}, nil
|
||||
return &types.Response{Code: 510, Message: "product not found"}
|
||||
}
|
||||
//获取产品标签
|
||||
tagModel := model.NewFsTagsModel(l.svcCtx.MysqlConn)
|
||||
tagInfo, err := tagModel.FindOne(l.ctx, productInfo.Type)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "failed to get product tag"}, nil
|
||||
return &types.Response{Code: 510, Message: "failed to get product tag"}
|
||||
}
|
||||
//获取产品尺寸列表
|
||||
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||
productSizeList, err := productSizeModel.FindAllByStatus(l.ctx, 1, 1)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "failed to get product size list"}, nil
|
||||
return &types.Response{Code: 510, Message: "failed to get product size list"}
|
||||
}
|
||||
sizeIds := make([]string, 0, len(productSizeList))
|
||||
for _, v := range productSizeList {
|
||||
sizeIds = append(sizeIds, fmt.Sprintf("%d", v.Id))
|
||||
}
|
||||
//获取这些尺寸下的模型数据
|
||||
productModelModel := model.NewFsProductModelModel(l.svcCtx.MysqlConn)
|
||||
models, err := productModelModel.ListBySizeIdsTag(l.ctx, sizeIds, 1)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "failed to get product models"}
|
||||
}
|
||||
modelIds := make([]string, 0, len(models))
|
||||
for _, v := range models {
|
||||
modelIds = append(modelIds, fmt.Sprintf("%d", v.Id))
|
||||
}
|
||||
//通过产品id和模型id获取模板信息
|
||||
productTemplateV2Model := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
|
||||
templateV2List, err := productTemplateV2Model.FindAllByModelIdsProduct(l.ctx, modelIds, productInfo.Id, 2)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "failed to get templates"}
|
||||
}
|
||||
//获取模板包含的model_id
|
||||
templateModelIds := make([]string, 0, len(templateV2List))
|
||||
for _, v := range templateV2List {
|
||||
templateModelIds = append(templateModelIds, fmt.Sprintf("%d", v.ModelId))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -35,19 +35,19 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
|
|||
}
|
||||
|
||||
// 获取产品列表
|
||||
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response, err error) {
|
||||
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response) {
|
||||
//校验前台登录情况
|
||||
if loginInfo.UserId == 0 {
|
||||
return &types.Response{Code: 402, Message: "please sign in"}, nil
|
||||
return &types.Response{Code: 402, Message: "please sign in"}
|
||||
}
|
||||
//如果是demo
|
||||
if req.IsDemo == 1 {
|
||||
var demo types.GetProductListRsp
|
||||
if err = json.Unmarshal([]byte(l.DemoProductList()), &demo); err != nil {
|
||||
if err := json.Unmarshal([]byte(l.DemoProductList()), &demo); err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "demo data format err"}, nil
|
||||
return &types.Response{Code: 510, Message: "demo data format err"}
|
||||
}
|
||||
return &types.Response{Code: 200, Message: "success", Data: demo}, nil
|
||||
return &types.Response{Code: 200, Message: "success", Data: demo}
|
||||
}
|
||||
if req.Page <= 0 {
|
||||
req.Page = 1
|
||||
|
@ -61,22 +61,22 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
|||
userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId)
|
||||
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "get user info err"}, nil
|
||||
return &types.Response{Code: 510, Message: "get user info err"}
|
||||
}
|
||||
if userInfo == nil {
|
||||
return &types.Response{Code: 402, Message: "user not exists"}, nil
|
||||
return &types.Response{Code: 402, Message: "user not exists"}
|
||||
}
|
||||
//查询符合的产品列表
|
||||
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
||||
productList, err := productModel.GetProductListByConditions(l.ctx, int(req.Cid), 0, 1, "sort-desc")
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "failed to get product list"}, nil
|
||||
return &types.Response{Code: 510, Message: "failed to get product list"}
|
||||
}
|
||||
fmt.Println(len(productList))
|
||||
productLen := len(productList)
|
||||
if productLen == 0 {
|
||||
return &types.Response{Code: 200, Message: "success"}, nil
|
||||
return &types.Response{Code: 200, Message: "success"}
|
||||
}
|
||||
//提取产品ids
|
||||
productIds := make([]string, 0, productLen)
|
||||
|
@ -87,7 +87,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
|||
productPriceList, err := productPriceModel.GetPriceList(l.ctx, productIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "failed to get product min price list"}, nil
|
||||
return &types.Response{Code: 510, Message: "failed to get product min price list"}
|
||||
}
|
||||
//存储产品最小价格
|
||||
mapProductMinPrice := make(map[int64]int64)
|
||||
|
@ -96,7 +96,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
|||
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: err.Error()}, nil
|
||||
return &types.Response{Code: 510, Message: err.Error()}
|
||||
}
|
||||
if len(priceSlice) == 0 {
|
||||
continue
|
||||
|
@ -106,10 +106,10 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
|||
}
|
||||
//获取模板
|
||||
productTemplateModel := model.NewFsProductTemplateV2Model(l.svcCtx.MysqlConn)
|
||||
productTemplatesV2, err := productTemplateModel.FindAllByCondition(l.ctx, productIds, 0, 1)
|
||||
productTemplatesV2, err := productTemplateModel.FindAllByCondition(l.ctx, productIds)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "get product template_v2 err"}, nil
|
||||
return &types.Response{Code: 510, Message: "get product template_v2 err"}
|
||||
}
|
||||
mapProductTemplate := make(map[int64]struct{})
|
||||
for _, v := range productTemplatesV2 {
|
||||
|
@ -120,17 +120,17 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
|||
tagInfo, err := tagsModel.FindOne(l.ctx, req.Cid)
|
||||
if err != nil && !errors.Is(err, sqlc.ErrNotFound) {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "get classification err "}, nil
|
||||
return &types.Response{Code: 510, Message: "get classification err "}
|
||||
}
|
||||
if tagInfo == nil {
|
||||
return &types.Response{Code: 510, Message: "classification not exists "}, nil
|
||||
return &types.Response{Code: 510, Message: "classification not exists "}
|
||||
}
|
||||
//获取产品尺寸数量
|
||||
productSizeModel := model.NewFsProductSizeModel(l.svcCtx.MysqlConn)
|
||||
productSizeCount, err := productSizeModel.CountByStatus(l.ctx, 1)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return &types.Response{Code: 510, Message: "get product size count err "}, nil
|
||||
return &types.Response{Code: 510, Message: "get product size count err "}
|
||||
}
|
||||
//拼接返回
|
||||
itemList := make([]types.Items, 0, productLen)
|
||||
|
@ -185,7 +185,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
|||
},
|
||||
TypeName: tagInfo.Title,
|
||||
Description: tagInfo.Description,
|
||||
}}, nil
|
||||
}}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
import (
|
||||
"fusenapi/utils/basic"
|
||||
)
|
||||
|
||||
type GetProductListReq struct {
|
||||
Cid int64 `form:"cid"`
|
||||
Size uint32 `form:"size"`
|
||||
|
@ -164,3 +168,49 @@ type Auth struct {
|
|||
AccessSecret string `json:"AccessSecret"`
|
||||
AccessExpire int `json:"AccessExpire"`
|
||||
}
|
||||
|
||||
// Set 设置Response的Code和Message值
|
||||
func (resp *Response) Set(Code int, Message string) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
}
|
||||
|
||||
// Set 设置整个Response
|
||||
func (resp *Response) SetWithData(Code int, Message string, Data interface{}) {
|
||||
resp.Code = Code
|
||||
resp.Message = Message
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetMessage 设置Response的Message
|
||||
func (resp *Response) SetMessage(msg string) {
|
||||
resp.Message = msg
|
||||
}
|
||||
|
||||
// SetWithData 设置Data
|
||||
func (resp *Response) SetData(Data interface{}) {
|
||||
resp.Data = Data
|
||||
}
|
||||
|
||||
// SetWithData 设置Response的Code和Message值 带Data入参数
|
||||
func (resp *Response) SetCode(Code int) {
|
||||
resp.Code = Code
|
||||
}
|
||||
|
||||
// SetStatus 设置默认StatusResponse(内部自定义) 默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = sr.Message
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
}
|
||||
|
||||
// SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数
|
||||
func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, data ...interface{}) {
|
||||
resp.Code = sr.Code
|
||||
resp.Message = msg
|
||||
if len(data) == 1 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,3 @@ type response {
|
|||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// Auth jwt认证认证的安全参数
|
||||
type Auth {
|
||||
AccessSecret string `json:"AccessSecret"`
|
||||
AccessExpire int `json:"AccessExpire"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user