From 5df0a0f18437cb6d66caef916741f88e49706be5 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 15 Sep 2023 10:23:40 +0800 Subject: [PATCH] fix --- model/gmodel/fs_orders_trade_gen.go | 35 +++++++ model/gmodel/fs_orders_trade_logic.go | 2 + .../internal/logic/getcartslogic.go | 99 +------------------ server/shopping-cart/internal/types/types.go | 16 +-- server_api/shopping-cart.api | 16 +-- .../verify_shopping_cart_channged.go | 95 ++++++++++++++++++ 6 files changed, 152 insertions(+), 111 deletions(-) create mode 100644 model/gmodel/fs_orders_trade_gen.go create mode 100644 model/gmodel/fs_orders_trade_logic.go create mode 100644 utils/shopping_cart/verify_shopping_cart_channged.go diff --git a/model/gmodel/fs_orders_trade_gen.go b/model/gmodel/fs_orders_trade_gen.go new file mode 100644 index 00000000..4a5f4c17 --- /dev/null +++ b/model/gmodel/fs_orders_trade_gen.go @@ -0,0 +1,35 @@ +package gmodel + +import ( + "gorm.io/gorm" + "time" +) + +// fs_orders_trade 订单交易记录表 +type FsOrdersTrade struct { + Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单交易ID + UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID + OrderNo *string `gorm:"default:'';" json:"order_no"` // + OrderSource *string `gorm:"default:'';" json:"order_source"` // + TradeNo *string `gorm:"index;default:'';" json:"trade_no"` // + PayAmount *int64 `gorm:"default:0;" json:"pay_amount"` // 支付金额 (分) + PayStatus *int64 `gorm:"default:0;" json:"pay_status"` // 支付状态:1=未成功,2=已成功 + PaymentMethod *int64 `gorm:"default:0;" json:"payment_method"` // 支付方式:1=stripe,2=paypal + PayStage *int64 `gorm:"default:0;" json:"pay_stage"` // 支付阶段:1=首付,2=尾款 + RefundStatus *int64 `gorm:"default:0;" json:"refund_status"` // 退款状态:1=未退款,2=已退款 + CardNo *string `gorm:"default:'';" json:"card_no"` // + CardBrand *string `gorm:"default:'';" json:"card_brand"` // + Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // + Utime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"utime"` // + Country *string `gorm:"default:'';" json:"country"` // + Currency *string `gorm:"default:'';" json:"currency"` // + Metadata *[]byte `gorm:"default:'';" json:"metadata"` // +} +type FsOrdersTradeModel struct { + db *gorm.DB + name string +} + +func NewFsOrdersTradeModel(db *gorm.DB) *FsOrdersTradeModel { + return &FsOrdersTradeModel{db: db, name: "fs_orders_trade"} +} diff --git a/model/gmodel/fs_orders_trade_logic.go b/model/gmodel/fs_orders_trade_logic.go new file mode 100644 index 00000000..e68225aa --- /dev/null +++ b/model/gmodel/fs_orders_trade_logic.go @@ -0,0 +1,2 @@ +package gmodel +// TODO: 使用model的属性做你想做的 \ No newline at end of file diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index f28304c1..015b88fb 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -1,17 +1,13 @@ package logic import ( - "encoding/json" + "context" "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" - "fusenapi/utils/hash" "fusenapi/utils/shopping_cart" "math" - "strings" - - "context" "fusenapi/server/shopping-cart/internal/svc" "fusenapi/server/shopping-cart/internal/types" @@ -107,7 +103,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo //定义map收集变更信息 mapCartChange := make(map[int64]string) //校验购物车数据是否变更 - err = VerifyShoppingCartSnapshotDataChange(VerifyShoppingCartSnapshotDataChangeReq{ + err = shopping_cart.VerifyShoppingCartSnapshotDataChange(shopping_cart.VerifyShoppingCartSnapshotDataChangeReq{ Carts: carts, MapSize: mapSize, MapModel: mapModel, @@ -125,97 +121,6 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo return resp.SetStatus(basic.CodeOK) } -// 校验购物车快照数据跟目前是否一致 -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 -} -type VerifyShoppingCartSnapshotDataChangeRsp struct { - CartId int64 //有改变的列表下标 - Descrption string //变更描述信息 -} - -func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error { - for _, cartInfo := range req.Carts { - var snapShotParseInfo shopping_cart.CartSnapshot - if err := json.Unmarshal([]byte(*cartInfo.Snapshot), &snapShotParseInfo); err != nil { - return err - } - //快照中模板设计json数据哈希值 - snapshotTemplateJsonHash := hash.JsonHashKey(snapShotParseInfo.TemplateInfo.TemplateJson) - //快照中模型设计json数据哈希值 - snapshotModelJsonHash := hash.JsonHashKey(snapShotParseInfo.ModelInfo.ModelJson) - //快照中配件设计json数据哈希值 - snapshotFittingJsonHash := hash.JsonHashKey(snapShotParseInfo.FittingInfo.FittingJson) - descrptionBuilder := strings.Builder{} - //有模板验证模板相关 - if *cartInfo.TemplateId > 0 { - if curTemplateInfo, ok := req.MapTemplate[*cartInfo.TemplateId]; !ok { - descrptionBuilder.WriteString("
the template is lose
") - } else { - //当前模板设计json数据哈希值 - curTemplateJsonHash := hash.JsonHashKey(*curTemplateInfo.TemplateInfo) - //模板设计信息改变了 - if snapshotTemplateJsonHash != curTemplateJsonHash { - descrptionBuilder.WriteString("the template design info has changed
") - } - //模板标签改变了 - if snapShotParseInfo.TemplateInfo.TemplateTag != *curTemplateInfo.TemplateTag { - descrptionBuilder.WriteString("the template`s template tag has changed
") - } - } - } - //有模型验证模型相关 - if *cartInfo.ModelId > 0 { - if curModelInfo, ok := req.MapModel[*cartInfo.ModelId]; !ok { //不存在 - descrptionBuilder.WriteString("the model is lose
") - } else { - //当前模型设计json数据哈希值 - curModelJsonHash := hash.JsonHashKey(*curModelInfo.ModelInfo) - if snapshotModelJsonHash != curModelJsonHash { - descrptionBuilder.WriteString("the model design info has changed
") - } - } - } - //有配件验证配件相关 - if *cartInfo.FittingId > 0 { - if curFittingInfo, ok := req.MapModel[*cartInfo.FittingId]; !ok { //不存在 - descrptionBuilder.WriteString("the fitting is lose
") - } else { - //当前配件设计json数据哈希值 - curFittingJsonHash := hash.JsonHashKey(*curFittingInfo.ModelInfo) - if snapshotFittingJsonHash != curFittingJsonHash { - descrptionBuilder.WriteString("the fitting design info has changed
") - } - } - } - //验证尺寸相关 - if *cartInfo.SizeId > 0 { - curSize, ok := req.MapSize[*cartInfo.SizeId] - if !ok { - descrptionBuilder.WriteString("the size is lose
") - } else { - var curSizeTitle shopping_cart.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("the size design info has changed
") - } - } - } - //收集错误 - descrption := descrptionBuilder.String() - if descrption != "" { - req.MapCartChange[cartInfo.Id] = descrption - } - } - return nil -} - // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 // func (l *GetCartsLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { // // httpx.OkJsonCtx(r.Context(), w, resp) diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index fc3f605c..8fe8d2a2 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -44,13 +44,15 @@ type GetCartsRsp struct { } type CartItem struct { - ProductId int64 `json:"product_id"` //产品id - SizeInfo SizeInfo `json:"size_info"` //尺寸信息 - FittingInfo FittingInfo `json:"fitting_info"` //配件信息 - ItemPrice string `json:"item_price"` //单价 - TotalPrice string `json:"totalPrice"` //单价X数量=总价 - DiyInformation DiyInformation `json:"diy_information"` //diy信息 - StepNum []int64 `json:"step_num"` //阶梯数量 + ProductId int64 `json:"product_id"` //产品id + SizeInfo SizeInfo `json:"size_info"` //尺寸信息 + FittingInfo FittingInfo `json:"fitting_info"` //配件信息 + ItemPrice string `json:"item_price"` //单价 + TotalPrice string `json:"totalPrice"` //单价X数量=总价 + DiyInformation DiyInformation `json:"diy_information"` //diy信息 + StepNum []int64 `json:"step_num"` //阶梯数量 + IsInvalid bool `json:"is_invalid"` //是否无效 + InvalidDescription string `json:"invalid_description"` //无效原因 } type SizeInfo struct { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 3f1f19c5..7e96eebb 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -60,13 +60,15 @@ type GetCartsRsp { CartList []CartItem `json:"cart_list"` } type CartItem { - ProductId int64 `json:"product_id"` //产品id - SizeInfo SizeInfo `json:"size_info"` //尺寸信息 - FittingInfo FittingInfo `json:"fitting_info"` //配件信息 - ItemPrice string `json:"item_price"` //单价 - TotalPrice string `json:"totalPrice"` //单价X数量=总价 - DiyInformation DiyInformation `json:"diy_information"` //diy信息 - StepNum []int64 `json:"step_num"` //阶梯数量 + ProductId int64 `json:"product_id"` //产品id + SizeInfo SizeInfo `json:"size_info"` //尺寸信息 + FittingInfo FittingInfo `json:"fitting_info"` //配件信息 + ItemPrice string `json:"item_price"` //单价 + TotalPrice string `json:"totalPrice"` //单价X数量=总价 + DiyInformation DiyInformation `json:"diy_information"` //diy信息 + StepNum []int64 `json:"step_num"` //阶梯数量 + IsInvalid bool `json:"is_invalid"` //是否无效 + InvalidDescription string `json:"invalid_description"` //无效原因 } type SizeInfo { SizeId int64 `json:"size_id"` //尺寸id diff --git a/utils/shopping_cart/verify_shopping_cart_channged.go b/utils/shopping_cart/verify_shopping_cart_channged.go new file mode 100644 index 00000000..6863291b --- /dev/null +++ b/utils/shopping_cart/verify_shopping_cart_channged.go @@ -0,0 +1,95 @@ +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 +} + +func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error { + for _, cartInfo := range req.Carts { + var snapShotParseInfo CartSnapshot + if err := json.Unmarshal([]byte(*cartInfo.Snapshot), &snapShotParseInfo); err != nil { + return err + } + //快照中模板设计json数据哈希值 + snapshotTemplateJsonHash := hash.JsonHashKey(snapShotParseInfo.TemplateInfo.TemplateJson) + //快照中模型设计json数据哈希值 + snapshotModelJsonHash := hash.JsonHashKey(snapShotParseInfo.ModelInfo.ModelJson) + //快照中配件设计json数据哈希值 + snapshotFittingJsonHash := hash.JsonHashKey(snapShotParseInfo.FittingInfo.FittingJson) + descrptionBuilder := strings.Builder{} + //有模板验证模板相关 + if *cartInfo.TemplateId > 0 { + if curTemplateInfo, ok := req.MapTemplate[*cartInfo.TemplateId]; !ok { + descrptionBuilder.WriteString("the template is lose
") + } else { + //当前模板设计json数据哈希值 + curTemplateJsonHash := hash.JsonHashKey(*curTemplateInfo.TemplateInfo) + //模板设计信息改变了 + if snapshotTemplateJsonHash != curTemplateJsonHash { + descrptionBuilder.WriteString("the template design info has changed
") + } + //模板标签改变了 + if snapShotParseInfo.TemplateInfo.TemplateTag != *curTemplateInfo.TemplateTag { + descrptionBuilder.WriteString("the template`s template tag has changed
") + } + } + } + //有模型验证模型相关 + if *cartInfo.ModelId > 0 { + if curModelInfo, ok := req.MapModel[*cartInfo.ModelId]; !ok { //不存在 + descrptionBuilder.WriteString("the model is lose
") + } else { + //当前模型设计json数据哈希值 + curModelJsonHash := hash.JsonHashKey(*curModelInfo.ModelInfo) + if snapshotModelJsonHash != curModelJsonHash { + descrptionBuilder.WriteString("the model design info has changed
") + } + } + } + //有配件验证配件相关 + if *cartInfo.FittingId > 0 { + if curFittingInfo, ok := req.MapModel[*cartInfo.FittingId]; !ok { //不存在 + descrptionBuilder.WriteString("the fitting is lose
") + } else { + //当前配件设计json数据哈希值 + curFittingJsonHash := hash.JsonHashKey(*curFittingInfo.ModelInfo) + if snapshotFittingJsonHash != curFittingJsonHash { + descrptionBuilder.WriteString("the fitting design info has changed
") + } + } + } + //验证尺寸相关 + if *cartInfo.SizeId > 0 { + curSize, ok := req.MapSize[*cartInfo.SizeId] + if !ok { + descrptionBuilder.WriteString("the size is lose
") + } 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("the size design info has changed
") + } + } + } + //收集错误 + descrption := descrptionBuilder.String() + if descrption != "" { + req.MapCartChange[cartInfo.Id] = descrption + } + } + return nil +}