コード例 #1
0
ファイル: JdlogsAgent.cs プロジェクト: GSIL-Monitor/BTP
        /// <summary>
        /// 保存京东日志信息
        /// </summary>
        /// <param name="VatInvoiceProof"></param>
        /// <returns></returns>
        public ResultDTO SaveJdlogs(Jinher.AMP.BTP.Deploy.JdlogsDTO model)
        {
            //定义返回值
            ResultDTO result;

            try
            {
                //调用代理方法
                result = base.Channel.SaveJdlogs(model);
            }
            catch
            {
                //抛异常
                throw;
            }
            finally
            {
                //关链接
                ChannelClose();
            }            //返回结果
            return(result);
        }
コード例 #2
0
 /// <summary>
 /// 获得方正物流信息数据
 /// </summary>
 public static ThirdOrderPackageExpress FangZheng_Logistics_InfoList(Guid OrderId)
 {
     try
     {
         var OrderData = CommodityOrder.ObjectSet().Where(w => w.Id == OrderId).FirstOrDefault();
         if (string.IsNullOrWhiteSpace(OrderData.ExpOrderNo))
         {
             return(null);
         }
         var Logistics     = FangZheng_Logistics_Data(OrderData.ExpOrderNo);
         var LogisticsList = (from data in Logistics["result"]["list"].Children()
                              select new ThirdExpressTrace
         {
             Time = data["time"].ToString(),
             Desc = data["status"].ToString()
         }).ToList();
         return(new ThirdOrderPackageExpress
         {
             OrderId = OrderId.ToString(),
             ExpressCompany = OrderData.ShipExpCo,
             ExpressNo = OrderData.ExpOrderNo,
             ExpressTraceList = LogisticsList
         });
     }
     catch (Exception ex)
     {
         var LogInfo = new Jinher.AMP.BTP.Deploy.JdlogsDTO
         {
             Id                 = Guid.NewGuid(),
             Content            = "获得物流信息Exception:" + ex.Message,
             SubTime            = DateTime.Now,
             ThirdECommerceType = (int)ThirdECommerceTypeEnum.FangZheng
         };
         new JdlogsFacade().SaveJdlogs(LogInfo);
         return(null);
     }
 }
