fix:购物车下单
This commit is contained in:
parent
78558bb74d
commit
b45da2b637
|
@ -76,8 +76,11 @@ var OrderStatusMessage map[OrderStatusCode]string
|
|||
// 支付状态名称
|
||||
var PayStatusMessage map[PayStatusCode]string
|
||||
|
||||
// 订单状态--用户可见
|
||||
var OrderStatusUser []OrderStatusCode
|
||||
// 订单状态--用户可见--直邮
|
||||
var OrderStatusUserDIRECTMAIL []OrderStatusCode
|
||||
|
||||
// 订单状态--用户可见--云仓
|
||||
var OrderStatusUserCLOUDSTORE []OrderStatusCode
|
||||
|
||||
func init() {
|
||||
// 订单状态名称
|
||||
|
@ -101,10 +104,14 @@ func init() {
|
|||
OrderStatusMessage[ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION] = "云仓单--生产完成"
|
||||
OrderStatusMessage[ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE] = "云仓单--直达仓库"
|
||||
|
||||
// 订单状态--用户可见
|
||||
OrderStatusUser = []OrderStatusCode{
|
||||
// 订单状态--用户可见--直邮
|
||||
OrderStatusUserDIRECTMAIL = []OrderStatusCode{
|
||||
ORDERSTATUSUNPAIDDEPOSIT,
|
||||
ORDERSTATUSDIRECTMAILORDERED, ORDERSTATUSDIRECTMAILSTARTPRODUCTION, ORDERSTATUSDIRECTMAILCOMPLETEPRODUCTION, ORDERSTATUSDIRECTMAILSHIPPED, ORDERSTATUSDIRECTMAILARRIVED,
|
||||
}
|
||||
// 订单状态--用户可见--云仓
|
||||
OrderStatusUserCLOUDSTORE = []OrderStatusCode{
|
||||
ORDERSTATUSUNPAIDDEPOSIT,
|
||||
ORDERSTATUSCLOUDSTOREORDERED, ORDERSTATUSCLOUDSTORESTARTPRODUCTION, ORDERSTATUSCLOUDSTOREOMPLETEPRODUCTION, ORDERSTATUSCLOUDSTOREARRIVEDWAREHOUSE,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ type PayInfo struct {
|
|||
Metadata map[string]interface{} `json:"metadata"` // 额外参数
|
||||
PayAmount AmountInfo `json:"pay_amount"` // 金额明细
|
||||
PayMethod string `json:"pay_method"` // 交易方式
|
||||
PayTime string `json:"pay_time"` // 支付时间
|
||||
PayTime time.Time `json:"pay_time"` // 支付时间
|
||||
Status PayStatus `json:"status"` // 当前状态
|
||||
StatusLink []PayStatus `json:"status_link"` // 状态链路
|
||||
TradeNo string `json:"trade_no"` // 支付交易号
|
||||
|
@ -86,24 +86,24 @@ type PayStatus struct {
|
|||
|
||||
// 订单信息
|
||||
type OrderInfo struct {
|
||||
Ctime string `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 string `json:"utime"` // 更新时间
|
||||
Utime time.Time `json:"utime"` // 更新时间
|
||||
}
|
||||
|
||||
// 订单状态--用户
|
||||
type OrderStatus struct {
|
||||
Children []*OrderStatus `json:"children"` // 子状态,管理人员的处理状态, 用户不可见
|
||||
Ctime string `json:"ctime"` // 创建时间
|
||||
ExpectedTime string `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 string `json:"utime"` // 更新时间
|
||||
Utime time.Time `json:"utime"` // 更新时间
|
||||
}
|
||||
|
||||
// 订单商品
|
||||
|
|
|
@ -6,9 +6,10 @@ import (
|
|||
|
||||
type RelaFsShoppingCart struct {
|
||||
FsShoppingCart
|
||||
ShoppingCartProduct *RelaFsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references:id"`
|
||||
ShoppingCartProductPriceList []*FsProductPrice `json:"shopping_cart_product_price_list" gorm:"foreignkey:product_id;references:product_id"`
|
||||
ShoppingCartProductModel3dList []*FsProductModel3d `json:"shopping_cart_product_model3d_list" gorm:"foreignkey:product_id;references:product_id"`
|
||||
ShoppingCartProduct *RelaFsProduct `json:"shopping_cart_product" gorm:"foreignkey:product_id;references:id"`
|
||||
ShoppingCartProductPriceList []*FsProductPrice `json:"shopping_cart_product_price_list" gorm:"foreignkey:product_id;references:product_id"`
|
||||
ShoppingCartProductModel3dList []*FsProductModel3d `json:"shopping_cart_product_model3d_list" gorm:"foreignkey:product_id;references:product_id"`
|
||||
ShoppingCartProductModel3dFitting *FsProductModel3d `json:"shopping_cart_product_model3d_list_fitting" gorm:"foreignkey:fitting_id;references:id"`
|
||||
}
|
||||
|
||||
// 获取单个
|
||||
|
|
|
@ -15,7 +15,7 @@ service order {
|
|||
post /api/order/create(CreateOrderReq) returns (response);
|
||||
|
||||
@handler CreatePrePaymentHandler
|
||||
post /api/order/create-prepayment(CreatePrePaymentReq) returns (response);
|
||||
post /api/order/create-prepayment-balance(CreatePrePaymentReq) returns (response);
|
||||
|
||||
@handler OrderListHandler
|
||||
post /api/order/list(OrderListReq) returns (response);
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/basic"
|
||||
|
@ -62,12 +61,15 @@ type (
|
|||
// 下单
|
||||
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))
|
||||
|
||||
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").Preload("ShoppingCartProductModel3dList").
|
||||
}).Preload("ShoppingCartProductPriceList").Preload("ShoppingCartProductModel3dList").Preload("ShoppingCartProductModel3dFitting").
|
||||
Where("id IN ?", in.CartIds).
|
||||
Where("user_id = ?", in.UserId).
|
||||
Find(&shoppingCartList)
|
||||
|
@ -86,7 +88,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
}
|
||||
|
||||
// 订单商品列表
|
||||
var orderProductList []*gmodel.OrderProduct
|
||||
var orderProductList []gmodel.OrderProduct
|
||||
|
||||
var shippingFee gmodel.AmountInfo
|
||||
// 订单税费总价(厘)
|
||||
|
@ -229,7 +231,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
var productSnapshot = make(map[string]interface{}, 1)
|
||||
productSnapshot["product_snapshot"] = shoppingCart.ShoppingCartProduct
|
||||
|
||||
orderProductList = append(orderProductList, &gmodel.OrderProduct{
|
||||
orderProductList = append(orderProductList, gmodel.OrderProduct{
|
||||
Amount: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ExchangeRate: in.ExchangeRate,
|
||||
Initiate: productTotalPrice,
|
||||
|
@ -272,29 +274,94 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
OriginalCurrency: in.OriginalCurrency,
|
||||
})
|
||||
// 定金
|
||||
var depositInt int64 //厘
|
||||
var depositInt int64 = orderTotal / 2
|
||||
var deposit = gmodel.PayInfo{
|
||||
Status: gmodel.PayStatus{
|
||||
StatusCode: int64(constants.PAYSTATUSUNPAID),
|
||||
StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID],
|
||||
},
|
||||
PayAmount: gmodel.AmountInfo{},
|
||||
PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ExchangeRate: in.ExchangeRate,
|
||||
Initiate: depositInt,
|
||||
Current: depositInt,
|
||||
CurrentCurrency: in.CurrentCurrency,
|
||||
OriginalCurrency: in.OriginalCurrency,
|
||||
}),
|
||||
}
|
||||
|
||||
// 尾款
|
||||
var remainingBalanceInt int64 //厘
|
||||
var remainingBalance = gmodel.PayInfo{}
|
||||
fmt.Println(orderProductList, shippingFee, shippingFeeTotal, tax, taxTotal, discount, discountTotal, subtotal, orderProductTotal, total)
|
||||
var remainingBalanceInt int64 = orderTotal - depositInt
|
||||
var remainingBalance = gmodel.PayInfo{
|
||||
Status: gmodel.PayStatus{
|
||||
StatusCode: int64(constants.PAYSTATUSUNPAID),
|
||||
StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID],
|
||||
},
|
||||
PayAmount: order.GetAmountInfo(order.GetAmountInfoReq{
|
||||
ExchangeRate: in.ExchangeRate,
|
||||
Initiate: remainingBalanceInt,
|
||||
Current: remainingBalanceInt,
|
||||
CurrentCurrency: in.CurrentCurrency,
|
||||
OriginalCurrency: in.OriginalCurrency,
|
||||
}),
|
||||
}
|
||||
var orderAmount = gmodel.OrderAmount{
|
||||
Deposit: deposit,
|
||||
RemainingBalance: remainingBalance,
|
||||
Discount: discount,
|
||||
ShippingFee: shippingFee,
|
||||
Tax: tax,
|
||||
Subtotal: subtotal,
|
||||
Total: total,
|
||||
}
|
||||
|
||||
// 订单状态--当前
|
||||
var status = gmodel.OrderStatus{
|
||||
Ctime: nowTime,
|
||||
Utime: nowTime,
|
||||
StatusCode: constants.ORDERSTATUSUNPAIDDEPOSIT,
|
||||
StatusTitle: constants.OrderStatusMessage[constants.ORDERSTATUSUNPAIDDEPOSIT],
|
||||
}
|
||||
// 订单状态--链路
|
||||
var statusLink = order.GenerateOrderStatusLink(in.DeliveryMethod, nowTime)
|
||||
var orderInfo = gmodel.OrderInfo{
|
||||
Ctime: nowTime,
|
||||
DeliveryMethod: in.DeliveryMethod,
|
||||
OrderSn: orderSn,
|
||||
Status: status,
|
||||
StatusLink: statusLink,
|
||||
}
|
||||
|
||||
var orderDetail = gmodel.OrderDetail{
|
||||
DeliveryAddress: orderAddress,
|
||||
OrderAmount: orderAmount,
|
||||
OrderInfo: orderInfo,
|
||||
OrderProduct: orderProductList,
|
||||
PayStatus: payStatus,
|
||||
}
|
||||
// 数据库操作
|
||||
var order = gmodel.NewFsOrder{
|
||||
UserId: &in.UserId,
|
||||
DeliveryMethod: &in.DeliveryMethod,
|
||||
OrderSn: &orderSn,
|
||||
Status: (*int64)(&status.StatusCode),
|
||||
PayStatus: (*int64)(&payStatus),
|
||||
Ctime: &nowTime,
|
||||
Metadata: &orderDetail,
|
||||
}
|
||||
result := tx.Create(&order)
|
||||
if result.Error != nil {
|
||||
return result.Error
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return &CreateRes{
|
||||
OrderSn: orderSn,
|
||||
ErrorCode: errorCode,
|
||||
}, err
|
||||
}
|
||||
return &CreateRes{
|
||||
OrderSn: orderSn,
|
||||
ErrorCode: errorCode,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ func GetAmountInfo(req GetAmountInfoReq) gmodel.AmountInfo {
|
|||
}
|
||||
}
|
||||
|
||||
func GenerateOrderNumber(userID int) string {
|
||||
func GenerateOrderNumber(deliveryMethod int, userID int) string {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
|
||||
|
@ -98,26 +98,30 @@ func GenerateOrderNumber(userID int) string {
|
|||
randomNum := fmt.Sprintf("%02d", rand.Intn(100))
|
||||
|
||||
// 拼接订单号
|
||||
orderNumber := year + month + day + hour + minute + second + randomNum + strconv.Itoa(userID)
|
||||
orderNumber := year + month + day + hour + minute + second + randomNum + strconv.Itoa(userID) + strconv.Itoa(deliveryMethod)
|
||||
return orderNumber
|
||||
}
|
||||
|
||||
// 初始化订单状态
|
||||
func GenerateOrderStatusLink(req []gmodel.OrderStatus) []gmodel.OrderStatus {
|
||||
func GenerateOrderStatusLink(deliveryMethod int64, noTime time.Time) []gmodel.OrderStatus {
|
||||
var list []gmodel.OrderStatus
|
||||
|
||||
for _, v := range constants.OrderStatusUser {
|
||||
for _, v1 := range req {
|
||||
if v1.StatusCode == v {
|
||||
list = append(list, v1)
|
||||
} else {
|
||||
list = append(list, gmodel.OrderStatus{
|
||||
StatusCode: v,
|
||||
StatusTitle: constants.OrderStatusMessage[v],
|
||||
})
|
||||
}
|
||||
}
|
||||
var orderStatus []constants.OrderStatusCode
|
||||
if deliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
|
||||
orderStatus = constants.OrderStatusUserDIRECTMAIL
|
||||
} else {
|
||||
orderStatus = constants.OrderStatusUserCLOUDSTORE
|
||||
}
|
||||
for _, v := range orderStatus {
|
||||
list = append(list, gmodel.OrderStatus{
|
||||
StatusCode: v,
|
||||
StatusTitle: constants.OrderStatusMessage[v],
|
||||
})
|
||||
}
|
||||
list[0].Ctime = noTime
|
||||
list[0].Utime = noTime
|
||||
tPlus60Days := noTime.AddDate(0, 0, 60)
|
||||
list[len(list)-1].ExpectedTime = tPlus60Days
|
||||
return list
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user