This commit is contained in:
邹宗楠
2022-08-11 16:38:20 +08:00
parent 5c8bc4610e
commit 75bd8fb887
2 changed files with 184 additions and 157 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"git.rosy.net.cn/baseapi/platformapi/jxprintapi" "git.rosy.net.cn/baseapi/platformapi/jxprintapi"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" "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"
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
@@ -13,8 +12,6 @@ import (
"git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
"regexp" "regexp"
"strings"
"time"
) )
var ( var (
@@ -88,151 +85,153 @@ func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *p
} }
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) {
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) // expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
} // }
orderParams := []interface{}{} // orderParams := []interface{}{}
getCode := "" // getCode := ""
if order.VendorID == model.VendorIDEBAI { // if order.VendorID == model.VendorIDEBAI {
getCode = fmt.Sprintf("<b>饿百取货码:%s</b><br><br>\n", jxutils.GetEbaiOrderGetCode(order)) // getCode = fmt.Sprintf("<b>饿百取货码:%s</b><br><br>\n", jxutils.GetEbaiOrderGetCode(order))
} // }
orderFmt := `` // orderFmt := ``
if storeDetail != nil { // if storeDetail != nil {
if storeDetail.BrandIsPrint == model.NO { // if storeDetail.BrandIsPrint == model.NO {
orderFmt += ` // orderFmt += `
<sound>您有新订单啦!</sound><br> // <sound>您有新订单啦!</sound><br>
<center><b>%s</b></center><br><br> // <center><b>%s</b></center><br><br>
` // `
if order.VendorOrgCode == "34665" { // if order.VendorOrgCode == "34665" {
orderParams = append(orderParams, globals.StoreNameEbai2) // orderParams = append(orderParams, globals.StoreNameEbai2)
} else { // } else {
orderParams = append(orderParams, storeDetail.BrandName) // orderParams = append(orderParams, storeDetail.BrandName)
} // }
} // }
} // }
orderFmt += ` // orderFmt += `
<center>手机买菜上京西</center><br> //<center>手机买菜上京西</center><br>
<center>极速到家送惊喜</center><br> //<center>极速到家送惊喜</center><br>
--------------------------------<br> //--------------------------------<br>
下单时间: %s<br> //下单时间: %s<br>
预计送达: %s<br> //预计送达: %s<br>
订单编号: %s<br> //订单编号: %s<br>
<br> //<br>
//
<b>%s#%d</b><br> //<b>%s#%d</b><br>
<qrc>%s</qrc><br> //<qrc>%s</qrc><br>
` + getCode + //` + getCode +
`客户: %s<br> // `客户: %s<br>
电话: %s<br> //电话: %s<br>
地址: %s<br> //地址: %s<br>
<br> //<br>
客户备注: <br> //客户备注: <br>
<b>%s</b><br> //<b>%s</b><br>
<br> //<br>
//
<br> //<br>
商品明细: <br> //商品明细: <br>
品名 数量 单价 小计<br> //品名 数量 单价 小计<br>
--------------------------------<br>` //--------------------------------<br>`
// <BOLD>实际支付:</BOLD>%s<BR> // // <BOLD>实际支付:</BOLD>%s<BR>
orderParams = append(orderParams, // orderParams = append(orderParams,
utils.Time2Str(order.OrderCreatedAt), // utils.Time2Str(order.OrderCreatedAt),
utils.Time2Str(expectedDeliveryTime), // utils.Time2Str(expectedDeliveryTime),
order.VendorOrderID, // order.VendorOrderID,
jxutils.GetVendorName(order.VendorID), // jxutils.GetVendorName(order.VendorID),
order.OrderSeq, // order.OrderSeq,
order.VendorOrderID, // order.VendorOrderID,
order.ConsigneeName, // order.ConsigneeName,
order.ConsigneeMobile, // order.ConsigneeMobile,
order.ConsigneeAddress, // order.ConsigneeAddress,
order.BuyerComment, // order.BuyerComment,
// jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), // // jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice),
) // )
//
for _, sku := range order.Skus { // for _, sku := range order.Skus {
orderFmt += `%s<br>` // orderFmt += `%s<br>`
orderFmt += `%8s%10s%10s<br>` // orderFmt += `%8s%10s%10s<br>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))) // orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
} // }
orderFmt += `<br> // orderFmt += `<br>
共%d种%d件商品 //共%d种%d件商品
<br> //<br>
--------------------------------<br> //--------------------------------<br>
<center><hb>商品质量问题请联系:</hb></center><br> //<center><hb>商品质量问题请联系:</hb></center><br>
<center><hb>%s:%s</hb></center><br> //<center><hb>%s:%s</hb></center><br>
<br> //<br>
更多信息请关注官方微信: %s<br> //更多信息请关注官方微信: %s<br>
<br> //<br>
<br> //<br>
--------------------------------<br> //--------------------------------<br>
--------------------------------<br> //--------------------------------<br>
<br> //<br>
` //`
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, "京西菜市") // orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, "京西菜市")
return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...) // return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...)
return ""
} }
func (c *PrinterHandler) getOrderContentByTemplate(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) { func (c *PrinterHandler) getOrderContentByTemplate(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) {
orderFmt := "" //orderFmt := ""
if storeDetail != nil { //if storeDetail != nil {
//开头加上语音 // //开头加上语音
if storeDetail.PrinterSound != "" { // if storeDetail.PrinterSound != "" {
orderFmt += "<sound>" + storeDetail.PrinterSound + "</sound><br>" // orderFmt += "<sound>" + storeDetail.PrinterSound + "</sound><br>"
} // }
} //}
//把带有${}的变量换成实际值 ////把带有${}的变量换成实际值
template := storeDetail.PrinterTemplate //template := storeDetail.PrinterTemplate
regexpValues := regexpPrint.FindAllStringSubmatch(template, -1) //regexpValues := regexpPrint.FindAllStringSubmatch(template, -1)
for _, v := range regexpValues { //for _, v := range regexpValues {
switch v[0] { // switch v[0] {
case "${下单时间}": // case "${下单时间}":
template = strings.ReplaceAll(template, v[0], utils.Time2Str(order.OrderCreatedAt)) // template = strings.ReplaceAll(template, v[0], utils.Time2Str(order.OrderCreatedAt))
case "${预计送达}": // case "${预计送达}":
expectedDeliveryTime := order.ExpectedDeliveredTime // expectedDeliveryTime := order.ExpectedDeliveredTime
if utils.IsTimeZero(expectedDeliveryTime) { // if utils.IsTimeZero(expectedDeliveryTime) {
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) // expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
} // }
template = strings.ReplaceAll(template, v[0], utils.Time2Str(expectedDeliveryTime)) // template = strings.ReplaceAll(template, v[0], utils.Time2Str(expectedDeliveryTime))
case "${订单号}": // case "${订单号}":
template = strings.ReplaceAll(template, v[0], order.VendorOrderID) // template = strings.ReplaceAll(template, v[0], order.VendorOrderID)
case "${平台名}": // case "${平台名}":
template = strings.ReplaceAll(template, v[0], jxutils.GetVendorName(order.VendorID)) // template = strings.ReplaceAll(template, v[0], jxutils.GetVendorName(order.VendorID))
case "${订单序号}": // case "${订单序号}":
template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.OrderSeq)) // template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.OrderSeq))
case "${客户名}": // case "${客户名}":
template = strings.ReplaceAll(template, v[0], order.ConsigneeName) // template = strings.ReplaceAll(template, v[0], order.ConsigneeName)
case "${客户电话}": // case "${客户电话}":
template = strings.ReplaceAll(template, v[0], order.ConsigneeMobile) // template = strings.ReplaceAll(template, v[0], order.ConsigneeMobile)
case "${客户地址}": // case "${客户地址}":
template = strings.ReplaceAll(template, v[0], order.ConsigneeAddress) // template = strings.ReplaceAll(template, v[0], order.ConsigneeAddress)
case "${备注}": // case "${备注}":
template = strings.ReplaceAll(template, v[0], order.BuyerComment) // template = strings.ReplaceAll(template, v[0], order.BuyerComment)
case "${商品种数}": // case "${商品种数}":
template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.SkuCount)) // template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.SkuCount))
case "${商品件数}": // case "${商品件数}":
template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.GoodsCount)) // template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.GoodsCount))
case "${门店名}": // case "${门店名}":
template = strings.ReplaceAll(template, v[0], order.StoreName) // template = strings.ReplaceAll(template, v[0], order.StoreName)
case "${门店电话}": // case "${门店电话}":
template = strings.ReplaceAll(template, v[0], storeTel) // template = strings.ReplaceAll(template, v[0], storeTel)
case "${商品明细}": // case "${商品明细}":
skus := "" // skus := ""
skuParams := []interface{}{} // skuParams := []interface{}{}
for i := 0; i < len(order.Skus); i++ { // for i := 0; i < len(order.Skus); i++ {
skus += "%s<br>" // skus += "%s<br>"
skus += "%8s%10s%10s<br><br>" // skus += "%8s%10s%10s<br><br>"
skuParams = append(skuParams, order.Skus[i].SkuName) // skuParams = append(skuParams, order.Skus[i].SkuName)
skuParams = append(skuParams, "x"+utils.Int2Str(order.Skus[i].Count)) // skuParams = append(skuParams, "x"+utils.Int2Str(order.Skus[i].Count))
skuParams = append(skuParams, jxutils.IntPrice2StandardCurrencyString(order.Skus[i].SalePrice)) // skuParams = append(skuParams, jxutils.IntPrice2StandardCurrencyString(order.Skus[i].SalePrice))
skuParams = append(skuParams, jxutils.IntPrice2StandardCurrencyString(order.Skus[i].SalePrice*int64(order.Skus[i].Count))) // skuParams = append(skuParams, jxutils.IntPrice2StandardCurrencyString(order.Skus[i].SalePrice*int64(order.Skus[i].Count)))
} // }
skus = fmt.Sprintf(skus, skuParams...) // skus = fmt.Sprintf(skus, skuParams...)
template = strings.ReplaceAll(template, v[0], skus) // template = strings.ReplaceAll(template, v[0], skus)
} // }
} //}
orderFmt += template //orderFmt += template
return strings.Replace(orderFmt, "\n", "", -1) //return strings.Replace(orderFmt, "\n", "", -1)
return ""
} }
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) { func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
@@ -241,15 +240,15 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store,
return return
} }
printData := ManagerOrderAndStore(order, store.Tel1, storeDetail) printData := ManagerOrderAndStore(order, store.Tel1, storeDetail)
printData[BigFont] = "small" //printData[BigFont] = "small"
if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 { //if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
printData[BigFont] = "big" // printData[BigFont] = "big"
} //}
// 打印次数 //// 打印次数
printData[PrintNumber] = utils.Int2Str(model.YES) //printData[PrintNumber] = utils.Int2Str(model.YES)
if store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2 { //if store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2 {
printData[PrintNumber] = utils.Int2Str(2) // printData[PrintNumber] = utils.Int2Str(2)
} //}
printData[AppID] = "1000" // 菜市应用 printData[AppID] = "1000" // 菜市应用
printData[OrderStatus] = utils.Int2Str(order.Status) // 订单状态 printData[OrderStatus] = utils.Int2Str(order.Status) // 订单状态
printData[WayBillStatus] = order.VendorStatus // 运单状态 printData[WayBillStatus] = order.VendorStatus // 运单状态

