106 lines
3.4 KiB
C#
106 lines
3.4 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.Carts;
|
|
using ARW.Service.Api.IBusinessService.Carts;
|
|
using ARW.Model.Dto.Api.Carts;
|
|
using ARW.Model.Models.Business.Carts;
|
|
using ARW.Model.Vo.Api.Carts;
|
|
using ARW.Model.Models.Business.Custom.Customers;
|
|
using ARW.Model.Models.Business.GoodsManager.Goodss;
|
|
using ARW.Model.Models.Business.ShopManager.Shops;
|
|
|
|
namespace ARW.Service.Api.BusinessService.Carts
|
|
{
|
|
/// <summary>
|
|
/// 购物车记录接口实现类Api
|
|
///
|
|
/// @author lwh
|
|
/// @date 2023-07-20
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(ICartServiceApi), ServiceLifetime = LifeTime.Transient)]
|
|
public class CartServiceImplApi : BaseService<Cart>, ICartServiceApi
|
|
{
|
|
private readonly CartRepository _CartRepository;
|
|
|
|
public CartServiceImplApi(CartRepository CartRepository)
|
|
{
|
|
this._CartRepository = CartRepository;
|
|
}
|
|
|
|
#region Api接口代码
|
|
|
|
|
|
/// <summary>
|
|
/// 查询购物车记录列表(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<PagedInfo<CartVoApi>> GetCartListApi(CartQueryDtoApi parm)
|
|
{
|
|
//开始拼装查询条件d
|
|
var predicate = Expressionable.Create<Cart>();
|
|
|
|
predicate = predicate.AndIF(parm.CustomerGuid != null, s => s.CustomerGuid == parm.CustomerGuid);
|
|
predicate = predicate.AndIF(parm.ShopGuid != null, s => s.ShopGuid == parm.ShopGuid);
|
|
var query = _CartRepository
|
|
.Queryable()
|
|
.LeftJoin<Shop>((s, c) => s.ShopGuid == c.ShopGuid)
|
|
.LeftJoin<Goods>((s, c, d) => s.GoodsGuid == d.GoodsGuid)
|
|
.LeftJoin<Customer>((s, c, d, f) => s.CustomerGuid == f.CustomerGuid)
|
|
.Where(predicate.ToExpression())
|
|
.OrderBy(s => s.Create_time, OrderByType.Desc)
|
|
.Select(s => new CartVoApi
|
|
{
|
|
CartId = s.CartId,
|
|
CartGuid = s.CartGuid,
|
|
CustomerGuid = s.CustomerGuid,
|
|
ShopGuid = s.ShopGuid,
|
|
GoodsGuid = s.GoodsGuid,
|
|
GoodsSkuId = s.GoodsSkuId,
|
|
CartGoodsNum = s.CartGoodsNum,
|
|
});
|
|
|
|
|
|
return await query.ToPageAsync(parm);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询购物车记录详情(Api)
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public async Task<string> GetCartDetails(CartDtoApi parm)
|
|
{
|
|
|
|
var query = _CartRepository
|
|
.Queryable()
|
|
.Where(s => s.CartGuid == parm.CartGuid)
|
|
.Select(s => new CartApiDetailsVo
|
|
{
|
|
CartId = s.CartId,
|
|
CartGuid = s.CartGuid,
|
|
CustomerGuid = s.CustomerGuid,
|
|
ShopGuid = s.ShopGuid,
|
|
GoodsGuid = s.GoodsGuid,
|
|
GoodsSkuId = s.GoodsSkuId,
|
|
CartGoodsNum = s.CartGoodsNum,
|
|
}).Take(1);
|
|
|
|
|
|
return await query.ToJsonAsync();
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|