/// <summary> /// 严选物流绑单回调补偿机制 /// </summary> public static void AutoDeliverOrder() { var yesterday = DateTime.Now.AddDays(-5); var ComOrders = (from co in CommodityOrder.ObjectSet() join yo in YXOrder.ObjectSet() on co.Id equals yo.OrderId where CustomConfig.YxAppIdList.Contains(co.AppId) && co.State == 1 && co.PaymentTime >= yesterday select co.Id).ToList(); LogHelper.Info("YXJob.AutoDeliverOrder 严选物流绑单回调补偿机制订单Id:" + string.Join(",", ComOrders.Select(c => c.ToString()).ToArray())); ComOrders.ForEach(p => { string jsonstr = string.Empty; var orderOut = YXSV.GetPaidOrder(p.ToString(), ref jsonstr); if (orderOut == null || orderOut.orderPackages == null) { return; } var orderPackages = orderOut.orderPackages.Select(o => new JobOrderPackage { orderId = p.ToString(), packageId = long.Parse(o.packageId), expressDetailInfos = o.expressDetailInfos, expCreateTime = ConvertDataTimeToLong(Convert.ToDateTime(o.expCreateTime)) }).ToList(); orderPackages.ForEach(op => { var package = SerializationHelper.JsonSerialize(op); YXOrderHelper.DeliverOrder(new YXSign(), package, true); }); }); }
/// <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); } }