diff --git a/constants/orders.go b/constants/orders.go index abbc45ec..070b96ac 100644 --- a/constants/orders.go +++ b/constants/orders.go @@ -24,16 +24,16 @@ type PayMethods string const ( PAY_METHOD_CARD PayMethods = "CARD" - PayMethodVISA PayMethods = "VISA" + PAY_METHOD_VISA PayMethods = "VISA" ) // 支付状态 type PayStatusCode int64 const ( - PAYSTATUSUNPAID PayStatusCode = 10 //10,未支付 - PAYSTATUSPAID PayStatusCode = 20 //20,已支付 - PAYSTATUSREFUNDED PayStatusCode = 30 //30,已退款 + PAY_STATUS_UNPAID PayStatusCode = 10 //10,未支付 + PAY_STATUS_PAID PayStatusCode = 20 //20,已支付 + PAY_STATUS_REFUNDED PayStatusCode = 30 //30,已退款 ) // 订单支付状态 @@ -45,11 +45,11 @@ type OrderPayStatusCode int64 // 30,已付尾款 // 40,已退尾款 const ( - ORDERPAYSTATUSUNPAIDDEPOSIT OrderPayStatusCode = 0 - ORDERPAYSTATUSPAIDDEPOSIT OrderPayStatusCode = 10 - ORDERPAYSTATUSREFUNDEDDEPOSIT OrderPayStatusCode = 20 - ORDERPAYSTATUSPAIDDREMAINING OrderPayStatusCode = 30 - ORDERPAYSTATUSREFUNDEDREMAINING OrderPayStatusCode = 40 + ORDER_PAY_STATUS_UNPAIDDEPOSIT OrderPayStatusCode = 0 + ORDER_PAY_STATUS_PAIDDEPOSIT OrderPayStatusCode = 10 + ORDER_PAY_STATUS_REFUNDEDDEPOSIT OrderPayStatusCode = 20 + ORDER_PAY_STATUS_PAIDDREMAINING OrderPayStatusCode = 30 + ORDER_PAY_STATUS_REFUNDEDREMAINING OrderPayStatusCode = 40 ) // 订单状态 @@ -79,6 +79,9 @@ var OrderStatusMessage map[OrderStatusCode]string // 支付状态名称 var PayStatusMessage map[PayStatusCode]string +// 支付状态名称 +var OrderPayStatusMessage map[OrderPayStatusCode]string + // 订单状态--用户可见--直邮 var OrderStatusUserDIRECTMAIL []OrderStatusCode @@ -86,23 +89,33 @@ var OrderStatusUserDIRECTMAIL []OrderStatusCode var OrderStatusUserCLOUDSTORE []OrderStatusCode func init() { + // 订单状态名称 + OrderPayStatusMessage = make(map[OrderPayStatusCode]string) + OrderPayStatusMessage[ORDER_PAY_STATUS_UNPAIDDEPOSIT] = "未付首款" + OrderPayStatusMessage[ORDER_PAY_STATUS_PAIDDEPOSIT] = "已付首款" + OrderPayStatusMessage[ORDER_PAY_STATUS_REFUNDEDDEPOSIT] = "已退首款" + OrderPayStatusMessage[ORDER_PAY_STATUS_PAIDDREMAINING] = "已付尾款" + OrderPayStatusMessage[ORDER_PAY_STATUS_REFUNDEDREMAINING] = "已退尾款" + // 订单状态名称 PayStatusMessage = make(map[PayStatusCode]string) - PayStatusMessage[PAYSTATUSUNPAID] = "Unpaid" - PayStatusMessage[PAYSTATUSPAID] = "Paid" - PayStatusMessage[PAYSTATUSREFUNDED] = "Refunded" + PayStatusMessage[PAY_STATUS_UNPAID] = "Unpaid" + PayStatusMessage[PAY_STATUS_PAID] = "Paid" + PayStatusMessage[PAY_STATUS_REFUNDED] = "Refunded" // 订单状态名称 OrderStatusMessage = make(map[OrderStatusCode]string) OrderStatusMessage[ORDER_STATUS_UNPAIDDEPOSIT] = "未支付定金" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_ORDERED] = "直邮单--已下单" + OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_ORDEREDMAINING] = "直邮单--已下单--尾款" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION] = "直邮单--开始生产" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION] = "直邮单--生产完成" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_SHIPPED] = "直邮单--已发货" OrderStatusMessage[ORDER_STATUS_DIRECTMAIL_ARRIVED] = "直邮单--已到达" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_ORDERED] = "云仓单--已下单" + OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_ORDEREDMAINING] = "云仓单--已下单-尾款" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_STARTPRODUCTION] = "云仓单--开始生产" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_COMPLETEPRODUCTION] = "云仓单--生产完成" OrderStatusMessage[ORDER_STATUS_CLOUDSTORE_ARRIVEDWAREHOUSE] = "云仓单--直达仓库" @@ -111,12 +124,14 @@ func init() { // 订单状态--用户可见--直邮 OrderStatusUserDIRECTMAIL = []OrderStatusCode{ - ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_COMPLETE, + ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_DIRECTMAIL_ORDERED, ORDER_STATUS_DIRECTMAIL_STARTPRODUCTION, ORDER_STATUS_DIRECTMAIL_COMPLETEPRODUCTION, ORDER_STATUS_DIRECTMAIL_SHIPPED, ORDER_STATUS_DIRECTMAIL_ARRIVED, + ORDER_STATUS_COMPLETE, } // 订单状态--用户可见--云仓 OrderStatusUserCLOUDSTORE = []OrderStatusCode{ - ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_COMPLETE, + ORDER_STATUS_UNPAIDDEPOSIT, ORDER_STATUS_CLOUDSTORE_ORDERED, ORDER_STATUS_CLOUDSTORE_STARTPRODUCTION, ORDER_STATUS_CLOUDSTORE_COMPLETEPRODUCTION, ORDER_STATUS_CLOUDSTORE_ARRIVEDWAREHOUSE, + ORDER_STATUS_COMPLETE, } } diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index f2a7439a..0c05b483 100644 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -73,6 +73,7 @@ type PayStatus struct { // 订单信息 type OrderInfo struct { + UserId int64 `json:"user_id"` // 物流类型 Ctime *time.Time `json:"ctime"` // 创建日期 DeliveryMethod int64 `json:"delivery_method"` // 物流类型 Metadata map[string]interface{} `json:"metadata"` // 额外参数 @@ -95,21 +96,22 @@ type OrderStatus struct { // 订单商品 type OrderProduct struct { - TotalPrice AmountInfo `json:"total_price"` // 商品总价 - ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间 - PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量 - ProductID int64 `json:"product_id"` // 商品ID - ProductName string `json:"product_name"` // 商品名称 - ItemPrice AmountInfo `json:"item_price"` // 商品单价 - ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照 - ShoppingCartSnapshot *FsShoppingCartData `json:"shopping_cart_snapshot"` // 购物车快照 - ProductCover string `json:"product_cover"` // 商品封面 - ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面 - ProductSn string `json:"product_sn"` // 商品编码 - DiyInformation *UserDiyInformation `json:"diy_information"` - SizeInfo *OrderProductSizeInfo `json:"size_info"` - FittingInfo *OrderProductFittingInfo `json:"fitting_info"` - IsHighlyCustomized int64 `json:"is_highly_customized"` + TotalPrice AmountInfo `json:"total_price"` // 商品总价 + ItemPrice AmountInfo `json:"item_price"` // 商品单价 + ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间 + PurchaseQuantity PurchaseQuantity `json:"purchase_quantity"` // 购买数量 + ProductId int64 `json:"product_id"` // 商品ID + ProductSn string `json:"product_sn"` // 商品编码 + ProductName string `json:"product_name"` // 商品名称 + ProductCover string `json:"product_cover"` // 商品封面 + ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面 + ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照 + ShoppingCartSnapshot *FsShoppingCartData `json:"shopping_cart_snapshot"` // 购物车快照 + + DiyInformation *UserDiyInformation `json:"diy_information"` + SizeInfo *OrderProductSizeInfo `json:"size_info"` + FittingInfo *OrderProductFittingInfo `json:"fitting_info"` + IsHighlyCustomized int64 `json:"is_highly_customized"` } type PurchaseQuantity struct { Current interface{} `json:"current"` @@ -131,3 +133,24 @@ type OrderProductFittingInfo struct { FittingID int64 `json:"fitting_id"` //配件ID FittingName string `json:"fitting_name"` //配件名称 } + +type ExpectedDelivery struct { + Current time.Time `json:"current"` + Initiate time.Time `json:"initiate"` +} + +type OrderProductInter struct { + TotalPrice AmountInfo `json:"total_price"` // 商品总价 + ItemPrice AmountInfo `json:"item_price"` // 商品单价 + ExpectedDelivery *ExpectedDelivery `json:"expected_delivery"` // 预计到货 + PurchaseQuantity *PurchaseQuantity `json:"purchase_quantity"` // 购买数量 + ProductId int64 `json:"product_id"` // 商品ID + ProductName string `json:"product_name"` // 商品名称 + ProductCover string `json:"product_cover"` // 商品封面 + ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面 + ProductSn string `json:"product_sn"` // 商品编码 + DiyInformation *UserDiyInformation `json:"diy_information"` + SizeInfo *OrderProductSizeInfo `json:"size_info"` + FittingInfo *OrderProductFittingInfo `json:"fitting_info"` + IsHighlyCustomized int64 `json:"is_highly_customized"` +} diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index c84373b1..92a54a39 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "fusenapi/constants" - "github.com/zeromicro/go-zero/core/logx" "sort" ) @@ -186,16 +185,17 @@ func (d *FsProductModel3dModel) GetProductMinPrice(ctx context.Context, productI switch *modelInfo.Tag { case constants.TAG_MODEL: //模型 if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 { - return errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) + mapModelMinPrice[modelInfo.Id] = 0 + continue } var stepPrice StepPriceJsonStruct if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { - logx.Error(err) return errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) } lenRange := len(stepPrice.PriceRange) if lenRange == 0 { - return errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) + mapModelMinPrice[modelInfo.Id] = 0 + continue } sort.SliceStable(stepPrice.PriceRange, func(i, j int) bool { return stepPrice.PriceRange[i].Price > stepPrice.PriceRange[j].Price diff --git a/model/gmodel/fs_shopping_cart_logic.go b/model/gmodel/fs_shopping_cart_logic.go index 21f020a8..6ebda339 100644 --- a/model/gmodel/fs_shopping_cart_logic.go +++ b/model/gmodel/fs_shopping_cart_logic.go @@ -27,7 +27,6 @@ type FsShoppingCartData struct { FittingId *int64 `gorm:"default:0;" json:"fitting_id"` // 配件id PurchaseQuantity *int64 `gorm:"default:0;" json:"purchase_quantity"` // 购买数量 Snapshot *map[string]interface{} `gorm:"default:'';" json:"snapshot"` // - SnapshotData *string `gorm:"default:'';" json:"snapshot_data"` // IsSelected *int64 `gorm:"default:0;" json:"is_selected"` // 是否被选中 0非 1是 IsHighlyCustomized *int64 `gorm:"default:0;" json:"is_highly_customized"` // 是否高度定制 0非 1是(针对客人高度定制只能后台增加如购物车) Ctime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"ctime"` // diff --git a/server/home-user-auth/internal/logic/userlogosetlogic.go b/server/home-user-auth/internal/logic/userlogosetlogic.go index 7fc085f4..2aa57b56 100644 --- a/server/home-user-auth/internal/logic/userlogosetlogic.go +++ b/server/home-user-auth/internal/logic/userlogosetlogic.go @@ -62,6 +62,7 @@ func (l *UserLogoSetLogic) UserLogoSet(req *types.UserLogoSetReq, userinfo *auth ResourceId: defaultMaterialInfo.ResourceId, ResourceUrl: defaultMaterialInfo.ResourceUrl, Ctime: &nowTime, + Metadata: defaultMaterialInfo.Metadata, } MaterialCreateRes := l.svcCtx.MysqlConn.Create(&defaultMaterial) err = MaterialCreateRes.Error diff --git a/server/order/internal/logic/createorderlogic.go b/server/order/internal/logic/createorderlogic.go index c7aded6e..802ece8d 100644 --- a/server/order/internal/logic/createorderlogic.go +++ b/server/order/internal/logic/createorderlogic.go @@ -40,7 +40,7 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth // 如果是,返回未授权的错误码 return resp.SetStatus(basic.CodeUnAuth) } - tPlus60Days := time.Now().AddDate(0, 0, 60) + tPlus60Days := time.Now().AddDate(0, 0, 60).UTC() res, err := l.svcCtx.Repositories.NewOrder.Create(l.ctx, &repositories.CreateReq{ ExpectedDeliveryTime: tPlus60Days, CurrentCurrency: string(constants.CURRENCYUSD), diff --git a/server/product/internal/logic/getfittingbypidlogic.go b/server/product/internal/logic/getfittingbypidlogic.go index 53db5460..4b63b88b 100644 --- a/server/product/internal/logic/getfittingbypidlogic.go +++ b/server/product/internal/logic/getfittingbypidlogic.go @@ -7,6 +7,7 @@ import ( "fusenapi/model/gmodel" "fusenapi/utils/auth" "fusenapi/utils/basic" + "fusenapi/utils/format" "gorm.io/gorm" "strings" @@ -111,7 +112,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us Id: fitting.Id, MaterialImg: materialImg, Title: *fitting.Title, - Price: *fitting.Price, + Price: format.CentitoDollar(*fitting.Price, 3), ModelInfo: modelInfo, IsPopular: *fitting.IsHot > 0, }) diff --git a/server/product/internal/logic/getproductsteppricelogic.go b/server/product/internal/logic/getproductsteppricelogic.go index bf5bc09d..60527bcf 100644 --- a/server/product/internal/logic/getproductsteppricelogic.go +++ b/server/product/internal/logic/getproductsteppricelogic.go @@ -91,13 +91,17 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep 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)) } - //最小价格要加配件 - minPrice += *fittingPriceInfo.Price + //最小/最大价格要加配件 + fittingPrice = *fittingPriceInfo.Price + minPrice += fittingPrice + maxPrice += fittingPrice //如果配件装箱基数比主体大,则基数以配件为主 if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity { stepPurchaseQuantity = *fittingPriceInfo.PackedUnit @@ -110,18 +114,27 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep 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, 3), + "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, 3), + "item_price": format.CentitoDollar(rangeInfo.Price+fittingPrice, 3), }) } + //计算起购数量的单价 + _, minBuyUnitsQuantityPrice, err := l.svcCtx.Repositories.NewShoppingCart.CaculateStepPrice(stepPrice.MinBuyUnitsNum, stepPrice, fittingPrice) + if err != nil { + return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get min buy quantity item price") + } mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{ "step_purchase_quantity": stepPurchaseQuantity, "step_purchase_quantity_description": stepPurchaseQuantityDescription, @@ -129,6 +142,8 @@ func (l *GetProductStepPriceLogic) GetProductStepPrice(req *types.GetProductStep "max_price": maxPrice, "step_range": stepRange, "min_buy_units_quantity": stepPrice.MinBuyUnitsNum, + "min_buy_units_quantity_total_price": format.CentitoDollarWithNoHalfAdjust(minBuyUnitsQuantityPrice*stepPrice.MinBuyUnitsNum, 2), + "min_buy_units_quantity_item_price": format.CentitoDollar(minBuyUnitsQuantityPrice, 3), } } return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) diff --git a/server/product/internal/logic/getrecommandproductlistlogic.go b/server/product/internal/logic/getrecommandproductlistlogic.go index b65c3cb1..24721e95 100644 --- a/server/product/internal/logic/getrecommandproductlistlogic.go +++ b/server/product/internal/logic/getrecommandproductlistlogic.go @@ -94,6 +94,7 @@ func (l *GetRecommandProductListLogic) GetRecommandProductList(req *types.GetRec //获取产品最低价 mapProductMinPrice := make(map[int64]int64) if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil { + logx.Error(err) return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price") } //获取产品标签相关属性 diff --git a/server/product/internal/logic/getsizebypidlogic.go b/server/product/internal/logic/getsizebypidlogic.go index 7f27f40e..46d81e4f 100644 --- a/server/product/internal/logic/getsizebypidlogic.go +++ b/server/product/internal/logic/getsizebypidlogic.go @@ -8,7 +8,6 @@ import ( "fusenapi/utils/basic" "fusenapi/utils/format" "gorm.io/gorm" - "sort" "strings" "context" @@ -81,32 +80,10 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a productIds = append(productIds, *v.ProductId) } //获取产品价格列表 - productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price list") - } mapProductMinPrice := make(map[int64]int64) - //存储产品最小价格 - for _, v := range productPriceList { - priceStrSlic := strings.Split(v.Price, ",") - priceSlice, err := format.StrSlicToIntSlice(priceStrSlic) - if err != nil { - logx.Error(err) - return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error()) - } - if len(priceSlice) == 0 { - continue - } - //正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算) - sort.Ints(priceSlice) - if min, ok := mapProductMinPrice[v.ProductId]; ok { - if min > int64(priceSlice[0]) { - mapProductMinPrice[v.ProductId] = int64(priceSlice[0]) - } - } else { - mapProductMinPrice[v.ProductId] = int64(priceSlice[0]) - } + if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product min price") } //获取对应模型数据 modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllBySizeIdsTag(l.ctx, sizeIds, constants.TAG_MODEL, "id,size_id") @@ -140,7 +117,7 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a PartsCanDeleted: *sizeInfo.PartsCanDeleted > 0, ModelId: modelList[modelIndex].Id, IsPopular: *sizeInfo.IsHot > 0, - MinPrice: float64(minPrice) / 100, + MinPrice: format.CentitoDollar(minPrice, 3), IsDefault: defaultSizeId == sizeInfo.Id, }) } diff --git a/server/product/internal/logic/gettagproductlistlogic.go b/server/product/internal/logic/gettagproductlistlogic.go index fdc951e6..a3861e39 100644 --- a/server/product/internal/logic/gettagproductlistlogic.go +++ b/server/product/internal/logic/gettagproductlistlogic.go @@ -229,6 +229,7 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn } //获取产品最低价格 if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, req.MapProductMinPrice); err != nil { + logx.Error(err) return nil, errors.New("failed to get product min price") } //获取模板 diff --git a/server/product/internal/logic/homepagerecommendproductlistlogic.go b/server/product/internal/logic/homepagerecommendproductlistlogic.go index eeb5726b..a4447811 100644 --- a/server/product/internal/logic/homepagerecommendproductlistlogic.go +++ b/server/product/internal/logic/homepagerecommendproductlistlogic.go @@ -114,6 +114,7 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty //获取产品最低价格 mapProductMinPrice := make(map[int64]int64) if err = l.svcCtx.AllModels.FsProductModel3d.GetProductMinPrice(l.ctx, productIds, mapProductMinPrice); err != nil { + logx.Error(err) return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product min price") } //获取模板(只是获取产品product_id) diff --git a/server/product/internal/types/types.go b/server/product/internal/types/types.go index 61d79237..59bcb8a7 100644 --- a/server/product/internal/types/types.go +++ b/server/product/internal/types/types.go @@ -361,7 +361,7 @@ type GetSizeByPidRsp struct { PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件 ModelId int64 `json:"model_id"` //产品主模型id IsPopular bool `json:"is_popular"` //是否受欢迎 - MinPrice float64 `json:"min_price"` //最小价格 + MinPrice string `json:"min_price"` //最小价格 IsDefault bool `json:"is_default"` //是否默认(这里的默认是跟列表页一致) } @@ -379,7 +379,7 @@ type GetFittingByPidRsp struct { Id int64 `json:"id"` MaterialImg string `json:"material_img"` Title string `json:"title"` - Price int64 `json:"price"` + Price string `json:"price"` IsPopular bool `json:"is_popular"` ModelInfo interface{} `json:"model_info"` } diff --git a/server/shopping-cart/shopping-cart_test.go b/server/shopping-cart/shopping-cart_test.go new file mode 100644 index 00000000..ef649768 --- /dev/null +++ b/server/shopping-cart/shopping-cart_test.go @@ -0,0 +1,7 @@ +package main + +import "testing" + +func TestMain(t *testing.T) { + main() +} diff --git a/server/websocket/internal/logic/datatransferlogic.go b/server/websocket/internal/logic/datatransferlogic.go index e3bb67db..f313acc6 100644 --- a/server/websocket/internal/logic/datatransferlogic.go +++ b/server/websocket/internal/logic/datatransferlogic.go @@ -179,6 +179,7 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use l.sendGetUniqueIdErrResponse(conn) return wsConnectItem{}, err } + renderCtx, renderCtxCancelFunc := context.WithCancel(l.ctx) ws := wsConnectItem{ conn: conn, userAgent: userAgent, @@ -192,7 +193,9 @@ func (l *DataTransferLogic) setConnPool(conn *websocket.Conn, userInfo *auth.Use userId: userInfo.UserId, guestId: userInfo.GuestId, extendRenderProperty: extendRenderProperty{ - renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen), + renderChan: make(chan websocket_data.RenderImageReqMsg, renderChanLen), + renderCtx: renderCtx, + renderCtxCancelFunc: renderCtxCancelFunc, }, } //保存连接 diff --git a/server/websocket/internal/logic/ws_render_image.go b/server/websocket/internal/logic/ws_render_image.go index f5a80572..2d20f1e5 100644 --- a/server/websocket/internal/logic/ws_render_image.go +++ b/server/websocket/internal/logic/ws_render_image.go @@ -3,6 +3,7 @@ package logic //处理websocket云渲染任务数据 import ( "bytes" + "context" "encoding/json" "errors" "fmt" @@ -32,7 +33,11 @@ type renderProcessor struct { // 云渲染属性 type extendRenderProperty struct { - renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列 + renderChan chan websocket_data.RenderImageReqMsg //渲染消息入口的缓冲队列 + renderCtx context.Context //渲染控制上下文(用于切换模板标签/颜色取消之前发送的不相同的任务) + renderCtxCancelFunc context.CancelFunc //渲染控制上下文取消方法 + selectColorIndex int //选择的颜色索引 + templateTag string //模板标签 } // 处理分发到这里的数据 @@ -44,6 +49,16 @@ func (r *renderProcessor) allocationMessage(w *wsConnectItem, data []byte) { logx.Error("invalid format of websocket render image message", err) return } + if renderImageData.RenderData.TemplateTag != w.extendRenderProperty.templateTag || renderImageData.RenderData.TemplateTagColor.SelectedColorIndex != w.extendRenderProperty.selectColorIndex { + //赋值 + w.extendRenderProperty.templateTag = renderImageData.RenderData.TemplateTag + w.extendRenderProperty.selectColorIndex = renderImageData.RenderData.TemplateTagColor.SelectedColorIndex + //让之前的失效 + w.extendRenderProperty.renderCtxCancelFunc() + logx.Info("模板标签/颜色更换上下文取消") + //重新赋值 + w.extendRenderProperty.renderCtx, w.extendRenderProperty.renderCtxCancelFunc = context.WithCancel(w.logic.ctx) + } select { case <-w.closeChan: //已经关闭 return diff --git a/server_api/product.api b/server_api/product.api index 687400ef..23c3e8fd 100644 --- a/server_api/product.api +++ b/server_api/product.api @@ -411,7 +411,7 @@ type GetSizeByPidRsp { PartsCanDeleted bool `json:"parts_can_deleted"` //用户可否删除配件 ModelId int64 `json:"model_id"` //产品主模型id IsPopular bool `json:"is_popular"` //是否受欢迎 - MinPrice float64 `json:"min_price"` //最小价格 + MinPrice string `json:"min_price"` //最小价格 IsDefault bool `json:"is_default"` //是否默认(这里的默认是跟列表页一致) } //获取产品模板 @@ -428,7 +428,7 @@ type GetFittingByPidRsp { Id int64 `json:"id"` MaterialImg string `json:"material_img"` Title string `json:"title"` - Price int64 `json:"price"` + Price string `json:"price"` IsPopular bool `json:"is_popular"` ModelInfo interface{} `json:"model_info"` } diff --git a/service/repositories/order.go b/service/repositories/order.go index b2349f43..d23c170d 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -8,7 +8,6 @@ import ( "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/basic" - "fusenapi/utils/fssql" "fusenapi/utils/handlers" "fusenapi/utils/order" "fusenapi/utils/pay" @@ -46,11 +45,12 @@ type ( } PayInfo struct { - PayMethod string `json:"pay_method"` // 交易方式 - PayTime time.Time `json:"pay_time"` // 支付时间 - Status gmodel.PayStatus `json:"status"` // 当前状态 - StatusLink []gmodel.PayStatus `json:"status_link"` // 状态链路 - TradeNo string `json:"trade_no"` // 支付交易号 + PayMethod string `json:"pay_method"` // 支付方式 + PaymentMethod string `json:"payment_method"` // 交易方式 + PayTime time.Time `json:"pay_time"` // 支付时间 + Status gmodel.PayStatus `json:"status"` // 当前状态 + StatusLink []gmodel.PayStatus `json:"status_link"` // 状态链路 + TradeNo string `json:"trade_no"` // 支付交易号 } OrderAddress struct { @@ -141,7 +141,17 @@ type ( DetailRes struct { ErrorCode basic.StatusResponse OrderDetail gmodel.OrderDetail - OrderDetailOriginal gmodel.OrderDetail + OrderDetailOriginal OrderDetailOriginal + } + OrderDetailOriginal struct { + Status *gmodel.OrderStatus + OrderAmount *gmodel.OrderAmount + OrderAddress *gmodel.OrderAddress + OrderProduct []gmodel.OrderProductInter + ShoppingCartSnapshot []gmodel.FsShoppingCart + ShoppingProductSnapshot []gmodel.RelaFsProduct + StatusLink []gmodel.OrderStatus + PayStatusLink []gmodel.PayStatus } /* 详情 */ @@ -173,13 +183,14 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess var payAmount int64 var payTitle string var payTime time.Time + var paymentMethod string - var paymentMethod int64 = 1 + var payMethod int64 = 1 if in.PaymentMethod == "stripe" { - paymentMethod = 1 + payMethod = 1 } if in.PaymentMethod == "paypal" { - paymentMethod = 2 + payMethod = 2 } if in.Charge != nil { @@ -211,6 +222,9 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess brand = string(charge.PaymentMethodDetails.Card.Brand) } } + if charge.PaymentMethodDetails.Type != "" { + paymentMethod = string(charge.PaymentMethodDetails.Type) + } } if charge.Currency != "" { currency = string(charge.Currency) @@ -234,16 +248,18 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess return err } var ntime = time.Now().UTC() - if (payStage == "deposit" && *orderInfo.PayStatus == int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT)) || (payStage == "remaining_balance" && *orderInfo.PayStatus == int64(constants.ORDERPAYSTATUSPAIDDEPOSIT)) { - var payStatus = int64(constants.PAYSTATUSPAID) + if (payStage == "deposit" && *orderInfo.PayStatus == int64(constants.ORDER_PAY_STATUS_UNPAIDDEPOSIT)) || (payStage == "remaining_balance" && *orderInfo.PayStatus == int64(constants.ORDER_PAY_STATUS_PAIDDEPOSIT)) { + var payStatus = int64(constants.PAY_STATUS_PAID) var payStageInt int64 var orderPayStatusCode constants.OrderPayStatusCode // 订单状态--当前 var status gmodel.OrderStatus var statusLink []gmodel.OrderStatus - var uOrderDetail = make(map[string]interface{}) + var payStatusLink []gmodel.PayStatus + var orderAmount = make(map[string]interface{}) var payInfo PayInfo - payInfo.PayMethod = in.PaymentMethod + payInfo.PayMethod = paymentMethod + payInfo.PaymentMethod = in.PaymentMethod payInfo.PayTime = payTime payInfo.TradeNo = tradeSn // 当前状态 @@ -259,29 +275,25 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess statusCode = constants.ORDER_STATUS_CLOUDSTORE_ORDERED } payStageInt = 1 - orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDEPOSIT + orderPayStatusCode = constants.ORDER_PAY_STATUS_PAIDDEPOSIT status = gmodel.OrderStatus{ Ctime: &ntime, Utime: &ntime, StatusCode: statusCode, StatusTitle: constants.OrderStatusMessage[statusCode], } - statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.OrderInfo.StatusLink, gmodel.OrderStatus{ + statusLink = order.UpdateOrderStatusLink(ress.OrderDetailOriginal.StatusLink, gmodel.OrderStatus{ Ctime: &ntime, Utime: &ntime, StatusCode: statusCode, StatusTitle: constants.OrderStatusMessage[statusCode], }) payInfo.Status = gmodel.PayStatus{ - StatusCode: int64(constants.PAYSTATUSPAID), - StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSPAID], - } - payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.Deposit.StatusLink, payInfo.Status) - uOrderDetail["order_amount"] = struct { - Deposit PayInfo `json:"deposit"` - }{ - Deposit: payInfo, + StatusCode: int64(constants.PAY_STATUS_PAID), + StatusTitle: constants.PayStatusMessage[constants.PAY_STATUS_PAID], } + payInfo.StatusLink = append(ress.OrderDetailOriginal.OrderAmount.Deposit.StatusLink, payInfo.Status) + orderAmount["deposit"] = payInfo } if payStage == "remaining_balance" { if *orderInfo.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { @@ -295,11 +307,11 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess statusCode = constants.ORDER_STATUS_CLOUDSTORE_ORDEREDMAINING } payStageInt = 2 - orderPayStatusCode = constants.ORDERPAYSTATUSPAIDDREMAINING + orderPayStatusCode = constants.ORDER_PAY_STATUS_PAIDDREMAINING var statusChildren []*gmodel.OrderStatus // 更新订单状态链路--子状态 - for oStatusLinkKey, oStatusLink := range ress.OrderDetail.OrderInfo.StatusLink { + for oStatusLinkKey, oStatusLink := range ress.OrderDetailOriginal.StatusLink { if oStatusLink.StatusCode == statusCodePre { statusChildren = append(oStatusLink.Children, &gmodel.OrderStatus{ Ctime: &ntime, @@ -307,26 +319,45 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess StatusCode: statusCode, StatusTitle: constants.OrderStatusMessage[statusCode], }) - ress.OrderDetail.OrderInfo.StatusLink[oStatusLinkKey].Children = statusChildren + ress.OrderDetailOriginal.StatusLink[oStatusLinkKey].Children = statusChildren } } - statusLink = ress.OrderDetail.OrderInfo.StatusLink + statusLink = ress.OrderDetailOriginal.StatusLink - if ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDER_STATUS_DIRECTMAIL_ORDERED || ress.OrderDetail.OrderInfo.Status.StatusCode == constants.ORDER_STATUS_CLOUDSTORE_ORDERED { - status = ress.OrderDetail.OrderInfo.Status + if ress.OrderDetailOriginal.Status.StatusCode == constants.ORDER_STATUS_DIRECTMAIL_ORDERED || ress.OrderDetailOriginal.Status.StatusCode == constants.ORDER_STATUS_CLOUDSTORE_ORDERED { + status = *ress.OrderDetailOriginal.Status status.Children = statusChildren } payInfo.Status = gmodel.PayStatus{ - StatusCode: int64(constants.PAYSTATUSPAID), - StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSPAID], + StatusCode: int64(constants.PAY_STATUS_PAID), + StatusTitle: constants.PayStatusMessage[constants.PAY_STATUS_PAID], } - payInfo.StatusLink = append(ress.OrderDetail.OrderAmount.RemainingBalance.StatusLink, payInfo.Status) - uOrderDetail["order_amount"] = struct { - RemainingBalance PayInfo `json:"remaining_balance"` - }{ - RemainingBalance: payInfo, - } + payInfo.StatusLink = append(ress.OrderDetailOriginal.OrderAmount.RemainingBalance.StatusLink, payInfo.Status) + orderAmount["remaining_balance"] = payInfo + } + + payStatusLink = append(ress.OrderDetailOriginal.PayStatusLink, gmodel.PayStatus{ + StatusCode: int64(orderPayStatusCode), + StatusTitle: constants.OrderPayStatusMessage[orderPayStatusCode], + }) + + orderAmountByte, err := json.Marshal(orderAmount) + if err != nil { + logc.Errorf(ctx, "PaymentSuccessful failed Marshal orderAmount,eventId:%s, err: %v", in.EventId, err) + return err + } + + statusLinkByte, err := json.Marshal(statusLink) + if err != nil { + logc.Errorf(ctx, "PaymentSuccessful failed Marshal statusLink,eventId:%s, err: %v", in.EventId, err) + return err + } + + payStatusLinkByte, err := json.Marshal(payStatusLink) + if err != nil { + logc.Errorf(ctx, "PaymentSuccessful failed Marshal payStatusLink,eventId:%s, err: %v", in.EventId, err) + return err } // 新增交易信息 @@ -337,7 +368,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess TradeSn: &tradeSn, PayAmount: &payAmount, PayStatus: &payStatus, - PaymentMethod: &paymentMethod, + PaymentMethod: &payMethod, PayStage: &payStageInt, CardSn: &card, CardBrand: &brand, @@ -347,33 +378,23 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess Utime: &ntime, PayTitle: &payTitle, }) - var sql string + + // 更新数据库 + var table = gmodel.NewAllModels(d.MysqlConn).FsOrder.TableName() + var resUpdate *gorm.DB + var resUpdateSql string if *orderInfo.Status == int64(constants.ORDER_STATUS_UNPAIDDEPOSIT) { - sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d, `status` = %d ", ntime, orderPayStatusCode, statusCode) + resUpdateSql = fmt.Sprintf("UPDATE %s SET `status` = %d,`pay_status` = %d , `utime` = '%s'", table, statusCode, orderPayStatusCode, ntime) } else { - sql = fmt.Sprintf(", `utime` = '%s', `pay_status` = %d", ntime, orderPayStatusCode) + resUpdateSql = fmt.Sprintf("UPDATE %s SET `pay_status` = %d , `utime` = '%s'", table, orderPayStatusCode, ntime) } + resUpdate = d.MysqlConn.Exec(fmt.Sprintf("%s ,`status_link`= JSON_MERGE_PATCH(`status_link`,?),`pay_status_link`= JSON_MERGE_PATCH(`pay_status_link`,?),`order_amount`= JSON_MERGE_PATCH(`order_amount`,?) WHERE `id` = %d", resUpdateSql, orderInfo.Id), statusLinkByte, payStatusLinkByte, orderAmountByte) - // 更新订单信息 - uOrderDetail["pay_status"] = orderPayStatusCode - uOrderDetail["order_info"] = struct { - Utime *time.Time `json:"utime"` - Status gmodel.OrderStatus `json:"status"` - StatusLink []gmodel.OrderStatus `json:"status_link"` - }{ - Utime: &ntime, - Status: status, - StatusLink: statusLink, + err = resUpdate.Error + if err != nil { + logc.Errorf(ctx, "PaymentSuccessful failed resUpdate,eventId:%s, err: %v", in.EventId, err) + return err } - fmt.Printf("uOrderDetail :%+v", uOrderDetail) - if len(uOrderDetail) > 0 { - err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, orderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", orderInfo.Id) - if err != nil { - logc.Errorf(ctx, "PaymentSuccessful failed MetadataOrderPATCH,eventId:%s, err: %v", in.EventId, err) - return err - } - } - } return nil }) @@ -383,7 +404,7 @@ func (d *defaultOrder) PaymentSuccessful(ctx context.Context, in *PaymentSuccess // 预支付--尾款 func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *CreatePrePaymentByBalanceReq) (res *CreatePrePaymentByBalanceRes, err error) { var errorCode basic.StatusResponse - var order gmodel.FsOrder + var orderInfo gmodel.FsOrder model := d.MysqlConn.Where("is_del = ?", 0) if in.UserId != 0 { model.Where("user_id = ?", in.UserId) @@ -391,7 +412,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create if in.OrderSn != "" { model.Where("order_sn = ?", in.OrderSn) } - result := model.Take(&order) + result := model.Take(&orderInfo) if result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) { errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound @@ -404,7 +425,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create }, result.Error } // 非未支付 - if *order.PayStatus != int64(constants.ORDERPAYSTATUSPAIDDEPOSIT) { + if *orderInfo.PayStatus != int64(constants.ORDER_PAY_STATUS_PAIDDEPOSIT) { errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid err = errors.New("order balance pay status is not unPaid") logc.Errorf(ctx, "create prePayment balance failed, err: %v", err) @@ -413,7 +434,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create }, err } - ress, err := d.OrderDetailHandler(ctx, &order, 1) + ress, err := d.OrderDetailHandler(ctx, &orderInfo, 1) if err != nil { logc.Errorf(ctx, "create prePayment balance failed DetailOrderDetailHandler, err: %v", err) errorCode = *basic.CodeServiceErr @@ -469,7 +490,7 @@ func (d *defaultOrder) CreatePrePaymentByBalance(ctx context.Context, in *Create // 预支付--定金 func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *CreatePrePaymentByDepositReq) (res *CreatePrePaymentByDepositRes, err error) { var errorCode basic.StatusResponse - var order gmodel.FsOrder + var orderInfo gmodel.FsOrder model := d.MysqlConn.Where("is_del = ?", 0) if in.UserId != 0 { model.Where("user_id = ?", in.UserId) @@ -477,7 +498,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create if in.OrderSn != "" { model.Where("order_sn = ?", in.OrderSn) } - result := model.Take(&order) + result := model.Take(&orderInfo) if result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) { errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound @@ -491,7 +512,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create } // 非未支付 - if *order.PayStatus != int64(constants.ORDERPAYSTATUSUNPAIDDEPOSIT) { + if *orderInfo.PayStatus != int64(constants.ORDER_PAY_STATUS_UNPAIDDEPOSIT) { errorCode = *basic.CodeErrOrderCreatePrePaymentNoUnPaid err = errors.New("order pay status is not unPaidDeposit") logc.Errorf(ctx, "create prePayment deposit failed, err: %v", err) @@ -502,7 +523,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create // 是否超时支付 ntime := time.Now().UTC() - ctime := *order.Ctime + ctime := *orderInfo.Ctime ctimeTimeOut := ctime.Add(30 * time.Minute).UTC().Unix() ntimeTimeOut := ntime.Unix() @@ -516,7 +537,7 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create }, err } - ress, err := d.OrderDetailHandler(ctx, &order, 0) + ress, err := d.OrderDetailHandler(ctx, &orderInfo, 1) if err != nil { logc.Errorf(ctx, "create prePayment deposit failed DetailOrderDetailHandler, err: %v", err) errorCode = *basic.CodeServiceErr @@ -525,62 +546,57 @@ func (d *defaultOrder) CreatePrePaymentByDeposit(ctx context.Context, in *Create }, err } - var uOrderDetail = make(map[string]interface{}) - var orderAddress *gmodel.OrderAddress + var orderAddressByte []byte + var statusLinkByte []byte + if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { orderAddress = &gmodel.OrderAddress{ Name: in.DeliveryAddress.Name, Mobile: in.DeliveryAddress.Mobile, Address: in.DeliveryAddress.Address, } - } - - var sql string = fmt.Sprintf(", `utime` = '%s'", ntime) - // 是否更新 - if in.DeliveryMethod != *order.DeliveryMethod { - sql = sql + fmt.Sprintf(",`delivery_method` = %d", in.DeliveryMethod) - if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { - uOrderDetail["delivery_address"] = orderAddress - } else { - uOrderDetail["delivery_address"] = nil - } - uOrderDetail["order_info"] = struct { - DeliveryMethod int64 `json:"delivery_method"` - Utime *time.Time `json:"utime"` - }{ - DeliveryMethod: in.DeliveryMethod, - Utime: &ntime, - } - } else { - if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { - // 更新收货地址 - if orderAddress != nil { - uOrderDetail["delivery_address"] = orderAddress - uOrderDetail["order_info"] = struct { - DeliveryMethod int64 `json:"delivery_method"` - Utime *time.Time `json:"utime"` - }{ - DeliveryMethod: in.DeliveryMethod, - Utime: &ntime, - } - } - } - } - - if len(uOrderDetail) > 0 { - err = fssql.MetadataOrderPATCH(d.MysqlConn, sql, in.OrderSn, gmodel.FsOrder{}, uOrderDetail, "id = ?", order.Id) + orderAddressByte, err = json.Marshal(orderAddress) if err != nil { + logc.Errorf(ctx, "create prePayment deposit failed orderAddressByte, err: %v", err) errorCode = *basic.CodeServiceErr - logc.Errorf(ctx, "create prePayment deposit failed MetadataOrderPATCH, err: %v", err) return &CreatePrePaymentByDepositRes{ ErrorCode: errorCode, - }, result.Error + }, err } } + // 订单状态--链路 + tPlus60Days := ntime.AddDate(0, 0, 60).UTC() + var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, ntime, tPlus60Days) + statusLinkByte, err = json.Marshal(statusLink) + if err != nil { + logc.Errorf(ctx, "create prePayment deposit failed statusLinkByte, err: %v", err) + errorCode = *basic.CodeServiceErr + return &CreatePrePaymentByDepositRes{ + ErrorCode: errorCode, + }, err + } + + // 更新数据库 + var table = gmodel.NewAllModels(d.MysqlConn).FsOrder.TableName() + var resUpdate *gorm.DB + if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { + resUpdate = d.MysqlConn.Exec(fmt.Sprintf("UPDATE %s SET `order_address` = JSON_MERGE_PATCH(`order_address`,?),`status_link` = JSON_MERGE_PATCH(`status_link`,?), `delivery_method` = ? , `utime` = ? WHERE `id` = ?", table), orderAddressByte, statusLinkByte, in.DeliveryMethod, ntime, orderInfo.Id) + } else { + resUpdate = d.MysqlConn.Exec(fmt.Sprintf("UPDATE %s SET `delivery_method` = ? , `utime` = ? WHERE `id` = ?", table), in.DeliveryMethod, ntime, orderInfo.Id) + } + err = resUpdate.Error + if err != nil { + logc.Errorf(ctx, "create prePayment deposit failed update Exec, err: %v", err) + errorCode = *basic.CodeServiceErr + return &CreatePrePaymentByDepositRes{ + ErrorCode: errorCode, + }, err + } ress.OrderDetail.OrderInfo.Utime = &ntime ress.OrderDetail.OrderInfo.DeliveryMethod = in.DeliveryMethod + ress.OrderDetail.OrderInfo.StatusLink = statusLink ress.OrderDetail.DeliveryAddress = orderAddress // 支付初始化 @@ -691,7 +707,7 @@ func (d *defaultOrder) List(ctx context.Context, in *ListReq) (res *ListRes, err // 详情 func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRes, err error) { var errorCode basic.StatusResponse - var order gmodel.FsOrder + var orderInfo gmodel.FsOrder model := d.MysqlConn.Where("is_del = ?", 0) if in.UserId != 0 { model.Where("user_id = ?", in.UserId) @@ -699,7 +715,7 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe if in.OrderSn != "" { model.Where("order_sn = ?", in.OrderSn) } - result := model.Take(&order) + result := model.Take(&orderInfo) if result.Error != nil { if errors.Is(result.Error, gorm.ErrRecordNotFound) { errorCode = *basic.CodeErrOrderCreatePrePaymentInfoNoFound @@ -727,7 +743,7 @@ func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRe // } // } - ress, err := d.OrderDetailHandler(ctx, &order, 1) + ress, err := d.OrderDetailHandler(ctx, &orderInfo, 1) if err != nil { logc.Errorf(ctx, "order detail failed, err: %v", err) errorCode = *basic.CodeServiceErr @@ -774,7 +790,9 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe } // 订单商品列表 - var orderProductList []gmodel.OrderProduct + var orderProductList []*gmodel.OrderProductInter + var shoppingProductSnapshotList []*gmodel.RelaFsProduct + var shoppingCartSnapshotList []*gmodel.FsShoppingCart var shippingFee gmodel.AmountInfo // 订单税费总价(厘) @@ -802,7 +820,9 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe var orderAddress *gmodel.OrderAddress // 支付状态 - var payStatus = constants.ORDERPAYSTATUSUNPAIDDEPOSIT + var payStatus = constants.ORDER_PAY_STATUS_UNPAIDDEPOSIT + // 订单状态 + var status = constants.ORDER_STATUS_UNPAIDDEPOSIT // 直邮 if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL { @@ -854,32 +874,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe if shoppingCart.ShoppingCartProduct.CoverResource != nil && shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil { json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &productCoverMetadata) } - snapshot, err := d.OrderDetailSnapshotHandler(ctx, shoppingCart.FsShoppingCart.Snapshot) - if err != nil { - return err - } - var shoppingCartSnapshotInter = &gmodel.FsShoppingCartData{ - Id: shoppingCart.FsShoppingCart.Id, - UserId: shoppingCart.FsShoppingCart.UserId, - ProductId: shoppingCart.FsShoppingCart.ProductId, - TemplateId: shoppingCart.FsShoppingCart.TemplateId, - ModelId: shoppingCart.FsShoppingCart.ModelId, - SizeId: shoppingCart.FsShoppingCart.SizeId, - LightId: shoppingCart.FsShoppingCart.LightId, - FittingId: shoppingCart.FsShoppingCart.FittingId, - PurchaseQuantity: shoppingCart.FsShoppingCart.PurchaseQuantity, - Snapshot: &snapshot, - SnapshotData: shoppingCart.FsShoppingCart.Snapshot, - IsSelected: shoppingCart.FsShoppingCart.IsSelected, - IsHighlyCustomized: shoppingCart.FsShoppingCart.IsHighlyCustomized, - Ctime: shoppingCart.FsShoppingCart.Ctime, - Utime: shoppingCart.FsShoppingCart.Utime, - } - var purchaseQuantityInter = gmodel.PurchaseQuantity{ - Current: *shoppingCart.PurchaseQuantity, - Initiate: *shoppingCart.PurchaseQuantity, - } - productInter := gmodel.OrderProduct{ + + productInter := gmodel.OrderProductInter{ TotalPrice: order.GetAmountInfo(order.GetAmountInfoReq{ ExchangeRate: in.ExchangeRate, Initiate: productTotalPrice, @@ -887,12 +883,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe CurrentCurrency: in.CurrentCurrency, OriginalCurrency: in.OriginalCurrency, }), - ExpectedDeliveryTime: &in.ExpectedDeliveryTime, - PurchaseQuantity: purchaseQuantityInter, - ProductID: *shoppingCart.ProductId, - ProductCover: *shoppingCart.ShoppingCartProduct.Cover, - ProductCoverMetadata: productCoverMetadata, - ProductName: *shoppingCart.ShoppingCartProduct.Title, ItemPrice: order.GetAmountInfo(order.GetAmountInfoReq{ ExchangeRate: in.ExchangeRate, Initiate: productPrice, @@ -900,10 +890,21 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe CurrentCurrency: in.CurrentCurrency, OriginalCurrency: in.OriginalCurrency, }), - ProductSnapshot: shoppingCart.ShoppingCartProduct, - ShoppingCartSnapshot: shoppingCartSnapshotInter, - ProductSn: *shoppingCart.ShoppingCartProduct.Sn, - DiyInformation: &shoppingCartSnapshot.UserDiyInformation, + ExpectedDelivery: &gmodel.ExpectedDelivery{ + Current: in.ExpectedDeliveryTime, + Initiate: in.ExpectedDeliveryTime, + }, + PurchaseQuantity: &gmodel.PurchaseQuantity{ + Current: *shoppingCart.PurchaseQuantity, + Initiate: *shoppingCart.PurchaseQuantity, + }, + ProductId: *shoppingCart.ProductId, + ProductCover: *shoppingCart.ShoppingCartProduct.Cover, + ProductCoverMetadata: productCoverMetadata, + ProductName: *shoppingCart.ShoppingCartProduct.Title, + + ProductSn: *shoppingCart.ShoppingCartProduct.Sn, + DiyInformation: &shoppingCartSnapshot.UserDiyInformation, FittingInfo: &gmodel.OrderProductFittingInfo{ FittingID: *shoppingCart.FittingId, FittingName: shoppingCartSnapshot.FittingInfo.FittingName, @@ -918,7 +919,9 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe }, IsHighlyCustomized: *shoppingCart.IsHighlyCustomized, } - orderProductList = append(orderProductList, productInter) + orderProductList = append(orderProductList, &productInter) + shoppingProductSnapshotList = append(shoppingProductSnapshotList, shoppingCart.ShoppingCartProduct) + shoppingCartSnapshotList = append(shoppingCartSnapshotList, &shoppingCart.FsShoppingCart) } subtotal = order.GetAmountInfo(order.GetAmountInfoReq{ @@ -941,8 +944,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe var depositInt int64 = orderTotal / 2 var deposit = gmodel.PayInfo{ Status: gmodel.PayStatus{ - StatusCode: int64(constants.PAYSTATUSUNPAID), - StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID], + StatusCode: int64(constants.PAY_STATUS_UNPAID), + StatusTitle: constants.PayStatusMessage[constants.PAY_STATUS_UNPAID], }, StatusLink: make([]gmodel.PayStatus, 0), PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{ @@ -958,8 +961,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe var remainingBalanceInt int64 = orderTotal - depositInt var remainingBalance = gmodel.PayInfo{ Status: gmodel.PayStatus{ - StatusCode: int64(constants.PAYSTATUSUNPAID), - StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID], + StatusCode: int64(constants.PAY_STATUS_UNPAID), + StatusTitle: constants.PayStatusMessage[constants.PAY_STATUS_UNPAID], }, StatusLink: make([]gmodel.PayStatus, 0), PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{ @@ -980,48 +983,36 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe Total: total, } - // 订单状态--当前 - var status = gmodel.OrderStatus{ - Ctime: &nowTime, - Utime: &nowTime, - StatusCode: constants.ORDER_STATUS_UNPAIDDEPOSIT, - StatusTitle: constants.OrderStatusMessage[constants.ORDER_STATUS_UNPAIDDEPOSIT], - } // 订单状态--链路 var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime) - var orderInfo = gmodel.OrderInfo{ - Ctime: &nowTime, - DeliveryMethod: in.DeliveryMethod, - OrderSn: orderSn, - Status: status, - StatusLink: statusLink, + + byteOrderProduct, _ := json.Marshal(orderProductList) + var byteOrderAddress []byte + if orderAddress != nil { + byteOrderAddress, _ = json.Marshal(orderAddress) } - var orderDetail = gmodel.OrderDetail{ - DeliveryAddress: orderAddress, - OrderAmount: orderAmount, - OrderInfo: orderInfo, - OrderProduct: orderProductList, - PayStatus: payStatus, - PayTimeout: 30 * time.Minute, - } + byteOrderAmount, _ := json.Marshal(orderAmount) + byteShoppingCartSnapshot, _ := json.Marshal(shoppingCartSnapshotList) + byteShoppingProductSnapshot, _ := json.Marshal(shoppingProductSnapshotList) + byteStatusLink, _ := json.Marshal(statusLink) - // 数据库操作 - orderDetailByte, err := json.Marshal(orderDetail) - if err != nil { - return err - } - var order = gmodel.FsOrder{ - UserId: &in.UserId, - DeliveryMethod: &in.DeliveryMethod, - OrderSn: &orderSn, - Status: (*int64)(&status.StatusCode), - PayStatus: (*int64)(&payStatus), - Ctime: &nowTime, - Metadata: &orderDetailByte, - } // 创建订单 - resultCreate := tx.Create(&order) + resultCreate := tx.Create(&gmodel.FsOrder{ + OrderProduct: &byteOrderProduct, + OrderAddress: &byteOrderAddress, + OrderAmount: &byteOrderAmount, + ShoppingCartSnapshot: &byteShoppingCartSnapshot, + ShoppingProductSnapshot: &byteShoppingProductSnapshot, + StatusLink: &byteStatusLink, + UserId: &in.UserId, + DeliveryMethod: &in.DeliveryMethod, + OrderSn: &orderSn, + Status: (*int64)(&status), + PayStatus: (*int64)(&payStatus), + Ctime: &nowTime, + }) + if resultCreate.Error != nil { return resultCreate.Error } @@ -1051,8 +1042,8 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe }, nil } -// 处理订单购物车快照 -func (d *defaultOrder) OrderDetailSnapshotHandler(ctx context.Context, req *string) (res map[string]interface{}, err error) { +// 订单购物车快照处理 +func (d *defaultOrder) OrderShoppingCartSnapshotHandler(ctx context.Context, req *string) (res map[string]interface{}, err error) { var snapshot map[string]interface{} json.Unmarshal([]byte(*req), &snapshot) snapshotFittingInfoData, snapshotFittingInfoEx := snapshot["fitting_info"] @@ -1108,37 +1099,170 @@ func (d *defaultOrder) OrderDetailSnapshotHandler(ctx context.Context, req *stri templateInfoMap["template_tag"] = templateTag } snapshot["template_info"] = templateInfoMap + + snapshotLightInfoData, snapshotLightInfoEx := snapshot["light_info"] + var lightInfoMap map[string]interface{} + if snapshotLightInfoEx { + var snapshotLightInfoJson map[string]interface{} + var lightTag string + snapshotLightInfo := snapshotLightInfoData.(map[string]interface{}) + snapshotLightInfoJsonData, snapshotLightInfoJsonEx := snapshotLightInfo["light_json"] + if snapshotLightInfoJsonEx { + json.Unmarshal([]byte(snapshotLightInfoJsonData.(string)), &snapshotLightInfoJson) + } + lightTagData, lightTagEx := snapshotLightInfo["light_tag"] + if lightTagEx { + lightTag = lightTagData.(string) + } + lightInfoMap = make(map[string]interface{}, 2) + lightInfoMap["light_json"] = snapshotLightInfoJson + lightInfoMap["light_tag"] = lightTag + } + snapshot["light_info"] = lightInfoMap return snapshot, nil } // 详情处理 func (d *defaultOrder) OrderDetailHandler(ctx context.Context, orderInfo *gmodel.FsOrder, original int64) (res *DetailRes, err error) { - var orderDetail gmodel.OrderDetail - err = json.Unmarshal(*orderInfo.Metadata, &orderDetail) + var orderAmount gmodel.OrderAmount + err = json.Unmarshal(*orderInfo.OrderAmount, &orderAmount) if err != nil { - logc.Errorf(ctx, "order detail handler unmarshal metadata failed, err: %v", err) + logc.Errorf(ctx, "order detail handler unmarshal OrderAmount failed, err: %v", err) return nil, err } - orderDetailOriginal := orderDetail - if original == 1 { - for orderProductKey, orderProduct := range orderDetail.OrderProduct { - orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) - orderDetail.OrderProduct[orderProductKey].TotalPrice = order.GetAmountInfoFormat(&orderProduct.TotalPrice) - orderDetail.OrderProduct[orderProductKey].PurchaseQuantity = order.GetPurchaseQuantity(&orderProduct.PurchaseQuantity) - orderDetail.OrderProduct[orderProductKey].ProductSnapshot = nil - orderDetail.OrderProduct[orderProductKey].ShoppingCartSnapshot.SnapshotData = nil + + var orderAddress *gmodel.OrderAddress + if orderInfo.OrderAddress != nil { + err = json.Unmarshal(*orderInfo.OrderAddress, &orderAddress) + if err != nil { + logc.Errorf(ctx, "order detail handler unmarshal OrderAddress failed, err: %v", err) + return nil, err } - orderDetail.OrderInfo.StatusLink = order.GetOrderStatusLinkUser(orderDetail.OrderInfo.DeliveryMethod, orderDetail.OrderInfo.StatusLink) - orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Deposit.PayAmount) - orderDetail.OrderAmount.RemainingBalance.PayAmount = order.GetAmountInfoFormat(&orderDetail.OrderAmount.RemainingBalance.PayAmount) - orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Subtotal) - orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderDetail.OrderAmount.Total) - orderDetail.PayTimeout = time.Duration(orderDetail.OrderInfo.Ctime.Add(orderDetail.PayTimeout).UTC().Unix() - time.Now().UTC().Unix()) + } + + var orderProduct []gmodel.OrderProductInter + err = json.Unmarshal(*orderInfo.OrderProduct, &orderProduct) + if err != nil { + logc.Errorf(ctx, "order detail handler unmarshal OrderProduct failed, err: %v", err) + return nil, err + } + + var shoppingCartSnapshot []gmodel.FsShoppingCart + err = json.Unmarshal(*orderInfo.ShoppingCartSnapshot, &shoppingCartSnapshot) + if err != nil { + logc.Errorf(ctx, "order detail handler unmarshal ShoppingCartSnapshot failed, err: %v", err) + return nil, err + } + + var shoppingProductSnapshot []gmodel.RelaFsProduct + err = json.Unmarshal(*orderInfo.ShoppingProductSnapshot, &shoppingProductSnapshot) + if err != nil { + logc.Errorf(ctx, "order detail handler unmarshal ShoppingCartSnapshot failed, err: %v", err) + return nil, err + } + + var statusLink []gmodel.OrderStatus + err = json.Unmarshal(*orderInfo.StatusLink, &statusLink) + if err != nil { + logc.Errorf(ctx, "order detail handler unmarshal StatusLink failed, err: %v", err) + return nil, err + } + + var payStatusLink []gmodel.PayStatus + if orderInfo.PayStatusLink != nil { + err = json.Unmarshal(*orderInfo.PayStatusLink, &payStatusLink) + if err != nil { + logc.Errorf(ctx, "order detail handler unmarshal PayStatusLink failed, err: %v", err) + return nil, err + } + } + var status = order.GetOrderStatusCurrent(statusLink, constants.OrderStatusCode(*orderInfo.Status)) + var orderDetail gmodel.OrderDetail + var orderMetadata map[string]interface{} + if orderInfo.Metadata != nil { + json.Unmarshal(*orderInfo.Metadata, &orderMetadata) + } + if original == 1 { + orderDetail.DeliveryAddress = orderAddress + orderDetail.OrderAmount = orderAmount + orderDetail.OrderAmount.Deposit.PayAmount = order.GetAmountInfoFormat(&orderAmount.Deposit.PayAmount) + orderDetail.OrderAmount.RemainingBalance.PayAmount = order.GetAmountInfoFormat(&orderAmount.RemainingBalance.PayAmount) + orderDetail.OrderAmount.Subtotal = order.GetAmountInfoFormat(&orderAmount.Subtotal) + orderDetail.OrderAmount.Total = order.GetAmountInfoFormat(&orderAmount.Total) + orderDetail.PayStatus = constants.OrderPayStatusCode(*orderInfo.PayStatus) + orderDetail.PayTimeout = time.Duration(orderInfo.Ctime.Add(30*time.Minute).UTC().Unix() - time.Now().UTC().Unix()) + orderDetail.OrderInfo = gmodel.OrderInfo{ + UserId: *orderInfo.UserId, + DeliveryMethod: *orderInfo.DeliveryMethod, + OrderSn: *orderInfo.OrderSn, + Ctime: orderInfo.Ctime, + Utime: orderInfo.Utime, + Status: status, + StatusLink: order.GetOrderStatusLinkUser(*orderInfo.DeliveryMethod, statusLink), + Metadata: orderMetadata, + } + + var orderProductList []gmodel.OrderProduct + for _, productValue := range orderProduct { + var shoppingCartSnapshotData gmodel.FsShoppingCartData + for _, shoppingCartSnapshotValue := range shoppingCartSnapshot { + snapshot, err := d.OrderShoppingCartSnapshotHandler(ctx, shoppingCartSnapshotValue.Snapshot) + if err != nil { + logc.Errorf(ctx, "OrderDetailHandler OrderShoppingCartSnapshotHandler failed, err: %v", err) + return nil, err + } + shoppingCartSnapshotData.Id = shoppingCartSnapshotValue.Id + shoppingCartSnapshotData.UserId = shoppingCartSnapshotValue.UserId + shoppingCartSnapshotData.ProductId = shoppingCartSnapshotValue.ProductId + shoppingCartSnapshotData.TemplateId = shoppingCartSnapshotValue.TemplateId + shoppingCartSnapshotData.ModelId = shoppingCartSnapshotValue.ModelId + shoppingCartSnapshotData.SizeId = shoppingCartSnapshotValue.SizeId + shoppingCartSnapshotData.LightId = shoppingCartSnapshotValue.LightId + shoppingCartSnapshotData.FittingId = shoppingCartSnapshotValue.FittingId + shoppingCartSnapshotData.PurchaseQuantity = shoppingCartSnapshotValue.PurchaseQuantity + shoppingCartSnapshotData.IsSelected = shoppingCartSnapshotValue.IsSelected + shoppingCartSnapshotData.IsSelected = shoppingCartSnapshotValue.IsSelected + shoppingCartSnapshotData.IsHighlyCustomized = shoppingCartSnapshotValue.IsHighlyCustomized + shoppingCartSnapshotData.Ctime = shoppingCartSnapshotValue.Ctime + shoppingCartSnapshotData.Utime = shoppingCartSnapshotValue.Utime + shoppingCartSnapshotData.Snapshot = &snapshot + } + + orderProductItem := gmodel.OrderProduct{ + TotalPrice: order.GetAmountInfoFormat(&productValue.TotalPrice), + ItemPrice: order.GetAmountInfoFormat(&productValue.ItemPrice), + ExpectedDeliveryTime: &productValue.ExpectedDelivery.Current, + PurchaseQuantity: *productValue.PurchaseQuantity, + ProductId: productValue.ProductId, + ProductSn: productValue.ProductSn, + ProductName: productValue.ProductName, + ProductCover: productValue.ProductCover, + ProductCoverMetadata: productValue.ProductCoverMetadata, + ShoppingCartSnapshot: &shoppingCartSnapshotData, + + DiyInformation: productValue.DiyInformation, + SizeInfo: productValue.SizeInfo, + FittingInfo: productValue.FittingInfo, + IsHighlyCustomized: productValue.IsHighlyCustomized, + } + + orderProductList = append(orderProductList, orderProductItem) + } + orderDetail.OrderProduct = orderProductList } return &DetailRes{ - OrderDetail: orderDetail, - OrderDetailOriginal: orderDetailOriginal, + OrderDetail: orderDetail, + OrderDetailOriginal: OrderDetailOriginal{ + Status: &status, + OrderAmount: &orderAmount, + OrderAddress: orderAddress, + OrderProduct: orderProduct, + ShoppingCartSnapshot: shoppingCartSnapshot, + ShoppingProductSnapshot: shoppingProductSnapshot, + StatusLink: statusLink, + PayStatusLink: payStatusLink, + }, }, nil } diff --git a/utils/format/number.go b/utils/format/number.go index d4912c5e..3782ac74 100644 --- a/utils/format/number.go +++ b/utils/format/number.go @@ -1,7 +1,7 @@ package format import ( - "log" + "github.com/zeromicro/go-zero/core/logx" "strconv" "strings" ) @@ -9,10 +9,10 @@ import ( // 数字变成带千分位的字符串 func NumToStringWithThousandthPercentile(numberStr string) string { if _, err := strconv.ParseFloat(numberStr, 64); err != nil { - log.Fatalln("is not a number") + logx.Error("is not a number") return "" } - sliceList := strings.Split(numberStr, ".") + sliceList := strings.Split(numberStr, ".") //切分开小数 s := sliceList[0] f := "" if len(sliceList) == 2 { diff --git a/utils/order/order.go b/utils/order/order.go index 0036ad7c..e28f0278 100644 --- a/utils/order/order.go +++ b/utils/order/order.go @@ -208,6 +208,12 @@ func GetOrderStatusLinkUser(deliveryMethod int64, statusLink []gmodel.OrderStatu } // 获取订单当前状态 -func GenerateOrderStatusCurrent() gmodel.OrderStatus { - return gmodel.OrderStatus{} +func GetOrderStatusCurrent(statusLink []gmodel.OrderStatus, orderStatusCode constants.OrderStatusCode) gmodel.OrderStatus { + var status gmodel.OrderStatus + for _, v := range statusLink { + if v.StatusCode == orderStatusCode { + status = v + } + } + return status }