diff --git a/business/partner/partner_printer.go b/business/partner/partner_printer.go index f0ea317db..51a413c74 100644 --- a/business/partner/partner_printer.go +++ b/business/partner/partner_printer.go @@ -19,6 +19,11 @@ const ( PrintResultNoPrinter = 1 // 没有配置网络打印机 ) +const ( + PrinterFontSizeNormal = int8(0)//正常大小 + PrinterFontSizeBig = int8(1)//两倍大小 +) + var ( PrinterStatusName = map[int]string{ PrinterStatusUnknown: "未知", diff --git a/business/partner/printer/feie/feie.go b/business/partner/printer/feie/feie.go index 9179cbdaa..c0e22bb27 100644 --- a/business/partner/printer/feie/feie.go +++ b/business/partner/printer/feie/feie.go @@ -101,6 +101,80 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...) } +func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string) (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("饿百取货码:%s

\n", jxutils.GetEbaiOrderGetCode(order)) + } + orderFmt := ` +%s

+手机买菜上京西
+极速到家送惊喜
+--------------------------------
+下单时间: %s


+预计送达: %s


+订单编号: %s
+
+ +%s#%d

+%s
+` + getCode + + `客户: %s
+电话: %s
+地址: %s
+
+客户备注:
+%s
+
+ +实际支付:%s
+
+商品明细:
+品名数量单价小计
+--------------------------------
` + orderParams := []interface{}{ + globals.StoreName, + 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
` + orderFmt += `%s %s %s

` + orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice*int64(sku.Count))) + } + orderFmt += `
+共%d种%d件商品 +
+--------------------------------
+商品质量问题请联系:
+%s:%s

+
+更多信息请关注官方微信: %s
+
+

+--------------------------------
+--------------------------------
+

+` + // http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk + orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, globals.StoreName) + return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...) +} + func (c *PrinterHandler) GetVendorID() int { return model.VendorIDFeiE } @@ -136,7 +210,12 @@ 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) + content := "" + if store.PrinterFontSize == partner.PrinterFontSizeBig { + content = c.getOrderContentBig(order, store.Tel1) + } else { + content = c.getOrderContent(order, store.Tel1) + } return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content) } diff --git a/business/partner/printer/feie/feie_test.go b/business/partner/printer/feie/feie_test.go index 03800c3b7..d4088eab6 100644 --- a/business/partner/printer/feie/feie_test.go +++ b/business/partner/printer/feie/feie_test.go @@ -18,16 +18,17 @@ func init() { testinit.Init() } -func TestGetCityShops(t *testing.T) { - orderID := "919864156000342" +func TestPrintMsg(t *testing.T) { + orderID := "910838879000442" vendorID := 0 order, err := partner.CurOrderManager.LoadOrder(orderID, vendorID) if err != nil { t.Fatal(err) } - context := CurPrinterHandler.getOrderContent(order, "mobile") - status, err := CurPrinterHandler.PrintMsg(jxcontext.AdminCtx, "id1", "id2", "title", context) + context := CurPrinterHandler.getOrderContent(order, "13412345678") + //context := CurPrinterHandler.getOrderContentBig(order, "13412345678") + status, err := CurPrinterHandler.PrintMsg(jxcontext.AdminCtx, "218510310", "ztdpveyg", "test", context) t.Log(utils.Format4Output(status, false)) if err != nil { t.Fatal(err) @@ -35,7 +36,7 @@ func TestGetCityShops(t *testing.T) { } func TestRegisterPrinter(t *testing.T) { - newID1, newID2, err := CurPrinterHandler.RegisterPrinter(jxcontext.AdminCtx, "id1", "id2", "title") + newID1, newID2, err := CurPrinterHandler.RegisterPrinter(jxcontext.AdminCtx, "218510310", "ztdpveyg", "title") t.Log(newID1 + "," + newID2) if err != nil { t.Fatal(err) diff --git a/business/partner/printer/xiaowm/xiaowm.go b/business/partner/printer/xiaowm/xiaowm.go index 23a86639a..cc6ef46fb 100644 --- a/business/partner/printer/xiaowm/xiaowm.go +++ b/business/partner/printer/xiaowm/xiaowm.go @@ -59,9 +59,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin * 客户备注: * %s* -* 实际支付: %s* -* 商品明细: * 品名 数量 单价 小计 --------------------------------* @@ -105,6 +103,80 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin return content } +func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string) (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("饿百取货码:%s**\n", jxutils.GetEbaiOrderGetCode(order)) + } + buyerComment := order.BuyerComment + if buyerComment == "" { + buyerComment = " " + } + orderFmt := ` + %s** + 手机买菜上京西* + 极速到家送惊喜* +------------------------------* +下单时间: %s** +预计送达: %s** +订单编号: %s* +* +%s\#%d* +%s* +` + getCode + +`客户: %s* +电话: %s* +地址: %s* +* +客户备注: * +%s* +实际支付: %s* +商品明细: * +品名数量单价小计* +--------------------------------* +` + orderParams := []interface{}{ + globals.StoreName, + utils.Time2Str(order.OrderCreatedAt), + utils.Time2Str(expectedDeliveryTime), + order.VendorOrderID, + jxutils.GetVendorName(order.VendorID), + order.OrderSeq, + order.VendorOrderID, + order.ConsigneeName, + order.ConsigneeMobile, + order.ConsigneeAddress, + buyerComment, + jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), + } + for _, sku := range order.Skus { + orderFmt += `%s*` + orderFmt += `%s %s %s*` + orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice*int64(sku.Count))) + } + orderFmt += ` +共%d种%d件商品* +--------------------------------* +商品质量问题请联系:* +%s:%s* +* +更多信息请关注官方微信: %s* +-------------------------------- +-------------------------------- +** +` + // http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk + orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, globals.StoreName) + content = fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), escapeString4Printer(orderParams)...) + // globals.SugarLogger.Debugf("xiaowm orderParams:%s\n", utils.Format4Output(orderParams, false)) + // globals.SugarLogger.Debugf("xiaowm getOrderContent:%s\n", content) + return content +} + func (c *PrinterHandler) getOrderContent2(order *model.GoodsOrder, storeTel string) (content string) { expectedDeliveryTime := order.ExpectedDeliveredTime if utils.IsTimeZero(expectedDeliveryTime) { @@ -223,7 +295,11 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, if isV500(store.PrinterSN) { content = c.getOrderContent2(order, store.Tel1) } else { - content = c.getOrderContent(order, store.Tel1) + if store.PrinterFontSize == partner.PrinterFontSizeBig { + content = c.getOrderContentBig(order, store.Tel1) + } else { + content = c.getOrderContent(order, store.Tel1) + } } return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content) } diff --git a/business/partner/printer/xiaowm/xiaowm_test.go b/business/partner/printer/xiaowm/xiaowm_test.go new file mode 100644 index 000000000..50d62c110 --- /dev/null +++ b/business/partner/printer/xiaowm/xiaowm_test.go @@ -0,0 +1,44 @@ +package xiaowm + +import ( + "testing" + + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + + "git.rosy.net.cn/baseapi/utils" + + "git.rosy.net.cn/jx-callback/business/partner" + + _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" + _ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" + "git.rosy.net.cn/jx-callback/globals/testinit" +) + +func init() { + testinit.Init() +} + +func TestPrintMsg(t *testing.T) { + orderID := "910838879000442" + vendorID := 0 + order, err := partner.CurOrderManager.LoadOrder(orderID, vendorID) + if err != nil { + t.Fatal(err) + } + + // context := CurPrinterHandler.getOrderContent(order, "13412345678") + context := CurPrinterHandler.getOrderContentBig(order, "13412345678") + status, err := CurPrinterHandler.PrintMsg(jxcontext.AdminCtx, "7JizmSyiXNzkggaqU", "177f213277dd842ba2b53f6c926a48ea", "test", context) + t.Log(utils.Format4Output(status, false)) + if err != nil { + t.Fatal(err) + } +} + +func TestRegisterPrinter(t *testing.T) { + newID1, newID2, err := CurPrinterHandler.RegisterPrinter(jxcontext.AdminCtx, "7JizmSyiXNzkggaqU", "", "title") + t.Log(newID1 + "," + newID2) + if err != nil { + t.Fatal(err) + } +} diff --git a/business/partner/printer/yilianyun/yilianyun.go b/business/partner/printer/yilianyun/yilianyun.go index 744b7c877..47bddd467 100644 --- a/business/partner/printer/yilianyun/yilianyun.go +++ b/business/partner/printer/yilianyun/yilianyun.go @@ -95,6 +95,74 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin return strings.Replace(fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...), "\\n", "\r\n", -1) } +func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string) (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("饿百取货码:%s\\n\n", jxutils.GetEbaiOrderGetCode(order)) + } + orderFmt := ` +
%s
\n\n +
手机买菜上京西
+
极速到家送惊喜
\n +-------------------------------- +下单时间: %s\n\n +预计送达: %s\n\n +订单编号: %s\n +\n +%s#%d\n\n +%s +` + getCode + `\n +客户: %s\n +电话: %s\n +地址: %s\n +\n +客户备注: \n +%s\n +\n +实际支付:%s\n +\n +商品明细: \n +品名数量单价小计\n +--------------------------------\n` + orderParams := []interface{}{ + globals.StoreName, + 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\n` + orderFmt += `%s %s %s\n\n` + orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice*int64(sku.Count))) + } + orderFmt += `\n +共%d种%d件商品 +\n +--------------------------------\n +
商品质量问题请联系:
+
%s:%s
\n +更多信息请关注官方微信: %s\n +--------------------------------\n +--------------------------------\n +` + // http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk + orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, globals.StoreName) + return strings.Replace(fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...), "\\n", "\r\n", -1) +} + func (c *PrinterHandler) GetVendorID() int { return model.VendorIDYiLianYun } @@ -135,7 +203,12 @@ func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, machineCode, p 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) + content := "" + if store.PrinterFontSize == partner.PrinterFontSizeBig { + content = c.getOrderContentBig(order, store.Tel1) + } else { + content = c.getOrderContent(order, store.Tel1) + } return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content) } diff --git a/business/partner/printer/yilianyun/yilianyun_test.go b/business/partner/printer/yilianyun/yilianyun_test.go new file mode 100644 index 000000000..5b67f77ca --- /dev/null +++ b/business/partner/printer/yilianyun/yilianyun_test.go @@ -0,0 +1,46 @@ +package yilianyun + +import ( + "testing" + + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + + "git.rosy.net.cn/baseapi/utils" + + "git.rosy.net.cn/jx-callback/business/partner" + + _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" + _ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" + "git.rosy.net.cn/jx-callback/globals/testinit" + "git.rosy.net.cn/jx-callback/globals/api" +) + +func init() { + testinit.Init() + api.YilianyunAPI.SetToken("8d54951744984b7a8908251c3063b445") +} + +func TestPrintMsg(t *testing.T) { + orderID := "910838879000442" + vendorID := 0 + order, err := partner.CurOrderManager.LoadOrder(orderID, vendorID) + if err != nil { + t.Fatal(err) + } + + // context := CurPrinterHandler.getOrderContent(order, "13412345678") + context := CurPrinterHandler.getOrderContentBig(order, "13412345678") + status, err := CurPrinterHandler.PrintMsg(jxcontext.AdminCtx, "4004600675", "fem2ukwvduik", "test", context) + t.Log(utils.Format4Output(status, false)) + if err != nil { + t.Fatal(err) + } +} + +func TestRegisterPrinter(t *testing.T) { + newID1, newID2, err := CurPrinterHandler.RegisterPrinter(jxcontext.AdminCtx, "4004600675", "fem2ukwvduik", "title") + t.Log(newID1 + "," + newID2) + if err != nil { + t.Fatal(err) + } +} diff --git a/business/partner/printer/zhongwu/zhongwu.go b/business/partner/printer/zhongwu/zhongwu.go index 42dd9a148..f8adc7115 100644 --- a/business/partner/printer/zhongwu/zhongwu.go +++ b/business/partner/printer/zhongwu/zhongwu.go @@ -96,6 +96,74 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...) } +func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string) (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("饿百取货码:%s\n", jxutils.GetEbaiOrderGetCode(order)) + } + orderFmt := ` +%s +手机买菜上京西 +极速到家送惊喜 +******************************** +下单时间: %s +预计送达: %s +订单编号: %s + +%s#%d +%s +` + getCode + ` +客户: %s +电话: %s +地址: %s + +客户备注: +%s + +实际支付:%s + +商品明细: +品名数量单价小计 +********************************` + orderParams := []interface{}{ + globals.StoreName, + 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` + orderFmt += `%s %s %s` + orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice*int64(sku.Count))) + } + orderFmt += ` +共%d种%d件商品 + +******************************** +

