This commit is contained in:
richboo111
2023-03-17 14:14:35 +08:00
parent 103b4dab34
commit 762fc0f70e
7 changed files with 304 additions and 3 deletions

View File

@@ -4,13 +4,14 @@ import (
"bytes"
"context"
"fmt"
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"net"
"regexp"
"strconv"
"strings"
"time"
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"git.rosy.net.cn/jx-callback/business/partner/delivery"
"github.com/360EntSecGroup-Skylar/excelize"
@@ -824,6 +825,9 @@ func PrintMsg(ctx *jxcontext.Context, vendorID int, id1, id2, msgTitle, msgConte
if handler == nil {
return nil, fmt.Errorf("打印机厂商:%d当前不被支持请检查vendorID", vendorID)
}
if vendorID == model.VendorIDXpYun {
id2 = "1" //id2传打印份数
}
return handler.PrintMsg(ctx, id1, id2, msgTitle, msgContent)
}

View File

@@ -974,6 +974,19 @@ func TranslateSoundSize(vendorID, soundPercentage int) (soundSize string) {
if soundPercentage > 80 && soundPercentage <= 100 {
soundSize = "5"
}
} else if vendorID == model.VendorIDXpYun {
if soundPercentage == 0 {
soundSize = "3"
}
if soundPercentage > 0 && soundPercentage <= 33 {
soundSize = "2"
}
if soundPercentage > 33 && soundPercentage <= 66 {
soundSize = "1"
}
if soundPercentage > 66 && soundPercentage <= 100 {
soundSize = "0"
}
}
return soundSize
}

View File

