Esempio n. 1
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 }));
            }
        }
Esempio n. 2
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);
        }