/// <summary> /// 根据用户位置,区域,菜品,获取周围5千米以内的骑手位置信息 /// /// </summary> /// <param name="foodId"></param> /// <param name="lat"></param> /// <param name="lng"></param> /// <param name="areaId"></param> /// <returns></returns> public int[] GetRiderIdsByFoodId_Position(int foodId, decimal lat, decimal lng, int areaId) { var list = CacheHelper.GetByCondition <RiderStockJoin>("RiderStockJoin", " riderstatus=1 and riderAreaId=" + areaId + " and foodId=" + foodId); int[] riderIds = list.Select(p => (int)p.riderId).Distinct().ToArray(); List <int> r = new List <int>(); foreach (var item in riderIds) { RiderPosition rp = CacheHelper.GetRiderPosition(item); var lat1 = Convert.ToDouble(lat); var lng1 = Convert.ToDouble(lng); var lat2 = Convert.ToDouble(rp.lat); var lng2 = Convert.ToDouble(rp.lng); if (DistanceHelperHere.Distance(lat1, lng1, lat2, lng2) < 5) { r.Add(item); } } return(r.ToArray()); }
/// <summary> /// 计算骑手和目的地的距离 /// </summary> /// <param name="riderId"></param> /// <param name="userAddressId"></param> /// <returns></returns> public decimal GetDistance(int riderId, int userAddressId, string lat, string lng) { var list = CacheHelper.GetByCondition <UserAddressView>("UserAddressView", " id=" + userAddressId); var ua = list.First(); var lat1 = 0d; var lng1 = 0d; var lat2 = 0d; var lng2 = 0d; if (ua.riderType != 2) { RiderPosition rp = CacheHelper.GetRiderPosition(riderId); if (rp == null) { return(0); } lat1 = Convert.ToDouble(rp.lat); lng1 = Convert.ToDouble(rp.lng); lat2 = Convert.ToDouble(ua.lat); lng2 = Convert.ToDouble(ua.lng); } else { lat1 = Convert.ToDouble(ua.lat); lng1 = Convert.ToDouble(ua.lng); lat2 = Convert.ToDouble(lat); lng2 = Convert.ToDouble(lng); } var r = DistanceHelperHere.Distance(lat1, lng1, lat2, lng2); var r2 = r.ToString("#0.0"); return(Convert.ToDecimal(r2)); }