/*********************************************************************** * Project: baifenBinfa * ProjectName: 百分兵法管理系统 * Web: http://chuanyin.com * Author: * Email: * CreateTime: 202403/02 * Description: 暂无 ***********************************************************************/ using System; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using CoreCms.Net.Configuration; using CoreCms.Net.IRepository; using CoreCms.Net.IRepository.UnitOfWork; using CoreCms.Net.IServices; using CoreCms.Net.Loging; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities.Expression; using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.UI; using SqlSugar; using StackExchange.Redis; namespace CoreCms.Net.Services { /// /// 商品收藏表 接口实现 /// public class CoreCmsGoodsCollectionServices : BaseServices, ICoreCmsGoodsCollectionServices { private readonly ICoreCmsGoodsCollectionRepository _dal; private readonly IUnitOfWork _unitOfWork; public CoreCmsGoodsCollectionServices(IUnitOfWork unitOfWork, ICoreCmsGoodsCollectionRepository dal) { this._dal = dal; base.BaseDal = dal; _unitOfWork = unitOfWork; } /// /// 根据用户序列获取用户的收藏 /// /// /// public async Task GetUserCountAsync(int userId) { return await _dal.GetUserCountAsync(userId); } /// /// 检查是否收藏了此商品 /// /// /// /// public async Task Check(int userId, int goodsId) { var bl =await _dal.ExistsAsync(p => p.userId == userId && p.goodsId == goodsId); return bl; } /// /// 重写根据条件查询分页数据 /// /// 判断集合 /// 排序方式 /// 当前页面索引 /// 分布大小 /// /// public async Task> QueryPageAsync(Expression> predicate, Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, int pageSize = 20) { return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize); } /// /// 如果收藏了,就取消收藏,如果没有收藏,就收藏 /// public async Task ToDo(int userId, int goodsId) { var collectionInfo = await _dal.ExistsAsync(p => p.userId == userId && p.goodsId == goodsId); if (collectionInfo) { return await ToDel(userId, goodsId); } else { return await ToAdd(userId, goodsId); } } /// /// 取消收藏 /// /// /// /// private async Task ToDel(int userId, int goodsId) { var jm = new WebApiCallBack() { status = true, msg = "取消收藏成功" }; await _dal.DeleteAsync(p => p.userId == userId && p.goodsId == goodsId); return jm; } /// /// 收藏 /// /// /// /// public async Task ToAdd(int userId, int goodsId) { return await _dal.ToAdd(userId, goodsId); } } }