diff --git a/model/gmodel/fs_order_logic.go b/model/gmodel/fs_order_logic.go index 582c0ab6..3edc5d6b 100644 --- a/model/gmodel/fs_order_logic.go +++ b/model/gmodel/fs_order_logic.go @@ -7,20 +7,6 @@ import ( // TODO: 使用model的属性做你想做的 -type NewFsOrder struct { - Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单ID - UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID - DeliveryMethod *int64 `gorm:"index;default:0;" json:"delivery_method"` // 物流类型 - OrderSn *string `gorm:"index;default:'';" json:"order_sn"` // - OrderSource *string `gorm:"default:'';" json:"order_source"` // - Status *int64 `gorm:"index;default:0;" json:"status"` // 订单状态 - PayStatus *int64 `gorm:"default:0;" json:"pay_status"` // 支付状态 - Metadata *OrderDetail `gorm:"metadata,type:json" json:"metadata"` // - 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"` // - IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:0=否,1=是 -} - // 订单详情 type OrderDetail struct { DeliveryAddress *OrderAddress `json:"delivery_address"` // 收货地址 @@ -53,7 +39,7 @@ type PayInfo struct { Metadata map[string]interface{} `json:"metadata"` // 额外参数 PayAmount AmountInfo `json:"pay_amount"` // 金额明细 PayMethod string `json:"pay_method"` // 交易方式 - PayTime time.Time `json:"pay_time"` // 支付时间 + PayTime **time.Time `json:"pay_time"` // 支付时间 Status PayStatus `json:"status"` // 当前状态 StatusLink []PayStatus `json:"status_link"` // 状态链路 TradeNo string `json:"trade_no"` // 支付交易号 @@ -86,35 +72,35 @@ type PayStatus struct { // 订单信息 type OrderInfo struct { - Ctime time.Time `json:"ctime"` // 创建日期 + Ctime *time.Time `json:"ctime"` // 创建日期 DeliveryMethod int64 `json:"delivery_method"` // 物流类型 Metadata map[string]interface{} `json:"metadata"` // 额外参数 OrderSn string `json:"order_sn"` // 订单编号 Status OrderStatus `json:"status"` // 当前状态 StatusLink []OrderStatus `json:"status_link"` // 状态链路 - Utime time.Time `json:"utime"` // 更新时间 + Utime *time.Time `json:"utime"` // 更新时间 } // 订单状态--用户 type OrderStatus struct { Children []*OrderStatus `json:"children"` // 子状态,管理人员的处理状态, 用户不可见 - Ctime time.Time `json:"ctime"` // 创建时间 - ExpectedTime time.Time `json:"expected_time"` // 预计时间 + Ctime *time.Time `json:"ctime"` // 创建时间 + ExpectedTime *time.Time `json:"expected_time"` // 预计时间 Metadata map[string]interface{} `json:"metadata"` // 额外参数 StatusCode constants.OrderStatusCode `json:"status_code"` // 状态编码 StatusTitle string `json:"status_title"` // 状态名称 - Utime time.Time `json:"utime"` // 更新时间 + Utime *time.Time `json:"utime"` // 更新时间 } // 订单商品 type OrderProduct struct { TotalPrice AmountInfo `json:"amount"` // 商品总价 - ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间 + ExpectedDeliveryTime *time.Time `json:"expected_delivery_time"` // 预计到货时间 PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量 ProductID int64 `json:"product_id"` // 商品ID ProductName string `json:"product_name"` // 商品名称 ItemPrice AmountInfo `json:"product_price"` // 商品单价 - ProductSnapshot map[string]interface{} `json:"product_snapshot"` // 商品快照 + ProductSnapshot interface{} `json:"product_snapshot"` // 商品快照 ShoppingCartSnapshot *FsShoppingCart `json:"shopping_cart_snapshot"` // 购物车快照 ProductCover string `json:"product_cover"` // 商品封面 ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面 diff --git a/model/gmodel/fs_shopping_cart_logic.go b/model/gmodel/fs_shopping_cart_logic.go index 2e6da87d..63947f74 100644 --- a/model/gmodel/fs_shopping_cart_logic.go +++ b/model/gmodel/fs_shopping_cart_logic.go @@ -4,6 +4,10 @@ import ( "context" ) +func (m *FsShoppingCartModel) TableName() string { + return m.name +} + // 关联查询 type RelaFsShoppingCart struct { FsShoppingCart @@ -37,6 +41,7 @@ type ModelInfo struct { type FittingInfo struct { FittingJson string `json:"fitting_json"` //配件设计json数据 FittingName string `json:"fitting_name"` //配件名称 + } type TemplateInfo struct { TemplateJson string `json:"template_json"` //模板设计json数据 diff --git a/server/order/internal/handler/orderdetailhandler.go b/server/order/internal/handler/orderdetailhandler.go new file mode 100644 index 00000000..6a6e661d --- /dev/null +++ b/server/order/internal/handler/orderdetailhandler.go @@ -0,0 +1,35 @@ +package handler + +import ( + "net/http" + "reflect" + + "fusenapi/utils/basic" + + "fusenapi/server/order/internal/logic" + "fusenapi/server/order/internal/svc" + "fusenapi/server/order/internal/types" +) + +func OrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + + var req types.OrderDetailReq + userinfo, err := basic.RequestParse(w, r, svcCtx, &req) + if err != nil { + return + } + + // 创建一个业务逻辑层实例 + l := logic.NewOrderDetailLogic(r.Context(), svcCtx) + + rl := reflect.ValueOf(l) + basic.BeforeLogic(w, r, rl) + + resp := l.OrderDetail(&req, userinfo) + + if !basic.AfterLogic(w, r, rl, resp) { + basic.NormalAfterLogic(w, r, resp) + } + } +} diff --git a/server/order/internal/handler/routes.go b/server/order/internal/handler/routes.go index 474d436c..e3554925 100644 --- a/server/order/internal/handler/routes.go +++ b/server/order/internal/handler/routes.go @@ -23,10 +23,15 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Handler: CreatePrePaymentDepositHandler(serverCtx), }, { - Method: http.MethodPost, + Method: http.MethodGet, Path: "/api/order/list", Handler: OrderListHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/api/order/detail", + Handler: OrderDetailHandler(serverCtx), + }, }, ) } diff --git a/server/order/internal/logic/createorderlogic.go b/server/order/internal/logic/createorderlogic.go index e2495155..0cd09c94 100644 --- a/server/order/internal/logic/createorderlogic.go +++ b/server/order/internal/logic/createorderlogic.go @@ -36,7 +36,7 @@ func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Creat func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth.UserInfo) (resp *basic.Response) { // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) // userinfo 传入值时, 一定不为null - if userinfo.IsUser() { + if !userinfo.IsUser() { // 如果是,返回未授权的错误码 return resp.SetStatus(basic.CodeUnAuth) } @@ -54,7 +54,9 @@ func (l *CreateOrderLogic) CreateOrder(req *types.CreateOrderReq, userinfo *auth return resp.SetStatus(&res.ErrorCode) } - return resp.SetStatus(basic.CodeOK) + return resp.SetStatus(basic.CodeOK, map[string]interface{}{ + "order_sn": res.OrderSn, + }) } // 处理逻辑后 w,r 如:重定向, resp 必须重新处理 diff --git a/server/order/internal/logic/orderdetaillogic.go b/server/order/internal/logic/orderdetaillogic.go new file mode 100644 index 00000000..b4b2aef9 --- /dev/null +++ b/server/order/internal/logic/orderdetaillogic.go @@ -0,0 +1,57 @@ +package logic + +import ( + "fusenapi/service/repositories" + "fusenapi/utils/auth" + "fusenapi/utils/basic" + + "context" + + "fusenapi/server/order/internal/svc" + "fusenapi/server/order/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type OrderDetailLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewOrderDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderDetailLogic { + return &OrderDetailLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +// 处理进入前逻辑w,r +// func (l *OrderDetailLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) { +// } + +func (l *OrderDetailLogic) OrderDetail(req *types.OrderDetailReq, userinfo *auth.UserInfo) (resp *basic.Response) { + // 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data) + // userinfo 传入值时, 一定不为null + if !userinfo.IsUser() { + // 如果是,返回未授权的错误码 + return resp.SetStatus(basic.CodeUnAuth) + } + res, err := l.svcCtx.Repositories.NewOrder.Detail(l.ctx, &repositories.DetailReq{ + OrderSn: req.OrderSn, + UserId: userinfo.UserId, + }) + if err != nil { + return resp.SetStatus(basic.CodeApiErr) + } + + return resp.SetStatus(basic.CodeOK, map[string]interface{}{ + "order_detail": res, + }) +} + +// 处理逻辑后 w,r 如:重定向, resp 必须重新处理 +// func (l *OrderDetailLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) { +// // httpx.OkJsonCtx(r.Context(), w, resp) +// } diff --git a/server/order/internal/types/types.go b/server/order/internal/types/types.go index 3deff58e..ce2e2805 100644 --- a/server/order/internal/types/types.go +++ b/server/order/internal/types/types.go @@ -5,6 +5,10 @@ import ( "fusenapi/utils/basic" ) +type OrderDetailReq struct { + OrderSn string `form:"order_sn"` +} + type CreateOrderReq struct { CartIds []int64 `json:"cart_ids"` DeliveryMethod int64 `json:"delivery_method,options=[1,2]"` diff --git a/server/shopping-cart/internal/logic/getcartslogic.go b/server/shopping-cart/internal/logic/getcartslogic.go index 9ebdb738..c77ac8fa 100644 --- a/server/shopping-cart/internal/logic/getcartslogic.go +++ b/server/shopping-cart/internal/logic/getcartslogic.go @@ -208,6 +208,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo IsInvalid: false, InvalidDescription: "", IsHighlyCustomized: *cart.IsHighlyCustomized > 0, + IsSelected: *cart.IsSelected > 0, } //是否有失效的 if description, ok := mapCartChange[cart.Id]; ok { diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index 2ff85906..6ae69b01 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -52,6 +52,7 @@ type CartItem struct { IsHighlyCustomized bool `json:"is_highly_customized"` //是否高度定制 IsInvalid bool `json:"is_invalid"` //是否无效 InvalidDescription string `json:"invalid_description"` //无效原因 + IsSelected bool `json:"is_selected"` //是否选中 } type ProductInfo struct { diff --git a/server/shopping-cart/order_test.go b/server/shopping-cart/order_test.go new file mode 100644 index 00000000..ef649768 --- /dev/null +++ b/server/shopping-cart/order_test.go @@ -0,0 +1,7 @@ +package main + +import "testing" + +func TestMain(t *testing.T) { + main() +} diff --git a/server_api/order.api b/server_api/order.api index bcaf2561..cf61669a 100644 --- a/server_api/order.api +++ b/server_api/order.api @@ -18,8 +18,15 @@ service order { post /api/order/create-prepayment-deposit(CreatePrePaymentDepositReq) returns (response); @handler OrderListHandler - post /api/order/list(OrderListReq) returns (response); + get /api/order/list(OrderListReq) returns (response); + @handler OrderDetailHandler + get /api/order/detail(OrderDetailReq) returns (response); + +} + +type OrderDetailReq { + OrderSn string `form:"order_sn"` } type CreateOrderReq { diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index cb441d90..19ec260b 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -69,6 +69,7 @@ type CartItem { 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 diff --git a/service/repositories/image_handle.go b/service/repositories/image_handle.go index 052d7ca4..acf1f0c2 100644 --- a/service/repositories/image_handle.go +++ b/service/repositories/image_handle.go @@ -9,6 +9,7 @@ import ( "fusenapi/utils/curl" "fusenapi/utils/file" "fusenapi/utils/hash" + "strings" "time" "github.com/aws/aws-sdk-go/aws/session" @@ -222,21 +223,22 @@ type TemplateTagColor struct { } func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) { - // 查询logo最新基础信息 - resLogoInfo, err := l.LogoInfo(ctx, &LogoInfoReq{ - UserId: in.UserId, - GuestId: in.GuestId, - }) + s := strings.Split(in.LogoUrl, "/") + if len(s) <= 1 { + return nil, errors.New("无效的logo") + } + logoResourceId := s[len(s)-1] + userMaterialModel := gmodel.NewFsUserMaterialModel(l.MysqlConn) + resLogoInfo, err := userMaterialModel.FindOneByLogoResourceId(ctx, logoResourceId) if err != nil { logx.Error(err) return nil, err } - // 根据hash 查询数据资源 var hashKeyData = *in hashKeyData.GuestId = 0 hashKeyData.UserId = 0 - hashKeyData.LogoUrl = *resLogoInfo.LogoUrl + hashKeyData.LogoUrl = in.LogoUrl var hashKeyDataMap map[string]interface{} hashKeyDataB, _ := json.Marshal(hashKeyData) json.Unmarshal(hashKeyDataB, &hashKeyDataMap) diff --git a/service/repositories/order.go b/service/repositories/order.go index e821d2d9..6e96a452 100644 --- a/service/repositories/order.go +++ b/service/repositories/order.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "fusenapi/constants" "fusenapi/model/gmodel" "fusenapi/utils/basic" @@ -11,6 +12,7 @@ import ( "time" "github.com/aws/aws-sdk-go/aws/session" + "github.com/zeromicro/go-zero/core/logx" "gorm.io/gorm" ) @@ -30,6 +32,7 @@ type ( // 预支付 // 列表 // 详情 + Detail(ctx context.Context, in *DetailReq) (res *DetailRes, err error) } OrderAddress struct { @@ -54,20 +57,54 @@ type ( OrderSn string } /* 下单 */ + + /* 详情 */ + DetailReq struct { + UserId int64 `json:"user_id"` + OrderSn string `json:"order_sn"` + } + DetailRes struct { + } + /* 详情 */ ) +// 详情 +func (d *defaultOrder) Detail(ctx context.Context, in *DetailReq) (res *DetailRes, err error) { + var order gmodel.FsOrder + result := d.MysqlConn.Where("order_sn = ?", in.OrderSn).Where("user_id = ?", in.UserId).Take(&order) + if result.Error != nil { + return nil, result.Error + } + d.OrderDetailHandler(ctx, &order) + return &DetailRes{}, nil +} + +func (d *defaultOrder) OrderDetailHandler(ctx context.Context, order *gmodel.FsOrder) (res *DetailRes, err error) { + var orderDetail gmodel.OrderDetail + + err = json.Unmarshal(*order.Metadata, &orderDetail) + if err != nil { + logx.Errorf("create handler unmarshal metadata failed, err: %v", err) + return nil, err + } + fmt.Println(orderDetail) + + return nil, nil +} + // 下单 func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error) { var errorCode basic.StatusResponse // 订单编号 - var orderSn string = order.GenerateOrderNumber(int(in.DeliveryMethod), int(in.UserId)) + var orderSn string = order.GenerateOrderNumber() err = d.MysqlConn.WithContext(ctx).Transaction(func(tx *gorm.DB) error { // 查询购物车 var shoppingCartList []*gmodel.RelaFsShoppingCart - resShoppingCartFind := tx.Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB { - return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource") - }).Preload("ShoppingCartProductPriceList"). + resShoppingCartFind := tx.Table(gmodel.NewFsShoppingCartModel(tx).TableName()). + Preload("ShoppingCartProduct", func(dbPreload *gorm.DB) *gorm.DB { + return dbPreload.Table(gmodel.NewFsProductModel(tx).TableName()).Preload("CoverResource") + }).Preload("ShoppingCartProductPriceList"). Preload("ShoppingCartProductModel3dList"). Preload("ShoppingCartProductModel3dFitting"). Where("id IN ?", in.CartIds). @@ -150,7 +187,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe } else { var isProductPrice bool for _, shoppingCartProductPriceInfo := range shoppingCart.ShoppingCartProductPriceList { - if shoppingCart.SizeId == shoppingCartProductPriceInfo.SizeId { + if *shoppingCart.SizeId == *shoppingCartProductPriceInfo.SizeId { shoppingCartProductPrice = shoppingCartProductPriceInfo isProductPrice = true break @@ -172,7 +209,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe } else { var isProductModel bool for _, shoppingCartProductModel3dInfo := range shoppingCart.ShoppingCartProductModel3dList { - if shoppingCart.SizeId == shoppingCartProductModel3dInfo.SizeId { + if *shoppingCart.SizeId == *shoppingCartProductModel3dInfo.SizeId { shoppingCartProductModel3d = shoppingCartProductModel3dInfo isProductModel = true break @@ -216,8 +253,6 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe orderProductTotal = orderProductTotal + productTotalPrice // 订单商品 - var productSnapshot = make(map[string]interface{}, 1) - productSnapshot["product_snapshot"] = shoppingCart.ShoppingCartProduct var productCoverMetadata map[string]interface{} if shoppingCart.ShoppingCartProduct.CoverResource != nil && shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil { json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &productCoverMetadata) @@ -230,7 +265,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe CurrentCurrency: in.CurrentCurrency, OriginalCurrency: in.OriginalCurrency, }), - ExpectedDeliveryTime: in.ExpectedDeliveryTime, + ExpectedDeliveryTime: &in.ExpectedDeliveryTime, PurchaseQuantity: *shoppingCart.PurchaseQuantity, ProductID: *shoppingCart.ProductId, ProductCover: *shoppingCart.ShoppingCartProduct.Cover, @@ -243,7 +278,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe CurrentCurrency: in.CurrentCurrency, OriginalCurrency: in.OriginalCurrency, }), - ProductSnapshot: productSnapshot, + ProductSnapshot: shoppingCart.ShoppingCartProduct, ShoppingCartSnapshot: &shoppingCart.FsShoppingCart, ProductSn: *shoppingCart.ShoppingCartProduct.Sn, DiyInformation: &shoppingCartSnapshot.UserDiyInformation, @@ -322,15 +357,15 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe // 订单状态--当前 var status = gmodel.OrderStatus{ - Ctime: nowTime, - Utime: nowTime, + Ctime: &nowTime, + Utime: &nowTime, StatusCode: constants.ORDERSTATUSUNPAIDDEPOSIT, StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT], } // 订单状态--链路 var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime) var orderInfo = gmodel.OrderInfo{ - Ctime: nowTime, + Ctime: &nowTime, DeliveryMethod: in.DeliveryMethod, OrderSn: orderSn, Status: status, @@ -345,14 +380,19 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe PayStatus: payStatus, } // 数据库操作 - var order = gmodel.NewFsOrder{ + + 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: &orderDetail, + Metadata: &orderDetailByte, } result := tx.Create(&order) if result.Error != nil { @@ -361,6 +401,12 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe return nil }) if err != nil { + logx.Errorf("create order failed, err: %v", err) + + if errorCode.Code == 0 { + errorCode.Code = basic.CodeApiErr.Code + errorCode.Message = basic.CodeApiErr.Message + } return &CreateRes{ OrderSn: orderSn, ErrorCode: errorCode, diff --git a/utils/basic/basic.go b/utils/basic/basic.go index dc6f383b..c99004fe 100644 --- a/utils/basic/basic.go +++ b/utils/basic/basic.go @@ -100,12 +100,12 @@ var ( CodeLogoCombineErr = &StatusResponse{5115, "logo combine fail"} // 合图失败 CodeLogoCombineNoFoundErr = &StatusResponse{5116, "template record not found"} // 模版不存在 - CodeErrOrder = &StatusResponse{5300, "ocreate order failed"} // 订单错误 - CodeErrOrderCreatShoppingCartEmpty = &StatusResponse{5301, "ocreate order failed, shopping cart is empty"} // 订单创建失败,购物车为空 - CodeErrOrderCreatShoppingCartNotMatched = &StatusResponse{5302, "ocreate order failed, shopping cart not matched"} // 订单创建失败,购物车不相符 - CodeErrOrderCreatProductAbsent = &StatusResponse{5303, "ocreate order failed, product is absent"} // 订单创建失败,商品不存在 - CodeErrOrderCreatProductPriceAbsent = &StatusResponse{5304, "ocreate order failed, price of product is absent"} // 订单创建失败,商品价格不存在 - CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "ocreate order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在 + CodeErrOrder = &StatusResponse{5300, "create order failed"} // 订单错误 + CodeErrOrderCreatShoppingCartEmpty = &StatusResponse{5301, "create order failed, shopping cart is empty"} // 订单创建失败,购物车为空 + CodeErrOrderCreatShoppingCartNotMatched = &StatusResponse{5302, "create order failed, shopping cart not matched"} // 订单创建失败,购物车不相符 + CodeErrOrderCreatProductAbsent = &StatusResponse{5303, "create order failed, product is absent"} // 订单创建失败,商品不存在 + CodeErrOrderCreatProductPriceAbsent = &StatusResponse{5304, "create order failed, price of product is absent"} // 订单创建失败,商品价格不存在 + CodeErrOrderCreatProductAccessoryAbsent = &StatusResponse{5305, "create order failed, accessory of product is absent"} // 订单创建失败,商品配件不存在 ) type Response struct { diff --git a/utils/order/order.go b/utils/order/order.go index 17f708cf..d6602860 100644 --- a/utils/order/order.go +++ b/utils/order/order.go @@ -4,8 +4,6 @@ import ( "fmt" "fusenapi/constants" "fusenapi/model/gmodel" - "math/rand" - "strconv" "time" ) @@ -81,24 +79,33 @@ func GetAmountInfo(req GetAmountInfoReq) gmodel.AmountInfo { } } -func GenerateOrderNumber(deliveryMethod int, userID int) string { - // 获取当前时间 - now := time.Now() +type GetAmountCurrencyUSDReq struct { + ExchangeRate int64 `json:"exchange_rate"` // 换算汇率 + CurrentAmount int64 `json:"current_amount"` // 当前金额 + OriginalAmount int64 `json:"original_amount"` // 原始金额 + CurrentCurrency string `json:"current_currency"` // 当前货币 + OriginalCurrency string `json:"original_currency"` // 原始货币 +} - // 生成年月日时分秒的字符串 - year := strconv.Itoa(now.Year()) - month := strconv.Itoa(int(now.Month())) - day := strconv.Itoa(now.Day()) - hour := strconv.Itoa(now.Hour()) - minute := strconv.Itoa(now.Minute()) - second := strconv.Itoa(now.Second()) +type GetAmountCurrencyUSDRes struct { + ExchangeRate string `json:"exchange_rate"` // 换算汇率 + CurrentAmount string `json:"current_amount"` // 当前金额 + OriginalAmount string `json:"original_amount"` // 原始金额 + CurrentCurrency string `json:"current_currency"` // 当前货币 + OriginalCurrency string `json:"original_currency"` // 原始货币 +} - // 生成2位随机数 - rand.Seed(time.Now().UnixNano()) - randomNum := fmt.Sprintf("%02d", rand.Intn(100)) +// 处理金额(美元) +func GetAmountCurrencyUSD(req *GetAmountCurrencyUSDReq) (res GetAmountCurrencyUSDRes) { + return GetAmountCurrencyUSDRes{ + ExchangeRate: fmt.Sprintf("%.2f", float64(req.ExchangeRate)/1000), + } +} - // 拼接订单号 - orderNumber := year + month + day + hour + minute + second + randomNum + strconv.Itoa(userID) + strconv.Itoa(deliveryMethod) +func GenerateOrderNumber() string { + t := time.Now() + orderNumber := fmt.Sprintf("%d%02d%02d%08d", t.Year(), t.Month(), t.Day(), t.UnixNano()%100000000) + fmt.Println(orderNumber) return orderNumber } @@ -118,9 +125,9 @@ func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time, expectedTim StatusTitle: constants.OrderStatusMessage[v], }) } - list[0].Ctime = noTime - list[0].Utime = noTime - list[len(list)-1].ExpectedTime = expectedTime + list[0].Ctime = &noTime + list[0].Utime = &noTime + list[len(list)-1].ExpectedTime = &expectedTime return list }