- 门店网络打印机设置修改,只有在成功绑定后才执行可能的解绑(之前是先解绑,可能有问题)

- 所有网络打印机适配层写入性API添加EnableStoreWrite控制
This commit is contained in:
gazebo
2019-08-06 21:58:06 +08:00
parent 447237f252
commit e3e900cd10
6 changed files with 84 additions and 46 deletions

View File

@@ -102,7 +102,10 @@ func (c *PrinterHandler) GetVendorID() int {
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, machineCode, possibleToken, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
globals.SugarLogger.Debugf("PrintMsg machineCode:%s", machineCode)
if machineCode != "" {
if err = getApiByToken(possibleToken).PrintMsgWithToken(machineCode, msgTitle, msgContent, possibleToken); err == nil {
if globals.EnableStoreWrite {
err = getApiByToken(possibleToken).PrintMsgWithToken(machineCode, msgTitle, msgContent, possibleToken)
}
if err == nil {
printerStatus, err = c.GetPrinterStatus(ctx, machineCode, possibleToken)
}
} else {
@@ -137,12 +140,16 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store,
}
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, machineCode, secret, printerName string) (notUsed1, notUsed2 string, err error) {
err = api.YilianyunAPI.AddPrinter(machineCode, secret, printerName)
if globals.EnableStoreWrite {
err = api.YilianyunAPI.AddPrinter(machineCode, secret, printerName)
}
return "", "", err
}
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, machineCode, notUsed string) (err error) {
err = api.YilianyunAPI.DeletePrinter(machineCode)
if globals.EnableStoreWrite {
err = api.YilianyunAPI.DeletePrinter(machineCode)
}
return err
}
@@ -160,7 +167,12 @@ func (c *PrinterHandler) BindPrinter(ctx *jxcontext.Context, mapData map[string]
}
func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *partner.BindPrinterResult) (bindResult *partner.BindPrinterResult, err error) {
tokenInfo, err := api.YilianyunAPI2.RefreshToken(lastBindResult.PrinterKey2)
var tokenInfo *yilianyunapi.TokenInfo
if globals.EnableStoreWrite {
tokenInfo, err = api.YilianyunAPI2.RefreshToken(lastBindResult.PrinterKey2)
} else {
tokenInfo = &yilianyunapi.TokenInfo{}
}
if err == nil {
bindResult = yilianyunToken2BindResult(tokenInfo)
}
@@ -184,11 +196,15 @@ func getApiByToken(possibleToken string) *yilianyunapi.API {
}
func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, id1, id2 string) (err error) {
err = api.YilianyunAPI.CancelAll(id1, id2)
if globals.EnableStoreWrite {
err = api.YilianyunAPI.CancelAll(id1, id2)
}
return err
}
func (c *PrinterHandler) PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *partner.PrinterStatus, err error) {
err = api.YilianyunAPI.PlayText(id1, orderID, text, id2)
if globals.EnableStoreWrite {
err = api.YilianyunAPI.PlayText(id1, orderID, text, id2)
}
return nil, err
}