package model import "time" const ( OrderDeliveryTypePlatform = "platform" // 平台负责配送 OrderDeliveryTypeStoreSelf = "store" // 门店自送 OrderDeliveryTypeSelfTake = "self" // 用户自提 ) 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)" json:"id"` VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` VendorOrderID2 string `orm:"column(vendor_order_id2);size(48);index" json:"vendorOrderID2"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid StoreName string `orm:"size(64)" json:"storeName"` ShopPrice int64 `json:"shopPrice"` // 京西价 VendorPrice int64 `json:"vendorPrice"` // 平台价 SalePrice int64 `json:"salePrice"` // 售卖价 ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付 TotalShopMoney int64 `json:"totalShopMoney"` // 应结金额-第三方平台结算给京西的金额(包括了所有的补贴,扣除) DiscountMoney int64 `json:"discountMoney"` // 订单总优惠金额 PmSubsidyMoney int64 `json:"pmSubsidyMoney"` // 平台活动补贴(订单主体活动补贴+订单单条sku补贴)1+ DistanceFreightMoney int64 `json:"distanceFreightMoney"` // 商户承担的远距离配送费(当前只有京东到家有值) WaybillTipMoney int64 `json:"waybillTipMoney"` // 京西加的平台配送小费 EarningPrice int64 `json:"earningPrice"` // 结算给门店老板的钱(未扣除可能的三方配送费) Weight int `json:"weight"` // 单位为克 VendorUserID string `orm:"column(vendor_user_id);size(48)" json:"vendorUserID"` UserID string `orm:"column(user_id);size(48)" json:"userID"` ConsigneeName string `orm:"size(32)" json:"consigneeName"` ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"` // 订单中的收货手机号 ConsigneeMobile2 string `orm:"size(32)" json:"consigneeMobile2"` // 收货人真实手机号 ConsigneeAddress string `orm:"size(255)" json:"consigneeAddress"` CoordinateType int `json:"coordinateType"` ConsigneeLng int `json:"consigneeLng"` // 坐标 * (10的六次方) ConsigneeLat int `json:"consigneeLat"` // 坐标 * (10的六次方) SkuCount int `json:"skuCount"` // 商品类别数量,即有多少种商品(注意在某些情况下,相同SKU的商品由于售价不同,也会当成不同商品在这个值里) GoodsCount int `json:"goodsCount"` // 商品个数 Status int `json:"status"` // 参见OrderStatus*相关的常量定义 VendorStatus string `orm:"size(255)" json:"vendorStatus"` LockStatus int `json:"lockStatus"` LockStatusTime time.Time `orm:"type(datetime);null" json:"lockStatusTime"` // last lock status time OrderSeq int `json:"orderSeq"` // 门店订单序号 BuyerComment string `orm:"size(255)" json:"buyerComment"` BusinessType int `json:"businessType"` ExpectedDeliveredTime time.Time `orm:"type(datetime)" json:"expectedDeliveredTime"` // 预期送达时间 CancelApplyReason string `orm:"size(255)" json:"-"` // ""表示没有申请,不为null表示用户正在取消申请 DeliveryType string `orm:"size(32)" json:"deliveryType"` // 订单配送方式,缺省是平台配送 VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)" json:"vendorWaybillID"` WaybillVendorID int `orm:"column(waybill_vendor_id)" json:"waybillVendorID"` // 表示当前承运商,-1表示还没有安排 AdjustCount int8 `json:"adjustCount"` // 调整单(次数) DeliveryFlag int8 `json:"deliveryFlag"` // 第1位为1表示禁止调度器调度三方配送 DuplicatedCount int `json:"-"` // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的 OrderCreatedAt time.Time `orm:"type(datetime);index" json:"orderCreatedAt"` // 这里记录的是订单生效时间,即用户支付完成(货到付款即为下单时间) OrderFinishedAt time.Time `orm:"type(datetime)" json:"orderFinishedAt"` StatusTime time.Time `orm:"type(datetime)" json:"statusTime"` // last status time PickDeadline time.Time `orm:"type(datetime);null" json:"pickDeadline"` DeliveryFeeFrom *time.Time `orm:"type(datetime);null" json:"deliveryFeeFrom,omitempty"` // 三方配置费计算的开始基准时间 ModelTimeInfo `json:"-"` Flag int `json:"flag"` //非运单调整相关的其它状态 InvoiceTitle string `orm:"size(64)" json:"invoiceTitle"` // 发票抬头 InvoiceTaxerID string `orm:"size(32);column(invoice_taxer_id)" json:"invoiceTaxerID"` // 发票纳税人识别码 InvoiceEmail string `orm:"size(64)" json:"invoiceEmail"` // 发票邮箱 // 以下只是用于传递数据 OriginalData string `orm:"-" json:"-"` Skus []*OrderSku `orm:"-" json:"-"` } func (o *GoodsOrder) TableUnique() [][]string { return [][]string{ []string{"VendorOrderID", "VendorID"}, } } type GoodsOrderOriginal struct { ID int64 `orm:"column(id)" json:"-"` VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` AccountNo string `orm:"size(32)" json:"accountNo"` OrderCreatedAt time.Time `orm:"type(datetime);index" json:"orderCreatedAt"` // 这里记录的是订单生效时间,即用户支付完成(货到付款即为下单时间) CreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"` OriginalData string `orm:"type(text)" json:"-"` } func (o *GoodsOrderOriginal) TableUnique() [][]string { return [][]string{ []string{"VendorOrderID", "VendorID"}, } } type OrderSku struct { ID int64 `orm:"column(id)" json:"-"` VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` StoreSubID int `orm:"column(store_sub_id)" json:"storeSubID"` // 当前这个字段被当成结算活动ID用 StoreSubName string `orm:"size(64)" json:"storeSubName"` // 当前这个字段被用作vendorActType Count int `json:"count"` VendorSkuID string `orm:"column(vendor_sku_id);size(48)" json:"vendorSkuID"` SkuID int `orm:"column(sku_id)" json:"skuID"` // 外部系统里记录的 jxskuid JxSkuID int `orm:"column(jx_sku_id)" json:"jxSkuID"` // 根据VendorSkuID在本地系统里查询出来的 jxskuid SkuName string `orm:"size(255)" json:"skuName"` ShopPrice int64 `json:"shopPrice"` // 京西价 VendorPrice int64 `json:"vendorPrice"` // 平台价 SalePrice int64 `json:"salePrice"` // 售卖价 EarningPrice int64 `json:"earningPrice"` // 活动商品设置,结算给门店老板的钱,如果结算活动ID为0,是按结算比例算的,否则就是结算表中的值 Weight int `json:"weight"` // 单位为克 SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0 PromotionType int `json:"promotionType"` // todo 当前是用于记录京东的PromotionType(生成jxorder用),没有做转换 OrderCreatedAt time.Time `orm:"type(datetime);index" json:"-"` // 分区考虑 } // 同样商品在一个订单中可能重复出现(比如搞活动时,相同商品价格不一样,第一个有优惠) // 所以这里不能用唯一索引 func (o *OrderSku) TableIndex() [][]string { return [][]string{ []string{"VendorOrderID", "SkuID"}, []string{"JxSkuID", "VendorOrderID"}, } } type Waybill struct { ID int64 `orm:"column(id)" json:"-"` VendorWaybillID string `orm:"column(vendor_waybill_id);size(48)" json:"vendorWaybillID"` VendorWaybillID2 string `orm:"column(vendor_waybill_id2);size(48)" json:"vendorWaybillID2"` // 某些平台有多个ID,比如美团配送,当前美团配送的 delivery_id存这里 WaybillVendorID int `orm:"column(waybill_vendor_id)" json:"waybillVendorID"` VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` OrderVendorID int `orm:"column(order_vendor_id)" json:"orderVendorID"` CourierName string `orm:"size(32)" json:"courierName"` CourierMobile string `orm:"size(32)" json:"courierMobile"` Status int `json:"status"` // 参见WaybillStatus*相关的常量定义 VendorStatus string `orm:"size(255)" json:"-"` ActualFee int64 `json:"actualFee"` // 实际要支付给快递公司的费用 DesiredFee int64 `json:"desiredFee"` // 运单总费用 DuplicatedCount int `json:"-"` // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的 DeliveryFlag int8 `json:"deliveryFlag"` WaybillCreatedAt time.Time `orm:"type(datetime);index" json:"waybillCreatedAt"` WaybillFinishedAt time.Time `orm:"type(datetime)" json:"waybillFinishedAt"` StatusTime time.Time `orm:"type(datetime)" json:"-"` // last status time ModelTimeInfo `json:"-"` OriginalData string `orm:"type(text)" json:"-"` Remark string `orm:"-" json:"-"` // 用于传递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)" json:"id"` VendorOrderID string `orm:"column(vendor_order_id);size(48)" json:"vendorOrderID"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` OrderType int `json:"orderType"` // 0:订单,1:运单 RefVendorOrderID string `orm:"column(ref_vendor_order_id);size(48)" json:"refVendorOrderID"` RefVendorID int `orm:"column(ref_vendor_id)" json:"refVendorID"` Status int `json:"status"` // 如果Status为OrderStatusEvent,表示VendorStatus只是一个通知事件,不是状态变化 VendorStatus string `orm:"size(255)" json:"vendorStatus"` StatusTime time.Time `orm:"type(datetime);index" json:"statusTime"` DuplicatedCount int `json:"-"` // 收到的重复状态转换(或消息)数,一般是由于重发造成的 Remark string `orm:"size(255)" json:"remark"` ModelTimeInfo `json:"-"` // LockStatus int `orm:"-" json:"-"` // todo 只是用于传递状态,应该可以优化掉 } func (v *OrderStatus) TableIndex() [][]string { return [][]string{ []string{"VendorOrderID", "Status", "VendorStatus"}, []string{"RefVendorOrderID", "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 != nil && !(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 } type OrderComment struct { ModelIDCUL VendorOrderID string `orm:"column(vendor_order_id);size(48);unique" json:"vendorOrderID"` VendorOrderID2 string `orm:"column(vendor_order_id2);size(48);unique" json:"vendorOrderID2"` VendorID int `orm:"column(vendor_id)" json:"vendorID"` VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"` StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid ConsigneeMobile string `orm:"size(32)" json:"consigneeMobile"` UserCommentID string `orm:"column(user_comment_id);size(48)" json:"userCommentID"` IsReplied int8 Status int8 ModifyDuration int16 // 改评价的小时数 TagList string Score int8 Content string CommentCreatedAt time.Time OriginalMsg string `orm:"type(text)" json:"-"` UpdatedTagList string UpdatedScore int8 UpdatedContent string CommentUpdatedAt time.Time UpdatedOriginalMsg string `orm:"type(text)" json:"-"` } // 判断是否是购买平台自有物流 // 对于京东,饿百来说,就是其自有的物流,对于微商城来说,是达达 func IsWaybillPlatformOwn(bill *Waybill) bool { return bill.OrderVendorID == bill.WaybillVendorID } // 订单是否已经有了有效运单 func IsOrderHaveWaybill(order *GoodsOrder) bool { return order.WaybillVendorID != VendorIDUnknown && order.VendorWaybillID != "" } // 订单是否有自己平台的有效运单 func IsOrderHaveOwnWaybill(order *GoodsOrder) bool { return order.VendorID == order.WaybillVendorID && order.VendorWaybillID != "" } // 订单的初始配送方式是否是门店自配送 func IsOrderDeliveryByStore(order *GoodsOrder) bool { return order.DeliveryType == OrderDeliveryTypeStoreSelf } // 订单的初始配送方式是否是平台负责配送 func IsOrderDeliveryByPlatform(order *GoodsOrder) bool { return order.DeliveryType == OrderDeliveryTypePlatform } func IsOrderJXTemp(order *GoodsOrder) bool { // return order.Flag&OrderFlagMaskTempJX != 0 return true } func IsAfsOrderJXTemp(order *AfsOrder) bool { // return order.Flag&OrderFlagMaskTempJX != 0 return true }