using Infrastructure; using Infrastructure.Attribute; using Infrastructure.Enums; using Infrastructure.Model; using Mapster; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using ARW.Admin.WebApi.Extensions; using ARW.Admin.WebApi.Filters; using ARW.Common; using ARW.Admin.WebApi.Controllers; using ARW.Model.Dto.Api.Custom.CustomerAddresses; using ARW.Service.Api.IBusinessService.Custom.CustomerAddresses; using ARW.Model.Models.Business.Custom.CustomerAddresses; using ARW.Model.Vo.Api.Custom.CustomerAddresses; using Microsoft.AspNetCore.Authorization; using Geocoding; 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 { /// /// 客户收货地址控制器Api /// /// @author admin /// @date 2023-06-09 /// [Verify] [Route("api/[controller]")] public class CustomerAddressApiController : BaseController { private readonly ICustomerAddressServiceApi _CustomerAddressServiceApi; private readonly IRegionService _RegionService; /// /// 依赖注入 /// /// 客户收货地址客户收货地址Api服务 /// 省市区服务 public CustomerAddressApiController(ICustomerAddressServiceApi CustomerAddressServiceApi, IRegionService regionService) { _CustomerAddressServiceApi = CustomerAddressServiceApi; _RegionService = regionService; } /// /// 获取客户收货地址列表(Api) /// /// 查询参数 /// [HttpGet("getCustomerAddressList")] public async Task GetCustomerAddressListApi([FromQuery] CustomerAddressQueryDtoApi parm) { var user = JwtUtil.GetLoginUser(App.HttpContext); parm.CustomerAddressCustomerGuid = user.UserId; var res = await _CustomerAddressServiceApi.GetCustomerAddressListApi(parm); return SUCCESS(res); } /// /// 获取CustomerAddress详情(Api) /// /// 查询参数 /// [HttpGet("getCustomerAddressDetails")] public async Task GetCustomerAddressDetails([FromQuery] CustomerAddressDtoApi parm) { if (parm == null) throw new CustomException("参数错误!"); var res = await _CustomerAddressServiceApi.GetCustomerAddressDetails(parm); if (res != "[]") { res = res.Remove(0, 1); res = res.Substring(0, res.Length - 1); var data = res.FromJSON(); return SUCCESS(data); } else { return SUCCESS(res); } } /// /// 添加或修改客户收货地址 /// /// /// [HttpPost("addOrUpdateCustomerAddress")] [Log(Title = "添加或修改客户收货地址", BusinessType = BusinessType.ADDORUPDATE)] public async Task AddOrUpdateCustomerAddress([FromBody] CustomerAddressAddDtoApi parm) { if (parm == null) { throw new CustomException("请求参数错误"); } var modal = new CustomerAddress(); if (parm.CustomerAddressId != 0) modal = parm.Adapt().ToUpdate(HttpContext); else modal = parm.Adapt().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); } /// /// 删除客户收货地址 /// /// [HttpDelete("{ids}")] [Log(Title = "客户收货地址删除", BusinessType = BusinessType.DELETE)] public IActionResult Delete(string ids) { long[] idsArr = Tools.SpitLongArrary(ids); if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } var response = _CustomerAddressServiceApi.Delete(idsArr); return SUCCESS("删除成功!"); } } }