fix
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
package shopping_cart
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/step_price"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"math"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 计算价格
|
||||
func CaculateCartPrice(purchaseQuantity int64, productPrice *gmodel.FsProductPrice, fittingPrice int64) (ItemPrice, totalPrice int64, stepNum, stepPrice []int, err error) {
|
||||
//阶梯数量切片
|
||||
stepNum, err = format.StrSlicToIntSlice(strings.Split(*productPrice.StepNum, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("failed to parse step number:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
||||
}
|
||||
lenStepNum := len(stepNum)
|
||||
//阶梯价格切片
|
||||
stepPrice, err = format.StrSlicToIntSlice(strings.Split(*productPrice.StepPrice, ","))
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("failed to parse step price:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
||||
}
|
||||
lenStepPrice := len(stepPrice)
|
||||
if lenStepPrice == 0 || lenStepNum == 0 {
|
||||
return 0, 0, nil, nil, errors.New(fmt.Sprintf("step price or step number is not set:%d_%d", *productPrice.ProductId, *productPrice.SizeId))
|
||||
}
|
||||
//请求的数量
|
||||
reqPurchaseQuantity := purchaseQuantity
|
||||
//购买箱数
|
||||
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*productPrice.EachBoxNum)))
|
||||
//根据数量获取阶梯价格中对应的价格
|
||||
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
||||
//如果有配件,单价也要加入配件价格
|
||||
itemPrice += fittingPrice
|
||||
//单个购物车总价
|
||||
totalPrice = itemPrice * reqPurchaseQuantity
|
||||
return itemPrice, totalPrice, stepNum, stepPrice, nil
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package shopping_cart
|
||||
|
||||
// 购物车快照数据结构
|
||||
type CartSnapshot struct {
|
||||
Logo string `json:"logo"` //logo地址
|
||||
CombineImage string `json:"combine_image"` //刀版图地址
|
||||
RenderImage string `json:"render_image"` //渲染结果图
|
||||
TemplateInfo TemplateInfo `json:"template_info"` //模板数据
|
||||
ModelInfo ModelInfo `json:"model_info"` //模型的数据
|
||||
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
|
||||
SizeInfo SizeInfo `json:"size_info"` //尺寸基本信息
|
||||
ProductInfo ProductInfo `json:"product_info"` //产品基本信息(只记录不要使用)
|
||||
UserDiyInformation UserDiyInformation `json:"user_diy_information"` //用户diy数据
|
||||
LightInfo LightInfo `json:"light_info"` //灯光数据
|
||||
}
|
||||
type ProductInfo struct {
|
||||
ProductName string `json:"product_name"`
|
||||
ProductSn string `json:"product_sn"`
|
||||
}
|
||||
type ModelInfo struct {
|
||||
ModelJson string `json:"model_json"` //模型设计json数据
|
||||
}
|
||||
type FittingInfo struct {
|
||||
FittingJson string `json:"fitting_json"` //配件设计json数据
|
||||
FittingName string `json:"fitting_name"` //配件名称
|
||||
}
|
||||
type TemplateInfo struct {
|
||||
TemplateJson string `json:"template_json"` //模板设计json数据
|
||||
TemplateTag string `json:"template_tag"` //模板标签
|
||||
}
|
||||
type SizeInfo struct {
|
||||
Inch string `json:"inch"`
|
||||
Cm string `json:"cm"`
|
||||
Capacity string `json:"capacity"`
|
||||
}
|
||||
type UserDiyInformation struct {
|
||||
Phone string `json:"phone"` //电话
|
||||
Address string `json:"address"` //地址
|
||||
Website string `json:"website"` //网站
|
||||
Qrcode string `json:"qrcode"` //二维码
|
||||
Slogan string `json:"slogan"` //slogan
|
||||
}
|
||||
type LightInfo struct {
|
||||
LightJson string `json:"light_json"` //灯光设计json数据
|
||||
LightName string `json:"light_name"` //名称
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
package shopping_cart
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/hash"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// 校验购物车快照数据跟目前是否一致
|
||||
type VerifyShoppingCartSnapshotDataChangeReq struct {
|
||||
Carts []gmodel.FsShoppingCart
|
||||
MapSize map[int64]gmodel.FsProductSize
|
||||
MapModel map[int64]gmodel.FsProductModel3d //模型跟配件都在
|
||||
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
||||
MapCartChange map[int64]string
|
||||
MapSnapshot map[int64]CartSnapshot
|
||||
MapProduct map[int64]gmodel.FsProduct
|
||||
}
|
||||
|
||||
func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error {
|
||||
for _, cartInfo := range req.Carts {
|
||||
descrptionBuilder := strings.Builder{}
|
||||
//产品下架/删除
|
||||
if _, ok := req.MapProduct[*cartInfo.ProductId]; !ok {
|
||||
descrptionBuilder.WriteString("<p>the product is off shelf or deleted </p>")
|
||||
}
|
||||
var snapShotParseInfo CartSnapshot
|
||||
if err := json.Unmarshal([]byte(*cartInfo.Snapshot), &snapShotParseInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
req.MapSnapshot[cartInfo.Id] = snapShotParseInfo
|
||||
//快照中模板设计json数据哈希值
|
||||
snapshotTemplateJsonHash := hash.JsonHashKey(snapShotParseInfo.TemplateInfo.TemplateJson)
|
||||
//快照中模型设计json数据哈希值
|
||||
snapshotModelJsonHash := hash.JsonHashKey(snapShotParseInfo.ModelInfo.ModelJson)
|
||||
//快照中配件设计json数据哈希值
|
||||
snapshotFittingJsonHash := hash.JsonHashKey(snapShotParseInfo.FittingInfo.FittingJson)
|
||||
//有模板验证模板相关
|
||||
if *cartInfo.TemplateId > 0 {
|
||||
if curTemplateInfo, ok := req.MapTemplate[*cartInfo.TemplateId]; !ok {
|
||||
descrptionBuilder.WriteString("<p>the template is lose</p>")
|
||||
} else {
|
||||
//当前模板设计json数据哈希值
|
||||
curTemplateJsonHash := hash.JsonHashKey(*curTemplateInfo.TemplateInfo)
|
||||
//模板设计信息改变了
|
||||
if snapshotTemplateJsonHash != curTemplateJsonHash {
|
||||
descrptionBuilder.WriteString("<p>the template design info has changed</p>")
|
||||
}
|
||||
//模板标签改变了
|
||||
if snapShotParseInfo.TemplateInfo.TemplateTag != *curTemplateInfo.TemplateTag {
|
||||
descrptionBuilder.WriteString("<p>the template`s template tag has changed</p>")
|
||||
}
|
||||
}
|
||||
}
|
||||
//有模型验证模型相关
|
||||
if *cartInfo.ModelId > 0 {
|
||||
if curModelInfo, ok := req.MapModel[*cartInfo.ModelId]; !ok { //不存在
|
||||
descrptionBuilder.WriteString("<p>the model is lose</p>")
|
||||
} else {
|
||||
//当前模型设计json数据哈希值
|
||||
curModelJsonHash := hash.JsonHashKey(*curModelInfo.ModelInfo)
|
||||
if snapshotModelJsonHash != curModelJsonHash {
|
||||
descrptionBuilder.WriteString("<p>the model design info has changed</p>")
|
||||
}
|
||||
}
|
||||
}
|
||||
//有配件验证配件相关
|
||||
if *cartInfo.FittingId > 0 {
|
||||
if curFittingInfo, ok := req.MapModel[*cartInfo.FittingId]; !ok { //不存在
|
||||
descrptionBuilder.WriteString("<p>the fitting is lose</p>")
|
||||
} else {
|
||||
//当前配件设计json数据哈希值
|
||||
curFittingJsonHash := hash.JsonHashKey(*curFittingInfo.ModelInfo)
|
||||
if snapshotFittingJsonHash != curFittingJsonHash {
|
||||
descrptionBuilder.WriteString("<p>the fitting design info has changed</p>")
|
||||
}
|
||||
}
|
||||
}
|
||||
//验证尺寸相关
|
||||
if *cartInfo.SizeId > 0 {
|
||||
curSize, ok := req.MapSize[*cartInfo.SizeId]
|
||||
if !ok {
|
||||
descrptionBuilder.WriteString("<p>the size is lose</p>")
|
||||
} else {
|
||||
var curSizeTitle SizeInfo
|
||||
if err := json.Unmarshal([]byte(*curSize.Title), &curSizeTitle); err != nil {
|
||||
return err
|
||||
}
|
||||
if snapShotParseInfo.SizeInfo.Inch != curSizeTitle.Inch || snapShotParseInfo.SizeInfo.Cm != curSizeTitle.Cm {
|
||||
descrptionBuilder.WriteString("<p>the size design info has changed</p>")
|
||||
}
|
||||
}
|
||||
}
|
||||
//收集错误
|
||||
descrption := descrptionBuilder.String()
|
||||
if descrption != "" {
|
||||
req.MapCartChange[cartInfo.Id] = descrption
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user