Exemplo n.º 1
0
        static void handleOrderAgreeRefund(Newtonsoft.Json.Linq.JObject jsonObj)
        {
            var    message = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonObj.Value <string>("message"));
            var    orderid = message.Value <string>("orderId");
            string reason  = message.Value <string>("reason");

            var refundInfo = new OrderRefundInfo()
            {
                OrderID = orderid,
                Reason  = reason,
                Money   = message.Value <double?>("totalPrice")
            };


            try
            {
                var goodsList = (Newtonsoft.Json.Linq.JArray)message["goodsList"];
                for (int i = 0; i < goodsList.Count; i++)
                {
                    var            good = goodsList[i];
                    RefundDishInfo info = new RefundDishInfo();
                    info.DishName    = good.Value <string>("name");
                    info.Quantity    = good.Value <int>("quantity");
                    info.Price       = good.Value <double>("price");
                    info.RefundPrice = good.Value <double>("price");
                    refundInfo.RefundDishInfos.Add(info);
                }
            }
            catch
            {
            }
            ResturantFactory.ResturantListener.OnOrderRefundCompleted(ResturantPlatformType.Ele, refundInfo);
        }
        public TaskStatus Handle(IHttpProxy httpHandler)
        {
            httpHandler.ResponseContentType = "application/json";
            var forms = httpHandler.Form.ToObject <SortedDictionary <string, string> >();

            try
            {
                if (forms.Count > 0)
                {
                    //验证sign
                    var config = new Config(ResturantFactory.ResturantListener.OnGetPlatformConfigXml(ResturantPlatformType.Meituan));
                    if (forms["sign"] != MeituanHelper.Sign(forms, config.SignKey))
                    {
                        throw new Exception("签名验证失败");
                    }


                    string notifyType = forms["notifyType"];

                    /*
                     * part	发起退款
                     * agree	确认退款
                     * reject	驳回退款
                     */
                    OrderRefundInfo info = new OrderRefundInfo();
                    info.OrderID = forms["orderId"];
                    info.Reason  = forms["reason"];
                    info.Money   = Convert.ToDouble(forms["money"]);
                    if (ResturantFactory.ResturantListener != null)
                    {
                        new Thread(() =>
                        {
                            try
                            {
                                var foodJsonArr = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(forms["food"]);
                                for (int i = 0; i < foodJsonArr.Count; i++)
                                {
                                    var dishinfo         = new RefundDishInfo();
                                    dishinfo.DishName    = foodJsonArr[i].Value <string>("food_name");
                                    dishinfo.ErpDishId   = foodJsonArr[i].Value <string>("app_food_code");
                                    dishinfo.RefundPrice = foodJsonArr[i].Value <double>("refund_price");
                                    dishinfo.Price       = foodJsonArr[i].Value <double>("origin_food_price");
                                    dishinfo.Quantity    = foodJsonArr[i].Value <int>("count");
                                    info.RefundDishInfos.Add(dishinfo);
                                }
                            }
                            catch
                            {
                            }
                            try
                            {
                                if (notifyType == "part")
                                {
                                    ResturantFactory.ResturantListener.OnOrderRefund(ResturantPlatformType.Meituan, info);
                                }
                                else if (notifyType == "agree")
                                {
                                    ResturantFactory.ResturantListener.OnOrderRefundCompleted(ResturantPlatformType.Meituan, info);
                                }
                            }
                            catch { }
                        }).Start();
                    }
                }
            }
            catch (Exception ex)
            {
                using (Log log = new Log("美团OrderPartRefundCallback解析错误"))
                {
                    log.Log(ex.ToString());
                }
                throw ex;
            }
            httpHandler.ResponseWrite("{\"data\":\"OK\"}");

            return(TaskStatus.Completed);
        }