Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into feature/auth
This commit is contained in:
commit
056101121b
@ -8,4 +8,13 @@ const (
|
|||||||
RABBIT_MQ_ASSEMBLE_RENDER_DATA RABBIT_MQ = "RABBIT_MQ_ASSEMBLE_RENDER_DATA"
|
RABBIT_MQ_ASSEMBLE_RENDER_DATA RABBIT_MQ = "RABBIT_MQ_ASSEMBLE_RENDER_DATA"
|
||||||
//渲染结果数据队列
|
//渲染结果数据队列
|
||||||
RABBIT_MQ_RENDER_RESULT_DATA RABBIT_MQ = "RABBIT_MQ_RENDER_RESULT_DATA"
|
RABBIT_MQ_RENDER_RESULT_DATA RABBIT_MQ = "RABBIT_MQ_RENDER_RESULT_DATA"
|
||||||
|
//原来发送到unity渲染的队列
|
||||||
|
RABBIT_MQ_TO_UNITY RABBIT_MQ = "newTaskQueue"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 队列列表
|
||||||
|
var MqQueueArr = []RABBIT_MQ{
|
||||||
|
RABBIT_MQ_ASSEMBLE_RENDER_DATA,
|
||||||
|
RABBIT_MQ_RENDER_RESULT_DATA,
|
||||||
|
RABBIT_MQ_TO_UNITY,
|
||||||
|
}
|
||||||
|
@ -32,10 +32,10 @@ func InitMysql(sourceMysql string) *gorm.DB {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
// SetMaxIdleConns 设置空闲连接池中连接的最大数量
|
||||||
sqlDB.SetMaxIdleConns(10)
|
sqlDB.SetMaxIdleConns(4)
|
||||||
|
|
||||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||||
sqlDB.SetMaxOpenConns(50)
|
sqlDB.SetMaxOpenConns(25)
|
||||||
|
|
||||||
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
||||||
sqlDB.SetConnMaxLifetime(time.Minute * 20)
|
sqlDB.SetConnMaxLifetime(time.Minute * 20)
|
||||||
|
@ -21,12 +21,6 @@ type queueItem struct {
|
|||||||
queue amqp.Queue
|
queue amqp.Queue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 队列列表
|
|
||||||
var mqQueueArr = []constants.RABBIT_MQ{
|
|
||||||
constants.RABBIT_MQ_ASSEMBLE_RENDER_DATA,
|
|
||||||
constants.RABBIT_MQ_RENDER_RESULT_DATA,
|
|
||||||
}
|
|
||||||
|
|
||||||
// 存储连接
|
// 存储连接
|
||||||
var mapMq = make(map[constants.RABBIT_MQ]queueItem)
|
var mapMq = make(map[constants.RABBIT_MQ]queueItem)
|
||||||
|
|
||||||
@ -44,7 +38,7 @@ func InitRabbitMq(url string, config *tls.Config) *RabbitMqHandle {
|
|||||||
log.Fatalf("Failed to open a channel: %v", err)
|
log.Fatalf("Failed to open a channel: %v", err)
|
||||||
}
|
}
|
||||||
//声明队列
|
//声明队列
|
||||||
for _, queueName := range mqQueueArr {
|
for _, queueName := range constants.MqQueueArr {
|
||||||
q, err := ch.QueueDeclare(
|
q, err := ch.QueueDeclare(
|
||||||
string(queueName), // 队列名
|
string(queueName), // 队列名
|
||||||
true, // 是否持久化
|
true, // 是否持久化
|
||||||
|
@ -6,12 +6,12 @@ import (
|
|||||||
|
|
||||||
// fs_product_tag_prop 产品标签相关属性表
|
// fs_product_tag_prop 产品标签相关属性表
|
||||||
type FsProductTagProp struct {
|
type FsProductTagProp struct {
|
||||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // id
|
||||||
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id
|
ProductId *int64 `gorm:"default:0;" json:"product_id"` // 产品id
|
||||||
TagId *int64 `gorm:"default:0;" json:"tag_id"` // 模板标签id
|
TemplateTagId *int64 `gorm:"default:0;" json:"template_tag_id"` // 模板标签id
|
||||||
Cover *string `gorm:"default:'';" json:"cover"` //
|
Cover *string `gorm:"default:'';" json:"cover"` //
|
||||||
Status *int64 `gorm:"default:1;" json:"status"` // 状态
|
Status *int64 `gorm:"default:1;" json:"status"` // 状态
|
||||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间
|
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 创建时间
|
||||||
}
|
}
|
||||||
type FsProductTagPropModel struct {
|
type FsProductTagPropModel struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
|
@ -1,2 +1,21 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
// TODO: 使用model的属性做你想做的
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
// TODO: 使用model的属性做你想做的
|
||||||
|
type GetTagPropByProductIdsWithProductTagRsp struct {
|
||||||
|
FsProductTagProp
|
||||||
|
Title string `json:"title"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *FsProductTagPropModel) GetTagPropByProductIdsWithProductTag(ctx context.Context, productIds []int64) (resp []GetTagPropByProductIdsWithProductTagRsp, err error) {
|
||||||
|
if len(productIds) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = p.db.WithContext(ctx).Table(p.name+" as p ").
|
||||||
|
Joins("left join fs_product_template_tags as t on p.template_tag_id = t.id").
|
||||||
|
Select("p.*,t.title as title").
|
||||||
|
Where("p.product_id in (?) and p.status = ? and t.status = ?", productIds, 1, 1).
|
||||||
|
Find(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
package gmodel
|
package gmodel
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
// TODO: 使用model的属性做你想做的
|
// TODO: 使用model的属性做你想做的
|
||||||
|
|
||||||
|
func (e *FsProductTemplateElementModel) FindOneByModelId(ctx context.Context, modelId int64) (resp *FsProductTemplateElement, err error) {
|
||||||
|
err = e.db.WithContext(ctx).Model(&FsProductTemplateElement{}).
|
||||||
|
//以前的神仙员工把表model_id变成product_template_id
|
||||||
|
Where("`product_template_id` = ?", modelId).
|
||||||
|
Take(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
@ -57,6 +57,9 @@ func (t *FsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelI
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `is_del` = ? and `status` = ?", modelIds, 0, 1)
|
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `is_del` = ? and `status` = ?", modelIds, 0, 1)
|
||||||
|
if len(fields) != 0 {
|
||||||
|
db = db.Select(fields[0])
|
||||||
|
}
|
||||||
switch orderBy {
|
switch orderBy {
|
||||||
case "":
|
case "":
|
||||||
db = db.Order("id DESC")
|
db = db.Order("id DESC")
|
||||||
@ -119,3 +122,20 @@ func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx cont
|
|||||||
Take(&resp).Error
|
Take(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Context, modelIds []int64, templateTag string, orderBy string, fields ...string) (resp []FsProductTemplateV2, err error) {
|
||||||
|
if len(modelIds) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `tag` = ? and `is_del` = ? and `status` = ?", modelIds, templateTag, 0, 1)
|
||||||
|
if len(fields) != 0 {
|
||||||
|
db = db.Select(fields[0])
|
||||||
|
}
|
||||||
|
switch orderBy {
|
||||||
|
case "":
|
||||||
|
db = db.Order("id DESC")
|
||||||
|
default:
|
||||||
|
db = db.Order(orderBy)
|
||||||
|
}
|
||||||
|
err = db.Find(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
@ -6,7 +6,9 @@ import (
|
|||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/format"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"context"
|
"context"
|
||||||
@ -52,8 +54,38 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get size list")
|
||||||
}
|
}
|
||||||
sizeIds := make([]int64, 0, len(sizeList))
|
sizeIds := make([]int64, 0, len(sizeList))
|
||||||
|
productIds := make([]int64, 0, len(sizeList))
|
||||||
for _, v := range sizeList {
|
for _, v := range sizeList {
|
||||||
sizeIds = append(sizeIds, v.Id)
|
sizeIds = append(sizeIds, v.Id)
|
||||||
|
productIds = append(productIds, *v.ProductId)
|
||||||
|
}
|
||||||
|
//获取产品价格列表
|
||||||
|
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list")
|
||||||
|
}
|
||||||
|
mapProductMinPrice := make(map[int64]int64)
|
||||||
|
//存储产品最小价格
|
||||||
|
for _, v := range productPriceList {
|
||||||
|
priceStrSlic := strings.Split(v.Price, ",")
|
||||||
|
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||||
|
}
|
||||||
|
if len(priceSlice) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
|
||||||
|
sort.Ints(priceSlice)
|
||||||
|
if min, ok := mapProductMinPrice[v.ProductId]; ok {
|
||||||
|
if min > int64(priceSlice[0]) {
|
||||||
|
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mapProductMinPrice[v.ProductId] = int64(priceSlice[0])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//获取对应模型数据
|
//获取对应模型数据
|
||||||
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id")
|
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id")
|
||||||
@ -75,6 +107,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||||||
}
|
}
|
||||||
var title interface{}
|
var title interface{}
|
||||||
_ = json.Unmarshal([]byte(*sizeInfo.Title), &title)
|
_ = json.Unmarshal([]byte(*sizeInfo.Title), &title)
|
||||||
|
minPrice := int64(0)
|
||||||
|
if price, ok := mapProductMinPrice[*sizeInfo.ProductId]; ok {
|
||||||
|
minPrice = price
|
||||||
|
}
|
||||||
listRsp = append(listRsp, types.GetSizeByPidRsp{
|
listRsp = append(listRsp, types.GetSizeByPidRsp{
|
||||||
Id: sizeInfo.Id,
|
Id: sizeInfo.Id,
|
||||||
Title: title,
|
Title: title,
|
||||||
@ -83,6 +119,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
|
|||||||
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
|
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
|
||||||
ModelId: modelList[modelIndex].Id,
|
ModelId: modelList[modelIndex].Id,
|
||||||
IsPopular: *sizeInfo.IsPopular > 0,
|
IsPopular: *sizeInfo.IsPopular > 0,
|
||||||
|
MinPrice: float64(minPrice) / 100,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", listRsp)
|
||||||
|
@ -34,16 +34,16 @@ func NewGetTagProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListReq, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||||
//获取合适尺寸
|
|
||||||
if req.Size > 0 {
|
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
|
||||||
}
|
|
||||||
//查询用户信息(不用判断存在)
|
//查询用户信息(不用判断存在)
|
||||||
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
}
|
}
|
||||||
|
//获取合适尺寸
|
||||||
|
if req.Size > 0 {
|
||||||
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
|
}
|
||||||
//查询分类列表
|
//查询分类列表
|
||||||
tStatus := int64(1)
|
tStatus := int64(1)
|
||||||
tReq := gmodel.GetAllTagByParamsReq{
|
tReq := gmodel.GetAllTagByParamsReq{
|
||||||
@ -81,7 +81,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
typeIds = append(typeIds, v.Id)
|
typeIds = append(typeIds, v.Id)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
productList []gmodel.FsProduct //产品列表(select 字段需要看查询的地方)
|
||||||
|
mapTagProp = make(map[int64][]types.CoverDefaultItem)
|
||||||
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
productOptionalPartList []gmodel.GetGroupPartListByProductIdsRsp //产品配件列表
|
||||||
mapProductHaveOptionFitting = make(map[int64]struct{})
|
mapProductHaveOptionFitting = make(map[int64]struct{})
|
||||||
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
productPriceList []gmodel.GetPriceListByProductIdsRsp //产品价格列表(select 字段需要看查询的地方)
|
||||||
@ -129,6 +130,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
}
|
}
|
||||||
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
mapProductHaveOptionFitting[partList.ProductId] = struct{}{}
|
||||||
}
|
}
|
||||||
|
//获取产品标签相关属性
|
||||||
|
productTagPropList, err := l.svcCtx.AllModels.FsProductTagProp.GetTagPropByProductIdsWithProductTag(l.ctx, productIds)
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product tag property")
|
||||||
|
}
|
||||||
|
for _, v := range productTagPropList {
|
||||||
|
mapTagProp[*v.ProductId] = append(mapTagProp[*v.ProductId], types.CoverDefaultItem{
|
||||||
|
Tag: v.Title,
|
||||||
|
Cover: *v.Cover,
|
||||||
|
})
|
||||||
|
}
|
||||||
//获取产品价格列表
|
//获取产品价格列表
|
||||||
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
productPriceList, err = l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -183,6 +196,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
|||||||
TagList: tagList,
|
TagList: tagList,
|
||||||
WithProduct: req.WithProduct,
|
WithProduct: req.WithProduct,
|
||||||
ProductList: productList,
|
ProductList: productList,
|
||||||
|
MapTagProp: mapTagProp,
|
||||||
MapProductMinPrice: mapProductMinPrice,
|
MapProductMinPrice: mapProductMinPrice,
|
||||||
MapProductTemplate: mapProductTemplate,
|
MapProductTemplate: mapProductTemplate,
|
||||||
MapProductSizeCount: mapProductSizeCount,
|
MapProductSizeCount: mapProductSizeCount,
|
||||||
@ -206,6 +220,8 @@ type dealWithTagMenuDataReq struct {
|
|||||||
TagList []gmodel.FsTags
|
TagList []gmodel.FsTags
|
||||||
WithProduct bool
|
WithProduct bool
|
||||||
ProductList []gmodel.FsProduct
|
ProductList []gmodel.FsProduct
|
||||||
|
MapTagProp map[int64][]types.CoverDefaultItem
|
||||||
|
ProductTagPropList []gmodel.FsProductTagProp
|
||||||
MapProductMinPrice map[int64]int64
|
MapProductMinPrice map[int64]int64
|
||||||
MapProductTemplate map[int64]struct{}
|
MapProductTemplate map[int64]struct{}
|
||||||
MapProductSizeCount map[int64]int64
|
MapProductSizeCount map[int64]int64
|
||||||
@ -238,6 +254,7 @@ func (l *GetTagProductListLogic) dealWithTagMenuData(req dealWithTagMenuDataReq)
|
|||||||
productListRsp := l.getTagProducts(getTagProductsReq{
|
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||||
TagId: tagInfo.Id,
|
TagId: tagInfo.Id,
|
||||||
ProductList: req.ProductList,
|
ProductList: req.ProductList,
|
||||||
|
MapTagProp: req.MapTagProp,
|
||||||
MapProductMinPrice: req.MapProductMinPrice,
|
MapProductMinPrice: req.MapProductMinPrice,
|
||||||
MapProductTemplate: req.MapProductTemplate,
|
MapProductTemplate: req.MapProductTemplate,
|
||||||
MapProductSizeCount: req.MapProductSizeCount,
|
MapProductSizeCount: req.MapProductSizeCount,
|
||||||
@ -308,6 +325,7 @@ func (l *GetTagProductListLogic) organizationLevelRelation(minLevel int, mapTagL
|
|||||||
type getTagProductsReq struct {
|
type getTagProductsReq struct {
|
||||||
TagId int64
|
TagId int64
|
||||||
ProductList []gmodel.FsProduct
|
ProductList []gmodel.FsProduct
|
||||||
|
MapTagProp map[int64][]types.CoverDefaultItem
|
||||||
MapProductMinPrice map[int64]int64
|
MapProductMinPrice map[int64]int64
|
||||||
MapProductTemplate map[int64]struct{}
|
MapProductTemplate map[int64]struct{}
|
||||||
MapProductSizeCount map[int64]int64
|
MapProductSizeCount map[int64]int64
|
||||||
@ -344,17 +362,20 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
|||||||
Sn: *productInfo.Sn,
|
Sn: *productInfo.Sn,
|
||||||
Title: *productInfo.Title,
|
Title: *productInfo.Title,
|
||||||
SizeNum: uint32(sizeNum),
|
SizeNum: uint32(sizeNum),
|
||||||
|
CoverDefault: []types.CoverDefaultItem{},
|
||||||
MinPrice: minPrice,
|
MinPrice: minPrice,
|
||||||
HaveOptionalFitting: haveOptionalFitting,
|
HaveOptionalFitting: haveOptionalFitting,
|
||||||
Recommended: *productInfo.IsRecommend > 0,
|
Recommended: *productInfo.IsRecommend > 0,
|
||||||
}
|
}
|
||||||
|
if _, ok = req.MapTagProp[productInfo.Id]; ok {
|
||||||
|
item.CoverDefault = req.MapTagProp[productInfo.Id]
|
||||||
|
}
|
||||||
//千人千面处理
|
//千人千面处理
|
||||||
r := image.ThousandFaceImageFormatReq{
|
r := image.ThousandFaceImageFormatReq{
|
||||||
Size: int(req.Size),
|
Size: int(req.Size),
|
||||||
IsThousandFace: 0,
|
IsThousandFace: 0,
|
||||||
Cover: *productInfo.Cover,
|
Cover: *productInfo.Cover,
|
||||||
CoverImg: *productInfo.CoverImg,
|
CoverImg: *productInfo.CoverImg,
|
||||||
CoverDefault: *productInfo.CoverImg,
|
|
||||||
ProductId: productInfo.Id,
|
ProductId: productInfo.Id,
|
||||||
UserId: req.User.Id,
|
UserId: req.User.Id,
|
||||||
}
|
}
|
||||||
@ -363,7 +384,6 @@ func (l *GetTagProductListLogic) getTagProducts(req getTagProductsReq) (productL
|
|||||||
}
|
}
|
||||||
image.ThousandFaceImageFormat(&r)
|
image.ThousandFaceImageFormat(&r)
|
||||||
item.Cover = r.Cover
|
item.Cover = r.Cover
|
||||||
item.CoverDefault = nil
|
|
||||||
//加入分类产品切片
|
//加入分类产品切片
|
||||||
productListRsp = append(productListRsp, item)
|
productListRsp = append(productListRsp, item)
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,9 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
|||||||
if req.Size > 0 {
|
if req.Size > 0 {
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
}
|
}
|
||||||
|
if req.ProductTemplateTagId <= 0 {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id")
|
||||||
|
}
|
||||||
//获取产品信息(只是获取id)
|
//获取产品信息(只是获取id)
|
||||||
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -51,7 +54,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
|||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||||
}
|
}
|
||||||
//获取尺寸ids(只获取)
|
//获取尺寸ids(只获取id)
|
||||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id")
|
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
@ -80,7 +83,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
|
|||||||
mapModel[v.Id] = k
|
mapModel[v.Id] = k
|
||||||
}
|
}
|
||||||
//获取模板数据
|
//获取模板数据
|
||||||
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIds(l.ctx, modelIds, "sort DESC")
|
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "sort DESC")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product templates")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product templates")
|
||||||
|
@ -336,11 +336,13 @@ type GetSizeByPidRsp struct {
|
|||||||
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
||||||
ModelId int64 `json:"model_id"` //产品主模型id
|
ModelId int64 `json:"model_id"` //产品主模型id
|
||||||
IsPopular bool `json:"is_popular"` //是否受欢迎
|
IsPopular bool `json:"is_popular"` //是否受欢迎
|
||||||
|
MinPrice float64 `json:"min_price"` //最小价格
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetTemplateByPidReq struct {
|
type GetTemplateByPidReq struct {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
Size uint32 `form:"size"`
|
Size uint32 `form:"size"`
|
||||||
|
ProductTemplateTagId int64 `form:"product_template_tag_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetFittingByPidReq struct {
|
type GetFittingByPidReq struct {
|
||||||
|
@ -6,12 +6,15 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"fusenapi/constants"
|
||||||
|
"fusenapi/initalize"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/websocket_data"
|
"fusenapi/utils/websocket_data"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -73,10 +76,11 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
|||||||
pyapiBeginTime := time.Now().UnixMilli()
|
pyapiBeginTime := time.Now().UnixMilli()
|
||||||
//这里curl post请求数据。获取处理好的贴图数据,用于贴model的贴图
|
//这里curl post请求数据。获取处理好的贴图数据,用于贴model的贴图
|
||||||
pythonPostData := map[string]interface{}{
|
pythonPostData := map[string]interface{}{
|
||||||
"tids": templateInfo.Id,
|
"tids": []int64{templateInfo.Id},
|
||||||
"data": parseInfo.RenderData.Data,
|
"data": parseInfo.RenderData.Data,
|
||||||
}
|
}
|
||||||
pyPostBytes, _ := json.Marshal(pythonPostData)
|
pyPostBytes, _ := json.Marshal(pythonPostData)
|
||||||
|
//post 数据结构 `{"tids":[128,431],"data":[{"id":"9d35ac5a-81a0-3caf-3246-cdbea9f2ddfe","tag":"MainColor","title":"\u8d34\u56fe2","type":"color","text":"","fill":"#c028b9","fontSize":20,"fontFamily":"Aqum2SmallCaps3","ifBr":false,"ifShow":true,"ifGroup":false,"maxNum":50,"rotation":0,"align":"center","verticalAlign":"middle","material":"","width":1024,"height":1024,"x":0,"y":0,"opacity":1,"optionalColor":[{"color":"#000000","name":"Black","default":true}],"zIndex":2,"svgPath":"","follow":{"fill":"","ifShow":"","content":""},"group":[],"cameraStand":{"x":0,"y":0,"z":0},"proportion":60,"materialName":"","materialTime":""},{"id":"c9be653f-dfc1-5659-1eb8-7ab128abe3d5","tag":"Logo","title":"\u8d34\u56fe4","type":"image","text":"","fill":"#c028b9","fontSize":65,"fontFamily":"MontserratBold3","ifBr":true,"ifShow":true,"ifGroup":false,"maxNum":50,"rotation":0,"align":"center","verticalAlign":"middle","material":"","width":312,"height":144.8044172010362,"x":99,"y":406.49999999999875,"opacity":1,"optionalColor":[{"color":"#000000","name":"Black","default":false},{"color":"#FFFFFF","name":"White","default":false},{"name":"MainColor","color":"#c028b9","default":true}],"zIndex":3,"svgPath":"","follow":{"fill":"","ifShow":"","content":""},"group":[],"cameraStand":{"x":0,"y":0,"z":0},"proportion":60,"materialTime":"","materialName":""},{"id":"e3269e77-b8c2-baec-bb9b-8399915a711c","tag":"Slogan","title":"\u8d34\u56fe5","type":"text","text":"","fill":"","fontSize":16,"fontFamily":"MontserratBold3","ifBr":false,"ifShow":true,"ifGroup":false,"maxNum":50,"rotation":0,"align":"center","verticalAlign":"middle","material":"","width":312,"height":18.999939381668568,"x":99,"y":605.0000538829611,"opacity":1,"optionalColor":[{"color":"#000000","name":"Black","default":true}],"zIndex":4,"svgPath":"","follow":{"fill":"bfc2b5a3-10af-c95b-fbf1-3016540fffad","ifShow":"","content":""},"group":[],"cameraStand":{"x":0,"y":0,"z":36},"proportion":60,"materialName":"","materialTime":""},{"id":"bfc2b5a3-10af-c95b-fbf1-3016540fffad","tag":"SecondaryColor","title":"\u8d34\u56fe9","type":"color","text":"","fill":"#FFFFFF","fontSize":20,"fontFamily":"Aqum2SmallCaps3","ifBr":false,"ifShow":true,"ifGroup":false,"maxNum":50,"rotation":0,"align":"center","verticalAlign":"middle","material":"","width":1024,"height":1024,"x":0,"y":0,"opacity":1,"optionalColor":[{"color":"#000000","name":"Black","default":true}],"zIndex":1,"svgPath":"","follow":{"fill":"","ifShow":"","content":""},"group":[],"cameraStand":{"x":0,"y":0,"z":0},"proportion":60}]}`
|
||||||
url := "http://110.41.19.98:8867/imgRender"
|
url := "http://110.41.19.98:8867/imgRender"
|
||||||
pyRsp, err := http.Post(url, "application/json;charset=UTF-8", bytes.NewReader(pyPostBytes))
|
pyRsp, err := http.Post(url, "application/json;charset=UTF-8", bytes.NewReader(pyPostBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -102,6 +106,10 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
|||||||
logx.Error("python api 接口没有数据:")
|
logx.Error("python api 接口没有数据:")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
mapImageData := make(map[int64]int)
|
||||||
|
for k, v := range rspInfo.Data {
|
||||||
|
mapImageData[v.Tid] = k
|
||||||
|
}
|
||||||
//云渲染日志
|
//云渲染日志
|
||||||
title = "2-请求->接收python合成刀版图接口"
|
title = "2-请求->接收python合成刀版图接口"
|
||||||
now = time.Now().Unix()
|
now = time.Now().Unix()
|
||||||
@ -140,99 +148,107 @@ func (m *MqConsumerRenderAssemble) Run(ctx context.Context, data []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
}
|
}
|
||||||
|
timePinjieBegin := time.Now().UnixMilli()
|
||||||
//获取渲染设置信息
|
//获取渲染设置信息
|
||||||
//element, err := allmodels.FsProductTemplateElement
|
element, err := allmodels.FsProductTemplateElement.FindOneByModelId(ctx, *templateInfo.ModelId)
|
||||||
/*
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
$element = ProductTemplateElement::find()
|
logx.Error("element info is not found,model_id = ?", *templateInfo.ModelId)
|
||||||
->andFilterWhere(['in', 'product_template_id', $mids])
|
return nil
|
||||||
->asArray()
|
}
|
||||||
->all();
|
logx.Error("failed to get element list,", err)
|
||||||
|
return err
|
||||||
$element = array_column($element, null, 'product_template_id');
|
}
|
||||||
$elementTitles = array_column($element, 'title');
|
//组装数据
|
||||||
|
refletion := -1
|
||||||
$result = [];
|
if element.Refletion != nil && *element.Refletion != "" {
|
||||||
|
refletion, err = strconv.Atoi(*element.Refletion)
|
||||||
$time_pinjie_begin = $render->getMillisecond();
|
}
|
||||||
foreach ($templates as $key => $val) {
|
//组装data数据
|
||||||
if(!isset($element[$val['model_id']]) || !isset($imageData[$val['id']])){
|
var mode map[string]interface{}
|
||||||
continue;
|
if element.Mode != nil && *element.Mode != "" {
|
||||||
}
|
if err = json.Unmarshal([]byte(*element.Mode), &mode); err != nil {
|
||||||
//数据拼装
|
logx.Error("faile to parse element mode json:", err)
|
||||||
$item = [];
|
return err
|
||||||
|
}
|
||||||
$item['light'] = $element[$val['model_id']]['light'];
|
}
|
||||||
$item['refletion'] = $element[$val['model_id']]['refletion'] == '' ? -1 : (int)$element[$val['model_id']]['refletion'];
|
baseImage := ""
|
||||||
$item['scale'] = $element[$val['model_id']]['scale'];
|
if index, ok := mapImageData[templateInfo.Id]; ok {
|
||||||
$item['sku_id'] = $val['product_id'];
|
baseImage = constants.H5_URL + "/storage" + rspInfo.Data[index].Imgurl
|
||||||
$item['tid'] = $element[$val['model_id']]['title'];
|
}
|
||||||
$item['rotation'] = $element[$val['model_id']]['rotation'];
|
tempData := make([]map[string]interface{}, 0, 3)
|
||||||
$item['filePath'] = '';//todo 文件路径,针对千人千面
|
if element.Base != nil && *element.Base != "" {
|
||||||
|
tempData = append(tempData, map[string]interface{}{
|
||||||
//组装data数据
|
"name": "model",
|
||||||
$tempData = [];
|
"data": "0," + baseImage + "," + *element.Base,
|
||||||
//获取材质模式对应关系
|
"type": "other",
|
||||||
$mode = $element[$val['model_id']]['mode'] ? json_decode($element[$val['model_id']]['mode'], true) : [];
|
"layer": "0",
|
||||||
// $base_img = (new ImageService())->base64EncodeImageNoHeader(\Yii::$app->params['baseurl'].$imageData[$val['id']]['imgurl']);
|
"is_update": 1,
|
||||||
$base_img = \Yii::$app->params['h5Url'].'/storage'.$imageData[$val['id']]['imgurl'];
|
"mode": mode["model"],
|
||||||
//判断是否包含base数据 即对应建模那边的model
|
})
|
||||||
if($element[$val['model_id']]['base']){
|
}
|
||||||
$tempData[] = [
|
if element.Shadow != nil && *element.Shadow != "" {
|
||||||
'name' => 'model',
|
tempData = append(tempData, map[string]interface{}{
|
||||||
'data' => '0,'.$base_img.','.$element[$val['model_id']]['base'],
|
"name": "shadow",
|
||||||
'type' => 'other',
|
"data": *element.Shadow,
|
||||||
'layer' => '0',
|
"type": "other",
|
||||||
'is_update' => 1,
|
"layer": "0",
|
||||||
'mode' => $mode['model'],
|
"is_update": 0,
|
||||||
];
|
"mode": mode["shadow"],
|
||||||
}
|
})
|
||||||
if($element[$val['model_id']]['shadow']){
|
}
|
||||||
$tempData[] = [
|
if element.ModelP != nil && *element.ModelP != "" {
|
||||||
'name' => 'shadow',
|
tempData = append(tempData, map[string]interface{}{
|
||||||
'data' => $element[$val['model_id']]['shadow'],
|
"name": "model_P",
|
||||||
'type' => 'other',
|
"data": "0," + *element.ModelP,
|
||||||
'layer' => '0',
|
"type": "other",
|
||||||
'is_update' => 0,
|
"layer": "0",
|
||||||
'mode' => $mode['shadow'],
|
"is_update": 0,
|
||||||
];
|
"mode": mode["model_P"],
|
||||||
}
|
})
|
||||||
if($element[$val['model_id']]['model_p']){
|
}
|
||||||
$tempData[] = [
|
result := []interface{}{
|
||||||
'name' => 'model_P',
|
map[string]interface{}{
|
||||||
'data' => '0,'.$element[$val['model_id']]['model_p'],
|
"light": *element.Light,
|
||||||
'type' => 'other',
|
"refletion": refletion,
|
||||||
'layer' => '0',
|
"scale": *element.Scale,
|
||||||
'is_update' => 0,
|
"sku_id": *templateInfo.ProductId,
|
||||||
'mode' => $mode['model_P'],
|
"tid": *element.Title,
|
||||||
];
|
"rotation": *element.Rotation,
|
||||||
}
|
"filePath": "", //todo 文件路径,针对千人千面
|
||||||
$item['data'] = $tempData;
|
"data": tempData,
|
||||||
$result[] = $item;
|
},
|
||||||
|
}
|
||||||
}
|
timePinjie := time.Now().UnixMilli() - timePinjieBegin
|
||||||
$log = new CloudRenderLog();
|
//云渲染日志
|
||||||
$log->title = '接收到python刀版图 -> 3-组装MQ渲染任务队列';
|
title = "接收到python刀版图 -> 3-组装MQ渲染任务队列"
|
||||||
$log->time = $render->getMillisecond() - $time_pinjie_begin;
|
now = time.Now().Unix()
|
||||||
$log->user_id = $user_id;
|
err = allmodels.FsCloudRenderLog.Create(ctx, &gmodel.FsCloudRenderLog{
|
||||||
$log->post_data = '';
|
UserId: &parseInfo.RenderData.UserId,
|
||||||
$log->post_url = '';
|
Title: &title,
|
||||||
$log->result = $res;
|
Time: &timePinjie,
|
||||||
$log->tag = $inputData['id'];
|
Tag: &parseInfo.RenderId,
|
||||||
$log->ctime = time();
|
Ctime: &now,
|
||||||
$log->save(false);
|
})
|
||||||
}
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
$sendData = [
|
}
|
||||||
'id' => $inputData['id'],
|
sendData := map[string]interface{}{
|
||||||
'order_id' => 0,
|
"id": parseInfo.RenderId,
|
||||||
'user_id' => \Yii::$app->user->id,
|
"order_id": 0,
|
||||||
'sku_ids' => $inputData['sku_ids'],
|
"user_id": parseInfo.RenderData.UserId,
|
||||||
'tids' => $elementTitles,
|
"sku_ids": []int64{parseInfo.RenderData.ProductId},
|
||||||
'data' => $result,
|
"tids": []string{*element.Title},
|
||||||
'is_thousand_face' => 0,
|
"data": result,
|
||||||
'folder' => '',//todo 千人千面需要使用
|
"is_thousand_face": 0,
|
||||||
];
|
"folder": "", //todo 千人千面需要使用
|
||||||
return $sendData;*/
|
}
|
||||||
|
b, _ := json.Marshal(sendData)
|
||||||
|
rabbitmq := initalize.RabbitMqHandle{}
|
||||||
|
if err = rabbitmq.SendMsg(constants.RABBIT_MQ_TO_UNITY, b); err != nil {
|
||||||
|
logx.Error("发送渲染组装数据到rabbitmq失败:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
logx.Info("发送渲染组装数据到rabbitmq 成功")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
//鉴权不成功10秒后断开
|
//鉴权不成功10秒后断开
|
||||||
var (
|
/*var (
|
||||||
userInfo *auth.UserInfo
|
userInfo *auth.UserInfo
|
||||||
isAuth bool
|
isAuth bool
|
||||||
)
|
)
|
||||||
@ -103,7 +103,10 @@ func (l *DataTransferLogic) DataTransfer(svcCtx *svc.ServiceContext, w http.Resp
|
|||||||
//发送关闭信息
|
//发送关闭信息
|
||||||
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
_ = conn.WriteMessage(websocket.CloseMessage, nil)
|
||||||
return
|
return
|
||||||
}
|
}*/
|
||||||
|
//测试的目前写死 39
|
||||||
|
var userInfo auth.UserInfo
|
||||||
|
userInfo.UserId = 39
|
||||||
//生成连接唯一标识
|
//生成连接唯一标识
|
||||||
uniqueId := websocketIdGenerator.Get()
|
uniqueId := websocketIdGenerator.Get()
|
||||||
ws := wsConnectItem{
|
ws := wsConnectItem{
|
||||||
|
@ -24,7 +24,7 @@ type renderImageControlChanItem struct {
|
|||||||
|
|
||||||
// 渲染发送到组装数据组装数据
|
// 渲染发送到组装数据组装数据
|
||||||
func (w *wsConnectItem) renderImage(data []byte) {
|
func (w *wsConnectItem) renderImage(data []byte) {
|
||||||
var renderImageData websocket_data.RenderImageReqMsg
|
var renderImageData websocket_data.AssembleRenderData
|
||||||
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
if err := json.Unmarshal(data, &renderImageData); err != nil {
|
||||||
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))
|
w.outChan <- w.respondDataFormat(constants.WEBSOCKET_ERR_DATA_FORMAT, "invalid format of websocket render image message:"+string(data))
|
||||||
logx.Error("invalid format of websocket render image message", err)
|
logx.Error("invalid format of websocket render image message", err)
|
||||||
|
@ -381,11 +381,13 @@ type GetSizeByPidRsp {
|
|||||||
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
|
||||||
ModelId int64 `json:"model_id"` //产品主模型id
|
ModelId int64 `json:"model_id"` //产品主模型id
|
||||||
IsPopular bool `json:"is_popular"` //是否受欢迎
|
IsPopular bool `json:"is_popular"` //是否受欢迎
|
||||||
|
MinPrice float64 `json:"min_price"` //最小价格
|
||||||
}
|
}
|
||||||
//获取产品模板列表
|
//获取产品模板列表
|
||||||
type GetTemplateByPidReq {
|
type GetTemplateByPidReq {
|
||||||
Pid string `form:"pid"`
|
Pid string `form:"pid"`
|
||||||
Size uint32 `form:"size"`
|
Size uint32 `form:"size"`
|
||||||
|
ProductTemplateTagId int64 `form:"product_template_tag_id"`
|
||||||
}
|
}
|
||||||
//获取产品配件数据
|
//获取产品配件数据
|
||||||
type GetFittingByPidReq {
|
type GetFittingByPidReq {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user