/// <summary> /// 获取用户最新的所有订单的物流信息 /// 查询前三条数据 /// </summary> /// <param name="AppId"></param> /// <param name="Userid"></param> /// <returns></returns> public ResultDTO <ListResult <ComOrderExpressNew> > GetUserAllNewOrderExpressExt(Guid AppId, Guid Userid) { ListResult <ComOrderExpressNew> expressNews = new ListResult <ComOrderExpressNew>(); expressNews.List = new List <ComOrderExpressNew>(); ResultDTO <ListResult <ComOrderExpressNew> > result = new ResultDTO <ListResult <ComOrderExpressNew> >() { isSuccess = false, ResultCode = 1, Data = expressNews }; string json = string.Empty; JObject obj = null; try { LogHelper.Info("【三条---京东】京东物流[开始调用]AppId=" + AppId + " Userid=" + Userid + ""); //获取已发货的订单信息 //var comOrders = CommodityOrder.ObjectSet().Where(p => p.State == 2 && p.UserId == Userid && p.EsAppId == AppId).OrderByDescending(p => p.ModifiedOn).ToList(); var comOrders = CommodityOrder.ObjectSet().Where(p => p.State != 0 && p.UserId == Userid && p.EsAppId == AppId).OrderByDescending(p => p.ModifiedOn).Take(3).ToList(); LogHelper.Info("【三条---京东】京东物流comOrders-->[" + comOrders.Count() + "]"); if (comOrders != null) { List <ExpressTrace> expressList = null; ComOrderExpressNew expressNew = null; foreach (var order in comOrders.ToList()) { expressList = new List <ExpressTrace>(); expressNew = new ComOrderExpressNew(); var OrderItemInfo = OrderItem.ObjectSet().Where(p => p.CommodityOrderId == order.Id).FirstOrDefault(); expressNew.CommodityOrderId = order.Id; //订单id expressNew.Pic = OrderItemInfo.PicturesPath; //首条订单图片 //京东信息 var commodityOrderId = order.Id.ToString(); if (ThirdECommerceHelper.IsJingDongDaKeHu(order.AppId)) { //var jdOrderitem = JdOrderItem.ObjectSet().FirstOrDefault(p => p.CommodityOrderId.Contains(commodityOrderId)); var query = JdOrderItem.ObjectSet().Where(p => p.CommodityOrderId.Contains(commodityOrderId)); //去重后的父单集合 var jdOrderList = query.Select(p => new { p.JdOrderId }).GroupBy(p => p.JdOrderId).ToList(); if (jdOrderList.Any()) { jdOrderList.ForEach(p => { var jdwuliu = JdHelper.orderTrack(p.Key); LogHelper.Info("【三条---京东】京东物流====返回-->[" + jdwuliu + "]"); if (jdwuliu != null) { JArray objson = JArray.Parse(jdwuliu); foreach (var item in objson) { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = DateTime.Parse(item["msgTime"].ToString()); Express.AcceptStation = item["content"].ToString().Trim(); expressList.Add(Express); } AddExpressNewAll(expressNews, expressList, expressNew, "京东"); } }); } } else if (ThirdECommerceHelper.IsWangYiYanXuan(order.AppId))//网易严选或第三方电商 { var orderItem = OrderItem.ObjectSet().FirstOrDefault(p => p.CommodityOrderId == order.Id); var express = ThirdECommerceHelper.GetOrderItemExpressTrace(order.AppId, orderItem.Id); LogHelper.Info("【三条---严选】网易严选物流-->[" + JsonHelper.JsonSerializer(express) + "]"); if (express != null) { if (express.ExpressTraceList != null && express.ExpressTraceList.Count > 0) { express.ExpressTraceList.ForEach(p => { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = p.Time == null ? DateTime.Now : DateTime.Parse(p.Time); Express.AcceptStation = p.Desc; expressList.Add(Express); }); string name = "严选"; var yxExpress = YXExpressTrace.ObjectSet().Where(p => p.OrderId == order.Id).FirstOrDefault(); if (yxExpress != null) { name = yxExpress.ExpressCompany; } AddExpressNewAll(expressNews, expressList, expressNew, name); } } } else if (ThirdECommerceHelper.IsSuNingYiGou(order.AppId))//苏宁店铺 { var snOrderitem = SNOrderItem.ObjectSet().FirstOrDefault(p => p.OrderId == order.Id); SNExpressTraceFacade snExpress = new SNExpressTraceFacade(); var SuningWuliu = snExpress.GetExpressTrace(order.Id.ToString(), snOrderitem.OrderItemId.ToString()); LogHelper.Info("【三条---苏宁】苏宁物流[" + order.Id.ToString() + "," + snOrderitem.OrderItemId.ToString() + "]===返回-->[" + JsonHelper.JsonSerializer(SuningWuliu) + "]"); if (SuningWuliu != null) { SuningWuliu.ForEach(p => { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = p.OperateTime == null ? DateTime.Now : p.OperateTime.Value; Express.AcceptStation = p.OperateState; expressList.Add(Express); }); AddExpressNewAll(expressNews, expressList, expressNew, "苏宁"); } } else if (ThirdECommerceHelper.IsFangZheng(order.AppId))//方正店铺 { var FangZhengWuliu = FangZhengSV.FangZheng_Logistics_InfoList(order.Id); LogHelper.Info("【三条---方正】方正物流[" + commodityOrderId + "]===返回-->[" + JsonHelper.JsonSerializer(FangZhengWuliu) + "]"); if (FangZhengWuliu != null) { FangZhengWuliu.ExpressTraceList.ForEach(p => { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = DateTime.Parse(p.Time); Express.AcceptStation = p.Desc; expressList.Add(Express); }); AddExpressNewAll(expressNews, expressList, expressNew, "方正"); } } else { if (order.ExpOrderNo != null) { json = Express100SV.GetExpressFromKD100(order.ExpOrderNo, order.ShipExpCo); obj = JObject.Parse(json); LogHelper.Info(string.Format("【三条---快递100】快递100:订单Id:{0},物流信息:{1}", order.Id, obj)); if (obj["message"].ToString().ToLower().Equals("ok")) { JToken arr = obj["data"]; foreach (var item in arr) { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = Convert.ToDateTime(item["ftime"].ToString()); Express.AcceptStation = item["context"].ToString().Trim(); expressList.Add(Express); } LogHelper.Info(string.Format("【三条---快递100】arr[{0}]--->expressList[{1}]", arr.Count(), expressList.Count)); //快递单当前签收状态,包括0在途中、1已揽收、2疑难、3已签收、4退签、5同城派送中、6退回、7转单等7个状态,其中4-7需要另外开通才有效 int deliverystatus = Convert.ToInt32(obj["state"].ToString()); LogHelper.Info("【三条---快递100】deliverystatus-->[" + deliverystatus + "]"); if (deliverystatus == 0) { expressNew.shipmentsTime = expressList.Min(p => p.AcceptTime); expressNew.state = "已发货"; expressNew.Remarked = "您的订单已发货,由" + order.ShipExpCo + "快递配送,请注意物流信息~"; expressNews.List.Add(expressNew); } else if (deliverystatus == 5) { expressNew.shipmentsTime = expressList.OrderByDescending(p => p.AcceptTime).FirstOrDefault().AcceptTime; expressNew.state = "派件中"; expressNew.Remarked = "您的订单已开始派送,请保持电话畅通,确认商品外包装完好后签收~"; expressNews.List.Add(expressNew); } else if (deliverystatus == 3) { expressNew.shipmentsTime = expressList.OrderByDescending(p => p.AcceptTime).FirstOrDefault().AcceptTime; expressNew.state = "已签收"; expressNew.Remarked = "您的订单已签收"; expressNews.List.Add(expressNew); } else { continue; } } } } } expressNews.Count = expressNews.List == null ? 0 : expressNews.List.Count(); if (expressNews.List.Any()) { ListResult <ComOrderExpressNew> express = new ListResult <ComOrderExpressNew>(); express.List = new List <ComOrderExpressNew>(); express.List = expressNews.List.Take(3).ToList(); //取前三条 result.Data = express; result.isSuccess = true; result.ResultCode = 0; } else { result.Data = expressNews; result.isSuccess = false; result.ResultCode = 1; } LogHelper.Info(string.Format("获取用户最新的所有订单物流信息返回数据:{0}", JsonHelper.JsonSerializer(result))); return(result); } else { return(result); } } catch (Exception ex) { LogHelper.Error(string.Format("获取用户最新的所有订单物流信息信息异常,异常信息:{0}", ex)); return(result); } }
/// <summary> /// 获取用户最新的订单物流信息 /// 查询第一条数据 /// </summary> public Jinher.AMP.BTP.Deploy.CustomDTO.ResultDTO <Jinher.AMP.BTP.Deploy.CustomDTO.Commodity.ComOrderExpressNew> GetUserNewOrderExpressExt(System.Guid AppId, System.Guid Userid) { LogHelper.Info("【一条物流】====AppId-->[" + AppId + "]--->UserId=[" + Userid + "]"); ComOrderExpressNew ExpressNews = new ComOrderExpressNew(); ResultDTO <ComOrderExpressNew> result = new ResultDTO <ComOrderExpressNew>() { ResultCode = 1, isSuccess = false, Data = ExpressNews }; string json = null; JObject obj = null; try { //获取已发货的订单信息 var ComOrder = CommodityOrder.ObjectSet().Where(p => p.State == 2 && p.UserId == Userid && p.EsAppId == AppId).OrderByDescending(p => p.ModifiedOn).FirstOrDefault(); if (ComOrder != null) { List <ExpressTrace> ExpressList = new List <ExpressTrace>(); var OrderItemInfo = OrderItem.ObjectSet().Where(p => p.CommodityOrderId == ComOrder.Id).FirstOrDefault(); ExpressNews.CommodityOrderId = ComOrder.Id; //订单id ExpressNews.Pic = OrderItemInfo.PicturesPath; //首条订单图片 //京东信息 var commodityOrderId = ComOrder.Id; /* * var jdOrderitem = JdOrderItem.ObjectSet().FirstOrDefault(p => p.CommodityOrderId.Contains(commodityOrderId)); * LogHelper.Debug(string.Format("物流信息(订单信息),订单id{0}:", ComOrder.Id)); * //急速数据信息 * if (!string.IsNullOrWhiteSpace(ComOrder.ExpOrderNo) && jdOrderitem == null) * { * //根据快递编号获取急速数据信息 * json = GetWuliuJson(ComOrder.ExpOrderNo); * obj = JObject.Parse(json); * LogHelper.Info(string.Format("极速物流信息:订单Id:{0},物流信息:{1}", ComOrder.Id, obj)); * if (Convert.ToInt32(obj["status"]) != 0) * { * return result; * } * JArray arr = (JArray)JsonConvert.DeserializeObject(obj["result"]["list"].ToString()); * foreach (var item in arr) * { * ExpressTrace Express = new ExpressTrace(); * Express.AcceptTime = Convert.ToDateTime(item["time"].ToString()); * Express.AcceptStation = item["status"].ToString().Trim(); * ExpressList.Add(Express); * } * * if (Convert.ToInt32(obj["result"]["deliverystatus"]) == 1) * { * ExpressNews.shipmentsTime = ExpressList.Min(p => p.AcceptTime); * ExpressNews.state = "已发货"; * ExpressNews.Remarked = "您的订单已发货,由" + ComOrder.ShipExpCo + "快递配送,请注意物流信息~"; * result.ResultCode = 0; * result.isSuccess = true; * } * else if (Convert.ToInt32(obj["result"]["deliverystatus"]) == 2) * { * ExpressNews.shipmentsTime = ExpressList.OrderByDescending(p => p.AcceptTime).FirstOrDefault().AcceptTime; * ExpressNews.state = "派件中"; * ExpressNews.Remarked = "您的订单已开始派送,请保持电话畅通,确认商品外包装完好后签收~"; * result.ResultCode = 0; * result.isSuccess = true; * } * else * { * result.ResultCode = 1; * result.isSuccess = false; * } * } * else * { * if (jdOrderitem != null) * { * var jdwuliu = JdHelper.orderTrack(jdOrderitem.JdOrderId); * if (jdwuliu != null) * { * JArray objson = JArray.Parse(jdwuliu); * foreach (var item in objson) * { * ExpressTrace Express = new ExpressTrace(); * Express.AcceptTime = DateTime.Parse(item["msgTime"].ToString()); * Express.AcceptStation = item["content"].ToString().Trim(); * ExpressList.Add(Express); * } * var NewExpress = ExpressList.OrderByDescending(p => p.AcceptTime).FirstOrDefault(); * if (NewExpress.AcceptStation.Contains("正在配送") || NewExpress.AcceptStation.Contains("自提")) * { * ExpressNews.shipmentsTime = NewExpress.AcceptTime; * ExpressNews.state = "派件中"; * ExpressNews.Remarked = "您的订单已开始派送,请保持电话畅通,确认商品外包装完好后签收~"; * result.ResultCode = 0; * result.isSuccess = true; * } * else if (NewExpress.AcceptStation.Contains("已签收")) * { * result.ResultCode = 1; * result.isSuccess = false; * } * else if (NewExpress.AcceptStation.Contains("出库") || NewExpress != null) * { * ExpressNews.shipmentsTime = ExpressList.Min(p => p.AcceptTime); * ExpressNews.state = "已发货"; * ExpressNews.Remarked = "您的订单已发货,由京东快递配送,请注意物流信息~"; * result.ResultCode = 0; * result.isSuccess = true; * } * } * } * }*/ if (ThirdECommerceHelper.IsJingDongDaKeHu(ComOrder.AppId)) { string orderId = commodityOrderId.ToString().ToLower(); LogHelper.Info("IsJingDongDaKeHu1--->" + orderId); var jdOrderitem = JdOrderItem.ObjectSet().Where(p => p.CommodityOrderId.ToLower() == orderId).FirstOrDefault(); LogHelper.Info("IsJingDongDaKeHu2--->" + orderId); if (jdOrderitem != null) { LogHelper.Info("IsJingDongDaKeHu3--->" + orderId); var jdwuliu = JdHelper.orderTrack(jdOrderitem.JdOrderId); LogHelper.Info("【一条---京东】京东物流[" + JsonHelper.JsonSerializer(jdOrderitem) + "]====返回-->[" + jdwuliu + "]"); if (jdwuliu != null) { JArray objson = JArray.Parse(jdwuliu); foreach (var item in objson) { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = DateTime.Parse(item["msgTime"].ToString()); Express.AcceptStation = item["content"].ToString().Trim(); ExpressList.Add(Express); } AddExpressNew(ExpressList, ExpressNews, result); } } } else if (ThirdECommerceHelper.IsWangYiYanXuan(ComOrder.AppId))//网易严选或第三方电商 { var yxOrder = YXOrder.ObjectSet().FirstOrDefault(p => p.OrderId == commodityOrderId); if (yxOrder != null) { var express = ThirdECommerceHelper.GetOrderItemExpressTrace(AppId, yxOrder.Id); LogHelper.Info("【一条---严选】网易严选物流[" + JsonHelper.JsonSerializer(yxOrder) + "]===返回-->[" + JsonHelper.JsonSerializer(express) + "]"); if (express != null) { if (express.ExpressTraceList != null && express.ExpressTraceList.Count > 0) { express.ExpressTraceList.ForEach(p => { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = p.Time == null ? DateTime.Now : DateTime.Parse(p.Time); Express.AcceptStation = p.Desc; ExpressList.Add(Express); }); AddExpressNew(ExpressList, ExpressNews, result); } } } } else if (ThirdECommerceHelper.IsSuNingYiGou(ComOrder.AppId))//苏宁店铺 { var snOrderitem = SNOrderItem.ObjectSet().FirstOrDefault(p => p.OrderId == commodityOrderId); if (snOrderitem != null) { SNExpressTraceFacade snExpress = new SNExpressTraceFacade(); var SuningWuliu = snExpress.GetExpressTrace(commodityOrderId.ToString(), snOrderitem.Id.ToString()); LogHelper.Info("【一条---苏宁】苏宁物流[" + JsonHelper.JsonSerializer(snOrderitem) + "]===返回-->[" + JsonHelper.JsonSerializer(SuningWuliu) + "]"); if (SuningWuliu != null) { SuningWuliu.ForEach(p => { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = p.OperateTime == null ? DateTime.Now : p.OperateTime.Value; Express.AcceptStation = p.OperateState; ExpressList.Add(Express); }); AddExpressNew(ExpressList, ExpressNews, result); } } } else if (ThirdECommerceHelper.IsFangZheng(ComOrder.AppId))//方正店铺 { var FangZhengWuliu = FangZhengSV.FangZheng_Logistics_InfoList(commodityOrderId); LogHelper.Info("【一条---方正】方正物流[" + commodityOrderId + "]===返回-->[" + JsonHelper.JsonSerializer(FangZhengWuliu) + "]"); if (FangZhengWuliu != null) { FangZhengWuliu.ExpressTraceList.ForEach(p => { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = DateTime.Parse(p.Time); Express.AcceptStation = p.Desc; ExpressList.Add(Express); }); AddExpressNew(ExpressList, ExpressNews, result); } } else { json = Express100SV.GetExpressFromKD100(ComOrder.ExpOrderNo, ComOrder.ShipExpCo); obj = JObject.Parse(json); LogHelper.Info(string.Format("【一条---快递100】快递100:订单Id:{0},物流信息:{1}", commodityOrderId, obj)); if (obj["message"].ToString().ToLower().Equals("ok")) { JArray arr = (JArray)JsonConvert.DeserializeObject(obj["data"].ToString()); foreach (var item in arr) { ExpressTrace Express = new ExpressTrace(); Express.AcceptTime = Convert.ToDateTime(item["ftime"].ToString()); Express.AcceptStation = item["context"].ToString().Trim(); ExpressList.Add(Express); } //快递单当前签收状态,包括0在途中、1已揽收、2疑难、3已签收、4退签、5同城派送中、6退回、7转单等7个状态,其中4-7需要另外开通才有效 int deliverystatus = Convert.ToInt32(obj["state"].ToString()); if (deliverystatus == 0) { ExpressNews.shipmentsTime = ExpressList.Min(p => p.AcceptTime); ExpressNews.state = "已发货"; ExpressNews.Remarked = "您的订单已发货,由" + ComOrder.ShipExpCo + "快递配送,请注意物流信息~"; result.ResultCode = 0; result.isSuccess = true; } else if (deliverystatus == 5) { ExpressNews.shipmentsTime = ExpressList.OrderByDescending(p => p.AcceptTime).FirstOrDefault().AcceptTime; ExpressNews.state = "派件中"; ExpressNews.Remarked = "您的订单已开始派送,请保持电话畅通,确认商品外包装完好后签收~"; result.ResultCode = 0; result.isSuccess = true; } else if (deliverystatus == 3) { ExpressNews.shipmentsTime = ExpressList.OrderByDescending(p => p.AcceptTime).FirstOrDefault().AcceptTime; ExpressNews.state = "已签收"; ExpressNews.Remarked = "您的订单已签收"; result.ResultCode = 0; result.isSuccess = true; } } } result.Data = ExpressNews; LogHelper.Info("Express100--->result[" + JsonHelper.JsonSerializer(result) + "]"); return(result); } else { return(result); } } catch (Exception ex) { LogHelper.Error(string.Format("获取用户最新的订单物流信息信息异常,异常信息:{0}", ex)); return(result); } }