将菜市蜂鸟信息通知到果园去
This commit is contained in:
@@ -2,6 +2,7 @@ package tasks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi/fnpsapi"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -20,7 +21,6 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
|
||||||
"github.com/astaxie/beego/client/orm"
|
"github.com/astaxie/beego/client/orm"
|
||||||
beego "github.com/astaxie/beego/server/web"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -159,14 +159,11 @@ func RefreshFnToken() (err error) {
|
|||||||
dao.ExecuteSQL(dao.GetDB(), sql, []interface{}{
|
dao.ExecuteSQL(dao.GetDB(), sql, []interface{}{
|
||||||
token, refreshToken, "fn",
|
token, refreshToken, "fn",
|
||||||
})
|
})
|
||||||
//}
|
|
||||||
if beego.BConfig.RunMode == "jxgy" {
|
if _, err = fnpsapi.HttpToGuoYuanFN(map[string]interface{}{"token": curConfig.Token, "refresh_token": curConfig.RefreshToken}, fnpsapi.FengNiaoCallbackTypeToken); err != nil {
|
||||||
config := &legacymodel.Config{}
|
globals.SugarLogger.Debugf("菜市token通知到果园错误:%v", err)
|
||||||
sql := `SELECT * FROM config WHERE thirdparty = 'fn'`
|
|
||||||
if err := dao.GetRow(dao.GetDB(), &config, sql, nil); err == nil {
|
|
||||||
token = config.Token
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return token, expireTimeStr, refreshToken
|
return token, expireTimeStr, refreshToken
|
||||||
}, func(value, v2 string) {
|
}, func(value, v2 string) {
|
||||||
api.FnAPI.SetToken(value)
|
api.FnAPI.SetToken(value)
|
||||||
|
|||||||
@@ -147,7 +147,14 @@ func (c *DeliveryHandler) UpdateStore(ctx *jxcontext.Context, storeDetail *dao.S
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 蜂鸟门店状态改变
|
// 蜂鸟门店状态改变
|
||||||
func OnStoreStatus(msg *fnpsapi.ChainstoreStatusNotify) (retVal *fnpsapi.CallbackResponse) {
|
func OnStoreStatus(msg *fnpsapi.ChainstoreStatusNotify, reallyData *fnpsapi.ShortStatus) (retVal *fnpsapi.CallbackResponse) {
|
||||||
|
store, err := dao.GetStoreDetail2(dao.GetDB(), 0, msg.Param.OutShopCode, model.VendorIDFengNiao)
|
||||||
|
if store == nil || store.ID == model.NO || err != nil {
|
||||||
|
if _, err = fnpsapi.HttpToGuoYuanFN(utils.Struct2MapByJson(reallyData), fnpsapi.FengNiaoCallbackTypeStore); err != nil {
|
||||||
|
return fnpsapi.Err2CallbackResponse(err, "")
|
||||||
|
}
|
||||||
|
return fnpsapi.Err2CallbackResponse(nil, "")
|
||||||
|
}
|
||||||
return CurDeliveryHandler.OnStoreStatus(msg)
|
return CurDeliveryHandler.OnStoreStatus(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/tao_vegetable"
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/tao_vegetable"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -247,6 +248,15 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify, resultParam *fnpsapi.ShortSta
|
|||||||
if err := utils.Map2StructByJson(msg.Param, cc, true); err != nil {
|
if err := utils.Map2StructByJson(msg.Param, cc, true); err != nil {
|
||||||
return fnpsapi.Err2CallbackResponse(err, "")
|
return fnpsapi.Err2CallbackResponse(err, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
good, err := dao.GetSimpleOrder(dao.GetDB(), cc.PartnerOrderCode)
|
||||||
|
if good == nil || good.VendorOrderID == "" || err != nil {
|
||||||
|
if _, err = fnpsapi.HttpToGuoYuanFN(utils.Struct2MapByJson(resultParam), fnpsapi.FengNiaoCallbackTypeOrder); err != nil {
|
||||||
|
return fnpsapi.Err2CallbackResponse(err, "")
|
||||||
|
}
|
||||||
|
return fnpsapi.Err2CallbackResponse(nil, "")
|
||||||
|
}
|
||||||
|
|
||||||
// 多次取消,只处理第一次
|
// 多次取消,只处理第一次
|
||||||
if cc.OrderStatus == fnpsapi.OrderStatusAcceptCacle {
|
if cc.OrderStatus == fnpsapi.OrderStatusAcceptCacle {
|
||||||
bill, err := partner.CurOrderManager.LoadWaybill(utils.Int64ToStr(cc.OrderId), model.VendorIDFengNiao)
|
bill, err := partner.CurOrderManager.LoadWaybill(utils.Int64ToStr(cc.OrderId), model.VendorIDFengNiao)
|
||||||
@@ -258,18 +268,6 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify, resultParam *fnpsapi.ShortSta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var good *model.GoodsOrder
|
|
||||||
sql := `SELECT * FROM goods_order WHERE vendor_order_id = ? ORDER BY order_created_at DESC LIMIT 1 OFFSET 0`
|
|
||||||
sqlParams := []interface{}{cc.PartnerOrderCode}
|
|
||||||
dao.GetRow(dao.GetDB(), &good, sql, sqlParams)
|
|
||||||
if good == nil || good.VendorOrderID == "" {
|
|
||||||
_, err := fnpsapi.HttpToGuoYuanFN(utils.Struct2MapByJson(resultParam), "order")
|
|
||||||
if err != nil {
|
|
||||||
return fnpsapi.Err2CallbackResponse(err, "")
|
|
||||||
}
|
|
||||||
return fnpsapi.Err2CallbackResponse(nil, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
order := &model.Waybill{
|
order := &model.Waybill{
|
||||||
VendorWaybillID: utils.Int64ToStr(cc.OrderId),
|
VendorWaybillID: utils.Int64ToStr(cc.OrderId),
|
||||||
VendorWaybillID2: cc.PartnerOrderCode,
|
VendorWaybillID2: cc.PartnerOrderCode,
|
||||||
@@ -375,7 +373,14 @@ func tiktokStatusPush(order *model.Waybill, orderStatus int64, lng, lat, vendorO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 异常报备
|
// 异常报备
|
||||||
func OnWaybillExceptFn(msg *fnpsapi.AbnormalReportNotify) (retVal *fnpsapi.CallbackResponse) {
|
func OnWaybillExceptFn(msg *fnpsapi.AbnormalReportNotify, reallyData *fnpsapi.ShortStatus) (retVal *fnpsapi.CallbackResponse) {
|
||||||
|
order, err := dao.GetSimpleOrder(dao.GetDB(), msg.PartnerOrderCode)
|
||||||
|
if order == nil || order.VendorOrderID == "" || err != nil {
|
||||||
|
if _, err = fnpsapi.HttpToGuoYuanFN(utils.Struct2MapByJson(reallyData), fnpsapi.FengNiaoCallbackTypeAbnormal); err != nil {
|
||||||
|
return fnpsapi.Err2CallbackResponse(err, "")
|
||||||
|
}
|
||||||
|
return fnpsapi.Err2CallbackResponse(nil, "")
|
||||||
|
}
|
||||||
return CurDeliveryHandler.OnWaybillExcept(msg)
|
return CurDeliveryHandler.OnWaybillExcept(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +390,7 @@ func (c *DeliveryHandler) OnWaybillExcept(msg *fnpsapi.AbnormalReportNotify) (re
|
|||||||
VendorWaybillID: msg.PartnerOrderCode,
|
VendorWaybillID: msg.PartnerOrderCode,
|
||||||
VendorWaybillID2: utils.Int64ToStr(msg.OrderId),
|
VendorWaybillID2: utils.Int64ToStr(msg.OrderId),
|
||||||
WaybillVendorID: model.VendorIDFengNiao,
|
WaybillVendorID: model.VendorIDFengNiao,
|
||||||
CourierName: string(msg.CarrierDriverId),
|
CourierName: strconv.FormatInt(msg.CarrierDriverId, 10),
|
||||||
CourierMobile: "",
|
CourierMobile: "",
|
||||||
Status: model.WaybillStatusUnknown, // todo 这里要再确定一下是否只要收到订单异常消息就只简单当成一个消息
|
Status: model.WaybillStatusUnknown, // todo 这里要再确定一下是否只要收到订单异常消息就只简单当成一个消息
|
||||||
VendorStatus: msg.AbnormalCode,
|
VendorStatus: msg.AbnormalCode,
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ func (p PrinterHandler) PrintStore(ctx *jxcontext.Context, store *model.Store, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p PrinterHandler) PrintCancelOrRefundOrder(ctx *jxcontext.Context, printType int, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
func (p PrinterHandler) PrintCancelOrRefundOrder(ctx *jxcontext.Context, printType int, store *model.Store, storeDetail *dao.StoreDetail, order *model.GoodsOrder) (printerStatus *partner.PrinterStatus, err error) {
|
||||||
globals.SugarLogger.Debugf("==============storeDetail := %s", utils.Format4Output("=====================kkk", false))
|
|
||||||
if len(order.Skus) == 0 {
|
if len(order.Skus) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -151,8 +150,6 @@ func (p PrinterHandler) PrintCancelOrRefundOrder(ctx *jxcontext.Context, printTy
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
globals.SugarLogger.Debugf("=======PrintCancelOrRefundOrder== : %s , %s", utils.Format4Output(content, false), store.PrinterSN)
|
|
||||||
|
|
||||||
return p.PrintMsg(ctx, store.PrinterSN, "", voiceType, content)
|
return p.PrintMsg(ctx, store.PrinterSN, "", voiceType, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,17 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi/fnpsapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
|
||||||
"git.rosy.net.cn/jx-callback/business/partner/delivery/fn"
|
"git.rosy.net.cn/jx-callback/business/partner/delivery/fn"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
"github.com/astaxie/beego/server/web"
|
"github.com/astaxie/beego/server/web"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FnController struct {
|
type FnController struct {
|
||||||
@@ -14,14 +21,14 @@ type FnController struct {
|
|||||||
// 门店回掉
|
// 门店回掉
|
||||||
func (c *FnController) FnStore() {
|
func (c *FnController) FnStore() {
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
msg, callbackResponse := api.FnAPI.GetChainstoreStatusNotify(c.Ctx.Request)
|
msg, reallyData, callbackResponse := api.FnAPI.GetChainstoreStatusNotify(c.Ctx.Request)
|
||||||
if callbackResponse.Code == -1 {
|
if callbackResponse.Code == -1 {
|
||||||
c.Data["code"] = callbackResponse
|
c.Data["code"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
callbackResponse = fn.OnStoreStatus(msg)
|
callbackResponse = fn.OnStoreStatus(msg, reallyData)
|
||||||
c.Data["code"] = callbackResponse
|
c.Data["code"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
} else {
|
} else {
|
||||||
@@ -51,17 +58,63 @@ func (c *FnController) FnOrder() {
|
|||||||
// 异常回调
|
// 异常回调
|
||||||
func (c *FnController) FnAbnormal() {
|
func (c *FnController) FnAbnormal() {
|
||||||
if c.Ctx.Input.Method() == http.MethodPost {
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
msg, callbackResponse := api.FnAPI.GetChainAbnormaltatusNotify(c.Ctx.Request)
|
msg, reallyData, callbackResponse := api.FnAPI.GetChainAbnormaltatusNotify(c.Ctx.Request)
|
||||||
if callbackResponse.Code == -1 {
|
if callbackResponse.Code == -1 {
|
||||||
c.Data["json"] = callbackResponse
|
c.Data["json"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
callbackResponse = fn.OnWaybillExceptFn(msg.Param)
|
callbackResponse = fn.OnWaybillExceptFn(msg.Param, reallyData)
|
||||||
c.Data["code"] = callbackResponse
|
c.Data["code"] = callbackResponse
|
||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
} else {
|
} else {
|
||||||
c.Abort("404")
|
c.Abort("404")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FnToken 更新token
|
||||||
|
func (c *FnController) FnToken() {
|
||||||
|
var tokenInfo struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
RefreshToken string `json:"refresh_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Ctx.Input.Method() == http.MethodPost {
|
||||||
|
data, err := ioutil.ReadAll(c.Ctx.Request.Body)
|
||||||
|
if err != nil {
|
||||||
|
c.Data["json"] = &fnpsapi.SignatureIsNotOk
|
||||||
|
c.ServeJSON()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var token = &tokenInfo
|
||||||
|
if err = json.Unmarshal(data, &token); err != nil {
|
||||||
|
c.Data["json"] = &fnpsapi.SignatureIsNotOk
|
||||||
|
c.ServeJSON()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
db := dao.GetDB()
|
||||||
|
curConfig := &legacymodel.Config{
|
||||||
|
Thirdparty: "fn",
|
||||||
|
}
|
||||||
|
if err = dao.GetEntity(db, curConfig); err != nil {
|
||||||
|
c.Data["json"] = &fnpsapi.SignatureIsNotOk
|
||||||
|
c.ServeJSON()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
curConfig.Token = token.Token
|
||||||
|
curConfig.RefreshToken = token.RefreshToken
|
||||||
|
curConfig.Date = utils.Time2Str(time.Now())
|
||||||
|
api.FnAPI.SetToken(curConfig.Token)
|
||||||
|
api.FnAPI.SetRefreshToken(curConfig.RefreshToken)
|
||||||
|
|
||||||
|
dao.UpdateEntity(db, curConfig, "Token", "RefreshToken", "Date")
|
||||||
|
c.Data["json"] = &fnpsapi.SuccessResponse
|
||||||
|
c.ServeJSON()
|
||||||
|
} else {
|
||||||
|
c.Abort("404")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user