package controllers import ( "bytes" "io/ioutil" "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" "github.com/astaxie/beego/context" ) // 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(getUsefulRequest(c.Ctx)) } else { obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(getUsefulRequest(c.Ctx)) } globals.SugarLogger.Debug(utils.Format4Output(obj, false)) 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(getUsefulRequest(c.Ctx)) 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(getUsefulRequest(c.Ctx)) 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(getUsefulRequest(c.Ctx)) 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(getUsefulRequest(c.Ctx)) 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) EndOrderFinance() { c.nullOperation() } func (c *DjswController) FinanceAdjustment() { c.nullOperation() } func (c *DjswController) DeliveryCarrierModify() { c.nullOperation() } func (c *DjswController) NewApplyAfterSaleBill() { c.nullOperation() } func (c *DjswController) UpdateApplyAfterSaleBill() { c.nullOperation() } func (c *DjswController) NewAfterSaleBill() { c.nullOperation() } func (c *DjswController) AfterSaleBillStatus() { // c.orderStatus(false) c.OrderAccounting() } func (c *DjswController) OrderAccounting() { var obj *jdapi.CallbackOrderMsg var callbackResponse *jdapi.CallbackResponse obj, callbackResponse = api.JdAPI.GetOrderCallbackMsg(getUsefulRequest(c.Ctx)) if callbackResponse == nil { callbackResponse = jd.OnFinancialMsg2(obj) } c.Data["json"] = c.transferResponse(callbackResponse) c.ServeJSON() } func getUsefulRequest(ctx *context.Context) *http.Request { ctx.Request.Body = ioutil.NopCloser(bytes.NewReader(ctx.Input.RequestBody)) return ctx.Request } func (c *DjswController) nullOperation() { c.Data["json"] = c.transferResponse(nil) c.ServeJSON() }