Files
jx-callback/controllers/jd_callback.go
2019-05-07 14:50:27 +08:00

179 lines
4.4 KiB
Go

package controllers
import (
"net/http"
"git.rosy.net.cn/baseapi/platformapi/jdapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/promotion"
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
"git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api"
"github.com/astaxie/beego"
)
// Operations about JDOrder
type DjswController struct {
beego.Controller
}
func (c *DjswController) orderStatus(isCancelOrder bool) {
if c.Ctx.Input.Method() == http.MethodPost {
var obj *jdapi.CallbackOrderMsg
var callbackResponse *jdapi.CallbackResponse
if isCancelOrder {
obj, callbackResponse = api.JdAPI.GetOrderApplyCancelCallbackMsg(c.Ctx.Input.RequestBody)
} else {
obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
}
if callbackResponse == nil {
callbackResponse = jd.OnOrderMsg(obj)
}
c.Data["json"] = c.transferResponse(callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
}
func (c *DjswController) NewOrder() {
c.orderStatus(false)
}
func (c *DjswController) OrderAdjust() {
c.orderStatus(false)
}
func (c *DjswController) OrderWaitOutStore() {
c.orderStatus(false)
}
func (c *DjswController) PickFinishOrder() {
c.orderStatus(false)
}
func (c *DjswController) DeliveryOrder() {
c.orderStatus(false)
}
func (c *DjswController) FinishOrder() {
c.orderStatus(false)
}
func (c *DjswController) LockOrder() {
c.orderStatus(false)
}
func (c *DjswController) UnlockOrder() {
c.orderStatus(false)
}
func (c *DjswController) UserCancelOrder() {
c.orderStatus(false)
}
func (c *DjswController) ApplyCancelOrder() {
c.orderStatus(true)
}
func (c *DjswController) PushDeliveryStatus() {
if c.Ctx.Input.Method() == http.MethodPost {
obj, callbackResponse := api.JdAPI.GetOrderDeliveryCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
callbackResponse = jd.OnWaybillMsg(obj)
}
c.Data["json"] = c.transferResponse(callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
}
func (c *DjswController) OrderCommentPush() {
c.orderStatus(false)
}
func (c *DjswController) Token() {
urlValues, err := utils.HTTPBody2Values(c.Ctx.Input.RequestBody, false)
if err == nil {
globals.SugarLogger.Info(utils.Format4Output(utils.URLValues2Map(urlValues), false))
}
c.Data["json"] = c.transferResponse(nil)
c.ServeJSON()
}
func (c *DjswController) StockIsHave() {
// globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody))
if c.Ctx.Input.Method() == http.MethodPost {
obj, callbackResponse := api.JdAPI.GetStoreStockCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
// globals.SugarLogger.Debugf("StockIsHave, obj:%s", utils.Format4Output(obj, false))
callbackResponse = promotion.OnStoreStockMsg(obj)
}
c.Data["json"] = c.transferResponse(callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
}
func (c *DjswController) SinglePromoteCreate() {
if c.Ctx.Input.Method() == http.MethodPost {
obj, callbackResponse := api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
callbackResponse = promotion.OnNewPromotionMsg(obj)
}
c.Data["json"] = c.transferResponse(callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
}
func (c *DjswController) StoreCrud() {
if c.Ctx.Input.Method() == http.MethodPost {
obj, callbackResponse := api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
callbackResponse = jd.OnStoreMsg(obj)
}
c.Data["json"] = c.transferResponse(callbackResponse)
c.ServeJSON()
} else {
c.Abort("404")
}
}
func (c *DjswController) transferResponse(inCallbackResponse *jdapi.CallbackResponse) (outCallbackResponse *jdapi.CallbackResponse) {
if globals.IsCallbackAlwaysReturnSuccess() {
return jdapi.SuccessResponse
}
if inCallbackResponse == nil {
return jdapi.SuccessResponse
}
return inCallbackResponse
}
func (c *DjswController) afterSaleBillStatus() {
var obj *jdapi.CallbackOrderMsg
var callbackResponse *jdapi.CallbackResponse
obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(c.Ctx.Input.RequestBody)
if callbackResponse == nil {
callbackResponse = jd.OnAfterSaleMsg(obj)
}
c.Data["json"] = c.transferResponse(callbackResponse)
c.ServeJSON()
}
func (c *DjswController) NewAfterSaleBill() {
c.afterSaleBillStatus()
}
func (c *DjswController) AfterSaleBillStatus() {
c.afterSaleBillStatus()
}
func (c *DjswController) OrderAccounting() {
c.afterSaleBillStatus()
}