package controllers import ( "git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/jx-callback/business/model" "net/http" "strings" "git.rosy.net.cn/baseapi/platformapi/ebaiapi" "git.rosy.net.cn/jx-callback/business/partner/purchase/ebai" "git.rosy.net.cn/jx-callback/globals/api" "github.com/astaxie/beego/server/web" ) type EbaiController struct { web.Controller } func (c *EbaiController) Msg() { if c.Ctx.Input.Method() == http.MethodPost { obj, callbackResponse := api.EbaiAPI.GetCallbackMsg(c.Ctx.Request) if callbackResponse == nil { vendorStoreId := obj.Body["platform_shop_id"].(string) if vendorStoreId != "" { //storeDetail, _ := dao.GetStoreDetailByVendorStoreID(dao.GetDB(), vendorStoreId, model.VendorIDEBAI, "") //if storeDetail == nil { // globals.SugarLogger.Debugf("-----饿百订单非菜市消息推送-%s", utils.Format4Output(obj, false)) // switch beego.BConfig.RunMode { // case model.ServerTypeVegetable: // callbackResponse = c.EBaiMsgPush2FruitsOrPet(model.ServerTypeFruits, utils.Struct2Map(obj, "", false)) // case model.ServerTypeFruits: // callbackResponse = c.EBaiMsgPush2FruitsOrPet(model.ServerTypePet, utils.Struct2Map(obj, "", false)) // case model.ServerTypePet: // ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "47B1E94E8D2411EFB666525400E86DC0", "饿了么菜市推果园,果园退超市未找到门店", fmt.Sprintf("cmd:%s,storeId:%s", obj.Cmd, vendorStoreId)) // callbackResponse = api.EbaiAPI.Err2CallbackResponse(ebaiapi.GetCmd(c.Ctx.Request), nil, nil) // api.EbaiAPI.Err2CallbackResponse(ebaiapi.GetCmd(c.Ctx.Request), fmt.Errorf("饿了么菜市推果园,果园退超市未找到门店cmd:%s,storeId:%s", obj.Cmd, vendorStoreId), nil) // return // } // c.Data["json"] = callbackResponse // c.ServeJSON() // return //} } callbackResponse = ebai.OnCallbackMsg(obj) } if callbackResponse == nil { callbackResponse = api.EbaiAPI.Err2CallbackResponse(ebaiapi.GetCmd(c.Ctx.Request), nil, nil) } c.Data["json"] = callbackResponse c.ServeJSON() } else { c.Abort("404") } } func (c *EbaiController) EBaiMsgPush2FruitsOrPet(serverType string, msg map[string]interface{}) *ebaiapi.CallbackResponse { cl := http.Client{} var request *http.Request var err error switch serverType { case model.ServerTypeFruits: request, err = http.NewRequest(http.MethodPost, "http://callback-jxgy.jxc4.com/ebai/msg", strings.NewReader(utils.Map2URLValues(msg).Encode())) if err != nil { return api.EbaiAPI.Err2CallbackResponse(ebaiapi.GetCmd(c.Ctx.Request), err, nil) } case model.ServerTypePet: request, err = http.NewRequest(http.MethodPost, "http://callback-gblm.jxc4.com/mtps/status", strings.NewReader(utils.Map2URLValues(msg).Encode())) if err != nil { return api.EbaiAPI.Err2CallbackResponse(ebaiapi.GetCmd(c.Ctx.Request), err, nil) } } request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") _, err = cl.Do(request) return api.EbaiAPI.Err2CallbackResponse(ebaiapi.GetCmd(c.Ctx.Request), err, nil) }