package controllers

import (
	"net/http"

	"git.rosy.net.cn/baseapi/platformapi/ebaiapi"
	"git.rosy.net.cn/jx-callback/business/partner/purchase/ebai"
	"git.rosy.net.cn/jx-callback/globals/api"
	"github.com/astaxie/beego/server/web"
)

type EbaiController struct {
	web.Controller
}

func (c *EbaiController) Msg() {
	if c.Ctx.Input.Method() == http.MethodPost {
		obj, callbackResponse := api.EbaiAPI.GetCallbackMsg(c.Ctx.Request)
		if callbackResponse == nil {
			callbackResponse = ebai.OnCallbackMsg(obj)
		}
		if callbackResponse == nil {
			callbackResponse = api.EbaiAPI.Err2CallbackResponse(ebaiapi.GetCmd(c.Ctx.Request), nil, nil)
		}
		c.Data["json"] = callbackResponse
		c.ServeJSON()
	} else {
		c.Abort("404")
	}
}
