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

This commit is contained in:
eson 2023-06-06 20:09:06 +08:00
commit ef50dbb6fe
27 changed files with 287 additions and 299 deletions

View File

@ -1,6 +1,10 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsProductModel = (*customFsProductModel)(nil)
@ -9,6 +13,8 @@ type (
// and implement the added methods in customFsProductModel.
FsProductModel interface {
fsProductModel
GetProductListByConditions(ctx context.Context, productType int, sort string) ([]FsProduct, error)
GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error)
}
customFsProductModel struct {
@ -22,3 +28,29 @@ func NewFsProductModel(conn sqlx.SqlConn) FsProductModel {
defaultFsProductModel: newFsProductModel(conn),
}
}
func (m *defaultFsProductModel) GetProductListByConditions(ctx context.Context, productType 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, 0, 1)
if err != nil {
return nil, err
}
return
}
func (m *defaultFsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
query := fmt.Sprintf("select %s from %s where `is_del` =? and `is_shelf` = ? order by RAND() limit ?",
fsProductRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, 0, 1, limit)
if err != nil {
return nil, err
}
return
}

View File

@ -1,6 +1,11 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsProductModel3dLightModel = (*customFsProductModel3dLightModel)(nil)
@ -9,6 +14,7 @@ type (
// and implement the added methods in customFsProductModel3dLightModel.
FsProductModel3dLightModel interface {
fsProductModel3dLightModel
ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error)
}
customFsProductModel3dLightModel struct {
@ -22,3 +28,11 @@ func NewFsProductModel3dLightModel(conn sqlx.SqlConn) FsProductModel3dLightModel
defaultFsProductModel3dLightModel: newFsProductModel3dLightModel(conn),
}
}
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
}

View File

@ -27,7 +27,6 @@ type (
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 {

View File

@ -1,6 +1,11 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsProductModel3dModel = (*customFsProductModel3dModel)(nil)
@ -9,6 +14,7 @@ type (
// and implement the added methods in customFsProductModel3dModel.
FsProductModel3dModel interface {
fsProductModel3dModel
ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error)
}
customFsProductModel3dModel struct {
@ -22,3 +28,14 @@ func NewFsProductModel3dModel(conn sqlx.SqlConn) FsProductModel3dModel {
defaultFsProductModel3dModel: newFsProductModel3dModel(conn),
}
}
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
}

View File

@ -27,7 +27,6 @@ type (
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) (resp []FsProductModel3d, err error)
}
defaultFsProductModel3dModel struct {

View File

@ -28,8 +28,6 @@ type (
FindOneBySn(ctx context.Context, sn string) (*FsProduct, error)
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 {

View File

@ -1,6 +1,12 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsProductPriceModel = (*customFsProductPriceModel)(nil)
@ -9,6 +15,8 @@ type (
// and implement the added methods in customFsProductPriceModel.
FsProductPriceModel interface {
fsProductPriceModel
GetPriceList(ctx context.Context, productIds []string) ([]GetPriceListRsp, error)
FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error)
}
customFsProductPriceModel struct {
@ -22,3 +30,32 @@ func NewFsProductPriceModel(conn sqlx.SqlConn) FsProductPriceModel {
defaultFsProductPriceModel: newFsProductPriceModel(conn),
}
}
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
}
func (m *defaultFsProductPriceModel) FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error) {
var resp FsProductPrice
query := fmt.Sprintf("select %s from %s where `product_id` = ? and `material_id` = ? and `size_id` = ? limit 1", fsProductPriceRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, productId, materialId, sizeId)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}

View File

@ -25,10 +25,8 @@ type (
fsProductPriceModel interface {
Insert(ctx context.Context, data *FsProductPrice) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsProductPrice, error)
FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error)
Update(ctx context.Context, data *FsProductPrice) error
Delete(ctx context.Context, id int64) error
GetPriceList(ctx context.Context, productIds []string) ([]GetPriceListRsp, error)
}
defaultFsProductPriceModel struct {
@ -80,20 +78,6 @@ func (m *defaultFsProductPriceModel) FindOne(ctx context.Context, id int64) (*Fs
}
}
func (m *defaultFsProductPriceModel) FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error) {
var resp FsProductPrice
query := fmt.Sprintf("select %s from %s where `product_id` = ? and `material_id` = ? and `size_id` = ? limit 1", fsProductPriceRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, productId, materialId, sizeId)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultFsProductPriceModel) Insert(ctx context.Context, data *FsProductPrice) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductPriceRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Sn, data.Title, data.ProductId, data.MaterialId, data.SizeId, data.EachBoxNum, data.EachBoxWeight, data.MinBuyNum, data.StepNum, data.StepPrice, data.Status, data.IsDefault)

