- 重构打印机流程,添加“外卖管家”打印
This commit is contained in:
@@ -22,6 +22,30 @@ const (
|
||||
CancelWaybillReasonOther = 10
|
||||
)
|
||||
|
||||
const (
|
||||
PrinterStatusUnknown = 0
|
||||
PrinterStatusOffline = 1
|
||||
PrinterStatusOnlineOK = 2
|
||||
PrinterStatusOnlineAbnormal = 3
|
||||
)
|
||||
|
||||
const (
|
||||
PrintResultSuccess = 0
|
||||
PrintResultNoPrinter = 1
|
||||
)
|
||||
|
||||
type PrinterStatus struct {
|
||||
PrintResult int `json:"printResult"` // 0:成功,1:没有配置网络打印机
|
||||
|
||||
// PrinterStatusUnknown = 0
|
||||
// PrinterStatusOffline = 1
|
||||
// PrinterStatusOnlineOK = 2
|
||||
// PrinterStatusOnlineAbnormal = 3
|
||||
PrinterStatus int `json:"printerStatus"`
|
||||
Printed int `json:"printed"` // 已经打印的单数
|
||||
Waiting int `json:"waiting"` // 等待打印的单数,超过1一般不太正常
|
||||
}
|
||||
|
||||
const (
|
||||
TimerTypeNoOverride = 0 // GetStatusActionConfig 返回表示不修改缺省配置
|
||||
TimerTypeByPass = 1
|
||||
@@ -65,6 +89,7 @@ var (
|
||||
PurchasePlatformHandlers map[int]IPurchasePlatformHandler
|
||||
DeliveryPlatformHandlers map[int]*DeliveryPlatformHandlerInfo
|
||||
UseableDeliveryVendorIDs []int
|
||||
PrinterPlatformHandlers map[int]IPrinterHandler
|
||||
)
|
||||
|
||||
type IOrderManager interface {
|
||||
@@ -167,6 +192,16 @@ type IDeliveryPlatformHandler interface {
|
||||
GetVendorID() int
|
||||
}
|
||||
|
||||
type IPrinterHandler interface {
|
||||
GetVendorID() int
|
||||
PrintMsg(ctx *jxcontext.Context, id1, id2, msg string) (printerStatus *PrinterStatus, err error)
|
||||
GetPrinterStatus(ctx *jxcontext.Context, id1, id2 string) (printerStatus *PrinterStatus, err error)
|
||||
|
||||
PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *PrinterStatus, err error)
|
||||
RegisterPrinter(ctx *jxcontext.Context, store *model.Store, id1, id2 string) (err error)
|
||||
UnregisterPrinter(ctx *jxcontext.Context, store *model.Store) (err error)
|
||||
}
|
||||
|
||||
type DeliveryPlatformHandlerInfo struct {
|
||||
Handler IDeliveryPlatformHandler
|
||||
Use4CreateWaybill bool
|
||||
@@ -182,6 +217,7 @@ func (p *BasePurchasePlatform) GetStatusActionTimeout(order *model.GoodsOrder, s
|
||||
func init() {
|
||||
PurchasePlatformHandlers = make(map[int]IPurchasePlatformHandler)
|
||||
DeliveryPlatformHandlers = make(map[int]*DeliveryPlatformHandlerInfo)
|
||||
PrinterPlatformHandlers = make(map[int]IPrinterHandler)
|
||||
}
|
||||
|
||||
func Init(curOrderManager IOrderManager) {
|
||||
@@ -213,6 +249,18 @@ func RegisterDeliveryPlatform(handler IDeliveryPlatformHandler, isUse4CreateWayb
|
||||
}
|
||||
UseableDeliveryVendorIDs = append(UseableDeliveryVendorIDs, vendorID)
|
||||
}
|
||||
|
||||
func RegisterPrinterPlatform(handler IPrinterHandler) {
|
||||
vendorID := handler.GetVendorID()
|
||||
if !(model.IsPrinterVendorExist(vendorID)) {
|
||||
panic(fmt.Sprintf("printer vendor:%d is illegal", vendorID))
|
||||
}
|
||||
if _, ok := PrinterPlatformHandlers[vendorID]; ok {
|
||||
panic(fmt.Sprintf("printer vendor:%d, already exists", vendorID))
|
||||
}
|
||||
PrinterPlatformHandlers[vendorID] = handler
|
||||
}
|
||||
|
||||
func GetPurchasePlatformFromVendorID(vendorID int) IPurchasePlatformHandler {
|
||||
return PurchasePlatformHandlers[vendorID]
|
||||
}
|
||||
@@ -220,3 +268,7 @@ func GetPurchasePlatformFromVendorID(vendorID int) IPurchasePlatformHandler {
|
||||
func GetDeliveryPlatformFromVendorID(vendorID int) *DeliveryPlatformHandlerInfo {
|
||||
return DeliveryPlatformHandlers[vendorID]
|
||||
}
|
||||
|
||||
func GetPrinterPlatformFromVendorID(vendorID int) IPrinterHandler {
|
||||
return PrinterPlatformHandlers[vendorID]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user