From 58d436eb56f94a3710d56cd2495d2d988e94cbe9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Sun, 19 Jan 2020 18:08:20 +0800 Subject: [PATCH] Djsw2Controller --- controllers/jd2_callback.go | 209 ++++++++++++++++++++++++++++++++++++ routers/router.go | 1 + 2 files changed, 210 insertions(+) create mode 100644 controllers/jd2_callback.go diff --git a/controllers/jd2_callback.go b/controllers/jd2_callback.go new file mode 100644 index 000000000..44723cd85 --- /dev/null +++ b/controllers/jd2_callback.go @@ -0,0 +1,209 @@ +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/partner/purchase/jd" + "git.rosy.net.cn/jx-callback/globals" + "github.com/astaxie/beego" +) + +// Operations about JDOrder +type Djsw2Controller struct { + beego.Controller +} + +func (c *Djsw2Controller) handleMsg(handler func(*jdapi.API, interface{}) *jdapi.CallbackResponse) (callbackResponse *jdapi.CallbackResponse) { + // callbackMsg, mapData, callbackResponse := jdapi.GetCallbackMsg(getUsefulRequest(c.Ctx)) + // globals.SugarLogger.Debug(utils.Format4Output(callbackMsg, true)) + // if callbackResponse == nil { + // if jdAPI := jd.GetAPI(jd.AppKey2OrgCode(callbackMsg.AppKey)); jdAPI != nil { + // if callbackResponse = jdAPI.CheckCallbackValidation(mapData, callbackMsg.Sign); callbackResponse == nil { + // callbackResponse = handler(jdAPI, callbackMsg.Param) + // } + // } else { + // callbackResponse = jdapi.Err2CallbackResponse(fmt.Errorf("没有匹配的appKey,非法请求"), "") + // } + // } + return callbackResponse +} + +func (c *Djsw2Controller) orderStatus() { + if c.Ctx.Input.Method() == http.MethodPost { + callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) { + callbackResponse = jd.OnOrderMsg(obj.(*jdapi.CallbackOrderMsg)) + return callbackResponse + }) + c.Data["json"] = c.transferResponse("orderStatus", callbackResponse) + c.ServeJSON() + } else { + c.Abort("404") + } +} + +func (c *Djsw2Controller) NewOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) OrderAdjust() { + c.orderStatus() +} + +func (c *Djsw2Controller) OrderWaitOutStore() { + c.orderStatus() +} + +func (c *Djsw2Controller) PickFinishOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) DeliveryOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) FinishOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) LockOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) UnlockOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) UserCancelOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) ApplyCancelOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) VenderAuditApplyCancelOrder() { + c.orderStatus() +} + +func (c *Djsw2Controller) PushDeliveryStatus() { + if c.Ctx.Input.Method() == http.MethodPost { + callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) { + callbackResponse = jd.OnWaybillMsg(obj.(*jdapi.CallbackDeliveryStatusMsg)) + return callbackResponse + }) + c.Data["json"] = c.transferResponse("PushDeliveryStatus", callbackResponse) + c.ServeJSON() + } else { + c.Abort("404") + } +} + +func (c *Djsw2Controller) OrderCommentPush() { + c.orderStatus() +} + +func (c *Djsw2Controller) 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("Token", nil) + c.ServeJSON() +} + +func (c *Djsw2Controller) StockIsHave() { + // globals.SugarLogger.Info(string(c.Ctx.Input.RequestBody)) + if c.Ctx.Input.Method() == http.MethodPost { + callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) { + return callbackResponse + }) + c.Data["json"] = c.transferResponse("StockIsHave", callbackResponse) + c.ServeJSON() + } else { + c.Abort("404") + } +} + +func (c *Djsw2Controller) SinglePromoteCreate() { + if c.Ctx.Input.Method() == http.MethodPost { + callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) { + callbackResponse = jd.OnActMsg(obj.(*jdapi.CallbackOrderMsg)) + return callbackResponse + }) + c.Data["json"] = c.transferResponse("SinglePromoteCreate", callbackResponse) + c.ServeJSON() + } else { + c.Abort("404") + } +} + +func (c *Djsw2Controller) StoreCrud() { + if c.Ctx.Input.Method() == http.MethodPost { + callbackResponse := c.handleMsg(func(a *jdapi.API, obj interface{}) (callbackResponse *jdapi.CallbackResponse) { + callbackResponse = jd.OnStoreMsg(obj.(*jdapi.CallbackOrderMsg)) + return callbackResponse + }) + c.Data["json"] = c.transferResponse("StoreCrud", callbackResponse) + c.ServeJSON() + } else { + c.Abort("404") + } +} + +func (c *Djsw2Controller) transferResponse(funcName string, inCallbackResponse *jdapi.CallbackResponse) (outCallbackResponse *jdapi.CallbackResponse) { + if globals.IsCallbackAlwaysReturnSuccess() { + return jdapi.SuccessResponse + } + if inCallbackResponse == nil { + return jdapi.SuccessResponse + } + globals.SugarLogger.Debugf("%s callbackResponse:%s", funcName, utils.Format4Output(inCallbackResponse, true)) + return inCallbackResponse +} + +func (c *Djsw2Controller) EndOrderFinance() { + c.nullOperation() +} + +func (c *Djsw2Controller) FinanceAdjustment() { + c.nullOperation() +} + +func (c *Djsw2Controller) DeliveryCarrierModify() { + c.nullOperation() +} + +func (c *Djsw2Controller) NewApplyAfterSaleBill() { + c.nullOperation() +} + +func (c *Djsw2Controller) UpdateApplyAfterSaleBill() { + c.nullOperation() +} + +func (c *Djsw2Controller) NewAfterSaleBill() { + c.nullOperation() +} + +func (c *Djsw2Controller) AfterSaleBillStatus() { + c.orderStatus() +} + +func (c *Djsw2Controller) OrderAccounting() { + c.orderStatus() +} + +func (c *Djsw2Controller) nullOperation() { + c.Data["json"] = c.transferResponse("nullOperation", nil) + c.ServeJSON() +} + +func (c *Djsw2Controller) UpdateSku() { + c.nullOperation() +} + +func (c *Djsw2Controller) OrderAddTips() { + c.orderStatus() +} diff --git a/routers/router.go b/routers/router.go index 25c299a46..e12b6a539 100644 --- a/routers/router.go +++ b/routers/router.go @@ -154,6 +154,7 @@ func init() { beego.AutoRouter(&controllers.WeixinController{}) beego.AutoRouter(&controllers.DingDingController{}) beego.AutoRouter(&controllers.WXPayController{}) + beego.AutoRouter(&controllers.Djsw2Controller{}) // 如下都是用于检测存活的空接口 beego.Any("/", func(ctx *beecontext.Context) {