Esempio n. 1
0
        public static string RepairJdOrder(string jdPorderId)
        {
            var commodityorderfacade = new Jinher.AMP.BTP.IBP.Facade.CommodityOrderFacade();

            commodityorderfacade.ContextDTO = AuthorizeHelper.CoinInitAuthorizeInfo();
            var jdorderitemfacade = new Jinher.AMP.BTP.IBP.Facade.JdOrderItemFacade();

            jdorderitemfacade.ContextDTO = AuthorizeHelper.CoinInitAuthorizeInfo();
            var jdjournalfacade = new Jinher.AMP.BTP.IBP.Facade.JdJournalFacade();

            jdjournalfacade.ContextDTO = AuthorizeHelper.CoinInitAuthorizeInfo();

            //开始拆单
            JdOrderItemDTO model = new JdOrderItemDTO();

            model.JdPorderId = jdPorderId;
            model.State      = 1;//
            //获取jdorderitem表中的数据
            var jdorderitem = jdorderitemfacade.GetJdOrderItemList(model).FirstOrDefault();

            if (jdorderitem != null)
            {
                var  getFullOrderInfo = commodityorderfacade.GetFullOrderInfoById(jdorderitem.CommodityOrderId);
                bool flag             = JdHelper.IsjdOrder(jdPorderId);
                if (flag == true)
                {
                    #region 父订单拆单行为
                    var selectJdOrder2 = JdHelper.selectJdOrder2(jdPorderId);
                    if (!string.IsNullOrWhiteSpace(selectJdOrder2))
                    {
                        List <string> list = new List <string>();
                        list.Add(jdPorderId);
                        //删除已有的父类订单
                        var delresult = jdorderitemfacade.DeleteJdOrderItem(list);
                        if (delresult.isSuccess == true)
                        {
                            JArray objson = JArray.Parse(selectJdOrder2);
                            foreach (var item in objson)
                            {
                                JArray objsku = JArray.Parse(item["sku"].ToString());
                                foreach (var ZiJdOrder in objsku)
                                {
                                    #region 子订单包含包含多个商品的情况
                                    string skuId  = ZiJdOrder["skuId"].ToString();
                                    Guid   TempId = Guid.Empty;
                                    Guid   commodityOrderItemId = Guid.Empty;
                                    if (getFullOrderInfo.OrderItems != null && getFullOrderInfo.OrderItems.Count() > 0)
                                    {
                                        var commoditydto = getFullOrderInfo.OrderItems.Where(p => p.JdCode == skuId).FirstOrDefault();
                                        if (commoditydto != null)
                                        {
                                            commodityOrderItemId = commoditydto.Id;
                                            TempId = commoditydto.CommodityId;
                                        }
                                    }
                                    int    State        = Convert.ToInt32(JdEnum.BCF);
                                    string StateContent = new EnumHelper().GetDescription(JdEnum.BCF);
                                    string JdOrderId    = item["jdOrderId"].ToString();
                                    string Name         = "京东下订单" + StateContent;
                                    string Details      = "订单状态由" + jdorderitem.State + "变成" + State;
                                    if (item["orderState"].ToString() == "0")
                                    {
                                        State        = Convert.ToInt32(JdEnum.BCF);
                                        StateContent = new EnumHelper().GetDescription(JdEnum.BCF);
                                        Name         = "京东下订单" + StateContent;
                                        Details      = "订单状态由" + jdorderitem.State + "变成" + State;
                                    }
                                    JdOrderItemDTO jdorderitemdto = new JdOrderItemDTO()
                                    {
                                        Id                   = Guid.NewGuid(),
                                        JdPorderId           = jdPorderId,
                                        TempId               = TempId,
                                        JdOrderId            = JdOrderId,
                                        MainOrderId          = jdorderitem.MainOrderId,
                                        CommodityOrderId     = jdorderitem.CommodityOrderId,
                                        State                = State,
                                        StateContent         = StateContent,
                                        SubTime              = DateTime.Now,
                                        ModifiedOn           = DateTime.Now,
                                        CommoditySkuId       = skuId,
                                        CommodityOrderItemId = commodityOrderItemId
                                    };
                                    var restult = jdorderitemfacade.SaveJdOrderItem(jdorderitemdto);
                                    if (restult.isSuccess == true)
                                    {
                                        JdJournalDTO ex = new JdJournalDTO()
                                        {
                                            JdPorderId       = jdPorderId,
                                            TempId           = TempId,
                                            JdOrderId        = JdOrderId,
                                            MainOrderId      = jdorderitem.MainOrderId,
                                            CommodityOrderId = jdorderitem.CommodityOrderId,
                                            Name             = Name,
                                            Details          = StateContent
                                        };
                                        var res = jdjournalfacade.GetJdJournalList(ex);
                                        if (res.Count() == 0)
                                        {
                                            JdJournalDTO jdjournaldto = new JdJournalDTO()
                                            {
                                                Id               = Guid.NewGuid(),
                                                JdPorderId       = jdPorderId,
                                                TempId           = TempId,
                                                JdOrderId        = JdOrderId,
                                                MainOrderId      = jdorderitem.MainOrderId,
                                                CommodityOrderId = jdorderitem.CommodityOrderId,
                                                Name             = Name,
                                                Details          = StateContent,
                                                SubTime          = DateTime.Now
                                            };
                                            jdjournalfacade.SaveJdJournal(jdjournaldto);
                                        }
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    #region  拆单行为
                    var selectJdOrder1 = JdHelper.selectJdOrder1(jdPorderId);
                    if (!string.IsNullOrWhiteSpace(selectJdOrder1))
                    {
                        JObject objs   = JObject.Parse(selectJdOrder1);
                        JArray  objson = JArray.Parse(objs["sku"].ToString());
                        foreach (var ZiJdOrder in objson)
                        {
                            #region 子订单包含包含多个商品的情况
                            string skuId  = ZiJdOrder["skuId"].ToString();
                            Guid   TempId = Guid.Empty;
                            Guid   commodityOrderItemId = Guid.Empty;
                            if (getFullOrderInfo.OrderItems != null && getFullOrderInfo.OrderItems.Count() > 0)
                            {
                                var commoditydto = getFullOrderInfo.OrderItems.Where(p => p.JdCode == skuId).FirstOrDefault();
                                if (commoditydto != null)
                                {
                                    commodityOrderItemId = commoditydto.Id;
                                    TempId = commoditydto.CommodityId;
                                }
                            }
                            int    State        = Convert.ToInt32(JdEnum.BCF);
                            string StateContent = new EnumHelper().GetDescription(JdEnum.BCF);
                            string JdOrderId    = objs["jdOrderId"].ToString();
                            string Name         = "京东下订单" + StateContent;
                            string Details      = "订单状态由" + jdorderitem.State + "变成" + State;
                            jdorderitem.TempId               = TempId;
                            jdorderitem.JdOrderId            = JdOrderId;
                            jdorderitem.State                = State;
                            jdorderitem.StateContent         = StateContent;
                            jdorderitem.CommoditySkuId       = skuId;
                            jdorderitem.CommodityOrderItemId = commodityOrderItemId;
                            var restult = jdorderitemfacade.UpdateJdOrderItem(jdorderitem);
                            if (restult.isSuccess == true)
                            {
                                JdJournalDTO ex = new JdJournalDTO()
                                {
                                    JdPorderId       = jdPorderId,
                                    TempId           = TempId,
                                    JdOrderId        = JdOrderId,
                                    MainOrderId      = jdorderitem.MainOrderId,
                                    CommodityOrderId = jdorderitem.CommodityOrderId,
                                    Name             = Name,
                                    Details          = StateContent
                                };
                                var res = jdjournalfacade.GetJdJournalList(ex);
                                if (res.Count() == 0)
                                {
                                    JdJournalDTO jdjournaldto = new JdJournalDTO()
                                    {
                                        Id               = Guid.NewGuid(),
                                        JdPorderId       = jdPorderId,
                                        TempId           = TempId,
                                        JdOrderId        = JdOrderId,
                                        MainOrderId      = jdorderitem.MainOrderId,
                                        CommodityOrderId = jdorderitem.CommodityOrderId,
                                        Name             = Name,
                                        Details          = StateContent,
                                        SubTime          = DateTime.Now
                                    };
                                    jdjournalfacade.SaveJdJournal(jdjournaldto);
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion
                }

                #region 更新订单信息状态
                Jinher.AMP.BTP.Deploy.CommodityOrderDTO commodity = new Jinher.AMP.BTP.Deploy.CommodityOrderDTO();
                commodity.Id            = Guid.Parse(jdorderitem.CommodityOrderId);
                commodity.State         = 2;
                commodity.ShipmentsTime = DateTime.Now;
                //更新订单状态
                commodityorderfacade.UpdateCommodityOrder(commodity);
                #endregion

                return("ok");
            }
            return("no found");
        }
Esempio n. 2
0
 // 更新京东订单
 public static void UpdateJdorder(Guid orderId)
 {
     try
     {
         //如果更新成功 京东下单
         Jinher.AMP.BTP.IBP.Facade.CommodityOrderFacade commodityorderfacade = new Jinher.AMP.BTP.IBP.Facade.CommodityOrderFacade();
         commodityorderfacade.ContextDTO = AuthorizeHelper.InitAuthorizeInfo();
         Jinher.AMP.BTP.IBP.Facade.JdOrderItemFacade jdorderitemfacade = new Jinher.AMP.BTP.IBP.Facade.JdOrderItemFacade();
         jdorderitemfacade.ContextDTO = AuthorizeHelper.InitAuthorizeInfo();
         Jinher.AMP.BTP.IBP.Facade.JdJournalFacade jdjournalfacade = new Jinher.AMP.BTP.IBP.Facade.JdJournalFacade();
         jdjournalfacade.ContextDTO = AuthorizeHelper.InitAuthorizeInfo();
         var mainOrder = commodityorderfacade.GetMainOrderInfo(orderId);
         var order     = commodityorderfacade.GetCommodityOrder(orderId, Guid.Empty);
         if (mainOrder == null || order == null || !order.PaymentTime.HasValue)
         {
             LogHelper.Info("订单未支付orderId=" + orderId);
             return;
         }
         JdOrderItemDTO model = new JdOrderItemDTO();
         model.State            = 1;
         model.CommodityOrderId = orderId.ToString();
         LogHelper.Info("jdorderitem是否为空数据单号:" + model.CommodityOrderId + "");
         //获取最早的京东数据模型
         var jdorderitem = jdorderitemfacade.GetJdOrderItemList(model).ToList().FirstOrDefault();
         if (jdorderitem != null)
         {
             //京东确认下单
             bool flag = JdHelper.confirmOrder(jdorderitem.JdPorderId);
             if (flag == true)
             {
                 jdorderitem.StateContent = "确认预占";
                 jdorderitem.MainOrderId  = mainOrder.MainOrderId.ToString();
                 var res = jdorderitemfacade.UpdateJdOrderItem(jdorderitem);
                 LogHelper.Info("京东确认下单res:" + res + "");
                 if (res.isSuccess == true)
                 {
                     JdJournalDTO jdjournaldto = new JdJournalDTO()
                     {
                         Id               = Guid.NewGuid(),
                         JdPorderId       = jdorderitem.JdPorderId,
                         TempId           = jdorderitem.TempId,
                         JdOrderId        = Guid.Empty.ToString(),
                         MainOrderId      = mainOrder.MainOrderId.ToString(),
                         CommodityOrderId = jdorderitem.CommodityOrderId,
                         Name             = "京东确认预占库存订单接口",
                         Details          = "京东确认预占库存订单接口",
                         SubTime          = DateTime.Now
                     };
                     //添加明细记录
                     jdjournalfacade.SaveJdJournal(jdjournaldto);
                 }
             }
         }
         else
         {
             LogHelper.Info("jdorderitemjdorderitemjdorderitemjdorderitemjdorderitem为空");
         }
     }
     catch (Exception ex)
     {
         LogHelper.Error("OrderEventHelper.UpdateJdorder 异常", ex);
     }
 }