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

This commit is contained in:
eson 2023-09-21 18:12:26 +08:00
commit b110532a9a
8 changed files with 48 additions and 76 deletions

View File

@ -134,11 +134,11 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
}) })
updData := &gmodel.FsShoppingCart{ updData := &gmodel.FsShoppingCart{
PurchaseQuantity: &reqPurchaseQuantity, PurchaseQuantity: &reqPurchaseQuantity,
IsSelected: &isSelected,
} }
//如果是选中则累加总价 //如果是选中则累加总价
if isSelected == 1 { if isSelected == 1 {
subTotalPrice += totalPrice subTotalPrice += totalPrice
updData.IsSelected = &isSelected
} }
//更新购物车购买数量 //更新购物车购买数量
if err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, updData); err != nil { if err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, updData); err != nil {

View File

@ -123,24 +123,17 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
} }
} }
//计算价格 //计算价格
itemPrice, totalPrice, stepNum, _, err := l.svcCtx.Repositories.NewShoppingCart.CaculateCartPrice(*cart.PurchaseQuantity, &sizePrice, fittingPrice) itemPrice, totalPrice, _, _, err := l.svcCtx.Repositories.NewShoppingCart.CaculateCartPrice(*cart.PurchaseQuantity, &sizePrice, fittingPrice)
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()) return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
} }
//获取阶梯数量 //尺寸信息
stepQuantityList := make([]int64, 0, 20)
tmpMinBuyNum := *sizePrice.MinBuyNum
for tmpMinBuyNum < (int64(stepNum[len(stepNum)-1]) + 5) {
//阶梯数
tmpQuantity := tmpMinBuyNum * (*sizePrice.EachBoxNum)
stepQuantityList = append(stepQuantityList, tmpQuantity)
tmpMinBuyNum++
}
sizeCapacity := snapShot.SizeInfo.Capacity sizeCapacity := snapShot.SizeInfo.Capacity
if sizeInfo, ok := mapSize[*cart.SizeId]; ok { if sizeInfo, ok := mapSize[*cart.SizeId]; ok {
sizeCapacity = *sizeInfo.Capacity sizeCapacity = *sizeInfo.Capacity
} }
//配件信息
fittingName := snapShot.FittingInfo.FittingName fittingName := snapShot.FittingInfo.FittingName
if fittingInfo, ok := mapModel[*cart.FittingId]; ok { if fittingInfo, ok := mapModel[*cart.FittingId]; ok {
fittingName = *fittingInfo.Name fittingName = *fittingInfo.Name
@ -148,7 +141,9 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
productCover := "" //产品封面图 productCover := "" //产品封面图
productName := snapShot.ProductInfo.ProductName productName := snapShot.ProductInfo.ProductName
productSn := snapShot.ProductInfo.ProductSn productSn := snapShot.ProductInfo.ProductSn
//产品封面图资源元数据
var productCoverMetadata interface{} var productCoverMetadata interface{}
//产品信息
if productInfo, ok := mapProduct[*cart.ProductId]; ok { if productInfo, ok := mapProduct[*cart.ProductId]; ok {
productCover = *productInfo.Cover productCover = *productInfo.Cover
productName = *productInfo.Title productName = *productInfo.Title
@ -187,17 +182,18 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
Qrcode: snapShot.UserDiyInformation.Qrcode, Qrcode: snapShot.UserDiyInformation.Qrcode,
Slogan: snapShot.UserDiyInformation.Slogan, Slogan: snapShot.UserDiyInformation.Slogan,
}, },
PurchaseQuantity: *cart.PurchaseQuantity, PurchaseQuantity: *cart.PurchaseQuantity,
StepNum: stepQuantityList, MinPurchaseQuantity: *sizePrice.EachBoxNum * (*sizePrice.MinBuyNum),
IsInvalid: false, StepPurchaseQuantity: *sizePrice.EachBoxNum,
InvalidDescription: "", IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
IsHighlyCustomized: *cart.IsHighlyCustomized > 0, IsSelected: *cart.IsSelected > 0,
IsSelected: *cart.IsSelected > 0,
} }
//是否有失效的 //是否有失效的
if description, ok := mapCartChange[cart.Id]; ok { if description, ok := mapCartChange[cart.Id]; ok {
item.IsInvalid = true item.IsInvalid = true
item.InvalidDescription = description item.InvalidDescription = description
//失效了返回给前端也是不选中
item.IsSelected = false
} }
list = append(list, item) list = append(list, item)
} }

