Files
jx-callback/controllers/jd_order.go
2018-06-13 11:12:28 +08:00

156 lines
4.3 KiB
Go

package controllers
import (
"encoding/json"
"net/url"
"github.com/astaxie/beego/logs"
"git.rosy.net.cn/baseapi/platform/jdapi"
"git.rosy.net.cn/jx-callback/business/jd/controller"
"git.rosy.net.cn/jx-callback/globals"
"github.com/astaxie/beego"
)
const JD_PARAM_JSON = "jd_param_json"
// Operations about JDOrder
type JDOrderController struct {
beego.Controller
}
func (c *JDOrderController) URLMapping() {
c.Mapping("NewOrder", c.NewOrder)
}
func (c *JDOrderController) handleJDCallback(obj interface{}, needUnescape bool, hanlder func() interface{}) {
jdParamJSON := c.GetString(JD_PARAM_JSON)
if needUnescape {
jdParamJSON2, err := url.QueryUnescape(jdParamJSON)
if err != nil {
globals.SugarLogger.Warnf("can not escape data:%v, error:%v", jdParamJSON, err)
}
jdParamJSON = jdParamJSON2
}
err := json.Unmarshal([]byte(jdParamJSON), obj)
if err != nil {
logs.Error(err)
c.Data["json"] = jdapi.JDOrderMsgResponse{jdapi.JDerrorCodeMissingMandatoryParam, "jd_param_json format is wrong", jdParamJSON}
} else {
c.Data["json"] = hanlder()
}
c.ServeJSON()
}
func (c *JDOrderController) orderStatus() {
var ob jdapi.JDOrderMsg
c.handleJDCallback(&ob, false, func() interface{} {
cc := controller.OrderControler{}
return cc.OrderStatus(&ob)
})
}
// @Title newOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /newOrder [post]
func (c *JDOrderController) NewOrder() {
c.orderStatus()
}
// @Title AdjustOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /orderAdjust [post]
func (c *JDOrderController) OrderAdjust() {
c.orderStatus()
}
// @Title orderWaitOutStore
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /orderWaitOutStore [post]
func (c *JDOrderController) OrderWaitOutStore() {
c.orderStatus()
}
// @Title pickFinishOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /pickFinishOrder [post]
func (c *JDOrderController) PickFinishOrder() {
c.orderStatus()
}
// @Title deliveryOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /deliveryOrder [post]
func (c *JDOrderController) DeliveryOrder() {
c.orderStatus()
}
// @Title finishOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /finishOrder [post]
func (c *JDOrderController) FinishOrder() {
c.orderStatus()
}
// @Title lockOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /lockOrder [post]
func (c *JDOrderController) LockOrder() {
c.orderStatus()
}
// @Title userCancelOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /userCancelOrder [post]
func (c *JDOrderController) UserCancelOrder() {
c.orderStatus()
}
// @Title applyCancelOrder
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /applyCancelOrder [post]
func (c *JDOrderController) ApplyCancelOrder() {
c.orderStatus()
}
// @Title pushDeliveryStatus
// @Description create object
// @Param jd_param_json formData string true "应用级别输入参数"
// @Success 200 {string} models.Object.Id
// @Failure 403 body is empty
// @router /pushDeliveryStatus [post]
func (c *JDOrderController) PushDeliveryStatus() {
var ob jdapi.JDDeliveryStatusMsg
c.handleJDCallback(&ob, true, func() interface{} {
cc := controller.OrderControler{}
return cc.OrderDeliveryStatus(&ob)
})
}