mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 21:03:26 +08:00
添加项目文件。
This commit is contained in:
362
CoreCms.Net.Web.Admin/Controllers/Good/CoreCmsBrandController.cs
Normal file
362
CoreCms.Net.Web.Admin/Controllers/Good/CoreCmsBrandController.cs
Normal file
@@ -0,0 +1,362 @@
|
||||
/***********************************************************************
|
||||
* 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.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 品牌表
|
||||
/// </summary>
|
||||
[Description("品牌表")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[RequiredErrorForAdmin]
|
||||
[Authorize(Permissions.Name)]
|
||||
public class CoreCmsBrandController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsBrandServices _coreCmsBrandServices;
|
||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CoreCmsBrandController(IWebHostEnvironment webHostEnvironment,
|
||||
ICoreCmsBrandServices coreCmsBrandServices, ICoreCmsGoodsServices goodsServices)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsBrandServices = coreCmsBrandServices;
|
||||
_goodsServices = goodsServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
|
||||
// POST: Api/CoreCmsBrand/GetPageList
|
||||
/// <summary>
|
||||
/// 获取列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取列表")]
|
||||
public async Task<AdminUiCallBack> GetPageList()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
|
||||
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
|
||||
var where = PredicateBuilder.True<CoreCmsBrand>();
|
||||
//获取排序字段
|
||||
var orderField = Request.Form["orderField"].FirstOrDefault();
|
||||
Expression<Func<CoreCmsBrand, object>> orderEx;
|
||||
switch (orderField)
|
||||
{
|
||||
case "id":
|
||||
orderEx = p => p.id;
|
||||
break;
|
||||
case "name":
|
||||
orderEx = p => p.name;
|
||||
break;
|
||||
case "logoImageUrl":
|
||||
orderEx = p => p.logoImageUrl;
|
||||
break;
|
||||
case "sort":
|
||||
orderEx = p => p.sort;
|
||||
break;
|
||||
case "isShow":
|
||||
orderEx = p => p.isShow;
|
||||
break;
|
||||
case "createTime":
|
||||
orderEx = p => p.createTime;
|
||||
break;
|
||||
default:
|
||||
orderEx = p => p.sort;
|
||||
break;
|
||||
}
|
||||
|
||||
//设置排序方式
|
||||
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
|
||||
var orderBy = orderDirection switch
|
||||
{
|
||||
"asc" => OrderByType.Asc,
|
||||
"desc" => OrderByType.Desc,
|
||||
_ => OrderByType.Desc
|
||||
};
|
||||
//查询筛选
|
||||
|
||||
//品牌ID int
|
||||
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
|
||||
if (id > 0) @where = @where.And(p => p.id == id);
|
||||
//品牌名称 nvarchar
|
||||
var name = Request.Form["name"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(name)) @where = @where.And(p => p.name.Contains(name));
|
||||
//品牌LOGO nvarchar
|
||||
var logoImageUrl = Request.Form["logoImageUrl"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(logoImageUrl)) @where = @where.And(p => p.logoImageUrl.Contains(logoImageUrl));
|
||||
//品牌排序 int
|
||||
var sort = Request.Form["sort"].FirstOrDefault().ObjectToInt(0);
|
||||
if (sort > 0) @where = @where.And(p => p.sort == sort);
|
||||
//是否显示 bit
|
||||
var isShow = Request.Form["isShow"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(isShow) && isShow.ToLowerInvariant() == "true")
|
||||
@where = @where.And(p => p.isShow);
|
||||
else if (!string.IsNullOrEmpty(isShow) && isShow.ToLowerInvariant() == "false")
|
||||
@where = @where.And(p => p.isShow == false);
|
||||
//更新时间 datetime
|
||||
var createTime = Request.Form["createTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(createTime))
|
||||
{
|
||||
if (createTime.Contains("到"))
|
||||
{
|
||||
var dts = createTime.Split("到");
|
||||
var dtStart = dts[0].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime > dtStart);
|
||||
var dtEnd = dts[1].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime < dtEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = createTime.ObjectToDate();
|
||||
where = where.And(p => p.createTime > dt);
|
||||
}
|
||||
}
|
||||
|
||||
//获取数据
|
||||
var list = await _coreCmsBrandServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize);
|
||||
//返回数据
|
||||
jm.data = list;
|
||||
jm.code = 0;
|
||||
jm.count = list.TotalCount;
|
||||
jm.msg = "数据调用成功!";
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 首页数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsBrand/GetIndex
|
||||
/// <summary>
|
||||
/// 首页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("首页数据")]
|
||||
public AdminUiCallBack GetIndex()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 创建数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsBrand/GetCreate
|
||||
/// <summary>
|
||||
/// 创建数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建数据")]
|
||||
public AdminUiCallBack GetCreate()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 创建提交============================================================
|
||||
|
||||
// POST: Api/CoreCmsBrand/DoCreate
|
||||
/// <summary>
|
||||
/// 创建提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建提交")]
|
||||
public async Task<AdminUiCallBack> DoCreate([FromBody] CoreCmsBrand entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await _coreCmsBrandServices.InsertAsync(entity) > 0;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
|
||||
|
||||
if (bl)
|
||||
{
|
||||
var brands = await _coreCmsBrandServices.QueryListByClauseAsync(p => p.id > 0, p => p.id, OrderByType.Desc, true);
|
||||
jm.data = new
|
||||
{
|
||||
brands
|
||||
};
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 编辑数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsBrand/GetEdit
|
||||
/// <summary>
|
||||
/// 编辑数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑数据")]
|
||||
public async Task<AdminUiCallBack> GetEdit([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsBrandServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
jm.code = 0;
|
||||
jm.data = model;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 编辑提交============================================================
|
||||
|
||||
// POST: Admins/CoreCmsBrand/Edit
|
||||
/// <summary>
|
||||
/// 编辑提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑提交")]
|
||||
public async Task<AdminUiCallBack> DoEdit([FromBody] CoreCmsBrand entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await _coreCmsBrandServices.QueryByIdAsync(entity.id);
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
//事物处理过程开始
|
||||
oldModel.name = entity.name;
|
||||
oldModel.logoImageUrl = entity.logoImageUrl;
|
||||
oldModel.sort = entity.sort;
|
||||
oldModel.isShow = entity.isShow;
|
||||
oldModel.createTime = DateTime.Now;
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = await _coreCmsBrandServices.UpdateAsync(oldModel);
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsBrand/DoDelete/10
|
||||
/// <summary>
|
||||
/// 单选删除
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("单选删除")]
|
||||
public async Task<AdminUiCallBack> DoDelete([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsBrandServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (await _goodsServices.ExistsAsync(p => p.brandId == model.id))
|
||||
{
|
||||
jm.msg = "有商品关联品牌数据,禁止删除";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var bl = await _coreCmsBrandServices.DeleteByIdAsync(entity.id);
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 设置是否显示============================================================
|
||||
|
||||
// POST: Api/CoreCmsBrand/DoSetisShow/10
|
||||
/// <summary>
|
||||
/// 设置是否显示
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("设置是否显示")]
|
||||
public async Task<AdminUiCallBack> DoSetisShow([FromBody] FMUpdateBoolDataByIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await _coreCmsBrandServices.QueryByIdAsync(entity.id);
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
oldModel.isShow = entity.data;
|
||||
oldModel.createTime = DateTime.Now;
|
||||
|
||||
var bl = await _coreCmsBrandServices.UpdateAsync(oldModel);
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,306 @@
|
||||
/***********************************************************************
|
||||
* 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.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using AutoMapper;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.IServices;
|
||||
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;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品分类
|
||||
///</summary>
|
||||
[Description("商品分类")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[RequiredErrorForAdmin]
|
||||
[Authorize(Permissions.Name)]
|
||||
public class CoreCmsGoodsCategoryController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly ICoreCmsGoodsCategoryServices _coreCmsGoodsCategoryServices;
|
||||
private readonly ICoreCmsGoodsServices _goodsServices;
|
||||
private IMapper _mapper;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CoreCmsGoodsCategoryController(IWebHostEnvironment webHostEnvironment
|
||||
, ICoreCmsGoodsCategoryServices coreCmsGoodsCategoryServices
|
||||
, IMapper mapper, ICoreCmsGoodsServices goodsServices)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsGoodsCategoryServices = coreCmsGoodsCategoryServices;
|
||||
_mapper = mapper;
|
||||
_goodsServices = goodsServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
// POST: Api/CoreCmsGoodsCategory/GetPageList
|
||||
/// <summary>
|
||||
/// 获取列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取列表")]
|
||||
public async Task<AdminUiCallBack> GetPageList()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
//获取数据
|
||||
var list = await _coreCmsGoodsCategoryServices.QueryListByClauseAsync(p => p.id > 0, p => p.sort,
|
||||
OrderByType.Desc);
|
||||
//返回数据
|
||||
jm.data = list;
|
||||
jm.code = 0;
|
||||
jm.msg = "数据调用成功!";
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 首页数据============================================================
|
||||
// POST: Api/CoreCmsGoodsCategory/GetIndex
|
||||
/// <summary>
|
||||
/// 首页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("首页数据")]
|
||||
public AdminUiCallBack GetIndex()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建数据============================================================
|
||||
// POST: Api/CoreCmsGoodsCategory/GetCreate
|
||||
/// <summary>
|
||||
/// 创建数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建数据")]
|
||||
public async Task<AdminUiCallBack> GetCreate()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
var categories = await _coreCmsGoodsCategoryServices.QueryListByClauseAsync(p => p.isShow == true, p => p.sort,
|
||||
OrderByType.Asc);
|
||||
jm.data = new
|
||||
{
|
||||
categories = GoodsHelper.GetTree(categories),
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建提交============================================================
|
||||
// POST: Api/CoreCmsGoodsCategory/DoCreate
|
||||
/// <summary>
|
||||
/// 创建提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建提交")]
|
||||
public async Task<AdminUiCallBack> DoCreate([FromBody] CoreCmsGoodsCategory entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var result = await _coreCmsGoodsCategoryServices.InsertAsync(entity);
|
||||
var bl = result.code == 0;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = (bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure);
|
||||
if (bl)
|
||||
{
|
||||
var categories = await _coreCmsGoodsCategoryServices.QueryListByClauseAsync(p => p.isShow == true, p => p.sort,
|
||||
OrderByType.Asc);
|
||||
jm.data = new
|
||||
{
|
||||
categories = GoodsHelper.GetTree(categories, false)
|
||||
};
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 编辑数据============================================================
|
||||
// POST: Api/CoreCmsGoodsCategory/GetEdit
|
||||
/// <summary>
|
||||
/// 编辑数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑数据")]
|
||||
public async Task<AdminUiCallBack> GetEdit([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsCategoryServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
jm.code = 0;
|
||||
|
||||
var categories = await _coreCmsGoodsCategoryServices.QueryListByClauseAsync(p => p.isShow == true, p => p.sort,
|
||||
OrderByType.Asc); ;
|
||||
jm.data = new
|
||||
{
|
||||
model,
|
||||
categories = GoodsHelper.GetTree(categories),
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 编辑提交============================================================
|
||||
// POST: Admins/CoreCmsGoodsCategory/Edit
|
||||
/// <summary>
|
||||
/// 编辑提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑提交")]
|
||||
public async Task<AdminUiCallBack> DoEdit([FromBody] CoreCmsGoodsCategory entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await _coreCmsGoodsCategoryServices.QueryByIdAsync(entity.id);
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (entity.id == entity.parentId)
|
||||
{
|
||||
jm.msg = "上级不能为本类";
|
||||
return jm;
|
||||
}
|
||||
|
||||
//事物处理过程开始
|
||||
oldModel.parentId = entity.parentId;
|
||||
oldModel.name = entity.name;
|
||||
oldModel.typeId = entity.typeId;
|
||||
oldModel.sort = entity.sort;
|
||||
oldModel.imageUrl = entity.imageUrl;
|
||||
oldModel.isShow = entity.isShow;
|
||||
oldModel.createTime = entity.createTime;
|
||||
|
||||
//事物处理过程结束
|
||||
var result = await _coreCmsGoodsCategoryServices.UpdateAsync(oldModel);
|
||||
var bl = result.code == 0;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除数据============================================================
|
||||
// POST: Api/CoreCmsGoodsCategory/DoDelete/10
|
||||
/// <summary>
|
||||
/// 单选删除
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("单选删除")]
|
||||
public async Task<AdminUiCallBack> DoDelete([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsCategoryServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (await _coreCmsGoodsCategoryServices.ExistsAsync(p => p.parentId == entity.id))
|
||||
{
|
||||
jm.msg = GlobalConstVars.DeleteIsHaveChildren;
|
||||
return jm;
|
||||
}
|
||||
|
||||
if (await _goodsServices.ExistsAsync(p => p.goodsCategoryId == entity.id && !p.isDel))
|
||||
{
|
||||
jm.msg = "有商品关联此栏目,禁止删除";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var result = await _coreCmsGoodsCategoryServices.DeleteByIdAsync(entity.id);
|
||||
var bl = result.code == 0;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
return jm;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 设置是否显示============================================================
|
||||
// POST: Api/CoreCmsGoodsCategory/DoSetisShow/10
|
||||
/// <summary>
|
||||
/// 设置是否显示
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("设置是否显示")]
|
||||
public async Task<AdminUiCallBack> DoSetisShow([FromBody] FMUpdateBoolDataByIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await _coreCmsGoodsCategoryServices.QueryByIdAsync(entity.id);
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
oldModel.isShow = (bool)entity.data;
|
||||
|
||||
var result = await _coreCmsGoodsCategoryServices.UpdateAsync(oldModel);
|
||||
var bl = result.code == 0;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
/***********************************************************************
|
||||
* 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.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品评价表
|
||||
///</summary>
|
||||
[Description("商品评价表")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[RequiredErrorForAdmin]
|
||||
[Authorize(Permissions.Name)]
|
||||
public class CoreCmsGoodsCommentController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly ICoreCmsGoodsCommentServices _coreCmsGoodsCommentServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
///</summary>
|
||||
public CoreCmsGoodsCommentController(IWebHostEnvironment webHostEnvironment
|
||||
, ICoreCmsGoodsCommentServices coreCmsGoodsCommentServices
|
||||
)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsGoodsCommentServices = coreCmsGoodsCommentServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
// POST: Api/CoreCmsGoodsComment/GetPageList
|
||||
/// <summary>
|
||||
/// 获取列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取列表")]
|
||||
public async Task<AdminUiCallBack> GetPageList()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
|
||||
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
|
||||
var where = PredicateBuilder.True<CoreCmsGoodsComment>();
|
||||
//获取排序字段
|
||||
var orderField = Request.Form["orderField"].FirstOrDefault();
|
||||
Expression<Func<CoreCmsGoodsComment, object>> orderEx;
|
||||
switch (orderField)
|
||||
{
|
||||
case "id":
|
||||
orderEx = p => p.id;
|
||||
break;
|
||||
case "commentId":
|
||||
orderEx = p => p.commentId;
|
||||
break;
|
||||
case "score":
|
||||
orderEx = p => p.score;
|
||||
break;
|
||||
case "userId":
|
||||
orderEx = p => p.userId;
|
||||
break;
|
||||
case "goodsId":
|
||||
orderEx = p => p.goodsId;
|
||||
break;
|
||||
case "orderId":
|
||||
orderEx = p => p.orderId;
|
||||
break;
|
||||
case "addon":
|
||||
orderEx = p => p.addon;
|
||||
break;
|
||||
case "images":
|
||||
orderEx = p => p.images;
|
||||
break;
|
||||
case "contentBody":
|
||||
orderEx = p => p.contentBody;
|
||||
break;
|
||||
case "sellerContent":
|
||||
orderEx = p => p.sellerContent;
|
||||
break;
|
||||
case "isDisplay":
|
||||
orderEx = p => p.isDisplay;
|
||||
break;
|
||||
case "createTime":
|
||||
orderEx = p => p.createTime;
|
||||
break;
|
||||
default:
|
||||
orderEx = p => p.id;
|
||||
break;
|
||||
}
|
||||
//设置排序方式
|
||||
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
|
||||
var orderBy = orderDirection switch
|
||||
{
|
||||
"asc" => OrderByType.Asc,
|
||||
"desc" => OrderByType.Desc,
|
||||
_ => OrderByType.Desc
|
||||
};
|
||||
//查询筛选
|
||||
|
||||
//序列 int
|
||||
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
|
||||
if (id > 0)
|
||||
{
|
||||
where = where.And(p => p.id == id);
|
||||
}
|
||||
//父级评价ID int
|
||||
var commentId = Request.Form["commentId"].FirstOrDefault().ObjectToInt(0);
|
||||
if (commentId > 0)
|
||||
{
|
||||
where = where.And(p => p.commentId == commentId);
|
||||
}
|
||||
//评价1-5星 int
|
||||
var score = Request.Form["score"].FirstOrDefault().ObjectToInt(0);
|
||||
if (score > 0)
|
||||
{
|
||||
where = where.And(p => p.score == score);
|
||||
}
|
||||
//评价用户ID int
|
||||
var userId = Request.Form["userId"].FirstOrDefault().ObjectToInt(0);
|
||||
if (userId > 0)
|
||||
{
|
||||
where = where.And(p => p.userId == userId);
|
||||
}
|
||||
//商品ID int
|
||||
var goodsId = Request.Form["goodsId"].FirstOrDefault().ObjectToInt(0);
|
||||
if (goodsId > 0)
|
||||
{
|
||||
where = where.And(p => p.goodsId == goodsId);
|
||||
}
|
||||
//评价订单ID nvarchar
|
||||
var orderId = Request.Form["orderId"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(orderId))
|
||||
{
|
||||
where = where.And(p => p.orderId.Contains(orderId));
|
||||
}
|
||||
//货品规格序列号存储 nvarchar
|
||||
var addon = Request.Form["addon"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(addon))
|
||||
{
|
||||
where = where.And(p => p.addon.Contains(addon));
|
||||
}
|
||||
//评价图片逗号分隔最多五张 nvarchar
|
||||
var images = Request.Form["images"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(images))
|
||||
{
|
||||
where = where.And(p => p.images.Contains(images));
|
||||
}
|
||||
//评价内容 nvarchar
|
||||
var contentBody = Request.Form["contentBody"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(contentBody))
|
||||
{
|
||||
where = where.And(p => p.contentBody.Contains(contentBody));
|
||||
}
|
||||
//商家回复 nvarchar
|
||||
var sellerContent = Request.Form["sellerContent"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(sellerContent))
|
||||
{
|
||||
where = where.And(p => p.sellerContent.Contains(sellerContent));
|
||||
}
|
||||
|
||||
|
||||
//用户昵称 nvarchar
|
||||
var nickName = Request.Form["nickName"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(nickName))
|
||||
{
|
||||
where = where.And(p => p.nickName.Contains(nickName));
|
||||
}
|
||||
//商品名称 nvarchar
|
||||
var goodName = Request.Form["goodName"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(goodName))
|
||||
{
|
||||
where = where.And(p => p.goodName.Contains(goodName));
|
||||
}
|
||||
|
||||
|
||||
//前台显示 bit
|
||||
var isDisplay = Request.Form["isDisplay"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(isDisplay) && isDisplay.ToLowerInvariant() == "true")
|
||||
{
|
||||
where = where.And(p => p.isDisplay == true);
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(isDisplay) && isDisplay.ToLowerInvariant() == "false")
|
||||
{
|
||||
where = where.And(p => p.isDisplay == false);
|
||||
}
|
||||
//创建时间 datetime
|
||||
var createTime = Request.Form["createTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(createTime))
|
||||
{
|
||||
if (createTime.Contains("到"))
|
||||
{
|
||||
var dts = createTime.Split("到");
|
||||
var dtStart = dts[0].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime > dtStart);
|
||||
var dtEnd = dts[1].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime < dtEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = createTime.ObjectToDate();
|
||||
where = where.And(p => p.createTime > dt);
|
||||
}
|
||||
}
|
||||
//获取数据
|
||||
var list = await _coreCmsGoodsCommentServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true);
|
||||
//返回数据
|
||||
jm.data = list;
|
||||
jm.code = 0;
|
||||
jm.count = list.TotalCount;
|
||||
jm.msg = "数据调用成功!";
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 首页数据============================================================
|
||||
// POST: Api/CoreCmsGoodsComment/GetIndex
|
||||
/// <summary>
|
||||
/// 首页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("首页数据")]
|
||||
public AdminUiCallBack GetIndex()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 编辑数据============================================================
|
||||
// POST: Api/CoreCmsGoodsComment/GetEdit
|
||||
/// <summary>
|
||||
/// 编辑数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑数据")]
|
||||
public async Task<AdminUiCallBack> GetEdit([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsCommentServices.DetailsByIdAsync(p => p.id == entity.id, p => p.id, OrderByType.Desc);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
jm.code = 0;
|
||||
jm.data = model;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 编辑提交============================================================
|
||||
// POST: Api/CoreCmsGoodsComment/Edit
|
||||
/// <summary>
|
||||
/// 编辑提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑提交")]
|
||||
public async Task<AdminUiCallBack> DoEdit([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = await _coreCmsGoodsCommentServices.Reply(entity.id, entity.data.ToString());
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 删除数据============================================================
|
||||
// POST: Api/CoreCmsGoodsComment/DoDelete/10
|
||||
/// <summary>
|
||||
/// 单选删除
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("单选删除")]
|
||||
public async Task<AdminUiCallBack> DoDelete([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsCommentServices.ExistsAsync(p => p.id == entity.id, true);
|
||||
if (!model)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
jm = await _coreCmsGoodsCommentServices.DeleteByIdAsync(entity.id);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 预览数据============================================================
|
||||
// POST: Api/CoreCmsGoodsComment/GetDetails/10
|
||||
/// <summary>
|
||||
/// 预览数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("预览数据")]
|
||||
public async Task<AdminUiCallBack> GetDetails([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsCommentServices.DetailsByIdAsync(p => p.id == entity.id, p => p.id, OrderByType.Desc);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
jm.code = 0;
|
||||
jm.data = model;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 设置前台显示============================================================
|
||||
// POST: Api/CoreCmsGoodsComment/DoSetisDisplay/10
|
||||
/// <summary>
|
||||
/// 设置前台显示
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("设置前台显示")]
|
||||
public async Task<AdminUiCallBack> DoSetisDisplay([FromBody] FMUpdateBoolDataByIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await _coreCmsGoodsCommentServices.QueryByIdAsync(entity.id, false);
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
oldModel.isDisplay = (bool)entity.data;
|
||||
|
||||
jm = await _coreCmsGoodsCommentServices.UpdateAsync(oldModel);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
1240
CoreCms.Net.Web.Admin/Controllers/Good/CoreCmsGoodsController.cs
Normal file
1240
CoreCms.Net.Web.Admin/Controllers/Good/CoreCmsGoodsController.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,540 @@
|
||||
/***********************************************************************
|
||||
* 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.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品参数表
|
||||
/// </summary>
|
||||
[Description("商品参数表")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[RequiredErrorForAdmin]
|
||||
[Authorize(Permissions.Name)]
|
||||
public class CoreCmsGoodsParamsController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsGoodsParamsServices _coreCmsGoodsParamsServices;
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CoreCmsGoodsParamsController(IWebHostEnvironment webHostEnvironment,
|
||||
ICoreCmsGoodsParamsServices coreCmsGoodsParamsServices)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsGoodsParamsServices = coreCmsGoodsParamsServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/GetPageList
|
||||
/// <summary>
|
||||
/// 获取列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取列表")]
|
||||
public async Task<AdminUiCallBack> GetPageList()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
|
||||
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
|
||||
var where = PredicateBuilder.True<CoreCmsGoodsParams>();
|
||||
//获取排序字段
|
||||
var orderField = Request.Form["orderField"].FirstOrDefault();
|
||||
Expression<Func<CoreCmsGoodsParams, object>> orderEx;
|
||||
switch (orderField)
|
||||
{
|
||||
case "id":
|
||||
orderEx = p => p.id;
|
||||
break;
|
||||
case "name":
|
||||
orderEx = p => p.name;
|
||||
break;
|
||||
case "value":
|
||||
orderEx = p => p.value;
|
||||
break;
|
||||
case "type":
|
||||
orderEx = p => p.type;
|
||||
break;
|
||||
case "createTime":
|
||||
orderEx = p => p.createTime;
|
||||
break;
|
||||
case "updateTime":
|
||||
orderEx = p => p.updateTime;
|
||||
break;
|
||||
default:
|
||||
orderEx = p => p.id;
|
||||
break;
|
||||
}
|
||||
|
||||
//设置排序方式
|
||||
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
|
||||
var orderBy = orderDirection switch
|
||||
{
|
||||
"asc" => OrderByType.Asc,
|
||||
"desc" => OrderByType.Desc,
|
||||
_ => OrderByType.Desc
|
||||
};
|
||||
//查询筛选
|
||||
|
||||
//序列 int
|
||||
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
|
||||
if (id > 0) @where = @where.And(p => p.id == id);
|
||||
//参数名称 nvarchar
|
||||
var name = Request.Form["name"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(name)) @where = @where.And(p => p.name.Contains(name));
|
||||
//参数值 nvarchar
|
||||
var value = Request.Form["value"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(value)) @where = @where.And(p => p.value.Contains(value));
|
||||
//参数类型 nvarchar
|
||||
var type = Request.Form["type"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(type)) @where = @where.And(p => p.type.Contains(type));
|
||||
//创建时间 datetime
|
||||
var createTime = Request.Form["createTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(createTime))
|
||||
{
|
||||
if (createTime.Contains("到"))
|
||||
{
|
||||
var dts = createTime.Split("到");
|
||||
var dtStart = dts[0].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime > dtStart);
|
||||
var dtEnd = dts[1].Trim().ObjectToDate();
|
||||
where = where.And(p => p.createTime < dtEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = createTime.ObjectToDate();
|
||||
where = where.And(p => p.createTime > dt);
|
||||
}
|
||||
}
|
||||
|
||||
//更新时间 datetime
|
||||
var updateTime = Request.Form["updateTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(updateTime))
|
||||
{
|
||||
if (updateTime.Contains("到"))
|
||||
{
|
||||
var dts = updateTime.Split("到");
|
||||
var dtStart = dts[0].Trim().ObjectToDate();
|
||||
where = where.And(p => p.updateTime > dtStart);
|
||||
var dtEnd = dts[1].Trim().ObjectToDate();
|
||||
where = where.And(p => p.updateTime < dtEnd);
|
||||
}
|
||||
else
|
||||
{
|
||||
var dt = updateTime.ObjectToDate();
|
||||
where = where.And(p => p.updateTime > dt);
|
||||
}
|
||||
}
|
||||
|
||||
//获取数据
|
||||
var list = await _coreCmsGoodsParamsServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent, pageSize);
|
||||
//返回数据
|
||||
jm.data = list;
|
||||
jm.code = 0;
|
||||
jm.count = list.TotalCount;
|
||||
jm.msg = "数据调用成功!";
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 首页数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/GetIndex
|
||||
/// <summary>
|
||||
/// 首页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("首页数据")]
|
||||
public AdminUiCallBack GetIndex()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
var goodsParamTypes = EnumHelper.EnumToList<GlobalEnumVars.GoodsParamTypes>();
|
||||
jm.data = new
|
||||
{
|
||||
goodsParamTypes
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 创建数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/GetCreate
|
||||
/// <summary>
|
||||
/// 创建数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建数据")]
|
||||
public AdminUiCallBack GetCreate()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
var goodsParamTypes = EnumHelper.EnumToList<GlobalEnumVars.GoodsParamTypes>();
|
||||
jm.data = new
|
||||
{
|
||||
goodsParamTypes
|
||||
};
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 创建提交============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/DoCreate
|
||||
/// <summary>
|
||||
/// 创建提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建提交")]
|
||||
public async Task<AdminUiCallBack> DoCreate([FromBody] CoreCmsGoodsParams entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
entity.createTime = DateTime.Now;
|
||||
var bl = await _coreCmsGoodsParamsServices.InsertAsync(entity) > 0;
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
|
||||
|
||||
if (bl)
|
||||
{
|
||||
//获取列表
|
||||
var paramsList = await _coreCmsGoodsParamsServices.QueryListByClauseAsync(p => p.id > 0, p => p.id, OrderByType.Desc, true);
|
||||
jm.data = new
|
||||
{
|
||||
paramsList
|
||||
};
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 编辑数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/GetEdit
|
||||
/// <summary>
|
||||
/// 编辑数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑数据")]
|
||||
public async Task<AdminUiCallBack> GetEdit([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsParamsServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
jm.code = 0;
|
||||
var goodsParamTypes = EnumHelper.EnumToList<GlobalEnumVars.GoodsParamTypes>();
|
||||
jm.data = new
|
||||
{
|
||||
model,
|
||||
goodsParamTypes
|
||||
};
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 编辑提交============================================================
|
||||
|
||||
// POST: Admins/CoreCmsGoodsParams/Edit
|
||||
/// <summary>
|
||||
/// 编辑提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑提交")]
|
||||
public async Task<AdminUiCallBack> DoEdit([FromBody] CoreCmsGoodsParams entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await _coreCmsGoodsParamsServices.QueryByIdAsync(entity.id);
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
//事物处理过程开始
|
||||
oldModel.name = entity.name;
|
||||
oldModel.value = entity.value;
|
||||
oldModel.type = entity.type;
|
||||
oldModel.updateTime = DateTime.Now;
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = await _coreCmsGoodsParamsServices.UpdateAsync(oldModel);
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/DoDelete/10
|
||||
/// <summary>
|
||||
/// 单选删除
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("单选删除")]
|
||||
public async Task<AdminUiCallBack> DoDelete([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsParamsServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
|
||||
var bl = await _coreCmsGoodsParamsServices.DeleteByIdAsync(entity.id);
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 预览数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/GetDetails/10
|
||||
/// <summary>
|
||||
/// 预览数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("预览数据")]
|
||||
public async Task<AdminUiCallBack> GetDetails([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsParamsServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
|
||||
jm.code = 0;
|
||||
jm.data = model;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 选择导出============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/SelectExportExcel/10
|
||||
/// <summary>
|
||||
/// 选择导出
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("选择导出")]
|
||||
public async Task<AdminUiCallBack> SelectExportExcel([FromBody] FMArrayIntIds entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
//创建Excel文件的对象
|
||||
var book = new HSSFWorkbook();
|
||||
//添加一个sheet
|
||||
var sheet1 = book.CreateSheet("Sheet1");
|
||||
//获取list数据
|
||||
var listmodel =
|
||||
await _coreCmsGoodsParamsServices.QueryListByClauseAsync(p => entity.id.Contains(p.id), p => p.id,
|
||||
OrderByType.Asc);
|
||||
//给sheet1添加第一行的头部标题
|
||||
var row1 = sheet1.CreateRow(0);
|
||||
row1.CreateCell(0).SetCellValue("序列");
|
||||
row1.CreateCell(1).SetCellValue("参数名称");
|
||||
row1.CreateCell(2).SetCellValue("参数值");
|
||||
row1.CreateCell(3).SetCellValue("参数类型");
|
||||
row1.CreateCell(4).SetCellValue("创建时间");
|
||||
row1.CreateCell(5).SetCellValue("更新时间");
|
||||
|
||||
//将数据逐步写入sheet1各个行
|
||||
for (var i = 0; i < listmodel.Count; i++)
|
||||
{
|
||||
var rowtemp = sheet1.CreateRow(i + 1);
|
||||
rowtemp.CreateCell(0).SetCellValue(listmodel[i].id.ToString());
|
||||
rowtemp.CreateCell(1).SetCellValue(listmodel[i].name);
|
||||
rowtemp.CreateCell(2).SetCellValue(listmodel[i].value);
|
||||
rowtemp.CreateCell(3).SetCellValue(listmodel[i].type);
|
||||
rowtemp.CreateCell(4).SetCellValue(listmodel[i].createTime.ToString());
|
||||
rowtemp.CreateCell(5).SetCellValue(listmodel[i].updateTime.ToString());
|
||||
}
|
||||
|
||||
// 导出excel
|
||||
var webRootPath = _webHostEnvironment.WebRootPath;
|
||||
var tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
|
||||
var fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-CoreCmsGoodsParams导出(选择结果).xls";
|
||||
var filePath = webRootPath + tpath;
|
||||
var di = new DirectoryInfo(filePath);
|
||||
if (!di.Exists) di.Create();
|
||||
var fileHssf = new FileStream(filePath + fileName, FileMode.Create);
|
||||
book.Write(fileHssf);
|
||||
fileHssf.Close();
|
||||
|
||||
jm.code = 0;
|
||||
jm.msg = GlobalConstVars.ExcelExportSuccess;
|
||||
jm.data = tpath + fileName;
|
||||
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 查询导出============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsParams/QueryExportExcel/10
|
||||
/// <summary>
|
||||
/// 查询导出
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("查询导出")]
|
||||
public async Task<AdminUiCallBack> QueryExportExcel()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var where = PredicateBuilder.True<CoreCmsGoodsParams>();
|
||||
//查询筛选
|
||||
|
||||
//序列 int
|
||||
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
|
||||
if (id > 0) @where = @where.And(p => p.id == id);
|
||||
//参数名称 nvarchar
|
||||
var name = Request.Form["name"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(name)) @where = @where.And(p => p.name.Contains(name));
|
||||
//参数值 nvarchar
|
||||
var value = Request.Form["value"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(value)) @where = @where.And(p => p.value.Contains(value));
|
||||
//参数类型 nvarchar
|
||||
var type = Request.Form["type"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(type)) @where = @where.And(p => p.type.Contains(type));
|
||||
//创建时间 datetime
|
||||
var createTime = Request.Form["createTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(createTime))
|
||||
{
|
||||
var dt = createTime.ObjectToDate();
|
||||
where = where.And(p => p.createTime > dt);
|
||||
}
|
||||
|
||||
//更新时间 datetime
|
||||
var updateTime = Request.Form["updateTime"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(updateTime))
|
||||
{
|
||||
var dt = updateTime.ObjectToDate();
|
||||
where = where.And(p => p.updateTime > dt);
|
||||
}
|
||||
|
||||
//获取数据
|
||||
//创建Excel文件的对象
|
||||
var book = new HSSFWorkbook();
|
||||
//添加一个sheet
|
||||
var sheet1 = book.CreateSheet("Sheet1");
|
||||
//获取list数据
|
||||
var listmodel =
|
||||
await _coreCmsGoodsParamsServices.QueryListByClauseAsync(where, p => p.id, OrderByType.Asc);
|
||||
//给sheet1添加第一行的头部标题
|
||||
var row1 = sheet1.CreateRow(0);
|
||||
row1.CreateCell(0).SetCellValue("序列");
|
||||
row1.CreateCell(1).SetCellValue("参数名称");
|
||||
row1.CreateCell(2).SetCellValue("参数值");
|
||||
row1.CreateCell(3).SetCellValue("参数类型");
|
||||
row1.CreateCell(4).SetCellValue("创建时间");
|
||||
row1.CreateCell(5).SetCellValue("更新时间");
|
||||
|
||||
//将数据逐步写入sheet1各个行
|
||||
for (var i = 0; i < listmodel.Count; i++)
|
||||
{
|
||||
var rowtemp = sheet1.CreateRow(i + 1);
|
||||
rowtemp.CreateCell(0).SetCellValue(listmodel[i].id.ToString());
|
||||
rowtemp.CreateCell(1).SetCellValue(listmodel[i].name);
|
||||
rowtemp.CreateCell(2).SetCellValue(listmodel[i].value);
|
||||
rowtemp.CreateCell(3).SetCellValue(listmodel[i].type);
|
||||
rowtemp.CreateCell(4).SetCellValue(listmodel[i].createTime.ToString());
|
||||
rowtemp.CreateCell(5).SetCellValue(listmodel[i].updateTime.ToString());
|
||||
}
|
||||
|
||||
// 写入到excel
|
||||
var webRootPath = _webHostEnvironment.WebRootPath;
|
||||
var tpath = "/files/" + DateTime.Now.ToString("yyyy-MM-dd") + "/";
|
||||
var fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "-CoreCmsGoodsParams导出(查询结果).xls";
|
||||
var filePath = webRootPath + tpath;
|
||||
var di = new DirectoryInfo(filePath);
|
||||
if (!di.Exists) di.Create();
|
||||
var fileHssf = new FileStream(filePath + fileName, FileMode.Create);
|
||||
book.Write(fileHssf);
|
||||
fileHssf.Close();
|
||||
|
||||
jm.code = 0;
|
||||
jm.msg = GlobalConstVars.ExcelExportSuccess;
|
||||
jm.data = tpath + fileName;
|
||||
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -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.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品类型属性表
|
||||
/// </summary>
|
||||
[Description("商品类型属性表")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[RequiredErrorForAdmin]
|
||||
[Authorize(Permissions.Name)]
|
||||
public class CoreCmsGoodsTypeSpecController : ControllerBase
|
||||
{
|
||||
private readonly ICoreCmsGoodsTypeSpecServices _coreCmsGoodsTypeSpecServices;
|
||||
private readonly ICoreCmsGoodsTypeSpecValueServices _valueServices;
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public CoreCmsGoodsTypeSpecController(IWebHostEnvironment webHostEnvironment
|
||||
, ICoreCmsGoodsTypeSpecServices coreCmsGoodsTypeSpecServices
|
||||
, ICoreCmsGoodsTypeSpecValueServices coreCmsGoodsTypeSpecValueServices)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsGoodsTypeSpecServices = coreCmsGoodsTypeSpecServices;
|
||||
_valueServices = coreCmsGoodsTypeSpecValueServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsTypeSpec/GetPageList
|
||||
/// <summary>
|
||||
/// 获取列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取列表")]
|
||||
public async Task<AdminUiCallBack> GetPageList()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
|
||||
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
|
||||
var where = PredicateBuilder.True<CoreCmsGoodsTypeSpec>();
|
||||
//获取排序字段
|
||||
var orderField = Request.Form["orderField"].FirstOrDefault();
|
||||
Expression<Func<CoreCmsGoodsTypeSpec, object>> orderEx;
|
||||
switch (orderField)
|
||||
{
|
||||
case "id":
|
||||
orderEx = p => p.id;
|
||||
break;
|
||||
case "name":
|
||||
orderEx = p => p.name;
|
||||
break;
|
||||
case "sort":
|
||||
orderEx = p => p.sort;
|
||||
break;
|
||||
default:
|
||||
orderEx = p => p.id;
|
||||
break;
|
||||
}
|
||||
|
||||
//设置排序方式
|
||||
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
|
||||
var orderBy = orderDirection switch
|
||||
{
|
||||
"asc" => OrderByType.Asc,
|
||||
"desc" => OrderByType.Desc,
|
||||
_ => OrderByType.Desc
|
||||
};
|
||||
//查询筛选
|
||||
|
||||
//序列 int
|
||||
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
|
||||
if (id > 0) @where = @where.And(p => p.id == id);
|
||||
//属性名称 nvarchar
|
||||
var name = Request.Form["name"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(name)) @where = @where.And(p => p.name.Contains(name));
|
||||
//属性排序 int
|
||||
var sort = Request.Form["sort"].FirstOrDefault().ObjectToInt(0);
|
||||
if (sort > 0) @where = @where.And(p => p.sort == sort);
|
||||
//获取数据
|
||||
var list = await _coreCmsGoodsTypeSpecServices.QueryPageAsync(where, orderEx, orderBy, pageCurrent,
|
||||
pageSize);
|
||||
|
||||
if (list != null && list.Any())
|
||||
{
|
||||
var ids = list.Select(p => p.id).ToList();
|
||||
if (ids.Any())
|
||||
{
|
||||
var values = await _valueServices.QueryListByClauseAsync(p => ids.Contains(p.specId));
|
||||
foreach (var item in list)
|
||||
item.specValues = values.Where(p => p.specId == item.id).OrderBy(p => p.sort).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
//返回数据
|
||||
jm.data = list;
|
||||
jm.code = 0;
|
||||
jm.count = list.TotalCount;
|
||||
jm.msg = "数据调用成功!";
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 首页数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsTypeSpec/GetIndex
|
||||
/// <summary>
|
||||
/// 首页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("首页数据")]
|
||||
public AdminUiCallBack GetIndex()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 创建数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsTypeSpec/GetCreate
|
||||
/// <summary>
|
||||
/// 创建数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建数据")]
|
||||
public AdminUiCallBack GetCreate()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 创建提交============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsTypeSpec/DoCreate
|
||||
/// <summary>
|
||||
/// 创建提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("创建提交")]
|
||||
public async Task<AdminUiCallBack> DoCreate([FromBody] FmGoodsTypeSpecInsert entity)
|
||||
{
|
||||
var jm = await _coreCmsGoodsTypeSpecServices.InsertAsync(entity);
|
||||
|
||||
if (jm.code == 0)
|
||||
{
|
||||
//获取SKU列表
|
||||
var skuList = await _coreCmsGoodsTypeSpecServices.QueryListByClauseAsync(p => p.id > 0, p => p.id, OrderByType.Desc, true);
|
||||
jm.data = new
|
||||
{
|
||||
skuList
|
||||
};
|
||||
|
||||
}
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 编辑数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsTypeSpec/GetEdit
|
||||
/// <summary>
|
||||
/// 编辑数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑数据")]
|
||||
public async Task<AdminUiCallBack> GetEdit([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var model = await _coreCmsGoodsTypeSpecServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var values =
|
||||
await _valueServices.QueryListByClauseAsync(p => p.specId == model.id, p => p.sort,
|
||||
OrderByType.Asc);
|
||||
model.specValues = values;
|
||||
jm.code = 0;
|
||||
jm.data = model;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 编辑提交============================================================
|
||||
|
||||
// POST: Admins/CoreCmsGoodsTypeSpec/Edit
|
||||
/// <summary>
|
||||
/// 编辑提交
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("编辑提交")]
|
||||
public async Task<AdminUiCallBack> DoEdit([FromBody] FmGoodsTypeSpecUpdate entity)
|
||||
{
|
||||
var jm = await _coreCmsGoodsTypeSpecServices.UpdateAsync(entity);
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 删除数据============================================================
|
||||
|
||||
// POST: Api/CoreCmsGoodsTypeSpec/DoDelete/10
|
||||
/// <summary>
|
||||
/// 单选删除
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("单选删除")]
|
||||
public async Task<AdminUiCallBack> DoDelete([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsGoodsTypeSpecServices.QueryByIdAsync(entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
jm = await _coreCmsGoodsTypeSpecServices.DeleteByIdAsync(entity.id);
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/***********************************************************************
|
||||
* 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.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.Entities.Expression;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Filter;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Web.Admin.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 货品表
|
||||
///</summary>
|
||||
[Description("货品表")]
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[RequiredErrorForAdmin]
|
||||
[Authorize(Permissions.Name)]
|
||||
public class CoreCmsProductsController : ControllerBase
|
||||
{
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly ICoreCmsProductsServices _coreCmsProductsServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
///</summary>
|
||||
public CoreCmsProductsController(IWebHostEnvironment webHostEnvironment
|
||||
, ICoreCmsProductsServices coreCmsProductsServices
|
||||
)
|
||||
{
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_coreCmsProductsServices = coreCmsProductsServices;
|
||||
}
|
||||
|
||||
#region 获取列表============================================================
|
||||
// POST: Api/CoreCmsProducts/GetPageList
|
||||
/// <summary>
|
||||
/// 获取列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("获取列表")]
|
||||
public async Task<AdminUiCallBack> GetPageList()
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
|
||||
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
|
||||
var where = PredicateBuilder.True<CoreCmsProducts>();
|
||||
where = where.And(p => p.isDel == false);
|
||||
|
||||
|
||||
//获取排序字段
|
||||
var orderField = Request.Form["orderField"].FirstOrDefault();
|
||||
|
||||
Expression<Func<CoreCmsProducts, object>> orderEx = orderField switch
|
||||
{
|
||||
"id" => p => p.id,
|
||||
"goodsId" => p => p.goodsId,
|
||||
"barcode" => p => p.barcode,
|
||||
"sn" => p => p.sn,
|
||||
"price" => p => p.price,
|
||||
"costprice" => p => p.costprice,
|
||||
"mktprice" => p => p.mktprice,
|
||||
"marketable" => p => p.marketable,
|
||||
"weight" => p => p.weight,
|
||||
"stock" => p => p.stock,
|
||||
"freezeStock" => p => p.freezeStock,
|
||||
"spesDesc" => p => p.spesDesc,
|
||||
"isDefalut" => p => p.isDefalut,
|
||||
"images" => p => p.images,
|
||||
"isDel" => p => p.isDel,
|
||||
_ => p => p.id
|
||||
};
|
||||
|
||||
//设置排序方式
|
||||
var orderDirection = Request.Form["orderDirection"].FirstOrDefault();
|
||||
var orderBy = orderDirection switch
|
||||
{
|
||||
"asc" => OrderByType.Asc,
|
||||
"desc" => OrderByType.Desc,
|
||||
_ => OrderByType.Desc
|
||||
};
|
||||
//查询筛选
|
||||
|
||||
|
||||
//货品条码 nvarchar
|
||||
var barcode = Request.Form["barcode"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(barcode))
|
||||
{
|
||||
where = where.And(p => p.barcode.Contains(barcode));
|
||||
}
|
||||
//商品编码 nvarchar
|
||||
var sn = Request.Form["sn"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(sn))
|
||||
{
|
||||
where = where.And(p => p.sn.Contains(sn));
|
||||
}
|
||||
//规格值 nvarchar
|
||||
var spesDesc = Request.Form["spesDesc"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(spesDesc))
|
||||
{
|
||||
where = where.And(p => p.spesDesc.Contains(spesDesc));
|
||||
}
|
||||
//规格值 nvarchar
|
||||
var name = Request.Form["name"].FirstOrDefault();
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
where = where.And(p => p.name.Contains(name));
|
||||
}
|
||||
|
||||
//获取数据
|
||||
var list = await _coreCmsProductsServices.QueryDetailPageAsync(where, orderEx, orderBy, pageCurrent, pageSize, true);
|
||||
//返回数据
|
||||
jm.data = list;
|
||||
jm.code = 0;
|
||||
jm.count = list.TotalCount;
|
||||
jm.msg = "数据调用成功!";
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 首页数据============================================================
|
||||
// POST: Api/CoreCmsProducts/GetIndex
|
||||
/// <summary>
|
||||
/// 首页数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("首页数据")]
|
||||
public AdminUiCallBack GetIndex()
|
||||
{
|
||||
//返回数据
|
||||
var jm = new AdminUiCallBack { code = 0 };
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 预览数据============================================================
|
||||
// POST: Api/CoreCmsProducts/GetDetails/10
|
||||
/// <summary>
|
||||
/// 预览数据
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("预览数据")]
|
||||
public async Task<AdminUiCallBack> GetDetails([FromBody] FMIntId entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await _coreCmsProductsServices.QueryByClauseAsync(p => p.id == entity.id);
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
jm.code = 0;
|
||||
jm.data = model;
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 设置库存============================================================
|
||||
// POST: Api/CoreCmsProducts/DoSetStock/10
|
||||
/// <summary>
|
||||
/// 设置库存
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Description("设置库存")]
|
||||
public async Task<AdminUiCallBack> DoSetStock([FromBody] FMUpdateIntegerDataByIntId entity)
|
||||
{
|
||||
var jm = await _coreCmsProductsServices.EditStock(entity.id, entity.data);
|
||||
|
||||
return jm;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user