This commit is contained in:
laodaming
2023-09-20 15:28:57 +08:00
19 changed files with 583 additions and 63 deletions

View File

@@ -10,7 +10,6 @@ import (
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/order"
"fusenapi/utils/shopping_cart"
"fusenapi/utils/step_price"
"math"
"strings"
@@ -32,6 +31,7 @@ type (
}
Order interface {
// 下单
Create(ctx context.Context, in *CreateReq) (res *CreateRes, err error)
// 预支付
// 列表
// 详情
@@ -45,7 +45,7 @@ type (
/* 下单 */
CreateReq struct {
ExpectedDeliveryTime string `json:"expected_delivery_time"` // 预计到货时间
ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间
ExchangeRate int64 `json:"exchange_rate"` // 换算汇率(厘)
CurrentCurrency string `json:"current_currency"` // 当前货币
OriginalCurrency string `json:"original_currency"` // 原始货币
@@ -72,7 +72,9 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
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").Preload("ShoppingCartProductModel3dList").Preload("ShoppingCartProductModel3dFitting").
}).Preload("ShoppingCartProductPriceList").
Preload("ShoppingCartProductModel3dList").
Preload("ShoppingCartProductModel3dFitting").
Where("id IN ?", in.CartIds).
Where("user_id = ?", in.UserId).
Find(&shoppingCartList)
@@ -131,7 +133,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
for _, shoppingCart := range shoppingCartList {
// 购物车快照
var shoppingCartSnapshot shopping_cart.CartSnapshot
var shoppingCartSnapshot gmodel.CartSnapshot
// 购物车商品价格
var shoppingCartProductPrice *gmodel.FsProductPrice
// 购物车商品模型
@@ -250,24 +252,14 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
orderProductTotal = orderProductTotal + productTotalPrice
// 订单商品
var productLogoResource *gmodel.Resource
if shoppingCart.ShoppingCartProduct.CoverResource != nil {
var coverResourceMetadata map[string]interface{}
if shoppingCart.ShoppingCartProduct.CoverResource.Metadata != nil {
json.Unmarshal(*shoppingCart.ShoppingCartProduct.CoverResource.Metadata, &coverResourceMetadata)
}
productLogoResource = &gmodel.Resource{
Metadata: coverResourceMetadata,
ResourceID: shoppingCart.ShoppingCartProduct.CoverResource.ResourceId,
ResourceType: *shoppingCart.ShoppingCartProduct.CoverResource.ResourceType,
ResourceURL: *shoppingCart.ShoppingCartProduct.CoverResource.ResourceUrl,
}
}
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)
}
orderProductList = append(orderProductList, gmodel.OrderProduct{
Amount: order.GetAmountInfo(order.GetAmountInfoReq{
TotalPrice: order.GetAmountInfo(order.GetAmountInfoReq{
ExchangeRate: in.ExchangeRate,
Initiate: productTotalPrice,
Current: productTotalPrice,
@@ -275,12 +267,12 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
OriginalCurrency: in.OriginalCurrency,
}),
ExpectedDeliveryTime: in.ExpectedDeliveryTime,
Number: *shoppingCart.PurchaseQuantity,
PurchaseQuantity: *shoppingCart.PurchaseQuantity,
ProductID: *shoppingCart.ProductId,
ProductLogo: *shoppingCart.ShoppingCartProduct.Cover,
ProductLogoResource: productLogoResource,
ProductCover: *shoppingCart.ShoppingCartProduct.Cover,
ProductCoverMetadata: productCoverMetadata,
ProductName: *shoppingCart.ShoppingCartProduct.Title,
ProductPrice: order.GetAmountInfo(order.GetAmountInfoReq{
ItemPrice: order.GetAmountInfo(order.GetAmountInfoReq{
ExchangeRate: in.ExchangeRate,
Initiate: productPrice,
Current: productPrice,
@@ -289,6 +281,23 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
}),
ProductSnapshot: productSnapshot,
ShoppingCartSnapshot: &shoppingCart.FsShoppingCart,
ProductSn: *shoppingCart.ShoppingCartProduct.Sn,
DiyInformation: &gmodel.DiyInformation{
Address: shoppingCartSnapshot.UserDiyInformation.Address,
Phone: shoppingCartSnapshot.UserDiyInformation.Phone,
Qrcode: shoppingCartSnapshot.UserDiyInformation.Qrcode,
Slogan: shoppingCartSnapshot.UserDiyInformation.Slogan,
Website: shoppingCartSnapshot.UserDiyInformation.Website,
},
FittingInfo: &gmodel.FittingInfo{
FittingID: *shoppingCart.FittingId,
FittingName: shoppingCartSnapshot.FittingInfo.FittingName,
},
SizeInfo: &gmodel.SizeInfo{
SizeID: *shoppingCart.SizeId,
Capacity: shoppingCartSnapshot.SizeInfo.Capacity,
},
StepNum: stepNum,
})
}
@@ -357,7 +366,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT],
}
// 订单状态--链路
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime)
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime, in.ExpectedDeliveryTime)
var orderInfo = gmodel.OrderInfo{
Ctime: nowTime,
DeliveryMethod: in.DeliveryMethod,