fix:购物车下单
This commit is contained in:
parent
12085dca8f
commit
f4f5a62270
|
@ -1,10 +1,16 @@
|
|||
package constants
|
||||
|
||||
// 订单类型
|
||||
const (
|
||||
DELIVERYMETHODDIRECTMAIL int64 = 1
|
||||
DELIVERYMETHODDSCLOUDSTORE int64 = 1
|
||||
)
|
||||
|
||||
// 货币
|
||||
type Currency string
|
||||
|
||||
const (
|
||||
Usd Currency = "usd"
|
||||
CURRENCYUSD Currency = "usd"
|
||||
)
|
||||
|
||||
// 金额单位
|
||||
|
@ -17,17 +23,17 @@ type ExchangeRateUnit interface{}
|
|||
type PayMethods string
|
||||
|
||||
const (
|
||||
Card PayMethods = "CARD"
|
||||
Visa PayMethods = "VISA"
|
||||
PAYMETHODCARD PayMethods = "CARD"
|
||||
PayMethodVISA PayMethods = "VISA"
|
||||
)
|
||||
|
||||
// 支付状态
|
||||
type PayStatusCode int64
|
||||
|
||||
const (
|
||||
PayStatusUnpaid PayStatusCode = 10 //10,未支付
|
||||
PayStatusPaid PayStatusCode = 20 //20,已支付
|
||||
PayStatusRefunded PayStatusCode = 30 //30,已退款
|
||||
PAYSTATUSUNPAID PayStatusCode = 10 //10,未支付
|
||||
PAYSTATUSPAID PayStatusCode = 20 //20,已支付
|
||||
PAYSTATUSREFUNDED PayStatusCode = 30 //30,已退款
|
||||
)
|
||||
|
||||
// 订单支付状态
|
||||
|
@ -39,11 +45,11 @@ type OrderPayStatusCode int64
|
|||
// 30,已付尾款
|
||||
// 40,已退尾款
|
||||
const (
|
||||
OrderPayStatusUnpaidDEPOSIT OrderPayStatusCode = 0
|
||||
OrderPayStatusPaidDEPOSIT OrderPayStatusCode = 10
|
||||
OrderPayStatusRefundedDEPOSIT OrderPayStatusCode = 20
|
||||
OrderPayStatusPaidDREMAINING OrderPayStatusCode = 30
|
||||
OrderPayStatusRefundedREMAINING OrderPayStatusCode = 40
|
||||
ORDERPAYSTATUSUNPAIDDEPOSIT OrderPayStatusCode = 0
|
||||
ORDERPAYSTATUSPAIDDEPOSIT OrderPayStatusCode = 10
|
||||
ORDERPAYSTATUSREFUNDEDDEPOSIT OrderPayStatusCode = 20
|
||||
ORDERPAYSTATUSPAIDDREMAINING OrderPayStatusCode = 30
|
||||
ORDERPAYSTATUSREFUNDEDREMAINING OrderPayStatusCode = 40
|
||||
)
|
||||
|
||||
// 订单状态
|
||||
|
@ -76,9 +82,9 @@ var OrderStatusUser []OrderStatusCode
|
|||
func init() {
|
||||
// 订单状态名称
|
||||
PayStatusMessage = make(map[PayStatusCode]string)
|
||||
PayStatusMessage[PayStatusUnpaid] = "Paid"
|
||||
PayStatusMessage[PayStatusPaid] = "Unpaid"
|
||||
PayStatusMessage[PayStatusRefunded] = "Refunded"
|
||||
PayStatusMessage[PAYSTATUSUNPAID] = "Paid"
|
||||
PayStatusMessage[PAYSTATUSPAID] = "Unpaid"
|
||||
PayStatusMessage[PAYSTATUSREFUNDED] = "Refunded"
|
||||
|
||||
// 订单状态名称
|
||||
OrderStatusMessage = make(map[OrderStatusCode]string)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
// fs_cloud_storage 仓库的基本信息, 只做映射
|
||||
type FsCloudStorage struct {
|
||||
CloudStorageId *string `gorm:"unique_key;default:'';" json:"cloud_storage_id"` // 仓库id, 需要固定的命名规则, 能表达国外国内,区域等,简单明了
|
||||
CloudStorageId *string `gorm:"unique_key;default:'';" json:"cloud_storage_id"` //
|
||||
Name *string `gorm:"default:'';" json:"name"` // 仓库的名字, 中文使用拼音,国外使用英文
|
||||
Address *string `gorm:"default:'';" json:"address"` // 仓库地址
|
||||
Contact *[]byte `gorm:"default:'';" json:"contact"` //
|
||||
|
|
20
model/gmodel/fs_cloud_storage_stock_gen.go
Normal file
20
model/gmodel/fs_cloud_storage_stock_gen.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// fs_cloud_storage_stock
|
||||
type FsCloudStorageStock struct {
|
||||
StockId int64 `gorm:"primary_key;default:0;auto_increment;" json:"stock_id"` // 库存ID
|
||||
OrderSn *string `gorm:"default:'';" json:"order_sn"` //
|
||||
CloudStorageId *string `gorm:"default:'';" json:"cloud_storage_id"` //
|
||||
}
|
||||
type FsCloudStorageStockModel struct {
|
||||
db *gorm.DB
|
||||
name string
|
||||
}
|
||||
|
||||
func NewFsCloudStorageStockModel(db *gorm.DB) *FsCloudStorageStockModel {
|
||||
return &FsCloudStorageStockModel{db: db, name: "fs_cloud_storage_stock"}
|
||||
}
|
2
model/gmodel/fs_cloud_storage_stock_logic.go
Normal file
2
model/gmodel/fs_cloud_storage_stock_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
|||
package gmodel
|
||||
// TODO: 使用model的属性做你想做的
|
|
@ -1,9 +1,8 @@
|
|||
package gmodel
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// fs_order 订单表
|
||||
|
@ -11,13 +10,14 @@ type FsOrder 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"` //
|
||||
OrderSn *string `gorm:"unique_key;default:'';" json:"order_sn"` //
|
||||
OrderSource *string `gorm:"default:'';" json:"order_source"` //
|
||||
Status *int64 `gorm:"index;default:0;" json:"status"` // 订单状态
|
||||
Metadata *[]byte `gorm:"default:'';" 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=是
|
||||
PayStatus *int64 `gorm:"default:0;" json:"pay_status"` // 支付状态
|
||||
}
|
||||
type FsOrderModel struct {
|
||||
db *gorm.DB
|
||||
|
|
|
@ -14,6 +14,7 @@ type NewFsOrder struct {
|
|||
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"` //
|
||||
|
|
|
@ -9,15 +9,15 @@ import (
|
|||
type FsOrderTrade struct {
|
||||
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 订单交易ID
|
||||
UserId *int64 `gorm:"index;default:0;" json:"user_id"` // 用户ID
|
||||
OrderNo *string `gorm:"default:'';" json:"order_no"` //
|
||||
OrderSn *string `gorm:"default:'';" json:"order_sn"` //
|
||||
OrderSource *string `gorm:"default:'';" json:"order_source"` //
|
||||
TradeNo *string `gorm:"index;default:'';" json:"trade_no"` //
|
||||
TradeSn *string `gorm:"index;default:'';" json:"trade_sn"` //
|
||||
PayAmount *int64 `gorm:"default:0;" json:"pay_amount"` // 支付金额 (分)
|
||||
PayStatus *int64 `gorm:"default:0;" json:"pay_status"` // 支付状态:1=未成功,2=已成功
|
||||
PaymentMethod *int64 `gorm:"default:0;" json:"payment_method"` // 支付方式:1=stripe,2=paypal
|
||||
PayStage *int64 `gorm:"default:0;" json:"pay_stage"` // 支付阶段:1=首付,2=尾款
|
||||
RefundStatus *int64 `gorm:"default:0;" json:"refund_status"` // 退款状态:1=未退款,2=已退款
|
||||
CardNo *string `gorm:"default:'';" json:"card_no"` //
|
||||
CardSn *string `gorm:"default:'';" json:"card_sn"` //
|
||||
CardBrand *string `gorm:"default:'';" json:"card_brand"` //
|
||||
Country *string `gorm:"default:'';" json:"country"` //
|
||||
Currency *string `gorm:"default:'';" json:"currency"` //
|
||||
|
|
|
@ -31,6 +31,7 @@ type AllModelsGen struct {
|
|||
FsCloudReceiveOld *FsCloudReceiveOldModel // fs_cloud_receive_old 云仓接收工厂总单
|
||||
FsCloudRenderLogOld *FsCloudRenderLogOldModel // fs_cloud_render_log_old 云渲染日志表
|
||||
FsCloudStorage *FsCloudStorageModel // fs_cloud_storage 仓库的基本信息, 只做映射
|
||||
FsCloudStorageStock *FsCloudStorageStockModel // fs_cloud_storage_stock
|
||||
FsCloudUserApplyBackOld *FsCloudUserApplyBackOldModel // fs_cloud_user_apply_back_old 该表废弃
|
||||
FsContact *FsContactModel // fs_contact 该表暂未使用
|
||||
FsContactService *FsContactServiceModel // fs_contact_service
|
||||
|
@ -141,6 +142,7 @@ func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
|||
FsCloudReceiveOld: NewFsCloudReceiveOldModel(gdb),
|
||||
FsCloudRenderLogOld: NewFsCloudRenderLogOldModel(gdb),
|
||||
FsCloudStorage: NewFsCloudStorageModel(gdb),
|
||||
FsCloudStorageStock: NewFsCloudStorageStockModel(gdb),
|
||||
FsCloudUserApplyBackOld: NewFsCloudUserApplyBackOldModel(gdb),
|
||||
FsContact: NewFsContactModel(gdb),
|
||||
FsContactService: NewFsContactServiceModel(gdb),
|
||||
|
|
|
@ -5,12 +5,14 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/order"
|
||||
"fusenapi/utils/shopping_cart"
|
||||
"fusenapi/utils/step_price"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"gorm.io/gorm"
|
||||
|
@ -33,6 +35,12 @@ type (
|
|||
// 详情
|
||||
}
|
||||
|
||||
OrderAddress struct {
|
||||
Address string `json:"address"` // 详细地址
|
||||
Mobile string `json:"mobile"` // 手机
|
||||
Name string `json:"name"` // 姓名
|
||||
}
|
||||
|
||||
/* 下单 */
|
||||
CreateReq struct {
|
||||
ExpectedDeliveryTime string `json:"expected_delivery_time"` // 预计到货时间
|
||||
|
@ -41,7 +49,8 @@ type (
|
|||
OriginalCurrency string `json:"original_currency"` // 原始货币
|
||||
UserId int64 `json:"user_id"`
|
||||
CartIds []int64 `json:"cart_ids"`
|
||||
DeliveryMethod string `json:"delivery_method"`
|
||||
DeliveryMethod int64 `json:"delivery_method"`
|
||||
DeliveryAddress *OrderAddress `json:"delivery_address"` // 收货地址
|
||||
}
|
||||
CreateRes struct {
|
||||
ErrorCode basic.StatusResponse
|
||||
|
@ -99,7 +108,21 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
// 订单总价(厘)
|
||||
var orderTotal int64
|
||||
|
||||
var payStatus int64
|
||||
var nowTime = time.Now().UTC()
|
||||
|
||||
// 收货地址
|
||||
var orderAddress *gmodel.OrderAddress
|
||||
|
||||
// 支付状态
|
||||
var payStatus = constants.ORDERPAYSTATUSUNPAIDDEPOSIT
|
||||
|
||||
// 直邮
|
||||
if in.DeliveryMethod == constants.DELIVERYMETHODDIRECTMAIL {
|
||||
orderAddress = &gmodel.OrderAddress{
|
||||
Mobile: in.DeliveryAddress.Mobile,
|
||||
Name: in.DeliveryAddress.Name,
|
||||
}
|
||||
}
|
||||
|
||||
for _, shoppingCart := range shoppingCartList {
|
||||
// 购物车快照
|
||||
|
@ -248,8 +271,24 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
CurrentCurrency: in.CurrentCurrency,
|
||||
OriginalCurrency: in.OriginalCurrency,
|
||||
})
|
||||
fmt.Println(orderProductList, shippingFee, shippingFeeTotal, tax, taxTotal, discount, discountTotal, subtotal, orderProductTotal, total)
|
||||
// 定金
|
||||
var depositInt int64 //厘
|
||||
var deposit = gmodel.PayInfo{
|
||||
Status: gmodel.PayStatus{
|
||||
StatusCode: int64(constants.PAYSTATUSUNPAID),
|
||||
StatusTitle: constants.PayStatusMessage[constants.PAYSTATUSUNPAID],
|
||||
},
|
||||
PayAmount: gmodel.AmountInfo{},
|
||||
}
|
||||
|
||||
// 尾款
|
||||
var remainingBalanceInt int64 //厘
|
||||
var remainingBalance = gmodel.PayInfo{}
|
||||
fmt.Println(orderProductList, shippingFee, shippingFeeTotal, tax, taxTotal, discount, discountTotal, subtotal, orderProductTotal, total)
|
||||
var orderAmount = gmodel.OrderAmount{
|
||||
Deposit: deposit,
|
||||
RemainingBalance: remainingBalance,
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package order
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AmountCurrencyReq struct {
|
||||
|
@ -75,3 +80,48 @@ func GetAmountInfo(req GetAmountInfoReq) gmodel.AmountInfo {
|
|||
Metadata: req.Metadata,
|
||||
}
|
||||
}
|
||||
|
||||
func GenerateOrderNumber(userID int) string {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
|
||||
// 生成年月日时分秒的字符串
|
||||
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())
|
||||
|
||||
// 生成2位随机数
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
randomNum := fmt.Sprintf("%02d", rand.Intn(100))
|
||||
|
||||
// 拼接订单号
|
||||
orderNumber := year + month + day + hour + minute + second + randomNum + strconv.Itoa(userID)
|
||||
return orderNumber
|
||||
}
|
||||
|
||||
// 初始化订单状态
|
||||
func GenerateOrderStatusLink(req []gmodel.OrderStatus) []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],
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// 获取订单当前状态
|
||||
func GenerateOrderStatusCurrent() gmodel.OrderStatus {
|
||||
return gmodel.OrderStatus{}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user