添加项目文件。

This commit is contained in:
JianWeie
2021-12-20 21:27:32 +08:00
parent 747486f5cb
commit 82d825b7a5
3514 changed files with 887941 additions and 0 deletions

View File

@@ -0,0 +1,316 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Manual;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.ViewModels.UI;
using NLog;
using SqlSugar;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 代理商品池 接口实现
/// </summary>
public class CoreCmsAgentGoodsRepository : BaseRepository<CoreCmsAgentGoods>, ICoreCmsAgentGoodsRepository
{
private readonly IUnitOfWork _unitOfWork;
public CoreCmsAgentGoodsRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
_unitOfWork = unitOfWork;
}
#region ==========================================================
/// <summary>
/// 重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <param name="products"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> InsertAsync(CoreCmsAgentGoods entity, List<CoreCmsAgentProducts> products)
{
var jm = new AdminUiCallBack();
try
{
var isHave = await DbClient.Queryable<CoreCmsAgentGoods>().AnyAsync(p => p.goodId == entity.goodId);
if (isHave)
{
jm.msg = "此商品已录入代理池";
return jm;
}
var good = await DbClient.Queryable<CoreCmsGoods>().FirstAsync(p => p.id == entity.goodId);
if (good == null)
{
jm.msg = "商品不存在";
return jm;
}
_unitOfWork.BeginTran();
entity.createTime = DateTime.Now;
entity.goodRefreshTime = good.updateTime;
var id = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync();
if (id <= 0)
{
_unitOfWork.RollbackTran();
jm.msg = GlobalConstVars.DataHandleEx;
return jm;
}
products.ForEach(p =>
{
p.agentGoodsId = id;
p.createTime = DateTime.Now;
p.isDel = false;
p.goodId = entity.goodId;
});
var bl = await DbClient.Insertable(products).ExecuteCommandAsync() > 0;
_unitOfWork.CommitTran();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
}
catch (Exception e)
{
_unitOfWork.RollbackTran();
jm.msg = GlobalConstVars.DataHandleEx;
jm.data = e;
}
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <param name="products"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> UpdateAsync(CoreCmsAgentGoods entity, List<CoreCmsAgentProducts> products)
{
var jm = new AdminUiCallBack();
try
{
var isHave = await DbClient.Queryable<CoreCmsAgentGoods>().AnyAsync(p => p.goodId == entity.goodId && p.id != entity.id);
if (isHave)
{
jm.msg = "此商品已录入代理池";
return jm;
}
var good = await DbClient.Queryable<CoreCmsGoods>().FirstAsync(p => p.id == entity.goodId);
if (good == null)
{
jm.msg = "商品不存在";
return jm;
}
var oldModel = await DbClient.Queryable<CoreCmsAgentGoods>().FirstAsync(p => p.id == entity.id);
if (oldModel == null)
{
jm.msg = "编辑数据不存在";
return jm;
}
_unitOfWork.BeginTran();
oldModel.updateTime = DateTime.Now;
oldModel.goodId = entity.goodId;
oldModel.sortId = entity.sortId;
oldModel.isEnable = entity.isEnable;
oldModel.goodRefreshTime = good.updateTime;
products.ForEach(p =>
{
p.agentGoodsId = oldModel.id;
p.createTime = DateTime.Now;
p.isDel = false;
p.goodId = entity.goodId;
});
//数据处理
await DbClient.Updateable(oldModel).ExecuteCommandAsync();
await DbClient.Deleteable<CoreCmsAgentProducts>(p => p.agentGoodsId == oldModel.id).ExecuteCommandHasChangeAsync();
await DbClient.Insertable(products).ExecuteCommandAsync();
_unitOfWork.CommitTran();
jm.code = 0;
jm.msg = GlobalConstVars.EditSuccess;
}
catch (Exception e)
{
_unitOfWork.RollbackTran();
jm.msg = GlobalConstVars.DataHandleEx;
jm.data = e;
}
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsAgentGoods> entity)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Updateable(entity).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
return jm;
}
/// <summary>
/// 重写删除指定ID的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> DeleteByIdAsync(int id)
{
var jm = new AdminUiCallBack();
try
{
var model = await DbClient.Queryable<CoreCmsAgentGoods>().FirstAsync(p => p.id == id);
if (model == null)
{
jm.msg = GlobalConstVars.DataisNo;
return jm;
}
_unitOfWork.BeginTran();
var bl = await DbClient.Deleteable<CoreCmsAgentGoods>(id).ExecuteCommandHasChangeAsync();
if (bl)
{
await DbClient.Deleteable<CoreCmsAgentProducts>(p => p.agentGoodsId == model.id).ExecuteCommandHasChangeAsync();
}
_unitOfWork.CommitTran();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
}
catch (Exception e)
{
_unitOfWork.RollbackTran();
NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "删除代理池商品", "删除报错 ", e);
}
return jm;
}
/// <summary>
/// 重写删除指定ID集合的数据(批量删除)
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable<CoreCmsAgentGoods>().In(ids).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
#endregion
#region
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="orderByExpression"></param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public new async Task<IPageList<CoreCmsAgentGoods>> QueryPageAsync(Expression<Func<CoreCmsAgentGoods, bool>> predicate,
Expression<Func<CoreCmsAgentGoods, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsAgentGoods> page;
if (blUseNoLock)
{
page = await DbClient.Queryable<CoreCmsAgentGoods, CoreCmsGoods>((ag, cg) => new JoinQueryInfos(JoinType.Left, ag.goodId == cg.id))
.Select((ag, cg) => new CoreCmsAgentGoods
{
id = ag.id,
goodId = ag.goodId,
goodRefreshTime = ag.goodRefreshTime,
sortId = ag.sortId,
isEnable = ag.isEnable,
createTime = ag.createTime,
updateTime = ag.updateTime,
goodName = cg.name,
goodImage = cg.image,
goodUpdateTime = cg.updateTime
})
.With(SqlWith.NoLock)
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate)
.ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable<CoreCmsAgentGoods, CoreCmsGoods>((ag, cg) => new JoinQueryInfos(JoinType.Left, ag.goodId == cg.id))
.Select((ag, cg) => new CoreCmsAgentGoods
{
id = ag.id,
goodId = ag.goodId,
goodRefreshTime = ag.goodRefreshTime,
sortId = ag.sortId,
isEnable = ag.isEnable,
createTime = ag.createTime,
updateTime = ag.updateTime,
goodName = cg.name,
goodImage = cg.image,
goodUpdateTime = cg.updateTime
})
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate)
.ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList<CoreCmsAgentGoods>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}

