131 lines
4.7 KiB
C#
131 lines
4.7 KiB
C#
|
||
using Assets.Scenes.Ride.Scripts.Model;
|
||
using Assets.Scripts.Apis.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace Assets.Scripts.Apis
|
||
{
|
||
public class MapApi :ApiBase
|
||
{
|
||
public string GetMapToken(string name)
|
||
{
|
||
return Get($"Map/GetMapToken?name={name}");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取路线数据
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <returns></returns>
|
||
public MapDataModel GetData(int id)
|
||
{
|
||
return Newtonsoft.Json.JsonConvert.DeserializeObject<MapDataModel>(Get("Map/GetData?routeId="+id));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从服务端获取记录信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public List<MapRecordRanking> GetRecordFileFromServer(List<string> id)
|
||
{
|
||
return Post<JsonResult<List<MapRecordRanking>>>("Map/GetCyclingRecordsById", id).data;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过Id获取路书
|
||
/// </summary>
|
||
/// <param name="id"></param>
|
||
/// <returns></returns>
|
||
public JsonResult<MapRoute> GetById(int id)
|
||
{
|
||
return Get<JsonResult<MapRoute>>($"Map/GetMapRouteById?id={id}");
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="pageIndex"></param>
|
||
/// <param name="pageSize"></param>
|
||
/// <param name="name">名称,地址,编号</param>
|
||
/// <param name="distance">距离,格式0-10</param>
|
||
/// <param name="is3D"></param>
|
||
/// <param name="sort">hot, distance</param>
|
||
/// <param name="sortDire">asc</param>
|
||
/// <returns></returns>
|
||
public JsonResult<List<MapRoute>> GetList(int pageIndex, int pageSize, string name, string distance="", string hands="", bool is3D=false, string sort="", string sortDire = "", bool isFav = false)
|
||
{
|
||
var url = $"Map/GetRoute?pageIndex={ pageIndex }&pageSize={ pageSize }&name={ name }&distance={ distance }&hands={ hands }&is3D={ is3D }&sort={ sort }&sortDire={ sortDire }&isFav={isFav}";
|
||
|
||
return Get<JsonResult<List<MapRoute>>>(url);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从服务端获取Key
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public Dictionary<string, string> GetServiceKeyFromServer()
|
||
{
|
||
return Get<JsonResult<Dictionary<string, string>>>($"Map/GetServiceKey").data;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取在线用户的数据
|
||
/// </summary>
|
||
/// <param name="ids"></param>
|
||
/// <returns></returns>
|
||
public JsonResult<List<OnlineUser>> GetOnlineUserInfo(IEnumerable<int> ids)
|
||
{
|
||
//var result = PostAsync<JsonResult<List<OnlineUser>>>("Map/GetUserInfoByIds", ids).ConfigureAwait(false).GetAwaiter().GetResult();
|
||
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonResult<List<OnlineUser>>>(Post("Map/GetUserInfoByIds", ids));
|
||
if (result.result)
|
||
{
|
||
return result;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
|
||
public async Task<JsonResult<List<NearRouteModel>>> GetNearRouteAsync(float lat, float lng, float zoom, string bounds)
|
||
{
|
||
var res = await GetAsync<JsonResult<List<NearRouteModel>>>($"/Map/GetNearRoute?lat={ lat }&lng={ lng }&zoom={zoom}&bounds={ bounds }");
|
||
|
||
//var result = System.Text.Encoding.UTF8.GetString(res);
|
||
return res;
|
||
}
|
||
|
||
public async Task<string> GetDetailsAsync(int[] ids)
|
||
{
|
||
var res = await GetAsync("/Map/GetDetails?ids=" + string.Join(",", ids));
|
||
|
||
return Encoding.UTF8.GetString(res);
|
||
}
|
||
/// <summary>
|
||
/// 添加收藏
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task<JsonResult<object>> AddFav(string routeId)
|
||
{
|
||
return await PostAsync<JsonResult<object>>("/MemberFavoriteMap/Add",new { routeId });
|
||
}
|
||
/// <summary>
|
||
/// 取消收藏
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public async Task<JsonResult<object>> CancelFav(string routeId)
|
||
{
|
||
return await PostAsync<JsonResult<object>>("/MemberFavoriteMap/Cancel", new { routeId });
|
||
}
|
||
|
||
public JsonResult<MapRouteRankingList> GetRouteRanking(int id,string type, int pageIndex,int pageSize,string name)
|
||
{
|
||
var url = $"Map/v1/GetRouteRanking?pageIndex={ 0 }&pageSize={ pageSize }&name={ name }&id={ id }&type={ type }&filterSelf={ true }";
|
||
|
||
return Get<JsonResult<MapRouteRankingList>>(url);
|
||
}
|
||
}
|
||
}
|