コード例 #3
0
 private static void FangZheng_Order_Confirm(Guid MyOrderId)
 {
     Task.Factory.StartNew(() =>
     {
         var LogMessage         = string.Empty;
         CommodityOrder MyOrder = null;
         try
         {
             if (FangZhengOrder.ObjectSet().Where(w => w.OrderId == MyOrderId && w.OrderStatus == 200).Count() > 0)
             {
                 return;
             }
             MyOrder = CommodityOrder.ObjectSet().Where(w => w.Id == MyOrderId)
                       .Where(w => w.PaymentTime.HasValue)
                       .Where(w => w.State == 1)
                       .FirstOrDefault();
             if (MyOrder != null)
             {
                 Decimal OrderSumPrice = 0;
                 var CommodityList     = new List <object>();
                 OrderItem.ObjectSet().Where(w => w.CommodityOrderId == MyOrderId)
                 .ToList().ForEach(Item =>
                 {
                     if (Item.AppId != null)
                     {
                         var AppId = (Guid)Item.AppId;
                         if (ThirdECommerceHelper.IsFangZheng(AppId))
                         {
                             if (Item.CostPrice == null)
                             {
                                 throw new Exception("商品[" + Item.Name + "]价格为空!");
                             }
                             CommodityList.Add(new
                             {
                                 orderId         = Item.CommodityOrderId,
                                 orderEntryId    = Item.Id,
                                 productMapType  = 1,
                                 productCode     = Item.JDCode,
                                 productName     = Item.Name,
                                 productNum      = Item.Number,
                                 basePrice       = Item.CostPrice,
                                 realPrice       = Item.CostPrice,
                                 mallDiscountFee = 0,
                                 discountFee     = 0
                             });
                             OrderSumPrice += Item.Number * (decimal)Item.CostPrice;
                         }
                     }
                     else
                     {
                         throw new Exception("订单中商品AppId为空!");
                     }
                 });
                 if (CommodityList.Count > 0 && OrderSumPrice > 0)
                 {
                     var RequestTime   = TimeHelper.GetTimestampM();
                     var RequestParams = JsonConvert.SerializeObject(new
                     {
                         sign    = GetMd5(GetFangZhengInfo.Password + RequestTime + GetFangZhengInfo.ShopId),
                         shopId  = GetFangZhengInfo.ShopId,
                         reqTime = RequestTime,
                         data    = new
                         {
                             orderId          = MyOrder.Id,
                             orderStatus      = 1,
                             payTotalPrice    = OrderSumPrice,
                             totalPrice       = OrderSumPrice,
                             mallDiscountFee  = 0,
                             discountFee      = 0,
                             orderCreateTime  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                             remark           = MyOrder.Details,
                             orderEntryList   = CommodityList,
                             hasInvoice       = true,                 //是否要发票
                             invoiceTitle     = "中国石化销售有限公司北京石油分公司",  //发票抬头
                             invoiceTitleType = 1,                    //0:个人,1:企业
                             taxpayerNumber   = "911100008011253056", //企业识别号
                             invoiceEmail     = "*****@*****.**",    //用户收发票的邮箱
                             receiverinfo     = new
                             {
                                 receiverPhone    = "",
                                 receiverName     = MyOrder.ReceiptUserName,
                                 receiverMobile   = MyOrder.ReceiptPhone,
                                 receiverProvince = FangZheng_Order_Confirm("省", MyOrder),
                                 receiverCity     = FangZheng_Order_Confirm("市", MyOrder),
                                 receiverDistrct  = FangZheng_Order_Confirm("区", MyOrder),
                                 receiverCounty   = "",
                                 receiverAddress  = MyOrder.ReceiptAddress,
                                 receiverZip      = MyOrder.RecipientsZipCode
                             }
                         }
                     });
                     var ResponseData = SendRequest(GetFangZhengInfo.UrlBase + "/submitorder", RequestParams);
                     ContextSession contextSession = ContextFactory.CurrentThreadContext;
                     FangZhengOrder.ObjectSet().Where(w => w.OrderId == MyOrderId)
                     .ToList().ForEach(Item =>
                     {
                         int Code = Convert.ToInt32(ResponseData["code"]);
                         if (Code != 200)
                         {
                             LogMessage = Code + "-" + ResponseData["msg"].ToString();
                         }
                         Item.OrderStatus = Code;
                         Item.ModifiedOn  = DateTime.Now;
                         Item.EntityState = EntityState.Modified;
                         contextSession.SaveObject(Item);
                     });
                     contextSession.SaveChange();
                 }
                 else
                 {
                     throw new Exception("订单商品总价为0元!");
                 }
             }
             else
             {
                 throw new Exception("未查到易捷订单信息");
             }
         }
         catch (Exception ex)
         {
             LogMessage = ex.Message;
             LogHelper.Error("方正电商订单提交接口Exception:" + ex);
         }
         finally
         {
             if (!string.IsNullOrWhiteSpace(LogMessage))
             {
                 var LogInfo = new Jinher.AMP.BTP.Deploy.JdlogsDTO
                 {
                     Id                 = Guid.NewGuid(),
                     Content            = ",Exception:" + LogMessage,
                     SubTime            = DateTime.Now,
                     AppId              = MyOrder.AppId,
                     ThirdECommerceType = (int)ThirdECommerceTypeEnum.FangZheng
                 };
                 if (MyOrder == null)
                 {
                     LogInfo.Content = "订单主键:[" + MyOrderId + "]" + LogInfo.Content;
                 }
                 else
                 {
                     LogInfo.Content = "订单Code:[" + MyOrder.Code + "]" + LogInfo.Content;
                 }
                 new JdlogsFacade().SaveJdlogs(LogInfo);
             }
         }
     });
 }
