194 lines
8.3 KiB
Go
194 lines
8.3 KiB
Go
package model
|
||
|
||
import "time"
|
||
|
||
type ModelTimeInfo struct {
|
||
CreatedAt time.Time `orm:"auto_now_add;type(datetime)"`
|
||
UpdatedAt time.Time `orm:"auto_now;type(datetime)"`
|
||
}
|
||
|
||
type GoodsOrder struct {
|
||
ID int64 `orm:"column(id)"`
|
||
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
||
VendorID int `orm:"column(vendor_id)"`
|
||
VendorStoreID string `orm:"column(vendor_store_id);size(48)"`
|
||
StoreID int `orm:"column(store_id)"` // 外部系统里记录的 jxstoreid
|
||
JxStoreID int `orm:"column(jx_store_id)"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
||
StoreName string `orm:"size(64)"`
|
||
ShopPrice int64 // 单位为分 门店标价
|
||
SalePrice int64 // 单位为分 售卖价
|
||
ActualPayPrice int64 // 单位为分 顾客实际支付
|
||
Weight int // 单位为克
|
||
ConsigneeName string `orm:"size(32)"`
|
||
ConsigneeMobile string `orm:"size(32)"`
|
||
ConsigneeAddress string `orm:"size(255)"`
|
||
CoordinateType int
|
||
ConsigneeLng int // 坐标 * (10的六次方)
|
||
ConsigneeLat int // 坐标 * (10的六次方)
|
||
SkuCount int // 商品类别数量,即有多少种商品(注意在某些情况下,相同SKU的商品由于售价不同,也会当成不同商品在这个值里)
|
||
GoodsCount int // 商品个数
|
||
Status int // 参见OrderStatus*相关的常量定义
|
||
VendorStatus string `orm:"size(255)"`
|
||
LockStatus int
|
||
OrderSeq int // 门店订单序号
|
||
BuyerComment string `orm:"size(255)"`
|
||
BusinessType int
|
||
ExpectedDeliveredTime time.Time `orm:"type(datetime)"` // 预期送达时间
|
||
CancelApplyReason string `orm:"size(255)"` // ""表示没有申请,不为null表示用户正在取消申请
|
||
VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)"`
|
||
WaybillVendorID int `orm:"column(waybill_vendor_id)"` // 表示当前承运商,-1表示还没有安排
|
||
DuplicatedCount int // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的
|
||
OrderCreatedAt time.Time `orm:"type(datetime);index"` // 这里记录的是订单生效时间,即用户支付完成(货到付款即为下单时间)
|
||
OrderFinishedAt time.Time `orm:"type(datetime)"`
|
||
StatusTime time.Time `orm:"type(datetime)"` // last status time
|
||
ModelTimeInfo
|
||
OriginalData string `orm:"type(text)"`
|
||
Skus []*OrderSku `orm:"-"`
|
||
SkuPmFee int64 //门店商品促销总支出
|
||
OrderPmFee int64 //门店订单促销支出
|
||
SkuPmSubsidy int64 //平台商品促销总补贴
|
||
OrderPmSubsidy int64 //平台订单促销补贴
|
||
BoxFee int64 //餐盒费
|
||
PlatformFeeRate int16 //平台费
|
||
BillStoreFreightFee int64 //需要回调,门店所承担的运费
|
||
}
|
||
|
||
func (o *GoodsOrder) TableUnique() [][]string {
|
||
return [][]string{
|
||
[]string{"VendorOrderID", "VendorID"},
|
||
}
|
||
}
|
||
|
||
type OrderSku struct {
|
||
ID int64 `orm:"column(id)"`
|
||
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
||
VendorID int `orm:"column(vendor_id)"`
|
||
StoreSubID int `orm:"column(store_sub_id)"`
|
||
StoreSubName string `orm:"size(64)"`
|
||
Count int
|
||
VendorSkuID string `orm:"column(vendor_sku_id);size(48)"`
|
||
SkuID int `orm:"column(sku_id)"` // 外部系统里记录的 jxskuid
|
||
JxSkuID int `orm:"column(jx_sku_id)"` // 根据VendorSkuID在本地系统里查询出来的 jxskuid
|
||
SkuName string `orm:"size(255)"`
|
||
ShopPrice int64 // 门店标价
|
||
SalePrice int64 // 售卖价
|
||
Weight int // 单位为克
|
||
SkuType int // 当前如果为gift就为1,否则缺省为0
|
||
PromotionType int // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换
|
||
OrderCreatedAt time.Time `orm:"type(datetime);index"` // 分区考虑
|
||
SkuPmSubsidy int64 //平台商品活动补贴
|
||
SkuPmFee int64 //门店商品促销支出
|
||
}
|
||
|
||
// 同样商品在一个订单中可能重复出现(比如搞活动时,相同商品价格不一样,第一个有优惠)
|
||
// 所以这里不能用唯一索引
|
||
func (o *OrderSku) TableIndex() [][]string {
|
||
return [][]string{
|
||
[]string{"VendorOrderID", "SkuID"},
|
||
}
|
||
}
|
||
|
||
type Waybill struct {
|
||
ID int64 `orm:"column(id)"`
|
||
VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)"`
|
||
VendorWaybillID2 string `orm:"column(vendor_waybill_id2);size(48)"` // 某些平台有多个ID,比如美团配送,当前美团配送的 delivery_id存这里
|
||
WaybillVendorID int `orm:"column(waybill_vendor_id)"`
|
||
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
||
OrderVendorID int `orm:"column(order_vendor_id)"`
|
||
CourierName string `orm:"size(32)"`
|
||
CourierMobile string `orm:"size(32)"`
|
||
Status int // 参见WaybillStatus*相关的常量定义
|
||
VendorStatus string `orm:"size(255)"`
|
||
ActualFee int64 // 实际要支付给快递公司的实际费用
|
||
DesiredFee int64 // 根据合同计算出来的预期费用
|
||
DuplicatedCount int // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的
|
||
WaybillCreatedAt time.Time `orm:"type(datetime);index"`
|
||
WaybillFinishedAt time.Time `orm:"type(datetime)"`
|
||
StatusTime time.Time `orm:"type(datetime)"` // last status time
|
||
ModelTimeInfo
|
||
OriginalData string `orm:"type(text)"`
|
||
Remark string `orm:"-"` // 用于传递remark
|
||
}
|
||
|
||
func (w *Waybill) TableUnique() [][]string {
|
||
return [][]string{
|
||
[]string{"VendorWaybillID", "WaybillVendorID"},
|
||
}
|
||
}
|
||
|
||
func (w *Waybill) TableIndex() [][]string {
|
||
return [][]string{
|
||
[]string{"VendorOrderID"},
|
||
}
|
||
}
|
||
|
||
// 包含订单与运单的状态及事件vendor status
|
||
type OrderStatus struct {
|
||
ID int64 `orm:"column(id)"`
|
||
VendorOrderID string `orm:"column(vendor_order_id);size(48)"`
|
||
VendorID int `orm:"column(vendor_id)"`
|
||
OrderType int // 0:订单,1:运单
|
||
RefVendorOrderID string `orm:"column(ref_vendor_order_id);size(48)"`
|
||
RefVendorID int `orm:"column(ref_vendor_id)"`
|
||
Status int // 如果Status为OrderStatusEvent,表示VendorStatus只是一个通知事件,不是状态变化
|
||
VendorStatus string `orm:"size(255)"`
|
||
StatusTime time.Time `orm:"type(datetime);index"`
|
||
DuplicatedCount int // 收到的重复状态转换(或消息)数,一般是由于重发造成的
|
||
Remark string `orm:"size(255)"`
|
||
ModelTimeInfo
|
||
LockStatus int `orm:"-"` // todo 只是用于传递状态,应该可以优化掉
|
||
}
|
||
|
||
func (v *OrderStatus) TableIndex() [][]string {
|
||
return [][]string{
|
||
[]string{"VendorOrderID", "Status", "VendorStatus"},
|
||
}
|
||
}
|
||
|
||
func Order2Status(order *GoodsOrder) (retVal *OrderStatus) {
|
||
retVal = &OrderStatus{
|
||
VendorOrderID: order.VendorOrderID,
|
||
VendorID: order.VendorID,
|
||
OrderType: OrderTypeOrder,
|
||
RefVendorOrderID: order.VendorOrderID,
|
||
RefVendorID: order.VendorID,
|
||
Status: order.Status,
|
||
VendorStatus: order.VendorStatus,
|
||
StatusTime: order.StatusTime,
|
||
LockStatus: order.LockStatus,
|
||
}
|
||
return retVal
|
||
}
|
||
|
||
func Waybill2Status(bill *Waybill) (retVal *OrderStatus) {
|
||
retVal = &OrderStatus{
|
||
VendorOrderID: bill.VendorWaybillID,
|
||
VendorID: bill.WaybillVendorID,
|
||
OrderType: OrderTypeWaybill,
|
||
RefVendorOrderID: bill.VendorOrderID,
|
||
RefVendorID: bill.OrderVendorID,
|
||
Status: bill.Status,
|
||
VendorStatus: bill.VendorStatus,
|
||
StatusTime: bill.StatusTime,
|
||
Remark: bill.Remark,
|
||
}
|
||
return retVal
|
||
}
|
||
|
||
// 判断订单是否是临时的,不是真实收到了new order消息后的订单
|
||
func IsOrderSolid(order *GoodsOrder) bool {
|
||
return !(order.ConsigneeName == "" && order.ID == 0)
|
||
}
|
||
|
||
func (o *GoodsOrder) GetStatusTime() time.Time {
|
||
return o.StatusTime
|
||
}
|
||
|
||
func (o *Waybill) GetStatusTime() time.Time {
|
||
return o.StatusTime
|
||
}
|
||
|
||
func (o *OrderStatus) GetStatusTime() time.Time {
|
||
return o.StatusTime
|
||
}
|