添加项目文件。

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,26 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 品牌表 接口实现
/// </summary>
public class CoreCmsBrandRepository : BaseRepository<CoreCmsBrand>, ICoreCmsBrandRepository
{
public CoreCmsBrandRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

View File

@@ -0,0 +1,69 @@
/***********************************************************************
* 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.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using SqlSugar;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 商品浏览记录表 接口实现
/// </summary>
public class CoreCmsGoodsBrowsingRepository : BaseRepository<CoreCmsGoodsBrowsing>, ICoreCmsGoodsBrowsingRepository
{
public CoreCmsGoodsBrowsingRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="pageIndex">当前页面索引</param>
/// <param name="pageSize">分布大小</param>
/// <param name="orderByExpression"></param>
/// <returns></returns>
public async Task<IPageList<CoreCmsGoodsBrowsing>> QueryPageAsync(
Expression<Func<CoreCmsGoodsBrowsing, bool>> predicate,
Expression<Func<CoreCmsGoodsBrowsing, object>> orderByExpression, OrderByType orderByType,
int pageIndex = 1,
int pageSize = 20)
{
RefAsync<int> totalCount = 0;
var page = await DbClient.Queryable<CoreCmsGoodsBrowsing, CoreCmsGoods>((gb, goods) =>
new JoinQueryInfos(JoinType.Left, gb.goodsId == goods.id))
.Select((gb, goods) => new CoreCmsGoodsBrowsing
{
id = gb.id,
goodsId = gb.goodsId,
userId = gb.userId,
goodsName = gb.goodsName,
createTime = gb.createTime,
isdel = gb.isdel,
goodImage = goods.image
//isCollection = SqlFunc.Subqueryable<CoreCmsGoodsCollection>().Where(p => p.userId == gb.userId && p.goodsId == gb.goodsId).Any()
})
.With(SqlWith.NoLock)
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).ToPageListAsync(pageIndex, pageSize, totalCount);
var list = new PageList<CoreCmsGoodsBrowsing>(page, pageIndex, pageSize, totalCount);
return list;
}
}
}

View File

@@ -0,0 +1,27 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 商品分类扩展表 接口实现
/// </summary>
public class CoreCmsGoodsCategoryExtendRepository : BaseRepository<CoreCmsGoodsCategoryExtend>,
ICoreCmsGoodsCategoryExtendRepository
{
public CoreCmsGoodsCategoryExtendRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

View File

@@ -0,0 +1,167 @@
/***********************************************************************
* 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.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 CoreCmsGoodsCategoryRepository : BaseRepository<CoreCmsGoodsCategory>, ICoreCmsGoodsCategoryRepository
{
public CoreCmsGoodsCategoryRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
#region ==========================================================
/// <summary>
/// 重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsGoodsCategory 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;
if (bl)
{
await UpdateCaChe();
}
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsGoodsCategory 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>
/// 重写异步更新方法方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public new async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsGoodsCategory> 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 new async Task<AdminUiCallBack> DeleteByIdAsync(object id)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable<CoreCmsGoodsCategory>(id).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
if (bl)
{
await UpdateCaChe();
}
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<CoreCmsGoodsCategory>().In(ids).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
if (bl)
{
await UpdateCaChe();
}
return jm;
}
#endregion
#region ==========================================================
/// <summary>
/// 获取缓存的所有数据
/// </summary>
/// <returns></returns>
public async Task<List<CoreCmsGoodsCategory>> GetCaChe()
{
var cache = ManualDataCache.Instance.Get<List<CoreCmsGoodsCategory>>(GlobalConstVars.CacheCoreCmsGoodsCategory);
if (cache != null)
{
return cache;
}
return await UpdateCaChe();
}
/// <summary>
/// 更新cache
/// </summary>
private async Task<List<CoreCmsGoodsCategory>> UpdateCaChe()
{
var list = await DbClient.Queryable<CoreCmsGoodsCategory>().With(SqlWith.NoLock).ToListAsync();
ManualDataCache.Instance.Set(GlobalConstVars.CacheCoreCmsGoodsCategory, list);
return list;
}
#endregion
}
}

View File

@@ -0,0 +1,96 @@
/***********************************************************************
* 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.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
{
/// <summary>
/// 商品收藏表 接口实现
/// </summary>
public class CoreCmsGoodsCollectionRepository : BaseRepository<CoreCmsGoodsCollection>, ICoreCmsGoodsCollectionRepository
{
public CoreCmsGoodsCollectionRepository(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>
/// <returns></returns>
public async Task<IPageList<CoreCmsGoodsCollection>> QueryPageAsync(Expression<Func<CoreCmsGoodsCollection, bool>> predicate,
Expression<Func<CoreCmsGoodsCollection, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20)
{
RefAsync<int> totalCount = 0;
var page = await DbClient.Queryable<CoreCmsGoodsCollection>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate)
.Mapper(p => p.goods, p => p.goodsId)
.ToPageListAsync(pageIndex, pageSize, totalCount);
var list = new PageList<CoreCmsGoodsCollection>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
#region
/// <summary>
/// 收藏
/// </summary>
/// <param name="userId"></param>
/// <param name="goodsId"></param>
/// <returns></returns>
public async Task<WebApiCallBack> ToAdd(int userId, int goodsId)
{
var jm = new WebApiCallBack();
var goodsModel = await DbClient.Queryable<CoreCmsGoods>().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
}
}

View File

@@ -0,0 +1,278 @@
/***********************************************************************
* 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;
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 CoreCmsGoodsCommentRepository : BaseRepository<CoreCmsGoodsComment>, ICoreCmsGoodsCommentRepository
{
public CoreCmsGoodsCommentRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
#region ==========================================================
/// <summary>
/// 重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsGoodsComment 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(CoreCmsGoodsComment entity)
{
var jm = new AdminUiCallBack();
var oldModel = await DbClient.Queryable<CoreCmsGoodsComment>().In(entity.id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
//事物处理过程开始
oldModel.id = entity.id;
oldModel.commentId = entity.commentId;
oldModel.score = entity.score;
oldModel.userId = entity.userId;
oldModel.goodsId = entity.goodsId;
oldModel.orderId = entity.orderId;
oldModel.addon = entity.addon;
oldModel.images = entity.images;
oldModel.contentBody = entity.contentBody;
oldModel.sellerContent = entity.sellerContent;
oldModel.isDisplay = entity.isDisplay;
oldModel.createTime = entity.createTime;
//事物处理过程结束
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<CoreCmsGoodsComment> 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<CoreCmsGoodsComment>(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<CoreCmsGoodsComment>().In(ids).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
#endregion
/// <summary>
/// 商家回复评价
/// </summary>
/// <param name="id">序列</param>
/// <param name="sellerContent">回复内容</param>
/// <returns></returns>
public async Task<AdminUiCallBack> Reply(int id,string sellerContent)
{
var jm = new AdminUiCallBack();
var oldModel = await DbClient.Queryable<CoreCmsGoodsComment>().In(id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
//事物处理过程开始
oldModel.sellerContent = sellerContent;
//事物处理过程结束
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="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="orderByExpression"></param>
/// <returns></returns>
public async Task<CoreCmsGoodsComment> DetailsByIdAsync(Expression<Func<CoreCmsGoodsComment, bool>> predicate,
Expression<Func<CoreCmsGoodsComment, object>> orderByExpression, OrderByType orderByType)
{
var model = await DbClient.Queryable<CoreCmsGoodsComment, CoreCmsUser, CoreCmsGoods>((p, cUser, cGood) => new JoinQueryInfos(
JoinType.Left, p.userId == cUser.id,
JoinType.Left, p.goodsId == cGood.id
))
.Select((p, cUser, cGood) => new CoreCmsGoodsComment
{
id = p.id,
commentId = p.commentId,
score = p.score,
userId = p.userId,
goodsId = p.goodsId,
orderId = p.orderId,
addon = p.addon,
images = p.images,
contentBody = p.contentBody,
sellerContent = p.sellerContent,
isDisplay = p.isDisplay,
createTime = p.createTime,
avatarImage = cUser.avatarImage,
nickName = cUser.nickName,
mobile = cUser.mobile,
goodName = cGood.name,
})
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.Where(predicate)
.FirstAsync();
if (model != null)
{
model.imagesArr = !string.IsNullOrEmpty(model.images) ? model.images.Split(",") : new String[0];
}
return model;
}
#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<CoreCmsGoodsComment>> QueryPageAsync(Expression<Func<CoreCmsGoodsComment, bool>> predicate,
Expression<Func<CoreCmsGoodsComment, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsGoodsComment> page = await DbClient.Queryable<CoreCmsGoodsComment, CoreCmsUser, CoreCmsGoods>((p, cUser, cGood) => new JoinQueryInfos(
JoinType.Left, p.userId == cUser.id,
JoinType.Left, p.goodsId == cGood.id
))
.Select((p, cUser, cGood) => new CoreCmsGoodsComment
{
id = p.id,
commentId = p.commentId,
score = p.score,
userId = p.userId,
goodsId = p.goodsId,
orderId = p.orderId,
addon = p.addon,
images = p.images,
contentBody = p.contentBody,
sellerContent = p.sellerContent,
isDisplay = p.isDisplay,
createTime = p.createTime,
avatarImage = cUser.avatarImage,
nickName = cUser.nickName,
mobile = cUser.mobile,
goodName = cGood.name,
})
.MergeTable()//将上面的操作变成一个表 mergetable
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.Where(predicate)
.ToPageListAsync(pageIndex, pageSize, totalCount);
if (page.Any())
{
foreach (var item in page)
{
item.imagesArr = !string.IsNullOrEmpty(item.images) ? item.images.Split(",") : new String[0];
}
}
var list = new PageList<CoreCmsGoodsComment>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}

View File

@@ -0,0 +1,27 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 商品会员价表 接口实现
/// </summary>
public class CoreCmsGoodsGradeRepository : BaseRepository<CoreCmsGoodsGrade>, ICoreCmsGoodsGradeRepository
{
public CoreCmsGoodsGradeRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

View File

@@ -0,0 +1,26 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 商品参数表 接口实现
/// </summary>
public class CoreCmsGoodsParamsRepository : BaseRepository<CoreCmsGoodsParams>, ICoreCmsGoodsParamsRepository
{
public CoreCmsGoodsParamsRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,172 @@
/***********************************************************************
* 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;
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.FromBody;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Helper;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 商品类型属性表 接口实现
/// </summary>
public class CoreCmsGoodsTypeSpecRepository : BaseRepository<CoreCmsGoodsTypeSpec>, ICoreCmsGoodsTypeSpecRepository
{
public CoreCmsGoodsTypeSpecRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
/// <summary>
/// 使用事务重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public async Task<AdminUiCallBack> InsertAsync(FmGoodsTypeSpecInsert entity)
{
var jm = new AdminUiCallBack();
if (entity.value == null)
{
jm.msg = "请添加属性值"; return jm;
}
for (int i = 0; i < entity.value.Count; i++)
{
entity.value[i] = entity.value[i].Trim();
if (GoodsHelper.FilterChar(entity.value[i]) == false) continue;
jm.msg = "属性值不符合支持规则"; return jm;
}
if (entity.value.GroupBy(n => n).Any(c => c.Count() > 1))
{
jm.msg = "属性值不允许有相同"; return jm;
}
var goodsTypeSpec = new CoreCmsGoodsTypeSpec();
goodsTypeSpec.name = entity.name;
goodsTypeSpec.sort = entity.sort;
var specId = await DbClient.Insertable(goodsTypeSpec).ExecuteReturnIdentityAsync();
if (specId > 0 && entity.value != null && entity.value.Count > 0)
{
var list = new List<CoreCmsGoodsTypeSpecValue>();
for (var index = 0; index < entity.value.Count; index++)
{
var item = entity.value[index];
list.Add(new CoreCmsGoodsTypeSpecValue()
{
specId = specId,
value = item,
sort = index + 1
});
}
var bl = await DbClient.Insertable(list).ExecuteCommandAsync() > 0;
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
}
return jm;
}
/// <summary>
/// 重写异步更新方法方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> UpdateAsync(FmGoodsTypeSpecUpdate entity)
{
var jm = new AdminUiCallBack();
if (entity.value == null)
{
jm.msg = "请添加属性值"; return jm;
}
for (int i = 0; i < entity.value.Count; i++)
{
entity.value[i] = entity.value[i].Trim();
if (GoodsHelper.FilterChar(entity.value[i]) == false) continue;
jm.msg = "属性值不符合支持规则"; return jm;
}
if (entity.value.GroupBy(n => n).Any(c => c.Count() > 1))
{
jm.msg = "属性值不允许有相同"; return jm;
}
var oldModel = await DbClient.Queryable<CoreCmsGoodsTypeSpec>().In(entity.id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
oldModel.name = entity.name;
oldModel.sort = entity.sort;
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
if (bl)
{
var oldValues = await DbClient.Queryable<CoreCmsGoodsTypeSpecValue>().OrderBy(p => p.sort)
.Where(p => p.specId == oldModel.id).ToListAsync();
//获取需要删除的数据库数据
var deleteValues = oldValues.Where(p => !entity.value.Contains(p.value)).ToList();
//删除旧数据
if (deleteValues.Any()) bl = await DbClient.Deleteable<CoreCmsGoodsTypeSpecValue>(deleteValues).ExecuteCommandHasChangeAsync();
//新数据
var values = oldValues.Select(p => p.value).ToList();
var newValues = entity.value.Except(values).ToList();
//插入新数据
if (newValues.Any())
{
var newList = newValues.Select((t, index) => new CoreCmsGoodsTypeSpecValue() { specId = oldModel.id, value = t, sort = oldValues.Count + index }).ToList();
bl = await DbClient.Insertable<CoreCmsGoodsTypeSpecValue>(newList).ExecuteCommandAsync() > 0;
}
}
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<CoreCmsGoodsTypeSpec>(id).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
if (bl)
{
await DbClient.Deleteable<CoreCmsGoodsTypeSpecValue>(p => p.specId == (int)id).ExecuteCommandHasChangeAsync();
}
return jm;
}
}
}

View File

@@ -0,0 +1,26 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/1/31 21:45:10
* Description: 暂无
***********************************************************************/
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 商品类型属性值表 接口实现
/// </summary>
public class CoreCmsGoodsTypeSpecValueRepository : BaseRepository<CoreCmsGoodsTypeSpecValue>, ICoreCmsGoodsTypeSpecValueRepository
{
public CoreCmsGoodsTypeSpecValueRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

View File

@@ -0,0 +1,35 @@
/***********************************************************************
* 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.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;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 货品三级佣金表 接口实现
/// </summary>
public class CoreCmsProductsDistributionRepository : BaseRepository<CoreCmsProductsDistribution>, ICoreCmsProductsDistributionRepository
{
public CoreCmsProductsDistributionRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}

View File

@@ -0,0 +1,333 @@
/***********************************************************************
* 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.Auth.HttpContextUser;
using CoreCms.Net.Configuration;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Extensions;
using SqlSugar;
namespace CoreCms.Net.Repository
{
/// <summary>
/// 货品表 接口实现
/// </summary>
public class CoreCmsProductsRepository : BaseRepository<CoreCmsProducts>, ICoreCmsProductsRepository
{
private readonly IUnitOfWork _unitOfWork;
private readonly ICoreCmsStockRepository _stockRepository;
private readonly IHttpContextUser _user;
public CoreCmsProductsRepository(IUnitOfWork unitOfWork, ICoreCmsStockRepository stockRepository, IHttpContextUser user) : base(unitOfWork)
{
_unitOfWork = unitOfWork;
_stockRepository = stockRepository;
_user = user;
}
#region
/// <summary>
/// 判断货品上下架状态
/// </summary>
/// <param name="productsId">货品序列</param>
/// <returns></returns>
public async Task<bool> GetShelfStatus(int productsId)
{
var data = await DbClient.Queryable<CoreCmsProducts, CoreCmsGoods>((products, goods) => new object[]
{
JoinType.Inner, products.goodsId == goods.id
})
.Where((products, goods) => products.id == productsId)
.Select((products, goods) => new
{
productsId = products.id,
isMarketable = goods.isMarketable
}).FirstAsync();
return data != null && data.isMarketable == true;
}
#endregion
#region
/// <summary>
/// 获取库存报警数量
/// </summary>
/// <param name="goodsStocksWarn"></param>
/// <returns></returns>
public async Task<int> GoodsStaticsTotalWarn(int goodsStocksWarn)
{
var sql = @"SELECT COUNT(*) AS number
FROM ( SELECT t.goodsId
FROM ( SELECT goodsId ,
( CASE WHEN stock < freezeStock THEN 0
ELSE stock - freezeStock
END ) AS number
FROM CoreCmsProducts
) t
WHERE t.number < " + goodsStocksWarn + @"
GROUP BY t.goodsId
) d";
var dt = await DbClient.Ado.GetDataTableAsync(sql);
var number = dt.Rows[0][0].ObjectToInt(0);
return number;
}
#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 async Task<IPageList<CoreCmsProducts>> QueryDetailPageAsync(Expression<Func<CoreCmsProducts, bool>> predicate,
Expression<Func<CoreCmsProducts, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsProducts> page;
if (blUseNoLock)
{
page = await DbClient.Queryable<CoreCmsProducts, CoreCmsGoods>((p, good) => new JoinQueryInfos(
JoinType.Left, p.goodsId == good.id))
.Select((p, good) => new CoreCmsProducts
{
id = p.id,
goodsId = p.goodsId,
barcode = p.barcode,
sn = p.sn,
price = p.price,
costprice = p.costprice,
mktprice = p.mktprice,
marketable = p.marketable,
weight = p.weight,
stock = p.stock,
freezeStock = p.freezeStock,
spesDesc = p.spesDesc,
isDefalut = p.isDefalut,
images = p.images,
isDel = p.isDel,
name = good.name,
bn = good.bn,
isMarketable = good.isMarketable,
unit = good.unit
}).With(SqlWith.NoLock)
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate)
.ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable<CoreCmsProducts, CoreCmsGoods>((p, good) => new JoinQueryInfos(
JoinType.Left, p.goodsId == good.id))
.Select((p, good) => new CoreCmsProducts
{
id = p.id,
goodsId = p.goodsId,
barcode = p.barcode,
sn = p.sn,
price = p.price,
costprice = p.costprice,
mktprice = p.mktprice,
marketable = p.marketable,
weight = p.weight,
stock = p.stock,
freezeStock = p.freezeStock,
spesDesc = p.spesDesc,
isDefalut = p.isDefalut,
images = p.images,
isDel = p.isDel,
name = good.name,
bn = good.bn,
isMarketable = good.isMarketable,
unit = good.unit
})
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate)
.ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList<CoreCmsProducts>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
#region
/// <summary>
/// 修改单个货品库存并记入库存管理日志内
/// </summary>
/// <param name="productId"></param>
/// <param name="stockNumber"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> EditStock(int productId, int stockNumber)
{
var jm = new AdminUiCallBack();
var product = await DbClient.Queryable<CoreCmsProducts, CoreCmsGoods>((p, good) => new JoinQueryInfos(
JoinType.Left, p.goodsId == good.id))
.Select((p, good) => new CoreCmsProducts
{
id = p.id,
goodsId = p.goodsId,
barcode = p.barcode,
sn = p.sn,
price = p.price,
costprice = p.costprice,
mktprice = p.mktprice,
marketable = p.marketable,
weight = p.weight,
stock = p.stock,
freezeStock = p.freezeStock,
spesDesc = p.spesDesc,
isDefalut = p.isDefalut,
images = p.images,
isDel = p.isDel,
name = good.name,
bn = good.bn,
isMarketable = good.isMarketable,
unit = good.unit
})
.MergeTable()
.Where(p => p.id == productId)
.FirstAsync();
if (product == null)
{
jm.msg = "货品数据查询失败";
return jm;
}
var nums = stockNumber - product.stock;
var msg = string.Empty;
if (nums == 0)
{
jm.code = 0;
jm.msg = "库存未修改";
return jm;
}
else if (nums < 0)
{
jm.code = 0;
msg = "库存盘点:库存减少" + Math.Abs(nums);
}
else
{
msg = "库存盘点:库存增加" + nums;
}
var stockModel = new CoreCmsStock();
stockModel.id = await _stockRepository.CreateCode(GlobalEnumVars.StockType.CheckGoods.ToString());
stockModel.memo = msg;
stockModel.type = (int)GlobalEnumVars.StockType.CheckGoods;
stockModel.manager = _user.ID;
stockModel.createTime = DateTime.Now;
var stockLogModel = new CoreCmsStockLog();
stockLogModel.stockId = stockModel.id;
stockLogModel.productId = product.id;
stockLogModel.goodsId = product.goodsId;
stockLogModel.nums = nums;
stockLogModel.goodsName = product.name;
stockLogModel.sn = product.sn;
stockLogModel.bn = product.bn;
stockLogModel.spesDesc = product.spesDesc;
try
{
_unitOfWork.BeginTran();
await DbClient.Updateable<CoreCmsProducts>().SetColumns(p => new CoreCmsProducts() { stock = stockNumber }).Where(p => p.id == product.id).ExecuteCommandAsync();
await DbClient.Insertable(stockModel).ExecuteCommandAsync();
await DbClient.Insertable(stockLogModel).ExecuteCommandAsync();
jm.code = 0;
jm.msg = "库存修改成功";
_unitOfWork.CommitTran();
}
catch (Exception e)
{
jm.code = 1;
jm.msg = "库存修改异常";
jm.otherData = e;
_unitOfWork.RollbackTran();
}
return jm;
}
#endregion
#region
/// <summary>
/// 获取货品数据
/// </summary>
/// <param name="goodId"></param>
/// <returns></returns>
public async Task<List<CoreCmsProducts>> GetProducts(int goodId = 0)
{
var list = await DbClient.Queryable<CoreCmsProducts, CoreCmsGoods>((p, good) => new JoinQueryInfos(
JoinType.Left, p.goodsId == good.id))
.Select((p, good) => new CoreCmsProducts
{
id = p.id,
goodsId = p.goodsId,
barcode = p.barcode,
sn = p.sn,
price = p.price,
costprice = p.costprice,
mktprice = p.mktprice,
marketable = p.marketable,
weight = p.weight,
stock = p.stock,
freezeStock = p.freezeStock,
spesDesc = p.spesDesc,
isDefalut = p.isDefalut,
images = p.images,
isDel = p.isDel,
name = good.name,
bn = good.bn,
isMarketable = good.isMarketable,
unit = good.unit
}).With(SqlWith.NoLock)
.MergeTable()
.OrderBy(p => p.id, OrderByType.Desc)
.WhereIF(goodId > 0, p => p.goodsId == goodId)
.Where(p => p.isDel == false)
.ToListAsync();
return list;
}
#endregion
}
}