商品质量问题请联系:

+

%s:%s

+更多信息请关注官方微信: %s +******************************** +******************************** +` + // http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk + orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, globals.StoreName) + return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...) +} + func (c *PrinterHandler) GetVendorID() int { return model.VendorIDZhongWu } @@ -128,7 +196,12 @@ func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, deviceID, devi func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) { globals.SugarLogger.Debugf("zhongwu PrintOrderByOrder orderID:%s", order.VendorOrderID) - content := c.getOrderContent(order, store.Tel1) + content := "" + if store.PrinterFontSize == partner.PrinterFontSizeBig { + content = c.getOrderContentBig(order, store.Tel1) + } else { + content = c.getOrderContent(order, store.Tel1) + } return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content) } diff --git a/business/partner/printer/zhongwu/zhongwu_test.go b/business/partner/printer/zhongwu/zhongwu_test.go new file mode 100644 index 000000000..6db9d9805 --- /dev/null +++ b/business/partner/printer/zhongwu/zhongwu_test.go @@ -0,0 +1,44 @@ +package zhongwu + +import ( + "testing" + + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + + "git.rosy.net.cn/baseapi/utils" + + "git.rosy.net.cn/jx-callback/business/partner" + + _ "git.rosy.net.cn/jx-callback/business/jxcallback/orderman" + _ "git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch" + "git.rosy.net.cn/jx-callback/globals/testinit" +) + +func init() { + testinit.Init() +} + +func TestPrintMsg(t *testing.T) { + orderID := "910838879000442" + vendorID := 0 + order, err := partner.CurOrderManager.LoadOrder(orderID, vendorID) + if err != nil { + t.Fatal(err) + } + + // context := CurPrinterHandler.getOrderContent(order, "13412345678") + context := CurPrinterHandler.getOrderContentBig(order, "13412345678") + status, err := CurPrinterHandler.PrintMsg(jxcontext.AdminCtx, "12364142", "v7rvjv9b", "test", context) + t.Log(utils.Format4Output(status, false)) + if err != nil { + t.Fatal(err) + } +} + +func TestRegisterPrinter(t *testing.T) { + newID1, newID2, err := CurPrinterHandler.RegisterPrinter(jxcontext.AdminCtx, "12364142", "v7rvjv9b", "title") + t.Log(newID1 + "," + newID2) + if err != nil { + t.Fatal(err) + } +}