View File

@@ -0,0 +1,261 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Manual;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 代理商等级设置表 接口实现
/// </summary>
public class CoreCmsAgentGradeRepository : BaseRepository<CoreCmsAgentGrade>, ICoreCmsAgentGradeRepository
{
public CoreCmsAgentGradeRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
#region ==========================================================
/// <summary>
/// 重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsAgentGrade entity)
{
var jm = new AdminUiCallBack();
if (await DbClient.Queryable<CoreCmsAgentGrade>().AnyAsync(p => p.sortId == entity.sortId))
{
jm.msg = "存在相同等级排序,请更换!";
return jm;
}
var id = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync();
var bl = id > 0;
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
if (bl)
{
if (entity.isDefault == true)
{
await DbClient.Updateable<CoreCmsAgentGrade>().SetColumns(p => p.isDefault == false).Where(p => p.isDefault == true && p.id != id).ExecuteCommandAsync();
}
await UpdateCaChe();
}
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsAgentGrade entity)
{
var jm = new AdminUiCallBack();
if (await DbClient.Queryable<CoreCmsAgentGrade>().AnyAsync(p => p.sortId == entity.sortId && entity.id != p.id))
{
jm.msg = "存在相同等级排序,请更换!";
return jm;
}
if (entity.isDefault == false)
{
var otherHave = await DbClient.Queryable<CoreCmsAgentGrade>().AnyAsync(p => p.isDefault == true && p.id != entity.id);
if (otherHave == false)
{
jm.msg = "请保持一个默认分销等级";
return jm;
}
}
var oldModel = await DbClient.Queryable<CoreCmsAgentGrade>().In(entity.id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
//事物处理过程开始
//oldModel.id = entity.id;
oldModel.name = entity.name;
oldModel.isDefault = entity.isDefault;
oldModel.isAutoUpGrade = entity.isAutoUpGrade;
oldModel.defaultSalesPriceType = entity.defaultSalesPriceType;
oldModel.defaultSalesPriceNumber = entity.defaultSalesPriceNumber;
oldModel.sortId = entity.sortId;
oldModel.description = entity.description;
//事物处理过程结束
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
if (bl)
{
//其他处理
if (entity.isDefault)
{
await DbClient.Updateable<CoreCmsAgentGrade>().SetColumns(it => it.isDefault == false).Where(p => p.isDefault == true && p.id != entity.id).ExecuteCommandAsync();
}
await UpdateCaChe();
}
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsAgentGrade> entity)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Updateable(entity).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
if (bl)
{
await UpdateCaChe();
}
return jm;
}
/// <summary>
/// 重写删除指定ID的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> DeleteByIdAsync(int id)
{
var jm = new AdminUiCallBack();
if (await DbClient.Queryable<CoreCmsAgent>().AnyAsync(p => p.gradeId == id))
{
jm.msg = "存在关联的分销用户数据,禁止删除";
return jm;
}
var bl = await DbClient.Deleteable<CoreCmsAgentGrade>(id).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
if (bl)
{
await DbClient.Deleteable<CoreCmsAgentProducts>().Where(p => p.agentGradeId == id).ExecuteCommandHasChangeAsync();
await UpdateCaChe();
}
return jm;
}
#endregion
#region ==========================================================
/// <summary>
/// 获取缓存的所有数据
/// </summary>
/// <returns></returns>
public async Task<List<CoreCmsAgentGrade>> GetCaChe()
{
var cache = ManualDataCache.Instance.Get<List<CoreCmsAgentGrade>>(GlobalConstVars.CacheCoreCmsAgentGrade);
if (cache != null)
{
return cache;
}
return await UpdateCaChe();
}
/// <summary>
/// 更新cache
/// </summary>
public async Task<List<CoreCmsAgentGrade>> UpdateCaChe()
{
var list = await DbClient.Queryable<CoreCmsAgentGrade>().With(SqlWith.NoLock).ToListAsync();
ManualDataCache.Instance.Set(GlobalConstVars.CacheCoreCmsAgentGrade, list);
return list;
}
#endregion
#region
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="orderByExpression"></param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public new async Task<IPageList<CoreCmsAgentGrade>> QueryPageAsync(Expression<Func<CoreCmsAgentGrade, bool>> predicate,
Expression<Func<CoreCmsAgentGrade, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsAgentGrade> page;
if (blUseNoLock)
{
page = await DbClient.Queryable<CoreCmsAgentGrade>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsAgentGrade
{
id = p.id,
name = p.name,
isDefault = p.isDefault,
isAutoUpGrade = p.isAutoUpGrade,
defaultSalesPriceType = p.defaultSalesPriceType,
defaultSalesPriceNumber = p.defaultSalesPriceNumber,
sortId = p.sortId,
description = p.description,
}).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable<CoreCmsAgentGrade>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsAgentGrade
{
id = p.id,
name = p.name,
isDefault = p.isDefault,
isAutoUpGrade = p.isAutoUpGrade,
defaultSalesPriceType = p.defaultSalesPriceType,
defaultSalesPriceNumber = p.defaultSalesPriceNumber,
sortId = p.sortId,
description = p.description,
}).ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList<CoreCmsAgentGrade>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}