View File

@ -39,19 +39,20 @@ type GetCartsRsp struct {
} }
type CartItem struct { type CartItem struct {
CartId int64 `json:"cart_id"` CartId int64 `json:"cart_id"`
ProductInfo ProductInfo `json:"product_info"` //产品信息 ProductInfo ProductInfo `json:"product_info"` //产品信息
SizeInfo SizeInfo `json:"size_info"` //尺寸信息 SizeInfo SizeInfo `json:"size_info"` //尺寸信息
FittingInfo FittingInfo `json:"fitting_info"` //配件信息 FittingInfo FittingInfo `json:"fitting_info"` //配件信息
ItemPrice string `json:"item_price"` //单价 ItemPrice string `json:"item_price"` //单价
TotalPrice string `json:"total_price"` //单价X数量=总价 TotalPrice string `json:"total_price"` //单价X数量=总价
DiyInformation DiyInformation `json:"diy_information"` //diy信息 DiyInformation DiyInformation `json:"diy_information"` //diy信息
StepNum []int64 `json:"step_num"` //阶梯数量 PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制 StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量
IsInvalid bool `json:"is_invalid"` //是否无效 IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
InvalidDescription string `json:"invalid_description"` //无效原因 IsInvalid bool `json:"is_invalid"` //是否无效
IsSelected bool `json:"is_selected"` //是否选中 InvalidDescription string `json:"invalid_description"` //无效原因
IsSelected bool `json:"is_selected"` //是否选中
} }
type ProductInfo struct { type ProductInfo struct {

View File

@ -40,8 +40,6 @@ func pushCommonNotifyCache(data commonConnectionNotFoundDataCacheChanItem) {
select { select {
case commonConnectionNotFoundDataCacheChan <- data: case commonConnectionNotFoundDataCacheChan <- data:
return return
case <-time.After(time.Millisecond * 50): //超50ms就丢弃
return
} }
} }

View File

@ -164,8 +164,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
go ws.consumeOutChanData() go ws.consumeOutChanData()
//消费入口数据 //消费入口数据
go ws.consumeInChanData() go ws.consumeInChanData()
//操作连接中渲染任务的增加/删除
//go ws.operationRenderTask()
//消费渲染缓冲队列 //消费渲染缓冲队列
go ws.consumeRenderImageData() go ws.consumeRenderImageData()
//心跳 //心跳
@ -194,8 +192,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
userId: userInfo.UserId, userId: userInfo.UserId,
guestId: userInfo.GuestId, guestId: userInfo.GuestId,
extendRenderProperty: extendRenderProperty{ extendRenderProperty: extendRenderProperty{
renderChan: make(chan []byte, renderChanLen), renderChan: make(chan []byte, renderChanLen),
renderConsumeTickTime: 1, //默认1纳秒后面需要根据不同用户不同触发速度
}, },
} }
//保存连接 //保存连接
@ -400,9 +397,6 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
return return
case w.outChan <- data: case w.outChan <- data:
return return
case <-time.After(time.Millisecond * 50): //阻塞超过50ms丢弃
logx.Error("failed to send to out chan,time expired,data:", string(data))
return
} }
} }
@ -413,9 +407,6 @@ func (w *wsConnectItem) sendToInChan(data []byte) {
return return
case w.inChan <- data: case w.inChan <- data:
return return
case <-time.After(time.Millisecond * 200): //200豪秒超时丢弃说明超过消费速度了
w.sendToOutChan(w.respondDataFormat(constants.WEBSOCKET_INCOME_CACHE_QUEUE_OVERFLOW, "send message is too frequent,the message is ignore by system:"+string(data)))
return
} }
} }

View File

