diff --git a/business/jxutils/tasks/configrefresh.go b/business/jxutils/tasks/configrefresh.go index b4bbd90b2..3041941d4 100644 --- a/business/jxutils/tasks/configrefresh.go +++ b/business/jxutils/tasks/configrefresh.go @@ -2,6 +2,7 @@ package tasks import ( "fmt" + "git.rosy.net.cn/baseapi/platformapi/fnpsapi" "io/ioutil" "net/http" "time" @@ -20,7 +21,6 @@ import ( "git.rosy.net.cn/jx-callback/globals" "github.com/astaxie/beego/client/orm" - beego "github.com/astaxie/beego/server/web" ) const ( @@ -159,14 +159,11 @@ func RefreshFnToken() (err error) { dao.ExecuteSQL(dao.GetDB(), sql, []interface{}{ token, refreshToken, "fn", }) - //} - if beego.BConfig.RunMode == "jxgy" { - config := &legacymodel.Config{} - sql := `SELECT * FROM config WHERE thirdparty = 'fn'` - if err := dao.GetRow(dao.GetDB(), &config, sql, nil); err == nil { - token = config.Token - } + + if _, err = fnpsapi.HttpToGuoYuanFN(map[string]interface{}{"token": curConfig.Token, "refresh_token": curConfig.RefreshToken}, fnpsapi.FengNiaoCallbackTypeToken); err != nil { + globals.SugarLogger.Debugf("菜市token通知到果园错误:%v", err) } + return token, expireTimeStr, refreshToken }, func(value, v2 string) { api.FnAPI.SetToken(value) diff --git a/business/partner/delivery/fn/store.go b/business/partner/delivery/fn/store.go index d9604bd80..435126034 100644 --- a/business/partner/delivery/fn/store.go +++ b/business/partner/delivery/fn/store.go @@ -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) } diff --git a/business/partner/delivery/fn/waybill.go b/business/partner/delivery/fn/waybill.go index 2804e5434..e689bc21d 100644 --- a/business/partner/delivery/fn/waybill.go +++ b/business/partner/delivery/fn/waybill.go @@ -7,6 +7,7 @@ import ( "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/partner/purchase/tao_vegetable" + "strconv" "strings" "time" @@ -247,6 +248,15 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify, resultParam *fnpsapi.ShortSta if err := utils.Map2StructByJson(msg.Param, cc, true); err != nil { 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 { 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{ VendorWaybillID: utils.Int64ToStr(cc.OrderId), 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) } @@ -385,7 +390,7 @@ func (c *DeliveryHandler) OnWaybillExcept(msg *fnpsapi.AbnormalReportNotify) (re VendorWaybillID: msg.PartnerOrderCode, VendorWaybillID2: utils.Int64ToStr(msg.OrderId), WaybillVendorID: model.VendorIDFengNiao, - CourierName: string(msg.CarrierDriverId), + CourierName: strconv.FormatInt(msg.CarrierDriverId, 10), CourierMobile: "", Status: model.WaybillStatusUnknown, // todo 这里要再确定一下是否只要收到订单异常消息就只简单当成一个消息 VendorStatus: msg.AbnormalCode, diff --git a/business/partner/printer/trendit/trendit.go b/business/partner/printer/trendit/trendit.go index 28007e4db..2d08b6fe8 100644 --- a/business/partner/printer/trendit/trendit.go +++ b/business/partner/printer/trendit/trendit.go @@ -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) { - globals.SugarLogger.Debugf("==============storeDetail := %s", utils.Format4Output("=====================kkk", false)) if len(order.Skus) == 0 { return } @@ -151,8 +150,6 @@ func (p PrinterHandler) PrintCancelOrRefundOrder(ctx *jxcontext.Context, printTy return nil, nil } - globals.SugarLogger.Debugf("=======PrintCancelOrRefundOrder== : %s , %s", utils.Format4Output(content, false), store.PrinterSN) - return p.PrintMsg(ctx, store.PrinterSN, "", voiceType, content) } diff --git a/controllers/fn_callback.go b/controllers/fn_callback.go index 997fe77fc..92e5f5eef 100644 --- a/controllers/fn_callback.go +++ b/controllers/fn_callback.go @@ -1,10 +1,17 @@ package controllers 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/globals/api" "github.com/astaxie/beego/server/web" + "io/ioutil" "net/http" + "time" ) type FnController struct { @@ -14,14 +21,14 @@ type FnController struct { // 门店回掉 func (c *FnController) FnStore() { 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 { c.Data["code"] = callbackResponse c.ServeJSON() return } - callbackResponse = fn.OnStoreStatus(msg) + callbackResponse = fn.OnStoreStatus(msg, reallyData) c.Data["code"] = callbackResponse c.ServeJSON() } else { @@ -51,17 +58,63 @@ func (c *FnController) FnOrder() { // 异常回调 func (c *FnController) FnAbnormal() { 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 { c.Data["json"] = callbackResponse c.ServeJSON() return } - callbackResponse = fn.OnWaybillExceptFn(msg.Param) + callbackResponse = fn.OnWaybillExceptFn(msg.Param, reallyData) c.Data["code"] = callbackResponse c.ServeJSON() } else { 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") + } +}