View File

@@ -0,0 +1,216 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Manual;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 代理商订单记录表 接口实现
/// </summary>
public class CoreCmsAgentOrderRepository : BaseRepository<CoreCmsAgentOrder>, ICoreCmsAgentOrderRepository
{
public CoreCmsAgentOrderRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
#region ==========================================================
/// <summary>
/// 重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsAgentOrder entity)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync() > 0;
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsAgentOrder entity)
{
var jm = new AdminUiCallBack();
var oldModel = await DbClient.Queryable<CoreCmsAgentOrder>().In(entity.id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
//事物处理过程开始
oldModel.id = entity.id;
oldModel.userId = entity.userId;
oldModel.buyUserId = entity.buyUserId;
oldModel.orderId = entity.orderId;
oldModel.amount = entity.amount;
oldModel.isSettlement = entity.isSettlement;
oldModel.createTime = entity.createTime;
oldModel.updateTime = entity.updateTime;
oldModel.isDelete = entity.isDelete;
//事物处理过程结束
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsAgentOrder> entity)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Updateable(entity).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
return jm;
}
/// <summary>
/// 重写删除指定ID的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> DeleteByIdAsync(object id)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable<CoreCmsAgentOrder>(id).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
/// <summary>
/// 重写删除指定ID集合的数据(批量删除)
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable<CoreCmsAgentOrder>().In(ids).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
#endregion
#region
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="orderByExpression"></param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public new async Task<IPageList<CoreCmsAgentOrder>> QueryPageAsync(Expression<Func<CoreCmsAgentOrder, bool>> predicate,
Expression<Func<CoreCmsAgentOrder, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsAgentOrder> page;
if (blUseNoLock)
{
page = await DbClient.Queryable<CoreCmsAgentOrder, CoreCmsOrder, CoreCmsUser, CoreCmsUser>((dOrder, cOrder, cUser, pUser) => new object[] {
JoinType.Inner,dOrder.orderId==cOrder.orderId,
JoinType.Inner,dOrder.buyUserId==cUser.id,
JoinType.Inner,dOrder.userId==pUser.id
})
.Select((dOrder, cOrder, cUser, pUser) => new CoreCmsAgentOrder
{
id = dOrder.id,
userId = dOrder.userId,
buyUserId = dOrder.buyUserId,
orderId = dOrder.orderId,
amount = dOrder.amount,
isSettlement = dOrder.isSettlement,
createTime = dOrder.createTime,
updateTime = dOrder.updateTime,
isDelete = dOrder.isDelete,
buyUserNickName = cUser.nickName,
distributorName = pUser.nickName
})
.With(SqlWith.NoLock)
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate)
.ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable<CoreCmsAgentOrder, CoreCmsOrder, CoreCmsUser, CoreCmsUser>((dOrder, cOrder, cUser, pUser) => new object[] {
JoinType.Inner,dOrder.orderId==cOrder.orderId,
JoinType.Inner,dOrder.buyUserId==cUser.id,
JoinType.Inner,dOrder.userId==pUser.id
})
.Select((dOrder, cOrder, cUser, pUser) => new CoreCmsAgentOrder
{
id = dOrder.id,
userId = dOrder.userId,
buyUserId = dOrder.buyUserId,
orderId = dOrder.orderId,
amount = dOrder.amount,
isSettlement = dOrder.isSettlement,
createTime = dOrder.createTime,
updateTime = dOrder.updateTime,
isDelete = dOrder.isDelete,
buyUserNickName = cUser.nickName,
distributorName = pUser.nickName
})
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate)
.ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList<CoreCmsAgentOrder>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}

