|
|
|
|
@@ -1 +1,275 @@
|
|
|
|
|
package xpyun
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
|
|
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
|
|
|
|
|
|
|
|
|
"git.rosy.net.cn/baseapi/platformapi/xpyunapi"
|
|
|
|
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
|
|
|
|
"git.rosy.net.cn/jx-callback/business/model"
|
|
|
|
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
|
|
|
"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) GetVendorID() int {
|
|
|
|
|
return model.VendorIDXpYun
|
|
|
|
|
}
|
|
|
|
|
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, sn, copies, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
|
|
|
|
if sn != "" {
|
|
|
|
|
if globals.EnableStoreWrite {
|
|
|
|
|
if utils.Str2Int(copies) < 0 || utils.Str2Int(copies) > 3 {
|
|
|
|
|
copies = "1"
|
|
|
|
|
}
|
|
|
|
|
printOrderID, err1 := api.XpyunAPI.Print(&xpyunapi.PrintRequest{
|
|
|
|
|
Sn: sn,
|
|
|
|
|
Content: msgContent,
|
|
|
|
|
Copies: utils.Str2Int(copies),
|
|
|
|
|
Voice: xpyunapi.VoicePlayOrder,
|
|
|
|
|
Mode: xpyunapi.ModeCheckYes,
|
|
|
|
|
ExpiresIn: xpyunapi.ExpiresInDefault,
|
|
|
|
|
})
|
|
|
|
|
if err1 == nil && printOrderID != "" {
|
|
|
|
|
printerStatus, err = c.GetPrinterStatus(ctx, sn, "")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
printerStatus = &partner.PrinterStatus{
|
|
|
|
|
PrintResult: partner.PrintResultNoPrinter,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return printerStatus, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, sn, s string) (printerStatus *partner.PrinterStatus, err error) {
|
|
|
|
|
if status, err := api.XpyunAPI.QueryPrinterStatus(sn); err == nil {
|
|
|
|
|
printerStatus = &partner.PrinterStatus{
|
|
|
|
|
PrintResult: partner.PrintResultSuccess,
|
|
|
|
|
}
|
|
|
|
|
if status == xpyunapi.PrinterStateOffline {
|
|
|
|
|
printerStatus.PrinterStatus = partner.PrinterStatusOffline
|
|
|
|
|
} else if status == xpyunapi.PrinterStateOnlineNormal {
|
|
|
|
|
printerStatus.PrinterStatus = partner.PrinterStatusOnlineOK
|
|
|
|
|
} else if status == xpyunapi.PrinterStateOnlineUnusual {
|
|
|
|
|
printerStatus.PrinterStatus = partner.PrinterStatusOnlineAbnormal
|
|
|
|
|
} else {
|
|
|
|
|
printerStatus.PrinterStatus = partner.PrinterStatusUnknown
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return printerStatus, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, sn, id2, printerName string, soreId int64) (newID1, newID2 string, err error) {
|
|
|
|
|
if globals.EnableStoreWrite {
|
|
|
|
|
err = api.XpyunAPI.AddPrinters(sn, printerName)
|
|
|
|
|
}
|
|
|
|
|
return "", "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, sn, id2 string) (err error) {
|
|
|
|
|
if globals.EnableStoreWrite {
|
|
|
|
|
err = api.XpyunAPI.DelPrinters([]string{sn})
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) BindPrinter(ctx *jxcontext.Context, mapData map[string]interface{}) (bindResult *partner.BindPrinterResult, err error) {
|
|
|
|
|
return nil, fmt.Errorf("%s打印机当前不支持扫码绑定", model.VendorChineseNames[model.VendorIDXpYun])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *partner.BindPrinterResult) (bindResult *partner.BindPrinterResult, err error) {
|
|
|
|
|
return nil, fmt.Errorf("%s打印机当前不支持扫码解绑", model.VendorChineseNames[model.VendorIDXpYun])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder, printType string, asfOrder *model.AfsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
|
|
|
|
if len(order.Skus) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
content := ""
|
|
|
|
|
if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
|
|
|
|
|
content = c.getOrderContentBig(order, store.Tel1, storeDetail)
|
|
|
|
|
} else {
|
|
|
|
|
content = c.getOrderContent(order, store.Tel1, storeDetail)
|
|
|
|
|
}
|
|
|
|
|
count := 0
|
|
|
|
|
for {
|
|
|
|
|
printerStatus, err := c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content)
|
|
|
|
|
if (store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2) && count < 1 {
|
|
|
|
|
count += 1
|
|
|
|
|
continue
|
|
|
|
|
} else {
|
|
|
|
|
return printerStatus, err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) PrintStore(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, vendorId int) (printerStatus *partner.PrinterStatus, err error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) PrintCancelOrRefundOrder(ctx *jxcontext.Context, printType int, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, sn, id2 string) (err error) {
|
|
|
|
|
if globals.EnableStoreWrite {
|
|
|
|
|
err = api.XpyunAPI.EmptyPrinterQueue(sn)
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *partner.PrinterStatus, err error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *PrinterHandler) SetSound(ctx *jxcontext.Context, sn, id2, sound string) (err error) {
|
|
|
|
|
if globals.EnableStoreWrite {
|
|
|
|
|
err = api.XpyunAPI.SetVoiceType(sn, utils.Str2Int(sound))
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 正常打印模板
|
|
|
|
|
func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
|
|
|
|
|
expectedDeliveryTime := order.ExpectedDeliveredTime
|
|
|
|
|
if utils.IsTimeZero(expectedDeliveryTime) {
|
|
|
|
|
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
|
|
|
|
|
}
|
|
|
|
|
getCode := ""
|
|
|
|
|
if order.VendorID == model.VendorIDEBAI {
|
|
|
|
|
getCode = fmt.Sprintf("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
|
|
|
|
|
}
|
|
|
|
|
orderParams := []interface{}{}
|
|
|
|
|
orderFmt := ``
|
|
|
|
|
if storeDetail != nil {
|
|
|
|
|
if storeDetail.BrandIsPrint == model.NO {
|
|
|
|
|
orderFmt += `<BR><C>%s</C></BR>\n`
|
|
|
|
|
if order.VendorOrgCode == "34665" {
|
|
|
|
|
orderParams = append(orderParams, globals.StoreNameEbai2)
|
|
|
|
|
} else {
|
|
|
|
|
orderParams = append(orderParams, storeDetail.BrandName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
orderFmt += `
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<BR><L>下单时间: %s</BR>
|
|
|
|
|
<BR><L>预计送达: %s</BR>
|
|
|
|
|
<BR><L>客户姓名: %s</BR>
|
|
|
|
|
<BR><L>客户电话: %s</BR>
|
|
|
|
|
<BR><HB>订单编号: %s</HB></BR>
|
|
|
|
|
<IMG></IMG><BR><C><B>%s: #%d</B></BR></C>
|
|
|
|
|
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C>"
|
|
|
|
|
` + getCode + `
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<HB>客户地址: %s</HB><BR>
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<BR>客户备注: %s<BR>
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<BR>商品列表 ` + xpyunapi.StrRepeat("-", 6) + `<BR>
|
|
|
|
|
商品名` + xpyunapi.StrRepeat("-", 2) + `数量` + xpyunapi.StrRepeat("-", 3) + `单价` + xpyunapi.StrRepeat("-", 5) + `小计<BR>"
|
|
|
|
|
`
|
|
|
|
|
orderParams = append(orderParams,
|
|
|
|
|
utils.Time2Str(order.OrderCreatedAt),
|
|
|
|
|
utils.Time2Str(expectedDeliveryTime),
|
|
|
|
|
order.ConsigneeName,
|
|
|
|
|
order.ConsigneeMobile,
|
|
|
|
|
order.VendorOrderID,
|
|
|
|
|
jxutils.GetVendorName(order.VendorID),
|
|
|
|
|
order.OrderSeq,
|
|
|
|
|
order.VendorOrderID,
|
|
|
|
|
order.ConsigneeAddress,
|
|
|
|
|
order.BuyerComment,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for _, sku := range order.Skus {
|
|
|
|
|
orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
|
|
|
|
|
}
|
|
|
|
|
orderFmt += `
|
|
|
|
|
<L>共%d种%d件商品<BR></L>
|
|
|
|
|
<L>实际支付: %s元<BR></L>
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 2) + `
|
|
|
|
|
`
|
|
|
|
|
orderFmt += `<BR><BR>`
|
|
|
|
|
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice))
|
|
|
|
|
return fmt.Sprintf(orderFmt, orderParams...)
|
|
|
|
|
}
|
|
|
|
|
func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
|
|
|
|
|
expectedDeliveryTime := order.ExpectedDeliveredTime
|
|
|
|
|
if utils.IsTimeZero(expectedDeliveryTime) {
|
|
|
|
|
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
|
|
|
|
|
}
|
|
|
|
|
getCode := ""
|
|
|
|
|
if order.VendorID == model.VendorIDEBAI {
|
|
|
|
|
getCode = fmt.Sprintf("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
|
|
|
|
|
}
|
|
|
|
|
orderParams := []interface{}{}
|
|
|
|
|
orderFmt := ``
|
|
|
|
|
if storeDetail != nil {
|
|
|
|
|
if storeDetail.BrandIsPrint == model.NO {
|
|
|
|
|
orderFmt += `<BR><C>%s</C></BR>\n`
|
|
|
|
|
if order.VendorOrgCode == "34665" {
|
|
|
|
|
orderParams = append(orderParams, globals.StoreNameEbai2)
|
|
|
|
|
} else {
|
|
|
|
|
orderParams = append(orderParams, storeDetail.BrandName)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
orderFmt += `
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<BR><L>下单时间: %s</BR>
|
|
|
|
|
<BR><L>预计送达: %s</BR>
|
|
|
|
|
<BR><L>客户姓名: %s</BR>
|
|
|
|
|
<BR><L>客户电话: %s</BR>
|
|
|
|
|
<BR><HB>订单编号: %s</HB></BR>
|
|
|
|
|
<IMG></IMG><BR><C><B>%s: #%d</B></BR></C>
|
|
|
|
|
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C>"
|
|
|
|
|
` + getCode + `
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<HB>客户地址: %s</HB><BR>
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<BR>客户备注: %s<BR>
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 32) + `
|
|
|
|
|
<BR>商品列表 ` + xpyunapi.StrRepeat("-", 6) + `<BR>
|
|
|
|
|
商品名` + xpyunapi.StrRepeat("-", 2) + `数量` + xpyunapi.StrRepeat("-", 3) + `单价` + xpyunapi.StrRepeat("-", 5) + `小计<BR>"
|
|
|
|
|
`
|
|
|
|
|
orderParams = append(orderParams,
|
|
|
|
|
utils.Time2Str(order.OrderCreatedAt),
|
|
|
|
|
utils.Time2Str(expectedDeliveryTime),
|
|
|
|
|
order.ConsigneeName,
|
|
|
|
|
order.ConsigneeMobile,
|
|
|
|
|
order.VendorOrderID,
|
|
|
|
|
jxutils.GetVendorName(order.VendorID),
|
|
|
|
|
order.OrderSeq,
|
|
|
|
|
order.VendorOrderID,
|
|
|
|
|
order.ConsigneeAddress,
|
|
|
|
|
order.BuyerComment,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
for _, sku := range order.Skus {
|
|
|
|
|
orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
|
|
|
|
|
}
|
|
|
|
|
orderFmt += `
|
|
|
|
|
<L>共%d种%d件商品<BR></L>
|
|
|
|
|
<L>实际支付: %s元<BR></L>
|
|
|
|
|
` + xpyunapi.StrRepeat("-", 2) + `
|
|
|
|
|
`
|
|
|
|
|
orderFmt += `<BR><BR>`
|
|
|
|
|
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice))
|
|
|
|
|
return fmt.Sprintf(orderFmt, orderParams...)
|
|
|
|
|
}
|
|
|
|
|
|