Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
ef50dbb6fe
|
@ -1,6 +1,10 @@
|
||||||
package model
|
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)
|
var _ FsProductModel = (*customFsProductModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +13,8 @@ type (
|
||||||
// and implement the added methods in customFsProductModel.
|
// and implement the added methods in customFsProductModel.
|
||||||
FsProductModel interface {
|
FsProductModel interface {
|
||||||
fsProductModel
|
fsProductModel
|
||||||
|
GetProductListByConditions(ctx context.Context, productType int, sort string) ([]FsProduct, error)
|
||||||
|
GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsProductModel struct {
|
customFsProductModel struct {
|
||||||
|
@ -22,3 +28,29 @@ func NewFsProductModel(conn sqlx.SqlConn) FsProductModel {
|
||||||
defaultFsProductModel: newFsProductModel(conn),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package model
|
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)
|
var _ FsProductModel3dLightModel = (*customFsProductModel3dLightModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +14,7 @@ type (
|
||||||
// and implement the added methods in customFsProductModel3dLightModel.
|
// and implement the added methods in customFsProductModel3dLightModel.
|
||||||
FsProductModel3dLightModel interface {
|
FsProductModel3dLightModel interface {
|
||||||
fsProductModel3dLightModel
|
fsProductModel3dLightModel
|
||||||
|
ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsProductModel3dLightModel struct {
|
customFsProductModel3dLightModel struct {
|
||||||
|
@ -22,3 +28,11 @@ func NewFsProductModel3dLightModel(conn sqlx.SqlConn) FsProductModel3dLightModel
|
||||||
defaultFsProductModel3dLightModel: newFsProductModel3dLightModel(conn),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ type (
|
||||||
FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error)
|
FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error)
|
||||||
Update(ctx context.Context, data *FsProductModel3dLight) error
|
Update(ctx context.Context, data *FsProductModel3dLight) error
|
||||||
Delete(ctx context.Context, id int64) error
|
Delete(ctx context.Context, id int64) error
|
||||||
ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFsProductModel3dLightModel struct {
|
defaultFsProductModel3dLightModel struct {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package model
|
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)
|
var _ FsProductModel3dModel = (*customFsProductModel3dModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +14,7 @@ type (
|
||||||
// and implement the added methods in customFsProductModel3dModel.
|
// and implement the added methods in customFsProductModel3dModel.
|
||||||
FsProductModel3dModel interface {
|
FsProductModel3dModel interface {
|
||||||
fsProductModel3dModel
|
fsProductModel3dModel
|
||||||
|
ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsProductModel3dModel struct {
|
customFsProductModel3dModel struct {
|
||||||
|
@ -22,3 +28,14 @@ func NewFsProductModel3dModel(conn sqlx.SqlConn) FsProductModel3dModel {
|
||||||
defaultFsProductModel3dModel: newFsProductModel3dModel(conn),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ type (
|
||||||
FindOne(ctx context.Context, id int64) (*FsProductModel3d, error)
|
FindOne(ctx context.Context, id int64) (*FsProductModel3d, error)
|
||||||
Update(ctx context.Context, data *FsProductModel3d) error
|
Update(ctx context.Context, data *FsProductModel3d) error
|
||||||
Delete(ctx context.Context, id int64) error
|
Delete(ctx context.Context, id int64) error
|
||||||
ListBySizeIdsTag(ctx context.Context, sizeIds []string, tag int) (resp []FsProductModel3d, err error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFsProductModel3dModel struct {
|
defaultFsProductModel3dModel struct {
|
||||||
|
|
|
@ -28,8 +28,6 @@ type (
|
||||||
FindOneBySn(ctx context.Context, sn string) (*FsProduct, error)
|
FindOneBySn(ctx context.Context, sn string) (*FsProduct, error)
|
||||||
Update(ctx context.Context, data *FsProduct) error
|
Update(ctx context.Context, data *FsProduct) error
|
||||||
Delete(ctx context.Context, id int64) 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 {
|
defaultFsProductModel struct {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package model
|
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)
|
var _ FsProductPriceModel = (*customFsProductPriceModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +15,8 @@ type (
|
||||||
// and implement the added methods in customFsProductPriceModel.
|
// and implement the added methods in customFsProductPriceModel.
|
||||||
FsProductPriceModel interface {
|
FsProductPriceModel interface {
|
||||||
fsProductPriceModel
|
fsProductPriceModel
|
||||||
|
GetPriceList(ctx context.Context, productIds []string) ([]GetPriceListRsp, error)
|
||||||
|
FindOneByProductIdMaterialIdSizeId(ctx context.Context, productId int64, materialId int64, sizeId int64) (*FsProductPrice, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsProductPriceModel struct {
|
customFsProductPriceModel struct {
|
||||||
|
@ -22,3 +30,32 @@ func NewFsProductPriceModel(conn sqlx.SqlConn) FsProductPriceModel {
|
||||||
defaultFsProductPriceModel: newFsProductPriceModel(conn),
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,10 +25,8 @@ type (
|
||||||
fsProductPriceModel interface {
|
fsProductPriceModel interface {
|
||||||
Insert(ctx context.Context, data *FsProductPrice) (sql.Result, error)
|
Insert(ctx context.Context, data *FsProductPrice) (sql.Result, error)
|
||||||
FindOne(ctx context.Context, id int64) (*FsProductPrice, 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
|
Update(ctx context.Context, data *FsProductPrice) error
|
||||||
Delete(ctx context.Context, id int64) error
|
Delete(ctx context.Context, id int64) error
|
||||||
GetPriceList(ctx context.Context, productIds []string) ([]GetPriceListRsp, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFsProductPriceModel struct {
|
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) {
|
func (m *defaultFsProductPriceModel) Insert(ctx context.Context, data *FsProductPrice) (sql.Result, error) {
|
||||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsProductPriceRowsExpectAutoSet)
|
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)
|
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)
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package model
|
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)
|
var _ FsProductSizeModel = (*customFsProductSizeModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +13,8 @@ type (
|
||||||
// and implement the added methods in customFsProductSizeModel.
|
// and implement the added methods in customFsProductSizeModel.
|
||||||
FsProductSizeModel interface {
|
FsProductSizeModel interface {
|
||||||
fsProductSizeModel
|
fsProductSizeModel
|
||||||
|
CountByStatus(ctx context.Context, status int) (total int, err error)
|
||||||
|
FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsProductSizeModel struct {
|
customFsProductSizeModel struct {
|
||||||
|
@ -22,3 +28,25 @@ func NewFsProductSizeModel(conn sqlx.SqlConn) FsProductSizeModel {
|
||||||
defaultFsProductSizeModel: newFsProductSizeModel(conn),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@ type (
|
||||||
FindOne(ctx context.Context, id int64) (*FsProductSize, error)
|
FindOne(ctx context.Context, id int64) (*FsProductSize, error)
|
||||||
Update(ctx context.Context, data *FsProductSize) error
|
Update(ctx context.Context, data *FsProductSize) error
|
||||||
Delete(ctx context.Context, id int64) 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 {
|
defaultFsProductSizeModel struct {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package model
|
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)
|
var _ FsProductTemplateTagsModel = (*customFsProductTemplateTagsModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +13,7 @@ type (
|
||||||
// and implement the added methods in customFsProductTemplateTagsModel.
|
// and implement the added methods in customFsProductTemplateTagsModel.
|
||||||
FsProductTemplateTagsModel interface {
|
FsProductTemplateTagsModel interface {
|
||||||
fsProductTemplateTagsModel
|
fsProductTemplateTagsModel
|
||||||
|
ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsProductTemplateTagsModel struct {
|
customFsProductTemplateTagsModel struct {
|
||||||
|
@ -22,3 +27,14 @@ func NewFsProductTemplateTagsModel(conn sqlx.SqlConn) FsProductTemplateTagsModel
|
||||||
defaultFsProductTemplateTagsModel: newFsProductTemplateTagsModel(conn),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ type (
|
||||||
FindOne(ctx context.Context, id int64) (*FsProductTemplateTags, error)
|
FindOne(ctx context.Context, id int64) (*FsProductTemplateTags, error)
|
||||||
Update(ctx context.Context, data *FsProductTemplateTags) error
|
Update(ctx context.Context, data *FsProductTemplateTags) error
|
||||||
Delete(ctx context.Context, id int64) error
|
Delete(ctx context.Context, id int64) error
|
||||||
ListByIds(ctx context.Context, ids []string) (resp []FsProductTemplateTags, err error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFsProductTemplateTagsModel struct {
|
defaultFsProductTemplateTagsModel struct {
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package model
|
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)
|
var _ FsProductTemplateV2Model = (*customFsProductTemplateV2Model)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +14,9 @@ type (
|
||||||
// and implement the added methods in customFsProductTemplateV2Model.
|
// and implement the added methods in customFsProductTemplateV2Model.
|
||||||
FsProductTemplateV2Model interface {
|
FsProductTemplateV2Model interface {
|
||||||
fsProductTemplateV2Model
|
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 {
|
customFsProductTemplateV2Model struct {
|
||||||
|
@ -22,3 +30,43 @@ func NewFsProductTemplateV2Model(conn sqlx.SqlConn) FsProductTemplateV2Model {
|
||||||
defaultFsProductTemplateV2Model: newFsProductTemplateV2Model(conn),
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -27,9 +27,6 @@ type (
|
||||||
FindOne(ctx context.Context, id int64) (*FsProductTemplateV2, error)
|
FindOne(ctx context.Context, id int64) (*FsProductTemplateV2, error)
|
||||||
Update(ctx context.Context, data *FsProductTemplateV2) error
|
Update(ctx context.Context, data *FsProductTemplateV2) error
|
||||||
Delete(ctx context.Context, id int64) 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 {
|
defaultFsProductTemplateV2Model struct {
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
// Code generated by goctl. DO NOT EDIT.
|
|
||||||
|
|
||||||
package model
|
|
|
@ -21,7 +21,7 @@ func GetProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
Code: 510,
|
Code: 510,
|
||||||
Message: "parameter error",
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
logx.Info(err)
|
logx.Info(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -21,7 +21,7 @@ func GetSuccessRecommandHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
if err := httpx.Parse(r, &req); err != nil {
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||||
Code: 510,
|
Code: 510,
|
||||||
Message: "parameter error",
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
logx.Info(err)
|
logx.Info(err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,12 +12,10 @@ import (
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetProductListLogic struct {
|
type GetProductListLogic struct {
|
||||||
|
@ -73,7 +71,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
|
||||||
}
|
}
|
||||||
//查询符合的产品列表
|
//查询符合的产品列表
|
||||||
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
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 {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list")
|
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)
|
itemList := make([]types.Items, 0, productLen)
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
minPrice, ok := mapProductMinPrice[v.Id]
|
minPrice, ok := mapProductMinPrice[v.Id]
|
||||||
//无最小价格则不显示
|
_, tmpOk := mapProductTemplate[v.Id]
|
||||||
if !ok {
|
//无最小价格则不显示 || 没有模板也不显示
|
||||||
continue
|
if !ok || !tmpOk {
|
||||||
}
|
|
||||||
_, ok = mapProductTemplate[v.Id]
|
|
||||||
//没有模板也不显示
|
|
||||||
if !ok {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
item := types.Items{
|
item := types.Items{
|
||||||
Id: v.Id,
|
Id: v.Id,
|
||||||
Sn: v.Sn,
|
Sn: v.Sn,
|
||||||
Title: v.Title,
|
Title: v.Title,
|
||||||
Cover: v.Cover,
|
|
||||||
Intro: v.Intro.String,
|
Intro: v.Intro.String,
|
||||||
CoverImg: v.CoverImg,
|
|
||||||
IsEnv: v.IsProtection,
|
IsEnv: v.IsProtection,
|
||||||
IsMicro: v.IsMicrowave,
|
IsMicro: v.IsMicrowave,
|
||||||
SizeNum: uint32(productSizeCount),
|
SizeNum: uint32(productSizeCount),
|
||||||
MiniPrice: format.CentoDollar(minPrice),
|
MiniPrice: format.CentoDollar(minPrice),
|
||||||
}
|
}
|
||||||
if req.Size > 0 {
|
//千人千面处理
|
||||||
coverSlice := strings.Split(v.Cover, ".")
|
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
|
||||||
coverImgSlice := strings.Split(v.CoverImg, ".")
|
Size: int(req.Size),
|
||||||
if req.Size >= 200 {
|
IsThousandFace: int(userInfo.IsThousandFace),
|
||||||
item.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
|
Cover: v.Cover,
|
||||||
item.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
CoverImg: v.CoverImg,
|
||||||
}
|
CoverDefault: v.CoverImg,
|
||||||
//千人千面处理
|
ProductId: v.Id,
|
||||||
if userInfo.IsThousandFace == 1 {
|
UserInfo: *userInfo,
|
||||||
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])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
|
||||||
|
item.Cover = thousandFaceImageFormatReq.Cover
|
||||||
|
item.CoverImg = thousandFaceImageFormatReq.CoverImg
|
||||||
|
item.CoverDefault = thousandFaceImageFormatReq.CoverDefault
|
||||||
itemList = append(itemList, item)
|
itemList = append(itemList, item)
|
||||||
}
|
}
|
||||||
resp.SetWithData(constants.CODE_OK, "success", types.GetProductListRsp{
|
resp.SetWithData(constants.CODE_OK, "success", types.GetProductListRsp{
|
||||||
|
|
|
@ -3,17 +3,14 @@ package logic
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model"
|
"fusenapi/model"
|
||||||
"fusenapi/product/internal/svc"
|
"fusenapi/product/internal/svc"
|
||||||
"fusenapi/product/internal/types"
|
"fusenapi/product/internal/types"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/image"
|
"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/logx"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetSuccessRecommandLogic struct {
|
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) {
|
func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessRecommandReq, loginInfo auth.UserInfo) (resp *types.Response) {
|
||||||
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")
|
resp.Set(constants.CODE_UNAUTH, "failed to get user info")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if req.Num == 0 {
|
if req.Num == 0 || req.Num > 500 {
|
||||||
req.Num = 8
|
req.Num = 8
|
||||||
}
|
}
|
||||||
if req.Size > 0 {
|
if req.Size > 0 {
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
}
|
}
|
||||||
//获取所有产品的ids
|
//随机取8个产品
|
||||||
productModel := model.NewFsProductModel(l.svcCtx.MysqlConn)
|
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 {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
resp.Set(constants.CODE_SERVICE_ERR, "failed to get product list")
|
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")
|
resp.Set(constants.CODE_OK, "success")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
productIds := make([]string, 0, len(productList))
|
list := make([]types.GetSuccessRecommandRsp, 0, len(productList))
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
productIds = append(productIds, fmt.Sprintf("%d", v.Id))
|
data := types.GetSuccessRecommandRsp{
|
||||||
}
|
Title: v.Title,
|
||||||
//随机取8个
|
Sn: v.Sn,
|
||||||
if len(productIds) > int(req.Num) {
|
Id: v.Id,
|
||||||
//打乱顺序
|
SkuId: 0, //???????
|
||||||
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
|
//千人千面处理
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
resp.SetWithData(constants.CODE_OK, "success", list)
|
||||||
return resp
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
package image
|
package image
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"fusenapi/model"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// 定义尺寸规则
|
// 定义尺寸规则
|
||||||
var sizeArray = []uint32{1200, 1000, 750, 500, 128}
|
var sizeArray = []uint32{1200, 1000, 750, 500, 128}
|
||||||
|
|
||||||
// 裁剪尺寸阶梯
|
// 裁剪尺寸阶梯
|
||||||
var newSizeArray = []uint32{200, 400, 600, 800}
|
var newSizeArray = []uint32{200, 400, 600, 800}
|
||||||
|
|
||||||
|
// 获取合适尺寸
|
||||||
func GetCurrentSize(clientSize uint32) uint32 {
|
func GetCurrentSize(clientSize uint32) uint32 {
|
||||||
lenNewSize := len(newSizeArray)
|
lenNewSize := len(newSizeArray)
|
||||||
//大于最大尺寸则返回规则最大尺寸
|
//大于最大尺寸则返回规则最大尺寸
|
||||||
|
@ -23,3 +32,34 @@ func GetCurrentSize(clientSize uint32) uint32 {
|
||||||
}
|
}
|
||||||
return clientSize
|
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])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user