Merge branches 'develop' and 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
a8a7132a66
server
product/internal
websocket/internal/logic
server_api
|
@ -3,6 +3,7 @@ package logic
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"fusenapi/constants"
|
"fusenapi/constants"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
|
@ -83,6 +84,29 @@ func (l *CalculateProductPriceLogic) CalculateProductPrice(req *types.CalculateP
|
||||||
}
|
}
|
||||||
fittingPrice = *fittingInfo.Price
|
fittingPrice = *fittingInfo.Price
|
||||||
}
|
}
|
||||||
|
rangeLen := len(stepPrice.PriceRange)
|
||||||
|
stepRange := make([]interface{}, 0, rangeLen)
|
||||||
|
for rIndex, rangeInfo := range stepPrice.PriceRange {
|
||||||
|
//最后一个
|
||||||
|
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+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+fittingPrice, 3),
|
||||||
|
})
|
||||||
|
}
|
||||||
totalPrice, itemPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(req.PurchaseQuantity, stepPrice, fittingPrice)
|
totalPrice, itemPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(req.PurchaseQuantity, stepPrice, fittingPrice)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
@ -91,7 +115,7 @@ func (l *CalculateProductPriceLogic) CalculateProductPrice(req *types.CalculateP
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateProductPriceRsp{
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", types.CalculateProductPriceRsp{
|
||||||
ItemPrice: format.CentitoDollar(itemPrice, 3),
|
ItemPrice: format.CentitoDollar(itemPrice, 3),
|
||||||
TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
|
TotalPrice: format.CentitoDollarWithNoHalfAdjust(totalPrice, 2),
|
||||||
PurchaseQuantity: req.PurchaseQuantity,
|
StepRange: stepRange,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
|
@ -50,15 +51,21 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
|
||||||
}
|
}
|
||||||
//查询产品价格
|
//查询产品价格
|
||||||
modelPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdTag(l.ctx, req.ProductId, constants.TAG_MODEL, "id,size_id,part_id,step_price,packed_unit")
|
modelPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdTag(l.ctx, req.ProductId, constants.TAG_MODEL, "id,size_id,part_list,part_id,step_price,packed_unit")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model price list")
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model price list")
|
||||||
}
|
}
|
||||||
fittingIds := make([]int64, 0, len(modelPriceList))
|
fittingIds := make([]int64, 0, len(modelPriceList))
|
||||||
for _, v := range modelPriceList {
|
for _, v := range modelPriceList {
|
||||||
if *v.PartId > 0 {
|
*v.PartList = strings.Trim(*v.PartList, ",")
|
||||||
fittingIds = append(fittingIds, *v.PartId)
|
if *v.PartList != "" {
|
||||||
|
tmpPartIds, err := format.StrSlicToInt64Slice(strings.Split(*v.PartList, ","))
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model part list ")
|
||||||
|
}
|
||||||
|
fittingIds = append(fittingIds, tmpPartIds...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//查询配件价格列表
|
//查询配件价格列表
|
||||||
|
@ -73,77 +80,38 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep
|
||||||
}
|
}
|
||||||
//遍历处理模型价格
|
//遍历处理模型价格
|
||||||
mapRsp := make(map[string]interface{})
|
mapRsp := make(map[string]interface{})
|
||||||
for _, modelPriceInfo := range modelPriceList {
|
for _, modelInfo := range modelPriceList {
|
||||||
var stepPrice gmodel.StepPriceJsonStruct
|
var stepPrice gmodel.StepPriceJsonStruct
|
||||||
if err = json.Unmarshal(*modelPriceInfo.StepPrice, &stepPrice); err != nil {
|
if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price json")
|
return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price json")
|
||||||
}
|
}
|
||||||
rangeLen := len(stepPrice.PriceRange)
|
rangeLen := len(stepPrice.PriceRange)
|
||||||
if rangeLen == 0 {
|
if rangeLen == 0 {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price is not set:%d", modelPriceInfo.Id))
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price is not set:%d", modelInfo.Id))
|
||||||
}
|
}
|
||||||
//最小单价
|
*modelInfo.PartList = strings.Trim(*modelInfo.PartList, ",")
|
||||||
minPrice := stepPrice.PriceRange[rangeLen-1].Price
|
mapFittingUnit := make(map[string]interface{})
|
||||||
//最大单价
|
if *modelInfo.PartList != "" {
|
||||||
maxPrice := stepPrice.PriceRange[0].Price
|
tmpPartIds, err := format.StrSlicToInt64Slice(strings.Split(*modelInfo.PartList, ","))
|
||||||
//购买数步进基数
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
//最小/最大价格要加配件
|
|
||||||
fittingPrice = *fittingPriceInfo.Price
|
|
||||||
minPrice += fittingPrice
|
|
||||||
maxPrice += fittingPrice
|
|
||||||
//如果配件装箱基数比主体大,则基数以配件为主
|
|
||||||
if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity {
|
|
||||||
stepPurchaseQuantity = *fittingPriceInfo.PackedUnit
|
|
||||||
stepPurchaseQuantityDescription = "配件装箱数为步进基数"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stepRange := make([]interface{}, 0, rangeLen)
|
|
||||||
for rIndex, rangeInfo := range stepPrice.PriceRange {
|
|
||||||
//最后一个
|
|
||||||
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+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+fittingPrice, 3),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
//计算起购数量的单价
|
|
||||||
_, itemPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(stepPrice.MinBuyUnitsNum, stepPrice, fittingPrice)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get min buy quantity item price")
|
logx.Error(err)
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to parse model part list!! ")
|
||||||
}
|
}
|
||||||
mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{
|
for _, partId := range tmpPartIds {
|
||||||
"step_purchase_quantity": stepPurchaseQuantity,
|
fittingInfo, ok := mapFitting[*modelInfo.PartId]
|
||||||
"step_purchase_quantity_description": stepPurchaseQuantityDescription,
|
if !ok {
|
||||||
"min_price": minPrice,
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelInfo.PartId))
|
||||||
"max_price": maxPrice,
|
}
|
||||||
"step_range": stepRange,
|
mapFittingUnit[fmt.Sprintf("_%d", partId)] = map[string]interface{}{
|
||||||
"min_buy_units_quantity": stepPrice.MinBuyUnitsNum,
|
"packed_unit": *fittingInfo.PackedUnit, //装箱个数
|
||||||
"min_buy_units_quantity_total_price": format.CentitoDollarWithNoHalfAdjust(itemPrice*stepPrice.MinBuyUnitsNum, 2),
|
}
|
||||||
"min_buy_units_quantity_item_price": format.CentitoDollar(itemPrice, 3),
|
}
|
||||||
|
}
|
||||||
|
mapRsp[fmt.Sprintf("_%d", *modelInfo.SizeId)] = map[string]interface{}{
|
||||||
|
"min_buy_units_quantity": stepPrice.MinBuyUnitsNum, //起购数量
|
||||||
|
"main_packed_unit": *modelInfo.PackedUnit, //主体装箱数
|
||||||
|
"fitting": mapFittingUnit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp)
|
||||||
|
|
|
@ -345,7 +345,7 @@ type CalculateProductPriceReq struct {
|
||||||
type CalculateProductPriceRsp struct {
|
type CalculateProductPriceRsp struct {
|
||||||
ItemPrice string `json:"item_price"`
|
ItemPrice string `json:"item_price"`
|
||||||
TotalPrice string `json:"total_price"`
|
TotalPrice string `json:"total_price"`
|
||||||
PurchaseQuantity int64 `json:"purchase_quantity"`
|
StepRange interface{} `json:"step_range"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetSizeByPidReq struct {
|
type GetSizeByPidReq struct {
|
||||||
|
|
|
@ -24,7 +24,7 @@ var (
|
||||||
//每个websocket渲染任务缓冲队列长度默认值
|
//每个websocket渲染任务缓冲队列长度默认值
|
||||||
renderChanLen = 500
|
renderChanLen = 500
|
||||||
//每个websocket渲染并发数
|
//每个websocket渲染并发数
|
||||||
renderChanConcurrency = 500
|
renderChanConcurrency = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
// 渲染处理器
|
// 渲染处理器
|
||||||
|
@ -55,7 +55,6 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
|
||||||
w.extendRenderProperty.selectColorIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
|
w.extendRenderProperty.selectColorIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex
|
||||||
//让之前的失效
|
//让之前的失效
|
||||||
w.extendRenderProperty.renderCtxCancelFunc()
|
w.extendRenderProperty.renderCtxCancelFunc()
|
||||||
logx.Info("模板标签/颜色更换上下文取消")
|
|
||||||
//重新赋值
|
//重新赋值
|
||||||
w.extendRenderProperty.renderCtx, w.extendRenderProperty.renderCtxCancelFunc = context.WithCancel(w.logic.ctx)
|
w.extendRenderProperty.renderCtx, w.extendRenderProperty.renderCtxCancelFunc = context.WithCancel(w.logic.ctx)
|
||||||
}
|
}
|
||||||
|
@ -85,17 +84,39 @@ func (w *wsConnectItem) consumeRenderImageData() {
|
||||||
case <-w.closeChan: //已关闭
|
case <-w.closeChan: //已关闭
|
||||||
return
|
return
|
||||||
case data := <-w.extendRenderProperty.renderChan: //消费数据
|
case data := <-w.extendRenderProperty.renderChan: //消费数据
|
||||||
logx.Info("准备执行任务。。。。。")
|
//标签不一样
|
||||||
|
if data.RenderData.TemplateTag != w.extendRenderProperty.templateTag {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
//颜色不一致
|
||||||
|
if data.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex {
|
||||||
|
continue
|
||||||
|
}
|
||||||
limitChan <- struct{}{}
|
limitChan <- struct{}{}
|
||||||
logx.Info("执行任务中。。。。。")
|
|
||||||
go func(d websocket_data.RenderImageReqMsg) {
|
go func(d websocket_data.RenderImageReqMsg) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
logx.Error("func renderImage main panic:", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
//临时chan用select io多路复用去判断携程退出
|
||||||
|
tmpChan := make(chan struct{}, 1)
|
||||||
|
defer close(tmpChan)
|
||||||
|
defer func() {
|
||||||
|
<-limitChan
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
logx.Error("func renderImage panic:", err)
|
logx.Error("func renderImage panic:", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
defer func() {
|
select {
|
||||||
<-limitChan
|
case <-w.extendRenderProperty.renderCtx.Done():
|
||||||
|
panic("=========渲染取消旧的上下文=======")
|
||||||
|
case <-tmpChan:
|
||||||
|
return
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
w.renderImage(d)
|
w.renderImage(d)
|
||||||
}(data)
|
}(data)
|
||||||
|
@ -159,25 +180,7 @@ func (w *wsConnectItem) renderImage(renderImageData websocket_data.RenderImageRe
|
||||||
logx.Error("failed to get element ,", err)
|
logx.Error("failed to get element ,", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//获取模板开关信息并且对于没有默认值的给赋值默认值(但凡DIY有一个是空的就要请求默认数据)
|
|
||||||
/*if renderImageData.RenderData.Website == "" || renderImageData.RenderData.Phone == "" || renderImageData.RenderData.Address == "" || renderImageData.RenderData.Qrcode == "" || renderImageData.RenderData.Slogan == "" {
|
|
||||||
templateSwitchInfo := template_switch_info.GetTemplateSwitchInfo(productTemplate.Id, productTemplate.TemplateInfo, *productTemplate.MaterialImg)
|
|
||||||
if renderImageData.RenderData.Website == "" && templateSwitchInfo.MaterialData.Website.IfShow {
|
|
||||||
renderImageData.RenderData.Website = templateSwitchInfo.MaterialData.Website.DefaultValue
|
|
||||||
}
|
|
||||||
if renderImageData.RenderData.Phone == "" && templateSwitchInfo.MaterialData.Phone.IfShow {
|
|
||||||
renderImageData.RenderData.Phone = templateSwitchInfo.MaterialData.Phone.DefaultValue
|
|
||||||
}
|
|
||||||
if renderImageData.RenderData.Address == "" && templateSwitchInfo.MaterialData.Address.IfShow {
|
|
||||||
renderImageData.RenderData.Address = templateSwitchInfo.MaterialData.Address.DefaultValue
|
|
||||||
}
|
|
||||||
if renderImageData.RenderData.Qrcode == "" && templateSwitchInfo.MaterialData.QRcode.IfShow {
|
|
||||||
renderImageData.RenderData.Qrcode = templateSwitchInfo.MaterialData.QRcode.DefaultValue
|
|
||||||
}
|
|
||||||
if renderImageData.RenderData.Slogan == "" && templateSwitchInfo.MaterialData.Slogan.IfShow {
|
|
||||||
renderImageData.RenderData.Slogan = templateSwitchInfo.MaterialData.Slogan.DefaultValue
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
//获取刀版图
|
//获取刀版图
|
||||||
combineReq := repositories.LogoCombineReq{
|
combineReq := repositories.LogoCombineReq{
|
||||||
UserId: renderImageData.RenderData.UserId,
|
UserId: renderImageData.RenderData.UserId,
|
||||||
|
|
|
@ -396,7 +396,7 @@ type CalculateProductPriceReq {
|
||||||
type CalculateProductPriceRsp {
|
type CalculateProductPriceRsp {
|
||||||
ItemPrice string `json:"item_price"`
|
ItemPrice string `json:"item_price"`
|
||||||
TotalPrice string `json:"total_price"`
|
TotalPrice string `json:"total_price"`
|
||||||
PurchaseQuantity int64 `json:"purchase_quantity"`
|
StepRange interface{} `json:"step_range"`
|
||||||
}
|
}
|
||||||
//获取产品尺寸列表
|
//获取产品尺寸列表
|
||||||
type GetSizeByPidReq {
|
type GetSizeByPidReq {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user