161 lines
4.6 KiB
Go
161 lines
4.6 KiB
Go
package controllers
|
|
|
|
import (
|
|
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
|
"git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm"
|
|
"git.rosy.net.cn/jx-callback/globals/api"
|
|
"github.com/astaxie/beego/server/web"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
type MtwmController struct {
|
|
web.Controller
|
|
}
|
|
|
|
func (c *MtwmController) onCallbackMsg(msgType string) {
|
|
c.Data["json"] = mtwmapi.Err2CallbackResponse(nil, "")
|
|
msg, callbackResponse := api.MtwmAPI.GetCallbackMsg(c.Ctx.Request)
|
|
if callbackResponse == nil {
|
|
// 定时任务在拉去,暂时不推送了
|
|
//if web.BConfig.RunMode != "jxgy" { // 订单查询不到所属门店默认为果园订单
|
|
// vendorStoreId := msg.FormData.Get("app_poi_code")
|
|
// if vendorStoreId == "" {
|
|
// vendorStoreId = msg.FormData.Get("wm_poi_id")
|
|
// }
|
|
// if msgType == mtwmapi.MsgTypeOrderFinishedPickup {
|
|
// finishedPickup := FinishedPickup{}
|
|
// json.Unmarshal([]byte(msg.FormData.Get("pick_up_data")), &finishedPickup)
|
|
// vendorStoreId = finishedPickup.AppPoiCode
|
|
// }
|
|
// if vendorStoreId != "" {
|
|
// storeDetail, err2 := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), vendorStoreId, model.VendorIDMTWM, "")
|
|
//
|
|
// if storeDetail == nil {
|
|
// // 推送到果园
|
|
// if vendorStoreId == "9472886" {
|
|
// globals.SugarLogger.Debugf("=====store:%s", utils.Format4Output(storeDetail, false))
|
|
// globals.SugarLogger.Debugf("=====storeerr2:%s", utils.Format4Output(err2, false))
|
|
// globals.SugarLogger.Debugf("=====msg.FormData:%s", utils.Format4Output(msg.FormData, false))
|
|
// globals.SugarLogger.Debugf("=====msgType:%s", utils.Format4Output(msgType, false))
|
|
// }
|
|
// pushMTWMOrder2GY(msg.FormData, msgType)
|
|
// c.Data["json"] = mtwmapi.Err2CallbackResponse(nil, "")
|
|
// c.ServeJSON()
|
|
// return
|
|
// }
|
|
// }
|
|
//}
|
|
callbackResponse = mtwm.OnCallbackMsg(msg, msgType)
|
|
if callbackResponse == nil {
|
|
callbackResponse = mtwmapi.Err2CallbackResponse(nil, "")
|
|
}
|
|
}
|
|
|
|
c.Data["json"] = mtwmapi.Err2CallbackResponse(nil, "")
|
|
//c.Data["json"] = callbackResponse
|
|
c.ServeJSON()
|
|
}
|
|
|
|
func (c *MtwmController) WaybillStatus() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeWaybillStatus)
|
|
}
|
|
|
|
func (c *MtwmController) NewOrder() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeNewOrder)
|
|
}
|
|
|
|
func (c *MtwmController) OrderAccepted() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderAccepted)
|
|
}
|
|
|
|
func (c *MtwmController) OrderFinished() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderFinished)
|
|
}
|
|
|
|
func (c *MtwmController) OrderFinancial() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderFinancial)
|
|
}
|
|
|
|
func (c *MtwmController) UserUrgeOrder() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeUserUrgeOrder)
|
|
}
|
|
|
|
func (c *MtwmController) NumberDowngrade() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypePrivateNumberDowngrade)
|
|
}
|
|
|
|
func (c *MtwmController) OrderModified() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderModified)
|
|
}
|
|
|
|
func (c *MtwmController) OrderCanceled() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderCanceled)
|
|
}
|
|
|
|
func (c *MtwmController) OrderRefund() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderRefund)
|
|
}
|
|
|
|
func (c *MtwmController) OrderPartialRefund() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderPartialRefund)
|
|
}
|
|
|
|
func (c *MtwmController) StoreStatusChanged() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeStoreStatusChanged)
|
|
}
|
|
|
|
func (c *MtwmController) OrderFinishedPickup() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeOrderFinishedPickup)
|
|
}
|
|
|
|
func (c *MtwmController) StoreAuditStatusChanged() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeStoreAuditStatusChanged)
|
|
}
|
|
|
|
func (c *MtwmController) SkuDelete() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeSkuDelete)
|
|
}
|
|
|
|
func (c *MtwmController) StoreBind() {
|
|
c.onCallbackMsg(mtwmapi.MsgTypeStoreBind)
|
|
}
|
|
|
|
func (c *MtwmController) IMCallback() {
|
|
c.OnIMCallback()
|
|
}
|
|
|
|
func (c *MtwmController) OnIMCallback() {
|
|
c.Data["json"] = mtwmapi.Err2CallbackResponse(nil, "")
|
|
msg, callbackResponse := api.MtwmAPI.GetIMCallbackMsg(c.Ctx.Request)
|
|
if callbackResponse == nil {
|
|
callbackResponse = mtwm.OnImMsg(msg)
|
|
if callbackResponse == nil {
|
|
callbackResponse = mtwmapi.Err2CallbackResponse(nil, "")
|
|
}
|
|
}
|
|
c.Data["json"] = callbackResponse
|
|
c.ServeJSON()
|
|
}
|
|
|
|
type FinishedPickup struct {
|
|
AppPoiCode string `json:"app_poi_code"`
|
|
ConsumingTime int `json:"consuming_time"`
|
|
OrderId int64 `json:"order_id"`
|
|
OrderViewId int64 `json:"order_view_id"`
|
|
PickTime string `json:"pick_time"`
|
|
PickType string `json:"pick_type"`
|
|
}
|
|
|
|
// 订单所属门店在菜市不存在时尝试推送到果园去
|
|
func pushMTWMOrder2GY(value url.Values, msgType string) {
|
|
cl := http.Client{}
|
|
request, err := http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/mtwm/"+msgType, strings.NewReader(value.Encode()))
|
|
if err != nil {
|
|
return
|
|
}
|
|
request.Header.Set("Content-Type", "multipart/form-data; charset=UTF-8")
|
|
cl.Do(request)
|
|
}
|