public override string GetSdclEndPoint(string clientCode, ref string prevServiceCode) { var helper = new WebAPIHelper(); var parameters = new NameValueCollection(2) { { "clientcode", clientCode }, { "prevsdclcode", prevServiceCode } }; var res = helper.Get <SdclConnectInfo>(BpController, "getsdclinfo", parameters); prevServiceCode = res.Code; return(res.Endpoint); }
// // GET: /BMapRoutePlanning/ public ActionResult Index(long orderId) { Order order = _orderService.GetOrderByOrderId(orderId); if (order.OrderStatus == OrderStatusEnumType.FINISHED.ToString()) { return(Content("<script>alert('订单已派送结束');location.href='/Order/OrderDetail?orderId=" + orderId + "'</script>")); } Address address = _addressService.GetAddress(order.AddressId); // Current area second level delivery station DeliveryStation deliveryStation = _deliveryStationService.GetDeliveryStations(address.AreaId, 2).FirstOrDefault(); // Get Third level delivery station to destination in current area Dictionary <double, DeliveryStation> distanceMap = new Dictionary <double, DeliveryStation>(); if (deliveryStation.DeliveryStations.Count == 0) { return(Content("<script>alert('当前地址下无子级派送点');location.href='/Order/OrderDetail?orderId=" + orderId + "'</script>")); } else { foreach (var obj in deliveryStation.DeliveryStations) { double key = MathHelper.GetDistance(obj.Longitude, obj.Latitude, address.Longitude, address.Latitude); if (!distanceMap.ContainsKey(key)) { distanceMap.Add(key, obj); } } } // Order by distance var tempMap = distanceMap.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value); List <DeliveryStation> stationList = new List <DeliveryStation>(); int index = 1; foreach (var o in tempMap.Keys) { if ((index == tempMap.Keys.Count && tempMap.Keys.Count <= 15) || index == 16) { break; } stationList.Add(tempMap[o]); index++; } // Request BMap WebAPI and receive Json call back data String origins = "&origins="; for (var i = 0; i < stationList.Count; i++) { if (i == 0) { origins += stationList[i].Latitude + "," + stationList[i].Longitude; } else { origins += "|" + stationList[i].Latitude + "," + stationList[i].Longitude; } } String destinations = "&destinations=" + address.Latitude + "," + address.Longitude; String ak = "&ak=" + Constants.BMAP_AK; BMapDataModel bMapDataModel = JsonHelper. DeserializeJsonToObject <BMapDataModel>(WebAPIHelper.Get(Constants.BMAP_DRIVING_BASE_URL + Constants.BMAP_OUTPUT_TYPE + origins + destinations + ak)); // Get min index of delivery station int minDistanceIndex = bMapDataModel.Result.FindIndex(x => x.Distance.Value == bMapDataModel.Result.Min(y => y.Distance.Value)); // init originPoint OriginPointViewModel startUpPoint = new OriginPointViewModel(Constants.START_POINT_NAME, Constants.START_POINT_ADDRESS, Constants.START_POINT_LONGITUDE, Constants.START_POINT_LATITUDE); OriginPointViewModel firstPoint = new OriginPointViewModel(deliveryStation.ParentDeliveryStation.Name, deliveryStation.ParentDeliveryStation.Address, deliveryStation.ParentDeliveryStation.Longitude, deliveryStation.ParentDeliveryStation.Latitude); OriginPointViewModel secondPoint = new OriginPointViewModel(deliveryStation.Name, deliveryStation.Address, deliveryStation.Longitude, deliveryStation.Latitude); OriginPointViewModel thirdPoint = new OriginPointViewModel(stationList[minDistanceIndex].Name, stationList[minDistanceIndex].Address, stationList[minDistanceIndex].Longitude, stationList[minDistanceIndex].Latitude); OriginPointViewModel endPoint = new OriginPointViewModel(address.DeliveryAddress, address.DeliveryAddress, address.Longitude, address.Latitude); List <DeliveryInfoViewModel> deliveryinfos = new List <DeliveryInfoViewModel>(); List <DeliveryInfo> initDeliveryInfos = _deliveryInfoService.GetDeliveryInfo(orderId); foreach (var item in initDeliveryInfos) { DeliveryInfoViewModel temp = new DeliveryInfoViewModel(item.Description, item.UpdateTime); deliveryinfos.Add(temp); } BMapViewModel bMapViewModel = new BMapViewModel() { DeliveryInfos = deliveryinfos, OriginPoints = new List <OriginPointViewModel>() { startUpPoint, firstPoint, secondPoint, thirdPoint, endPoint }, Order = order }; return(View(bMapViewModel)); }
public ActionResult AddAddress(string areaId, string address, string receiverName, string receiverPhone, bool isDefault, long?OrderId) { Area area = _areaRepository.GetAreaById(int.Parse(areaId)); City city = _cityRepository.GetCityById(area.CityId); Province province = _provinceRepository.GetProvinceById(city.ProvinceId); long customerId = (Session[Constants.SESSION_USER] as Customer).Id; if (OrderId != 0) { isDefault = true; } if (isDefault) { List <Address> addressList = _addressService.GetAddresses(customerId); Address defaultAddress = addressList.Where(x => x.IsDefault == isDefault).ToList().FirstOrDefault(); if (defaultAddress != null) { defaultAddress.IsDefault = false; _addressService.UpdateAddress(defaultAddress); } } string fullAddress = province.ProvinceName + city.CityName + area.AreaName + address; string addressParam = "&address=" + fullAddress; string ak = "&ak=" + Constants.BMAP_AK; LocationDataModel locationDataModel = JsonHelper.DeserializeJsonToObject <LocationDataModel>(WebAPIHelper.Get(Constants.BMAP_GEOCODER_BASE_URL + Constants.BMAP_OUTPUT_TYPE + addressParam + ak)); Address DeliveryAddress = new Address() { ReceiverName = receiverName, ReceiverPhone = receiverPhone, DeliveryAddress = fullAddress, IsDefault = isDefault, Latitude = locationDataModel.Result.Location.Lat, Longitude = locationDataModel.Result.Location.Lng, AreaId = int.Parse(areaId), CustomerId = customerId }; _addressService.AddAddress(DeliveryAddress); if (OrderId == 0 || OrderId == null) { return(RedirectToAction("GetAddress")); } else { return(RedirectToRoute(new { controller = "Order", action = "CheckOrder", orderId = OrderId })); } }