/*********************************************************************** * 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.Loging; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Model.ViewModels.UI; using SqlSugar; namespace CoreCms.Net.Repository { /// /// 商品收藏表 接口实现 /// public class CoreCmsGoodsCollectionRepository : BaseRepository, ICoreCmsGoodsCollectionRepository { public CoreCmsGoodsCollectionRepository(IUnitOfWork unitOfWork) : base(unitOfWork) { } /// /// 根据用户序列获取用户的足迹数量 /// /// /// public async Task GetUserCountAsync(int userId) { var count = await DbClient.Queryable((gc, goods) => new JoinQueryInfos(JoinType.Left, gc.goodsId == goods.id)) .Where((gc, goods) => goods.isDel == false && goods.isMarketable == true && gc.userId == userId).With(SqlWith.NoLock).CountAsync(); return count; } #region 重写根据条件查询分页数据 /// /// 重写根据条件查询分页数据 /// /// 判断集合 /// 排序方式 /// 当前页面索引 /// 分布大小 /// /// public async Task> QueryPageAsync(Expression> predicate, Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, int pageSize = 20) { RefAsync totalCount = 0; var page = await DbClient.Queryable((gc, goods) => new JoinQueryInfos(JoinType.Left, gc.goodsId == goods.id)) .Where((gc, goods) => goods.isDel == false && goods.isMarketable == true) .Select((gc, goods) => new CoreCmsGoodsCollection { id = gc.id, userId = gc.userId, goodsId = gc.goodsId, createTime = gc.createTime, goodsName = gc.goodsName }) .With(SqlWith.NoLock) .MergeTable() .OrderByIF(orderByExpression != null, orderByExpression, orderByType) .WhereIF(predicate != null, predicate) .Mapper(p => p.goods, p => p.goodsId) .ToPageListAsync(pageIndex, pageSize, totalCount); var list = new PageList(page, pageIndex, pageSize, totalCount); return list; } #endregion #region 收藏 /// /// 收藏 /// /// /// /// public async Task ToAdd(int userId, int goodsId) { var jm = new WebApiCallBack(); var goodsModel = await DbClient.Queryable().Where(p => p.id == goodsId).FirstAsync(); if (goodsModel == null) { jm.msg = "没有此商品"; return jm; } var model = new CoreCmsGoodsCollection(); model.userId = userId; model.goodsId = goodsId; model.createTime = DateTime.Now; model.goodsName = goodsModel.name; await DbClient.Insertable(model).ExecuteCommandAsync(); jm.status = true; jm.msg = "收藏成功"; return jm; } #endregion } }