Beispiel #1
0
        public object PostAddShippingAddress(ShippingAddressAddModel value)
        {
            if (value.shopbranchid == 0)
            {
                throw new MallException("获取门店ID失败");
            }
            long shopBranchId = value.shopbranchid;

            CheckUserLogin();
            Entities.ShippingAddressInfo shippingAddr = new Entities.ShippingAddressInfo();
            shippingAddr.UserId    = CurrentUser.Id;
            shippingAddr.RegionId  = value.regionId;
            shippingAddr.Address   = value.address;
            shippingAddr.Phone     = value.phone;
            shippingAddr.ShipTo    = value.shipTo;
            shippingAddr.Latitude  = value.latitude;
            shippingAddr.Longitude = value.longitude;

            var shopBranchInfo = ServiceProvider.Instance <IShopBranchService> .Create.GetShopBranchById(shopBranchId);

            if (shopBranchInfo != null && shopBranchInfo.IsStoreDelive)
            {
                if (shopBranchInfo.ServeRadius > 0)
                {
                    string form = string.Format("{0},{1}", shippingAddr.Latitude, shippingAddr.Longitude); //收货地址的经纬度
                    if (form.Length <= 1)                                                                  //地址不含经纬度的不可配送
                    {
                        throw new MallApiException("地址经纬度获取失败");
                    }

                    double Distances = ServiceProvider.Instance <IShopBranchService> .Create.GetLatLngDistancesFromAPI(form, string.Format("{0},{1}", shopBranchInfo.Latitude, shopBranchInfo.Longitude));

                    if (Distances > shopBranchInfo.ServeRadius)//距离超过配送距离的不可配送,距离计算失败不可配送
                    {
                        throw new MallApiException("距离超过门店配送距离的不可配送");
                    }
                }
            }
            else
            {
                return(ErrorResult("门店不提供配送服务"));
            }
            try
            {
                ServiceProvider.Instance <IShippingAddressService> .Create.AddShippingAddress(shippingAddr);
            }
            catch (Exception ex)
            {
                return(ErrorResult(ex.Message));
            }
            return(SuccessResult());
        }
 public object PostAddShippingAddress(ShippingAddressAddModel value)
 {
     CheckUserLogin();
     Entities.ShippingAddressInfo shippingAddr = new Entities.ShippingAddressInfo();
     shippingAddr.UserId        = CurrentUser.Id;
     shippingAddr.RegionId      = value.regionId;
     shippingAddr.Address       = value.address;
     shippingAddr.Phone         = value.phone;
     shippingAddr.ShipTo        = value.shipTo;
     shippingAddr.Latitude      = value.latitude;
     shippingAddr.Longitude     = value.longitude;
     shippingAddr.AddressDetail = value.addressDetail;
     try
     {
         ServiceProvider.Instance <IShippingAddressService> .Create.AddShippingAddress(shippingAddr);
     }
     catch (Exception ex)
     {
         return(ErrorResult(ex.Message));
     }
     return(SuccessResult());
 }
Beispiel #3
0
        //新增收货地址
        public object PostAddShippingAddress(ShippingAddressAddModel value)
        {
            CheckUserLogin();
            ShippingAddressInfo shippingAddr = new ShippingAddressInfo();

            shippingAddr.UserId    = CurrentUser.Id;
            shippingAddr.RegionId  = value.regionId;
            shippingAddr.Address   = value.address;
            shippingAddr.Phone     = value.phone;
            shippingAddr.ShipTo    = value.shipTo;
            shippingAddr.Latitude  = value.latitude;
            shippingAddr.Longitude = value.longitude;
            try
            {
                ServiceProvider.Instance <IShippingAddressService> .Create.AddShippingAddress(shippingAddr);
            }
            catch (Exception ex)
            {
                return(Json(new { Success = "false", Msg = ex.Message }));
            }
            return(Json(new { Success = "true" }));
        }
        public object PostAddShippingAddress(ShippingAddressAddModel value)
        {
            long?shopbranchid;
            int  num;

            if (value.shopbranchid.HasValue)
            {
                shopbranchid = value.shopbranchid;
                num          = shopbranchid.Value != 0L ? 1 : 0;
            }
            else
            {
                num = 0;
            }
            if (num == 0)
            {
                throw new HimallException("获取门店ID失败");
            }
            shopbranchid = value.shopbranchid;
            long id = shopbranchid.Value;

            this.CheckUserLogin();
            ShippingAddressInfo shipinfo = new ShippingAddressInfo();

            shipinfo.UserId    = this.CurrentUser.Id;
            shipinfo.RegionId  = value.regionId;
            shipinfo.Address   = value.address;
            shipinfo.Phone     = value.phone;
            shipinfo.ShipTo    = value.shipTo;
            shipinfo.Latitude  = new float?(value.latitude);
            shipinfo.Longitude = new float?(value.longitude);
            ShopBranchInfo shopBranchById = Instance <IShopBranchService> .Create.GetShopBranchById(id);

            if (shopBranchById == null || !shopBranchById.IsStoreDelive)
            {
                return((object)this.Json(new
                {
                    Success = "false",
                    Msg = "门店不提供配送服务"
                }));
            }
            if (shopBranchById.ServeRadius.HasValue)
            {
                string fromLatLng = string.Format("{0},{1}", (object)shipinfo.Latitude, (object)shipinfo.Longitude);
                if (fromLatLng.Length <= 1)
                {
                    return((object)this.Json(new
                    {
                        Success = "false",
                        Msg = "地址经纬度获取失败"
                    }));
                }
                double distancesFromApi = Instance <IShopBranchService> .Create.GetLatLngDistancesFromAPI(fromLatLng, string.Format("{0},{1}", (object)shopBranchById.Latitude, (object)shopBranchById.Longitude));

                int?serveRadius = shopBranchById.ServeRadius;
                if ((distancesFromApi <= (double)serveRadius.GetValueOrDefault() ? 0 : (serveRadius.HasValue ? 1 : 0)) != 0)
                {
                    return((object)this.Json(new
                    {
                        Success = "false",
                        Msg = "距离超过门店配送距离的不可配送"
                    }));
                }
            }
            try
            {
                Instance <IShippingAddressService> .Create.AddShippingAddress(shipinfo);
            }
            catch (Exception ex)
            {
                return((object)this.Json(new
                {
                    Success = "false",
                    Msg = ex.Message
                }));
            }
            return((object)this.Json(new
            {
                Success = "true"
            }));
        }