Пример #1
0
        public override void CreateShipment()
        {
            ShipReply result = null;
            ProcessShipmentRequest request = CreateShipmentRequest();

            try
            {
                ShipService service = new ShipService();
                service.Url = Url;
                ProcessShipmentReply reply = service.processShipment(request);
                if ((reply.HighestSeverity != NotificationSeverityType.ERROR) && (reply.HighestSeverity != NotificationSeverityType.FAILURE))
                {
                    result = SetShipmentReply(reply);
                }
                else
                {
                    if (reply.Notifications.Length > 0)
                    {
                        ErrorMessage = string.Format("{0} {1}", reply.Notifications[0].Code, reply.Notifications[0].Message);
                    }
                }

                ShipReplyEx = result;
            }
            catch (SoapException e)
            {
                Debug.WriteLine(e.Detail.InnerText);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            // return result;
        }
Пример #2
0
        private ShipReply SetShipmentReply(ProcessShipmentReply reply)
        {
            ShipReply result = new ShipReply();

            //Details for each package
            foreach (CompletedPackageDetail packageDetail in reply.CompletedShipmentDetail.CompletedPackageDetails)
            {
                if (null != packageDetail.Label.Parts[0].Image)
                {
                    result.TrackNumber = packageDetail.TrackingIds[0].TrackingNumber;
                    result.TrackFormId = packageDetail.TrackingIds[0].FormId;
                    result.LabelImage  = packageDetail.Label.Parts[0].Image;
                }
            }
            return(result);
        }
Пример #3
0
        public JsonResult CreateShipInfo(string orderid)
        {
            ShipReply reply = null;

            try
            {
                long      orderId = long.Parse(orderid);
                OrderInfo order   = ServiceHelper.Create <IOrderService>().GetOrder(orderId);

                ISiteSettingService siteService = ServiceHelper.Create <ISiteSettingService>();
                string FedExKey           = siteService.GetSiteValue("FedExKey");
                string FedExPassword      = siteService.GetSiteValue("FedExPassword");
                string FedExAccountNumber = siteService.GetSiteValue("FedExAccountNumber");
                string FedExMeterNumber   = siteService.GetSiteValue("FedExMeterNumber");
                string FedShipUrl         = siteService.GetSiteValue("FedShipUrl");

                string FedPersonName  = siteService.GetSiteValue("PlatformCollectionPersonName");
                string FedCompanyName = siteService.GetSiteValue("PlatformCollectionCompanyName");
                string FedPhoneNumber = siteService.GetSiteValue("PlatformCollectionPhoneNumber");
                string FedStreetLine  = siteService.GetSiteValue("PlatformCollectionStreetLine");
                string FedCity        = siteService.GetSiteValue("PlatformCollectionCity");
                string FedPostalCode  = siteService.GetSiteValue("PlatformCollectionPostalCode");
                string FedCountryCode = siteService.GetSiteValue("PlatformCollectionCountryCode");

                IShipmentService shipmentService = ServiceHelper.Create <IShipmentService>();

                Address origin = new Address(FedStreetLine, "", "", FedCity, "", FedPostalCode, FedCountryCode);
                origin.PersonName  = FedPersonName;
                origin.PhoneNumber = FedPhoneNumber;
                origin.CompanyName = FedCompanyName;

                Address dest = shipmentService.GetAddress(order.UserId, order.RegionId);

                if (dest != null)
                {
                    dest.Line1       = order.Address;
                    dest.PersonName  = order.ShipTo;
                    dest.PhoneNumber = order.CellPhone;
                }
                else
                {
                    dest             = new Address(order.Address, null, null, null, null, null, null);
                    dest.PersonName  = order.ShipTo;
                    dest.PhoneNumber = order.CellPhone;
                }

                List <OrderItemInfo> itemInfoList = order.OrderItemInfo.OrderBy(x => x.Id).ToList();
                if (itemInfoList != null && itemInfoList.Count > 0)
                {
                    List <ShipPackage> pkgList = new List <ShipPackage>();
                    foreach (OrderItemInfo item in itemInfoList)
                    {
                        ShipPackage package = new ShipPackage()
                        {
                            Num = Convert.ToInt32(item.Quantity), PackingUnit = item.PackingUnit
                        };
                        package.OrderItemId = item.Id;
                        package.Description = string.Format("{0}-{1}", item.ProductName, item.SpecLevel);
                        pkgList.Add(package);
                    }

                    CreateShipQuery query = new CreateShipQuery()
                    {
                        Url = FedShipUrl, Key = FedExKey, Password = FedExPassword, AccountNumber = FedExAccountNumber, MeterNumber = FedExMeterNumber
                    };
                    query.ShipPkgs = pkgList;
                    query.Origin   = origin;
                    query.Dest     = dest;
                    query.CoinType = order.CoinType == 1 ? "CNY" : "USD";
                    query.OrderId  = orderId;

                    reply = shipmentService.CreateShip(query);
                }

                if (reply != null)
                {
                    if (!String.IsNullOrEmpty(reply.TrackNumber))
                    {
                        return(Json(new { Success = true, TrackNumber = reply.TrackNumber }));
                    }
                    else
                    {
                        return(Json(new { TrackNumber = "", msg = reply.ErrorMessage }));
                    }
                }
                else
                {
                    return(Json(new { TrackNumber = "" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { msg = ex.Message }));
            }
        }
Пример #4
0
        /// <summary>
        /// 生成运单
        /// </summary>
        public ShipReply CreateShip(CreateShipQuery shipQuery)
        {
            ShipReply        reply       = new ShipReply();
            FedExShipService shipService = new FedExShipService(shipQuery.Url, shipQuery.Key, shipQuery.Password, shipQuery.AccountNumber, shipQuery.MeterNumber);
            List <Package>   packages    = new List <Package>();
            Package          pkg;

            foreach (ShipPackage item in shipQuery.ShipPkgs)
            {
                //pkg = GetPackage(item);
                //pkg.Currency = shipQuery.CoinType;
                //pkg.Description = item.Description;
                //pkg.PackageCount = item.Num;
                //pkg.PackageType = "自备包装";
                //packages.Add(pkg);

                if (item.Num > 0)
                {
                    for (int i = 0; i < item.Num; i++)
                    {
                        pkg              = GetPackage(item);
                        pkg.Currency     = shipQuery.CoinType;
                        pkg.Description  = item.Description;
                        pkg.PackageCount = 1;
                        pkg.PackageType  = "自备包装";
                        packages.Add(pkg);
                    }
                }
            }
            try
            {
                ShipmentEx shipEx = new ShipmentEx(shipQuery.Origin, shipQuery.Dest, packages);
                shipEx.Currency = shipQuery.CoinType;

                CreateShipRep    shipRep   = shipService.CreateShip(shipEx);
                List <ShipReply> replyList = shipRep.ReplyList;
                reply.ErrorMessage = shipRep.Message;
                if (replyList != null)
                {
                    foreach (ShipReply item in replyList)
                    {
                        OrderShip orderShip = new OrderShip()
                        {
                            OrderId = shipQuery.OrderId, OrderItemId = shipQuery.OrderItemId, TrackFormId = item.TrackFormId, TrackNumber = item.TrackNumber
                        };
                        //  orderShip.LabelImage = item.LabelImage;
                        string result = System.Text.Encoding.UTF8.GetString(item.LabelImage);
                        orderShip.LabelImage = item.LabelImage;
                        orderShip.Master     = item.Master;
                        context.OrderShip.Add(orderShip);
                    }
                    context.SaveChanges();
                    List <ShipReply> tmpShip = replyList.Where(x => x.Master == true).ToList();
                    if (tmpShip.Count > 0)
                    {
                        reply = tmpShip[0];
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
            }
            catch (Exception ex)
            {
            }

            return(reply);
        }