mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 17:33:27 +08:00
【优化】优化用户地址内地图三级联动获取接口返回,因可能存在县区名称重复问题,改为三级匹配。
This commit is contained in:
@@ -71,12 +71,12 @@ namespace CoreCms.Net.Model.ViewModels.DTO
|
||||
public class GetAreaIdPost
|
||||
{
|
||||
/// <summary>
|
||||
/// 县
|
||||
/// 市/区
|
||||
/// </summary>
|
||||
public string cityName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 市/区
|
||||
/// 县
|
||||
/// </summary>
|
||||
public string countyName { get; set; }
|
||||
|
||||
|
||||
@@ -162,7 +162,9 @@
|
||||
this.form.address = location.address;
|
||||
|
||||
let postData = {
|
||||
id: location.district
|
||||
countyName: location.district,
|
||||
cityName: location.city,
|
||||
provinceName: location.province,
|
||||
}
|
||||
this.$u.api.getAreaIdByName(postData).then(res => {
|
||||
if (res.status) {
|
||||
@@ -176,8 +178,6 @@
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
console.log("location1:", location);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -561,19 +561,49 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 根据区/县名称获取城市id信息
|
||||
#region 根据三级联动名称获取城市id信息
|
||||
/// <summary>
|
||||
/// 根据区/县名称获取城市id信息
|
||||
/// 根据三级联动名称获取城市id信息
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<WebApiCallBack> GetAreaIdByName([FromBody] FMStringId entity)
|
||||
public async Task<WebApiCallBack> GetAreaIdByName([FromBody] GetAreaIdPost entity)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
var dataArea = await _areaServices.QueryByClauseAsync(p => p.name == entity.id && p.depth == 3);
|
||||
if (dataArea == null) return jm;
|
||||
if (string.IsNullOrEmpty(entity.cityName))
|
||||
{
|
||||
jm.msg = "市数据未传送。";
|
||||
return jm;
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.provinceName))
|
||||
{
|
||||
jm.msg = "省份数据未传送。";
|
||||
return jm;
|
||||
}
|
||||
if (string.IsNullOrEmpty(entity.countyName))
|
||||
{
|
||||
jm.msg = "县数据未传送。";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var cache = await _areaServices.GetCaChe();
|
||||
var provinceObj = cache.Find(p => p.name == entity.provinceName && p.depth == 1);
|
||||
if (provinceObj == null)
|
||||
{
|
||||
jm.msg = "省份获取失败。";
|
||||
return jm;
|
||||
}
|
||||
var cityObj = cache.Find(p => p.depth == 2 && p.parentId == provinceObj.id && p.name == entity.cityName);
|
||||
|
||||
//可能存在库里面的二级城市和腾讯地图的二级城市不匹配(不得已的办法,最好是同步到腾讯地图的所有三级联动数据)
|
||||
var dataArea = cityObj != null ? cache.Find(p => p.name == entity.countyName && p.depth == 3 && p.parentId == cityObj.id) : cache.Find(p => p.name == entity.countyName && p.depth == 3);
|
||||
if (dataArea == null)
|
||||
{
|
||||
return jm;
|
||||
}
|
||||
|
||||
var fullName = await _areaServices.GetAreaFullName(dataArea.id);
|
||||
jm.status = true;
|
||||
jm.data = new
|
||||
|
||||
Reference in New Issue
Block a user