/***********************************************************************
* Project: baifenBinfa
* ProjectName: 百分兵法管理系统
* Web: http://chuanyin.com
* Author:
* Email:
* CreateTime: 202403/02
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Aliyun.OSS;
using Aliyun.OSS.Util;
using CoreCms.Net.Auth.HttpContextUser;
using CoreCms.Net.Caching.AccressToken;
using CoreCms.Net.Configuration;
using CoreCms.Net.Filter;
using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.Entities.Expression;
using CoreCms.Net.Model.FromBody;
using CoreCms.Net.Model.ViewModels.DTO;
using CoreCms.Net.Model.ViewModels.Echarts;
using CoreCms.Net.Model.ViewModels.UI;
using CoreCms.Net.Utility.Extensions;
using CoreCms.Net.Utility.Helper;
using CoreCms.Net.WeChat.Service.HttpClients;
using COSXML;
using COSXML.Auth;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using SKIT.FlurlHttpClient.Wechat.Api;
using SKIT.FlurlHttpClient.Wechat.Api.Models;
using SqlSugar;
namespace CoreCms.Net.Web.Admin.Controllers
{
///
/// 后端常用方法
///
[Description("后端常用方法")]
[Route("api/[controller]/[action]")]
[ApiController]
[Authorize]
public class ToolsController : ControllerBase
{
private readonly ICoreCmsAreaServices _areaServices;
private readonly ICoreCmsArticleServices _coreCmsArticleServices;
private readonly ICoreCmsArticleTypeServices _coreCmsArticleTypeServices;
private readonly ICoreCmsFormServices _coreCmsFormServices;
private readonly ICoreCmsGoodsServices _coreCmsGoodsServices;
private readonly ICoreCmsNoticeServices _coreCmsNoticeServices;
private readonly ICoreCmsPinTuanRuleServices _coreCmsPinTuanRuleServices;
private readonly ICoreCmsPromotionServices _coreCmsPromotionServices;
private readonly ICoreCmsSettingServices _coreCmsSettingServices;
private readonly ICoreCmsLogisticsServices _logisticsServices;
private readonly ISysMenuServices _sysMenuServices;
private readonly ISysOrganizationServices _sysOrganizationServices;
private readonly ISysRoleServices _sysRoleServices;
private readonly ISysUserRoleServices _sysUserRoleServices;
private readonly ISysRoleMenuServices _sysRoleMenuServices;
private readonly ISysUserServices _sysUserServices;
private readonly IHttpContextUser _user;
private readonly IWebHostEnvironment _webHostEnvironment;
private readonly ISysLoginRecordServices _sysLoginRecordServices;
private readonly ISysNLogRecordsServices _sysNLogRecordsServices;
private readonly ICoreCmsBillPaymentsServices _paymentsServices;
private readonly ICoreCmsBillDeliveryServices _billDeliveryServices;
private readonly ICoreCmsBillAftersalesServices _aftersalesServices;
private readonly ICoreCmsUserServices _userServices;
private readonly ICoreCmsOrderServices _orderServices;
private readonly ICoreCmsSettingServices _settingServices;
private readonly ICoreCmsProductsServices _productsServices;
private readonly ICoreCmsServicesServices _servicesServices;
private readonly ICoreCmsPagesServices _pagesServices;
private readonly IToolsServices _toolsServices;
private readonly ICoreCmsReportsServices _reportsServices;
private readonly ICoreCmsGoodsCategoryServices _goodsCategoryServices;
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
private readonly SemaphoreSlim _semaphore;
private readonly ICoreCmsPlanOrderServices _coreCmsPlanOrderServices;
///
/// 构造函数
///
public ToolsController(
IHttpContextUser user
, IWebHostEnvironment webHostEnvironment
, ICoreCmsGoodsServices coreCmsGoodsServices
, ICoreCmsSettingServices coreCmsSettingServices
, ICoreCmsArticleServices coreCmsArticleServices
, ICoreCmsFormServices coreCmsFormServices
, ICoreCmsArticleTypeServices coreCmsArticleTypeServices
, ICoreCmsNoticeServices coreCmsNoticeServices
, ICoreCmsPinTuanRuleServices coreCmsPinTuanRuleServices
, ICoreCmsPromotionServices coreCmsPromotionServices
, ICoreCmsAreaServices areaServices
, ISysUserServices sysUserServices
, ISysRoleServices sysRoleServices
, ISysMenuServices sysMenuServices
, ISysUserRoleServices sysUserRoleServices
, ISysOrganizationServices sysOrganizationServices,
ICoreCmsLogisticsServices logisticsServices, ISysLoginRecordServices sysLoginRecordServices, ISysNLogRecordsServices sysNLogRecordsServices, ICoreCmsBillPaymentsServices paymentsServices, ICoreCmsBillDeliveryServices billDeliveryServices, ICoreCmsUserServices userServices, ICoreCmsOrderServices orderServices, ICoreCmsBillAftersalesServices aftersalesServices, ICoreCmsSettingServices settingServices, ICoreCmsProductsServices productsServices, ICoreCmsServicesServices servicesServices, ISysRoleMenuServices sysRoleMenuServices
, IWeChatApiHttpClientFactory weChatApiHttpClientFactory, ICoreCmsPagesServices pagesServices, IToolsServices toolsServices, ICoreCmsReportsServices reportsServices, ICoreCmsGoodsCategoryServices goodsCategoryServices
, ICoreCmsPlanOrderServices coreCmsPlanOrderServices )
{
_user = user;
_webHostEnvironment = webHostEnvironment;
_coreCmsGoodsServices = coreCmsGoodsServices;
_coreCmsSettingServices = coreCmsSettingServices;
_coreCmsArticleServices = coreCmsArticleServices;
_coreCmsFormServices = coreCmsFormServices;
_coreCmsArticleTypeServices = coreCmsArticleTypeServices;
_coreCmsNoticeServices = coreCmsNoticeServices;
_coreCmsPinTuanRuleServices = coreCmsPinTuanRuleServices;
_coreCmsPromotionServices = coreCmsPromotionServices;
_areaServices = areaServices;
_sysUserServices = sysUserServices;
_sysRoleServices = sysRoleServices;
_sysMenuServices = sysMenuServices;
_sysUserRoleServices = sysUserRoleServices;
_sysOrganizationServices = sysOrganizationServices;
_logisticsServices = logisticsServices;
_sysLoginRecordServices = sysLoginRecordServices;
_sysNLogRecordsServices = sysNLogRecordsServices;
_paymentsServices = paymentsServices;
_billDeliveryServices = billDeliveryServices;
_userServices = userServices;
_orderServices = orderServices;
_aftersalesServices = aftersalesServices;
_settingServices = settingServices;
_productsServices = productsServices;
_servicesServices = servicesServices;
_sysRoleMenuServices = sysRoleMenuServices;
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
_pagesServices = pagesServices;
_toolsServices = toolsServices;
_reportsServices = reportsServices;
_goodsCategoryServices = goodsCategoryServices;
_coreCmsPlanOrderServices = coreCmsPlanOrderServices;
//最多允许2个线程同时访问;
_semaphore = new SemaphoreSlim(2);
}
#region 获取登录用户用户信息(用于面板展示)====================================================
///
/// 获取登录用户用户信息(用于面板展示)
///
///
[HttpPost]
public async Task GetUserInfo()
{
var jm = new AdminUiCallBack();
var userModel = await _sysUserServices.QueryByIdAsync(_user.ID);
jm.code = userModel == null ? 401 : 0;
jm.msg = userModel == null ? "注销登录" : "数据获取正常";
jm.data = userModel == null ? null : new
{
userModel.userName,
userModel.nickName,
userModel.createTime
};
return jm;
}
#endregion
#region 获取登录用户用户全部信息(用于编辑个人信息)====================================================
///
/// 获取登录用户用户全部信息(用于编辑个人信息)
///
///
[HttpPost]
public async Task GetEditUserInfo()
{
var jm = new AdminUiCallBack();
var userModel = await _sysUserServices.QueryByIdAsync(_user.ID);
if (userModel != null)
{
var roles = await _sysUserRoleServices.QueryListByClauseAsync(p => p.userId == userModel.id);
if (roles.Any())
{
var roleIds = roles.Select(p => p.roleId).ToList();
userModel.roles = await _sysRoleServices.QueryListByClauseAsync(p => roleIds.Contains(p.id));
}
if (userModel.organizationId != null && userModel.organizationId > 0)
{
var organization = await _sysOrganizationServices.QueryByIdAsync(userModel.organizationId);
if (organization != null) userModel.organizationName = organization.organizationName;
}
}
jm.code = 0;
jm.msg = "数据获取正常";
jm.data = userModel;
return jm;
}
#endregion
#region 获取角色列表信息====================================================
///
/// 获取角色列表信息
///
///
[HttpPost]
public async Task GetManagerRoles()
{
var jm = new AdminUiCallBack();
var roles = await _sysRoleServices.QueryAsync();
jm.code = 0;
jm.msg = "数据获取正常";
jm.data = roles.Select(p => new { title = p.roleName, value = p.id });
return jm;
}
#endregion
#region 用户编辑个人登录账户密码====================================================
///
/// 获取登录用户用户信息
///
///
[HttpPost]
public async Task EditLoginUserPassWord([FromBody] FMEditLoginUserPassWord entity)
{
var jm = new AdminUiCallBack();
if (string.IsNullOrEmpty(entity.oldPassword))
{
jm.msg = "请键入旧密码";
return jm;
}
if (string.IsNullOrEmpty(entity.password))
{
jm.msg = "请键入新密码";
return jm;
}
if (string.IsNullOrEmpty(entity.repassword))
{
jm.msg = "请键入新密码确认密码";
return jm;
}
if (entity.password != entity.repassword)
{
jm.msg = "新密码与确认密码不相符";
return jm;
}
if (entity.password == entity.oldPassword)
{
jm.msg = "请设置与旧密码不同的新密码";
return jm;
}
var oldPassWord = CommonHelper.Md5For32(entity.oldPassword);
var newPassWord = CommonHelper.Md5For32(entity.password);
var userModel = await _sysUserServices.QueryByIdAsync(_user.ID);
if (userModel.passWord.ToUpperInvariant() != oldPassWord)
{
jm.msg = "旧密码输入错误";
return jm;
}
else if (userModel.passWord.ToUpperInvariant() == newPassWord)
{
jm.msg = "新旧密码一致,无需修改,请设置与旧密码不同的新密码";
return jm;
}
userModel.passWord = newPassWord;
var bl = await _sysUserServices.UpdateAsync(userModel);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "修改成功" : "修改失败";
return jm;
}
#endregion
#region 用户编辑个人非安全隐私数据====================================================
///
/// 用户编辑个人非安全隐私数据
///
///
[HttpPost]
public async Task EditLoginUserInfo([FromBody] EditLoginUserInfo entity)
{
var jm = new AdminUiCallBack();
if (entity.trueName.Length > 4)
{
jm.msg = "用户真实姓名不能大于4个字符。";
return jm;
}
var userModel = await _sysUserServices.QueryByIdAsync(_user.ID);
if (!string.IsNullOrEmpty(entity.nickName)) userModel.nickName = entity.nickName;
if (!string.IsNullOrEmpty(entity.avatar)) userModel.avatar = entity.avatar;
if (entity.sex > 0) userModel.sex = entity.sex;
if (!string.IsNullOrEmpty(entity.phone)) userModel.phone = entity.phone;
if (!string.IsNullOrEmpty(entity.email)) userModel.email = entity.email;
if (!string.IsNullOrEmpty(entity.introduction)) userModel.introduction = entity.introduction;
if (!string.IsNullOrEmpty(entity.trueName)) userModel.trueName = entity.trueName;
if (!string.IsNullOrEmpty(entity.idCard)) userModel.idCard = entity.idCard;
if (entity.birthday != null) userModel.birthday = entity.birthday;
userModel.updateTime = DateTime.Now;
var bl = await _sysUserServices.UpdateAsync(userModel);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "修改成功" : "修改失败";
return jm;
}
#endregion
#region 反射获取后端Api的controller和action
///
/// 反射获取后端Api的controller和action
///
///
[HttpPost]
public AdminUiCallBack GetAllControllerAndActionByAssembly()
{
var jm = new AdminUiCallBack();
var data = AdminsControllerPermission.GetCacheCoreCmsControllerPermission(GlobalEnumVars.CoreShopSystemCategory.Admin.ToString());
jm.data = data.OrderBy(u => u.name).ToList();
jm.code = 0;
jm.msg = "获取成功";
return jm;
}
#endregion
//通用操作=========================================================================
#region 计划订单上传接口====================================================
///
/// 计划订单上传接口
///
///
[Authorize]
[HttpPost]
public async Task UploadFilesXls()
{
var jm = new AdminUiCallBack();
await _semaphore.WaitAsync();
try
{
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
//初始化上传参数
var maxSize = 1024 * 1024 * filesStorageOptions.MaxSize; //上传大小5M
var file = Request.Form.Files["file"];
if (file == null)
{
jm.msg = "请选择文件";
return jm;
}
var fileName = file.FileName;
var fileExt = Path.GetExtension(fileName).ToLowerInvariant();
//检查大小
if (file.Length > maxSize)
{
jm.msg = "上传文件大小超过限制,最大允许上传" + filesStorageOptions.MaxSize + "M";
return jm;
}
//检查文件扩展名
if (string.IsNullOrEmpty(fileExt) ||
Array.IndexOf(filesStorageOptions.FileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
{
jm.msg = "上传文件扩展名是不允许的扩展名,请上传后缀名为:" + filesStorageOptions.FileTypes;
return jm;
}
var lie = new List();
using (var fileStream = file.OpenReadStream())
{
// 使用HSSFWorkbook打开.xls格式的文件
IWorkbook workbook = new XSSFWorkbook(fileStream);
// 获取第一个工作表
ISheet sheet = workbook.GetSheetAt(0);
// 迭代工作表中的所有行
for (int i = 1; i <= sheet.LastRowNum; i++)
{
var hang = new JiHuaOrder();
IRow row = sheet.GetRow(i);
if (row == null) continue; // 跳过空行
ICell cell1 = row.GetCell(1);
if (cell1 == null)
{
jm.msg ="第" +(i+1) + "学校不能为空";
return jm;
}
hang.shipAddress = getcellvalue(cell1);
ICell cell2 = row.GetCell(2);
if (cell2 == null)
{
jm.msg = "第" + (i + 1) + "联系人不能为空";
return jm;
}
hang.shipName = getcellvalue(cell2);
ICell cell3 = row.GetCell(3);
if (cell3 == null)
{
jm.msg = "第" + (i + 1) + "联系电话不能为空";
return jm;
}
hang.shipMobile = getcellvalue(cell3);
ICell cell4 = row.GetCell(4);
if (cell4 == null)
{
jm.msg = "第" + (i + 1) + "商品名称不能为空";
return jm;
}
hang.name = getcellvalue(cell4);
ICell cell5 = row.GetCell(5);
if (cell5 == null)
{
jm.msg = "第" + (i + 1) + "规格不能为空";
return jm;
}
hang.specification = getcellvalue(cell5);
ICell cell6 = row.GetCell(6);
if (cell6 == null)
{
jm.msg = "第" + (i + 1) + "单价(元)不能为空";
return jm;
}
hang.price = decimal.Parse(getcellvalue(cell6));
ICell cell7 = row.GetCell(7);
if (cell7 == null)
{
jm.msg = "第" + (i + 1) + "数量不能为空";
return jm;
}
hang.nums = int.Parse(getcellvalue(cell7)); ;
lie.Add(hang);
}
}
lie = lie.OrderBy(x => x.shipAddress).ThenBy(x => x.specification).ToList();
string url = string.Empty;
url = "121212";
if (lie!=null && lie.Count > 0)
{
var order = new List();
for(int i=0;i< lie.Count; i++)
{
if (i == 0 )
{
order.Add(lie[i]);
//if(lie.Count == 1)
//{
// //保存订单
// jm = await _coreCmsPlanOrderServices.ToAddJiHua(lie,_user.ID, _user.Name);
// if (jm.code == 1)
// {
// return jm;
// }
//}
}
else
{
if(lie[i].shipAddress == lie[i - 1].shipAddress)
{
order.Add(lie[i]);
}
else
{
//保存订单
jm = await _coreCmsPlanOrderServices.ToAddJiHua(lie, _user.ID, _user.Name);
if (jm.code == 1)
{
return jm;
}
order = new List();
order.Add(lie[i]);
}
}
if (i == lie.Count - 1)
{
//保存订单
jm = await _coreCmsPlanOrderServices.ToAddJiHua(lie, _user.ID, _user.Name);
if (jm.code == 1)
{
return jm;
}
}
}
}
else
{
jm.code =1;
jm.msg = "表格无数据";
jm.data = new
{
fileUrl = url,
src = url
};
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url
};
}
catch (Exception e)
{
jm.code = 1;
jm.msg = "数据异常";
jm.data = e;
}
finally
{
_semaphore.Release(); // 释放访问
}
return jm;
}
///
/// 计划订单上传接口
///
///
public string getcellvalue(ICell cell)
{
string cellvalue = "";
switch (cell.CellType)
{
case CellType.String:
// Console.WriteLine(cell.StringCellValue);
cellvalue = cell.StringCellValue.Trim();
break;
case CellType.Numeric:
//Console.WriteLine(cell.NumericCellValue);
cellvalue = cell.NumericCellValue.ToString().Trim();
break;
case CellType.Boolean:
//Console.WriteLine(cell.BooleanCellValue);
cellvalue = cell.BooleanCellValue.ToString().Trim();
break;
case CellType.Error:
// Console.WriteLine(cell.ErrorCellValue);
cellvalue = cell.ErrorCellValue.ToString().Trim();
break;
// 可以添加其他类型的case
}
return cellvalue;
}
#endregion
#region 通用上传接口====================================================
///
/// 通用上传接口
///
///
[HttpPost]
public async Task UploadFiles()
{
var jm = new AdminUiCallBack();
await _semaphore.WaitAsync();
try
{
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
//初始化上传参数
var maxSize = 1024 * 1024 * filesStorageOptions.MaxSize; //上传大小5M
var file = Request.Form.Files["file"];
if (file == null)
{
jm.msg = "请选择文件";
return jm;
}
var fileName = file.FileName;
var fileExt = Path.GetExtension(fileName).ToLowerInvariant();
//检查大小
if (file.Length > maxSize)
{
jm.msg = "上传文件大小超过限制,最大允许上传" + filesStorageOptions.MaxSize + "M";
return jm;
}
//检查文件扩展名
if (string.IsNullOrEmpty(fileExt) ||
Array.IndexOf(filesStorageOptions.FileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
{
jm.msg = "上传文件扩展名是不允许的扩展名,请上传后缀名为:" + filesStorageOptions.FileTypes;
return jm;
}
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = await _toolsServices.UpLoadFileForLocalStorage(filesStorageOptions, fileExt, file);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
url = await _toolsServices.UpLoadFileForAliYunOSS(filesStorageOptions, fileExt, file);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
url = await _toolsServices.UpLoadFileForQCloudOSS(filesStorageOptions, fileExt, file);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
url = await _toolsServices.UpLoadFileForQiNiuKoDo(filesStorageOptions, fileExt, file);
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url
};
}
catch (Exception e)
{
jm.code = 1;
jm.msg = "数据异常";
jm.data = e;
}
finally
{
_semaphore.Release(); // 释放访问
}
return jm;
}
#endregion
#region 裁剪Base64上传====================================================
///
/// 裁剪Base64上传
///
///
[HttpPost]
public async Task UploadFilesFByBase64([FromBody] FMBase64Post entity)
{
var jm = new AdminUiCallBack();
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
if (string.IsNullOrEmpty(entity.base64))
{
jm.msg = "请上传合法内容";
return jm;
}
//检查上传大小
if (!CommonHelper.CheckBase64Size(entity.base64, filesStorageOptions.MaxSize))
{
jm.msg = "上传文件大小超过限制,最大允许上传" + filesStorageOptions.MaxSize + "M";
return jm;
}
entity.base64 = entity.base64.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "").Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", "");//将base64头部信息替换
byte[] bytes = Convert.FromBase64String(entity.base64);
MemoryStream memStream = new MemoryStream(bytes);
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = _toolsServices.UpLoadBase64ForLocalStorage(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
//上传到阿里云
url = await _toolsServices.UpLoadBase64ForAliYunOSS(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
//上传到腾讯云OSS
url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, bytes);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
//上传到七牛云kodo
url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, bytes);
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url
};
return jm;
}
#endregion
#region CKEditor编辑上传接口====================================================
///
/// CKEditor编辑上传接口
///
///
[HttpPost]
public async Task CkEditorUploadFiles()
{
var jm = new CKEditorUploadedResult();
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
//初始化上传参数
var maxSize = 1024 * 1024 * filesStorageOptions.MaxSize; //上传大小5M
var file = Request.Form.Files["upload"];
if (file == null)
{
jm.error.message = "请选择文件";
return jm;
}
var fileName = file.FileName;
var fileExt = Path.GetExtension(fileName).ToLowerInvariant();
//检查大小
if (file.Length > maxSize)
{
jm.error.message = "上传文件大小超过限制,最大允许上传" + filesStorageOptions.MaxSize + "M";
return jm;
}
//检查文件扩展名
if (string.IsNullOrEmpty(fileExt) || Array.IndexOf(filesStorageOptions.FileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
{
jm.error.message = "上传文件扩展名是不允许的扩展名,请上传后缀名为:" + filesStorageOptions.FileTypes;
return jm;
}
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = await _toolsServices.UpLoadFileForLocalStorage(filesStorageOptions, fileExt, file);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
//上传到阿里云
url = await _toolsServices.UpLoadFileForAliYunOSS(filesStorageOptions, fileExt, file);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
url = await _toolsServices.UpLoadFileForQCloudOSS(filesStorageOptions, fileExt, file);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
url = await _toolsServices.UpLoadFileForQiNiuKoDo(filesStorageOptions, fileExt, file);
}
jm.uploaded = !string.IsNullOrEmpty(url) ? 1 : 0;
jm.fileName = fileName;
jm.url = url;
return jm;
}
#endregion
#region 根据id获取商品信息====================================================
// POST: Api/Tools/GetGoodsByIds
///
/// 根据id获取商品信息
///
///
[HttpPost]
[Description("根据id获取商品信息")]
public async Task GetGoodsByIds([FromBody] FMArrayIntIds entity)
{
var jm = new AdminUiCallBack();
var list = await _coreCmsGoodsServices.QueryByIDsAsync(entity.id);
jm.code = 0;
jm.data = list;
return jm;
}
#endregion
#region 后台生成小程序码============================================================
// POST: Api/CoreCmsForm/GetCreate
///
/// 后台生成小程序码
///
///
[HttpPost]
[Description("后台生成小程序码")]
public async Task GetFormWxCode([FromBody] FMIntId entity)
{
//返回数据
var jm = new AdminUiCallBack { code = 0 };
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
var formModel = await _coreCmsFormServices.QueryByIdAsync(entity.id);
if (formModel == null)
{
jm.code = 1;
jm.msg = "不存在此信息";
return jm;
}
var path = "pages/form/details/details?id=" + entity.id;
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var request = new CgibinWxaappCreateWxaQrcodeRequest();
request.AccessToken = accessToken;
request.Path = path;
var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request);
if (response.IsSuccessful())
{
var memStream = new MemoryStream(response.RawBytes);
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = _toolsServices.UpLoadBase64ForLocalStorage(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
//上传到阿里云
url = await _toolsServices.UpLoadBase64ForAliYunOSS(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
//上传到腾讯云OSS
url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
//上传到七牛云kodo
url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes);
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url
};
}
else
{
jm.code = 1;
jm.msg = response.ErrorMessage;
}
jm.otherData = response;
return jm;
}
#endregion
#region 后台生成商品小程序码============================================================
// POST: Api/CoreCmsGoods/GetCreate
///
/// 后台生成商品小程序码
///
///
[HttpPost]
[Description("后台生成商品小程序码")]
public async Task GetGoodWxCode([FromBody] FMIntId entity)
{
//返回数据
var jm = new AdminUiCallBack { code = 0 };
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
var goodModel = await _coreCmsGoodsServices.QueryByIdAsync(entity.id);
if (goodModel == null)
{
jm.code = 1;
jm.msg = "不存在此信息";
return jm;
}
var path = "pages/goods/goodDetails/goodDetails?id=" + entity.id;
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var request = new CgibinWxaappCreateWxaQrcodeRequest();
request.AccessToken = accessToken;
request.Path = path;
var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request);
if (response.IsSuccessful())
{
var memStream = new MemoryStream(response.RawBytes);
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = _toolsServices.UpLoadBase64ForLocalStorage(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
//上传到阿里云
url = await _toolsServices.UpLoadBase64ForAliYunOSS(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
//上传到腾讯云OSS
url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
//上传到七牛云kodo
url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes);
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url
};
}
else
{
jm.code = 1;
jm.msg = response.ErrorMessage;
}
jm.otherData = response;
return jm;
}
#endregion
#region 后台生成预览页面设计小程序码============================================================
// POST: Api/Tools/GetPageWxCode
///
/// 后台生成预览页面设计小程序码
///
///
[HttpPost]
[Description("后台生成小程序码")]
public async Task GetPageWxCode([FromBody] FMStringId entity)
{
//返回数据
var jm = new AdminUiCallBack { code = 0 };
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
var pageModel = await _pagesServices.QueryByClauseAsync(p => p.code == entity.id);
if (pageModel == null)
{
jm.code = 1;
jm.msg = "不存在此信息";
return jm;
}
var path = "pages/index/custom/custom?pageCode=" + entity.id;
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var request = new CgibinWxaappCreateWxaQrcodeRequest();
request.AccessToken = accessToken;
request.Path = path;
var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request);
if (response.IsSuccessful())
{
var memStream = new MemoryStream(response.RawBytes);
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = _toolsServices.UpLoadBase64ForLocalStorage(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
//上传到阿里云
url = await _toolsServices.UpLoadBase64ForAliYunOSS(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
//上传到腾讯云OSS
url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
//上传到七牛云kodo
url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes);
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url
};
}
else
{
jm.code = 1;
jm.msg = response.ErrorMessage;
}
jm.otherData = response;
return jm;
}
#endregion
#region 后台生成代理商小程序码============================================================
// POST: Api/Tools/GetAgentWxCode
///
/// 后台生成代理商小程序码
///
///
[HttpPost]
[Description("后台生成小程序码")]
public async Task GetAgentWxCode([FromBody] FMIntId entity)
{
//返回数据
var jm = new AdminUiCallBack { code = 0 };
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
var userModel = await _userServices.QueryByIdAsync(entity.id);
if (userModel == null)
{
jm.code = 1;
jm.msg = "不存在此信息";
return jm;
}
var userCode = UserHelper.GetShareCodeByUserId(entity.id);
var path = "pages/share/jump/jump?scene=11-" + userCode + "-" + userCode;
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var request = new CgibinWxaappCreateWxaQrcodeRequest();
request.AccessToken = accessToken;
request.Path = path;
var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request);
if (response.IsSuccessful())
{
var memStream = new MemoryStream(response.RawBytes);
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = _toolsServices.UpLoadBase64ForLocalStorage(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
//上传到阿里云
url = await _toolsServices.UpLoadBase64ForAliYunOSS(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
//上传到腾讯云OSS
url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
//上传到七牛云kodo
url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes);
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url,
path
};
}
else
{
jm.code = 1;
jm.msg = response.ErrorMessage;
}
jm.otherData = response;
return jm;
}
#endregion
#region 后台生成经销商小程序码============================================================
// POST: Api/Tools/GetDistributionWxCode
///
/// 后台生成经销商小程序码
///
///
[HttpPost]
[Description("后台生成小程序码")]
public async Task GetDistributionWxCode([FromBody] FMIntId entity)
{
//返回数据
var jm = new AdminUiCallBack { code = 0 };
var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
var userModel = await _userServices.QueryByIdAsync(entity.id);
if (userModel == null)
{
jm.code = 1;
jm.msg = "不存在此信息";
return jm;
}
var userCode = UserHelper.GetShareCodeByUserId(entity.id);
var path = "pages/share/jump/jump?scene=4-" + userCode + "-" + userCode;
var accessToken = WeChatCacheAccessTokenHelper.GetWxOpenAccessToken();
var client = _weChatApiHttpClientFactory.CreateWxOpenClient();
var request = new CgibinWxaappCreateWxaQrcodeRequest();
request.AccessToken = accessToken;
request.Path = path;
var response = await client.ExecuteCgibinWxaappCreateWxaQrcodeAsync(request);
if (response.IsSuccessful())
{
var memStream = new MemoryStream(response.RawBytes);
string url = string.Empty;
if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.LocalStorage.ToString())
{
url = _toolsServices.UpLoadBase64ForLocalStorage(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.AliYunOSS.ToString())
{
//上传到阿里云
url = await _toolsServices.UpLoadBase64ForAliYunOSS(filesStorageOptions, memStream);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QCloudOSS.ToString())
{
//上传到腾讯云OSS
url = _toolsServices.UpLoadBase64ForQCloudOSS(filesStorageOptions, response.RawBytes);
}
else if (filesStorageOptions.StorageType == GlobalEnumVars.FilesStorageOptionsType.QiNiuKoDo.ToString())
{
//上传到七牛云kodo
url = _toolsServices.UpLoadBase64ForQiNiuKoDo(filesStorageOptions, response.RawBytes);
}
var bl = !string.IsNullOrEmpty(url);
jm.code = bl ? 0 : 1;
jm.msg = bl ? "上传成功!" : "上传失败";
jm.data = new
{
fileUrl = url,
src = url
};
}
else
{
jm.code = 1;
jm.msg = response.ErrorMessage;
}
jm.otherData = response;
return jm;
}
#endregion
//通用页面获取=========================================================================
#region 获取商品列表====================================================
// POST: Api/Tools/GetGoods
///
/// 获取商品列表
///
///
[HttpPost]
[Description("获取商品列表")]
public async Task GetGoods()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
where = where.And(p => p.isMarketable);
//商品编码 nvarchar
var bn = Request.Form["bn"].FirstOrDefault();
if (!string.IsNullOrEmpty(bn)) where = where.And(p => p.bn.Contains(bn));
//商品名称 nvarchar
var name = Request.Form["name"].FirstOrDefault();
if (!string.IsNullOrEmpty(name)) where = where.And(p => p.name.Contains(name));
where = where.And(p => p.isDel == false);
//获取数据
var list = await _coreCmsGoodsServices.QueryPageAsync(where, p => p.createTime, OrderByType.Desc,
pageCurrent, pageSize);
//返回数据
var newObj = list.Select(p => new
{
p.id,
p.image,
p.images,
p.price,
p.name,
p.stock
}).ToList();
jm.data = newObj;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取商品列表====================================================
// POST: Api/Tools/GetGoods
///
/// 获取商品列表
///
///
[HttpPost]
[Description("获取商品列表")]
public async Task GetGoodAndSku()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
where = where.And(p => p.isMarketable);
//商品编码 nvarchar
var bn = Request.Form["bn"].FirstOrDefault();
if (!string.IsNullOrEmpty(bn)) where = where.And(p => p.bn.Contains(bn));
//商品名称 nvarchar
var name = Request.Form["name"].FirstOrDefault();
if (!string.IsNullOrEmpty(name)) where = where.And(p => p.name.Contains(name));
where = where.And(p => p.isDel == false);
//获取数据
var list = await _coreCmsGoodsServices.QueryGoodAndSkuPageAsync(where, p => p.createTime, OrderByType.Desc,
pageCurrent, pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 根据商品序列获取货品数据====================================================
// POST: Api/Tools/GetProducts
///
/// 根据商品序列获取货品数据
///
///
[HttpPost]
[Description("获取商品列表")]
public async Task GetProducts(FMIntId entity)
{
var jm = new AdminUiCallBack();
var list = await _productsServices.GetProducts(entity.id);
jm.code = 0;
jm.data = list;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取关联商品的货品列表数据====================================================
// POST: Api/Tools/GetProductsDetailPageAsync
///
/// 获取关联商品的货品列表数据
///
///
[HttpPost]
[Description("获取关联商品的货品列表数据")]
public async Task GetProductsPages()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
//商品名称 nvarchar
var name = Request.Form["name"].FirstOrDefault();
if (!string.IsNullOrEmpty(name))
{
where = where.And(p => p.name.Contains(name));
}
where = where.And(o => o.isDel == false && o.isMarketable == true);
var list = await _productsServices.QueryDetailPageAsync(where, p => p.goodsId, OrderByType.Desc, pageCurrent, pageSize);
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取文章列表============================================================
// POST: Api/Tools/GetArticles
///
/// 获取文章列表
///
///
[HttpPost]
[Description("获取文章列表")]
public async Task GetArticles()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
//标题 nvarchar
var title = Request.Form["title"].FirstOrDefault();
if (!string.IsNullOrEmpty(title)) where = where.And(p => p.title.Contains(title));
//获取数据
var list = await _coreCmsArticleServices.QueryPageAsync(where, p => p.id, OrderByType.Asc, pageCurrent, pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取智能表单列表============================================================
// POST: Api/Tools/GetForms
///
/// 获取智能表单列表
///
///
[HttpPost]
[Description("获取智能表单列表")]
public async Task GetForms()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
//表单名称 nvarchar
var name = Request.Form["name"].FirstOrDefault();
if (!string.IsNullOrEmpty(name)) where = where.And(p => p.name.Contains(name));
//获取数据
var list = await _coreCmsFormServices.QueryPageAsync(where, p => p.id, OrderByType.Desc, pageCurrent,
pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取文章分类列表============================================================
// POST: Api/Tools/GetArticleTypes
///
/// 获取文章分类列表
///
///
[HttpPost]
[Description("获取文章分类列表")]
public async Task GetArticleTypes()
{
var jm = new AdminUiCallBack();
//获取数据
var list = await _coreCmsArticleTypeServices.QueryAsync();
//返回数据
jm.data = list;
jm.code = 0;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取商品分类列表============================================================
// POST: Api/Tools/GetGoodTypes
///
/// 获取商品分类列表
///
///
[HttpPost]
[Description("获取商品分类列表")]
public async Task GetGoodTypes()
{
var jm = new AdminUiCallBack();
//获取数据
var list = await _goodsCategoryServices.QueryListByClauseAsync(p => p.id > 0, p => p.sort, OrderByType.Asc, true, true);
//返回数据
jm.data = GoodsHelper.GetTree(list, false).data;
jm.code = 0;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取公告列表============================================================
// POST: Api/Tools/GetNotices
///
/// 获取公告列表
///
///
[HttpPost]
[Description("获取公告列表")]
public async Task GetNotices()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
//公告标题 nvarchar
var title = Request.Form["title"].FirstOrDefault();
if (!string.IsNullOrEmpty(title)) where = where.And(p => p.title.Contains(title));
//获取数据
var list = await _coreCmsNoticeServices.QueryPageAsync(where, p => p.id, OrderByType.Desc, pageCurrent,
pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 供tag标签选择拼团商品的时候使用============================================================
// POST: Api/Tools/GetPingTuans
///
/// 供tag标签选择拼团商品的时候使用
///
///
[HttpPost]
[Description("获取列表")]
public async Task TagPinTuan()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
var dt = DateTime.Now;
where = where.And(p => p.isStatusOpen == true && p.startTime < dt && p.endTime > dt);
//活动名称 nvarchar
var name = Request.Form["name"].FirstOrDefault();
if (!string.IsNullOrEmpty(name)) where = where.And(p => p.name.Contains(name));
//获取数据
var list = await _coreCmsPinTuanRuleServices.QueryTagPinTuanPageAsync(where, p => p.id, OrderByType.Desc, pageCurrent, pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 供tag标签选择合法团购秒杀的时候使用============================================================
// POST: Api/Tools/TagPromotions
///
/// 供tag标签选择合法团购秒杀的时候使用
///
///
[HttpPost]
[Description("供tag标签选择合法团购秒杀的时候使用")]
public async Task TagPromotions()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var id = Request.Form["id"].FirstOrDefault().ObjectToInt(0);
var where = PredicateBuilder.True();
var dt = DateTime.Now;
where = where.And(p => p.isEnable == true && p.isDel == false && p.startTime < dt && p.endTime > dt && p.type == id);
//促销名称 nvarchar
var name = Request.Form["name"].FirstOrDefault();
if (!string.IsNullOrEmpty(name)) where = where.And(p => p.name.Contains(name));
where = where.And(p => p.isDel == false);
//获取数据
var list = await _coreCmsPromotionServices.QueryPageAsync(where, p => p.id, OrderByType.Desc, pageCurrent,
pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 供tag标签选择服务卡的时候使用============================================================
// POST: Api/Tools/TagServices
///
/// 供tag标签选择服务卡的时候使用
///
///
[HttpPost]
[Description("获取列表")]
public async Task TagServices()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var dt = DateTime.Now;
var where = PredicateBuilder.True();
where = where.And(p => p.status == (int)GlobalEnumVars.ServicesStatus.Shelve);
where = where.And(p => p.amount > 0);
where = where.And(p => p.startTime < dt && p.endTime > dt);
//服务名称 nvarchar
var title = Request.Form["title"].FirstOrDefault();
if (!string.IsNullOrEmpty(title)) where = where.And(p => p.title.Contains(title));
//获取数据
var list = await _servicesServices.TagQueryPageAsync(where, p => p.createTime, OrderByType.Desc, pageCurrent, pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取促销列表============================================================
// POST: Api/Tools/GetPromotions
///
/// 获取促销列表
///
///
[HttpPost]
[Description("获取促销列表")]
public async Task GetPromotions()
{
var jm = new AdminUiCallBack();
var pageCurrent = Request.Form["page"].FirstOrDefault().ObjectToInt(1);
var pageSize = Request.Form["limit"].FirstOrDefault().ObjectToInt(30);
var where = PredicateBuilder.True();
//序列 int
var types = Request.Form["types"].FirstOrDefault().ObjectToInt(0);
if (types == 1)
where = where.And(p => p.type == 1);
else if (types == 2)
where = where.And(p => p.type == 2);
else if (types == 3) where = where.And(p => p.type == 3 || p.type == 4);
//促销名称 nvarchar
var name = Request.Form["name"].FirstOrDefault();
if (!string.IsNullOrEmpty(name)) where = where.And(p => p.name.Contains(name));
where = where.And(p => p.isDel == false);
//获取数据
var list = await _coreCmsPromotionServices.QueryPageAsync(where, p => p.id, OrderByType.Desc, pageCurrent,
pageSize);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取区域信息=======================================================
///
/// 获取区域信息
///
///
[HttpPost]
public async Task GetArea()
{
var jm = new WebApiCallBack();
var ischecked = Request.Form["ischecked"].FirstOrDefault().ObjectToInt(0);
var nodeId = Request.Form["nodeId"].FirstOrDefault().ObjectToInt(0);
var idsStr = Request.Form["ids"].FirstOrDefault();
var ids = new List();
if (!string.IsNullOrEmpty(idsStr)) ids = JsonConvert.DeserializeObject>(idsStr);
var areaTrees = await _areaServices.GetTreeArea(ids, nodeId, ischecked);
jm.status = true;
jm.data = areaTrees;
jm.msg = ids.Count.ToString();
return jm;
}
#endregion
#region 物流查询接口=======================================================
///
/// 物流查询接口
///
///
[HttpPost]
public async Task LogisticsByApi([FromBody] FMApiLogisticsByApiPost entity)
{
var jm = new WebApiCallBack();
if (string.IsNullOrEmpty(entity.code) || string.IsNullOrEmpty(entity.no))
{
jm.code = 1;
jm.msg = GlobalErrorCodeVars.Code13225;
return jm;
}
var systemLogistics = SystemSettingDictionary.GetSystemLogistics();
foreach (var p in systemLogistics)
{
if (entity.code == p.sKey)
{
jm.msg = p.sDescription + "不支持轨迹查询";
return jm;
}
}
jm = await _logisticsServices.ExpressPoll(entity.code, entity.no, entity.mobile);
return jm;
}
#endregion
//用户相关=========================================================================
#region 根据用户权限获取对应左侧菜单列表====================================================
///
/// 根据用户权限获取对应左侧菜单列表
///
///
[HttpPost]
public async Task GetNavs()
{
var jm = new AdminUiCallBack();
//先获取用户关联角色
var roles = await _sysUserRoleServices.QueryListByClauseAsync(p => p.userId == _user.ID);
if (roles.Any())
{
var roleIds = roles.Select(p => p.roleId).ToList();
var sysRoleMenu = await _sysRoleMenuServices.QueryListByClauseAsync(p => roleIds.Contains(p.roleId));
var menuIds = sysRoleMenu.Select(p => p.menuId).ToList();
var navs = await _sysMenuServices.QueryListByClauseAsync(p => menuIds.Contains(p.id) && p.deleted == false && p.hide == false && p.menuType == 0, p => p.sortNumber, OrderByType.Asc);
var menus = GetMenus(navs, 0);
jm.data = menus;
}
jm.msg = "数据获取正常";
jm.code = 0;
return jm;
}
///
/// 迭代方法
///
///
///
///
private static List GetMenus(List oldNavs, int parentId)
{
var childTree = new List();
if (parentId == 0)
{
var topMenu = new AdminUiMenu { title = "主页", icon = "layui-icon-home", name = "HomePanel" };
var list = new List
{
new AdminUiMenu
{title = "控制台", jump = "/", name = "controllerPanel", list = new List()}
};
topMenu.list = list;
childTree.Add(topMenu);
}
var model = oldNavs.Where(p => p.parentId == parentId).ToList();
foreach (var item in model)
{
var menu = new AdminUiMenu
{
name = item.identificationCode,
title = item.menuName,
icon = item.menuIcon,
jump = !string.IsNullOrEmpty(item.path) ? item.path : null
};
childTree.Add(menu);
menu.list = GetMenus(oldNavs, item.id);
}
return childTree;
}
#endregion
#region 后台Select三级下拉联动配合
///
/// 获取大类列表
///
///
[HttpPost]
public async Task> GetAreaCheckedList([FromBody] FMIntId entity)
{
var res = new List();
if (entity.id != 0)
{
var model3 = new AreasDtoForAdminEdit();
model3.info = await _areaServices.QueryByIdAsync(entity.id);
if (model3.info != null && model3.info.parentId != 0)
{
model3.list = await _areaServices.QueryListByClauseAsync(p => p.parentId == model3.info.parentId);
var model2 = new AreasDtoForAdminEdit();
model2.info = await _areaServices.QueryByIdAsync(model3.info.parentId);
if (model2.info != null && model2.info.parentId != 0)
{
model2.list =
await _areaServices.QueryListByClauseAsync(p => p.parentId == model2.info.parentId);
var model = new AreasDtoForAdminEdit();
model.info = await _areaServices.QueryByIdAsync(model2.info.parentId);
if (model.info != null)
model.list =
await _areaServices.QueryListByClauseAsync(p => p.parentId == model.info.parentId);
res.Add(model);
}
else
{
//修改不可以任意选择层级的bug
model2.thisList = await _areaServices.QueryListByClauseAsync(p => p.parentId == 0);
}
res.Add(model2);
}
else
if(model3.info!=null&&model3.info.parentId==0)
{
//修改不可以任意选择层级的bug
model3.thisList = await _areaServices.QueryListByClauseAsync(p => p.parentId == 0);
}
res.Add(model3);
}
else
{
//修改不可以任意选择层级的bug
var model4 = new AreasDtoForAdminEdit();
model4.list = await _areaServices.QueryListByClauseAsync(p => p.parentId == 0);
model4.info = null;
res.Add(model4);
}
return res;
}
///
/// 取地区的下级列表
///
///
[HttpPost]
public async Task> GetAreaChildren([FromBody] FMIntId entity)
{
var list = await _areaServices.QueryListByClauseAsync(p => p.parentId == entity.id);
return list;
}
#endregion
//后端首页使用数据
#region 获取最近登录日志============================================================
// POST: Api/Tools/GetSysLoginRecord
///
/// 获取最近登录日志
///
///
[HttpPost]
[Description("获取最近登录日志")]
public async Task GetSysLoginRecord()
{
var jm = new AdminUiCallBack();
//获取数据
var list = await _sysLoginRecordServices.QueryPageAsync(p => p.id > 0, p => p.createTime, OrderByType.Desc, 1, 10);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取全局Nlog日志============================================================
// POST: Api/Tools/GetSysNLogRecords
///
/// 获取全局Nlog日志
///
///
[HttpPost]
[Description("获取全局Nlog日志")]
public async Task GetSysNLogRecords()
{
var jm = new AdminUiCallBack();
//获取数据
var list = await _sysNLogRecordsServices.QueryPageAsync(p => p.id > 0, p => p.id, OrderByType.Desc, 1, 10);
//返回数据
jm.data = list;
jm.code = 0;
jm.count = list.TotalCount;
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取7天订单情况数据统计============================================================
// POST: Api/Tools/GetOrdersStatistics
///
/// 获取7天订单情况数据统计
///
///
[HttpPost]
[Description("获取7天订单情况数据统计")]
public Task GetOrdersStatistics()
{
var jm = new AdminUiCallBack();
var dtEnd = DateTime.Now;
var dtStart = dtEnd.AddDays(-7);
var dtStr = dtStart.ToString("yyyy-MM-dd") + " 到 " + dtEnd.ToString("yyyy-MM-dd");
var dataRes = ReportsHelper.GetDate(dtStr, 2);
if (!dataRes.status)
{
jm.msg = dataRes.msg;
return System.Threading.Tasks.Task.FromResult(jm);
}
var echartsOption = new EchartsOption();
echartsOption.title.text = "最近7天订单统计";
var legend = new List() { "全部", "待付款", "已付款" };
echartsOption.legend.data = legend;
var getDate = dataRes.data as ReportsBackForGetDate;
var xData = ReportsHelper.GetXdata(getDate);
if (!xData.status)
{
jm.msg = dataRes.msg;
return System.Threading.Tasks.Task.FromResult(jm);
}
echartsOption.xAxis.data = xData.data as List;
var whereSql = string.Empty;
var data = new List();
var data1 = new List();
var data2 = new List();
var data3 = new List();
foreach (var item in legend)
{
switch (item)
{
case "全部":
whereSql = string.Empty;
whereSql += " and createTime > '" + getDate.start.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
whereSql += " and createTime < '" + getDate.end.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
data = _reportsServices.GetOrderMark(getDate.num, whereSql, getDate.section, getDate.start, "createTime");
data1 = data;
break;
case "待付款":
whereSql = string.Empty;
whereSql += " and createTime > '" + getDate.start.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
whereSql += " and createTime < '" + getDate.end.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
whereSql += " and payStatus=1 ";
data = _reportsServices.GetOrderMark(getDate.num, whereSql, getDate.section, getDate.start, "createTime");
data2 = data;
break;
case "已付款":
whereSql = string.Empty;
whereSql += " and paymentTime > '" + getDate.start.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
whereSql += " and paymentTime < '" + getDate.end.ToString("yyyy-MM-dd HH:mm:ss") + "' ";
whereSql += " and payStatus>1 ";
data = _reportsServices.GetOrderMark(getDate.num, whereSql, getDate.section, getDate.start, "paymentTime");
data3 = data;
break;
}
if (data != null && data.Any())
{
var vals = data.Select(p => p.val).ToList();
echartsOption.series.Add(new SeriesItem()
{
name = item,
type = "line",
data = vals.ConvertAll(x => x.ToString(CultureInfo.InvariantCulture))
});
}
else
{
echartsOption.series.Add(new SeriesItem()
{
name = item,
type = "line",
data = new List()
});
}
}
//组装数据列表用于table里使用
var tableData = new List();
for (int i = 0; i < getDate.num; i++)
{
var item = new OrderTableItem();
if (echartsOption.xAxis.data != null) item.x = echartsOption.xAxis.data[i];
item.order_all_val = data1[i].val.ToString(CultureInfo.InvariantCulture);
item.order_all_num = data1[i].num;
item.order_nopay_val = data2[i].val.ToString(CultureInfo.InvariantCulture);
item.order_nopay_num = data2[i].num;
item.order_payed_val = data3[i].val.ToString(CultureInfo.InvariantCulture);
item.order_payed_num = data3[i].num;
tableData.Add(item);
}
jm.code = 0;
jm.data = new
{
option = echartsOption,
table = tableData
};
return System.Threading.Tasks.Task.FromResult(jm);
}
#endregion
#region 获取用户最新统计数据============================================================
// POST: Api/Tools/GetUsersStatistics
///
/// 获取用户最新统计数据
///
///
[HttpPost]
[Description("获取用户最新统计数据")]
public async Task GetUsersStatistics()
{
var jm = new AdminUiCallBack();
var data = new List() { "新增记录", "活跃记录" };
var legend = new Legend();
legend.data = data;
var regs = await _userServices.Statistics(7);
var orders = await _userServices.StatisticsOrder(7);
var xAxis = new List();
var xItem = new XAxis();
xItem.type = "category";
xItem.data = orders.Select(p => p.day).ToList();
for (int i = 0; i < xItem.data.Count; i++)
{
xItem.data[i] = Convert.ToDateTime(xItem.data[i]).ToString("d日");
}
xAxis.Add(xItem);
var series = new List
{
new() {name = "新增记录", type = "line", data = regs.Select(p => p.nums).ToList()},
new() {name = "活跃记录", type = "line", data = orders.Select(p => p.nums).ToList()}
};
jm.code = 0;
jm.data = new
{
legend,
xAxis,
series
};
//返回数据
jm.msg = "数据调用成功!";
return jm;
}
#endregion
#region 获取代办事宜数据============================================================
// POST: Api/Tools/GetBackLog
///
/// 获取代办事宜数据
///
///
[HttpPost]
[Description("获取用户最新统计数据")]
public async Task GetBackLog()
{
var jm = new AdminUiCallBack();
//待支付
var paymentWhere = _orderServices.GetReverseStatus((int)GlobalEnumVars.OrderAllStatusType.ALL_PENDING_PAYMENT);
var unpaidCount = await _orderServices.GetCountAsync(paymentWhere);
//待发货
var deliveredWhere = _orderServices.GetReverseStatus((int)GlobalEnumVars.OrderAllStatusType.ALL_PENDING_DELIVERY);
var unshipCount = await _orderServices.GetCountAsync(deliveredWhere);
//待售后
var aftersalesCount = await _aftersalesServices.GetCountAsync(p => p.status == (int)GlobalEnumVars.BillAftersalesStatus.WaitAudit);
var allConfigs = await _settingServices.GetConfigDictionaries();
var goodsStocksWarn = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.GoodsStocksWarn).ObjectToInt(10);
//库存报警
var goodsStaticsTotalWarn = await _productsServices.GoodsStaticsTotalWarn(goodsStocksWarn);
//返回数据
jm.code = 0;
jm.msg = "数据调用成功!";
jm.data = new
{
unpaidCount,
unshipCount,
aftersalesCount,
goodsStaticsTotalWarn
};
return jm;
}
#endregion
}
}