Beispiel #1
0
        /// <summary>
        /// 保存京东日志信息
        /// </summary>
        /// <param name="VatInvoiceProof"></param>
        /// <returns></returns>
        public ResultDTO SaveJdlogsExt(Jinher.AMP.BTP.Deploy.JdlogsDTO model)
        {
            ResultDTO dto = null;

            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                Jdlogs         entity         = new Jdlogs();
                entity             = CommonUtil.ReadObjectExchange(entity, model);
                entity.EntityState = EntityState.Added;
                contextSession.SaveObject(entity);
                contextSession.SaveChanges();
                dto = new ResultDTO {
                    ResultCode = 0, Message = "保存成功", isSuccess = true
                };
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("保存异常。Jdlogs:{0}", ex));
                dto = new ResultDTO {
                    ResultCode = 1, Message = ex.Message, isSuccess = false
                };
            }
            return(dto);
        }
Beispiel #2
0
        /// <summary>
        /// 根据Id获取京东的日志内容
        /// </summary>
        /// <param name="search">查询类</param>
        /// <returns>结果</returns>
        public Jinher.AMP.BTP.Deploy.JdlogsDTO GetJdlogsExt(Guid Id)
        {
            Jinher.AMP.BTP.Deploy.JdlogsDTO exEntity = new Jinher.AMP.BTP.Deploy.JdlogsDTO();
            var model = Jdlogs.ObjectSet().FirstOrDefault(p => p.Id == Id);

            if (model != null)
            {
                exEntity = CommonUtil.ReadObjectExchange(exEntity, model);
            }
            return(exEntity);
        }
        /// <summary>
        /// 第三方电商保存错误日志
        /// </summary>
        /// <param name="dto"></param>
        public static void SaveErrorLog(ThirdECOrderErrorLogDTO dto)
        {
            var param = string.Empty;

            try
            {
                param = JsonConvert.SerializeObject(dto);
                var orderErrorLog = new ThirdECOrderErrorLog
                {
                    Id             = Guid.NewGuid(),
                    Content        = dto.Content,
                    AppId          = dto.AppId,
                    OrderId        = dto.OrderId,
                    OrderCode      = dto.OrderCode,
                    AppName        = dto.AppName,
                    CommodityNames = dto.CommodityNames,
                    Json           = dto.Json,
                    EntityState    = EntityState.Added
                };
                var jdlogs = new Jdlogs
                {
                    Id                 = Guid.NewGuid(),
                    Content            = dto.Content,
                    Remark             = string.Empty,
                    AppId              = dto.AppId,
                    ThirdECommerceType = (int)Deploy.Enum.ThirdECommerceTypeEnum.ByBiaoZhunJieKou,
                    EntityState        = EntityState.Added
                };
                if (!string.IsNullOrEmpty(dto.Json) && dto.Json.StartsWith("{"))
                {
                    var thirdResult = JsonConvert.DeserializeObject <ThirdResponse>(dto.Json);
                    if (thirdResult != null)
                    {
                        orderErrorLog.Content = thirdResult.Msg;
                        jdlogs.Content        = string.Format("{0}App中{1}等商品异常信息:{2}", dto.AppName, dto.CommodityNames, thirdResult.Msg);
                    }
                }
                ContextFactory.CurrentThreadContext.SaveObject(orderErrorLog);
                if (!dto.Isdisable)
                {
                    ContextFactory.CurrentThreadContext.SaveObject(jdlogs);
                }
                int count = ContextFactory.CurrentThreadContext.SaveChanges();
                if (count == 0)
                {
                    LogHelper.Error(string.Format("ThirdECommerceOrderHelper.SaveErrorLog第三方电商保存错误日志失败,入参:{0}", param));
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("ThirdECommerceOrderHelper.SaveErrorLog第三方电商保存错误日志异常,入参:{0}", param), ex);
            }
        }