コード例 #4
0
        /// <summary>
        /// 保存一个京东订单
        /// </summary>
        /// <param name="item">一个订单</param>
        /// <param name="comList">订单项对应的商品</param>
        private ResultDTO SaveOneJdOrder(OrderSDTO item, List <Commodity> comList)
        {
            ResultDTO <List <CommoditySummaryDTO> > result = new ResultDTO <List <CommoditySummaryDTO> >();

            if (item == null)
            {
                result.ResultCode = (int)ReturnCodeEnum.ParamEmpty;
                result.Message    = ReturnCodeEnum.ParamEmpty.GetDescription();
                return(result);
            }
            if (item.ShoppingCartItemSDTO == null || !item.ShoppingCartItemSDTO.Any() ||
                comList == null || !comList.Any())
            {
                result.ResultCode = (int)ReturnCodeEnum.ParamEmpty;
                result.Message    = ReturnCodeEnum.ParamEmpty.GetDescription();
                return(result);
            }
            //易捷北京所有的AppId
            string Appids = CustomConfig.AppIds;

            LogHelper.Info(string.Format("Appids{0}", Appids));
            List <string> Appidlist = null;

            if (!string.IsNullOrEmpty(Appids))
            {
                Appidlist = Appids.Split(new char[] { ',' }).ToList();
            }

            if (!Appidlist.Contains(comList[0].AppId.ToString().ToUpper()))
            {
                //todo 返回非京东app.
                result.ResultCode = (int)ReturnCodeEnum.NotJdShop;
                result.Message    = ReturnCodeEnum.NotJdShop.GetDescription();
                return(result);
            }
            LogHelper.Info(string.Format("Appidlist的数量{0}", Appidlist.Count()));

            string orderPriceSnap = null;
            string sku            = null;

            //订单项里的商品都是同一店铺的,店铺名称相同。
            string appName = APPSV.GetAppName(comList[0].AppId);

            List <CommoditySummaryDTO> errorCommodities = new List <CommoditySummaryDTO>();

            orderPriceSnap = null;
            sku            = null;

            ContextSession contextSession = ContextFactory.CurrentThreadContext;

            var scis = item.ShoppingCartItemSDTO;

            foreach (var _item in scis)
            {
                Commodity commodity = comList.FirstOrDefault(_ => _.Id == _item.Id);

                LogHelper.Info(string.Format("京东日志:商品Id:{0},JDCode:{1},AppId:{2}", commodity.Id, commodity.JDCode, commodity.AppId));

                //京东店铺的商品没有JDCode,返回错误。
                if (string.IsNullOrWhiteSpace(commodity.JDCode))
                {
                    #region

                    Jdlogs model = new Jdlogs();
                    model.Id         = Guid.NewGuid();
                    model.Content    = (appName + "App中" + commodity.Name + "商品的备注编码不存在,请尽快补充填写~");
                    model.Remark     = string.Empty;
                    model.AppId      = commodity.AppId;
                    model.ModifiedOn = DateTime.Now;
                    model.SubTime    = DateTime.Now;
                    model.Isdisable  = false;

                    model.EntityState = EntityState.Added;
                    contextSession.SaveObject(model);


                    bool falg = EmailHelper.SendEmail("京东错误日志", model.Content, "*****@*****.**");

                    var errorCommodity = new CommoditySummaryDTO();
                    errorCommodity.Id             = commodity.Id;
                    errorCommodity.Name           = commodity.Name;
                    errorCommodity.PicturesPath   = commodity.PicturesPath;
                    errorCommodity.Price          = _item.Price;
                    errorCommodity.Sku            = _item.SizeAndColorId;
                    errorCommodity.ShopCartItemId = _item.ShopCartItemId;
                    errorCommodities.Add(errorCommodity);

                    result.ResultCode = (int)ReturnCodeEnum.CommoditySold;
                    result.Message    = ReturnCodeEnum.CommoditySold.GetDescription();
                    result.Data       = errorCommodities;
                    return(result);

                    #endregion
                }

                orderPriceSnap += "{'price':" + commodity.CostPrice + ",'skuId':" + commodity.JDCode + "},";
                sku            += "{'skuId':" + commodity.JDCode + ", 'num':" + _item.CommodityNumber + ",'bNeedAnnex':true, 'bNeedGift':false},";
                LogHelper.Info(string.Format("京东日志2:{0}:{1}", orderPriceSnap, sku));
            }

            LogHelper.Info(string.Format("京东日志3:{0}:{1}", orderPriceSnap, sku));
            if (string.IsNullOrEmpty(orderPriceSnap) || string.IsNullOrEmpty(sku))
            {
                //没有商品要去京东下单。
                result.ResultCode = (int)ReturnCodeEnum.NoCommodityNeedJdOrder;
                result.Message    = ReturnCodeEnum.NoCommodityNeedJdOrder.GetDescription();
                return(result);
            }

            orderPriceSnap = orderPriceSnap.Remove(orderPriceSnap.Length - 1, 1);
            sku            = sku.Remove(sku.Length - 1, 1);
            orderPriceSnap = "[" + orderPriceSnap + "]";
            sku            = "[" + sku + "]";
            string thirdOrder = Guid.NewGuid().ToString();
            if (string.IsNullOrEmpty(item.StreetCode))
            {
                item.StreetCode = "0";
            }
            //获取京东编号
            ResultDTO jdResult = JdHelper.GetJDOrderNew(thirdOrder, orderPriceSnap, sku, item.ReceiptUserName, item.ReceiptAddress, item.ReceiptPhone, "*****@*****.**", item.ProvinceCode, item.CityCode, item.DistrictCode, item.StreetCode);
            LogHelper.Info(string.Format("京东日志4:{0}:{1}", orderPriceSnap, sku));

            //正常下单,保存订单项关系。
            if (jdResult.ResultCode == 0)
            {
                #region 京东下单情况

                JdOrderItem jdorderitemdto = new JdOrderItem()
                {
                    Id = Guid.NewGuid(),
                    //todo jdporderId????
                    //JdPorderId = jdporderId,
                    TempId           = Guid.Parse(thirdOrder),
                    JdOrderId        = Guid.Empty.ToString(),
                    MainOrderId      = Guid.Empty.ToString(),
                    CommodityOrderId = Guid.Empty.ToString(),
                    State            = Convert.ToInt32(JdEnum.YZ),
                    StateContent     = new EnumHelper().GetDescription(JdEnum.YZ),
                    SubTime          = DateTime.Now,
                    ModifiedOn       = DateTime.Now
                };

                //todo SaveJdOrderItem(jdorderitemdto);

                JdJournal jdjournaldto = new JdJournal()
                {
                    Id = Guid.NewGuid(),
                    //todo jdporderId
                    //JdPorderId = jdporderId,
                    TempId           = Guid.Parse(thirdOrder),
                    JdOrderId        = Guid.Empty.ToString(),
                    MainOrderId      = Guid.Empty.ToString(),
                    CommodityOrderId = Guid.Empty.ToString(),
                    Name             = "京东统一下单接口",
                    Details          = "初始状态为" + Convert.ToInt32(JdEnum.YZ),
                    SubTime          = DateTime.Now
                };

                //todo SaveJdJournal(jdjournaldto);

                #endregion
            }
            else
            {
                #region 记录京东日志

                int    resultCode = jdResult.ResultCode;
                string jdlog      = jdResult.Message;
                if (resultCode == 3017) //账户异常情况特殊
                {
                    #region

                    EmailHelper.SendEmail("京东错误日志", "您的京东账户余额不足,请充值!", "*****@*****.**");

                    Jinher.AMP.BTP.Deploy.JdlogsDTO model = new Jinher.AMP.BTP.Deploy.JdlogsDTO();
                    model.Id         = Guid.NewGuid();
                    model.Content    = "您的京东账户余额不足,请充值!";
                    model.Remark     = string.Empty;
                    model.AppId      = Guid.Empty;
                    model.ModifiedOn = DateTime.Now;
                    model.SubTime    = DateTime.Now;
                    model.Isdisable  = false;
                    //SaveJdlogs(model);

                    foreach (var itemlog in scis)
                    {
                        var errorCommodity = new CommoditySummaryDTO();
                        errorCommodity.Id             = itemlog.Id;
                        errorCommodity.Name           = itemlog.Name;
                        errorCommodity.PicturesPath   = itemlog.Pic;
                        errorCommodity.Price          = itemlog.Price;
                        errorCommodity.Sku            = itemlog.SizeAndColorId;
                        errorCommodity.ShopCartItemId = itemlog.ShopCartItemId;
                        errorCommodities.Add(errorCommodity);
                    }

                    #endregion
                }
                else
                {
                    #region

                    if (!string.IsNullOrEmpty(jdResult.Message))
                    {
                        string num     = null;
                        var    matches = Regex.Matches(jdResult.Message, @"(\d+)");
                        int    count   = 0;
                        foreach (Match match in matches)
                        {
                            if (count == 0)
                            {
                                num = match.Value;
                            }
                            count++;
                        }
                        foreach (var itemlog in scis)
                        {
                            Commodity commodity = comList.FirstOrDefault(_ => _.Id == itemlog.Id);
                            if (commodity.JDCode != num.ToString())
                            {
                                continue;
                            }

                            var errorCommodity = new CommoditySummaryDTO();
                            errorCommodity.Id             = commodity.Id;
                            errorCommodity.Name           = commodity.Name;
                            errorCommodity.PicturesPath   = commodity.PicturesPath;
                            errorCommodity.Price          = itemlog.Price;
                            errorCommodity.Sku            = itemlog.SizeAndColorId;
                            errorCommodity.ShopCartItemId = itemlog.ShopCartItemId;
                            errorCommodities.Add(errorCommodity);

                            string content = null;
                            content += (APPSV.GetAppName(commodity.AppId) + "App中" + itemlog.Name) + "商品[" + commodity.JDCode + "]";
                            if (resultCode == 2004)
                            {
                                content += "京东商品池中不存在";
                            }
                            else if (resultCode == 3019)
                            {
                                string str = jdlog;
                                if (!string.IsNullOrEmpty(str))
                                {
                                    content += "价格错误,";
                                    int      num1       = str.IndexOf('[');
                                    int      num2       = str.IndexOf(']');
                                    string   strjdprice = str.Substring(num1 + 1, (num2 - num1 - 1));
                                    string[] arr        = strjdprice.Split(new char[] { '=' });
                                    content += "京东价" + arr[1] + "元," + "易捷价" + commodity.CostPrice + "元";
                                }
                            }
                            else if (resultCode == 3008)
                            {
                                content += "已售馨";
                            }
                            else
                            {
                                content += "异常信息:" + jdlog;
                            }

                            EmailHelper.SendEmail("京东错误日志", content, "*****@*****.**");

                            Jinher.AMP.BTP.Deploy.JdlogsDTO model = new Jinher.AMP.BTP.Deploy.JdlogsDTO();
                            model.Id         = Guid.NewGuid();
                            model.Content    = content;
                            model.Remark     = string.Empty;
                            model.AppId      = itemlog.AppId;
                            model.ModifiedOn = DateTime.Now;
                            model.SubTime    = DateTime.Now;
                            model.Isdisable  = false;
                            //SaveJdlogs(model);
                        }
                    }

                    #endregion
                }

                #endregion

                #region 获取京东订单单号失败的情况

                //////京东确认取消订单
                ////bool flag = JdHelper.OrderCancel(jdorderid.JdporderId);
                ////if (flag == true)
                ////{
                ////    List<string> jdorder = new List<string>();
                ////    jdorder.Add(jdorderid.JdporderId);
                ////    //删除京东对应订单
                ////    var res = jdorderitemfacade.DeleteJdOrderItem(jdorder);
                ////    if (res.isSuccess == true)
                ////    {
                ////        JdJournal jdjournaldto = new JdJournal()
                ////        {
                ////            Id = Guid.NewGuid(),
                ////            JdPorderId = jdporderId,
                ////            TempId = Guid.Parse(thirdOrder),
                ////            JdOrderId = Guid.Empty.ToString(),
                ////            MainOrderId = Guid.Empty.ToString(),
                ////            CommodityOrderId = Guid.Empty.ToString(),
                ////            Name = "京东确认取消订单",
                ////            Details = "删除JdOrderItem表中相应的内容",
                ////            SubTime = DateTime.Now
                ////        };
                ////        //SaveJdJournal(jdjournaldto);
                ////    }
                ////}


                #endregion

                //LogHelper.Error("商品已售馨,请选择其他商品,Jdlogs:" + jdlog + " resultCode:" + resultCode);
                //return Json(new OrderResultDTO { ResultCode = 2, Message = "商品已售馨,请选择其他商品", ErrorCommodities = errorCommodities }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }