示例#1
0
        //DHL Api 预报信息
        //Add By zhengsong
        public ExpressRespons AddExpressResponseToAPI(ExpressRespons expressResponse, WayBillInfo wayBillInfo)
        {
            if (null == expressResponse)
            {
                throw new BusinessLogicException("数据不能为空!");
            }
            var result = _expressResponsRepository.Exists(p => p.WayBillNumber == expressResponse.WayBillNumber);

            if (result)
            {
                throw new BusinessLogicException("该数据已存在!");
            }

            expressResponse.LastUpdatedBy = wayBillInfo.CreatedBy;
            expressResponse.LastUpdatedOn = DateTime.Now;
            expressResponse.CreatedBy     = wayBillInfo.CreatedBy;
            expressResponse.CreatedOn     = DateTime.Now;
            //_expressResponsRepository.Add(expressResponse);

            //wayBillInfo.LastUpdatedBy = _workContext.User.UserUame;
            //wayBillInfo.LastUpdatedOn = DateTime.Now;
            //wayBillInfo.CustomerOrderInfo.LastUpdatedBy = _workContext.User.UserUame;
            //wayBillInfo.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;
            //_wayBillInfoRepository.Modify(wayBillInfo);
            //using (var tran = new TransactionScope())
            //{
            //    //_expressResponsRepository.UnitOfWork.Commit();
            //    //_wayBillInfoRepository.UnitOfWork.Commit();
            //    AddDeliveryChannelChangeLog(wayBillInfo.WayBillNumber, wayBillInfo.OutShippingMethodID.Value, wayBillInfo.VenderCode, wayBillInfo.CreatedBy);
            //    tran.Complete();
            //}
            return(expressResponse);
        }
示例#2
0
        /// <summary>
        /// 更新快递服务响应的数据
        /// </summary>
        /// <param name="expressResponse"></param>
        public void UpdateExpressResponse(ExpressRespons expressResponse)
        {
            if (null == expressResponse)
            {
                throw new BusinessLogicException("数据不能为空!");
            }
            var responseEntity = _expressResponsRepository.GetList(p => p.WayBillNumber == expressResponse.WayBillNumber).FirstOrDefault();

            if (null == responseEntity)
            {
                throw new BusinessLogicException("该数据不存在,更新失败!");
            }
            expressResponse.LastUpdatedBy = _workContext.User.UserUame;
            expressResponse.LastUpdatedOn = DateTime.Now;
            expressResponse.CreatedBy     = _workContext.User.UserUame;
            expressResponse.CreatedOn     = DateTime.Now;

            _expressResponsRepository.Modify(expressResponse);
            _expressResponsRepository.UnitOfWork.Commit();
        }
示例#3
0
        /// <summary>
        /// 添加快递服务响应的数据,并更新运单的物流商、发货运输方式ID和跟踪号
        /// </summary>
        /// <param name="expressResponse">快递响应实例</param>
        /// <param name="wayBillInfo">运单实例</param>
        public void AddExpressResponse(ExpressRespons expressResponse, WayBillInfo wayBillInfo, bool isNologin = false)
        {
            if (null == expressResponse)
            {
                throw new BusinessLogicException("数据不能为空!");
            }
            var result = _expressResponsRepository.Exists(p => p.WayBillNumber == expressResponse.WayBillNumber);

            if (result)
            {
                throw new BusinessLogicException("该数据已存在!");
            }
            var wayBill = _wayBillInfoRepository.Get(wayBillInfo.WayBillNumber);

            expressResponse.LastUpdatedBy = isNologin ? "System" : _workContext.User.UserUame;
            expressResponse.LastUpdatedOn = DateTime.Now;
            expressResponse.CreatedBy     = isNologin ? "System" : _workContext.User.UserUame;
            expressResponse.CreatedOn     = DateTime.Now;
            _expressResponsRepository.Add(expressResponse);
            wayBill.VenderCode          = wayBillInfo.VenderCode;
            wayBill.OutShippingMethodID = wayBillInfo.InShippingMethodID;
            wayBill.TrackingNumber      = wayBillInfo.TrackingNumber;
            wayBill.CustomerOrderInfo.TrackingNumber = wayBillInfo.TrackingNumber;
            wayBill.LastUpdatedBy = isNologin ? "System" : _workContext.User.UserUame;
            wayBill.LastUpdatedOn = DateTime.Now;
            wayBill.CustomerOrderInfo.LastUpdatedBy = isNologin ? "System" : _workContext.User.UserUame;
            wayBill.CustomerOrderInfo.LastUpdatedOn = DateTime.Now;
            _wayBillInfoRepository.Modify(wayBill);

            using (var tran = new TransactionScope())
            {
                _expressResponsRepository.UnitOfWork.Commit();
                _wayBillInfoRepository.UnitOfWork.Commit();
                AddDeliveryChannelChangeLog(wayBillInfo.WayBillNumber, wayBillInfo.OutShippingMethodID.Value, wayBillInfo.VenderCode, isNologin);
                tran.Complete();
            }
        }