View File

@ -1,6 +1,10 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsProductSizeModel = (*customFsProductSizeModel)(nil)
@ -9,6 +13,8 @@ type (
// and implement the added methods in customFsProductSizeModel.
FsProductSizeModel interface {
fsProductSizeModel
CountByStatus(ctx context.Context, status int) (total int, err error)
FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error)
}
customFsProductSizeModel struct {
@ -22,3 +28,25 @@ func NewFsProductSizeModel(conn sqlx.SqlConn) FsProductSizeModel {
defaultFsProductSizeModel: newFsProductSizeModel(conn),
}
}
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
}

View File

@ -27,8 +27,6 @@ type (
FindOne(ctx context.Context, id int64) (*FsProductSize, error)
Update(ctx context.Context, data *FsProductSize) error
Delete(ctx context.Context, id int64) error
CountByStatus(ctx context.Context, status int) (total int, err error)
FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error)
}
defaultFsProductSizeModel struct {

View File

@ -1,6 +1,10 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsProductTemplateTagsModel = (*customFsProductTemplateTagsModel)(nil)
@ -9,6 +13,7 @@ type (
// and implement the added methods in customFsProductTemplateTagsModel.
FsProductTemplateTagsModel interface {
fsProductTemplateTagsModel
ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error)
}
customFsProductTemplateTagsModel struct {
@ -22,3 +27,14 @@ func NewFsProductTemplateTagsModel(conn sqlx.SqlConn) FsProductTemplateTagsModel
defaultFsProductTemplateTagsModel: newFsProductTemplateTagsModel(conn),
}
}
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
}

View File

@ -27,7 +27,6 @@ type (
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 {

View File

@ -1,6 +1,11 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsProductTemplateV2Model = (*customFsProductTemplateV2Model)(nil)
@ -9,6 +14,9 @@ type (
// and implement the added methods in customFsProductTemplateV2Model.
FsProductTemplateV2Model interface {
fsProductTemplateV2Model
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)
}
customFsProductTemplateV2Model struct {
@ -22,3 +30,43 @@ func NewFsProductTemplateV2Model(conn sqlx.SqlConn) FsProductTemplateV2Model {
defaultFsProductTemplateV2Model: newFsProductTemplateV2Model(conn),
}
}
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
}

View File

@ -27,9 +27,6 @@ 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) (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 {

View File

@ -1,43 +0,0 @@
// 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
}

View File

@ -1,18 +0,0 @@
// 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
}

View File

@ -1,21 +0,0 @@
// 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
}

View File

@ -1,26 +0,0 @@
// 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
}

View File

@ -1,31 +0,0 @@
// 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
}

View File

@ -1,20 +0,0 @@
// 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
}

View File

@ -1,50 +0,0 @@
// 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
}

View File

@ -1,3 +0,0 @@
// Code generated by goctl. DO NOT EDIT.
package model

View File

