- 重构打印机流程,添加“外卖管家”打印
This commit is contained in:
176
business/partner/printer/feie/feie.go
Normal file
176
business/partner/printer/feie/feie.go
Normal file
@@ -0,0 +1,176 @@
|
||||
package feie
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/feieapi"
|
||||
"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/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) getOrderContent(order *model.GoodsOrder, storeTel string) (content string) {
|
||||
expectedDeliveryTime := order.ExpectedDeliveredTime
|
||||
if utils.IsTimeZero(expectedDeliveryTime) {
|
||||
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
|
||||
}
|
||||
orderFmt := `
|
||||
<CB>京西菜市</CB><BR>
|
||||
<C>手机买菜上京西</C><BR>
|
||||
<C>极速到家送惊喜</C><BR>
|
||||
--------------------------------<BR>
|
||||
下单时间: %s<BR>
|
||||
预计送达: %s<BR>
|
||||
订单编号: %s<BR>
|
||||
<BR>
|
||||
|
||||
<B>%s#%d</B><BR><BR>
|
||||
<QR>%s</QR>
|
||||
<BR>
|
||||
客户: %s<BR>
|
||||
电话: %s<BR>
|
||||
地址: %s<BR>
|
||||
<BR>
|
||||
客户备注: <BR>
|
||||
<B>%s</B><BR>
|
||||
<BR>
|
||||
|
||||
<BOLD>实际支付:</BOLD>%s<BR>
|
||||
<BR>
|
||||
商品明细: <BR>
|
||||
品名 数量 单价 小计<BR>
|
||||
--------------------------------<BR>`
|
||||
orderParams := []interface{}{
|
||||
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<BR>`
|
||||
orderFmt += `%10s%10s%10s<BR>`
|
||||
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
|
||||
}
|
||||
orderFmt += `<BR>
|
||||
<BOLD>共%d种%d件商品</BOLD>
|
||||
<BR>
|
||||
--------------------------------<BR>
|
||||
<C><L><BOLD>商品质量问题请联系:</BOLD></L><BR></C>
|
||||
<C><L><BOLD>%s:%s</BOLD></L><BR></C><BR>
|
||||
<BR>
|
||||
官方服务热线: 18011516898<BR>
|
||||
更多信息请关注官方微信: 京西菜市<BR>
|
||||
<BR>
|
||||
<BR><BR>
|
||||
--------------------------------<BR>
|
||||
--------------------------------<BR>
|
||||
<BR><BR>
|
||||
`
|
||||
// <QR>http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk</QR>
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel)
|
||||
return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) GetVendorID() int {
|
||||
return model.VendorIDFeiE
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, id1, id2, msg string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg id1:%s", id1)
|
||||
if id1 != "" {
|
||||
if _, err = api.FeieAPI.PrintMsg(id1, msg, 1); err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, id1, id2)
|
||||
}
|
||||
} else {
|
||||
printerStatus = &partner.PrinterStatus{
|
||||
PrintResult: partner.PrintResultNoPrinter,
|
||||
}
|
||||
}
|
||||
return printerStatus, err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, id1, id2 string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
sn := id1
|
||||
printerStatus = &partner.PrinterStatus{
|
||||
PrintResult: partner.PrintResultSuccess,
|
||||
}
|
||||
if printerStatus.PrinterStatus, err = api.FeieAPI.QueryPrinterStatus(sn); err == nil {
|
||||
printerStatus.Printed, printerStatus.Waiting, err = api.FeieAPI.QueryOrderInfoByDate(sn, time.Now())
|
||||
}
|
||||
return printerStatus, nil
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("feie PrintOrderByOrder orderID:%s", order.VendorOrderID)
|
||||
content := c.getOrderContent(order, store.Tel1)
|
||||
return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, content)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, store *model.Store, id1, id2 string) (err error) {
|
||||
if store.PrinterSN != "" && (store.PrinterSN != id1 || store.PrinterKey != id2) {
|
||||
err = c.UnregisterPrinter(ctx, store)
|
||||
}
|
||||
if true { //err == nil {
|
||||
if id1 != "" {
|
||||
if err = addNetPrinter(id1, id2, store.Name); err == nil {
|
||||
store.PrinterSN = id1
|
||||
store.PrinterKey = id2
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, store *model.Store) (err error) {
|
||||
if store.PrinterSN != "" {
|
||||
_, _, err = api.FeieAPI.PrinterDelList([]string{store.PrinterSN})
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func addNetPrinter(sn, key, storeName string) (err error) {
|
||||
name := storeName
|
||||
_, no, err := api.FeieAPI.PrinterAddList([]*feieapi.PrinterInfo{
|
||||
&feieapi.PrinterInfo{
|
||||
SN: sn,
|
||||
Key: key,
|
||||
Name: name,
|
||||
},
|
||||
})
|
||||
if err == nil {
|
||||
if no[sn] != "" {
|
||||
if no[sn] == feieapi.ErrMsgAlredyAdded {
|
||||
api.FeieAPI.PrinterEdit(sn, name, "")
|
||||
} else {
|
||||
err = fmt.Errorf("添加打印机出错:%s", no[sn])
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
147
business/partner/printer/xiaowm/xiaowm.go
Normal file
147
business/partner/printer/xiaowm/xiaowm.go
Normal file
@@ -0,0 +1,147 @@
|
||||
package xiaowm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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/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) getOrderContent(order *model.GoodsOrder, storeTel string) (content string) {
|
||||
expectedDeliveryTime := order.ExpectedDeliveredTime
|
||||
if utils.IsTimeZero(expectedDeliveryTime) {
|
||||
expectedDeliveryTime = order.OrderCreatedAt.Add(1 * time.Hour)
|
||||
}
|
||||
orderFmt := `
|
||||
<CB>京西菜市</CB><BR>
|
||||
<C>手机买菜上京西</C><BR>
|
||||
<C>极速到家送惊喜</C><BR>
|
||||
--------------------------------<BR>
|
||||
下单时间: %s<BR>
|
||||
预计送达: %s<BR>
|
||||
订单编号: %s<BR>
|
||||
<BR>
|
||||
|
||||
<B>%s#%d</B><BR><BR>
|
||||
<QR>%s</QR>
|
||||
<BR>
|
||||
客户: %s<BR>
|
||||
电话: %s<BR>
|
||||
地址: %s<BR>
|
||||
<BR>
|
||||
客户备注: <BR>
|
||||
<B>%s</B><BR>
|
||||
<BR>
|
||||
|
||||
<BOLD>实际支付:</BOLD>%s<BR>
|
||||
<BR>
|
||||
商品明细: <BR>
|
||||
品名 数量 单价 小计<BR>
|
||||
--------------------------------<BR>`
|
||||
orderParams := []interface{}{
|
||||
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<BR>`
|
||||
orderFmt += `%10s%10s%10s<BR>`
|
||||
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
|
||||
}
|
||||
orderFmt += `<BR>
|
||||
<BOLD>共%d种%d件商品</BOLD>
|
||||
<BR>
|
||||
--------------------------------<BR>
|
||||
<C><L><BOLD>商品质量问题请联系:</BOLD></L><BR></C>
|
||||
<C><L><BOLD>%s:%s</BOLD></L><BR></C><BR>
|
||||
<BR>
|
||||
官方服务热线: 18011516898<BR>
|
||||
更多信息请关注官方微信: 京西菜市<BR>
|
||||
<BR>
|
||||
<BR><BR>
|
||||
--------------------------------<BR>
|
||||
--------------------------------<BR>
|
||||
<BR><BR>
|
||||
`
|
||||
// <QR>http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk</QR>
|
||||
orderParams = append(orderParams, order.SkuCount, order.GoodsCount, order.StoreName, storeTel)
|
||||
return fmt.Sprintf(strings.Replace(orderFmt, "\n", "", -1), orderParams...)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) GetVendorID() int {
|
||||
return model.VendorIDXiaoWM
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, id1, id2, msg string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("PrintMsg id1:%s", id1)
|
||||
if id1 != "" {
|
||||
if _, err = api.XiaoWMAPI.SendMsg(id1, id2, msg); err == nil {
|
||||
printerStatus, err = c.GetPrinterStatus(ctx, id1, id2)
|
||||
}
|
||||
} else {
|
||||
printerStatus = &partner.PrinterStatus{
|
||||
PrintResult: partner.PrintResultNoPrinter,
|
||||
}
|
||||
}
|
||||
return printerStatus, err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, id1, id2 string) (printerStatus *partner.PrinterStatus, err error) {
|
||||
return printerStatus, err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
||||
globals.SugarLogger.Debugf("xiaowm PrintOrderByOrder orderID:%s", order.VendorOrderID)
|
||||
content := c.getOrderContent(order, store.Tel1)
|
||||
return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, content)
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, store *model.Store, id1, id2 string) (err error) {
|
||||
if store.PrinterSN != "" && (store.PrinterSN != id1 || store.PrinterKey != id2) {
|
||||
err = c.UnregisterPrinter(ctx, store)
|
||||
}
|
||||
if true { //err == nil {
|
||||
if id1 != "" {
|
||||
// if err = addNetPrinter(id1, id2, store.Name); err == nil {
|
||||
// store.PrinterSN = id1
|
||||
// store.PrinterKey = id2
|
||||
// }
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, store *model.Store) (err error) {
|
||||
if store.PrinterSN != "" {
|
||||
// _, _, err = api.FeieAPI.PrinterDelList([]string{store.PrinterSN})
|
||||
}
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user