View File

@@ -0,0 +1,97 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Manual;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 代理货品池 接口实现
/// </summary>
public class CoreCmsAgentProductsRepository : BaseRepository<CoreCmsAgentProducts>, ICoreCmsAgentProductsRepository
{
public CoreCmsAgentProductsRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
#region
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="orderByExpression"></param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public new async Task<IPageList<CoreCmsAgentProducts>> QueryPageAsync(Expression<Func<CoreCmsAgentProducts, bool>> predicate,
Expression<Func<CoreCmsAgentProducts, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsAgentProducts> page;
if (blUseNoLock)
{
page = await DbClient.Queryable<CoreCmsAgentProducts>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsAgentProducts
{
id = p.id,
goodId = p.goodId,
productId = p.productId,
productCostPrice = p.productCostPrice,
productPrice = p.productPrice,
agentGradeId = p.agentGradeId,
agentGradePrice = p.agentGradePrice,
createTime = p.createTime,
updateTime = p.updateTime,
isDel = p.isDel,
}).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable<CoreCmsAgentProducts>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsAgentProducts
{
id = p.id,
goodId = p.goodId,
productId = p.productId,
productCostPrice = p.productCostPrice,
productPrice = p.productPrice,
agentGradeId = p.agentGradeId,
agentGradePrice = p.agentGradePrice,
createTime = p.createTime,
updateTime = p.updateTime,
isDel = p.isDel,
}).ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList<CoreCmsAgentProducts>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}

View File