@ -21,7 +21,7 @@ import (
var ( var (
//每个websocket渲染任务缓冲队列长度默认值 //每个websocket渲染任务缓冲队列长度默认值
renderChanLen = 500 renderChanLen = 200
) )
// 渲染处理器 // 渲染处理器
@ -30,20 +30,17 @@ type renderProcessor struct {
// 云渲染属性 // 云渲染属性
type extendRenderProperty struct { type extendRenderProperty struct {
renderChan chan []byte //渲染消息入口的缓冲队列 renderChan chan []byte //渲染消息入口的缓冲队列
renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
} }
// 处理分发到这里的数据 // 处理分发到这里的数据
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
//logx.Info("收到渲染任务消息:", string(data)) //logx.Info("开始处理渲染任务消息:", string(data))
select { select {
case <-w.closeChan: //已经关闭 case <-w.closeChan: //已经关闭
return return
case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列 case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列
return return
case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃
return
} }
} }
@ -54,18 +51,13 @@ func (w *wsConnectItem) consumeRenderImageData() {
logx.Error("func renderImage err:", err) logx.Error("func renderImage err:", err)
} }
}() }()
var duration time.Duration = 1 var data []byte
if w.extendRenderProperty.renderConsumeTickTime > 0 {
duration = w.extendRenderProperty.renderConsumeTickTime
}
ticker := time.NewTicker(duration)
defer ticker.Stop()
for { for {
select { select {
case <-w.closeChan: //已关闭 case <-w.closeChan: //已关闭
return return
case <-ticker.C: //消费数据 case data = <-w.extendRenderProperty.renderChan: //消费数据
w.renderImage(<-w.extendRenderProperty.renderChan) w.renderImage(data)
} }
} }
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"time"
) )
var ( var (
@ -30,8 +29,6 @@ func createUserConnPoolElement(userId, guestId int64, uniqueId string) {
select { select {
case userConnPoolCtlChan <- data: case userConnPoolCtlChan <- data:
return return
case <-time.After(time.Millisecond * 200):
return
} }
} }
@ -51,8 +48,6 @@ func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) {
select { select {
case userConnPoolCtlChan <- data: case userConnPoolCtlChan <- data:
return return
case <-time.After(time.Millisecond * 200):
return
} }
} }
@ -68,8 +63,6 @@ func sendToOutChanByUserIndex(userId, guestId int64, message []byte) {
select { select {
case userConnPoolCtlChan <- data: case userConnPoolCtlChan <- data:
return return
case <-time.After(time.Millisecond * 200):
return
} }
} }

View File

@ -56,19 +56,20 @@ type GetCartsRsp {
CartList []CartItem `json:"cart_list"` CartList []CartItem `json:"cart_list"`
} }
type CartItem { type CartItem {
CartId int64 `json:"cart_id"` CartId int64 `json:"cart_id"`
ProductInfo ProductInfo `json:"product_info"` //产品信息 ProductInfo ProductInfo `json:"product_info"` //产品信息
SizeInfo SizeInfo `json:"size_info"` //尺寸信息 SizeInfo SizeInfo `json:"size_info"` //尺寸信息
FittingInfo FittingInfo `json:"fitting_info"` //配件信息 FittingInfo FittingInfo `json:"fitting_info"` //配件信息
ItemPrice string `json:"item_price"` //单价 ItemPrice string `json:"item_price"` //单价
TotalPrice string `json:"total_price"` //单价X数量=总价 TotalPrice string `json:"total_price"` //单价X数量=总价
DiyInformation DiyInformation `json:"diy_information"` //diy信息 DiyInformation DiyInformation `json:"diy_information"` //diy信息
StepNum []int64 `json:"step_num"` //阶梯数量 PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量 MinPurchaseQuantity int64 `json:"min_purchase_quantity"` //起购数量
IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制 StepPurchaseQuantity int64 `json:"step_purchase_quantity"` //购买加或者减少步进量
IsInvalid bool `json:"is_invalid"` //是否无效 IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制
InvalidDescription string `json:"invalid_description"` //无效原因 IsInvalid bool `json:"is_invalid"` //是否无效
IsSelected bool `json:"is_selected"` //是否选中 InvalidDescription string `json:"invalid_description"` //无效原因
IsSelected bool `json:"is_selected"` //是否选中
} }
type ProductInfo { type ProductInfo {
ProductId int64 `json:"product_id"` //产品id ProductId int64 `json:"product_id"` //产品id