fixed 修改商品收藏和浏览记录的接口

This commit is contained in:
AERWEN\26795 2023-10-23 19:55:52 +08:00
parent 4a29dfea07
commit ceb1ca4419
5 changed files with 31 additions and 13 deletions

View File

@ -235,6 +235,11 @@ namespace ARW.Model.Vo.Api.GoodsManager.Goodss
/// </summary>
public List<GoosSkuApiVo> SkuList { get; set; }
/// <summary>
/// 是否收藏
/// </summary>
public bool IsCollect { get; set; } = false;
}
}

View File

@ -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
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public async Task<string> GetGoodsDetails(GoodsDtoApi parm)
public async Task<string> 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
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public async Task<string> GetSpecList(string json)
public async Task<string> 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();
}

View File

@ -47,7 +47,7 @@ namespace ARW.Service.Api.IBusinessService.GoodsManager.Goodss
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
Task<string> GetGoodsDetails(GoodsDtoApi parm);
Task<string> GetGoodsDetails(GoodsDtoApi parm,long userId);
}
}

View File

@ -85,13 +85,14 @@ namespace ARW.WebApi.Controllers.Api.Custom.GoodsCollections
/// 删除商品收藏
/// </summary>
/// <returns></returns>
[HttpDelete("{ids}")]
[HttpPost("CancelGoodsCollection")]
[Log(Title = "商品收藏删除", BusinessType = BusinessType.DELETE)]
public IActionResult Delete(string ids)
public async Task<IActionResult> 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("删除成功!");
}

View File

@ -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<IActionResult> 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 != "[]")
{