View File

@@ -38,8 +38,16 @@ const (
BigFont = "bigFont" // 是否为大字体 BigFont = "bigFont" // 是否为大字体
PrintNumber = "printNumber" // 打印次数 PrintNumber = "printNumber" // 打印次数
AppID = "appId" // 应用id AppID = "appId" // 应用id
OrderStatus = "orderStatus" // 订单状态 // 状态对应打印设置的变化
WayBillStatus = "wayBillStatus" // 单状态 OrderStatus = "orderStatus" // 单状态
WayBillStatus = "wayBillStatus" // 运单状态
StoreStatusPrint = "storeStatus" // 门店状态
RiderVendorIdPrint = "riderVendorId" // 骑手所属平台id
RiderNamePrint = "riderName" // 骑手名称
RiderPhonePrint = "riderPhone" // 骑手电话
RejectionReasonPrint = "rejectionReason" // 拒收原因
CustcareRefundReasonPrint = "custcareRefundReason" // 客服退款理由
EnterTheStorePrint = "enterTheStore" // 进店
) )
type SkuListPrintOrder struct { type SkuListPrintOrder struct {
@@ -50,7 +58,27 @@ type SkuListPrintOrder struct {
Upc string `json:"upc"` // 条形码 Upc string `json:"upc"` // 条形码
} }
// ManagerOrderAndStore 京西云参数组装 // ManagerStore 送达提示数据组装
func ManagerStore(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) map[string]string {
printOrder := make(map[string]string, 0)
// 获取品牌名称
if storeDetail != nil && storeDetail.BrandIsPrint == model.NO {
if order.VendorOrgCode == "34665" {
printOrder[EBailOrderNo] = globals.StoreNameEbai2
} else {
printOrder[EBailOrderNo] = storeDetail.BrandName
}
}
printOrder[VendOrID] = utils.Int2Str(order.VendorID)
printOrder[VendorName] = jxutils.GetVendorName(order.VendorID)
printOrder[StoreName] = order.StoreName
printOrder[StoreTel] = storeTel
printOrder[OfficialName] = globals.StoreName
return printOrder
}
// ManagerOrderAndStore 京西云参数组装(订单参数)
func ManagerOrderAndStore(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) map[string]string { func ManagerOrderAndStore(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) map[string]string {
printOrder := make(map[string]string, 0) printOrder := make(map[string]string, 0)
skuList := make([]*SkuListPrintOrder, 0, 0) skuList := make([]*SkuListPrintOrder, 0, 0)