fixed 完善收货地址逻辑
This commit is contained in:
parent
a65cfcded6
commit
bb5b4d0b8a
@ -12,14 +12,14 @@ namespace ARW.Model.Dto.Api.Custom.CustomerAddresses
|
|||||||
/// @author admin
|
/// @author admin
|
||||||
/// @date 2023-06-09
|
/// @date 2023-06-09
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CustomerAddressQueryDtoApi : PagerInfo
|
public class CustomerAddressQueryDtoApi : PagerInfo
|
||||||
{
|
{
|
||||||
public long CustomerAddressCustomerGuid { get; set; }
|
public long CustomerAddressCustomerGuid { get; set; }
|
||||||
public string CustomerAddressName { get; set; }
|
public string CustomerAddressName { get; set; }
|
||||||
public string CustomerAddressPhone { get; set; }
|
public string CustomerAddressPhone { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 客户收货地址详情输入对象Api
|
/// 客户收货地址详情输入对象Api
|
||||||
///
|
///
|
||||||
@ -28,8 +28,42 @@ namespace ARW.Model.Dto.Api.Custom.CustomerAddresses
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class CustomerAddressDtoApi
|
public class CustomerAddressDtoApi
|
||||||
{
|
{
|
||||||
[Required(ErrorMessage = "CustomerAddressGuid不能为空")]
|
[Required(ErrorMessage = "CustomerAddressId不能为空")]
|
||||||
public long CustomerAddressGuid { get; set; }
|
public long CustomerAddressId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class CustomerAddressAddDtoApi
|
||||||
|
{
|
||||||
|
|
||||||
|
public int CustomerAddressId { get; set; }
|
||||||
|
|
||||||
|
public long CustomerAddressGuid { get; set; }
|
||||||
|
|
||||||
|
public long CustomerAddressCustomerGuid { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "省编码不能为空")]
|
||||||
|
public string ProvinceCode { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "市编码不能为空")]
|
||||||
|
public string CityCode { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "区编码不能为空")]
|
||||||
|
public string DistrictCode { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "收货人名称不能为空")]
|
||||||
|
public string CustomerAddressName { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "收货电话不能为空")]
|
||||||
|
public string CustomerAddressPhone { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "详细地址不能为空")]
|
||||||
|
public string CustomerAddressDetailed { get; set; }
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "是否默认地址不能为空")]
|
||||||
|
public int IsDefault { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ namespace ARW.Model.Dto.Api.Custom.Regions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class RegionQueryDtoApi : PagerInfo
|
public class RegionQueryDtoApi : PagerInfo
|
||||||
{
|
{
|
||||||
public string RegionName { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace ARW.Model.Vo.Api.Custom.CustomerAddresses
|
|||||||
/// 描述 : guid
|
/// 描述 : guid
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonConverter(typeof(ValueToStringConverter))]
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
[EpplusIgnore]
|
[EpplusIgnore]
|
||||||
public long CustomerAddressGuid { get; set; }
|
public long CustomerAddressGuid { get; set; }
|
||||||
|
|
||||||
|
|
||||||
@ -52,34 +52,72 @@ namespace ARW.Model.Vo.Api.Custom.CustomerAddresses
|
|||||||
public bool IsDefault { get; set; }
|
public bool IsDefault { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 客户收货地址详情展示对象Api
|
/// 客户收货地址详情展示对象Api
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class CustomerAddressApiDetailsVo
|
public class CustomerAddressApiDetailsVo
|
||||||
{
|
{
|
||||||
[EpplusIgnore]
|
|
||||||
public int CustomerAddressId { get; set; }
|
public int CustomerAddressId { get; set; }
|
||||||
[JsonConverter(typeof(ValueToStringConverter))]
|
|
||||||
[EpplusIgnore]
|
[JsonConverter(typeof(ValueToStringConverter))]
|
||||||
public long CustomerAddressGuid { get; set; }
|
public long CustomerAddressGuid { get; set; }
|
||||||
[JsonConverter(typeof(ValueToStringConverter))]
|
|
||||||
[EpplusTableColumn(Header = "客户guid")]
|
/// <summary>
|
||||||
public long CustomerAddressCustomerGuid { get; set; }
|
/// 省名称
|
||||||
[EpplusTableColumn(Header = "省id")]
|
/// </summary>
|
||||||
public int CustomerAddressProvinceId { get; set; }
|
public string ProvinceName { get; set; }
|
||||||
[EpplusTableColumn(Header = "市id")]
|
|
||||||
public int CustomerAddressCityId { get; set; }
|
/// <summary>
|
||||||
[EpplusTableColumn(Header = "区id")]
|
/// 省编码
|
||||||
public int CustomerAddressAreaId { get; set; }
|
/// </summary>
|
||||||
[EpplusTableColumn(Header = "收货人名称")]
|
public string ProvinceCode { get; set; }
|
||||||
public string CustomerAddressName { get; set; }
|
|
||||||
[EpplusTableColumn(Header = "收货电话")]
|
|
||||||
public string CustomerAddressPhone { get; set; }
|
/// <summary>
|
||||||
[EpplusTableColumn(Header = "详细地址")]
|
/// 市名称
|
||||||
public string CustomerAddressDetailed { get; set; }
|
/// </summary>
|
||||||
|
public string CityName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 市编码
|
||||||
|
/// </summary>
|
||||||
|
public string CityCode { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 区名称
|
||||||
|
/// </summary>
|
||||||
|
public string DistrictName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 区编码
|
||||||
|
/// </summary>
|
||||||
|
public string DistrictCode { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收货人名称
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 收货电话
|
||||||
|
/// </summary>
|
||||||
|
public string Phone { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 详细地址
|
||||||
|
/// </summary>
|
||||||
|
public string DetailAddress { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否为默认地址
|
||||||
|
/// </summary>
|
||||||
|
public bool IsDefault { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ using ARW.Model.Vo.Api.Custom.CustomerAddresses;
|
|||||||
using ARW.Model.Models.Business.Custom.Regions;
|
using ARW.Model.Models.Business.Custom.Regions;
|
||||||
using ARW.Model.Models.Business.Custom.Customers;
|
using ARW.Model.Models.Business.Custom.Customers;
|
||||||
using Microsoft.AspNetCore.Server.IISIntegration;
|
using Microsoft.AspNetCore.Server.IISIntegration;
|
||||||
|
using ARW.Repository.Business.Custom.Customers;
|
||||||
|
|
||||||
namespace ARW.Service.Api.BusinessService.Custom.CustomerAddresses
|
namespace ARW.Service.Api.BusinessService.Custom.CustomerAddresses
|
||||||
{
|
{
|
||||||
@ -29,10 +30,12 @@ namespace ARW.Service.Api.BusinessService.Custom.CustomerAddresses
|
|||||||
public class CustomerAddressServiceImplApi : BaseService<CustomerAddress>, ICustomerAddressServiceApi
|
public class CustomerAddressServiceImplApi : BaseService<CustomerAddress>, ICustomerAddressServiceApi
|
||||||
{
|
{
|
||||||
private readonly CustomerAddressRepository _CustomerAddressRepository;
|
private readonly CustomerAddressRepository _CustomerAddressRepository;
|
||||||
|
private readonly CustomerRepository _CustomerRepository;
|
||||||
|
|
||||||
public CustomerAddressServiceImplApi(CustomerAddressRepository CustomerAddressRepository)
|
public CustomerAddressServiceImplApi(CustomerAddressRepository CustomerAddressRepository, CustomerRepository customerRepository)
|
||||||
{
|
{
|
||||||
this._CustomerAddressRepository = CustomerAddressRepository;
|
this._CustomerAddressRepository = CustomerAddressRepository;
|
||||||
|
_CustomerRepository = customerRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Api接口代码
|
#region Api接口代码
|
||||||
@ -81,22 +84,25 @@ namespace ARW.Service.Api.BusinessService.Custom.CustomerAddresses
|
|||||||
|
|
||||||
var query = _CustomerAddressRepository
|
var query = _CustomerAddressRepository
|
||||||
.Queryable()
|
.Queryable()
|
||||||
.LeftJoin<Region>((s, c) => s.CustomerAddressProvinceId == c.RegionPid)
|
.LeftJoin<Region>((s, c) => s.CustomerAddressProvinceId == c.RegionId)
|
||||||
.LeftJoin<Region>((s, c, d) => s.CustomerAddressCityId == d.RegionPid)
|
.LeftJoin<Region>((s, c, d) => s.CustomerAddressCityId == d.RegionId)
|
||||||
.LeftJoin<Region>((s, c, d, f) => s.CustomerAddressAreaId == f.RegionPid)
|
.LeftJoin<Region>((s, c, d, f) => s.CustomerAddressAreaId == f.RegionId)
|
||||||
.LeftJoin<Customer>((s, c, d, f, g) => s.CustomerAddressCustomerGuid == g.CustomerGuid)
|
.LeftJoin<Customer>((s, c, d, f, g) => s.CustomerAddressCustomerGuid == g.CustomerGuid)
|
||||||
.Where(s => s.CustomerAddressGuid == parm.CustomerAddressGuid)
|
.Where(s => s.CustomerAddressId == parm.CustomerAddressId)
|
||||||
.Select(s => new CustomerAddressApiDetailsVo
|
.Select((s, c, d, f, g) => new CustomerAddressApiDetailsVo
|
||||||
{
|
{
|
||||||
CustomerAddressId = s.CustomerAddressId,
|
CustomerAddressId = s.CustomerAddressId,
|
||||||
CustomerAddressGuid = s.CustomerAddressGuid,
|
CustomerAddressGuid = s.CustomerAddressGuid,
|
||||||
CustomerAddressCustomerGuid = s.CustomerAddressCustomerGuid,
|
ProvinceName = c.RegionName,
|
||||||
CustomerAddressProvinceId = s.CustomerAddressProvinceId,
|
ProvinceCode = c.RegionCode,
|
||||||
CustomerAddressCityId = s.CustomerAddressCityId,
|
CityName = d.RegionName,
|
||||||
CustomerAddressAreaId = s.CustomerAddressAreaId,
|
CityCode = d.RegionCode,
|
||||||
CustomerAddressName = s.CustomerAddressName,
|
DistrictName = f.RegionName,
|
||||||
CustomerAddressPhone = s.CustomerAddressPhone,
|
DistrictCode = f.RegionCode,
|
||||||
CustomerAddressDetailed = s.CustomerAddressDetailed,
|
Name = s.CustomerAddressName,
|
||||||
|
Phone = s.CustomerAddressPhone,
|
||||||
|
DetailAddress = s.CustomerAddressDetailed,
|
||||||
|
IsDefault = s.CustomerAddressGuid == g.CustomerDefaultAddressGuid
|
||||||
}).Take(1);
|
}).Take(1);
|
||||||
|
|
||||||
|
|
||||||
@ -104,6 +110,61 @@ namespace ARW.Service.Api.BusinessService.Custom.CustomerAddresses
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改客户收货地址
|
||||||
|
/// </summary>
|
||||||
|
public async Task<string> AddOrUpdateCustomerAddress(CustomerAddress model, int IsDefault)
|
||||||
|
{
|
||||||
|
if (model.CustomerAddressId != 0)
|
||||||
|
{
|
||||||
|
var response = await _CustomerAddressRepository.UpdateAsync(model);
|
||||||
|
await HandleDefaultAddress(model, IsDefault, model.CustomerAddressGuid);
|
||||||
|
return "修改成功!";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var response = await _CustomerAddressRepository.InsertReturnSnowflakeIdAsync(model);
|
||||||
|
await HandleDefaultAddress(model, IsDefault, response);
|
||||||
|
return "添加成功!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 默认收货地址处理
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="model">CustomerAddress模型</param>
|
||||||
|
/// <param name="IsDefault">是否为默认地址</param>
|
||||||
|
/// <param name="defaultAddressGuid">默认地址Guid</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task HandleDefaultAddress(CustomerAddress model, int IsDefault, long defaultAddressGuid)
|
||||||
|
{
|
||||||
|
// 修改客户的默认地址guid
|
||||||
|
if (IsDefault == 1)
|
||||||
|
{
|
||||||
|
await _CustomerRepository.UpdateAsync(f => new Customer
|
||||||
|
{
|
||||||
|
CustomerDefaultAddressGuid = defaultAddressGuid
|
||||||
|
}, s => s.CustomerGuid == model.CustomerAddressCustomerGuid);
|
||||||
|
}
|
||||||
|
else if (IsDefault == 0)
|
||||||
|
{
|
||||||
|
// 找到当前客户的默认收货地址
|
||||||
|
var customerDefaultAddress = await _CustomerRepository.GetFirstAsync(s => s.CustomerGuid == model.CustomerAddressCustomerGuid);
|
||||||
|
var customerDefaultAddressGuid = customerDefaultAddress.CustomerDefaultAddressGuid;
|
||||||
|
// 当前的收货地址guid如果与客户的默认收货地址相同
|
||||||
|
if (customerDefaultAddressGuid != 0 && model.CustomerAddressGuid == customerDefaultAddressGuid)
|
||||||
|
{
|
||||||
|
// 重新设置为Null值
|
||||||
|
await _CustomerRepository.UpdateAsync(f => new Customer
|
||||||
|
{
|
||||||
|
CustomerDefaultAddressGuid = null
|
||||||
|
}, s => s.CustomerGuid == model.CustomerAddressCustomerGuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,5 +32,13 @@ namespace ARW.Service.Api.IBusinessService.Custom.CustomerAddresses
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<string> GetCustomerAddressDetails(CustomerAddressDtoApi parm);
|
Task<string> GetCustomerAddressDetails(CustomerAddressDtoApi parm);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改客户收货地址
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<string> AddOrUpdateCustomerAddress(CustomerAddress parm, int IsDefault);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ namespace ARW.Service.Business.BusinessService.Custom.Regions
|
|||||||
public async Task<int> GetRegionId(string RegionCode, int level)
|
public async Task<int> GetRegionId(string RegionCode, int level)
|
||||||
{
|
{
|
||||||
var region = await _RegionRepository.GetFirstAsync(s => s.RegionCode == RegionCode && s.RegionLevel == level);
|
var region = await _RegionRepository.GetFirstAsync(s => s.RegionCode == RegionCode && s.RegionLevel == level);
|
||||||
if (region == null) throw new Exception("编码不正确");
|
if (region == null) throw new Exception(RegionCode + "编码不正确");
|
||||||
return region.RegionId;
|
return region.RegionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,10 @@ using ARW.Model.Vo.Api.Custom.CustomerAddresses;
|
|||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Geocoding;
|
using Geocoding;
|
||||||
using ARW.Admin.WebApi.Framework;
|
using ARW.Admin.WebApi.Framework;
|
||||||
|
using ARW.Model.Dto.Business.Custom.CustomerAddresses;
|
||||||
|
using ARW.Service.Business.IBusinessService.Custom.CustomerAddresses;
|
||||||
|
using Microsoft.AspNetCore.Server.IISIntegration;
|
||||||
|
using ARW.Service.Business.IBusinessService.Custom.Regions;
|
||||||
|
|
||||||
namespace ARW.WebApi.Controllers.Api.Custom.CustomerAddresses
|
namespace ARW.WebApi.Controllers.Api.Custom.CustomerAddresses
|
||||||
{
|
{
|
||||||
@ -30,14 +34,17 @@ namespace ARW.WebApi.Controllers.Api.Custom.CustomerAddresses
|
|||||||
public class CustomerAddressApiController : BaseController
|
public class CustomerAddressApiController : BaseController
|
||||||
{
|
{
|
||||||
private readonly ICustomerAddressServiceApi _CustomerAddressServiceApi;
|
private readonly ICustomerAddressServiceApi _CustomerAddressServiceApi;
|
||||||
|
private readonly IRegionService _RegionService;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 依赖注入
|
/// 依赖注入
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="CustomerAddressServiceApi">客户收货地址客户收货地址Api服务</param>
|
/// <param name="CustomerAddressServiceApi">客户收货地址客户收货地址Api服务</param>
|
||||||
public CustomerAddressApiController(ICustomerAddressServiceApi CustomerAddressServiceApi)
|
/// <param name="regionService">省市区服务</param>
|
||||||
|
public CustomerAddressApiController(ICustomerAddressServiceApi CustomerAddressServiceApi, IRegionService regionService)
|
||||||
{
|
{
|
||||||
_CustomerAddressServiceApi = CustomerAddressServiceApi;
|
_CustomerAddressServiceApi = CustomerAddressServiceApi;
|
||||||
|
_RegionService = regionService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,5 +87,34 @@ namespace ARW.WebApi.Controllers.Api.Custom.CustomerAddresses
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加或修改客户收货地址
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parm"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("addOrUpdateCustomerAddress")]
|
||||||
|
[Log(Title = "添加或修改客户收货地址", BusinessType = BusinessType.ADDORUPDATE)]
|
||||||
|
public async Task<IActionResult> AddOrUpdateCustomerAddress([FromBody] CustomerAddressAddDtoApi parm)
|
||||||
|
{
|
||||||
|
if (parm == null) { throw new CustomException("请求参数错误"); }
|
||||||
|
|
||||||
|
var modal = new CustomerAddress();
|
||||||
|
if (parm.CustomerAddressId != 0) modal = parm.Adapt<CustomerAddress>().ToUpdate(HttpContext);
|
||||||
|
else modal = parm.Adapt<CustomerAddress>().ToCreate(HttpContext);
|
||||||
|
|
||||||
|
// 字段转换
|
||||||
|
var user = JwtUtil.GetLoginUser(App.HttpContext);
|
||||||
|
modal.CustomerAddressCustomerGuid = user.UserId;
|
||||||
|
|
||||||
|
modal.CustomerAddressProvinceId = await _RegionService.GetRegionId(parm.ProvinceCode,1);
|
||||||
|
modal.CustomerAddressCityId = await _RegionService.GetRegionId(parm.CityCode,2);
|
||||||
|
modal.CustomerAddressAreaId = await _RegionService.GetRegionId(parm.DistrictCode,3);
|
||||||
|
|
||||||
|
|
||||||
|
var res = await _CustomerAddressServiceApi.AddOrUpdateCustomerAddress(modal,parm.IsDefault);
|
||||||
|
return SUCCESS(res);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user