@@ -43,6 +43,7 @@ const (
VendorIDYiLianYun = 203 // 易联云
VendorIDZhongWu = 204 // 中午云打印
VendorIDJxprint = 205 // 京西打印
VendorIDXpYun = 206 // 芯烨云打印机
VendorIDPrinterEnd = 300
VendorIDOthersBegin = 301
@@ -144,6 +145,7 @@ var (
VendorIDYiLianYun: "易联云",
VendorIDZhongWu: "中午云",
VendorIDJxprint: "京西云",
VendorIDXpYun: "芯烨云",
VendorIDWXMP: "微信公众号",
VendorIDWXQRCode: "微信扫码",

View File

@@ -23,9 +23,9 @@ const (
const (
PrinterFontSizeNormal = int8(0) //正常大小一份
PrinterFontSizeBig = int8(1) //两倍大小一份
PrinterFontSizeBig = int8(1) //两倍大小一份,大一
PrinterFontSizeNormal2 = int8(2) //正常字体两份
PrinterFontSizeBig2 = int8(3) //大字体两份
PrinterFontSizeBig2 = int8(3) //大字体两份,大二
)
var (

View File

@@ -1 +1,275 @@
package xpyun
import (
"fmt"
"time"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/baseapi/platformapi/xpyunapi"
"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"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
)
var (
CurPrinterHandler *PrinterHandler
)
type PrinterHandler struct {
}
func init() {
CurPrinterHandler = new(PrinterHandler)
partner.RegisterPrinterPlatform(CurPrinterHandler)
}
func (c *PrinterHandler) GetVendorID() int {
return model.VendorIDXpYun
}
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, sn, copies, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
if sn != "" {
if globals.EnableStoreWrite {
if utils.Str2Int(copies) < 0 || utils.Str2Int(copies) > 3 {
copies = "1"
}
printOrderID, err1 := api.XpyunAPI.Print(&xpyunapi.PrintRequest{
Sn: sn,
Content: msgContent,
Copies: utils.Str2Int(copies),
Voice: xpyunapi.VoicePlayOrder,
Mode: xpyunapi.ModeCheckYes,
ExpiresIn: xpyunapi.ExpiresInDefault,
})
if err1 == nil && printOrderID != "" {
printerStatus, err = c.GetPrinterStatus(ctx, sn, "")
}
}
} else {
printerStatus = &partner.PrinterStatus{
PrintResult: partner.PrintResultNoPrinter,
}
}
return printerStatus, err
}
func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, sn, s string) (printerStatus *partner.PrinterStatus, err error) {
if status, err := api.XpyunAPI.QueryPrinterStatus(sn); err == nil {
printerStatus = &partner.PrinterStatus{
PrintResult: partner.PrintResultSuccess,
}
if status == xpyunapi.PrinterStateOffline {
printerStatus.PrinterStatus = partner.PrinterStatusOffline
} else if status == xpyunapi.PrinterStateOnlineNormal {
printerStatus.PrinterStatus = partner.PrinterStatusOnlineOK
} else if status == xpyunapi.PrinterStateOnlineUnusual {
printerStatus.PrinterStatus = partner.PrinterStatusOnlineAbnormal
} else {
printerStatus.PrinterStatus = partner.PrinterStatusUnknown
}
}
return printerStatus, err
}
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, sn, id2, printerName string, soreId int64) (newID1, newID2 string, err error) {
if globals.EnableStoreWrite {
err = api.XpyunAPI.AddPrinters(sn, printerName)
}
return "", "", err
}
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, sn, id2 string) (err error) {
if globals.EnableStoreWrite {
err = api.XpyunAPI.DelPrinters([]string{sn})
}
return err
}
func (c *PrinterHandler) BindPrinter(ctx *jxcontext.Context, mapData map[string]interface{}) (bindResult *partner.BindPrinterResult, err error) {
return nil, fmt.Errorf("%s打印机当前不支持扫码绑定", model.VendorChineseNames[model.VendorIDXpYun])
}
func (c *PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *partner.BindPrinterResult) (bindResult *partner.BindPrinterResult, err error) {
return nil, fmt.Errorf("%s打印机当前不支持扫码解绑", model.VendorChineseNames[model.VendorIDXpYun])
}
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder, printType string, asfOrder *model.AfsOrder) (printerStatus *partner.PrinterStatus, err error) {
if len(order.Skus) == 0 {
return
}
content := ""
if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
content = c.getOrderContentBig(order, store.Tel1, storeDetail)
} else {
content = c.getOrderContent(order, store.Tel1, storeDetail)
}
count := 0
for {
printerStatus, err := c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content)
if (store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2) && count < 1 {
count += 1
continue
} else {
return printerStatus, err
}
}
}
func (c *PrinterHandler) PrintStore(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, vendorId int) (printerStatus *partner.PrinterStatus, err error) {
return nil, err
}
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
}
func (c *PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, sn, id2 string) (err error) {
if globals.EnableStoreWrite {
err = api.XpyunAPI.EmptyPrinterQueue(sn)
}
return err
}
func (c *PrinterHandler) PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *partner.PrinterStatus, err error) {
return nil, err
}
func (c *PrinterHandler) SetSound(ctx *jxcontext.Context, sn, id2, sound string) (err error) {
if globals.EnableStoreWrite {
err = api.XpyunAPI.SetVoiceType(sn, utils.Str2Int(sound))
}
return err
}
// 正常打印模板
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)
}
getCode := ""
if order.VendorID == model.VendorIDEBAI {
getCode = fmt.Sprintf("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
}
orderParams := []interface{}{}
orderFmt := ``
if storeDetail != nil {
if storeDetail.BrandIsPrint == model.NO {
orderFmt += `<BR><C>%s</C></BR>\n`
if order.VendorOrgCode == "34665" {
orderParams = append(orderParams, globals.StoreNameEbai2)
} else {
orderParams = append(orderParams, storeDetail.BrandName)
}
}
}
orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + `
<BR><L>下单时间: %s</BR>
<BR><L>预计送达: %s</BR>
<BR><L>客户姓名: %s</BR>
<BR><L>客户电话: %s</BR>
<BR><HB>订单编号: %s</HB></BR>
<IMG></IMG><BR><C><B>%s: #%d</B></BR></C>
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C>"
` + getCode + `
` + xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB><BR>
` + xpyunapi.StrRepeat("-", 32) + `
<BR>客户备注: %s<BR>
` + xpyunapi.StrRepeat("-", 32) + `
<BR>商品列表 ` + xpyunapi.StrRepeat("-", 6) + `<BR>
商品名` + xpyunapi.StrRepeat("-", 2) + `数量` + xpyunapi.StrRepeat("-", 3) + `单价` + xpyunapi.StrRepeat("-", 5) + `小计<BR>"
`
orderParams = append(orderParams,
utils.Time2Str(order.OrderCreatedAt),
utils.Time2Str(expectedDeliveryTime),
order.ConsigneeName,
order.ConsigneeMobile,
order.VendorOrderID,
jxutils.GetVendorName(order.VendorID),
order.OrderSeq,
order.VendorOrderID,
order.ConsigneeAddress,
order.BuyerComment,
)
for _, sku := range order.Skus {
orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
}
orderFmt += `
<L>共%d种%d件商品<BR></L>
<L>实际支付: %s元<BR></L>
` + xpyunapi.StrRepeat("-", 2) + `
`
orderFmt += `<BR><BR>`
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice))
return fmt.Sprintf(orderFmt, orderParams...)
}
func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel string, storeDetail *dao.StoreDetail) (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("<CB>饿百取货码:%s</CB>", jxutils.GetEbaiOrderGetCode(order))
}
orderParams := []interface{}{}
orderFmt := ``
if storeDetail != nil {
if storeDetail.BrandIsPrint == model.NO {
orderFmt += `<BR><C>%s</C></BR>\n`
if order.VendorOrgCode == "34665" {
orderParams = append(orderParams, globals.StoreNameEbai2)
} else {
orderParams = append(orderParams, storeDetail.BrandName)
}
}
}
orderFmt += `
` + xpyunapi.StrRepeat("-", 32) + `
<BR><L>下单时间: %s</BR>
<BR><L>预计送达: %s</BR>
<BR><L>客户姓名: %s</BR>
<BR><L>客户电话: %s</BR>
<BR><HB>订单编号: %s</HB></BR>
<IMG></IMG><BR><C><B>%s: #%d</B></BR></C>
<C><QRCODE s=6 e=L l=center>%s</QRCODE></C>"
` + getCode + `
` + xpyunapi.StrRepeat("-", 32) + `
<HB>客户地址: %s</HB><BR>
` + xpyunapi.StrRepeat("-", 32) + `
<BR>客户备注: %s<BR>
` + xpyunapi.StrRepeat("-", 32) + `
<BR>商品列表 ` + xpyunapi.StrRepeat("-", 6) + `<BR>
商品名` + xpyunapi.StrRepeat("-", 2) + `数量` + xpyunapi.StrRepeat("-", 3) + `单价` + xpyunapi.StrRepeat("-", 5) + `小计<BR>"
`
orderParams = append(orderParams,
utils.Time2Str(order.OrderCreatedAt),
utils.Time2Str(expectedDeliveryTime),
order.ConsigneeName,
order.ConsigneeMobile,
order.VendorOrderID,
jxutils.GetVendorName(order.VendorID),
order.OrderSeq,
order.VendorOrderID,
order.ConsigneeAddress,
order.BuyerComment,
)
for _, sku := range order.Skus {
orderFmt += xpyunapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
}
orderFmt += `
<L>共%d种%d件商品<BR></L>
<L>实际支付: %s元<BR></L>
` + xpyunapi.StrRepeat("-", 2) + `
`
orderFmt += `<BR><BR>`
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice))
return fmt.Sprintf(orderFmt, orderParams...)
}

View File

@@ -134,6 +134,11 @@ yilianyunClientSecret = "4885d07c2997b661102e4b6099c0bf3b"
yilianyunClientID2 = "1098307169"
yilianyunClientSecret2 = "d5eedb40c99e6691b1ca2ba82a363d6a"
xpyunUserName="feng.shi@rosy.net.cn"
xpyunUserKey="20a24d4332954993b05876e7b3db2a96"
zhongwuAppID = 8000192
zhongwuAppSecret = "29435497822f52f3cf659c65da548a79"

View File

@@ -9,6 +9,7 @@ import (
"git.rosy.net.cn/baseapi/platformapi/tiktok"
tiktokShop "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
"git.rosy.net.cn/baseapi/platformapi/uuptapi"
"git.rosy.net.cn/baseapi/platformapi/xpyunapi"
"time"
@@ -109,6 +110,7 @@ var (
XiaoWMAPI *xiaowmapi.API
YilianyunAPI *yilianyunapi.API
YilianyunAPI2 *yilianyunapi.API
XpyunAPI *xpyunapi.API
ZhongwuAPI *zhongwuapi.API
JxPrintAPI *jxprintapi.API
@@ -307,6 +309,7 @@ func Init() {
XiaoWMAPI = xiaowmapi.New(beego.AppConfig.DefaultInt("xiaoWMAppID", 0), beego.AppConfig.DefaultString("xiaoWMAppKey", ""))
YilianyunAPI = yilianyunapi.New(beego.AppConfig.DefaultString("yilianyunClientID", ""), beego.AppConfig.DefaultString("yilianyunClientSecret", ""))
YilianyunAPI2 = yilianyunapi.New(beego.AppConfig.DefaultString("yilianyunClientID2", ""), beego.AppConfig.DefaultString("yilianyunClientSecret2", ""))
XpyunAPI = xpyunapi.New(beego.AppConfig.DefaultString("xpyunUserName", ""), beego.AppConfig.DefaultString("xpyunUserKey", ""))
ZhongwuAPI = zhongwuapi.New(beego.AppConfig.DefaultInt("zhongwuAppID", 0), beego.AppConfig.DefaultString("zhongwuAppSecret", ""))
PushAPI = unipushapi.New(beego.AppConfig.DefaultString("pushAppID", ""), beego.AppConfig.DefaultString("pushAppKey", ""), beego.AppConfig.DefaultString("pushAppSecret", ""), beego.AppConfig.DefaultString("pushMasterSecret", ""))
JxPrintAPI = jxprintapi.New(beego.AppConfig.DefaultString("jxPrintAppID", ""), beego.AppConfig.DefaultString("jxPrintAppKey", ""))