105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using Infrastructure.Attribute;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ARW.Model;
|
|
using ARW.Repository;
|
|
using ARW.Repository.Business.Custom.GoodsCollections;
|
|
using ARW.Service.Api.IBusinessService.Custom.GoodsCollections;
|
|
using ARW.Model.Dto.Api.Custom.GoodsCollections;
|
|
using ARW.Model.Models.Business.Custom.GoodsCollections;
|
|
using ARW.Model.Vo.Api.Custom.GoodsCollections;
|
|
using ARW.Model.Models.Business.GoodsManager.Goodss;
|
|
using Org.BouncyCastle.Crypto.Prng;
|
|
using Infrastructure;
|
|
|
|
namespace ARW.Service.Api.BusinessService.Custom.GoodsCollections
|
|
{
|
|
/// <summary>
|
|
/// 商品收藏接口实现类Api
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-10-22
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IGoodsCollectionServiceApi), ServiceLifetime = LifeTime.Transient)]
|
|
public class GoodsCollectionServiceImplApi : BaseService<GoodsCollection>, IGoodsCollectionServiceApi
|
|
{
|
|
private readonly GoodsCollectionRepository _GoodsCollectionRepository;
|
|
|
|
public GoodsCollectionServiceImplApi(GoodsCollectionRepository GoodsCollectionRepository)
|
|
{
|
|
this._GoodsCollectionRepository = GoodsCollectionRepository;
|
|
}
|
|
|
|
#region Api接口代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询商品收藏列表(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<PagedInfo<GoodsCollectionVoApi>> GetGoodsCollectionListApi(GoodsCollectionQueryDtoApi parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<GoodsCollection>();
|
|
predicate = predicate.AndIF(parm.CustomerGuid != 0, s => s.CustomerGuid == parm.CustomerGuid);
|
|
|
|
var query = _GoodsCollectionRepository
|
|
.Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.LeftJoin<Goods>((s, c) => s.GoodsGuid == c.GoodsGuid)
|
|
.OrderBy(s => s.Create_time, OrderByType.Desc)
|
|
.Select((s, c) => new GoodsCollectionVoApi
|
|
{
|
|
SpuId = s.GoodsGuid,
|
|
Title = c.GoodsName,
|
|
Thumb = c.GoodsPicture,
|
|
Price = c.GoodsPriceLowest,
|
|
OriginPrice = c.GoodsDashedPriceLowest,
|
|
SpuStockQuantity = c.GoodsTotalInventory,
|
|
IsPutOnSale = c.GoodsShelfStatus
|
|
});
|
|
|
|
|
|
var list = await query.ToPageAsync(parm);
|
|
|
|
foreach (var item in list.Result)
|
|
{
|
|
item.Thumb = item.Thumb.Split(",").First();
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加或修改商品收藏
|
|
/// </summary>
|
|
public async Task<string> AddOrUpdateGoodsCollection(GoodsCollection model)
|
|
{
|
|
if (model.GoodsCollectionId != 0)
|
|
{
|
|
var response = await _GoodsCollectionRepository.UpdateAsync(model);
|
|
return "修改成功!";
|
|
}
|
|
else
|
|
{
|
|
var isRepeat = await _GoodsCollectionRepository.GetFirstAsync(s => s.CustomerGuid == model.CustomerGuid && s.GoodsGuid == model.GoodsGuid);
|
|
if (isRepeat != null) throw new CustomException("商品已收藏,请勿重复收藏!");
|
|
var response = await _GoodsCollectionRepository.InsertReturnSnowflakeIdAsync(model);
|
|
return "添加成功!";
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|