trendit
This commit is contained in:
@@ -1 +1,385 @@
|
||||
package trendit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/xpyunapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/trenditapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"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 (p PrinterHandler) GetVendorID() int {
|
||||
return model.VendorIDTrendIT
|
||||
}
|
||||
|
||||
func init() {
|
||||
CurPrinterHandler = new(PrinterHandler)
|
||||
partner.RegisterPrinterPlatform(CurPrinterHandler)
|
||||
}
|
||||
|
||||
func (p PrinterHandler) PrintMsg(ctx *jxcontext.Context, sn, copies, voice, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
if sn != "" {
|
||||
if globals.EnableStoreWrite {
|
||||
printOrderID, err1 := api.TrendITAPI.Print(sn, msgContent, voice)
|
||||
if err1 == nil && printOrderID != "" {
|
||||
printerStatus, err = p.GetPrinterStatus(ctx, sn, "")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printerStatus = &partner.PrinterStatus{
|
||||
PrintResult: partner.PrintResultNoPrinter,
|
||||
}
|
||||
}
|
||||
return printerStatus, err
|
||||
}
|
||||
|
||||
func (p PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, sn, id2 string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
if onlineStatus, workStatus, err := api.TrendITAPI.GetDeviceStatus(sn); err == nil {
|
||||
printerStatus = &partner.PrinterStatus{
|
||||
PrintResult: partner.PrintResultSuccess,
|
||||
}
|
||||
tempOnline := utils.Float64TwoInt(onlineStatus)
|
||||
tempWork := utils.Float64TwoInt(workStatus)
|
||||
if tempOnline == trenditapi.OnlineStatus && tempWork == trenditapi.WorkStatusReady {
|
||||
printerStatus.PrinterStatus = partner.PrinterStatusOnlineOK
|
||||
} else if tempOnline == trenditapi.OfflineStatus {
|
||||
printerStatus.PrinterStatus = partner.PrinterStatusOffline
|
||||
} else if tempWork == trenditapi.WorkStatusPaperLack || tempWork == trenditapi.WorkStatusOverTemperature || tempWork == trenditapi.WorkStatusPrintFail {
|
||||
printerStatus.PrinterStatus = partner.PrinterStatusOnlineAbnormal
|
||||
} else {
|
||||
printerStatus.PrinterStatus = partner.PrinterStatusUnknown
|
||||
}
|
||||
}
|
||||
return printerStatus, err
|
||||
}
|
||||
|
||||
func (p PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, sn, key, printerName string, soreId int64) (newID1, newID2 string, err error) {
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.TrendITAPI.AddPrinter(sn, key, printerName)
|
||||
}
|
||||
//if strings.Contains(err.Error(), "设备已绑定") {
|
||||
// return "", "", errors.New("")
|
||||
//}
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
func (p PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, sn, id2 string) (err error) {
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.TrendITAPI.DelPrinter([]string{sn})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p PrinterHandler) BindPrinter(ctx *jxcontext.Context, mapData map[string]interface{}) (bindResult *partner.BindPrinterResult, err error) {
|
||||
return nil, fmt.Errorf("%s打印机当前不支持扫码绑定", model.VendorChineseNames[model.VendorIDTrendIT])
|
||||
}
|
||||
|
||||
func (p PrinterHandler) RebindPrinter(ctx *jxcontext.Context, lastBindResult *partner.BindPrinterResult) (bindResult *partner.BindPrinterResult, err error) {
|
||||
return nil, fmt.Errorf("%s打印机当前不支持扫码解绑", model.VendorChineseNames[model.VendorIDTrendIT])
|
||||
}
|
||||
|
||||
func (p 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 {
|
||||
globals.SugarLogger.Debugf("order.sku为空")
|
||||
return
|
||||
}
|
||||
content := ""
|
||||
if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
|
||||
content = p.getOrderContentBig(order, store.Tel1, storeDetail)
|
||||
} else {
|
||||
content = p.getOrderContent(order, store.Tel1, storeDetail)
|
||||
}
|
||||
count := 0
|
||||
for {
|
||||
printerStatus, err := p.PrintMsg(ctx, store.PrinterSN, "", trenditapi.VoiceNewShort, content)
|
||||
if (store.PrinterFontSize == partner.PrinterFontSizeBig2 || store.PrinterFontSize == partner.PrinterFontSizeNormal2) && count < 1 {
|
||||
count += 1
|
||||
continue
|
||||
} else {
|
||||
return printerStatus, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (p PrinterHandler) PrintStore(ctx *jxcontext.Context, store *model.Store, storeDetail *dao.StoreDetail, vendorId int) (printerStatus *partner.PrinterStatus, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (p PrinterHandler) PrintCancelOrRefundOrder(ctx *jxcontext.Context, printType int, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
||||
if len(order.Skus) == 0 {
|
||||
return
|
||||
}
|
||||
content := ""
|
||||
voiceType := ""
|
||||
if printType == model.YES { // 取消订单
|
||||
voiceType = trenditapi.VoiceCancel
|
||||
} else { // 售后订单
|
||||
voiceType = trenditapi.VoiceRefund
|
||||
}
|
||||
if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
|
||||
content = p.getCancelOrRefundOrderContent(order, printType, storeDetail)
|
||||
} else {
|
||||
content = p.getCancelOrRefundOrderContentBig(order, printType, storeDetail)
|
||||
}
|
||||
if content == "" {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return p.PrintMsg(ctx, store.PrinterSN, "", voiceType, content)
|
||||
}
|
||||
|
||||
func (p PrinterHandler) EmptyPrintList(ctx *jxcontext.Context, sn, id2 string) (err error) {
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.TrendITAPI.CleanWaitingQueue(sn)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p PrinterHandler) PlayText(ctx *jxcontext.Context, id1, id2, orderID, text string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (p PrinterHandler) SetSound(ctx *jxcontext.Context, sn, id2, sound string) (err error) {
|
||||
if globals.EnableStoreWrite {
|
||||
err = api.TrendITAPI.SetVolume(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("<C>饿百取货码:%s</C>", jxutils.GetEbaiOrderGetCode(order))
|
||||
}
|
||||
order.BuyerComment = ""
|
||||
if order.BuyerComment == "" {
|
||||
order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
|
||||
}
|
||||
orderParams := []interface{}{}
|
||||
orderFmt := ``
|
||||
if storeDetail != nil {
|
||||
if storeDetail.BrandIsPrint == model.NO {
|
||||
orderFmt += `<C><font# bolder=1 height=2 width=2>%s</font#></C>`
|
||||
if order.VendorOrgCode == "34665" {
|
||||
orderParams = append(orderParams, globals.StoreNameEbai2)
|
||||
} else {
|
||||
orderParams = append(orderParams, storeDetail.BrandName)
|
||||
}
|
||||
}
|
||||
}
|
||||
orderFmt += `
|
||||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT>下单时间: %s</LEFT>
|
||||
<LEFT>期望送达: %s</LEFT>
|
||||
<LEFT>客户姓名: %s</LEFT>
|
||||
<LEFT>客户电话: %s</LEFT>
|
||||
<LEFT><font# bolder=0 height=2 width=1>订单编号: %s</font#></LEFT><BR>
|
||||
<C><font# bolder=0 height=2 width=2>%s#%d</font#>
|
||||
<QR>%s</QR></C>
|
||||
` + getCode + `<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT><font# bolder=0 height=2 width=1>客户地址: %s</font#></LEFT>
|
||||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT><font# bolder=0 height=1 width=1>客户备注:%s</font#></LEFT>
|
||||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT><font# bolder=0 height=1 width=1>商品列表</font#></LEFT>
|
||||
商品名` + trenditapi.StrRepeat(" ", 2) + `数量` + trenditapi.StrRepeat(" ", 3) + `单价` + trenditapi.StrRepeat(" ", 5) + `小计
|
||||
` + trenditapi.StrRepeat("-", 32) + `
|
||||
`
|
||||
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 += trenditapi.FormatPrintOrderItem(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
|
||||
}
|
||||
orderFmt += `
|
||||
<LEFT>共%d种%d件商品
|
||||
实付金额: %s</LEFT><BR>
|
||||
<font# bolder=0 height=1 width=1>--------------#%d完-------------</font#>`
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq)
|
||||
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("<C>饿百取货码:%s</C>", jxutils.GetEbaiOrderGetCode(order))
|
||||
}
|
||||
order.BuyerComment = ""
|
||||
if order.BuyerComment == "" {
|
||||
order.BuyerComment = "客户电话: " + order.ConsigneeMobile + ",配送遇到问题,可联系18048531223取消配送单,禁止未配送直接完成订单!"
|
||||
}
|
||||
orderParams := []interface{}{}
|
||||
orderFmt := ``
|
||||
if storeDetail != nil {
|
||||
if storeDetail.BrandIsPrint == model.NO {
|
||||
orderFmt += `<C><font# bolder=1 height=2 width=2>%s</font#></C>`
|
||||
if order.VendorOrgCode == "34665" {
|
||||
orderParams = append(orderParams, globals.StoreNameEbai2)
|
||||
} else {
|
||||
orderParams = append(orderParams, storeDetail.BrandName)
|
||||
}
|
||||
}
|
||||
}
|
||||
orderFmt += `
|
||||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT><font# bolder=0 height=2 width=1>下单时间: %s</font#></LEFT>
|
||||
<LEFT><font# bolder=0 height=2 width=1>期望送达: %s</font#></LEFT>
|
||||
<LEFT><font# bolder=0 height=2 width=1>客户姓名: %s</font#></LEFT>
|
||||
<LEFT><font# bolder=0 height=2 width=1>客户电话: %s</font#></LEFT>
|
||||
<LEFT><font# bolder=0 height=3 width=1>订单编号: %s</font#></LEFT><BR>
|
||||
<C><font# bolder=1 height=2 width=2>%s#%d</font#>
|
||||
<QR>%s</QR></C>
|
||||
` + getCode + `<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT><font# bolder=1 height=2 width=1>客户地址: %s</font#></LEFT>
|
||||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT><font# bolder=0 height=2 width=1>客户备注:%s</font#></LEFT>
|
||||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
<LEFT><font# bolder=0 height=2 width=1>商品列表</font#>
|
||||
<LEFT><font# bolder=0 height=2 width=1>商品名 数量 单价 小计</font#></LEFT>
|
||||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||||
`
|
||||
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 k, sku := range order.Skus {
|
||||
orderFmt += trenditapi.FormatPrintOrderItemBig(sku.SkuName, sku.Count, utils.Int64ToFloat64(sku.SalePrice))
|
||||
if k != len(order.Skus) {
|
||||
orderFmt += `<BR>`
|
||||
}
|
||||
}
|
||||
orderFmt += `
|
||||
<LEFT><font# bolder=0 height=2 width=1>共%d种%d件商品</font#></LEFT>
|
||||
<LEFT><font# bolder=0 height=2 width=1>实付金额: %s</font#></LEFT><BR>
|
||||
<font# bolder=0 height=1 width=1>--------------#%d完-------------</font#>`
|
||||
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) {
|
||||
var orderParams []interface{}
|
||||
orderFmt := ``
|
||||
if storeDetail != nil {
|
||||
if storeDetail.BrandIsPrint == model.NO {
|
||||
orderFmt += `<C><font# bolder=1 height=2 width=2>%s</font#></C>`
|
||||
if order.VendorOrgCode == "34665" {
|
||||
orderParams = append(orderParams, globals.StoreNameEbai2)
|
||||
} else {
|
||||
orderParams = append(orderParams, storeDetail.BrandName)
|
||||
}
|
||||
}
|
||||
}
|
||||
title := ``
|
||||
if printType == model.YES { // 取消订单
|
||||
title = `<font# bolder=1 height=2 width=2>取消订单详情</font#>`
|
||||
} else { // 售后订单
|
||||
title = `<font# bolder=1 height=2 width=2>退款订单详情</font#>`
|
||||
}
|
||||
|
||||
orderFmt +=
|
||||
xpyunapi.StrRepeat("-", 32) + `
|
||||
<LEFT><font# bolder=1 height=1 width=1>下单时间: %s</font#></LEFT>
|
||||
<LEFT><font# bolder=0 height=2 width=1>订单编号: %s</font#></LEFT><BR>
|
||||
<font# bolder=1 height=2 width=2>%s#%d</font#>
|
||||
` + title
|
||||
orderParams = append(orderParams,
|
||||
utils.Time2Str(order.OrderCreatedAt),
|
||||
order.VendorOrderID,
|
||||
jxutils.GetVendorName(order.VendorID),
|
||||
order.OrderSeq,
|
||||
)
|
||||
orderFmt += xpyunapi.StrRepeat("-", 32)
|
||||
orderFmt += `<LEFT><font# bolder=1 height=2 width=1>共%d种%d件商品</font#></LEFT>
|
||||
<LEFT><font# bolder=1 height=2 width=1>实付金额: %s</font#></LEFT>
|
||||
<font# bolder=0 height=1 width=1>--------------#%d完-------------</font#>`
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq)
|
||||
return fmt.Sprintf(orderFmt, orderParams...)
|
||||
}
|
||||
|
||||
//取消/退货 大尺寸模板
|
||||
func (c *PrinterHandler) getCancelOrRefundOrderContentBig(order *model.GoodsOrder, printType int, storeDetail *dao.StoreDetail) (content string) {
|
||||
var orderParams []interface{}
|
||||
orderFmt := ``
|
||||
if storeDetail != nil {
|
||||
if storeDetail.BrandIsPrint == model.NO {
|
||||
orderFmt += `<C><font# bolder=1 height=2 width=2>%s</font#></C>`
|
||||
if order.VendorOrgCode == "34665" {
|
||||
orderParams = append(orderParams, globals.StoreNameEbai2)
|
||||
} else {
|
||||
orderParams = append(orderParams, storeDetail.BrandName)
|
||||
}
|
||||
}
|
||||
}
|
||||
title := ``
|
||||
if printType == model.YES { // 取消订单
|
||||
title = `<font# bolder=1 height=2 width=2>取消订单详情</font#>`
|
||||
} else { // 售后订单
|
||||
title = `<font# bolder=1 height=2 width=2>退款订单详情</font#>`
|
||||
}
|
||||
|
||||
orderFmt +=
|
||||
xpyunapi.StrRepeat("-", 32) + `
|
||||
<LEFT><font# bolder=1 height=1 width=1>下单时间: %s</font#></LEFT>
|
||||
<LEFT><font# bolder=0 height=2 width=1>订单编号: %s</font#></LEFT><BR>
|
||||
<font# bolder=1 height=2 width=2>%s#%d</font#>
|
||||
` + title
|
||||
orderParams = append(orderParams,
|
||||
utils.Time2Str(order.OrderCreatedAt),
|
||||
order.VendorOrderID,
|
||||
jxutils.GetVendorName(order.VendorID),
|
||||
order.OrderSeq,
|
||||
)
|
||||
orderFmt += xpyunapi.StrRepeat("-", 32)
|
||||
orderFmt += `<LEFT><font# bolder=1 height=2 width=1>共%d种%d件商品</font#></LEFT>
|
||||
<LEFT><font# bolder=1 height=2 width=1>实付金额: %s</font#></LEFT>
|
||||
<font# bolder=0 height=1 width=1>--------------#%d完-------------</font#>`
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice), order.OrderSeq)
|
||||
return fmt.Sprintf(orderFmt, orderParams...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user