@@ -0,0 +1,189 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Manual;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Model.ViewModels.DTO.Agent;
using SqlSugar;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 代理商表 接口实现
/// </summary>
public class CoreCmsAgentRepository : BaseRepository<CoreCmsAgent>, ICoreCmsAgentRepository
{
public CoreCmsAgentRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
#region
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="orderByExpression"></param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public new async Task<IPageList<CoreCmsAgent>> QueryPageAsync(Expression<Func<CoreCmsAgent, bool>> predicate,
Expression<Func<CoreCmsAgent, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsAgent> page;
if (blUseNoLock)
{
page = await DbClient.Queryable<CoreCmsAgent>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsAgent
{
id = p.id,
userId = p.userId,
name = p.name,
gradeId = p.gradeId,
mobile = p.mobile,
weixin = p.weixin,
qq = p.qq,
storeName = p.storeName,
storeLogo = p.storeLogo,
storeBanner = p.storeBanner,
storeDesc = p.storeDesc,
verifyStatus = p.verifyStatus,
createTime = p.createTime,
updateTime = p.updateTime,
verifyTime = p.verifyTime,
isDelete = p.isDelete,
}).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable<CoreCmsAgent>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsAgent
{
id = p.id,
userId = p.userId,
name = p.name,
gradeId = p.gradeId,
mobile = p.mobile,
weixin = p.weixin,
qq = p.qq,
storeName = p.storeName,
storeLogo = p.storeLogo,
storeBanner = p.storeBanner,
storeDesc = p.storeDesc,
verifyStatus = p.verifyStatus,
createTime = p.createTime,
updateTime = p.updateTime,
verifyTime = p.verifyTime,
isDelete = p.isDelete,
}).ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList<CoreCmsAgent>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
#region
/// <summary>
/// 根据条件查询分页数据
/// </summary>
/// <param name="userId"></param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="typeId"></param>
/// <returns></returns>
public async Task<IPageList<CoreCmsAgentOrder>> QueryOrderPageAsync(int userId, int pageIndex = 1, int pageSize = 20, int typeId = 0)
{
RefAsync<int> totalCount = 0;
var page = await DbClient.Queryable<CoreCmsAgentOrder, CoreCmsOrder, CoreCmsUser>((dOrder, cOrder, userInfo) => new object[] {
JoinType.Inner,dOrder.orderId==cOrder.orderId,JoinType.Inner,dOrder.buyUserId==userInfo.id
})
.Where((dOrder, cOrder, userInfo) => dOrder.userId == userId)
.Select((dOrder, cOrder, userInfo) => new CoreCmsAgentOrder()
{
id = dOrder.id,
userId = dOrder.userId,
buyUserId = dOrder.buyUserId,
orderId = dOrder.orderId,
amount = dOrder.amount,
isSettlement = dOrder.isSettlement,
createTime = dOrder.createTime,
updateTime = dOrder.updateTime,
isDelete = dOrder.isDelete,
buyUserNickName = userInfo.nickName
})
.With(SqlWith.NoLock)
.MergeTable()
.WhereIF(typeId > 0, p => p.isSettlement == typeId)
.OrderBy(dOrder => dOrder.id, OrderByType.Desc)
.ToPageListAsync(pageIndex, pageSize, totalCount);
var list = new PageList<CoreCmsAgentOrder>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
#region
/// <summary>
/// 获取代理商排行
/// </summary>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <returns></returns>
public async Task<IPageList<AgentRankingDTO>> QueryRankingPageAsync(int pageIndex = 1, int pageSize = 20)
{
RefAsync<int> totalCount = 0;
var page = await DbClient.Queryable<CoreCmsAgent>()
.Select(p => new AgentRankingDTO()
{
id = p.userId,
nickname = p.name,
createtime = p.createTime,
totalInCome = SqlFunc.Subqueryable<CoreCmsAgentOrder>().Where(o => o.userId == p.userId && p.isDelete == false && p.verifyStatus == (int)GlobalEnumVars.AgentOrderSettlementStatus.SettlementYes).Sum(o => o.amount),
orderCount = SqlFunc.Subqueryable<CoreCmsAgentOrder>().Where(o => o.userId == p.userId && p.isDelete == false && p.verifyStatus == (int)GlobalEnumVars.AgentOrderSettlementStatus.SettlementYes).Count()
})
.With(SqlWith.NoLock)
.MergeTable()
.OrderBy(dOrder => dOrder.totalInCome, OrderByType.Desc)
.WithCache()
.ToPageListAsync(pageIndex, pageSize, totalCount);
var list = new PageList<AgentRankingDTO>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}