订单配送,打印机

This commit is contained in:
邹宗楠
2022-06-01 15:36:08 +08:00
parent 1eae9e6ba4
commit b5a0ab5757
6 changed files with 100 additions and 30 deletions

View File

@@ -525,14 +525,14 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
if !isPending {
if order.Status >= model.OrderStatusDelivering && order.Status < model.OrderStatusEndBegin {
if order.DeliveryType == model.OrderDeliveryTypeStoreSelf {
s.SelfDeliverDelivering(order, bill.CourierMobile)
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, switch2SelfDeliverRetryCount, switch2SelfDeliverRetryGap)
} else {
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
}
} else if order.Status > model.OrderStatusEndBegin {
// 订单处于完成状态,来的新运单,取消三方配送,转自送!
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
s.SelfDeliverDelivered(order, "自送或三方")
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) // 取消三方配送调度
s.SelfDeliverDelivered(order, "自送或三方") // 取消当前运单调度
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, switch2SelfDeliverRetryCount, switch2SelfDeliverRetryGap) // 转自送
partner.CurOrderManager.OnOrderMsg(order, "订单处于结束状态来的运单", "取消三方运单转自送1")
} else {
needAddTip := order.WaybillTipMoney > 0 && !model.IsWaybillPlatformOwn(bill)
@@ -629,9 +629,9 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
smsmsg.NotifyPickOrder(order)
}
// 订单处于配送状态来的新分配骑手运单
if order.Status >= model.OrderStatusDelivering && order.Status < model.OrderStatusEndBegin && bill.Status < model.OrderStatusDelivering{
if order.Status >= model.OrderStatusDelivering && order.Status < model.OrderStatusEndBegin && bill.Status < model.OrderStatusDelivering {
if order.DeliveryType == model.OrderDeliveryTypeStoreSelf {
s.SelfDeliverDelivering(order, bill.CourierMobile)
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, switch2SelfDeliverRetryCount, switch2SelfDeliverRetryGap) // 转自送
} else {
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
}
@@ -639,7 +639,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
//订单已经是结束状态之后来的运单143945553920000001
if order.Status > model.OrderStatusEndBegin {
s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
s.SelfDeliverDelivered(order, "自送或三方")
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, switch2SelfDeliverRetryCount, switch2SelfDeliverRetryGap) // 转自送
partner.CurOrderManager.OnOrderMsg(order, "订单处于结束状态来的运单", "取消三方运单,转自送")
}
// 判断订单来源与运单是否为同一来源
@@ -656,7 +656,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
if err := s.SelfDeliverDelivering(order, bill.CourierMobile); err != nil {
if err := s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrSwitch2SelfFailed); err != nil {
// 如果转自送失败,且取消三方失败,循环多次转自送
s.swtich2SelfDeliverWithRetry(savedOrderInfo, bill, switch2SelfDeliverRetryCount, switch2SelfDeliverRetryGap)
partner.CurOrderManager.OnOrderMsg(order, "自送出设置失败", err.Error())
}
partner.CurOrderManager.OnOrderMsg(order, "转自送失败,并多次转自送", err.Error())
}
@@ -737,7 +737,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
s.resetTimer(savedOrderInfo, bill, isPending)
s.removeWaybillFromMap(savedOrderInfo, bill.WaybillVendorID)
if order.DeliveryType == model.OrderDeliveryTypeStoreSelf { // 只要门店自送,订单结束都推一下送达!(bug完成的订单还会继续美团外卖送)
s.SelfDeliverDelivered(order, "")
s.SelfDeliverDelivered(order, "")
}
if !isPending {
var err2 error

View File

@@ -331,7 +331,7 @@ type Store struct {
Comment string `orm:"size(255)" json:"comment"` //门店备注
PrinterDisabled int8 `orm:"default(0)" json:"printerDisabled"` // 是否禁用网络打印机
PrinterFontSize int8 `orm:"default(0)" json:"printerFontSize"` // 打印字体-10正常1
PrinterFontSize int8 `orm:"default(0)" json:"printerFontSize"` // 打印字体0(正常大小1份)1(大字体一份),2(正常字体两份),3(打字体两份)
PrinterVendorID int `orm:"column(printer_vendor_id);" json:"printerVendorID"`
PrinterSN string `orm:"size(32);column(printer_sn);index" json:"printerSN"`
PrinterKey string `orm:"size(64)" json:"printerKey"`

View File

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

View File

@@ -79,7 +79,7 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
\n
\n
商品明细: \n
品名 数量 单价 小计\n
品名 数量 小计\n
--------------------------------\n`
// <FB>实际支付:</FB>%s\n
orderParams = append(orderParams,
@@ -98,8 +98,9 @@ func (c *PrinterHandler) getOrderContent(order *model.GoodsOrder, storeTel strin
for _, sku := range order.Skus {
orderFmt += `%s\n`
orderFmt += `%8s%10s%10s\n`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
orderFmt += `%6s%8s%8s\n`
//orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
//标品需要打印条形码
if sku.Upc != "" {
orderFmt += `upc码 %s\n`
@@ -164,7 +165,7 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
\n
\n
<FS2>商品明细: \n</FS2>
<FS2>品名数量单价小计\n</FS2>
品名 数量 小计\n
--------------------------------\n`
// <FS2><FB>实际支付:</FB>%s\n</FS2>
orderParams = append(orderParams,
@@ -183,8 +184,10 @@ func (c *PrinterHandler) getOrderContentBig(order *model.GoodsOrder, storeTel st
for _, sku := range order.Skus {
orderFmt += `<FS2>%s\n</FS2>`
orderFmt += `<FS2>%s %s %s\n\n</FS2>`
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
//orderFmt += `<FS2>%s %s %s\n\n</FS2>`
orderFmt += `<FH><FB>%s %s %s\n\n</FB></FH>`
//orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
orderParams = append(orderParams, sku.SkuName, "x"+utils.Int2Str(sku.Count), jxutils.IntPrice2StandardCurrencyString(sku.SalePrice*int64(sku.Count)))
//标品需要打印条形码
if sku.Upc != "" {
orderFmt += `<FS2>upc码 %s\n</FS2>`
@@ -250,12 +253,22 @@ func (c *PrinterHandler) PrintOrder(ctx *jxcontext.Context, store *model.Store,
return
}
content := ""
if store.PrinterFontSize == partner.PrinterFontSizeBig {
if store.PrinterFontSize == partner.PrinterFontSizeBig || store.PrinterFontSize == partner.PrinterFontSizeBig2 {
content = c.getOrderContentBig(order, store.Tel1, storeDetail)
} else {
content = c.getOrderContent(order, store.Tel1, storeDetail)
}
return c.PrintMsg(ctx, store.PrinterSN, store.PrinterKey, order.VendorOrderID, content)
var 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 = count + 1
continue
} else {
return printerStatus, err
}
}
}
func (c *PrinterHandler) RegisterPrinter(ctx *jxcontext.Context, machineCode, secret, printerName string) (notUsed1, notUsed2 string, err error) {

View File

@@ -118,26 +118,40 @@ func onTTPayRefund(msg *wxpayapi.RefundResultMsg) (err error) {
return err
}
func refundOrderByTT(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) {
result, err := api.WxpayAPI.PayRefund(&wxpayapi.PayRefundParam{
OutTradeNo: orderPay.VendorOrderID,
NotifyURL: globals.WxpayNotifyURL,
OutRefundNo: refundID,
TotalFee: orderPay.TotalFee,
RefundFee: refundFee,
RefundDesc: wxpayapi.CData(refundDesc),
// 申请退款
func RefundOrderByTT(ctx *jxcontext.Context, orderPay *model.OrderPay, refundID string, refundFee int, refundDesc string) (orderPayRefund *model.OrderPayRefund, err error) {
result, err := api.TiktokApi.RefundOrderTT(&tiktok.RefundOrderReq{
AppID: api.TiktokApi.GetAppID(),
OutOrderNo: orderPay.VendorOrderID,
OutRefundNo: refundID,
Reason: refundDesc,
RefundAmount: orderPay.TotalFee,
CpExtra: "msg",
NotifyURL: globals.TictokpayNotifyURL,
})
if err == nil {
orderPayRefund = &model.OrderPayRefund{
RefundID: refundID,
VendorRefundID: result.RefundID,
VendorRefundID: result,
VendorOrderID: orderPay.VendorOrderID,
VendorID: orderPay.VendorID,
Status: model.RefundStatusNo,
TransactionID: orderPay.TransactionID,
RefundFee: orderPay.TotalFee,
RefundFee: refundFee,
RefundCreatedAt: time.Now(),
}
dao.WrapAddIDCULDEntity(orderPayRefund, ctx.GetUserName())
db := dao.GetDB()
if result != "" {
orderPayRefund.Status = model.RefundStatusYes
} else {
orderPayRefund.Status = model.RefundStatusFailed
}
orderPayRefund.OriginalData = utils.Format4Output(result, true)
dao.CreateEntity(db, orderPayRefund)
orderPay.Status = model.PayStatusRefund
dao.UpdateEntity(db, orderPay)
}
return orderPayRefund, err
}

View File

@@ -0,0 +1,41 @@
package controllers
import (
"fmt"
"net/http"
"git.rosy.net.cn/baseapi/platformapi/wxpayapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego/server/web"
)
type TTPayController struct {
web.Controller
}
func (c *TTPayController) Msg() {
if c.Ctx.Input.Method() == http.MethodPost {
msg, callbackResponse := api.WxpayAPI.GetCallbackMsg(c.Ctx.Request)
globals.SugarLogger.Debugf("wxpayapi callback msg:%s, callbackResponse:%s, %t", utils.Format4Output(msg, true), utils.Format4Output(callbackResponse, true), callbackResponse == nil)
var err error
if callbackResponse == nil {
if msg.MsgType == wxpayapi.MsgTypeUnkown {
err = fmt.Errorf("未知的微信支付回调类型:%d", msg.MsgType)
} else {
err = localjx.OnWxPayCallback(msg)
}
}
if callbackResponse == nil {
callbackResponse = wxpayapi.SuccessResponse
} else if err != nil {
callbackResponse = wxpayapi.Err2CallbackResponse(err, "")
}
c.Data["xml"] = callbackResponse
c.ServeXML()
} else {
c.Abort("404")
}
}