@ -21,7 +21,7 @@ func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
if err := httpx.Parse(r, &req); err != nil {
httpx.OkJsonCtx(r.Context(), w, &types.Response{
Code: 510,
Message: "parameter error",
Message: err.Error(),
})
logx.Info(err)
return

View File

@ -21,7 +21,7 @@ func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
if err := httpx.Parse(r, &req); err != nil {
httpx.OkJsonCtx(r.Context(), w, &types.Response{
Code: 510,
Message: "parameter error",
Message: err.Error(),
})
logx.Info(err)
return

View File

@ -12,12 +12,10 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/format"
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"sort"
"strings"
"time"
"github.com/zeromicro/go-zero/core/logx"
)
type GetProductListLogic struct {
@ -73,7 +71,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
}
//查询符合的产品列表
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
productList, err := productModel.GetProductListByConditions(l.ctx, int(req.Cid), 0, 1, "sort-desc")
productList, err := productModel.GetProductListByConditions(l.ctx, int(req.Cid), "sort-desc")
if err != nil {
logx.Error(err)
resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list")
@ -147,44 +145,35 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
itemList := make([]types.Items, 0, productLen)
for _, v := range productList {
minPrice, ok := mapProductMinPrice[v.Id]
//无最小价格则不显示
if !ok {
continue
}
_, ok = mapProductTemplate[v.Id]
//没有模板也不显示
if !ok {
_, tmpOk := mapProductTemplate[v.Id]
//无最小价格则不显示 || 没有模板也不显示
if !ok || !tmpOk {
continue
}
item := types.Items{
Id: v.Id,
Sn: v.Sn,
Title: v.Title,
Cover: v.Cover,
Intro: v.Intro.String,
CoverImg: v.CoverImg,
IsEnv: v.IsProtection,
IsMicro: v.IsMicrowave,
SizeNum: uint32(productSizeCount),
MiniPrice: format.CentoDollar(minPrice),
}
if req.Size > 0 {
coverSlice := strings.Split(v.Cover, ".")
coverImgSlice := strings.Split(v.CoverImg, ".")
if req.Size >= 200 {
item.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
item.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
//千人千面处理
if userInfo.IsThousandFace == 1 {
v.Cover = ""
item.CoverDefault = item.CoverImg
if req.Size >= 200 {
item.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, userInfo.Id, userInfo.Id, v.Id, time.Now().Unix())
item.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
}
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(userInfo.IsThousandFace),
Cover: v.Cover,
CoverImg: v.CoverImg,
CoverDefault: v.CoverImg,
ProductId: v.Id,
UserInfo: *userInfo,
}
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
item.Cover = thousandFaceImageFormatReq.Cover
item.CoverImg = thousandFaceImageFormatReq.CoverImg
item.CoverDefault = thousandFaceImageFormatReq.CoverDefault
itemList = append(itemList, item)
}
resp.SetWithData(constants.CODE_OK, "success", types.GetProductListRsp{

View File

@ -3,17 +3,14 @@ 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"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
type GetSuccessRecommandLogic struct {
@ -30,6 +27,7 @@ func NewGetSuccessRecommandLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
}
// 获取推荐的产品列表
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo auth.UserInfo) (resp *types.Response) {
resp = &types.Response{}
//校验前台登录情况
@ -49,15 +47,15 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
resp.Set(constants.CODE_UNAUTH, "failed to get user info")
return
}
if req.Num == 0 {
if req.Num == 0 || req.Num > 500 {
req.Num = 8
}
if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size)
}
//获取所有产品的ids
//随机取8个产品
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
productList, err := productModel.GetAllProductList(l.ctx, 0, 1, "sort-asc")
productList, err := productModel.GetRandomProductList(l.ctx, int(req.Num))
if err != nil {
logx.Error(err)
resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list")
@ -68,23 +66,30 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
resp.Set(constants.CODE_OK, "success")
return
}
productIds := make([]string, 0, len(productList))
list := make([]types.GetSuccessRecommandRsp, 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])
data := types.GetSuccessRecommandRsp{
Title: v.Title,
Sn: v.Sn,
Id: v.Id,
SkuId: 0, //???????
}
productIds = tmpProductIds
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(userInfo.IsThousandFace),
Cover: v.Cover,
CoverImg: v.CoverImg,
CoverDefault: v.CoverImg,
ProductId: v.Id,
UserInfo: *userInfo,
}
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
data.Cover = thousandFaceImageFormatReq.Cover
data.CoverImg = thousandFaceImageFormatReq.CoverImg
data.CoverDefault = thousandFaceImageFormatReq.CoverDefault
list = append(list, data)
}
return resp
resp.SetWithData(constants.CODE_OK, "success", list)
return
}

View File

@ -1,11 +1,20 @@
package image
import (
"fmt"
"fusenapi/constants"
"fusenapi/model"
"strings"
"time"
)
// 定义尺寸规则
var sizeArray = []uint32{1200, 1000, 750, 500, 128}
// 裁剪尺寸阶梯
var newSizeArray = []uint32{200, 400, 600, 800}
// 获取合适尺寸
func GetCurrentSize(clientSize uint32) uint32 {
lenNewSize := len(newSizeArray)
//大于最大尺寸则返回规则最大尺寸
@ -23,3 +32,34 @@ func GetCurrentSize(clientSize uint32) uint32 {
}
return clientSize
}
// 千人前面图像拼接
type ThousandFaceImageFormatReq struct {
Size int
IsThousandFace int
Cover string
CoverImg string
CoverDefault string
ProductId int64
UserInfo model.FsUser
}
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
if req.Size > 0 {
coverSlice := strings.Split(req.Cover, ".")
coverImgSlice := strings.Split(req.CoverImg, ".")
if req.Size >= 200 && len(coverSlice) == 2 && len(coverImgSlice) == 2 {
req.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
req.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
//千人千面处理
if req.IsThousandFace == 1 {
req.Cover = ""
req.CoverDefault = req.CoverImg
if req.Size >= 200 && len(coverSlice) == 2 && len(coverImgSlice) == 2 {
req.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, req.UserInfo.Id, req.UserInfo.Id, req.ProductId, time.Now().Unix())
req.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
}
}
}