示例#4
0
        /// <summary>
        /// 添加快递服务响应的数据
        /// </summary>
        /// <param name="expressResponses"></param>
        public void AddExpressResponse(IEnumerable <ExpressRespons> expressResponses)
        {
            string errorWayBillNumber = string.Empty;
            var    enumerable         = expressResponses as ExpressRespons[] ?? expressResponses.ToArray();

            if (!enumerable.Any())
            {
                throw new BusinessLogicException("数据不能为空!");
            }
            foreach (var expressResponse in enumerable)
            {
                ExpressRespons response = expressResponse;
                var            result   = _expressResponsRepository.Exists(p => p.WayBillNumber == response.WayBillNumber);
                if (result)
                {
                    continue;
                }
                expressResponse.LastUpdatedBy = _workContext.User.UserUame;
                expressResponse.LastUpdatedOn = DateTime.Now;
                expressResponse.CreatedBy     = _workContext.User.UserUame;
                expressResponse.CreatedOn     = DateTime.Now;
                try
                {
                    _expressResponsRepository.Add(expressResponse);
                    _expressResponsRepository.UnitOfWork.Commit();
                }
                catch (Exception)
                {
                    errorWayBillNumber = expressResponse + ",";
                }
            }
            if (!string.IsNullOrWhiteSpace(errorWayBillNumber))
            {
                throw new BusinessLogicException("提交失败的运单有:{0}!".FormatWith(errorWayBillNumber));
            }
        }