Beispiel #4
0
        /// <summary>
        ///修改京东日志信息
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public ResultDTO UpdateJdlogsExt(Jinher.AMP.BTP.Deploy.JdlogsDTO model)
        {
            ResultDTO dto = null;

            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                var            jdlogs         = Jdlogs.ObjectSet().FirstOrDefault(p => p.Id == model.Id);
                if (jdlogs != null)
                {
                    if (!string.IsNullOrEmpty(model.Remark))
                    {
                        jdlogs.Remark = model.Remark;
                    }
                    else
                    {
                        jdlogs.Remark = string.Empty;
                    }
                    jdlogs.ModifiedOn  = DateTime.Now;
                    jdlogs.EntityState = EntityState.Modified;
                    contextSession.SaveChanges();
                    dto = new ResultDTO()
                    {
                        ResultCode = 0, Message = "修改成功", isSuccess = true
                    };
                }
                else
                {
                    dto = new ResultDTO()
                    {
                        ResultCode = 1, Message = "该信息不存在", isSuccess = false
                    };
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("jdlogs信息保存异常。jdlogs:{0}", ex.Message));
                dto = new ResultDTO()
                {
                    ResultCode = 1, Message = ex.Message, isSuccess = false
                };
            }
            return(dto);
        }
Beispiel #5
0
        /// <summary>
        /// 查询所有的京东日志信息
        /// </summary>
        /// <param name="search">查询类</param>
        public List <Jinher.AMP.BTP.Deploy.JdlogsDTO> GetALLJdlogsListExt(Jinher.AMP.BTP.Deploy.CustomDTO.JdlogsDTO model)
        {
            List <Jinher.AMP.BTP.Deploy.JdlogsDTO> Jdlogslist = new List <Jinher.AMP.BTP.Deploy.JdlogsDTO>();
            var jdlogslist = Jdlogs.ObjectSet().Where(p => p.Isdisable == false).AsQueryable();

            if (model.AppId != Guid.Empty)
            {
                jdlogslist = jdlogslist.Where(p => p.AppId == model.AppId);
            }
            if (!string.IsNullOrEmpty(model.Content))
            {
                jdlogslist = jdlogslist.Where(p => p.Content.Contains(model.Content));
            }
            if (model.StartDate.ToString() != "0001/1/1 0:00:00" && model.EndDate.ToString() != "0001/1/1 0:00:00")
            {
                DateTime startTime = DateTime.Parse(model.StartDate.AddDays(-1).ToShortDateString().ToString() + " 23:59:59");
                DateTime endTime   = DateTime.Parse(model.EndDate.ToShortDateString().ToString() + " 23:59:59");
                jdlogslist = jdlogslist.Where(p => p.ModifiedOn >= startTime && p.ModifiedOn <= endTime);
            }
            if (model.ThirdECommerceType == ThirdECommerceTypeEnum.NotThirdECommerce || model.ThirdECommerceType == ThirdECommerceTypeEnum.JingDongDaKeHu)
            {
                jdlogslist = jdlogslist.Where(p => !p.ThirdECommerceType.HasValue);
            }
            else
            {
                jdlogslist = jdlogslist.Where(p => p.ThirdECommerceType.HasValue && p.ThirdECommerceType.Value == (int)model.ThirdECommerceType);
            }
            if (jdlogslist.Count() > 0)
            {
                foreach (var item in jdlogslist.OrderByDescending(p => p.SubTime).ToList())
                {
                    Jinher.AMP.BTP.Deploy.JdlogsDTO entity = new Jinher.AMP.BTP.Deploy.JdlogsDTO();
                    entity = CommonUtil.ReadObjectExchange(entity, item);
                    Jdlogslist.Add(entity);
                }
            }
            return(Jdlogslist);
        }
Beispiel #6
0
        /// <summary>
        /// 根据id删除京东日志信息
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public ResultDTO DeleteJdlogsExt(Guid id)
        {
            ResultDTO dto = null;

            try
            {
                ContextSession contextSession = ContextFactory.CurrentThreadContext;
                var            jdlogs         = Jdlogs.ObjectSet().FirstOrDefault(p => p.Id == id);
                if (jdlogs != null)
                {
                    jdlogs.Isdisable   = true;
                    jdlogs.ModifiedOn  = DateTime.Now;
                    jdlogs.EntityState = EntityState.Modified;
                    contextSession.SaveChanges();
                    dto = new ResultDTO()
                    {
                        ResultCode = 0, Message = "删除成功", isSuccess = true
                    };
                }
                else
                {
                    dto = new ResultDTO()
                    {
                        ResultCode = 1, Message = "该信息不存在", isSuccess = false
                    };
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(string.Format("jdlogs信息保存异常。jdlogs:{0}", ex.Message));
                dto = new ResultDTO()
                {
                    ResultCode = 1, Message = ex.Message, isSuccess = false
                };
            }
            return(dto);
        }
Beispiel #7
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);
        }