Merge branch 'develop' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
		
						commit
						b110532a9a
					
				@ -134,11 +134,11 @@ func (l *CalculateCartPriceLogic) CalculateCartPrice(req *types.CalculateCartPri
 | 
			
		||||
			})
 | 
			
		||||
			updData := &gmodel.FsShoppingCart{
 | 
			
		||||
				PurchaseQuantity: &reqPurchaseQuantity,
 | 
			
		||||
				IsSelected:       &isSelected,
 | 
			
		||||
			}
 | 
			
		||||
			//如果是选中则累加总价
 | 
			
		||||
			if isSelected == 1 {
 | 
			
		||||
				subTotalPrice += totalPrice
 | 
			
		||||
				updData.IsSelected = &isSelected
 | 
			
		||||
			}
 | 
			
		||||
			//更新购物车购买数量
 | 
			
		||||
			if err = shoppingCartModel.Update(l.ctx, cart.Id, userinfo.UserId, updData); err != nil {
 | 
			
		||||
 | 
			
		||||
@ -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 {
 | 
			
		||||
			logx.Error(err)
 | 
			
		||||
			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
 | 
			
		||||
		if sizeInfo, ok := mapSize[*cart.SizeId]; ok {
 | 
			
		||||
			sizeCapacity = *sizeInfo.Capacity
 | 
			
		||||
		}
 | 
			
		||||
		//配件信息
 | 
			
		||||
		fittingName := snapShot.FittingInfo.FittingName
 | 
			
		||||
		if fittingInfo, ok := mapModel[*cart.FittingId]; ok {
 | 
			
		||||
			fittingName = *fittingInfo.Name
 | 
			
		||||
@ -148,7 +141,9 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
 | 
			
		||||
		productCover := "" //产品封面图
 | 
			
		||||
		productName := snapShot.ProductInfo.ProductName
 | 
			
		||||
		productSn := snapShot.ProductInfo.ProductSn
 | 
			
		||||
		//产品封面图资源元数据
 | 
			
		||||
		var productCoverMetadata interface{}
 | 
			
		||||
		//产品信息
 | 
			
		||||
		if productInfo, ok := mapProduct[*cart.ProductId]; ok {
 | 
			
		||||
			productCover = *productInfo.Cover
 | 
			
		||||
			productName = *productInfo.Title
 | 
			
		||||
@ -187,17 +182,18 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
 | 
			
		||||
				Qrcode:  snapShot.UserDiyInformation.Qrcode,
 | 
			
		||||
				Slogan:  snapShot.UserDiyInformation.Slogan,
 | 
			
		||||
			},
 | 
			
		||||
			PurchaseQuantity:   *cart.PurchaseQuantity,
 | 
			
		||||
			StepNum:            stepQuantityList,
 | 
			
		||||
			IsInvalid:          false,
 | 
			
		||||
			InvalidDescription: "",
 | 
			
		||||
			IsHighlyCustomized: *cart.IsHighlyCustomized > 0,
 | 
			
		||||
			IsSelected:         *cart.IsSelected > 0,
 | 
			
		||||
			PurchaseQuantity:     *cart.PurchaseQuantity,
 | 
			
		||||
			MinPurchaseQuantity:  *sizePrice.EachBoxNum * (*sizePrice.MinBuyNum),
 | 
			
		||||
			StepPurchaseQuantity: *sizePrice.EachBoxNum,
 | 
			
		||||
			IsHighlyCustomized:   *cart.IsHighlyCustomized > 0,
 | 
			
		||||
			IsSelected:           *cart.IsSelected > 0,
 | 
			
		||||
		}
 | 
			
		||||
		//是否有失效的
 | 
			
		||||
		if description, ok := mapCartChange[cart.Id]; ok {
 | 
			
		||||
			item.IsInvalid = true
 | 
			
		||||
			item.InvalidDescription = description
 | 
			
		||||
			//失效了返回给前端也是不选中
 | 
			
		||||
			item.IsSelected = false
 | 
			
		||||
		}
 | 
			
		||||
		list = append(list, item)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -39,19 +39,20 @@ type GetCartsRsp struct {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type CartItem struct {
 | 
			
		||||
	CartId             int64          `json:"cart_id"`
 | 
			
		||||
	ProductInfo        ProductInfo    `json:"product_info"`         //产品信息
 | 
			
		||||
	SizeInfo           SizeInfo       `json:"size_info"`            //尺寸信息
 | 
			
		||||
	FittingInfo        FittingInfo    `json:"fitting_info"`         //配件信息
 | 
			
		||||
	ItemPrice          string         `json:"item_price"`           //单价
 | 
			
		||||
	TotalPrice         string         `json:"total_price"`          //单价X数量=总价
 | 
			
		||||
	DiyInformation     DiyInformation `json:"diy_information"`      //diy信息
 | 
			
		||||
	StepNum            []int64        `json:"step_num"`             //阶梯数量
 | 
			
		||||
	PurchaseQuantity   int64          `json:"purchase_quantity"`    //当前购买数量
 | 
			
		||||
	IsHighlyCustomized bool           `json:"is_highly_customized"` //是否高度定制
 | 
			
		||||
	IsInvalid          bool           `json:"is_invalid"`           //是否无效
 | 
			
		||||
	InvalidDescription string         `json:"invalid_description"`  //无效原因
 | 
			
		||||
	IsSelected         bool           `json:"is_selected"`          //是否选中
 | 
			
		||||
	CartId               int64          `json:"cart_id"`
 | 
			
		||||
	ProductInfo          ProductInfo    `json:"product_info"`           //产品信息
 | 
			
		||||
	SizeInfo             SizeInfo       `json:"size_info"`              //尺寸信息
 | 
			
		||||
	FittingInfo          FittingInfo    `json:"fitting_info"`           //配件信息
 | 
			
		||||
	ItemPrice            string         `json:"item_price"`             //单价
 | 
			
		||||
	TotalPrice           string         `json:"total_price"`            //单价X数量=总价
 | 
			
		||||
	DiyInformation       DiyInformation `json:"diy_information"`        //diy信息
 | 
			
		||||
	PurchaseQuantity     int64          `json:"purchase_quantity"`      //当前购买数量
 | 
			
		||||
	MinPurchaseQuantity  int64          `json:"min_purchase_quantity"`  //起购数量
 | 
			
		||||
	StepPurchaseQuantity int64          `json:"step_purchase_quantity"` //购买加或者减少步进量
 | 
			
		||||
	IsHighlyCustomized   bool           `json:"is_highly_customized"`   //是否高度定制
 | 
			
		||||
	IsInvalid            bool           `json:"is_invalid"`             //是否无效
 | 
			
		||||
	InvalidDescription   string         `json:"invalid_description"`    //无效原因
 | 
			
		||||
	IsSelected           bool           `json:"is_selected"`            //是否选中
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ProductInfo struct {
 | 
			
		||||
 | 
			
		||||
@ -40,8 +40,6 @@ func pushCommonNotifyCache(data commonConnectionNotFoundDataCacheChanItem) {
 | 
			
		||||
	select {
 | 
			
		||||
	case commonConnectionNotFoundDataCacheChan <- data:
 | 
			
		||||
		return
 | 
			
		||||
	case <-time.After(time.Millisecond * 50): //超50ms就丢弃
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -164,8 +164,6 @@ func (l *DataTransferLogic) DataTransfer(w http.ResponseWriter, r *http.Request)
 | 
			
		||||
	go ws.consumeOutChanData()
 | 
			
		||||
	//消费入口数据
 | 
			
		||||
	go ws.consumeInChanData()
 | 
			
		||||
	//操作连接中渲染任务的增加/删除
 | 
			
		||||
	//go ws.operationRenderTask()
 | 
			
		||||
	//消费渲染缓冲队列
 | 
			
		||||
	go ws.consumeRenderImageData()
 | 
			
		||||
	//心跳
 | 
			
		||||
@ -194,8 +192,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use
 | 
			
		||||
		userId:    userInfo.UserId,
 | 
			
		||||
		guestId:   userInfo.GuestId,
 | 
			
		||||
		extendRenderProperty: extendRenderProperty{
 | 
			
		||||
			renderChan:            make(chan []byte, renderChanLen),
 | 
			
		||||
			renderConsumeTickTime: 1, //默认1纳秒,后面需要根据不同用户不同触发速度
 | 
			
		||||
			renderChan: make(chan []byte, renderChanLen),
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	//保存连接
 | 
			
		||||
@ -400,9 +397,6 @@ func (w *wsConnectItem) sendToOutChan(data []byte) {
 | 
			
		||||
		return
 | 
			
		||||
	case w.outChan <- data:
 | 
			
		||||
		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
 | 
			
		||||
	case w.inChan <- data:
 | 
			
		||||
		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
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ import (
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	//每个websocket渲染任务缓冲队列长度默认值
 | 
			
		||||
	renderChanLen = 500
 | 
			
		||||
	renderChanLen = 200
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 渲染处理器
 | 
			
		||||
@ -30,20 +30,17 @@ type renderProcessor struct {
 | 
			
		||||
 | 
			
		||||
// 云渲染属性
 | 
			
		||||
type extendRenderProperty struct {
 | 
			
		||||
	renderChan            chan []byte   //渲染消息入口的缓冲队列
 | 
			
		||||
	renderConsumeTickTime time.Duration //消费渲染消息时钟间隔(纳秒),用于后期控制不同类型用户渲染速度限制
 | 
			
		||||
	renderChan chan []byte //渲染消息入口的缓冲队列
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 处理分发到这里的数据
 | 
			
		||||
func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) {
 | 
			
		||||
	//logx.Info("收到渲染任务消息:", string(data))
 | 
			
		||||
	//logx.Info("开始处理渲染任务消息:", string(data))
 | 
			
		||||
	select {
 | 
			
		||||
	case <-w.closeChan: //已经关闭
 | 
			
		||||
		return
 | 
			
		||||
	case w.extendRenderProperty.renderChan <- data: //发入到缓冲队列
 | 
			
		||||
		return
 | 
			
		||||
	case <-time.After(time.Second * 3): //三秒没进入缓冲队列就丢弃
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -54,18 +51,13 @@ func (w *wsConnectItem) consumeRenderImageData() {
 | 
			
		||||
			logx.Error("func renderImage err:", err)
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
	var duration time.Duration = 1
 | 
			
		||||
	if w.extendRenderProperty.renderConsumeTickTime > 0 {
 | 
			
		||||
		duration = w.extendRenderProperty.renderConsumeTickTime
 | 
			
		||||
	}
 | 
			
		||||
	ticker := time.NewTicker(duration)
 | 
			
		||||
	defer ticker.Stop()
 | 
			
		||||
	var data []byte
 | 
			
		||||
	for {
 | 
			
		||||
		select {
 | 
			
		||||
		case <-w.closeChan: //已关闭
 | 
			
		||||
			return
 | 
			
		||||
		case <-ticker.C: //消费数据
 | 
			
		||||
			w.renderImage(<-w.extendRenderProperty.renderChan)
 | 
			
		||||
		case data = <-w.extendRenderProperty.renderChan: //消费数据
 | 
			
		||||
			w.renderImage(data)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,6 @@ import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"github.com/zeromicro/go-zero/core/logx"
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
@ -30,8 +29,6 @@ func createUserConnPoolElement(userId, guestId int64, uniqueId string) {
 | 
			
		||||
	select {
 | 
			
		||||
	case userConnPoolCtlChan <- data:
 | 
			
		||||
		return
 | 
			
		||||
	case <-time.After(time.Millisecond * 200):
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -51,8 +48,6 @@ func deleteUserConnPoolElement(userId, guestId int64, uniqueId string) {
 | 
			
		||||
	select {
 | 
			
		||||
	case userConnPoolCtlChan <- data:
 | 
			
		||||
		return
 | 
			
		||||
	case <-time.After(time.Millisecond * 200):
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -68,8 +63,6 @@ func sendToOutChanByUserIndex(userId, guestId int64, message []byte) {
 | 
			
		||||
	select {
 | 
			
		||||
	case userConnPoolCtlChan <- data:
 | 
			
		||||
		return
 | 
			
		||||
	case <-time.After(time.Millisecond * 200):
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -56,19 +56,20 @@ type GetCartsRsp {
 | 
			
		||||
	CartList []CartItem `json:"cart_list"`
 | 
			
		||||
}
 | 
			
		||||
type CartItem {
 | 
			
		||||
	CartId             int64          `json:"cart_id"`
 | 
			
		||||
	ProductInfo        ProductInfo    `json:"product_info"`         //产品信息
 | 
			
		||||
	SizeInfo           SizeInfo       `json:"size_info"`            //尺寸信息
 | 
			
		||||
	FittingInfo        FittingInfo    `json:"fitting_info"`         //配件信息
 | 
			
		||||
	ItemPrice          string         `json:"item_price"`           //单价
 | 
			
		||||
	TotalPrice         string         `json:"total_price"`          //单价X数量=总价
 | 
			
		||||
	DiyInformation     DiyInformation `json:"diy_information"`      //diy信息
 | 
			
		||||
	StepNum            []int64        `json:"step_num"`             //阶梯数量
 | 
			
		||||
	PurchaseQuantity   int64          `json:"purchase_quantity"`    //当前购买数量
 | 
			
		||||
	IsHighlyCustomized bool           `json:"is_highly_customized"` //是否高度定制
 | 
			
		||||
	IsInvalid          bool           `json:"is_invalid"`           //是否无效
 | 
			
		||||
	InvalidDescription string         `json:"invalid_description"`  //无效原因
 | 
			
		||||
	IsSelected         bool           `json:"is_selected"`          //是否选中
 | 
			
		||||
	CartId               int64          `json:"cart_id"`
 | 
			
		||||
	ProductInfo          ProductInfo    `json:"product_info"`           //产品信息
 | 
			
		||||
	SizeInfo             SizeInfo       `json:"size_info"`              //尺寸信息
 | 
			
		||||
	FittingInfo          FittingInfo    `json:"fitting_info"`           //配件信息
 | 
			
		||||
	ItemPrice            string         `json:"item_price"`             //单价
 | 
			
		||||
	TotalPrice           string         `json:"total_price"`            //单价X数量=总价
 | 
			
		||||
	DiyInformation       DiyInformation `json:"diy_information"`        //diy信息
 | 
			
		||||
	PurchaseQuantity     int64          `json:"purchase_quantity"`      //当前购买数量
 | 
			
		||||
	MinPurchaseQuantity  int64          `json:"min_purchase_quantity"`  //起购数量
 | 
			
		||||
	StepPurchaseQuantity int64          `json:"step_purchase_quantity"` //购买加或者减少步进量
 | 
			
		||||
	IsHighlyCustomized   bool           `json:"is_highly_customized"`   //是否高度定制
 | 
			
		||||
	IsInvalid            bool           `json:"is_invalid"`             //是否无效
 | 
			
		||||
	InvalidDescription   string         `json:"invalid_description"`    //无效原因
 | 
			
		||||
	IsSelected           bool           `json:"is_selected"`            //是否选中
 | 
			
		||||
}
 | 
			
		||||
type ProductInfo {
 | 
			
		||||
	ProductId            int64       `json:"product_id"` //产品id
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user