示例#5
0
        public Dictionary <string, string> PostDHLShipment(List <WayBillInfo> dhLWayBill)
        {
            Dictionary <string, string> errorwayBills = new Dictionary <string, string>();

            var applicationName = string.Empty;

            foreach (var wayBillInfo in dhLWayBill)
            {
                var expressAccount = _expressService.GetExpressAccountInfo(venderCode, wayBillInfo.InShippingMethodID.Value);
                if (expressAccount == null)
                {
                    //"DHL帐号不存在,请求DHL接口失败"
                    errorwayBills.Add(wayBillInfo.WayBillNumber, "DHL帐号不存在,请求DHL接口失败");
                    continue;
                }
                applicationName = wayBillInfo.ApplicationInfos.First().ApplicationName.Cutstring(70);
                string[] shippingAddress = wayBillInfo.ShippingInfo.ShippingAddress.StringSplitLengthWords(35).ToArray();
                wayBillInfo.VenderCode          = venderCode;
                wayBillInfo.OutShippingMethodID = wayBillInfo.InShippingMethodID;
                if (null != wayBillInfo.ExpressRespons)
                {
                    //"运单号为{0},已经调用DHL接口,无需重复请求"
                    errorwayBills.Add(wayBillInfo.WayBillNumber, "已经调用DHL接口,无需重复请求");
                    continue;
                }
                LMS.Data.Express.DHL.Request.ShipmentValidateRequestAP ap = new LMS.Data.Express.DHL.Request.
                                                                            ShipmentValidateRequestAP()
                {
                    Billing = new LMS.Data.Express.DHL.Request.Billing()
                    {
                        DutyPaymentType      = wayBillInfo.EnableTariffPrepay ? LMS.Data.Express.DHL.Request.DutyTaxPaymentType.S : LMS.Data.Express.DHL.Request.DutyTaxPaymentType.R,
                        ShipperAccountNumber = expressAccount.ShipperAccountNumber,
                        ShippingPaymentType  = LMS.Data.Express.DHL.Request.ShipmentPaymentType.S
                    },
                    Commodity = new[]
                    {
                        new LMS.Data.Express.DHL.Request.Commodity()
                        {
                            CommodityCode = "1111"                 //商品代码
                        }
                    },
                    Consignee = new LMS.Data.Express.DHL.Request.Consignee()         //收货人
                    {
                        AddressLine = new[]
                        {
                            shippingAddress[0],
                            string.IsNullOrWhiteSpace(wayBillInfo.ShippingInfo.ShippingAddress1) && shippingAddress.Length > 1?shippingAddress[1]:wayBillInfo.ShippingInfo.ShippingAddress1,                                                          //多地址 yungchu
                            string.IsNullOrWhiteSpace(wayBillInfo.ShippingInfo.ShippingAddress2) && shippingAddress.Length > 2?shippingAddress[2]:wayBillInfo.ShippingInfo.ShippingAddress2
                        },
                        City        = wayBillInfo.ShippingInfo.ShippingCity,
                        CompanyName = string.IsNullOrWhiteSpace(wayBillInfo.ShippingInfo.ShippingCompany) ? (wayBillInfo.ShippingInfo.ShippingFirstName + " " +
                                                                                                             wayBillInfo.ShippingInfo.ShippingLastName) : wayBillInfo.ShippingInfo.ShippingCompany,
                        Contact = new LMS.Data.Express.DHL.Request.Contact()
                        {
                            //Email = new Email()
                            //{
                            //    Body = "*****@*****.**",
                            //    cc = new[] { "String", "String" },
                            //    From = "*****@*****.**",
                            //    ReplyTo = "String",
                            //    Subject = "String",
                            //    To = "*****@*****.**"
                            //},
                            PersonName =
                                wayBillInfo.ShippingInfo.ShippingFirstName + " " +
                                wayBillInfo.ShippingInfo.ShippingLastName,
                            PhoneNumber    = wayBillInfo.ShippingInfo.ShippingPhone,
                            PhoneExtension = 455,
                        },
                        CountryCode = wayBillInfo.ShippingInfo.CountryCode,
                        PostalCode  = wayBillInfo.ShippingInfo.ShippingZip
                    },
                    Dutiable = new LMS.Data.Express.DHL.Request.Dutiable()
                    {
                        DeclaredCurrency = "USD",
                        DeclaredValue    = wayBillInfo.ApplicationInfos.Sum(p => (p.UnitPrice ?? 1) * (p.Qty ?? 1)).ToString("F2"),
                        ShipperEIN       = "Text"
                    },
                    LanguageCode  = "en",
                    PiecesEnabled = LMS.Data.Express.DHL.Request.PiecesEnabled.Y,
                    Reference     = new[]
                    {
                        new LMS.Data.Express.DHL.Request.Reference()
                        {
                            ReferenceID = wayBillInfo.WayBillNumber
                        }
                    },
                    Request = new LMS.Data.Express.DHL.Request.Request()
                    {
                        ServiceHeader = new LMS.Data.Express.DHL.Request.ServiceHeader()
                        {
                            //MessageReference = "1234567890123456789012345678901",
                            //MessageTime = DateTime.Parse("2011-07-11T11:25:56.000-08:00"),
                            Password = expressAccount.Password,
                            SiteID   = expressAccount.Account
                        }
                    },
                    ShipmentDetails = new LMS.Data.Express.DHL.Request.ShipmentDetails()         //出货详情
                    {
                        Contents          = applicationName,
                        CurrencyCode      = "USD",
                        Date              = DateTime.Now,
                        DimensionUnit     = LMS.Data.Express.DHL.Request.DimensionUnit.C,
                        DoorTo            = LMS.Data.Express.DHL.Request.DoorTo.DD,
                        GlobalProductCode = "P",
                        LocalProductCode  = "P",
                        NumberOfPieces    = 1,
                        PackageType       = LMS.Data.Express.DHL.Request.PackageType.EE,
                        //Weight = wayBillInfo.ApplicationInfos.Sum(p => (p.UnitWeight ?? 0.001M) * (p.Qty ?? 1)),
                        Weight     = wayBillInfo.Weight ?? 0,
                        WeightUnit = LMS.Data.Express.DHL.Request.WeightUnit.K,
                        //保险费
                        //InsuredAmount =
                        //    wayBillInfo.CustomerOrderInfo.InsureAmount != null
                        //        ? wayBillInfo.CustomerOrderInfo.InsureAmount.ToString()
                        //        : "",
                        Pieces = new[]
                        {
                            new LMS.Data.Express.DHL.Request.Piece
                            {
                                // PieceID = "String",
                                Depth = Math.Ceiling(wayBillInfo.Length ?? 0).ConvertTo <uint>(),
                                // DimWeight = (decimal)2.111,
                                Height = Math.Ceiling(wayBillInfo.Height ?? 0).ConvertTo <uint>(),
                                //PackageType = PackageType.EE,
                                Weight = Math.Ceiling(wayBillInfo.Weight ?? 0),
                                Width  = Math.Ceiling(wayBillInfo.Width ?? 0).ConvertTo <uint>()
                            }
                        }
                    },
                    Shipper = new LMS.Data.Express.DHL.Request.Shipper()         //发货人
                    {
                        ShipperID   = expressAccount.ShipperAccountNumber,
                        AddressLine = new[] { expressAccount.Address },
                        City        = expressAccount.City,
                        CompanyName = expressAccount.CompanyName,
                        Contact     = new LMS.Data.Express.DHL.Request.Contact()
                        {
                            //Email = new Email()
                            //{
                            //    Body = "*****@*****.**",
                            //    cc = new[] { "String" },
                            //    From = "*****@*****.**",
                            //    ReplyTo = "*****@*****.**",
                            //    Subject = "String",
                            //    To = "*****@*****.**"
                            //},
                            PersonName     = expressAccount.PersonName,
                            FaxNumber      = expressAccount.FaxNumber,
                            PhoneExtension = expressAccount.PhoneExtension.ConvertTo <uint>(),
                            PhoneNumber    = expressAccount.PhoneNumber,
                            Telex          = expressAccount.Telex
                        },
                        CountryCode  = expressAccount.CountryCode,
                        CountryName  = expressAccount.CountryName,
                        DivisionCode = expressAccount.DivisionCode,
                        PostalCode   = expressAccount.PostalCode
                    }
                };

                ap.Consignee.AddressLine = ap.Consignee.AddressLine.Where(p => !string.IsNullOrWhiteSpace(p)).ToArray();

                try
                {
                    var country = _countryService.GetCountryList("").Single(c => c.CountryCode == wayBillInfo.ShippingInfo.CountryCode.ToUpperInvariant());
                    ap.Consignee.CountryName = country.Name;
                    var responseResult = _expressService.PostDHLShipment(ap, expressAccount.ServerUrl);
                    if (null != responseResult)
                    {
                        string         fileExtension = ".jpg";
                        ExpressRespons response      = new ExpressRespons()
                        {
                            DHLRoutingBarCode    = responseResult.DHLRoutingCode,
                            DataIdentifier       = responseResult.Pieces[0].DataIdentifier,
                            DHLRoutingBarCodeImg =
                                Tools.Base64StringToImage(dhlBarCodePath,
                                                          "DHLRouting" + Guid.NewGuid().ToString(""),
                                                          responseResult.Barcodes.DHLRoutingBarCode,
                                                          fileExtension),
                            DHLRoutingDataId       = responseResult.DHLRoutingDataId,
                            LicensePlate           = responseResult.Pieces[0].LicensePlate,
                            LicensePlateBarCodeImg =
                                Tools.Base64StringToImage(dhlBarCodePath,
                                                          "LicensePlate" +
                                                          Guid.NewGuid().ToString(""),
                                                          responseResult.Pieces[0].LicensePlateBarCode,
                                                          fileExtension),
                            ShipmentDetailTime         = responseResult.ShipmentDate,
                            ServiceAreaCode            = responseResult.DestinationServiceArea.ServiceAreaCode,
                            FacilityCode               = responseResult.DestinationServiceArea.FacilityCode,
                            WayBillNumber              = wayBillInfo.WayBillNumber,
                            AirwayBillNumber           = responseResult.AirwayBillNumber,
                            AirwayBillNumberBarCodeImg =
                                Tools.Base64StringToImage(dhlBarCodePath,
                                                          "WayBillNumber" +
                                                          responseResult.AirwayBillNumber,
                                                          responseResult.Barcodes.AWBBarCode, fileExtension),
                        };

                        wayBillInfo.TrackingNumber = responseResult.AirwayBillNumber;
                        wayBillInfo.CustomerOrderInfo.TrackingNumber = responseResult.AirwayBillNumber;
                        try
                        {
                            _expressService.AddExpressResponse(response, wayBillInfo, true);
                        }
                        catch (Exception ex)
                        {
                            Log.Exception(ex);
                            errorwayBills.Add(wayBillInfo.WayBillNumber, ex.Message);
                            //model.Message += "运单号为{0}:错误信息:{1}".FormatWith(wayBillInfo.WayBillNumber, ex.Message);
                        }
                    }
                    else
                    {
                        errorwayBills.Add(wayBillInfo.WayBillNumber, "请求DHL接口失败");
                        //errorwayBills += "[" + wayBillInfo.WayBillNumber + "]";
                        //model.Message += "运单号为{0}:请求DHL接口失败".FormatWith(wayBillInfo.WayBillNumber);
                    }
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                    errorwayBills.Add(wayBillInfo.WayBillNumber, ex.Message);
                    //model.Message += "运单号为{0}:错误信息:{1}".FormatWith(wayBillInfo.WayBillNumber, ex.Message);
                }
            }
            return(errorwayBills);
        }