diff --git a/business/partner/printer/xpyun/xpyun.go b/business/partner/printer/xpyun/xpyun.go index caab30d53..c881e7514 100644 --- a/business/partner/printer/xpyun/xpyun.go +++ b/business/partner/printer/xpyun/xpyun.go @@ -31,17 +31,18 @@ func init() { 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) { +func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, sn, copies, voiceType, msgContent string) (printerStatus *partner.PrinterStatus, err error) { if sn != "" { if globals.EnableStoreWrite { if utils.Str2Int(copies) < 0 || utils.Str2Int(copies) > 3 { copies = "1" } + globals.SugarLogger.Debugf("printMsg voiceType====%s", voiceType) printOrderID, err1 := api.XpyunAPI.Print(&xpyunapi.PrintRequest{ Sn: sn, Content: msgContent, Copies: utils.Str2Int(copies), - Voice: xpyunapi.VoicePlayOrder, + Voice: utils.Str2Int(voiceType), Mode: xpyunapi.ModeCheckYes, ExpiresIn: xpyunapi.ExpiresInDefault, }) @@ -115,7 +116,7 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, } count := 0 for { - printerStatus, err := c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content) + printerStatus, err := c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, utils.Int2Str(xpyunapi.VoicePlayOrder), content) if (store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2) && count < 1 { count += 1 continue @@ -130,7 +131,27 @@ func (c *PrinterHandler) PrintStore(ctx *jxcontext.Context, store *model.Store, } 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 + if len(order.Skus) == 0 { + return + } + content := "" + voiceType := "" + if printType == model.YES { // 取消订单 + voiceType = utils.Int2Str(xpyunapi.VoiceCancelOrder) + } else { // 售后订单 + voiceType = utils.Int2Str(xpyunapi.VoiceUserChargeback) + } + if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 { + content = c.getCancelOrRefundOrderContent(order, printType, storeDetail) + } else { + content = c.getCancelOrRefundOrderContentBig(order, printType, storeDetail) + } + globals.SugarLogger.Debugf("PrintCancelOrRefundOrder content=====%s", content) + if content == "" { + return nil, nil + } + + return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, voiceType, content) } func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, sn, id2 string) (err error) { @@ -151,7 +172,7 @@ func (c *PrinterHandler) SetSound(ctx *jxcontext.Context, sn, id2, sound string) return err } -// 正常打印模板 +// 新订单正常尺寸打印模板 func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) { expectedDeliveryTime := order.ExpectedDeliveredTime if utils.IsTimeZero(expectedDeliveryTime) { @@ -161,11 +182,14 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin if order.VendorID == model.VendorIDEBAI { getCode = fmt.Sprintf("饿百取货码:%s", jxutils.GetEbaiOrderGetCode(order)) } + if order.BuyerComment == "" { + order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!" + } orderParams := []interface{}{} orderFmt := `` if storeDetail != nil { if storeDetail.BrandIsPrint == model.NO { - orderFmt += `
%s
\n` + orderFmt += `%s` if order.VendorOrgCode == "34665" { orderParams = append(orderParams, globals.StoreNameEbai2) } else { @@ -175,21 +199,20 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin } orderFmt += ` ` + xpyunapi.StrRepeat("-", 32) + ` -
下单时间: %s -
预计送达: %s -
客户姓名: %s -
客户电话: %s -
订单编号: %s -
%s: #%d -%s" -` + getCode + ` -` + xpyunapi.StrRepeat("-", 32) + ` +下单时间: %s +预计送达: %s +客户姓名: %s +客户电话: %s
+订单编号: %s
+%s#%d +%s +` + getCode + + xpyunapi.StrRepeat("-", 32) + ` 客户地址: %s +` + xpyunapi.StrRepeat("-", 32) + `客户备注: %s ` + xpyunapi.StrRepeat("-", 32) + ` -
客户备注: %s -` + xpyunapi.StrRepeat("-", 32) + ` -
商品列表
-商品名` + xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计
+商品列表 +商品名` + xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计 ` + xpyunapi.StrRepeat("-", 32) + ` ` orderParams = append(orderParams, @@ -209,14 +232,16 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice)) } orderFmt += ` -共%d种%d件商品
-实际支付: %s元
+共%d种%d件商品 +实际支付: %s ` - orderFmt += `

` - orderFmt += xpyunapi.StrRepeat("-", 14) + "#23完" + xpyunapi.StrRepeat("-", 14) - orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice)) + orderFmt += `
` + orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完" + xpyunapi.StrRepeat("-", 14) + `
` + orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq) 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) { @@ -226,11 +251,14 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st if order.VendorID == model.VendorIDEBAI { getCode = fmt.Sprintf("饿百取货码:%s", jxutils.GetEbaiOrderGetCode(order)) } + if order.BuyerComment == "" { + order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!" + } orderParams := []interface{}{} orderFmt := `` if storeDetail != nil { if storeDetail.BrandIsPrint == model.NO { - orderFmt += `
%s
\n` + orderFmt += `%s` if order.VendorOrgCode == "34665" { orderParams = append(orderParams, globals.StoreNameEbai2) } else { @@ -240,21 +268,21 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st } orderFmt += ` ` + xpyunapi.StrRepeat("-", 32) + ` -
下单时间: %s
-
预计送达: %s
-
客户姓名: %s
-
客户电话: %s
-
订单编号: %s
-
%s: #%d
-%s" -` + getCode + ` +下单时间: %s +预计送达: %s +客户姓名: %s +客户电话: %s
+订单编号: %s
+%s#%d +%s +` + getCode + + xpyunapi.StrRepeat("-", 32) + ` +客户地址: %s +` + xpyunapi.StrRepeat("-", 32) + `客户备注: %s ` + xpyunapi.StrRepeat("-", 32) + ` -客户地址: %s
-` + xpyunapi.StrRepeat("-", 32) + ` -
客户备注: %s
-` + xpyunapi.StrRepeat("-", 32) + ` -
商品列表 ` + xpyunapi.StrRepeat("-", 6) + `
-商品名` + xpyunapi.StrRepeat("-", 2) + `数量` + xpyunapi.StrRepeat("-", 3) + `单价` + xpyunapi.StrRepeat("-", 5) + `小计
" +商品列表 +商品名` + xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计
+` + xpyunapi.StrRepeat("-", 32) + "" + ` ` orderParams = append(orderParams, utils.Time2Str(order.OrderCreatedAt), @@ -272,12 +300,98 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st for _, sku := range order.Skus { orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice)) } - orderFmt += ` -共%d种%d件商品
-实际支付: %s元
-` + xpyunapi.StrRepeat("-", 2) + ` + orderFmt += `共%d种%d件商品 +实际支付: %s ` - orderFmt += `

` + orderFmt += `
` + orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完
" + xpyunapi.StrRepeat("-", 14) + `
` + orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq) + return fmt.Sprintf(orderFmt, orderParams...) +} + +//退货/取消订单 正常尺寸模板 +func (c *PrinterHandler) getCancelOrRefundOrderContent(order *model.GoodsOrder, printType int, storeDetail *dao.StoreDetail) (content string) { + expectedDeliveryTime := order.ExpectedDeliveredTime + if utils.IsTimeZero(expectedDeliveryTime) { + expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) + } + var orderParams []interface{} + orderFmt := `` + if storeDetail != nil { + if storeDetail.BrandIsPrint == model.NO { + orderFmt += `%s` + if order.VendorOrgCode == "34665" { + orderParams = append(orderParams, globals.StoreNameEbai2) + } else { + orderParams = append(orderParams, storeDetail.BrandName) + } + } + } + title := `` + if printType == model.YES { // 取消订单 + title = `取消订单详情` + } else { // 售后订单 + title = `退款订单详情` + } + + orderFmt += + xpyunapi.StrRepeat("-", 32) + ` +下单时间: %s +订单编号: %s +%s#%d +` + title + orderParams = append(orderParams, + utils.Time2Str(order.OrderCreatedAt), + order.VendorOrderID, + jxutils.GetVendorName(order.VendorID), + order.OrderSeq, + ) + orderFmt += xpyunapi.StrRepeat("-", 32) + orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice)) + return fmt.Sprintf(orderFmt, orderParams...) +} + +//退货/取消订单 大尺寸模板 +func (c *PrinterHandler) getCancelOrRefundOrderContentBig(order *model.GoodsOrder, printType int, storeDetail *dao.StoreDetail) (content string) { + expectedDeliveryTime := order.ExpectedDeliveredTime + if utils.IsTimeZero(expectedDeliveryTime) { + expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) + } + var orderParams []interface{} + orderFmt := `` + if storeDetail != nil { + if storeDetail.BrandIsPrint == model.NO { + orderFmt += `%s` + if order.VendorOrgCode == "34665" { + orderParams = append(orderParams, globals.StoreNameEbai2) + } else { + orderParams = append(orderParams, storeDetail.BrandName) + } + } + } + + // 加载用户取消订单售后单 + + title := `` + if printType == model.YES { // 取消订单 + title = `取消订单详情` + } else { // 售后订单 + title = `退款订单详情` + } + + orderFmt += + xpyunapi.StrRepeat("-", 32) + ` +下单时间: %s +订单编号: %s
+%s#%d +` + title + orderParams = append(orderParams, + utils.Time2Str(order.OrderCreatedAt), + order.VendorOrderID, + jxutils.GetVendorName(order.VendorID), + order.OrderSeq, + ) + orderFmt += xpyunapi.StrRepeat("-", 32) orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice)) return fmt.Sprintf(orderFmt, orderParams...) }