package controllers

import (
	"fmt"
	"git.rosy.net.cn/jx-callback/business/partner/delivery/fn"
	"git.rosy.net.cn/jx-callback/globals/api"
	"github.com/astaxie/beego/server/web"
	"net/http"
)

type FnController struct {
	web.Controller
}


// 门店回掉
func (c *FnController) FnStore() {
	if c.Ctx.Input.Method() == http.MethodPost {
		fmt.Println("开始回调门店回掉==========================")
		msg, callbackResponse := api.FnAPI.GetChainstoreStatusNotify(c.Ctx.Request)
		fmt.Println("开始回调门店回掉==========================msg", msg)
		fmt.Println("开始回调门店回掉==========================callbackResponse", callbackResponse)
		if callbackResponse.Code == -1 {
			c.Data["code"] = callbackResponse
			c.ServeJSON()
			return
		}

		callbackResponse = fn.OnStoreStatus(msg)
		c.Data["code"] = callbackResponse
		c.ServeJSON()
	} else {
		c.Abort("404")
	}
}

// 订单状态
func (c *FnController) FnOrder() {
	if c.Ctx.Input.Method() == http.MethodPost {
		fmt.Println("开始回调订单状态==========================")
		msg, callbackResponse := api.FnAPI.GetChainOrderStatusNotify(c.Ctx.Request)
		fmt.Println("开始回调订单状态==========================msg", msg)
		fmt.Println("开始回调订单状态==========================callbackResponse", callbackResponse)
		if callbackResponse.Code == -1 {
			c.Data["code"] = callbackResponse
			c.ServeJSON()
			return
		}

		// 订单回调
		callbackResponse = fn.OnWaybillMsg(msg)
		c.Data["code"] = callbackResponse
		c.ServeJSON()
	} else {
		c.Abort("404")
	}
}

// 异常回调
func (c *FnController) FnAbnormal() {
	if c.Ctx.Input.Method() == http.MethodPost {
		fmt.Println("开始回调异常回调==========================")
		msg, callbackResponse := api.FnAPI.GetChainAbnormaltatusNotify(c.Ctx.Request)
		fmt.Println("开始回调异常回调==========================msg", msg)
		fmt.Println("开始回调异常回调==========================callbackResponse", callbackResponse)
		if callbackResponse.Code == -1 {
			c.Data["json"] = callbackResponse
			c.ServeJSON()
			return
		}

		callbackResponse = fn.OnWaybillExceptFn(msg.Param)
		c.Data["code"] = callbackResponse
		c.ServeJSON()
	} else {
		c.Abort("404")
	}
}

