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 Infrastructure; using ARW.Model; using ARW.Repository; using ARW.Repository.Business.Carts; using ARW.Service.Business.IBusinessService.Carts; using ARW.Model.Dto.Business.Carts; using ARW.Model.Models.Business.Carts; using ARW.Model.Vo.Business.Carts; using ARW.Model.Dto.Api.Carts; namespace ARW.Service.Business.BusinessService.Carts { /// /// 购物车记录接口实现类 /// /// @author lwh /// @date 2023-07-20 /// [AppService(ServiceType = typeof(ICartService), ServiceLifetime = LifeTime.Transient)] public class CartServiceImpl : BaseService, ICartService { private readonly CartRepository _CartRepository; public CartServiceImpl(CartRepository CartRepository) { this._CartRepository = CartRepository; } #region 业务逻辑代码 /// /// 查询购物车记录分页列表 /// public async Task> GetCartList(CartQueryDto parm) { //开始拼装查询条件d var predicate = Expressionable.Create(); 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() .Where(predicate.ToExpression()) .OrderBy(s => s.Create_time, OrderByType.Desc) .Select(s => new CartVo { CartId = s.CartId, CartGuid = s.CartGuid, CustomerGuid = s.CustomerGuid, ShopGuid = s.ShopGuid, //GoodsGud = s.GoodsGud, GoodsSkuId = s.GoodsSkuId, CartGoodsNum = s.CartGoodsNum, }); return await query.ToPageAsync(parm); } /// /// 添加或修改购物车记录 /// public async Task AddOrUpdateCart(Cart model) { if (model.CartId != 0) { var response = await _CartRepository.UpdateAsync(model); return "修改成功!"; } else { var cart = await _CartRepository.GetFirstAsync(s => s.CustomerGuid == model.CustomerGuid && s.GoodsGuid == model.GoodsGuid && s.GoodsSkuId == model.GoodsSkuId && s.IsDelete == false); if (cart != null) { cart.CartGoodsNum += model.CartGoodsNum; var response = await _CartRepository.UpdateAsync(cart); } else { var response = await _CartRepository.InsertReturnSnowflakeIdAsync(model); } return "添加成功!"; } } #region Excel处理 #endregion #endregion } }