- yilianyun printer added
This commit is contained in:
@@ -101,10 +101,10 @@ func (c *PrinterHandler) GetVendorID() int {
|
||||
return model.VendorIDFeiE
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, id1, id2, msg string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, id1, id2, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg id1:%s", id1)
|
||||
if id1 != "" {
|
||||
if _, err = api.FeieAPI.PrintMsg(id1, msg, 1); err == nil {
|
||||
if _, err = api.FeieAPI.PrintMsg(id1, msgContent, 1); err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, id1, id2)
|
||||
}
|
||||
} else {
|
||||
@@ -130,48 +130,30 @@ func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, printerSN, pri
|
||||
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("feie PrintOrderByOrder orderID:%s", order.VendorOrderID)
|
||||
content := c.getOrderContent(order, store.Tel1)
|
||||
return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, content)
|
||||
return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, store *model.Store, id1, id2 string) (err error) {
|
||||
if store.PrinterSN != "" && (store.PrinterSN != id1 || store.PrinterKey != id2) {
|
||||
err = c.UnregisterPrinter(ctx, store)
|
||||
}
|
||||
if true { //err == nil {
|
||||
if id1 != "" {
|
||||
if err = addNetPrinter(id1, id2, store.Name); err == nil {
|
||||
store.PrinterSN = id1
|
||||
store.PrinterKey = id2
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, store *model.Store) (err error) {
|
||||
if store.PrinterSN != "" {
|
||||
_, _, err = api.FeieAPI.PrinterDelList([]string{store.PrinterSN})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func addNetPrinter(sn, key, storeName string) (err error) {
|
||||
name := storeName
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, printerSN, printerKey, printerName string) (notUsed1, notUsed2 string, err error) {
|
||||
_, no, err := api.FeieAPI.PrinterAddList([]*feieapi.PrinterInfo{
|
||||
&feieapi.PrinterInfo{
|
||||
SN: sn,
|
||||
Key: key,
|
||||
Name: name,
|
||||
SN: printerSN,
|
||||
Key: printerKey,
|
||||
Name: printerName,
|
||||
},
|
||||
})
|
||||
if err == nil {
|
||||
if no[sn] != "" {
|
||||
if no[sn] == feieapi.ErrMsgAlredyAdded {
|
||||
api.FeieAPI.PrinterEdit(sn, name, "")
|
||||
if no[printerSN] != "" {
|
||||
if no[printerSN] == feieapi.ErrMsgAlredyAdded {
|
||||
api.FeieAPI.PrinterEdit(printerSN, printerName, "")
|
||||
} else {
|
||||
err = fmt.Errorf("添加打印机出错:%s", no[sn])
|
||||
err = fmt.Errorf("添加打印机出错:%s", no[printerSN])
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, printerSN, notUsed string) (err error) {
|
||||
_, _, err = api.FeieAPI.PrinterDelList([]string{printerSN})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -34,31 +34,29 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
|
||||
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
|
||||
}
|
||||
orderFmt := `
|
||||
<CB>京西菜市</CB><BR>
|
||||
<C>手机买菜上京西</C><BR>
|
||||
<C>极速到家送惊喜</C><BR>
|
||||
--------------------------------<BR>
|
||||
下单时间: %s<BR>
|
||||
预计送达: %s<BR>
|
||||
订单编号: %s<BR>
|
||||
<BR>
|
||||
|
||||
<B>%s#%d</B><BR><BR>
|
||||
<QR>%s</QR>
|
||||
<BR>
|
||||
客户: %s<BR>
|
||||
电话: %s<BR>
|
||||
地址: %s<BR>
|
||||
<BR>
|
||||
客户备注: <BR>
|
||||
<B>%s</B><BR>
|
||||
<BR>
|
||||
|
||||
<BOLD>实际支付:</BOLD>%s<BR>
|
||||
<BR>
|
||||
商品明细: <BR>
|
||||
品名 数量 单价 小计<BR>
|
||||
--------------------------------<BR>`
|
||||
<big> 京西菜市**
|
||||
手机买菜上京西*
|
||||
极速到家送惊喜*
|
||||
------------------------------*
|
||||
下单时间: %s*
|
||||
预计送达: %s*
|
||||
订单编号: %s*
|
||||
*
|
||||
<big>%s\\#%d**
|
||||
<qrcA4>%s*
|
||||
客户: %s*
|
||||
电话: %s*
|
||||
地址: %s*
|
||||
*
|
||||
客户备注: *
|
||||
<big>%s*
|
||||
*
|
||||
<S011>实际支付: %s*
|
||||
*
|
||||
商品明细: *
|
||||
品名 数量 单价 小计
|
||||
--------------------------------*
|
||||
`
|
||||
orderParams := []interface{}{
|
||||
utils.Time2Str(order.OrderCreatedAt),
|
||||
utils.Time2Str(expectedDeliveryTime),
|
||||
@@ -72,26 +70,22 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
|
||||
order.BuyerComment,
|
||||
jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice),
|
||||
}
|
||||
|
||||
for _, sku := range order.Skus {
|
||||
orderFmt += `%s<BR>`
|
||||
orderFmt += `%10s%10s%10s<BR>`
|
||||
orderFmt += `%s*`
|
||||
orderFmt += `%10s%10s%10s*`
|
||||
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
|
||||
}
|
||||
orderFmt += `<BR>
|
||||
<BOLD>共%d种%d件商品</BOLD>
|
||||
<BR>
|
||||
--------------------------------<BR>
|
||||
<C><L><BOLD>商品质量问题请联系:</BOLD></L><BR></C>
|
||||
<C><L><BOLD>%s:%s</BOLD></L><BR></C><BR>
|
||||
<BR>
|
||||
官方服务热线: 18011516898<BR>
|
||||
更多信息请关注官方微信: 京西菜市<BR>
|
||||
<BR>
|
||||
<BR><BR>
|
||||
--------------------------------<BR>
|
||||
--------------------------------<BR>
|
||||
<BR><BR>
|
||||
orderFmt += `
|
||||
*
|
||||
<S011>共%d种%d件商品*
|
||||
--------------------------------*
|
||||
<S020>商品质量问题请联系:*
|
||||
<S020>%s:%s*
|
||||
*
|
||||
更多信息请关注官方微信: 京西菜市*
|
||||
--------------------------------
|
||||
--------------------------------
|
||||
*<BEEP13500,3,2,1>*
|
||||
`
|
||||
// <QR>http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk</QR>
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel)
|
||||
@@ -102,10 +96,10 @@ func (c *PrinterHandler) GetVendorID() int {
|
||||
return model.VendorIDXiaoWM
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, printerNumber, printerToken, msg string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, printerNumber, printerToken, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg printerNumber:%s", printerNumber)
|
||||
if printerNumber != "" {
|
||||
if _, err = api.XiaoWMAPI.SendMsg(printerNumber, printerToken, msg); err == nil {
|
||||
if _, err = api.XiaoWMAPI.SendMsg(printerNumber, printerToken, msgContent); err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, printerNumber, printerToken)
|
||||
}
|
||||
} else {
|
||||
@@ -138,28 +132,17 @@ func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, printerNumber,
|
||||
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("xiaowm PrintOrderByOrder orderID:%s", order.VendorOrderID)
|
||||
content := c.getOrderContent(order, store.Tel1)
|
||||
return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, content)
|
||||
return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, store *model.Store, printerNumber, notUsed string) (err error) {
|
||||
if store.PrinterSN != "" && store.PrinterSN != printerNumber {
|
||||
err = c.UnregisterPrinter(ctx, store)
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, printerNumber, notUsed, printerName string) (newID1, printerToken string, err error) {
|
||||
if printerToken, err = api.XiaoWMAPI.AuthPrinter(printerNumber, "", ""); err == nil {
|
||||
return printerNumber, printerToken, nil
|
||||
}
|
||||
if true { //err == nil {
|
||||
if printerNumber != "" {
|
||||
var printerToken string
|
||||
if printerToken, err = api.XiaoWMAPI.AuthPrinter(printerNumber, "", ""); err == nil {
|
||||
store.PrinterSN = printerNumber
|
||||
store.PrinterKey = printerToken
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, store *model.Store) (err error) {
|
||||
if store.PrinterSN != "" {
|
||||
err = api.XiaoWMAPI.DelPrinter(store.PrinterSN, store.PrinterKey)
|
||||
}
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, printerNumber, printerToken string) (err error) {
|
||||
err = api.XiaoWMAPI.DelPrinter(printerNumber, printerToken)
|
||||
return err
|
||||
}
|
||||
|
||||
149
business/partner/printer/yilianyun/yilianyun.go
Normal file
149
business/partner/printer/yilianyun/yilianyun.go
Normal file
@@ -0,0 +1,149 @@
|
||||
package yilianyun
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/yilianyunapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
var (
|
||||
CurPrinterHandler *PrinterHandler
|
||||
)
|
||||
|
||||
type PrinterHandler struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
CurPrinterHandler = new(PrinterHandler)
|
||||
partner.RegisterPrinterPlatform(CurPrinterHandler)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel string) (content string) {
|
||||
expectedDeliveryTime := order.ExpectedDeliveredTime
|
||||
if utils.IsTimeZero(expectedDeliveryTime) {
|
||||
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
|
||||
}
|
||||
orderFmt := `
|
||||
<CB>京西菜市</CB><BR>
|
||||
<C>手机买菜上京西</C><BR>
|
||||
<C>极速到家送惊喜</C><BR>
|
||||
--------------------------------<BR>
|
||||
下单时间: %s<BR>
|
||||
预计送达: %s<BR>
|
||||
订单编号: %s<BR>
|
||||
<BR>
|
||||
|
||||
<B>%s#%d</B><BR><BR>
|
||||
<QR>%s</QR>
|
||||
<BR>
|
||||
客户: %s<BR>
|
||||
电话: %s<BR>
|
||||
地址: %s<BR>
|
||||
<BR>
|
||||
客户备注: <BR>
|
||||
<B>%s</B><BR>
|
||||
<BR>
|
||||
|
||||
<BOLD>实际支付:</BOLD>%s<BR>
|
||||
<BR>
|
||||
商品明细: <BR>
|
||||
品名 数量 单价 小计<BR>
|
||||
--------------------------------<BR>`
|
||||
orderParams := []interface{}{
|
||||
utils.Time2Str(order.OrderCreatedAt),
|
||||
utils.Time2Str(expectedDeliveryTime),
|
||||
order.VendorOrderID,
|
||||
jxutils.GetVendorName(order.VendorID),
|
||||
order.OrderSeq,
|
||||
order.VendorOrderID,
|
||||
order.ConsigneeName,
|
||||
order.ConsigneeMobile,
|
||||
order.ConsigneeAddress,
|
||||
order.BuyerComment,
|
||||
jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice),
|
||||
}
|
||||
|
||||
for _, sku := range order.Skus {
|
||||
orderFmt += `%s<BR>`
|
||||
orderFmt += `%10s%10s%10s<BR>`
|
||||
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
|
||||
}
|
||||
orderFmt += `<BR>
|
||||
<BOLD>共%d种%d件商品</BOLD>
|
||||
<BR>
|
||||
--------------------------------<BR>
|
||||
<C><L><BOLD>商品质量问题请联系:</BOLD></L><BR></C>
|
||||
<C><L><BOLD>%s:%s</BOLD></L><BR></C><BR>
|
||||
<BR>
|
||||
官方服务热线: 18011516898<BR>
|
||||
更多信息请关注官方微信: 京西菜市<BR>
|
||||
<BR>
|
||||
<BR><BR>
|
||||
--------------------------------<BR>
|
||||
--------------------------------<BR>
|
||||
<BR><BR>
|
||||
`
|
||||
// <QR>http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk</QR>
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel)
|
||||
return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) GetVendorID() int {
|
||||
return model.VendorIDYiLianYun
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, machineCode, notUsed, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg machineCode:%s", machineCode)
|
||||
if machineCode != "" {
|
||||
if err = api.YilianyunAPI.PrintMsg(machineCode, msgTitle, msgContent); err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, machineCode, "")
|
||||
}
|
||||
} else {
|
||||
printerStatus = &partner.PrinterStatus{
|
||||
PrintResult: partner.PrintResultNoPrinter,
|
||||
}
|
||||
}
|
||||
return printerStatus, err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, machineCode, notUsed string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
status, err := api.YilianyunAPI.GetPrintStatus(machineCode)
|
||||
if err == nil {
|
||||
printerStatus = &partner.PrinterStatus{
|
||||
PrintResult: partner.PrintResultSuccess,
|
||||
}
|
||||
if status == yilianyunapi.PrintStatusOffline {
|
||||
printerStatus.PrinterStatus = partner.PrinterStatusOffline
|
||||
} else if status == yilianyunapi.PrintStatusOnline {
|
||||
printerStatus.PrinterStatus = partner.PrinterStatusOnlineOK
|
||||
} else {
|
||||
printerStatus.PrinterStatus = partner.PrinterStatusOnlineAbnormal
|
||||
}
|
||||
}
|
||||
return printerStatus, err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("yilianyun PrintOrderByOrder orderID:%s", order.VendorOrderID)
|
||||
content := c.getOrderContent(order, store.Tel1)
|
||||
return c.PrintMsg(ctx, store.PrinterSN, "", order.VendorOrderID, content)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, machineCode, secret, printerName string) (notUsed1, notUsed2 string, err error) {
|
||||
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)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user