diff --git a/business/jxutils/tasks/configrefresh.go b/business/jxutils/tasks/configrefresh.go
index a798eed55..025dac7a7 100644
--- a/business/jxutils/tasks/configrefresh.go
+++ b/business/jxutils/tasks/configrefresh.go
@@ -198,7 +198,7 @@ func SaveWeimobToken(token *weimobapi.TokenInfo) (err error) {
func RefreshYilianyunToken() error {
return RefreshConfig("yilianyun", yilianyunTokenExpires, func() (string, string) {
globals.SugarLogger.Debugf("RefreshYilianyunToken RunMode:%s", beego.BConfig.RunMode)
- if true { //beego.BConfig.RunMode == "prod" {
+ if beego.BConfig.RunMode == "prod" {
if tokenInfo, err := api.YilianyunAPI.RetrieveToken(); err == nil {
return string(utils.MustMarshal(tokenInfo)), ""
} else {
diff --git a/business/partner/printer/zhongwu/zhongwu.go b/business/partner/printer/zhongwu/zhongwu.go
new file mode 100644
index 000000000..aba72c40b
--- /dev/null
+++ b/business/partner/printer/zhongwu/zhongwu.go
@@ -0,0 +1,149 @@
+package zhongwu
+
+import (
+ "fmt"
+ "strings"
+ "time"
+
+ "git.rosy.net.cn/baseapi/platformapi/yilianyunapi"
+ "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 := `
+京西菜市
+手机买菜上京西
+极速到家送惊喜
+--------------------------------
+下单时间: %s
+预计送达: %s
+订单编号: %s
+
+
+%s#%d
+%s
+
+客户: %s
+电话: %s
+地址: %s
+
+客户备注:
+%s
+
+
+实际支付:%s
+
+商品明细:
+品名 数量 单价 小计
+--------------------------------
`
+ 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
`
+ orderFmt += `%10s%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
+
+官方服务热线: 18011516898
+更多信息请关注官方微信: 京西菜市
+
+
+--------------------------------
+--------------------------------
+
+`
+ // http://weixin.qq.com/r/tkkDGzTERmk5rXB49xyk
+ 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.VendorIDYiLianYun
+}
+
+func (c *PrinterHandler) PrintMsg(ctx *jxcontext.Context, machineCode, notUsed, msgTitle, msgContent string) (printerStatus *partner.PrinterStatus, err error) {
+ globals.SugarLogger.Debugf("PrintMsg machineCode:%s", machineCode)
+ if machineCode != "" {
+ if err = api.YilianyunAPI.PrintMsg(machineCode, msgTitle, msgContent); err == nil {
+ printerStatus, err = c.GetPrinterStatus(ctx, machineCode, "")
+ }
+ } else {
+ printerStatus = &partner.PrinterStatus{
+ PrintResult: partner.PrintResultNoPrinter,
+ }
+ }
+ return printerStatus, err
+}
+
+func (c *PrinterHandler) GetPrinterStatus(ctx *jxcontext.Context, machineCode, notUsed string) (printerStatus *partner.PrinterStatus, err error) {
+ status, err := api.YilianyunAPI.GetPrintStatus(machineCode)
+ if err == nil {
+ printerStatus = &partner.PrinterStatus{
+ PrintResult: partner.PrintResultSuccess,
+ }
+ if status == yilianyunapi.PrintStatusOffline {
+ printerStatus.PrinterStatus = partner.PrinterStatusOffline
+ } else if status == yilianyunapi.PrintStatusOnline {
+ printerStatus.PrinterStatus = partner.PrinterStatusOnlineOK
+ } else {
+ printerStatus.PrinterStatus = partner.PrinterStatusOnlineAbnormal
+ }
+ }
+ return printerStatus, err
+}
+
+func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
+ globals.SugarLogger.Debugf("yilianyun PrintOrderByOrder orderID:%s", order.VendorOrderID)
+ content := c.getOrderContent(order, store.Tel1)
+ return c.PrintMsg(ctx, store.PrinterSN, "", order.VendorOrderID, content)
+}
+
+func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, machineCode, secret, printerName string) (notUsed1, notUsed2 string, err error) {
+ err = api.YilianyunAPI.AddPrinter(machineCode, secret, printerName)
+ return "", "", err
+}
+
+func (c *PrinterHandler) UnregisterPrinter(ctx *jxcontext.Context, machineCode, notUsed string) (err error) {
+ err = api.YilianyunAPI.DeletePrinter(machineCode)
+ return err
+}
diff --git a/conf/app.conf b/conf/app.conf
index eaf618635..d8912957b 100644
--- a/conf/app.conf
+++ b/conf/app.conf
@@ -75,6 +75,9 @@ xiaoWMAppKey = "94337"
yilianyunClientID = "1039586024"
yilianyunClientSecret = "4885d07c2997b661102e4b6099c0bf3b"
+zhongwuAppID = 8000192
+zhongwuAppSecret = "29435497822f52f3cf659c65da548a79"
+
[dev]
jdToken = "c8854ef2-f80a-45ee-aceb-dc8014d646f8"
jdAppKey = "06692746f7224695ad4788ce340bc854"
diff --git a/globals/api/api.go b/globals/api/api.go
index f308e9d60..a5a55d9e3 100644
--- a/globals/api/api.go
+++ b/globals/api/api.go
@@ -18,6 +18,7 @@ import (
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
"git.rosy.net.cn/baseapi/platformapi/xiaowmapi"
"git.rosy.net.cn/baseapi/platformapi/yilianyunapi"
+ "git.rosy.net.cn/baseapi/platformapi/zhongwuapi"
"git.rosy.net.cn/jx-callback/business/jxutils/cache"
"git.rosy.net.cn/jx-callback/business/jxutils/cache/redis"
@@ -46,6 +47,7 @@ var (
FeieAPI *feieapi.API
XiaoWMAPI *xiaowmapi.API
YilianyunAPI *yilianyunapi.API
+ ZhongwuAPI *zhongwuapi.API
Cacher cache.ICacher
)
@@ -103,6 +105,7 @@ func Init() {
FeieAPI = feieapi.New(beego.AppConfig.DefaultString("feieUser", ""), beego.AppConfig.DefaultString("feieKey", ""))
XiaoWMAPI = xiaowmapi.New(beego.AppConfig.DefaultInt("xiaoWMAppID", 0), beego.AppConfig.DefaultString("xiaoWMAppKey", ""))
YilianyunAPI = yilianyunapi.New(beego.AppConfig.DefaultString("yilianyunClientID", ""), beego.AppConfig.DefaultString("yilianyunClientSecret", ""))
+ ZhongwuAPI = zhongwuapi.New(beego.AppConfig.DefaultInt("zhongwuAppID", 0), beego.AppConfig.DefaultString("zhongwuAppSecret", ""))
}
func initElm() {