Djsw2Controller

This commit is contained in:
gazebo
2020-01-19 18:08:20 +08:00
parent 9f1ea37b50
commit 58d436eb56
2 changed files with 210 additions and 0 deletions

209
controllers/jd2_callback.go Normal file
View File

@@ -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()
}