diff --git a/constants/api_response_code.go b/constants/api_response_code.go new file mode 100644 index 00000000..28cfa20b --- /dev/null +++ b/constants/api_response_code.go @@ -0,0 +1,8 @@ +package constants + +// api接口code响应码 +const ( + CODE_UNAUTH = 401 //未授权 + CODE_SERVICE_ERR = 510 //内部代码错误 + CODE_OK = 200 //ok +) diff --git a/constants/product_list_demo.go b/constants/product_list_demo.go new file mode 100644 index 00000000..eb638fac --- /dev/null +++ b/constants/product_list_demo.go @@ -0,0 +1,271 @@ +package constants + +// 产品列表demo +const PRODUCT_LIST_DEMO = `{ + "ob": { + "items": [ + { + "id": 25, + "sn": "P1ELZGHU", + "title": "Packing box", + "cover": "/icon/icon_25_800.png", + "intro": "打包盒卡纸", + "cover_img": "/uploads/ognhdc6q_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 28, + "sn": "P9KVYAUS", + "title": "Pizza box", + "cover": "/icon/9dmom0g7_800.png", + "intro": "披萨盒 瓦楞纸", + "cover_img": "/uploads/9xf1olkl_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 30, + "sn": "PZWDSROX", + "title": "Paper bag with handle", + "cover": "/icon/iz44vraw_800.png", + "intro": "有提手纸袋牛皮纸", + "cover_img": "/uploads/rpwntxcq_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 20, + "sn": "PNACHNUK", + "title": "Four cups of milk tea cup", + "cover": "/icon/plz43wpo_800.png", + "intro": "卡纸", + "cover_img": "/uploads/9tqgsjqi_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 2, + "miniPrice": 2 + }, + { + "id": 19, + "sn": "PHHVEXRW", + "title": "Milk tea cup holder double cup", + "cover": "/icon/ipohmmcj_800.png", + "intro": "奶茶杯托奶茶杯托两杯袋", + "cover_img": "/uploads/57ogzeq5_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 11, + "sn": "P7N4D0MK", + "title": "Cup double layer", + "cover": "/icon/nrmzz4du_800.png", + "intro": "牛皮纸双层", + "cover_img": "/uploads/oqjm5own_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 33, + "sn": "P0NFP19Y", + "title": "High paper bowl", + "cover": "/icon/cla4k6om_800.png", + "intro": "牛皮纸", + "cover_img": "/uploads/dt1qjkzg_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 32, + "sn": "PDZ3HIUL", + "title": "Flat paper bowl", + "cover": "/icon/jy14adqz_800.png", + "intro": "牛皮纸", + "cover_img": "/uploads/bzwbxduc_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 3, + "miniPrice": 2 + }, + { + "id": 31, + "sn": "PEVSMU7I", + "title": "Paper bag without handle", + "cover": "/icon/osdsegor_800.png", + "intro": "牛皮纸", + "cover_img": "/uploads/ouvayny7_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 2, + "miniPrice": 2 + }, + { + "id": 29, + "sn": "P58ZZOTI", + "title": "plastic bag", + "cover": "/icon/dvsvddks_800.png", + "intro": "塑料袋", + "cover_img": "/uploads/qvvuzkzx_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 24, + "sn": "PG7XIXII", + "title": "Hamburger box", + "cover": "/icon/icon_24_800.png", + "intro": "汉堡盒 卡纸", + "cover_img": "/uploads/fm1itgge_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 23, + "sn": "PIJ2OVUE", + "title": "Milk tea ring portable double cup", + "cover": "/icon/nxb6hjln_800.png", + "intro": "卡纸", + "cover_img": "/uploads/52fash1n_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 21, + "sn": "PMHXGUL6", + "title": "Milk tea ring portable single cup", + "cover": "/icon/qoaf5mtp_800.png", + "intro": "卡纸", + "cover_img": "/uploads/epvkzvyf_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 18, + "sn": "PFCM8KNF", + "title": "Tableware set chopsticks", + "cover": "/icon/tcspod4b_800.png", + "intro": "餐具套装筷子厚牛皮纸包装", + "cover_img": "/uploads/5jgrgzvh_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 3, + "miniPrice": 2 + }, + { + "id": 17, + "sn": "PQKIQMIK", + "title": "Tableware set four piece set", + "cover": "/icon/mdo0vu1u_800.png", + "intro": "牛皮纸包装", + "cover_img": "/uploads/szsekvbw_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 4, + "miniPrice": 2 + }, + { + "id": 16, + "sn": "PBFOIOFH", + "title": "Tableware set four piece set", + "cover": "/icon/dzrf59cp_800.png", + "intro": "餐具套装", + "cover_img": "/uploads/svfoebf1_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 15, + "sn": "P02V10AB", + "title": " Hot drink cup holder", + "cover": "/icon/icon_15_800.png", + "intro": "杯托、瓦楞纸", + "cover_img": "/uploads/4qbdid7i_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 5, + "miniPrice": 2 + }, + { + "id": 13, + "sn": "PER6WLAV", + "title": " Cup pet", + "cover": "/icon/icon_13_800.png", + "intro": "pet", + "cover_img": "/uploads/kfxehwjd_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + }, + { + "id": 12, + "sn": "PGFWRMAU", + "title": " Cup PP", + "cover": "/icon/icon_12_800.png", + "intro": "pp", + "cover_img": "/uploads/azp8uwhz_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 2, + "miniPrice": 2 + }, + { + "id": 10, + "sn": "P4ZXDVHS", + "title": "Cup monolayer", + "cover": "/icon/icon_10_800.png", + "intro": "牛皮纸单层", + "cover_img": "/uploads/onuzax6l_800.png", + "isEnv": 1, + "isMicro": 1, + "sizeNum": 1, + "miniPrice": 2 + } + ], + "_links": { + "self": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" + }, + "first": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" + }, + "last": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" + }, + "next": { + "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" + } + }, + "_meta": { + "totalCount": 21, + "pageCount": 2, + "currentPage": 1, + "perPage": 20 + } + }, + "typeName": "Boxes", + "description": "" + }` diff --git a/constants/product_model3d.go b/constants/product_model3d.go new file mode 100644 index 00000000..6f3dc937 --- /dev/null +++ b/constants/product_model3d.go @@ -0,0 +1,5 @@ +package constants + +const TAG_MODEL = 1 //模型 +const TAG_PARTS = 2 //配件 +const TAG_SCENE = 3 //场景 diff --git a/ddl/fs_product_model3d_light.sql b/ddl/fs_product_model3d_light.sql new file mode 100644 index 00000000..2f2f33e7 --- /dev/null +++ b/ddl/fs_product_model3d_light.sql @@ -0,0 +1,10 @@ +-- fusentest.fs_product_model3d_light definition + +CREATE TABLE `fs_product_model3d_light` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL COMMENT '灯光名称', + `info` text NOT NULL COMMENT '灯光数据(json格式)', + `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态值(1:显示,0:删除)', + `ctime` int(11) DEFAULT NULL COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='模型-灯光组表'; \ No newline at end of file diff --git a/ddl/fs_product_template_tags.sql b/ddl/fs_product_template_tags.sql new file mode 100644 index 00000000..f7971864 --- /dev/null +++ b/ddl/fs_product_template_tags.sql @@ -0,0 +1,9 @@ +-- fusentest.fs_product_template_tags definition + +CREATE TABLE `fs_product_template_tags` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID', + `title` varchar(25) NOT NULL COMMENT '标题', + `status` tinyint(1) unsigned NOT NULL COMMENT '状态 1:可用', + `create_at` int(10) unsigned NOT NULL COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT=' 模板标签表'; \ No newline at end of file diff --git a/goctl_template/api/types.tpl b/goctl_template/api/types.tpl index 0875ec47..b340c33d 100644 --- a/goctl_template/api/types.tpl +++ b/goctl_template/api/types.tpl @@ -42,7 +42,7 @@ func (resp *Response) SetStatus(sr *basic.StatusResponse, data ...interface{}) { resp.Message = sr.Message if len(data) == 1 { resp.Data = data[0] - } + } } // SetStatusWithMessage 设置默认StatusResponse(内部自定义) 非默认msg, 可以带data, data只使用一个参数 @@ -51,5 +51,5 @@ func (resp *Response) SetStatusWithMessage(sr *basic.StatusResponse, msg string, resp.Message = msg if len(data) == 1 { resp.Data = data[0] - } + } } \ No newline at end of file diff --git a/model/fsproductmodel3dlightmodel.go b/model/fsproductmodel3dlightmodel.go new file mode 100755 index 00000000..9af5f0a5 --- /dev/null +++ b/model/fsproductmodel3dlightmodel.go @@ -0,0 +1,24 @@ +package model + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ FsProductModel3dLightModel = (*customFsProductModel3dLightModel)(nil) + +type ( + // FsProductModel3dLightModel is an interface to be customized, add more methods here, + // and implement the added methods in customFsProductModel3dLightModel. + FsProductModel3dLightModel interface { + fsProductModel3dLightModel + } + + customFsProductModel3dLightModel struct { + *defaultFsProductModel3dLightModel + } +) + +// NewFsProductModel3dLightModel returns a model for the database table. +func NewFsProductModel3dLightModel(conn sqlx.SqlConn) FsProductModel3dLightModel { + return &customFsProductModel3dLightModel{ + defaultFsProductModel3dLightModel: newFsProductModel3dLightModel(conn), + } +} diff --git a/model/fsproductmodel3dlightmodel_gen.go b/model/fsproductmodel3dlightmodel_gen.go new file mode 100755 index 00000000..89b35c5b --- /dev/null +++ b/model/fsproductmodel3dlightmodel_gen.go @@ -0,0 +1,88 @@ +// 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 ( + fsProductModel3dLightFieldNames = builder.RawFieldNames(&FsProductModel3dLight{}) + fsProductModel3dLightRows = strings.Join(fsProductModel3dLightFieldNames, ",") + fsProductModel3dLightRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductModel3dLightFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + fsProductModel3dLightRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductModel3dLightFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + fsProductModel3dLightModel interface { + Insert(ctx context.Context, data *FsProductModel3dLight) (sql.Result, error) + FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error) + Update(ctx context.Context, data *FsProductModel3dLight) error + Delete(ctx context.Context, id int64) error + ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error) + } + + defaultFsProductModel3dLightModel struct { + conn sqlx.SqlConn + table string + } + + FsProductModel3dLight struct { + Id int64 `db:"id"` + Name string `db:"name"` // 灯光名称 + Info string `db:"info"` // 灯光数据(json格式) + Status int64 `db:"status"` // 状态值(1:显示,0:删除) + Ctime sql.NullInt64 `db:"ctime"` // 创建时间 + } +) + +func newFsProductModel3dLightModel(conn sqlx.SqlConn) *defaultFsProductModel3dLightModel { + return &defaultFsProductModel3dLightModel{ + conn: conn, + table: "`fs_product_model3d_light`", + } +} + +func (m *defaultFsProductModel3dLightModel) 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 *defaultFsProductModel3dLightModel) FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductModel3dLightRows, m.table) + var resp FsProductModel3dLight + 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 *defaultFsProductModel3dLightModel) Insert(ctx context.Context, data *FsProductModel3dLight) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsProductModel3dLightRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Info, data.Status, data.Ctime) + return ret, err +} + +func (m *defaultFsProductModel3dLightModel) Update(ctx context.Context, data *FsProductModel3dLight) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductModel3dLightRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, data.Name, data.Info, data.Status, data.Ctime, data.Id) + return err +} + +func (m *defaultFsProductModel3dLightModel) tableName() string { + return m.table +} diff --git a/model/fsproductmodel3dmodel_gen.go b/model/fsproductmodel3dmodel_gen.go index 9e2c9c2b..1e0b4788 100755 --- a/model/fsproductmodel3dmodel_gen.go +++ b/model/fsproductmodel3dmodel_gen.go @@ -95,14 +95,7 @@ func (m *defaultFsProductModel3dModel) Update(ctx context.Context, data *FsProdu _, 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 *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 *defaultFsProductModel3dModel) tableName() string { return m.table } diff --git a/model/fsproductmodel_gen.go b/model/fsproductmodel_gen.go index 8f434238..e9edc4d9 100755 --- a/model/fsproductmodel_gen.go +++ b/model/fsproductmodel_gen.go @@ -29,6 +29,7 @@ type ( 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) + GetAllProductList(ctx context.Context, isDel int, isShelf int, sort string) (resp []FsProduct, err error) } defaultFsProductModel struct { @@ -122,24 +123,6 @@ 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 } diff --git a/model/fsproductpricemodel_gen.go b/model/fsproductpricemodel_gen.go index f95facf8..7b5280d5 100755 --- a/model/fsproductpricemodel_gen.go +++ b/model/fsproductpricemodel_gen.go @@ -106,18 +106,6 @@ func (m *defaultFsProductPriceModel) Update(ctx context.Context, newData *FsProd 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 } diff --git a/model/fsproductsizemodel_gen.go b/model/fsproductsizemodel_gen.go index fcd125d0..9ff3a983 100755 --- a/model/fsproductsizemodel_gen.go +++ b/model/fsproductsizemodel_gen.go @@ -88,28 +88,7 @@ func (m *defaultFsProductSizeModel) Update(ctx context.Context, data *FsProductS _, err := m.conn.ExecCtx(ctx, query, data.ProductId, data.Title, data.Cover, data.CoverImg, data.Capacity, data.Status, data.Sort, data.Remark, data.PartsCanDeleted, data.Id) return err } -func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) { - query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table) - err = m.conn.QueryRowCtx(ctx, &total, query, status) - if err != nil { - return 0, err - } - return -} -func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) { - query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, m.table) - switch sort { - case 1: - query = fmt.Sprintf("%s order by `sort` ASC", query) - case 2: - query = fmt.Sprintf("%s order by `sort` DESC", query) - } - err = m.conn.QueryRowsCtx(ctx, &resp, query, status) - if err != nil { - return nil, err - } - return -} + func (m *defaultFsProductSizeModel) tableName() string { return m.table } diff --git a/model/fsproducttemplatetagsmodel.go b/model/fsproducttemplatetagsmodel.go new file mode 100755 index 00000000..7f162d97 --- /dev/null +++ b/model/fsproducttemplatetagsmodel.go @@ -0,0 +1,24 @@ +package model + +import "github.com/zeromicro/go-zero/core/stores/sqlx" + +var _ FsProductTemplateTagsModel = (*customFsProductTemplateTagsModel)(nil) + +type ( + // FsProductTemplateTagsModel is an interface to be customized, add more methods here, + // and implement the added methods in customFsProductTemplateTagsModel. + FsProductTemplateTagsModel interface { + fsProductTemplateTagsModel + } + + customFsProductTemplateTagsModel struct { + *defaultFsProductTemplateTagsModel + } +) + +// NewFsProductTemplateTagsModel returns a model for the database table. +func NewFsProductTemplateTagsModel(conn sqlx.SqlConn) FsProductTemplateTagsModel { + return &customFsProductTemplateTagsModel{ + defaultFsProductTemplateTagsModel: newFsProductTemplateTagsModel(conn), + } +} diff --git a/model/fsproducttemplatetagsmodel_gen.go b/model/fsproducttemplatetagsmodel_gen.go new file mode 100755 index 00000000..0570b684 --- /dev/null +++ b/model/fsproducttemplatetagsmodel_gen.go @@ -0,0 +1,87 @@ +// 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 ( + fsProductTemplateTagsFieldNames = builder.RawFieldNames(&FsProductTemplateTags{}) + fsProductTemplateTagsRows = strings.Join(fsProductTemplateTagsFieldNames, ",") + fsProductTemplateTagsRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductTemplateTagsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",") + fsProductTemplateTagsRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductTemplateTagsFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?" +) + +type ( + fsProductTemplateTagsModel interface { + Insert(ctx context.Context, data *FsProductTemplateTags) (sql.Result, error) + FindOne(ctx context.Context, id int64) (*FsProductTemplateTags, error) + Update(ctx context.Context, data *FsProductTemplateTags) error + Delete(ctx context.Context, id int64) error + ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error) + } + + defaultFsProductTemplateTagsModel struct { + conn sqlx.SqlConn + table string + } + + FsProductTemplateTags struct { + Id int64 `db:"id"` // ID + Title string `db:"title"` // 标题 + Status int64 `db:"status"` // 状态 1:可用 + CreateAt int64 `db:"create_at"` // 创建时间 + } +) + +func newFsProductTemplateTagsModel(conn sqlx.SqlConn) *defaultFsProductTemplateTagsModel { + return &defaultFsProductTemplateTagsModel{ + conn: conn, + table: "`fs_product_template_tags`", + } +} + +func (m *defaultFsProductTemplateTagsModel) 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 *defaultFsProductTemplateTagsModel) FindOne(ctx context.Context, id int64) (*FsProductTemplateTags, error) { + query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductTemplateTagsRows, m.table) + var resp FsProductTemplateTags + 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 *defaultFsProductTemplateTagsModel) Insert(ctx context.Context, data *FsProductTemplateTags) (sql.Result, error) { + query := fmt.Sprintf("insert into %s (%s) values (?, ?)", m.table, fsProductTemplateTagsRowsExpectAutoSet) + ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.Status) + return ret, err +} + +func (m *defaultFsProductTemplateTagsModel) Update(ctx context.Context, data *FsProductTemplateTags) error { + query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductTemplateTagsRowsWithPlaceHolder) + _, err := m.conn.ExecCtx(ctx, query, data.Title, data.Status, data.Id) + return err +} + +func (m *defaultFsProductTemplateTagsModel) tableName() string { + return m.table +} diff --git a/model/fsproducttemplatev2model_gen.go b/model/fsproducttemplatev2model_gen.go index c7e4ffac..bfdb8cf0 100755 --- a/model/fsproducttemplatev2model_gen.go +++ b/model/fsproducttemplatev2model_gen.go @@ -29,6 +29,7 @@ type ( Delete(ctx context.Context, id int64) 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) + FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error) } defaultFsProductTemplateV2Model struct { @@ -94,26 +95,6 @@ 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) (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, ","), 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 -} func (m *defaultFsProductTemplateV2Model) tableName() string { return m.table } diff --git a/model/self_fsproductmodel.go b/model/self_fsproductmodel.go new file mode 100755 index 00000000..8655bdae --- /dev/null +++ b/model/self_fsproductmodel.go @@ -0,0 +1,43 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" +) + +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) GetAllProductList(ctx context.Context, isDel int, isShelf int, sort string) (resp []FsProduct, err error) { + query := fmt.Sprintf("select %s from %s where `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, isDel, isShelf) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproductmodel3dlightmodel.go b/model/self_fsproductmodel3dlightmodel.go new file mode 100755 index 00000000..4d9a6ce9 --- /dev/null +++ b/model/self_fsproductmodel3dlightmodel.go @@ -0,0 +1,18 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" + "strings" +) + +func (m *defaultFsProductModel3dLightModel) ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error) { + query := fmt.Sprintf("select %s from %s where `id` in (?)", fsProductModel3dLightRows, m.table) + err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(ids, ",")) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproductmodel3dmodel.go b/model/self_fsproductmodel3dmodel.go new file mode 100755 index 00000000..6967e4ad --- /dev/null +++ b/model/self_fsproductmodel3dmodel.go @@ -0,0 +1,21 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" + "strings" +) + +func (m *defaultFsProductModel3dModel) ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error) { + if len(sizeIds) == 0 { + return nil, nil + } + 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 +} diff --git a/model/self_fsproductpricemodel.go b/model/self_fsproductpricemodel.go new file mode 100755 index 00000000..63478230 --- /dev/null +++ b/model/self_fsproductpricemodel.go @@ -0,0 +1,26 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + + "fmt" + "strings" +) + +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) { + if len(productIds) == 0 { + return nil, nil + } + 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 +} diff --git a/model/self_fsproductsizemodel.go b/model/self_fsproductsizemodel.go new file mode 100755 index 00000000..ea61699c --- /dev/null +++ b/model/self_fsproductsizemodel.go @@ -0,0 +1,31 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" +) + +func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) { + query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table) + err = m.conn.QueryRowCtx(ctx, &total, query, status) + if err != nil { + return 0, err + } + return +} +func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) { + query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, m.table) + switch sort { + case 1: + query = fmt.Sprintf("%s order by `sort` ASC", query) + case 2: + query = fmt.Sprintf("%s order by `sort` DESC", query) + } + err = m.conn.QueryRowsCtx(ctx, &resp, query, status) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproducttemplatetagsmodel.go b/model/self_fsproducttemplatetagsmodel.go new file mode 100755 index 00000000..f8014603 --- /dev/null +++ b/model/self_fsproducttemplatetagsmodel.go @@ -0,0 +1,20 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" +) + +func (m *defaultFsProductTemplateTagsModel) ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error) { + if len(ids) == 0 { + return nil, nil + } + query := fmt.Sprintf("select %s from %s where `id` in (?) ", fsProductTemplateTagsRows, m.table) + err = m.conn.QueryRowsCtx(ctx, &resp, query, ids) + if err != nil { + return nil, err + } + return +} diff --git a/model/self_fsproducttemplatev2model.go b/model/self_fsproducttemplatev2model.go new file mode 100755 index 00000000..b7c23539 --- /dev/null +++ b/model/self_fsproducttemplatev2model.go @@ -0,0 +1,50 @@ +// Code generated by goctl. DO NOT EDIT. + +package model + +import ( + "context" + "fmt" + "strings" +) + +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, ","), 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) { + if len(modelIds) == 0 { + return + } + 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", query) + case 2: + query = fmt.Sprintf("%s order by `sort` DESC", query) + } + if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), productId, 0, 1); err != nil { + return nil, err + } + return +} + +func (m *defaultFsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error) { + if len(modelIds) == 0 { + return + } + query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table) + switch sort { + case 1: + query = fmt.Sprintf("%s order by `sort` ASC", query) + case 2: + query = fmt.Sprintf("%s order by `sort` DESC", query) + } + if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), 0, 1); err != nil { + return nil, err + } + return +} diff --git a/model/self_fstagsmodel.go b/model/self_fstagsmodel.go new file mode 100755 index 00000000..9695915d --- /dev/null +++ b/model/self_fstagsmodel.go @@ -0,0 +1,3 @@ +// Code generated by goctl. DO NOT EDIT. + +package model diff --git a/product/internal/handler/getproductinfohandler.go b/product/internal/handler/getsuccessrecommandhandler.go similarity index 77% rename from product/internal/handler/getproductinfohandler.go rename to product/internal/handler/getsuccessrecommandhandler.go index 21acd4e9..7a067ca9 100644 --- a/product/internal/handler/getproductinfohandler.go +++ b/product/internal/handler/getsuccessrecommandhandler.go @@ -13,11 +13,11 @@ import ( "fusenapi/product/internal/types" ) -func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { +func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { //用户登录信息 userInfo := auth.CheckAuth(r) - var req types.GetProductInfoReq + var req types.GetSuccessRecommandReq if err := httpx.Parse(r, &req); err != nil { httpx.OkJsonCtx(r.Context(), w, &types.Response{ Code: 510, @@ -26,8 +26,9 @@ func GetProductInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { logx.Info(err) return } - l := logic.NewGetProductInfoLogic(r.Context(), svcCtx) - resp := l.GetProductInfo(&req, userInfo) + + l := logic.NewGetSuccessRecommandLogic(r.Context(), svcCtx) + resp := l.GetSuccessRecommand(&req, userInfo) if resp != nil { httpx.OkJsonCtx(r.Context(), w, resp) } else { diff --git a/product/internal/handler/routes.go b/product/internal/handler/routes.go index 278cd1ef..b0cca7a2 100644 --- a/product/internal/handler/routes.go +++ b/product/internal/handler/routes.go @@ -19,8 +19,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodGet, - Path: "/product/info", - Handler: GetProductInfoHandler(serverCtx), + Path: "/product/success-recommand", + Handler: GetSuccessRecommandHandler(serverCtx), }, }, ) diff --git a/product/internal/logic/getproductinfologic.go b/product/internal/logic/getproductinfologic.go deleted file mode 100644 index 45c5a5ea..00000000 --- a/product/internal/logic/getproductinfologic.go +++ /dev/null @@ -1,88 +0,0 @@ -package logic - -import ( - "context" - "fusenapi/product/internal/svc" - "fusenapi/product/internal/types" - "fusenapi/utils/auth" - "github.com/zeromicro/go-zero/core/logx" -) - -type GetProductInfoLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewGetProductInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetProductInfoLogic { - return &GetProductInfoLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -// 获取产品详情 -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"} - } - req.Pid = strings.Trim(req.Pid, " ") - req.ClientNo = strings.Trim(req.ClientNo, " ") - if req.Size > 0 { - req.Size = image.GetCurrentSize(req.Size) - } - //获取产品详情 - productModel := model.NewFsProductModel(l.svcCtx.MysqlConn) - 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"} - } - if productInfo == 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"} - } - //获取产品尺寸列表 - 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"} - } - sizeIds := make([]string, 0, len(productSizeList)) - for _, v := range productSizeList { - sizeIds = append(sizeIds, fmt.Sprintf("%d", v.Id)) - } - //获取这些尺寸下的模型数据 - 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"} - } - 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 -} diff --git a/product/internal/logic/getproductlistlogic.go b/product/internal/logic/getproductlistlogic.go index eb639d8c..97fd6732 100644 --- a/product/internal/logic/getproductlistlogic.go +++ b/product/internal/logic/getproductlistlogic.go @@ -36,18 +36,21 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge // 获取产品列表 func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response) { + resp = &types.Response{} //校验前台登录情况 if loginInfo.UserId == 0 { - return &types.Response{Code: 402, Message: "please sign in"} + resp.Set(constants.CODE_UNAUTH, "please sign in") + return } //如果是demo if req.IsDemo == 1 { var demo types.GetProductListRsp - if err := json.Unmarshal([]byte(l.DemoProductList()), &demo); err != nil { + if err := json.Unmarshal([]byte(constants.PRODUCT_LIST_DEMO), &demo); err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "demo data format err"} + resp.Set(constants.CODE_SERVICE_ERR, "demo data format err") } - return &types.Response{Code: 200, Message: "success", Data: demo} + resp.SetWithData(constants.CODE_OK, "success", demo) + return } if req.Page <= 0 { req.Page = 1 @@ -61,22 +64,25 @@ 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"} + resp.Set(constants.CODE_SERVICE_ERR, "get user info err") + return } if userInfo == nil { - return &types.Response{Code: 402, Message: "user not exists"} + resp.Set(constants.CODE_UNAUTH, "user not exists") + return } //查询符合的产品列表 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"} + resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list") + return } - fmt.Println(len(productList)) productLen := len(productList) if productLen == 0 { - return &types.Response{Code: 200, Message: "success"} + resp.Set(constants.CODE_OK, "success") + return } //提取产品ids productIds := make([]string, 0, productLen) @@ -87,7 +93,8 @@ 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"} + resp.Set(constants.CODE_SERVICE_ERR, "failed to get product min price list") + return } //存储产品最小价格 mapProductMinPrice := make(map[int64]int64) @@ -96,7 +103,8 @@ 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()} + resp.Set(constants.CODE_SERVICE_ERR, err.Error()) + return } if len(priceSlice) == 0 { continue @@ -109,7 +117,8 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login productTemplatesV2, err := productTemplateModel.FindAllByCondition(l.ctx, productIds) if err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "get product template_v2 err"} + resp.Set(constants.CODE_SERVICE_ERR, "get product template_v2 err") + return } mapProductTemplate := make(map[int64]struct{}) for _, v := range productTemplatesV2 { @@ -120,7 +129,8 @@ 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 "} + resp.Set(constants.CODE_SERVICE_ERR, "get tag err") + return } if tagInfo == nil { return &types.Response{Code: 510, Message: "classification not exists "} @@ -130,7 +140,8 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login productSizeCount, err := productSizeModel.CountByStatus(l.ctx, 1) if err != nil { logx.Error(err) - return &types.Response{Code: 510, Message: "get product size count err "} + resp.Set(constants.CODE_SERVICE_ERR, "get product size count err") + return } //拼接返回 itemList := make([]types.Items, 0, productLen) @@ -176,287 +187,10 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login } itemList = append(itemList, item) } - return &types.Response{ - Code: 200, - Message: "success", - Data: types.GetProductListRsp{ - Ob: types.Ob{ - Items: itemList, - }, - TypeName: tagInfo.Title, - Description: tagInfo.Description, - }} + resp.SetWithData(constants.CODE_OK, "success", types.GetProductListRsp{ + Ob: types.Ob{ + Items: itemList, + }, TypeName: tagInfo.Title, Description: tagInfo.Description, + }) return } - -// 样本产品列表 -func (l *GetProductListLogic) DemoProductList() string { - return `{ - "ob": { - "items": [ - { - "id": 25, - "sn": "P1ELZGHU", - "title": "Packing box", - "cover": "/icon/icon_25_800.png", - "intro": "打包盒卡纸", - "cover_img": "/uploads/ognhdc6q_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 28, - "sn": "P9KVYAUS", - "title": "Pizza box", - "cover": "/icon/9dmom0g7_800.png", - "intro": "披萨盒 瓦楞纸", - "cover_img": "/uploads/9xf1olkl_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 30, - "sn": "PZWDSROX", - "title": "Paper bag with handle", - "cover": "/icon/iz44vraw_800.png", - "intro": "有提手纸袋牛皮纸", - "cover_img": "/uploads/rpwntxcq_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 20, - "sn": "PNACHNUK", - "title": "Four cups of milk tea cup", - "cover": "/icon/plz43wpo_800.png", - "intro": "卡纸", - "cover_img": "/uploads/9tqgsjqi_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 2, - "miniPrice": 2 - }, - { - "id": 19, - "sn": "PHHVEXRW", - "title": "Milk tea cup holder double cup", - "cover": "/icon/ipohmmcj_800.png", - "intro": "奶茶杯托奶茶杯托两杯袋", - "cover_img": "/uploads/57ogzeq5_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 11, - "sn": "P7N4D0MK", - "title": "Cup double layer", - "cover": "/icon/nrmzz4du_800.png", - "intro": "牛皮纸双层", - "cover_img": "/uploads/oqjm5own_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 33, - "sn": "P0NFP19Y", - "title": "High paper bowl", - "cover": "/icon/cla4k6om_800.png", - "intro": "牛皮纸", - "cover_img": "/uploads/dt1qjkzg_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 32, - "sn": "PDZ3HIUL", - "title": "Flat paper bowl", - "cover": "/icon/jy14adqz_800.png", - "intro": "牛皮纸", - "cover_img": "/uploads/bzwbxduc_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 3, - "miniPrice": 2 - }, - { - "id": 31, - "sn": "PEVSMU7I", - "title": "Paper bag without handle", - "cover": "/icon/osdsegor_800.png", - "intro": "牛皮纸", - "cover_img": "/uploads/ouvayny7_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 2, - "miniPrice": 2 - }, - { - "id": 29, - "sn": "P58ZZOTI", - "title": "plastic bag", - "cover": "/icon/dvsvddks_800.png", - "intro": "塑料袋", - "cover_img": "/uploads/qvvuzkzx_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 24, - "sn": "PG7XIXII", - "title": "Hamburger box", - "cover": "/icon/icon_24_800.png", - "intro": "汉堡盒 卡纸", - "cover_img": "/uploads/fm1itgge_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 23, - "sn": "PIJ2OVUE", - "title": "Milk tea ring portable double cup", - "cover": "/icon/nxb6hjln_800.png", - "intro": "卡纸", - "cover_img": "/uploads/52fash1n_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 21, - "sn": "PMHXGUL6", - "title": "Milk tea ring portable single cup", - "cover": "/icon/qoaf5mtp_800.png", - "intro": "卡纸", - "cover_img": "/uploads/epvkzvyf_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 18, - "sn": "PFCM8KNF", - "title": "Tableware set chopsticks", - "cover": "/icon/tcspod4b_800.png", - "intro": "餐具套装筷子厚牛皮纸包装", - "cover_img": "/uploads/5jgrgzvh_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 3, - "miniPrice": 2 - }, - { - "id": 17, - "sn": "PQKIQMIK", - "title": "Tableware set four piece set", - "cover": "/icon/mdo0vu1u_800.png", - "intro": "牛皮纸包装", - "cover_img": "/uploads/szsekvbw_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 4, - "miniPrice": 2 - }, - { - "id": 16, - "sn": "PBFOIOFH", - "title": "Tableware set four piece set", - "cover": "/icon/dzrf59cp_800.png", - "intro": "餐具套装", - "cover_img": "/uploads/svfoebf1_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 15, - "sn": "P02V10AB", - "title": " Hot drink cup holder", - "cover": "/icon/icon_15_800.png", - "intro": "杯托、瓦楞纸", - "cover_img": "/uploads/4qbdid7i_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 5, - "miniPrice": 2 - }, - { - "id": 13, - "sn": "PER6WLAV", - "title": " Cup pet", - "cover": "/icon/icon_13_800.png", - "intro": "pet", - "cover_img": "/uploads/kfxehwjd_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - }, - { - "id": 12, - "sn": "PGFWRMAU", - "title": " Cup PP", - "cover": "/icon/icon_12_800.png", - "intro": "pp", - "cover_img": "/uploads/azp8uwhz_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 2, - "miniPrice": 2 - }, - { - "id": 10, - "sn": "P4ZXDVHS", - "title": "Cup monolayer", - "cover": "/icon/icon_10_800.png", - "intro": "牛皮纸单层", - "cover_img": "/uploads/onuzax6l_800.png", - "isEnv": 1, - "isMicro": 1, - "sizeNum": 1, - "miniPrice": 2 - } - ], - "_links": { - "self": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" - }, - "first": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=1&is_demo=1" - }, - "last": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" - }, - "next": { - "href": "https://fusenapi.kayue.cn:8010/product/list?cid=13&size=620&page=2&is_demo=1" - } - }, - "_meta": { - "totalCount": 21, - "pageCount": 2, - "currentPage": 1, - "perPage": 20 - } - }, - "typeName": "Boxes", - "description": "" - }` -} diff --git a/product/internal/logic/getsuccessrecommandlogic.go b/product/internal/logic/getsuccessrecommandlogic.go new file mode 100644 index 00000000..1fb4d3fd --- /dev/null +++ b/product/internal/logic/getsuccessrecommandlogic.go @@ -0,0 +1,90 @@ +package logic + +import ( + "context" + "errors" + "fmt" + "fusenapi/constants" + "fusenapi/model" + "fusenapi/product/internal/svc" + "fusenapi/product/internal/types" + "fusenapi/utils/auth" + "fusenapi/utils/image" + "github.com/zeromicro/go-zero/core/stores/sqlx" + "math/rand" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetSuccessRecommandLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSuccessRecommandLogic { + return &GetSuccessRecommandLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo auth.UserInfo) (resp *types.Response) { + resp = &types.Response{} + //校验前台登录情况 + if loginInfo.UserId == 0 { + resp.Set(constants.CODE_UNAUTH, "please sign in") + return + } + //获取用户信息 + userModel := model.NewFsUserModel(l.svcCtx.MysqlConn) + userInfo, err := userModel.FindOne(l.ctx, loginInfo.UserId) + if err != nil && errors.Is(err, sqlx.ErrNotFound) { + logx.Error(err) + resp.Set(constants.CODE_SERVICE_ERR, "failed to get user info") + return + } + if userInfo == nil { + resp.Set(constants.CODE_UNAUTH, "failed to get user info") + return + } + if req.Num == 0 { + req.Num = 8 + } + if req.Size > 0 { + req.Size = image.GetCurrentSize(req.Size) + } + //获取所有产品的ids + productModel := model.NewFsProductModel(l.svcCtx.MysqlConn) + productList, err := productModel.GetAllProductList(l.ctx, 0, 1, "sort-asc") + if err != nil { + logx.Error(err) + resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list") + return + } + //没有推荐产品就返回 + if len(productList) == 0 { + resp.Set(constants.CODE_OK, "success") + return + } + productIds := make([]string, 0, len(productList)) + for _, v := range productList { + productIds = append(productIds, fmt.Sprintf("%d", v.Id)) + } + //随机取8个 + if len(productIds) > int(req.Num) { + //打乱顺序 + indexArr := rand.Perm(len(productIds)) + tmpProductIds := make([]string, 0, int(req.Num)) + for k, v := range indexArr { + if k == 8 { + break + } + tmpProductIds = append(tmpProductIds, productIds[v]) + } + productIds = tmpProductIds + } + + return resp +} diff --git a/product/internal/types/types.go b/product/internal/types/types.go index 9faf564b..46d0aefb 100644 --- a/product/internal/types/types.go +++ b/product/internal/types/types.go @@ -56,106 +56,20 @@ type Items struct { CoverDefault string `json:"coverDefault"` } -type GetProductInfoReq struct { - Pid string `json:"pid"` //sn - Size uint32 `json:"size"` //图片尺寸 - ClientNo string `json:"clientNo"` //页面标识 - HaveCloudRendering bool `json:"haveCloudRendering"` //是否显示云渲染开关 +type GetSuccessRecommandReq struct { + Num uint32 `form:"num"` + Size uint32 `form:"size"` + Sn string `form:"sn"` } -type GetProductInfoRsp struct { - Id int64 `json:"id"` - Type int32 `json:"type"` - Title string `json:"title"` - IsEnv uint32 `json:"isEnv"` - IsMicro uint32 `json:"isMicro"` - Materials []Materials `json:"materials"` - Sizes []Sizes `json:"sizes"` - TypeName string `json:"typeName"` - Templates Templates `json:"templates"` -} - -type Materials struct { - Id int64 `json:"id"` - Title string `json:"title"` -} - -type Sizes struct { - Id int64 `json:"id"` - Title SizeTitle `json:"title"` - Capacity string `json:"capacity"` - Cover string `json:"cover"` -} - -type SizeTitle struct { - Cm string `json:"cm"` - Inth string `json:"inth"` -} - -type Templates struct { - Ob484 []Ob484 `json:"4_84"` -} - -type Ob484 struct { - Id int64 `json:"id"` - Title string `json:"title"` - TemplateData TemplateData `json:"templateData"` -} - -type TemplateData struct { - Id int64 `json:"id"` - Cover string `json:"cover"` - Material string `json:"material"` - MaterialList []Material `json:"materialList"` -} - -type Material struct { - Id int64 `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int `json:"maxNum"` - Rotation int `json:"rotation"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - QRcodeType string `json:"qRcodeType"` - Width int `json:"width"` - Height int `json:"height"` - X int `json:"x"` - Y int `json:"y"` - Opacity int `json:"opacity"` - OptionalColor []OptionalColor `json:"optionalColor"` - ZIndex int `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow Follow `json:"follow"` - Group []string `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} - -type CameraStand struct { - X int `json:"x"` - Y int `json:"y"` - Z int `json:"z"` -} - -type Follow struct { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} - -type OptionalColor struct { - Color string `json:"color"` - Name string `json:"name"` - Default string `json:"default"` +type GetSuccessRecommandRsp struct { + Title string `json:"title"` + Cover string `json:"cover"` + CoverImg string `json:"coverImg"` + Sn string `json:"sn"` + Id int64 `json:"id"` + SkuId int64 `json:"skuId"` + CoverDefault string `json:"coverDefault"` } type Response struct { @@ -164,11 +78,6 @@ type Response struct { Data interface{} `json:"data"` } -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 diff --git a/server_api/product.api b/server_api/product.api index 200e2c57..32a96e38 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -12,14 +12,13 @@ service product { //获取产品列表 @handler GetProductListHandler get /product/list(GetProductListReq) returns (response); - //获取产品详情信息 - @handler GetProductInfoHandler - get /product/info(GetProductInfoReq) returns (response); + //获取成功后的推荐产品 + @handler GetSuccessRecommand + get /product/success-recommand (GetSuccessRecommandReq) returns (response); } //获取产品列表 type GetProductListReq { - // TODO: add members here and delete this comment Cid int64 `form:"cid"` Size uint32 `form:"size"` Page uint32 `form:"page"` @@ -63,95 +62,18 @@ type Items { MiniPrice float64 `json:"miniPrice"` CoverDefault string `json:"coverDefault"` } -//获取产品详情 -type GetProductInfoReq { - Pid string `json:"pid"` //sn - Size uint32 `json:"size"` //图片尺寸 - ClientNo string `json:"clientNo"` //页面标识 - HaveCloudRendering bool `json:"haveCloudRendering"` //是否显示云渲染开关 +//获取成功后的推荐产品 +type GetSuccessRecommandReq { + Num uint32 `form:"num"` + Size uint32 `form:"size"` + Sn string `form:"sn"` } -type GetProductInfoRsp { - Id int64 `json:"id"` - Type int32 `json:"type"` - Title string `json:"title"` - IsEnv uint32 `json:"isEnv"` - IsMicro uint32 `json:"isMicro"` - Materials []Materials `json:"materials"` - Sizes []Sizes `json:"sizes"` - TypeName string `json:"typeName"` - Templates Templates `json:"templates"` -} - -type Materials { - Id int64 `json:"id"` - Title string `json:"title"` -} -type Sizes { - Id int64 `json:"id"` - Title SizeTitle `json:"title"` - Capacity string `json:"capacity"` - Cover string `json:"cover"` -} -type SizeTitle { - Cm string `json:"cm"` - Inth string `json:"inth"` -} -type Templates { - Ob484 []Ob484 `json:"4_84"` -} -type Ob484 { - Id int64 `json:"id"` - Title string `json:"title"` - TemplateData TemplateData `json:"templateData"` -} -type TemplateData { - Id int64 `json:"id"` - Cover string `json:"cover"` - Material string `json:"material"` - MaterialList []Material `json:"materialList"` -} -type Material { - Id int64 `json:"id"` - Tag string `json:"tag"` - Title string `json:"title"` - Type string `json:"type"` - Text string `json:"text"` - Fill string `json:"fill"` - FontSize int `json:"fontSize"` - FontFamily string `json:"fontFamily"` - IfBr bool `json:"ifBr"` - IfShow bool `json:"ifShow"` - IfGroup bool `json:"ifGroup"` - MaxNum int `json:"maxNum"` - Rotation int `json:"rotation"` - Align string `json:"align"` - VerticalAlign string `json:"verticalAlign"` - Material string `json:"material"` - QRcodeType string `json:"qRcodeType"` - Width int `json:"width"` - Height int `json:"height"` - X int `json:"x"` - Y int `json:"y"` - Opacity int `json:"opacity"` - OptionalColor []OptionalColor `json:"optionalColor"` - ZIndex int `json:"zIndex"` - SvgPath string `json:"svgPath"` - Follow Follow `json:"follow"` - Group []string `json:"group"` - CameraStand CameraStand `json:"cameraStand"` -} -type CameraStand { - X int `json:"x"` - Y int `json:"y"` - Z int `json:"z"` -} -type Follow { - Fill string `json:"fill"` - IfShow string `json:"ifShow"` - Content string `json:"content"` -} -type OptionalColor { - Color string `json:"color"` - Name string `json:"name"` - Default string `json:"default"` +type GetSuccessRecommandRsp { + Title string `json:"title"` + Cover string `json:"cover"` + CoverImg string `json:"coverImg"` + Sn string `json:"sn"` + Id int64 `json:"id"` + SkuId int64 `json:"skuId"` + CoverDefault string `json:"coverDefault"` } \ No newline at end of file