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

This commit is contained in:
eson
2023-09-28 13:25:12 +08:00
20 changed files with 480 additions and 291 deletions

View File

@@ -62,6 +62,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth
ResourceId: defaultMaterialInfo.ResourceId,
ResourceUrl: defaultMaterialInfo.ResourceUrl,
Ctime: &nowTime,
Metadata: defaultMaterialInfo.Metadata,
}
MaterialCreateRes := l.svcCtx.MysqlConn.Create(&defaultMaterial)
err = MaterialCreateRes.Error

View File

@@ -40,7 +40,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth
// 如果是,返回未授权的错误码
return resp.SetStatus(basic.CodeUnAuth)
}
tPlus60Days := time.Now().AddDate(0, 0, 60)
tPlus60Days := time.Now().AddDate(0, 0, 60).UTC()
res, err := l.svcCtx.Repositories.NewOrder.Create(l.ctx, &repositories.CreateReq{
ExpectedDeliveryTime: tPlus60Days,
CurrentCurrency: string(constants.CURRENCYUSD),

View File

@@ -7,6 +7,7 @@ import (
"fusenapi/model/gmodel"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"gorm.io/gorm"
"strings"
@@ -111,7 +112,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us
Id: fitting.Id,
MaterialImg: materialImg,
Title: *fitting.Title,
Price: *fitting.Price,
Price: format.CentitoDollar(*fitting.Price, 3),
ModelInfo: modelInfo,
IsPopular: *fitting.IsHot > 0,
})

View File

@@ -91,13 +91,17 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
stepPurchaseQuantity := *modelPriceInfo.PackedUnit
//购买数步进基数描述
stepPurchaseQuantityDescription := "主体装箱数为步进基数"
//配件价格
fittingPrice := int64(0)
if *modelPriceInfo.PartId > 0 {
fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId]
if !ok {
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelPriceInfo.PartId))
}
//最小价格要加配件
minPrice += *fittingPriceInfo.Price
//最小/最大价格要加配件
fittingPrice = *fittingPriceInfo.Price
minPrice += fittingPrice
maxPrice += fittingPrice
//如果配件装箱基数比主体大,则基数以配件为主
if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity {
stepPurchaseQuantity = *fittingPriceInfo.PackedUnit
@@ -110,18 +114,27 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
if rIndex+1 == rangeLen {
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
stepRange = append(stepRange, map[string]interface{}{
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf(">=%s Units", begin),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
break
}
begin := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.StartQuantity))
end := format.NumToStringWithThousandthPercentile(fmt.Sprintf("%d", rangeInfo.EndQuantity))
stepRange = append(stepRange, map[string]interface{}{
"start": rangeInfo.StartQuantity,
"end": rangeInfo.EndQuantity,
"range_description": fmt.Sprintf("%s-%s Units", begin, end),
"item_price": format.CentitoDollar(rangeInfo.Price, 3),
"item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3),
})
}
//计算起购数量的单价
_, minBuyUnitsQuantityPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(stepPrice.MinBuyUnitsNum, stepPrice, fittingPrice)
if err != nil {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get min buy quantity item price")
}
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{
"step_purchase_quantity": stepPurchaseQuantity,
"step_purchase_quantity_description": stepPurchaseQuantityDescription,
@@ -129,6 +142,8 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
"max_price": maxPrice,
"step_range": stepRange,
"min_buy_units_quantity": stepPrice.MinBuyUnitsNum,
"min_buy_units_quantity_total_price": format.CentitoDollarWithNoHalfAdjust(minBuyUnitsQuantityPrice*stepPrice.MinBuyUnitsNum, 2),
"min_buy_units_quantity_item_price": format.CentitoDollar(minBuyUnitsQuantityPrice, 3),
}
}
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)

View File

@@ -94,6 +94,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec
//获取产品最低价
mapProductMinPrice := make(map[int64]int64)
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
}
//获取产品标签相关属性

View File

@@ -8,7 +8,6 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/format"
"gorm.io/gorm"
"sort"
"strings"
"context"
@@ -81,32 +80,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
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])
}
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price")
}
//获取对应模型数据
modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id")
@@ -140,7 +117,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0,
ModelId: modelList[modelIndex].Id,
IsPopular: *sizeInfo.IsHot > 0,
MinPrice: float64(minPrice) / 100,
MinPrice: format.CentitoDollar(minPrice, 3),
IsDefault: defaultSizeId == sizeInfo.Id,
})
}

View File

@@ -229,6 +229,7 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn
}
//获取产品最低价格
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, req.MapProductMinPrice); err != nil {
logx.Error(err)
return nil, errors.New("failed to get product min price")
}
//获取模板

View File

@@ -114,6 +114,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
//获取产品最低价格
mapProductMinPrice := make(map[int64]int64)
if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price")
}
//获取模板(只是获取产品product_id)

View File

@@ -361,7 +361,7 @@ type GetSizeByPidRsp struct {
PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件
ModelId int64 `json:"model_id"` //产品主模型id
IsPopular bool `json:"is_popular"` //是否受欢迎
MinPrice float64 `json:"min_price"` //最小价格
MinPrice string `json:"min_price"` //最小价格
IsDefault bool `json:"is_default"` //是否默认(这里的默认是跟列表页一致)
}
@@ -379,7 +379,7 @@ type GetFittingByPidRsp struct {
Id int64 `json:"id"`
MaterialImg string `json:"material_img"`
Title string `json:"title"`
Price int64 `json:"price"`
Price string `json:"price"`
IsPopular bool `json:"is_popular"`
ModelInfo interface{} `json:"model_info"`
}

View File

@@ -0,0 +1,7 @@
package main
import "testing"
func TestMain(t *testing.T) {
main()
}

View File

@@ -179,6 +179,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
l.sendGetUniqueIdErrResponse(conn)
return wsConnectItem{}, err
}
renderCtx, renderCtxCancelFunc := context.WithCancel(l.ctx)
ws := wsConnectItem{
conn: conn,
userAgent: userAgent,
@@ -192,7 +193,9 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
userId: userInfo.UserId,
guestId: userInfo.GuestId,
extendRenderProperty: extendRenderProperty{
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen),
renderCtx: renderCtx,
renderCtxCancelFunc: renderCtxCancelFunc,
},
}
//保存连接

View File

@@ -3,6 +3,7 @@ package logic
//处理websocket云渲染任务数据
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
@@ -32,7 +33,11 @@ type renderProcessor struct {
// 云渲染属性
type extendRenderProperty struct {
renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列
renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列
renderCtx context.Context //渲染控制上下文(用于切换模板标签/颜色取消之前发送的不相同的任务)
renderCtxCancelFunc context.CancelFunc //渲染控制上下文取消方法
selectColorIndex int //选择的颜色索引
templateTag string //模板标签
}
// 处理分发到这里的数据
@@ -44,6 +49,16 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
logx.Error("invalid format of websocket render image message", err)
return
}
if renderImageData.RenderData.TemplateTag != w.extendRenderProperty.templateTag || renderImageData.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex {
//赋值
w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag
w.extendRenderProperty.selectColorIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
//让之前的失效
w.extendRenderProperty.renderCtxCancelFunc()
logx.Info("模板标签/颜色更换上下文取消")
//重新赋值
w.extendRenderProperty.renderCtx, w.extendRenderProperty.renderCtxCancelFunc = context.WithCancel(w.logic.ctx)
}
select {
case <-w.closeChan: //已经关闭
return