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

This commit is contained in:
eson
2023-09-27 11:30:22 +08:00
11 changed files with 212 additions and 109 deletions

View File

@@ -45,8 +45,31 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
var nowTime = time.Now().UTC()
if req.LogoSelectedId == 0 {
return resp.SetStatus(basic.CodeLogoSetCategory, "logo logo_selected_id not null")
NewFsUserMaterialModel1 := gmodel.NewFsUserMaterialModel(l.svcCtx.MysqlConn)
NewFsUserMaterialModelRow1 := NewFsUserMaterialModel1.RowSelectBuilder(nil).Where("id = ?", 0)
defaultMaterialInfo, err := NewFsUserMaterialModel1.FindOne(l.ctx, NewFsUserMaterialModelRow1.Model(&gmodel.FsUserMaterial{}))
if err != nil {
logc.Errorf(l.ctx, "defaultMaterialInfo FindOne err%+v", err)
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
}
var defaultMaterial = gmodel.FsUserMaterial{
Module: defaultMaterialInfo.Module,
UserId: &userinfo.UserId,
GuestId: &userinfo.GuestId,
ResourceId: defaultMaterialInfo.ResourceId,
ResourceUrl: defaultMaterialInfo.ResourceUrl,
Ctime: &nowTime,
}
MaterialCreateRes := l.svcCtx.MysqlConn.Create(&defaultMaterial)
err = MaterialCreateRes.Error
if err != nil {
logc.Errorf(l.ctx, "defaultMaterialInfo Create err%+v", err)
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
}
req.LogoSelectedId = defaultMaterial.Id
}
if req.SetLogoCategory == 1 && req.CategoryId == 0 {
return resp.SetStatus(basic.CodeLogoSetCategory, "logo category_id not null")
@@ -73,7 +96,6 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
return resp.SetStatus(basic.CodeLogoSetCategory, "logo not find")
}
var nowTime = time.Now().UTC()
err = l.svcCtx.MysqlConn.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error {
var metadataMapOldUserMaterial map[string]interface{}
if userMaterialInfo.Metadata != nil {

View File

@@ -105,11 +105,18 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
}
}
stepRange := make([]interface{}, 0, rangeLen)
for _, rangeInfo := range stepPrice.PriceRange {
for rIndex, rangeInfo := range stepPrice.PriceRange {
//最后一个
if rIndex+1 == rangeLen {
stepRange = append(stepRange, map[string]interface{}{
"range_description": fmt.Sprintf(">=%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity)),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
})
break
}
stepRange = append(stepRange, map[string]interface{}{
"start_quantity": rangeInfo.StartQuantity,
"end_quantity": rangeInfo.EndQuantity,
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
"range_description": fmt.Sprintf("%s-%s Units", format.NumToStringWithThousandthPercentile(rangeInfo.StartQuantity), format.NumToStringWithThousandthPercentile(rangeInfo.EndQuantity)),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
})
}
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{

View File

@@ -3,10 +3,11 @@ package logic
import (
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/image"
"fusenapi/utils/s3url_to_s3id"
"gorm.io/gorm"
@@ -228,32 +229,52 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
CoverMetadata: req.MapResourceMetadata[*v.Cover],
})
}
//获取产品价格列表
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)
//获取产品模型价格列表
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,part_id,step_price")
if err != nil {
logx.Error(err)
return nil, errors.New("failed to get product min price list")
return nil, errors.New("failed to get model list")
}
//存储产品最小价格
for _, v := range productPriceList {
priceStrSlic := strings.Split(v.Price, ",")
priceSlice, err := format.StrSlicToIntSlice(priceStrSlic)
if err != nil {
logx.Error(err)
return nil, errors.New("parse price err")
mapModelMinPrice := make(map[int64]int64)
//每个模型/配件存储最小价格
for _, modelInfo := range modelList {
switch *modelInfo.Tag {
case constants.TAG_MODEL: //模型
if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 {
return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id))
}
var stepPrice gmodel.StepPriceJsonStruct
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
logx.Error(err)
return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id))
}
lenRange := len(stepPrice.PriceRange)
if lenRange == 0 {
return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id))
}
mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price
case constants.TAG_PARTS: //配件
mapModelMinPrice[modelInfo.Id] = *modelInfo.Price
}
if len(priceSlice) == 0 {
}
//给产品存储最小价格
for _, v := range modelList {
if *v.Tag != constants.TAG_MODEL {
continue
}
//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算)
sort.Ints(priceSlice)
if min, ok := req.MapProductMinPrice[v.ProductId]; ok {
if min > int64(priceSlice[0]) {
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
itemPrice := mapModelMinPrice[v.Id]
if *v.PartId > 0 {
if fittingPrice, ok := mapModelMinPrice[*v.PartId]; ok {
itemPrice += fittingPrice
}
} else {
req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0])
}
if minPrice, ok := req.MapProductMinPrice[*v.ProductId]; ok {
if itemPrice < minPrice {
req.MapProductMinPrice[*v.ProductId] = itemPrice
}
continue
}
req.MapProductMinPrice[*v.ProductId] = itemPrice
}
//获取模板
productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag")

View File

@@ -23,7 +23,7 @@ var (
//每个websocket渲染任务缓冲队列长度默认值
renderChanLen = 500
//每个websocket渲染并发数
renderChanConcurrency = 1
renderChanConcurrency = 500
)
// 渲染处理器
@@ -369,7 +369,7 @@ func (w *wsConnectItem) assembleRenderDataToUnity(taskId string, combineImage st
}
//发送运行阶段消息
w.sendRenderDataToUnityStepResponseMessage(info.RenderId)
logx.Info("发送到unity成功,刀版图:", combineImage , " 请求unity的数据:", string(postDataBytes))
logx.Info("发送到unity成功,刀版图:", combineImage /*, " 请求unity的数据:", string(postDataBytes)*/)
return nil
}