From ceb1ca4419e1eb69677668dca8e7fbd8ee88b53a Mon Sep 17 00:00:00 2001 From: "AERWEN\\26795" <123456789a> Date: Mon, 23 Oct 2023 19:55:52 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=94=B6=E8=97=8F=E5=92=8C=E6=B5=8F=E8=A7=88=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Vo/Api/GoodsManager/Goodss/GoodsApiVo.cs | 5 +++++ .../GoodsManager/Goodss/GoodsServiceApi.cs | 22 ++++++++++++++----- .../GoodsManager/Goodss/IGoodsServiceApi.cs | 2 +- .../GoodsCollectionApiController.cs | 11 +++++----- .../GoodsManager/Goodss/GoodsApiController.cs | 4 +++- 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ARW.Model/Vo/Api/GoodsManager/Goodss/GoodsApiVo.cs b/ARW.Model/Vo/Api/GoodsManager/Goodss/GoodsApiVo.cs index 6a308e1..75ffa22 100644 --- a/ARW.Model/Vo/Api/GoodsManager/Goodss/GoodsApiVo.cs +++ b/ARW.Model/Vo/Api/GoodsManager/Goodss/GoodsApiVo.cs @@ -235,6 +235,11 @@ namespace ARW.Model.Vo.Api.GoodsManager.Goodss /// public List SkuList { get; set; } + + /// + /// 是否收藏 + /// + public bool IsCollect { get; set; } = false; } } diff --git a/ARW.Service/Api/BusinessService/GoodsManager/Goodss/GoodsServiceApi.cs b/ARW.Service/Api/BusinessService/GoodsManager/Goodss/GoodsServiceApi.cs index 560dfb1..c03c126 100644 --- a/ARW.Service/Api/BusinessService/GoodsManager/Goodss/GoodsServiceApi.cs +++ b/ARW.Service/Api/BusinessService/GoodsManager/Goodss/GoodsServiceApi.cs @@ -29,6 +29,7 @@ using ARW.Repository.Business.LogisticsManage.DeliveryRules; using Infrastructure; using ARW.Model.Models.Business.LogisticsManage.DeliveryRules; using ARW.Model.Vo.Business.GoodsManager.Goodss; +using ARW.Service.Business.IBusinessService.Custom.GoodsCollections; namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss { @@ -50,9 +51,10 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss private readonly DeliveryRepository _DeliveryRepository; private readonly DeliveryRuleRepository _DeliveryRuleRepository; private readonly CustomerAddressRepository _CustomerAddressRepository; + private readonly IGoodsCollectionService _GoodsCollectionService; - public GoodsServiceImplApi(GoodsRepository GoodsRepository, GoodsSpecRelRepository goodsSpecRelRepository, SpecRepository specRepository, SpecValueRepository specValueRepository, GoodsSkuRepository goodsSkuRepository, GoodsCategoryRepository goodsCategoryRepository, DeliveryRepository deliveryRepository, CustomerAddressRepository customerAddressRepository, DeliveryRuleRepository deliveryRuleRepository) + public GoodsServiceImplApi(GoodsRepository GoodsRepository, GoodsSpecRelRepository goodsSpecRelRepository, SpecRepository specRepository, SpecValueRepository specValueRepository, GoodsSkuRepository goodsSkuRepository, GoodsCategoryRepository goodsCategoryRepository, DeliveryRepository deliveryRepository, CustomerAddressRepository customerAddressRepository, DeliveryRuleRepository deliveryRuleRepository, IGoodsCollectionService goodsCollectionService) { this._GoodsRepository = GoodsRepository; _GoodsSpecRelRepository = goodsSpecRelRepository; @@ -63,6 +65,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss _DeliveryRepository = deliveryRepository; _CustomerAddressRepository = customerAddressRepository; _DeliveryRuleRepository = deliveryRuleRepository; + _GoodsCollectionService = goodsCollectionService; } #region Api接口代码 @@ -136,7 +139,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss foreach (var item in list.Result) { - item.Thumb = item.Images.Split(",").First(); + item.Thumb = item.Images.Split(",").First(); } return list; @@ -207,7 +210,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss var adress = await _CustomerAddressRepository.GetFirstAsync(s => s.CustomerAddressGuid == parm.CustomerAddressGuid); // 判断是否在配送范围 - + var regionIdList = Tools.SpitIntArrary(deliveRule.DeliveryRuleRegion).ToList(); if (regionIdList.Contains(adress.CustomerAddressCityId)) { @@ -254,7 +257,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss /// /// /// - public async Task GetGoodsDetails(GoodsDtoApi parm) + public async Task GetGoodsDetails(GoodsDtoApi parm, long userId) { var query = _GoodsRepository @@ -287,7 +290,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss var json = await query.ToJsonAsync(); - var data = await GetSpecList(json); + var data = await GetSpecList(json, userId); return data; } @@ -297,7 +300,7 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss /// /// /// - public async Task GetSpecList(string json) + public async Task GetSpecList(string json, long userId) { if (json != "[]") { @@ -339,6 +342,13 @@ namespace ARW.Service.Api.BusinessService.GoodsManager.Goodss data.SkuList = await GetSkuListWithSpecValuesAsync(skuList); data.SpecList = goodsSpecListVo; + + if (userId != 0) + { + var isCollect = await _GoodsCollectionService.IsAnyAsync(s => s.CustomerGuid == userId && s.GoodsGuid == data.SpuId); + data.IsCollect = isCollect; + } + json = data.ToJson(); } diff --git a/ARW.Service/Api/IBusinessService/GoodsManager/Goodss/IGoodsServiceApi.cs b/ARW.Service/Api/IBusinessService/GoodsManager/Goodss/IGoodsServiceApi.cs index 5b4ede9..ff84407 100644 --- a/ARW.Service/Api/IBusinessService/GoodsManager/Goodss/IGoodsServiceApi.cs +++ b/ARW.Service/Api/IBusinessService/GoodsManager/Goodss/IGoodsServiceApi.cs @@ -47,7 +47,7 @@ namespace ARW.Service.Api.IBusinessService.GoodsManager.Goodss /// /// /// - Task GetGoodsDetails(GoodsDtoApi parm); + Task GetGoodsDetails(GoodsDtoApi parm,long userId); } } diff --git a/ARW.WebApi/Controllers/Api/Custom/GoodsCollections/GoodsCollectionApiController.cs b/ARW.WebApi/Controllers/Api/Custom/GoodsCollections/GoodsCollectionApiController.cs index 75840df..ea9550d 100644 --- a/ARW.WebApi/Controllers/Api/Custom/GoodsCollections/GoodsCollectionApiController.cs +++ b/ARW.WebApi/Controllers/Api/Custom/GoodsCollections/GoodsCollectionApiController.cs @@ -85,13 +85,14 @@ namespace ARW.WebApi.Controllers.Api.Custom.GoodsCollections /// 删除商品收藏 /// /// - [HttpDelete("{ids}")] + [HttpPost("CancelGoodsCollection")] [Log(Title = "商品收藏删除", BusinessType = BusinessType.DELETE)] - public IActionResult Delete(string ids) + public async Task CancelGoodsCollection([FromBody] GoodsCollectionDto parm) { - long[] idsArr = Tools.SpitLongArrary(ids); - if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } - var response = _GoodsCollectionServiceApi.Delete(idsArr); + var user = JwtUtil.GetLoginUser(App.HttpContext); + //long[] idsArr = Tools.SpitLongArrary(ids); + //if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); } + var response = await _GoodsCollectionServiceApi.DeleteAsync(s => s.GoodsGuid == parm.GoodsGuid && s.CustomerGuid == user.UserId); return SUCCESS("删除成功!"); } diff --git a/ARW.WebApi/Controllers/Api/GoodsManager/Goodss/GoodsApiController.cs b/ARW.WebApi/Controllers/Api/GoodsManager/Goodss/GoodsApiController.cs index a69d42a..2dc5890 100644 --- a/ARW.WebApi/Controllers/Api/GoodsManager/Goodss/GoodsApiController.cs +++ b/ARW.WebApi/Controllers/Api/GoodsManager/Goodss/GoodsApiController.cs @@ -16,6 +16,7 @@ using ARW.Model.Vo.Api.GoodsManager.Goodss; using Microsoft.AspNetCore.Authorization; using Geocoding; using ARW.Service.Api.IBusinessService.GoodsManager.GoodsCategorys; +using ARW.Admin.WebApi.Framework; namespace ARW.WebApi.Controllers.Api.GoodsManager.Goodss { @@ -76,8 +77,9 @@ namespace ARW.WebApi.Controllers.Api.GoodsManager.Goodss public async Task GetGoodsDetails([FromQuery] GoodsDtoApi parm) { //if (parm == null) throw new CustomException("参数错误!"); + var user = JwtUtil.GetLoginUser(App.HttpContext); - var res = await _GoodsServiceApi.GetGoodsDetails(parm); + var res = await _GoodsServiceApi.GetGoodsDetails(parm, user.UserId); if (res != "[]") {