将菜市蜂鸟信息通知到果园去
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user