增加打印大字体的功能
This commit is contained in:
@@ -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("<FS2>饿百取货码:%s</FS2>\\n\n", jxutils.GetEbaiOrderGetCode(order))
|
||||
}
|
||||
orderFmt := `
|
||||
<FS2><center>%s</center></FS2>\n\n
|
||||
<center>手机买菜上京西</center>
|
||||
<center>极速到家送惊喜</center>\n
|
||||
--------------------------------
|
||||
<FS2>下单时间: %s\n\n</FS2>
|
||||
<FS2>预计送达: %s\n\n</FS2>
|
||||
<FS2>订单编号: %s\n</FS2>
|
||||
\n
|
||||
<FS2>%s#%d</FS2>\n\n
|
||||
<QR>%s</QR>
|
||||
` + getCode + `\n
|
||||
<FS2>客户: %s\n</FS2>
|
||||
<FS2>电话: %s\n</FS2>
|
||||
<FS2>地址: %s\n</FS2>
|
||||
\n
|
||||
<FS2>客户备注: \n</FS2>
|
||||
<FS2>%s</FS2>\n
|
||||
\n
|
||||
<FS2><FB>实际支付:</FB>%s\n</FS2>
|
||||
\n
|
||||
<FS2>商品明细: \n</FS2>
|
||||
<FS2>品名数量单价小计\n</FS2>
|
||||
--------------------------------\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 += `<FS2>%s\n</FS2>`
|
||||
orderFmt += `<FS2>%s %s %s\n\n</FS2>`
|
||||
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice), jxutils.IntPrice2StandardCurrencyString(sku.VendorPrice*int64(sku.Count)))
|
||||
}
|
||||
orderFmt += `\n
|
||||
<FS2><FB>共%d种%d件商品</FB></FS2>
|
||||
\n
|
||||
--------------------------------\n
|
||||
<center><FH2>商品质量问题请联系:</FH2></center>
|
||||
<center><FH2>%s:%s</FH2></center>\n
|
||||
<FS2>更多信息请关注官方微信: %s\n</FS2>
|
||||
--------------------------------\n
|
||||
--------------------------------\n
|
||||
`
|
||||
// <QR>http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk</QR>
|
||||
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)
|
||||
}
|
||||
|
||||
|
||||
46
business/partner/printer/yilianyun/yilianyun_test.go
Normal file
46
business/partner/printer/yilianyun/yilianyun_test.go
Normal file
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user