From 75bd8fb887a0de9cde1ebe5d0964898b50449dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 11 Aug 2022 16:38:20 +0800 Subject: [PATCH] 1 --- business/partner/printer/jxprint/jxprint.go | 307 +++++++++--------- .../partner/printer/jxprint/jxprint_const.go | 34 +- 2 files changed, 184 insertions(+), 157 deletions(-) diff --git a/business/partner/printer/jxprint/jxprint.go b/business/partner/printer/jxprint/jxprint.go index 4c77fd7ef..204548cb2 100644 --- a/business/partner/printer/jxprint/jxprint.go +++ b/business/partner/printer/jxprint/jxprint.go @@ -5,7 +5,6 @@ import ( "fmt" "git.rosy.net.cn/baseapi/platformapi/jxprintapi" "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/model" "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/api" "regexp" - "strings" - "time" ) 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) { - expectedDeliveryTime := order.ExpectedDeliveredTime - if utils.IsTimeZero(expectedDeliveryTime) { - expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) - } - orderParams := []interface{}{} - getCode := "" - if order.VendorID == model.VendorIDEBAI { - getCode = fmt.Sprintf("饿百取货码:%s

\n", jxutils.GetEbaiOrderGetCode(order)) - } - 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) - } - } - } - orderFmt += ` -
手机买菜上京西

-
极速到家送惊喜

---------------------------------
-下单时间: %s
-预计送达: %s
-订单编号: %s
-
- -%s#%d
-%s
-` + getCode + - `客户: %s
-电话: %s
-地址: %s
-
-客户备注:
-%s
-
- -
-商品明细:
-品名 数量 单价 小计
---------------------------------
` - // 实际支付:%s
- orderParams = append(orderParams, - 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 += `%8s%10s%10s
` - orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))) - } - orderFmt += `
-共%d种%d件商品 -
---------------------------------
-
商品质量问题请联系:

-
%s:%s

-
-更多信息请关注官方微信: %s
-
-
---------------------------------
---------------------------------
-
-` - orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, "京西菜市") - return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...) + // expectedDeliveryTime := order.ExpectedDeliveredTime + // if utils.IsTimeZero(expectedDeliveryTime) { + // expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) + // } + // orderParams := []interface{}{} + // getCode := "" + // if order.VendorID == model.VendorIDEBAI { + // getCode = fmt.Sprintf("饿百取货码:%s

\n", jxutils.GetEbaiOrderGetCode(order)) + // } + // 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) + // } + // } + // } + // orderFmt += ` + //
手机买菜上京西

+ //
极速到家送惊喜

+ //--------------------------------
+ //下单时间: %s
+ //预计送达: %s
+ //订单编号: %s
+ //
+ // + //%s#%d
+ //%s
+ //` + getCode + + // `客户: %s
+ //电话: %s
+ //地址: %s
+ //
+ //客户备注:
+ //%s
+ //
+ // + //
+ //商品明细:
+ //品名 数量 单价 小计
+ //--------------------------------
` + // // 实际支付:%s
+ // orderParams = append(orderParams, + // 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 += `%8s%10s%10s
` + // orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count))) + // } + // orderFmt += `
+ //共%d种%d件商品 + //
+ //--------------------------------
+ //
商品质量问题请联系:

+ //
%s:%s

+ //
+ //更多信息请关注官方微信: %s
+ //
+ //
+ //--------------------------------
+ //--------------------------------
+ //
+ //` + // orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel, "京西菜市") + // return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...) + return "" } func (c *PrinterHandler) getOrderContentByTemplate(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (content string) { - orderFmt := "" - if storeDetail != nil { - //开头加上语音 - if storeDetail.PrinterSound != "" { - orderFmt += "" + storeDetail.PrinterSound + "
" - } - } - //把带有${}的变量换成实际值 - template := storeDetail.PrinterTemplate - regexpValues := regexpPrint.FindAllStringSubmatch(template, -1) - for _, v := range regexpValues { - switch v[0] { - case "${下单时间}": - template = strings.ReplaceAll(template, v[0], utils.Time2Str(order.OrderCreatedAt)) - case "${预计送达}": - expectedDeliveryTime := order.ExpectedDeliveredTime - if utils.IsTimeZero(expectedDeliveryTime) { - expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) - } - template = strings.ReplaceAll(template, v[0], utils.Time2Str(expectedDeliveryTime)) - case "${订单号}": - template = strings.ReplaceAll(template, v[0], order.VendorOrderID) - case "${平台名}": - template = strings.ReplaceAll(template, v[0], jxutils.GetVendorName(order.VendorID)) - case "${订单序号}": - template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.OrderSeq)) - case "${客户名}": - template = strings.ReplaceAll(template, v[0], order.ConsigneeName) - case "${客户电话}": - template = strings.ReplaceAll(template, v[0], order.ConsigneeMobile) - case "${客户地址}": - template = strings.ReplaceAll(template, v[0], order.ConsigneeAddress) - case "${备注}": - template = strings.ReplaceAll(template, v[0], order.BuyerComment) - case "${商品种数}": - template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.SkuCount)) - case "${商品件数}": - template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.GoodsCount)) - case "${门店名}": - template = strings.ReplaceAll(template, v[0], order.StoreName) - case "${门店电话}": - template = strings.ReplaceAll(template, v[0], storeTel) - case "${商品明细}": - skus := "" - skuParams := []interface{}{} - for i := 0; i < len(order.Skus); i++ { - skus += "%s
" - skus += "%8s%10s%10s

" - skuParams = append(skuParams, order.Skus[i].SkuName) - 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*int64(order.Skus[i].Count))) - } - skus = fmt.Sprintf(skus, skuParams...) - template = strings.ReplaceAll(template, v[0], skus) - } - } - orderFmt += template - return strings.Replace(orderFmt, "\n", "", -1) + //orderFmt := "" + //if storeDetail != nil { + // //开头加上语音 + // if storeDetail.PrinterSound != "" { + // orderFmt += "" + storeDetail.PrinterSound + "
" + // } + //} + ////把带有${}的变量换成实际值 + //template := storeDetail.PrinterTemplate + //regexpValues := regexpPrint.FindAllStringSubmatch(template, -1) + //for _, v := range regexpValues { + // switch v[0] { + // case "${下单时间}": + // template = strings.ReplaceAll(template, v[0], utils.Time2Str(order.OrderCreatedAt)) + // case "${预计送达}": + // expectedDeliveryTime := order.ExpectedDeliveredTime + // if utils.IsTimeZero(expectedDeliveryTime) { + // expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour) + // } + // template = strings.ReplaceAll(template, v[0], utils.Time2Str(expectedDeliveryTime)) + // case "${订单号}": + // template = strings.ReplaceAll(template, v[0], order.VendorOrderID) + // case "${平台名}": + // template = strings.ReplaceAll(template, v[0], jxutils.GetVendorName(order.VendorID)) + // case "${订单序号}": + // template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.OrderSeq)) + // case "${客户名}": + // template = strings.ReplaceAll(template, v[0], order.ConsigneeName) + // case "${客户电话}": + // template = strings.ReplaceAll(template, v[0], order.ConsigneeMobile) + // case "${客户地址}": + // template = strings.ReplaceAll(template, v[0], order.ConsigneeAddress) + // case "${备注}": + // template = strings.ReplaceAll(template, v[0], order.BuyerComment) + // case "${商品种数}": + // template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.SkuCount)) + // case "${商品件数}": + // template = strings.ReplaceAll(template, v[0], utils.Int2Str(order.GoodsCount)) + // case "${门店名}": + // template = strings.ReplaceAll(template, v[0], order.StoreName) + // case "${门店电话}": + // template = strings.ReplaceAll(template, v[0], storeTel) + // case "${商品明细}": + // skus := "" + // skuParams := []interface{}{} + // for i := 0; i < len(order.Skus); i++ { + // skus += "%s
" + // skus += "%8s%10s%10s

" + // skuParams = append(skuParams, order.Skus[i].SkuName) + // 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*int64(order.Skus[i].Count))) + // } + // skus = fmt.Sprintf(skus, skuParams...) + // template = strings.ReplaceAll(template, v[0], skus) + // } + //} + //orderFmt += template + //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) { @@ -241,15 +240,15 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, return } printData := ManagerOrderAndStore(order, store.Tel1, storeDetail) - printData[BigFont] = "small" - if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 { - printData[BigFont] = "big" - } - // 打印次数 - printData[PrintNumber] = utils.Int2Str(model.YES) - if store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2 { - printData[PrintNumber] = utils.Int2Str(2) - } + //printData[BigFont] = "small" + //if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 { + // printData[BigFont] = "big" + //} + //// 打印次数 + //printData[PrintNumber] = utils.Int2Str(model.YES) + //if store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2 { + // printData[PrintNumber] = utils.Int2Str(2) + //} printData[AppID] = "1000" // 菜市应用 printData[OrderStatus] = utils.Int2Str(order.Status) // 订单状态 printData[WayBillStatus] = order.VendorStatus // 运单状态 diff --git a/business/partner/printer/jxprint/jxprint_const.go b/business/partner/printer/jxprint/jxprint_const.go index be22cec9c..45cee17ae 100644 --- a/business/partner/printer/jxprint/jxprint_const.go +++ b/business/partner/printer/jxprint/jxprint_const.go @@ -38,8 +38,16 @@ const ( BigFont = "bigFont" // 是否为大字体 PrintNumber = "printNumber" // 打印次数 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 { @@ -50,7 +58,27 @@ type SkuListPrintOrder struct { 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 { printOrder := make(map[string]string, 0) skuList := make([]*SkuListPrintOrder, 0, 0)