Merge branch 'jdshop' of e.coding.net:rosydev/jx-callback into jdshop

This commit is contained in:
邹宗楠
2023-03-20 16:18:52 +08:00

View File

@@ -31,17 +31,18 @@ func init() {
func (c *PrinterHandler) GetVendorID() int { func (c *PrinterHandler) GetVendorID() int {
return model.VendorIDXpYun 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 sn != "" {
if globals.EnableStoreWrite { if globals.EnableStoreWrite {
if utils.Str2Int(copies) < 0 || utils.Str2Int(copies) > 3 { if utils.Str2Int(copies) < 0 || utils.Str2Int(copies) > 3 {
copies = "1" copies = "1"
} }
globals.SugarLogger.Debugf("printMsg voiceType====%s", voiceType)
printOrderID, err1 := api.XpyunAPI.Print(&xpyunapi.PrintRequest{ printOrderID, err1 := api.XpyunAPI.Print(&xpyunapi.PrintRequest{
Sn: sn, Sn: sn,
Content: msgContent, Content: msgContent,
Copies: utils.Str2Int(copies), Copies: utils.Str2Int(copies),
Voice: xpyunapi.VoicePlayOrder, Voice: utils.Str2Int(voiceType),
Mode: xpyunapi.ModeCheckYes, Mode: xpyunapi.ModeCheckYes,
ExpiresIn: xpyunapi.ExpiresInDefault, ExpiresIn: xpyunapi.ExpiresInDefault,
}) })
@@ -115,7 +116,7 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store,
} }
count := 0 count := 0
for { 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 { if (store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2) && count < 1 {
count += 1 count += 1
continue 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) { 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) { 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 return err
} }
// 正常打印模板 // 新订单正常尺寸打印模板
func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) { func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
expectedDeliveryTime := order.ExpectedDeliveredTime expectedDeliveryTime := order.ExpectedDeliveredTime
if utils.IsTimeZero(expectedDeliveryTime) { if utils.IsTimeZero(expectedDeliveryTime) {
@@ -161,11 +182,14 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
if order.VendorID == model.VendorIDEBAI { if order.VendorID == model.VendorIDEBAI {
getCode = fmt.Sprintf("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order)) getCode = fmt.Sprintf("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
} }
if order.BuyerComment == "" {
order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
}
orderParams := []interface{}{} orderParams := []interface{}{}
orderFmt := `` orderFmt := ``
if storeDetail != nil { if storeDetail != nil {
if storeDetail.BrandIsPrint == model.NO { if storeDetail.BrandIsPrint == model.NO {
orderFmt += `<BR><C>%s</C></BR>\n` orderFmt += `<C><B>%s</B><C>`
if order.VendorOrgCode == "34665" { if order.VendorOrgCode == "34665" {
orderParams = append(orderParams, globals.StoreNameEbai2) orderParams = append(orderParams, globals.StoreNameEbai2)
} else { } else {
@@ -175,21 +199,20 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
} }
orderFmt += ` orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + ` ` + xpyunapi.StrRepeat("-", 32) + `
<BR><L>下单时间: %s <L>下单时间: %s
<BR><L>预计送达: %s <L>预计送达: %s
<BR><L>客户姓名: %s <L>客户姓名: %s
<BR><L>客户电话: %s <L>客户电话: %s<BR>
<BR><HB>订单编号: %s</HB> <HB>订单编号: %s</HB><BR>
<IMG></IMG><BR><C><B>%s: #%d</B></C> <CB>%s#%d
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C>" <C><QRCODE s=6 e=L l=center>%s</QRCODE></C></CB>
` + getCode + ` ` + getCode +
` + xpyunapi.StrRepeat("-", 32) + ` xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB> <HB>客户地址: %s</HB>
` + xpyunapi.StrRepeat("-", 32) + `客户备注: %s
` + xpyunapi.StrRepeat("-", 32) + ` ` + xpyunapi.StrRepeat("-", 32) + `
<BR>客户备注: %s 商品列表
` + xpyunapi.StrRepeat("-", 32) + ` 商品名` + xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计
<BR>商品列表<BR>
商品名` + xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计<BR>
` + xpyunapi.StrRepeat("-", 32) + ` ` + xpyunapi.StrRepeat("-", 32) + `
` `
orderParams = append(orderParams, 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 += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
} }
orderFmt += ` orderFmt += `
<L>共%d种%d件商品<BR></L> <L>共%d种%d件商品</L>
<L>实际支付: %s元<BR></L> <L>实际支付: %s</L>
` `
orderFmt += `<BR><BR>` orderFmt += `<BR>`
orderFmt += xpyunapi.StrRepeat("-", 14) + "#23完" + xpyunapi.StrRepeat("-", 14) orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完" + xpyunapi.StrRepeat("-", 14) + `<BR>`
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice)) orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq)
return fmt.Sprintf(orderFmt, orderParams...) return fmt.Sprintf(orderFmt, orderParams...)
} }
//新订单大尺寸打印模板
func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) { func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
expectedDeliveryTime := order.ExpectedDeliveredTime expectedDeliveryTime := order.ExpectedDeliveredTime
if utils.IsTimeZero(expectedDeliveryTime) { if utils.IsTimeZero(expectedDeliveryTime) {
@@ -226,11 +251,14 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
if order.VendorID == model.VendorIDEBAI { if order.VendorID == model.VendorIDEBAI {
getCode = fmt.Sprintf("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order)) getCode = fmt.Sprintf("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
} }
if order.BuyerComment == "" {
order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
}
orderParams := []interface{}{} orderParams := []interface{}{}
orderFmt := `` orderFmt := ``
if storeDetail != nil { if storeDetail != nil {
if storeDetail.BrandIsPrint == model.NO { if storeDetail.BrandIsPrint == model.NO {
orderFmt += `<BR><C>%s</C></BR>\n` orderFmt += `<C><B>%s</B><C>`
if order.VendorOrgCode == "34665" { if order.VendorOrgCode == "34665" {
orderParams = append(orderParams, globals.StoreNameEbai2) orderParams = append(orderParams, globals.StoreNameEbai2)
} else { } else {
@@ -240,21 +268,21 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
} }
orderFmt += ` orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + ` ` + xpyunapi.StrRepeat("-", 32) + `
<BR><L>下单时间: %s</BR> <HB><L>下单时间: %s
<BR><L>预计送达: %s</BR> <L>预计送达: %s
<BR><L>客户姓名: %s</BR> <L>客户姓名: %s
<BR><L>客户电话: %s</BR> <L>客户电话: %s</HB><BR>
<BR><HB>订单编号: %s</HB></BR> <HB2>订单编号: %s</HB2><BR>
<IMG></IMG><BR><C><B>%s: #%d</B></BR></C> <CB>%s#%d
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C>" <C><QRCODE s=6 e=L l=center>%s</QRCODE></C></CB>
` + getCode + ` ` + getCode +
xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB>
` + xpyunapi.StrRepeat("-", 32) + `<HB>客户备注: %s
` + xpyunapi.StrRepeat("-", 32) + ` ` + xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB><BR> 商品列表
` + xpyunapi.StrRepeat("-", 32) + ` 商品名` + xpyunapi.StrRepeat(" ", 2) + `数量` + xpyunapi.StrRepeat(" ", 3) + `单价` + xpyunapi.StrRepeat(" ", 5) + `小计</HB>
<BR>客户备注: %s<BR> ` + xpyunapi.StrRepeat("-", 32) + "<HB>" + `
` + xpyunapi.StrRepeat("-", 32) + `
<BR>商品列表 ` + xpyunapi.StrRepeat("-", 6) + `<BR>
商品名` + xpyunapi.StrRepeat("-", 2) + `数量` + xpyunapi.StrRepeat("-", 3) + `单价` + xpyunapi.StrRepeat("-", 5) + `小计<BR>"
` `
orderParams = append(orderParams, orderParams = append(orderParams,
utils.Time2Str(order.OrderCreatedAt), utils.Time2Str(order.OrderCreatedAt),
@@ -272,12 +300,98 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
for _, sku := range order.Skus { for _, sku := range order.Skus {
orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice)) orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
} }
orderFmt += ` orderFmt += `<L>共%d种%d件商品</L>
<L>共%d种%d件商品<BR></L> <L>实际支付: %s</L>
<L>实际支付: %s元<BR></L>
` + xpyunapi.StrRepeat("-", 2) + `
` `
orderFmt += `<BR><BR>` orderFmt += `<BR>`
orderFmt += xpyunapi.StrRepeat("-", 14) + "#%d完</HB>" + xpyunapi.StrRepeat("-", 14) + `<BR>`
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 += `<CB>%s</CB>`
if order.VendorOrgCode == "34665" {
orderParams = append(orderParams, globals.StoreNameEbai2)
} else {
orderParams = append(orderParams, storeDetail.BrandName)
}
}
}
title := ``
if printType == model.YES { // 取消订单
title = `<CB>取消订单详情</CB>`
} else { // 售后订单
title = `<CB>退款订单详情</CB>`
}
orderFmt +=
xpyunapi.StrRepeat("-", 32) + `
<L>下单时间: %s
<HB>订单编号: %s</HB>
<CB>%s#%d</CB>
` + 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 += `<C><B>%s</B><C>`
if order.VendorOrgCode == "34665" {
orderParams = append(orderParams, globals.StoreNameEbai2)
} else {
orderParams = append(orderParams, storeDetail.BrandName)
}
}
}
// 加载用户取消订单售后单
title := ``
if printType == model.YES { // 取消订单
title = `<C><B>取消订单详情</B><C>`
} else { // 售后订单
title = `<C><B>退款订单详情</B><C>`
}
orderFmt +=
xpyunapi.StrRepeat("-", 32) + `
<HB><L>下单时间: %s<HB>
<HB2>订单编号: %s</HB2><BR>
<CB>%s#%d</CB>
` + 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)) orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice))
return fmt.Sprintf(orderFmt, orderParams...) return fmt.Sprintf(orderFmt, orderParams...)
} }