mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 16:23:26 +08:00
添加项目文件。
This commit is contained in:
18
CoreCms.Net.Utility/CoreCms.Net.Utility.csproj
Normal file
18
CoreCms.Net.Utility/CoreCms.Net.Utility.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="NPOI" Version="2.4.1" />
|
||||
<PackageReference Include="ToolGood.Words" Version="3.0.2.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CoreCms.Net.Configuration\CoreCms.Net.Configuration.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
217
CoreCms.Net.Utility/Extensions/ConvertObject.cs
Normal file
217
CoreCms.Net.Utility/Extensions/ConvertObject.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CoreCms.Net.Utility.Extensions
|
||||
{
|
||||
public class ConvertObjectExtensions
|
||||
{
|
||||
|
||||
#region Method1
|
||||
|
||||
/// <summary>
|
||||
/// 将object对象转换为实体对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体对象类名</typeparam>
|
||||
/// <param name="asObject">object对象</param>
|
||||
/// <returns></returns>
|
||||
private T ConvertObject<T>(object asObject) where T : new()
|
||||
{
|
||||
//创建实体对象实例
|
||||
var t = Activator.CreateInstance<T>();
|
||||
if (asObject != null)
|
||||
{
|
||||
Type type = asObject.GetType();
|
||||
//遍历实体对象属性
|
||||
foreach (var info in typeof(T).GetProperties())
|
||||
{
|
||||
object obj = null;
|
||||
//取得object对象中此属性的值
|
||||
var val = type.GetProperty(info.Name)?.GetValue(asObject);
|
||||
if (val != null)
|
||||
{
|
||||
//非泛型
|
||||
if (!info.PropertyType.IsGenericType)
|
||||
obj = Convert.ChangeType(val, info.PropertyType);
|
||||
else//泛型Nullable<>
|
||||
{
|
||||
Type genericTypeDefinition = info.PropertyType.GetGenericTypeDefinition();
|
||||
if (genericTypeDefinition == typeof(Nullable<>))
|
||||
{
|
||||
obj = Convert.ChangeType(val, Nullable.GetUnderlyingType(info.PropertyType));
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = Convert.ChangeType(val, info.PropertyType);
|
||||
}
|
||||
}
|
||||
info.SetValue(t, obj, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Method2
|
||||
|
||||
/// <summary>
|
||||
/// 将object对象转换为实体对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T">实体对象类名</typeparam>
|
||||
/// <param name="asObject">object对象</param>
|
||||
/// <returns></returns>
|
||||
public static T ConvertObjectByJson<T>(object asObject) where T : new()
|
||||
{
|
||||
//将object对象转换为json字符
|
||||
var json = JsonConvert.SerializeObject(asObject);
|
||||
//将json字符转换为实体对象
|
||||
var t = JsonConvert.DeserializeObject<T>(json);
|
||||
return t;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Method3
|
||||
/// <summary>
|
||||
/// 将object尝试转为指定对象
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public static T ConvertObjToModel<T>(object data) where T : new()
|
||||
{
|
||||
if (data == null) return new T();
|
||||
// 定义集合
|
||||
T result = new T();
|
||||
|
||||
// 获得此模型的类型
|
||||
Type type = typeof(T);
|
||||
string tempName = "";
|
||||
|
||||
// 获得此模型的公共属性
|
||||
PropertyInfo[] propertys = result.GetType().GetProperties();
|
||||
foreach (PropertyInfo pi in propertys)
|
||||
{
|
||||
tempName = pi.Name; // 检查object是否包含此列
|
||||
|
||||
// 判断此属性是否有Setter
|
||||
if (!pi.CanWrite) continue;
|
||||
|
||||
try
|
||||
{
|
||||
object value = GetPropertyValue(data, tempName);
|
||||
if (value != DBNull.Value)
|
||||
{
|
||||
Type tempType = pi.PropertyType;
|
||||
pi.SetValue(result, GetDataByType(value, tempType), null);
|
||||
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一个类指定的属性值
|
||||
/// </summary>
|
||||
/// <param name="info">object对象</param>
|
||||
/// <param name="field">属性名称</param>
|
||||
/// <returns></returns>
|
||||
public static object GetPropertyValue(object info, string field)
|
||||
{
|
||||
if (info == null) return null;
|
||||
Type t = info.GetType();
|
||||
IEnumerable<System.Reflection.PropertyInfo> property = from pi in t.GetProperties() where pi.Name.ToLower() == field.ToLower() select pi;
|
||||
return property.First().GetValue(info, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数据转为制定类型
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="data1"></param>
|
||||
/// <returns></returns>
|
||||
public static object GetDataByType(object data1, Type itype, params object[] myparams)
|
||||
{
|
||||
object result = new object();
|
||||
try
|
||||
{
|
||||
if (itype == typeof(decimal))
|
||||
{
|
||||
result = Convert.ToDecimal(data1);
|
||||
if (myparams.Length > 0)
|
||||
{
|
||||
result = Convert.ToDecimal(Math.Round(Convert.ToDecimal(data1), Convert.ToInt32(myparams[0])));
|
||||
}
|
||||
}
|
||||
else if (itype == typeof(double))
|
||||
{
|
||||
|
||||
if (myparams.Length > 0)
|
||||
{
|
||||
result = Convert.ToDouble(Math.Round(Convert.ToDouble(data1), Convert.ToInt32(myparams[0])));
|
||||
}
|
||||
else
|
||||
{
|
||||
result = double.Parse(Convert.ToDecimal(data1).ToString("0.00"));
|
||||
}
|
||||
}
|
||||
else if (itype == typeof(Int32))
|
||||
{
|
||||
result = Convert.ToInt32(data1);
|
||||
}
|
||||
else if (itype == typeof(DateTime))
|
||||
{
|
||||
result = Convert.ToDateTime(data1);
|
||||
}
|
||||
else if (itype == typeof(Guid))
|
||||
{
|
||||
result = new Guid(data1.ToString());
|
||||
}
|
||||
else if (itype == typeof(string))
|
||||
{
|
||||
result = data1.ToString();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (itype == typeof(decimal))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else if (itype == typeof(double))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else if (itype == typeof(Int32))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
else if (itype == typeof(DateTime))
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else if (itype == typeof(Guid))
|
||||
{
|
||||
result = Guid.Empty;
|
||||
}
|
||||
else if (itype == typeof(string))
|
||||
{
|
||||
result = "";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
181
CoreCms.Net.Utility/Extensions/ObjectExtensions.cs
Normal file
181
CoreCms.Net.Utility/Extensions/ObjectExtensions.cs
Normal file
@@ -0,0 +1,181 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* Versions: 1.0 *
|
||||
* CreateTime: 2020-02-01 17:48:52
|
||||
* NameSpace: CoreCms.Net.Framework.Utility.Extensions
|
||||
* FileName: ConvertExtensions
|
||||
* ClassDescription:
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CoreCms.Net.Utility.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 扩展数据转换
|
||||
/// </summary>
|
||||
public static class ObjectExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据转换为int类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static int ObjectToInt(this object thisValue)
|
||||
{
|
||||
int result = 0;
|
||||
if (thisValue == null)
|
||||
return 0;
|
||||
return thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out result) ? result : result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为int类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <param name="errorValue"></param>
|
||||
/// <returns></returns>
|
||||
public static int ObjectToInt(this object thisValue, int errorValue)
|
||||
{
|
||||
int result = 0;
|
||||
return thisValue != null && thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out result) ? result : errorValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为Double类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static double ObjectToDouble(this object thisValue)
|
||||
{
|
||||
double result = 0.0;
|
||||
return thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out result) ? result : 0.0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为Double类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <param name="errorValue"></param>
|
||||
/// <returns></returns>
|
||||
public static double ObjectToDouble(this object thisValue, double errorValue)
|
||||
{
|
||||
double result = 0.0;
|
||||
return thisValue != null && thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out result) ? result : errorValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为Float类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static float ObjectToFloat(this object thisValue)
|
||||
{
|
||||
float result = 0;
|
||||
return thisValue != null && thisValue != DBNull.Value && float.TryParse(thisValue.ToString(), out result) ? result : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为Float类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <param name="errorValue"></param>
|
||||
/// <returns></returns>
|
||||
public static float ObjectToFloat(this object thisValue, float errorValue)
|
||||
{
|
||||
float result = 0;
|
||||
return thisValue != null && thisValue != DBNull.Value && float.TryParse(thisValue.ToString(), out result) ? result : errorValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为String类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static string ObjectToString(this object thisValue)
|
||||
{
|
||||
return thisValue != null ? thisValue.ToString().Trim() : "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为String类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <param name="errorValue"></param>
|
||||
/// <returns></returns>
|
||||
public static string ObjectToString(this object thisValue, string errorValue)
|
||||
{
|
||||
return thisValue != null ? thisValue.ToString().Trim() : errorValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为Decimal类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static Decimal ObjectToDecimal(this object thisValue)
|
||||
{
|
||||
Decimal result = new Decimal();
|
||||
return thisValue != null && thisValue != DBNull.Value && Decimal.TryParse(thisValue.ToString(), out result) ? result : Decimal.Zero;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为Decimal类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <param name="errorValue"></param>
|
||||
/// <returns></returns>
|
||||
public static Decimal ObjectToDecimal(this object thisValue, Decimal errorValue)
|
||||
{
|
||||
Decimal result = new Decimal();
|
||||
return thisValue != null && thisValue != DBNull.Value && Decimal.TryParse(thisValue.ToString(), out result) ? result : errorValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为DateTime类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime ObjectToDate(this object thisValue)
|
||||
{
|
||||
DateTime result = DateTime.MinValue;
|
||||
if (thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out result))
|
||||
result = Convert.ToDateTime(thisValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为DateTime类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <param name="errorValue"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime ObjectToDate(this object thisValue, DateTime errorValue)
|
||||
{
|
||||
DateTime result = DateTime.MinValue;
|
||||
return thisValue != null && thisValue != DBNull.Value && DateTime.TryParse(thisValue.ToString(), out result) ? result : errorValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据转换为bool类型
|
||||
/// </summary>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ObjectToBool(this object thisValue)
|
||||
{
|
||||
bool result = false;
|
||||
return thisValue != null && thisValue != DBNull.Value && bool.TryParse(thisValue.ToString(), out result) ? result : result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
54
CoreCms.Net.Utility/Extensions/SerializeExtensions.cs
Normal file
54
CoreCms.Net.Utility/Extensions/SerializeExtensions.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* Versions: 1.0 *
|
||||
* CreateTime: 2020-02-02 1:03:21
|
||||
* NameSpace: CoreCms.Net.Framework.Utility.Extensions
|
||||
* FileName: SerializeExtensions
|
||||
* ClassDescription:
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace CoreCms.Net.Utility.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串序列化类(用于redis数据传递保持编码格式统一)
|
||||
/// </summary>
|
||||
public static class SerializeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 序列化
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public static byte[] Serialize(object item)
|
||||
{
|
||||
var jsonString = JsonConvert.SerializeObject(item);
|
||||
|
||||
return Encoding.UTF8.GetBytes(jsonString);
|
||||
}
|
||||
/// <summary>
|
||||
/// 反序列化
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static TEntity Deserialize<TEntity>(byte[] value)
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
return default(TEntity);
|
||||
}
|
||||
var jsonString = Encoding.UTF8.GetString(value);
|
||||
return JsonConvert.DeserializeObject<TEntity>(jsonString);
|
||||
}
|
||||
}
|
||||
}
|
||||
70
CoreCms.Net.Utility/Helper/AreaHelper.cs
Normal file
70
CoreCms.Net.Utility/Helper/AreaHelper.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-03-21 22:32:23
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.DTO;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public class AreaHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 迭代方法
|
||||
/// </summary>
|
||||
/// <param name="oldNavs"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
public static List<AreasDto> GetList(List<CoreCmsArea> oldNavs)
|
||||
{
|
||||
List<AreasDto> childList = new List<AreasDto>();
|
||||
var model1 = oldNavs.Where(p => p.depth == 1).ToList();
|
||||
var model2 = oldNavs.Where(p => p.depth == 2).ToList();
|
||||
var model3 = oldNavs.Where(p => p.depth == 3).ToList();
|
||||
|
||||
foreach (var item in model1)
|
||||
{
|
||||
var child = new AreasDto();
|
||||
child.value = item.id;
|
||||
child.label = item.name;
|
||||
|
||||
var fsChild = new List<AreasDto>();
|
||||
var sc = model2.Where(p => p.parentId == item.id).ToList();
|
||||
foreach (var sss in sc)
|
||||
{
|
||||
var scItem = new AreasDto();
|
||||
scItem.value = sss.id;
|
||||
scItem.label = sss.name;
|
||||
|
||||
var scChild = new List<AreasDtoTh>();
|
||||
var th = model3.Where(p => p.parentId == sss.id).ToList();
|
||||
foreach (var itsmth in th)
|
||||
{
|
||||
scChild.Add(new AreasDtoTh()
|
||||
{
|
||||
label = itsmth.name,
|
||||
value = itsmth.id
|
||||
});
|
||||
}
|
||||
scItem.children = scChild;
|
||||
fsChild.Add(scItem);
|
||||
}
|
||||
|
||||
child.children = fsChild;
|
||||
childList.Add(child);
|
||||
}
|
||||
return childList;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
74
CoreCms.Net.Utility/Helper/ArticleHelper.cs
Normal file
74
CoreCms.Net.Utility/Helper/ArticleHelper.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-03-13 1:50:16
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public class ArticleHelper
|
||||
{
|
||||
#region 获取文章分类下来Dtree============================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取导航下拉上级树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Description("获取导航下拉上级树")]
|
||||
public static DTree GetTree(List<CoreCmsArticleType> categories, bool isHaveTop = true)
|
||||
{
|
||||
var model = new DTree();
|
||||
model.status = new dtreeStatus() { code = 200, message = "操作成功" };
|
||||
var list = GetMenus(categories, 0);
|
||||
if (isHaveTop)
|
||||
{
|
||||
list.Insert(0, new dtreeChild()
|
||||
{
|
||||
id = "0",
|
||||
last = true,
|
||||
parentId = "0",
|
||||
title = "无父级",
|
||||
children = new List<dtreeChild>()
|
||||
});
|
||||
}
|
||||
model.data = list;
|
||||
return model;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 迭代方法
|
||||
/// </summary>
|
||||
/// <param name="oldNavs"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
private static List<dtreeChild> GetMenus(List<CoreCmsArticleType> oldNavs, int parentId)
|
||||
{
|
||||
List<dtreeChild> childTree = new List<dtreeChild>();
|
||||
var model = oldNavs.Where(p => p.parentId == parentId).ToList();
|
||||
foreach (var item in model)
|
||||
{
|
||||
var parentTree = new dtreeChild();
|
||||
parentTree.id = item.id.ToString();
|
||||
parentTree.title = item.name;
|
||||
parentTree.parentId = item.parentId.ToString();
|
||||
parentTree.last = !oldNavs.Exists(p => p.parentId == item.id);
|
||||
|
||||
childTree.Add(parentTree);
|
||||
parentTree.children = GetMenus(oldNavs, item.id);
|
||||
}
|
||||
return childTree;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
602
CoreCms.Net.Utility/Helper/CommonHelper.cs
Normal file
602
CoreCms.Net.Utility/Helper/CommonHelper.cs
Normal file
@@ -0,0 +1,602 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 通用帮助类
|
||||
/// </summary>
|
||||
public static class CommonHelper
|
||||
{
|
||||
|
||||
#region 判断字符串是否为手机号码
|
||||
/// <summary>
|
||||
/// 判断字符串是否为手机号码
|
||||
/// </summary>
|
||||
/// <param name="mobilePhoneNumber"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsMobile(string mobilePhoneNumber)
|
||||
{
|
||||
if (mobilePhoneNumber.Length < 11)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//电信手机号码正则
|
||||
string dianxin = @"^1[345789][01379]\d{8}$";
|
||||
Regex regexDx = new Regex(dianxin);
|
||||
//联通手机号码正则
|
||||
string liantong = @"^1[345678][01256]\d{8}$";
|
||||
Regex regexLt = new Regex(liantong);
|
||||
//移动手机号码正则
|
||||
string yidong = @"^1[345789][0123456789]\d{8}$";
|
||||
Regex regexYd = new Regex(yidong);
|
||||
if (regexDx.IsMatch(mobilePhoneNumber) || regexLt.IsMatch(mobilePhoneNumber) || regexYd.IsMatch(mobilePhoneNumber))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 检测是否符合email格式
|
||||
|
||||
/// <summary>
|
||||
/// 检测是否符合email格式
|
||||
/// </summary>
|
||||
/// <param name="strEmail">要判断的email字符串</param>
|
||||
/// <returns>判断结果</returns>
|
||||
public static bool IsValidEmail(string strEmail)
|
||||
{
|
||||
return Regex.IsMatch(strEmail, @"^[\w\.]+([-]\w+)*@[A-Za-z0-9-_]+[\.][A-Za-z0-9-_]");
|
||||
}
|
||||
|
||||
public static bool IsValidDoEmail(string strEmail)
|
||||
{
|
||||
return Regex.IsMatch(strEmail,
|
||||
@"^@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 检测是否是正确的Url
|
||||
/// <summary>
|
||||
/// 检测是否是正确的Url
|
||||
/// </summary>
|
||||
/// <param name="strUrl">要验证的Url</param>
|
||||
/// <returns>判断结果</returns>
|
||||
public static bool IsUrl(string strUrl)
|
||||
{
|
||||
return Regex.IsMatch(strUrl,
|
||||
@"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$");
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region string 转int数组
|
||||
|
||||
public static int[] StringToIntArray(string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(str)) return new int[0];
|
||||
if (str.EndsWith(","))
|
||||
{
|
||||
str = str.Remove(str.Length - 1, 1);
|
||||
}
|
||||
var idstrarr = str.Split(',');
|
||||
var idintarr = new int[idstrarr.Length];
|
||||
|
||||
for (int i = 0; i < idstrarr.Length; i++)
|
||||
{
|
||||
idintarr[i] = Convert.ToInt32(idstrarr[i]);
|
||||
}
|
||||
return idintarr;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region String转数组
|
||||
public static string[] StringToStringArray(string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(str)) return new string[0];
|
||||
if (str.EndsWith(",")) str = str.Remove(str.Length - 1, 1);
|
||||
return str.Split(',');
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new string[0];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region String数组转Int数组
|
||||
public static int[] StringArrAyToIntArray(string[] str)
|
||||
{
|
||||
try
|
||||
{
|
||||
int[] iNums = Array.ConvertAll<string, int>(str, s => int.Parse(s));
|
||||
return iNums;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region string转Guid数组
|
||||
public static System.Guid[] StringToGuidArray(string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(str)) return new System.Guid[0];
|
||||
if (str.EndsWith(",")) str = str.Remove(str.Length - 1, 1);
|
||||
var strarr = str.Split(',');
|
||||
System.Guid[] guids = new System.Guid[strarr.Length];
|
||||
for (int index = 0; index < strarr.Length; index++)
|
||||
{
|
||||
guids[index] = System.Guid.Parse(strarr[index]);
|
||||
}
|
||||
return guids;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new System.Guid[0];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取32位md5加密
|
||||
/// <summary>
|
||||
/// 通过创建哈希字符串适用于任何 MD5 哈希函数 (在任何平台) 上创建 32 个字符的十六进制格式哈希字符串
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns>32位md5加密字符串</returns>
|
||||
public static string Md5For32(string source)
|
||||
{
|
||||
using (MD5 md5Hash = MD5.Create())
|
||||
{
|
||||
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(source));
|
||||
StringBuilder sBuilder = new StringBuilder();
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
sBuilder.Append(data[i].ToString("x2"));
|
||||
}
|
||||
|
||||
string hash = sBuilder.ToString();
|
||||
return hash.ToUpper();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取16位md5加密
|
||||
/// <summary>
|
||||
/// 获取16位md5加密
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns>16位md5加密字符串</returns>
|
||||
public static string Md5For16(string source)
|
||||
{
|
||||
using (MD5 md5Hash = MD5.Create())
|
||||
{
|
||||
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(source));
|
||||
//转换成字符串,并取9到25位
|
||||
string sBuilder = BitConverter.ToString(data, 4, 8);
|
||||
//BitConverter转换出来的字符串会在每个字符中间产生一个分隔符,需要去除掉
|
||||
sBuilder = sBuilder.Replace("-", "");
|
||||
return sBuilder.ToUpper();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 返回当前的毫秒时间戳
|
||||
|
||||
/// <summary>
|
||||
/// 返回当前的毫秒时间戳
|
||||
/// </summary>
|
||||
public static string Msectime()
|
||||
{
|
||||
long timeTicks = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
|
||||
return timeTicks.ToString();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取多种数据编号
|
||||
/// <summary>
|
||||
/// 获取多种数据编号
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetSerialNumberType(int type)
|
||||
{
|
||||
var str = string.Empty;
|
||||
Random rand = new Random();
|
||||
switch (type)
|
||||
{
|
||||
case (int)GlobalEnumVars.SerialNumberType.订单编号: //订单编号
|
||||
str = type + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.支付单编号: //支付单编号
|
||||
str = type + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.商品编号: //商品编号
|
||||
str = 'G' + Msectime() + rand.Next(0, 5);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.货品编号: //货品编号
|
||||
str = 'P' + Msectime() + rand.Next(0, 5);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.售后单编号: //售后单编号
|
||||
str = type + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.退款单编号: //退款单编号
|
||||
str = type + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.退货单编号: //退货单编号
|
||||
str = type + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.发货单编号: //发货单编号
|
||||
str = type + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.服务订单编号: //服务订单编号
|
||||
str = type + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.提货单号: //提货单号
|
||||
//str = 'T' + type + msectime() + rand.Next(0, 5);
|
||||
var charsStr = new[] { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '2', '3', '4', '5', '6', '7', '8', '9' };
|
||||
var charsLen = charsStr.Length - 1;
|
||||
// shuffle($chars);
|
||||
str = "";
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
str += charsStr[rand.Next(0, charsLen)];
|
||||
}
|
||||
break;
|
||||
case (int)GlobalEnumVars.SerialNumberType.服务券兑换码: //服务券兑换码
|
||||
var charsStr2 = new[] { 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '2', '3', '4', '5', '6', '7', '8', '9' };
|
||||
var charsLen2 = charsStr2.Length - 1;
|
||||
// shuffle($chars);
|
||||
str = "";
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
str += charsStr2[rand.Next(0, charsLen2)];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
str = 'T' + Msectime() + rand.Next(0, 9);
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 剩余多久时间文字描述
|
||||
/// <summary>
|
||||
/// 剩余多久时间
|
||||
/// </summary>
|
||||
/// <param name="remainingTime"></param>
|
||||
/// <returns>文字描述</returns>
|
||||
public static string GetRemainingTime(DateTime remainingTime)
|
||||
{
|
||||
TimeSpan timeSpan = remainingTime - DateTime.Now;
|
||||
var day = timeSpan.Days;
|
||||
var hours = timeSpan.Hours;
|
||||
var minute = timeSpan.Minutes;
|
||||
var seconds = timeSpan.Seconds;
|
||||
if (day > 0)
|
||||
{
|
||||
return day + "天" + hours + "小时" + minute + "分" + seconds + "秒";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hours > 0)
|
||||
{
|
||||
return hours + "小时" + minute + "分" + seconds + "秒";
|
||||
}
|
||||
else
|
||||
{
|
||||
return minute + "分" + seconds + "秒";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 剩余多久时间返回时间类型
|
||||
/// <summary>
|
||||
/// 剩余多久时间
|
||||
/// </summary>
|
||||
/// <param name="remainingTime"></param>
|
||||
/// <returns>返回时间类型</returns>
|
||||
public static void GetBackTime(DateTime remainingTime, out int day, out int hours, out int minute, out int seconds)
|
||||
{
|
||||
TimeSpan timeSpan = remainingTime - DateTime.Now;
|
||||
day = timeSpan.Days;
|
||||
hours = timeSpan.Hours;
|
||||
minute = timeSpan.Minutes;
|
||||
seconds = timeSpan.Seconds;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 计算时间戳剩余多久时间
|
||||
|
||||
/// <summary>
|
||||
/// 计算时间戳剩余多久时间
|
||||
/// </summary>
|
||||
/// <param name="postTime">提交时间(要是以前的时间)</param>
|
||||
/// <returns></returns>
|
||||
public static string TimeAgo(DateTime postTime)
|
||||
{
|
||||
//当前时间的时间戳
|
||||
var nowtimes = ConvertTicks(DateTime.Now);
|
||||
//提交的时间戳
|
||||
var posttimes = ConvertTicks(postTime);
|
||||
//相差时间戳
|
||||
var counttime = nowtimes - posttimes;
|
||||
|
||||
//进行时间转换
|
||||
if (counttime <= 60)
|
||||
{
|
||||
return "刚刚";
|
||||
}
|
||||
else if (counttime > 60 && counttime <= 120)
|
||||
{
|
||||
return "1分钟前";
|
||||
}
|
||||
else if (counttime > 120 && counttime <= 180)
|
||||
{
|
||||
return "2分钟前";
|
||||
}
|
||||
else if (counttime > 180 && counttime < 3600)
|
||||
{
|
||||
return Convert.ToInt32((counttime / 60)) + "分钟前";
|
||||
}
|
||||
else if (counttime >= 3600 && counttime < 3600 * 24)
|
||||
{
|
||||
return Convert.ToInt32((counttime / 3600)) + "小时前";
|
||||
}
|
||||
else if (counttime >= 3600 * 24 && counttime < 3600 * 24 * 2)
|
||||
{
|
||||
return "昨天";
|
||||
}
|
||||
else if (counttime >= 3600 * 24 * 2 && counttime < 3600 * 24 * 3)
|
||||
{
|
||||
return "前天";
|
||||
}
|
||||
else if (counttime >= 3600 * 24 * 3 && counttime <= 3600 * 24 * 7)
|
||||
{
|
||||
return Convert.ToInt32((counttime / (3600 * 24))) + "天前";
|
||||
}
|
||||
else if (counttime >= 3600 * 24 * 7 && counttime <= 3600 * 24 * 30)
|
||||
{
|
||||
return Convert.ToInt32((counttime / (3600 * 24 * 7))) + "周前";
|
||||
}
|
||||
else if (counttime >= 3600 * 24 * 30 && counttime <= 3600 * 24 * 365)
|
||||
{
|
||||
return Convert.ToInt32((counttime / (3600 * 24 * 30))) + "个月前";
|
||||
}
|
||||
else if (counttime >= 3600 * 24 * 365)
|
||||
{
|
||||
return Convert.ToInt32((counttime / (3600 * 24 * 365))) + "年前";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 时间转换为秒的时间戳
|
||||
/// </summary>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
private static long ConvertTicks(DateTime time)
|
||||
{
|
||||
long currentTicks = time.Ticks;
|
||||
DateTime dtFrom = new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
long currentMillis = (currentTicks - dtFrom.Ticks) / 10000000; //转换为秒为Ticks/10000000,转换为毫秒Ticks/10000
|
||||
return currentMillis;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 清除HTML中指定样式
|
||||
/// <summary>
|
||||
/// 清除HTML中指定样式
|
||||
/// </summary>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="rule"></param>
|
||||
/// <returns></returns>
|
||||
public static string ClearHtml(string content, string[] rule)
|
||||
{
|
||||
if (!rule.Any())
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
foreach (var item in rule)
|
||||
{
|
||||
content = Regex.Replace(content, "/" + item + @"\s*=\s*\d+\s*/i", "");
|
||||
content = Regex.Replace(content, "/" + item + @"\s*=\s*.+?[""]/i", "");
|
||||
content = Regex.Replace(content, "/" + item + @"\s*:\s*\d+\s*px\s*;?/i", "");
|
||||
}
|
||||
return content;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region list随机排序方法
|
||||
/// <summary>
|
||||
/// list随机排序方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="ListT"></param>
|
||||
/// <returns></returns>
|
||||
public static List<T> RandomSortList<T>(List<T> ListT)
|
||||
{
|
||||
Random random = new Random();
|
||||
List<T> newList = new List<T>();
|
||||
foreach (T item in ListT)
|
||||
{
|
||||
newList.Insert(random.Next(newList.Count + 1), item);
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 从字典中取单个数据
|
||||
/// <summary>
|
||||
/// 从字典中取单个数据
|
||||
/// </summary>
|
||||
/// <param name="configs"></param>
|
||||
/// <param name="skey"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetConfigDictionary(Dictionary<string, DictionaryKeyValues> configs, string skey)
|
||||
{
|
||||
configs.TryGetValue(skey, out var di);
|
||||
return di?.sValue;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 截前后字符(串)
|
||||
///<summary>
|
||||
/// 截前后字符(串)
|
||||
///</summary>
|
||||
///<param name="val">原字符串</param>
|
||||
///<param name="str">要截掉的字符串</param>
|
||||
///<param name="all">是否贪婪</param>
|
||||
///<returns></returns>
|
||||
public static string GetCaptureInterceptedText(string val, string str, bool all = false)
|
||||
{
|
||||
return Regex.Replace(val, @"(^(" + str + ")" + (all ? "*" : "") + "|(" + str + ")" + (all ? "*" : "") + "$)", "");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 密码加密方法
|
||||
/// <summary>
|
||||
/// 密码加密方法
|
||||
/// </summary>
|
||||
/// <param name="password">要加密的字符串</param>
|
||||
/// <param name="createTime">时间组合</param>
|
||||
/// <returns></returns>
|
||||
public static string EnPassword(string password, DateTime createTime)
|
||||
{
|
||||
var dtStr = createTime.ToString("yyyyMMddHHmmss");
|
||||
var md5 = Md5For32(password);
|
||||
var enPwd = Md5For32(md5 + dtStr);
|
||||
return enPwd;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取现在是星期几
|
||||
/// <summary>
|
||||
/// 获取现在是星期几
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetWeek()
|
||||
{
|
||||
string week = string.Empty;
|
||||
switch (DateTime.Now.DayOfWeek)
|
||||
{
|
||||
case DayOfWeek.Monday:
|
||||
week = "周一";
|
||||
break;
|
||||
case DayOfWeek.Tuesday:
|
||||
week = "周二";
|
||||
break;
|
||||
case DayOfWeek.Wednesday:
|
||||
week = "周三";
|
||||
break;
|
||||
case DayOfWeek.Thursday:
|
||||
week = "周四";
|
||||
break;
|
||||
case DayOfWeek.Friday:
|
||||
week = "周五";
|
||||
break;
|
||||
case DayOfWeek.Saturday:
|
||||
week = "周六";
|
||||
break;
|
||||
case DayOfWeek.Sunday:
|
||||
week = "周日";
|
||||
break;
|
||||
default:
|
||||
week = "N/A";
|
||||
break;
|
||||
}
|
||||
return week;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region UrlEncode (URL编码)
|
||||
/// <summary>
|
||||
/// UrlEncode (URL编码)
|
||||
/// </summary>
|
||||
/// <param name="str"></param>
|
||||
/// <returns></returns>
|
||||
public static string UrlEncode(string str)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
|
||||
for (int i = 0; i < byStr.Length; i++)
|
||||
{
|
||||
sb.Append(@"%" + Convert.ToString(byStr[i], 16));
|
||||
}
|
||||
|
||||
return (sb.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取10位时间戳
|
||||
/// <summary>
|
||||
/// 获取10位时间戳
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static long GetTimeStampByTotalSeconds()
|
||||
{
|
||||
TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
return Convert.ToInt64(ts.TotalSeconds);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 获取13位时间戳
|
||||
/// <summary>
|
||||
/// 获取13位时间戳
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static long GetTimeStampByTotalMilliseconds()
|
||||
{
|
||||
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
return Convert.ToInt64(ts.TotalMilliseconds);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
29
CoreCms.Net.Utility/Helper/DateHelper.cs
Normal file
29
CoreCms.Net.Utility/Helper/DateHelper.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-07-17 0:50:39
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public class DateHelper
|
||||
{
|
||||
public static DateTime StampToDateTime(string time)
|
||||
{
|
||||
time = time.Substring(0, 10);
|
||||
double timestamp = Convert.ToInt64(time);
|
||||
System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
dateTime = dateTime.AddSeconds(timestamp).ToLocalTime();
|
||||
return dateTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
122
CoreCms.Net.Utility/Helper/EnumHelper.cs
Normal file
122
CoreCms.Net.Utility/Helper/EnumHelper.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public class EnumHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 将枚举转成List
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static List<EnumEntity> EnumToList<T>()
|
||||
{
|
||||
List<EnumEntity> list = new List<EnumEntity>();
|
||||
|
||||
foreach (var e in Enum.GetValues(typeof(T)))
|
||||
{
|
||||
EnumEntity m = new EnumEntity();
|
||||
object[] objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
if (objArr != null && objArr.Length > 0)
|
||||
{
|
||||
DescriptionAttribute da = objArr[0] as DescriptionAttribute;
|
||||
m.description = da.Description;
|
||||
}
|
||||
m.value = Convert.ToInt32(e);
|
||||
m.title = e.ToString();
|
||||
list.Add(m);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据枚举值来获取单个枚举实体
|
||||
/// </summary>
|
||||
/// <typeparam name="T">枚举</typeparam>
|
||||
/// <param name="value">value</param>
|
||||
/// <returns></returns>
|
||||
public static EnumEntity GetEnumberEntity<T>(int value)
|
||||
{
|
||||
foreach (var e in Enum.GetValues(typeof(T)))
|
||||
{
|
||||
EnumEntity m = new EnumEntity();
|
||||
object[] objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
if (objArr != null && objArr.Length > 0)
|
||||
{
|
||||
DescriptionAttribute da = objArr[0] as DescriptionAttribute;
|
||||
m.description = da.Description;
|
||||
}
|
||||
m.value = Convert.ToInt32(e);
|
||||
m.title = e.ToString();
|
||||
if (value == m.value)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据枚举值value来获取单个枚举实体的文字描述内容
|
||||
/// </summary>
|
||||
/// <typeparam name="T">枚举</typeparam>
|
||||
/// <param name="value">value</param>
|
||||
/// <returns></returns>
|
||||
public static string GetEnumDescriptionByValue<T>(int value)
|
||||
{
|
||||
foreach (var e in Enum.GetValues(typeof(T)))
|
||||
{
|
||||
EnumEntity m = new EnumEntity();
|
||||
object[] objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
if (objArr != null && objArr.Length > 0)
|
||||
{
|
||||
DescriptionAttribute da = objArr[0] as DescriptionAttribute;
|
||||
m.description = da.Description;
|
||||
}
|
||||
m.value = Convert.ToInt32(e);
|
||||
m.title = e.ToString();
|
||||
if (value == m.value)
|
||||
{
|
||||
return m.description;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据枚举key来获取单个枚举实体的文字描述内容
|
||||
/// </summary>
|
||||
/// <typeparam name="T">枚举</typeparam>
|
||||
/// <param name="key">value</param>
|
||||
/// <returns></returns>
|
||||
public static string GetEnumDescriptionByKey<T>(string key)
|
||||
{
|
||||
foreach (var e in Enum.GetValues(typeof(T)))
|
||||
{
|
||||
EnumEntity m = new EnumEntity();
|
||||
object[] objArr = e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), true);
|
||||
if (objArr != null && objArr.Length > 0)
|
||||
{
|
||||
DescriptionAttribute da = objArr[0] as DescriptionAttribute;
|
||||
m.description = da.Description;
|
||||
}
|
||||
m.value = Convert.ToInt32(e);
|
||||
m.title = e.ToString();
|
||||
if (key == m.title)
|
||||
{
|
||||
return m.description;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
65
CoreCms.Net.Utility/Helper/ExcelHelper.cs
Normal file
65
CoreCms.Net.Utility/Helper/ExcelHelper.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.HSSF.Util;
|
||||
using NPOI.SS.UserModel;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public static class ExcelHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取头部样式
|
||||
/// </summary>
|
||||
/// <param name="hs"></param>
|
||||
/// <returns></returns>
|
||||
public static ICellStyle GetHeaderStyle(HSSFWorkbook hs)
|
||||
{
|
||||
//样式
|
||||
ICellStyle headerStyle = hs.CreateCellStyle();//创建样式
|
||||
headerStyle.VerticalAlignment = VerticalAlignment.Center;//垂直居中 方法1
|
||||
//style.Alignment = HorizontalAlignment.CenterSelection;//设置居中 方法2
|
||||
headerStyle.Alignment = HorizontalAlignment.Center;//设置居中 方法3
|
||||
HSSFFont headerfont = (HSSFFont)hs.CreateFont();//创建字体
|
||||
headerfont.Color = HSSFColor.Black.Index;//给字体设置颜色
|
||||
headerfont.FontName = "宋体";
|
||||
headerfont.IsBold = true;
|
||||
headerfont.FontHeight = 11;
|
||||
headerfont.FontHeightInPoints = 11;
|
||||
headerStyle.SetFont(headerfont);
|
||||
|
||||
headerStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; //下边框线
|
||||
headerStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; //左边框线
|
||||
headerStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; //右边框线
|
||||
headerStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; //上边框线
|
||||
return headerStyle;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取通用列样式
|
||||
/// </summary>
|
||||
/// <param name="hs"></param>
|
||||
/// <returns></returns>
|
||||
public static ICellStyle GetCommonStyle(HSSFWorkbook hs)
|
||||
{
|
||||
//样式
|
||||
ICellStyle commonCellStyle = hs.CreateCellStyle();//创建样式
|
||||
commonCellStyle.VerticalAlignment = VerticalAlignment.Center;//垂直居中
|
||||
//commonCellStyle.Alignment = HorizontalAlignment.CenterSelection;//设置居中
|
||||
commonCellStyle.Alignment = HorizontalAlignment.Center;//设置居中
|
||||
|
||||
HSSFFont commonFont = (HSSFFont)hs.CreateFont();//创建字体
|
||||
commonFont.FontName = "宋体";
|
||||
commonFont.FontHeight = 10;
|
||||
commonFont.FontHeightInPoints = 10;
|
||||
commonCellStyle.SetFont(commonFont);
|
||||
|
||||
commonCellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin; //下边框线
|
||||
commonCellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin; //左边框线
|
||||
commonCellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin; //右边框线
|
||||
commonCellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin; //上边框线
|
||||
return commonCellStyle;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
76
CoreCms.Net.Utility/Helper/FormHelper.cs
Normal file
76
CoreCms.Net.Utility/Helper/FormHelper.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using NPOI.OpenXmlFormats.Dml;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public static class FormHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 验证字段类型及提交的值是否对应
|
||||
/// </summary>
|
||||
/// <param name="typeName"></param>
|
||||
/// <param name="thisValue"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ValidateField(string typeName, object thisValue)
|
||||
{
|
||||
var bl = false;
|
||||
var valueType = thisValue.GetType();
|
||||
if (typeName == GlobalEnumVars.FormValidationTypes.字符串.ToString())
|
||||
{
|
||||
return valueType == typeof(string);
|
||||
}
|
||||
else if (typeName == GlobalEnumVars.FormValidationTypes.数字.ToString())
|
||||
{
|
||||
return thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out _);
|
||||
}
|
||||
else if (typeName == GlobalEnumVars.FormValidationTypes.整数.ToString())
|
||||
{
|
||||
return thisValue != DBNull.Value && int.TryParse(thisValue.ToString(), out _);
|
||||
}
|
||||
else if (typeName == GlobalEnumVars.FormValidationTypes.价格.ToString())
|
||||
{
|
||||
return thisValue != DBNull.Value && double.TryParse(thisValue.ToString(), out _);
|
||||
}
|
||||
else if (typeName == GlobalEnumVars.FormValidationTypes.邮箱.ToString())
|
||||
{
|
||||
if (valueType == typeof(string) && !string.IsNullOrEmpty(thisValue.ToString()))
|
||||
{
|
||||
return Regex.IsMatch(thisValue.ToString() ?? string.Empty, @"^[\w\.]+([-]\w+)*@[A-Za-z0-9-_]+[\.][A-Za-z0-9-_]");
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (typeName == GlobalEnumVars.FormValidationTypes.手机号.ToString())
|
||||
{
|
||||
if (valueType == typeof(string) && !string.IsNullOrEmpty(thisValue.ToString()))
|
||||
{
|
||||
return CommonHelper.IsMobile(thisValue.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (typeName == GlobalEnumVars.FormValidationTypes.多数据.ToString())
|
||||
{
|
||||
return valueType == typeof(Array);
|
||||
}
|
||||
else
|
||||
{
|
||||
bl = false;
|
||||
}
|
||||
return bl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
148
CoreCms.Net.Utility/Helper/GoodsHelper.cs
Normal file
148
CoreCms.Net.Utility/Helper/GoodsHelper.cs
Normal file
@@ -0,0 +1,148 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-03-03 5:04:42
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品分类帮助
|
||||
/// </summary>
|
||||
public static class GoodsHelper
|
||||
{
|
||||
#region 获取商品分类下来Dtree============================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取导航下拉上级树
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Description("获取导航下拉上级树")]
|
||||
public static DTree GetTree(List<CoreCmsGoodsCategory> categories, bool isHaveTop = true)
|
||||
{
|
||||
|
||||
var model = new DTree();
|
||||
model.status = new dtreeStatus() { code = 200, message = "操作成功" };
|
||||
|
||||
var list = GetMenus(categories, 0);
|
||||
|
||||
if (isHaveTop)
|
||||
{
|
||||
list.Insert(0, new dtreeChild()
|
||||
{
|
||||
id = "0",
|
||||
last = true,
|
||||
parentId = "0",
|
||||
title = "无父级",
|
||||
children = new List<dtreeChild>()
|
||||
});
|
||||
}
|
||||
model.data = list;
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 迭代方法
|
||||
/// </summary>
|
||||
/// <param name="oldNavs"></param>
|
||||
/// <param name="parentId"></param>
|
||||
/// <returns></returns>
|
||||
private static List<dtreeChild> GetMenus(List<CoreCmsGoodsCategory> oldNavs, int parentId)
|
||||
{
|
||||
List<dtreeChild> childTree = new List<dtreeChild>();
|
||||
var model = oldNavs.Where(p => p.parentId == parentId).ToList();
|
||||
foreach (var item in model)
|
||||
{
|
||||
var parentTree = new dtreeChild();
|
||||
parentTree.id = item.id.ToString();
|
||||
parentTree.title = item.name;
|
||||
parentTree.parentId = item.parentId.ToString();
|
||||
parentTree.last = !oldNavs.Exists(p => p.parentId == item.id);
|
||||
|
||||
childTree.Add(parentTree);
|
||||
parentTree.children = GetMenus(oldNavs, item.id);
|
||||
}
|
||||
return childTree;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 获取可用库存
|
||||
/// <summary>
|
||||
/// 获取可用库存。
|
||||
/// 库存机制:商品下单 总库存不变,冻结库存加1,
|
||||
/// 商品发货:冻结库存减1,总库存减1,
|
||||
/// 商品退款&取消订单:总库存不变,冻结库存减1,
|
||||
/// 商品退货:总库存加1,冻结库存不变,
|
||||
/// 可销售库存:总库存-冻结库存
|
||||
/// </summary>
|
||||
/// <param name="stock">库存</param>
|
||||
/// <param name="freezeStock">静态库存</param>
|
||||
/// <returns></returns>
|
||||
public static int GetStock(int stock, int freezeStock)
|
||||
{
|
||||
return stock - freezeStock;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region arr图片提取单张,或设置一张默认
|
||||
/// <summary>
|
||||
/// arr图片提取单张,或设置一张默认
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetOneImage(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
return "/static/images/common/empty.png";
|
||||
}
|
||||
else if (url.Contains(","))
|
||||
{
|
||||
return url.Split(",")[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return url;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 小程序端获取编码后的分类集合
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 后端判断提交的商品属性值是否符合规则(判断内容,只允许中文,字母,数字,和-,/)
|
||||
|
||||
/// <summary>
|
||||
/// 判断内容,只允许中文,字母,数字,和-,/
|
||||
/// </summary>
|
||||
/// <param name="inputValue">输入字符串</param>
|
||||
/// <remarks>判断内容,只允许中文,字母,数字,和-,/</remarks>
|
||||
/// <returns></returns>
|
||||
public static bool FilterChar(string inputValue)
|
||||
{
|
||||
return Regex.IsMatch(inputValue, "[`.~!@#$^&*()=|\"{}':;',\\[\\]<>?~!@#¥……&*&;|{}。*-+]+");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
53
CoreCms.Net.Utility/Helper/HttpHelper.cs
Normal file
53
CoreCms.Net.Utility/Helper/HttpHelper.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-05-12 0:54:53
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 模拟标准表单Post提交
|
||||
/// </summary>
|
||||
public static class HttpHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 模拟标准表单Post提交
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="postdate"></param>
|
||||
/// <returns></returns>
|
||||
public static string PostSend(string url, string postdate)
|
||||
{
|
||||
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
|
||||
myHttpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||
myHttpWebRequest.Method = "POST";
|
||||
Stream myRequestStream = myHttpWebRequest.GetRequestStream();
|
||||
StreamWriter myStreamWriter = new StreamWriter(myRequestStream);
|
||||
myStreamWriter.Write(postdate);
|
||||
myStreamWriter.Flush();
|
||||
myStreamWriter.Close();
|
||||
myRequestStream.Close();
|
||||
|
||||
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
|
||||
Stream myResponseStream = myHttpWebResponse.GetResponseStream();
|
||||
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
|
||||
String outdata = myStreamReader.ReadToEnd();
|
||||
myStreamReader.Close();
|
||||
myResponseStream.Close();
|
||||
return outdata;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
155
CoreCms.Net.Utility/Helper/JsonFileHelper.cs
Normal file
155
CoreCms.Net.Utility/Helper/JsonFileHelper.cs
Normal file
@@ -0,0 +1,155 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-03-02 23:15:19
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Json文件读写
|
||||
/// 引用Newtonsoft.Json
|
||||
/// </summary>
|
||||
public class JsonFileHelper
|
||||
{
|
||||
//注意:section为根节点
|
||||
private readonly string _path;
|
||||
private IConfiguration Configuration { get; set; }
|
||||
public JsonFileHelper(string jsonName)
|
||||
{
|
||||
_path = !jsonName.EndsWith(".json") ? $"{jsonName}.json" : jsonName;
|
||||
//ReloadOnChange = true 当*.json文件被修改时重新加载
|
||||
Configuration = new ConfigurationBuilder()
|
||||
.Add(new JsonConfigurationSource { Path = _path, ReloadOnChange = true, Optional = true })
|
||||
.Build();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取Json返回实体对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public T Read<T>() => Read<T>("");
|
||||
|
||||
/// <summary>
|
||||
/// 根据节点读取Json返回实体对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public T Read<T>(string section)
|
||||
{
|
||||
using var file = new StreamReader(_path);
|
||||
using var reader = new JsonTextReader(file);
|
||||
var jObj = (JObject)JToken.ReadFrom(reader);
|
||||
if (!string.IsNullOrWhiteSpace(section))
|
||||
{
|
||||
var secJt = jObj[section];
|
||||
if (secJt != null)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(secJt.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(jObj.ToString());
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取Json返回集合
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<T> ReadList<T>() => ReadList<T>("");
|
||||
|
||||
/// <summary>
|
||||
/// 根据节点读取Json返回集合
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<T> ReadList<T>(string section)
|
||||
{
|
||||
using var file = new StreamReader(_path);
|
||||
using var reader = new JsonTextReader(file);
|
||||
var jObj = (JObject)JToken.ReadFrom(reader);
|
||||
if (!string.IsNullOrWhiteSpace(section))
|
||||
{
|
||||
var secJt = jObj[section];
|
||||
if (secJt != null)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<T>>(secJt.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return JsonConvert.DeserializeObject<List<T>>(jObj.ToString());
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写入文件
|
||||
/// </summary>
|
||||
/// <typeparam name="T">自定义对象</typeparam>
|
||||
/// <param name="t"></param>
|
||||
public void Write<T>(T t) => Write("", t);
|
||||
|
||||
/// <summary>
|
||||
/// 写入指定section文件
|
||||
/// </summary>
|
||||
/// <typeparam name="T">自定义对象</typeparam>
|
||||
/// <param name="t"></param>
|
||||
public void Write<T>(string section, T t)
|
||||
{
|
||||
JObject jObj;
|
||||
using (StreamReader file = new StreamReader(_path))
|
||||
using (JsonTextReader reader = new JsonTextReader(file))
|
||||
{
|
||||
jObj = (JObject)JToken.ReadFrom(reader);
|
||||
var json = JsonConvert.SerializeObject(t);
|
||||
if (string.IsNullOrWhiteSpace(section))
|
||||
jObj = JObject.Parse(json);
|
||||
else
|
||||
jObj[section] = JObject.Parse(json);
|
||||
}
|
||||
|
||||
using var writer = new StreamWriter(_path);
|
||||
using var jsonWriter = new JsonTextWriter(writer);
|
||||
jObj.WriteTo(jsonWriter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除指定section节点
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void Remove(string section)
|
||||
{
|
||||
JObject jObj;
|
||||
using (StreamReader file = new StreamReader(_path))
|
||||
using (JsonTextReader reader = new JsonTextReader(file))
|
||||
{
|
||||
jObj = (JObject)JToken.ReadFrom(reader);
|
||||
jObj.Remove(section);
|
||||
}
|
||||
|
||||
using (var writer = new StreamWriter(_path))
|
||||
using (var jsonWriter = new JsonTextWriter(writer))
|
||||
{
|
||||
jObj.WriteTo(jsonWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
69
CoreCms.Net.Utility/Helper/MessageHelper.cs
Normal file
69
CoreCms.Net.Utility/Helper/MessageHelper.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-08-18 0:35:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CoreCms.Net.Configuration;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public static class MessageHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据编码获取消息内容
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetTemp(string code, JObject parameters)
|
||||
{
|
||||
string msg = string.Empty;
|
||||
if (code == GlobalEnumVars.PlatformMessageTypes.CreateOrder.ToString())
|
||||
{
|
||||
msg = "订单创建成功。";
|
||||
}
|
||||
else if (code == GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString())
|
||||
{
|
||||
msg = "恭喜您,订单支付成功,祝您购物愉快。";
|
||||
}
|
||||
else if (code == GlobalEnumVars.PlatformMessageTypes.RemindOrderPay.ToString())
|
||||
{
|
||||
msg = "您的订单还有3个小时就要取消了,请立即进行支付。";
|
||||
}
|
||||
else if (code == GlobalEnumVars.PlatformMessageTypes.DeliveryNotice.ToString())
|
||||
{
|
||||
msg = "你好,你的订单已经发货。";
|
||||
}
|
||||
else if (code == GlobalEnumVars.PlatformMessageTypes.AfterSalesPass.ToString())
|
||||
{
|
||||
msg = "你好,您的售后已经通过。";
|
||||
}
|
||||
else if (code == GlobalEnumVars.PlatformMessageTypes.RefundSuccess.ToString())
|
||||
{
|
||||
msg = "用户你好,你的退款已经处理,请确认。";
|
||||
}
|
||||
else if (code == GlobalEnumVars.ShopMessageTypes.AftersalesAdd.ToString())
|
||||
{
|
||||
msg = "你好,有新的售后订单了,请及时处理。";
|
||||
}
|
||||
else if (code == GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString())
|
||||
{
|
||||
msg = "您有新的订单了,请及时处理。";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
18
CoreCms.Net.Utility/Helper/OrderHelper.cs
Normal file
18
CoreCms.Net.Utility/Helper/OrderHelper.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-04-09 0:01:28
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public class OrderHelper
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
27
CoreCms.Net.Utility/Helper/PinTuanHelper.cs
Normal file
27
CoreCms.Net.Utility/Helper/PinTuanHelper.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-06-14 21:09:20
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 拼团帮助类
|
||||
/// </summary>
|
||||
public static class PinTuanHelper
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
89
CoreCms.Net.Utility/Helper/PromotionHelper.cs
Normal file
89
CoreCms.Net.Utility/Helper/PromotionHelper.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-03-14 4:54:44
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public static class PromotionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据结果类型返回相应的参数数据
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="json"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetResultMsg(string code, string json)
|
||||
{
|
||||
var msg = string.Empty;
|
||||
var obj = (JObject)JsonConvert.DeserializeObject(json);
|
||||
switch (code)
|
||||
{
|
||||
case "GOODS_REDUCE":
|
||||
if (obj != null) msg = "减" + obj["money"].ObjectToString() + "元 ";
|
||||
break;
|
||||
case "GOODS_DISCOUNT":
|
||||
if (obj != null) msg = "打" + obj["discount"].ObjectToString() + "折 ";
|
||||
break;
|
||||
case "GOODS_ONE_PRICE":
|
||||
if (obj != null) msg = "一口价" + obj["money"].ObjectToString() + "元 ";
|
||||
break;
|
||||
case "ORDER_REDUCE":
|
||||
if (obj != null) msg = "订单减" + obj["money"].ObjectToString() + "元 ";
|
||||
break;
|
||||
case "ORDER_DISCOUNT":
|
||||
if (obj != null) msg = "订单打" + obj["discount"].ObjectToString() + "折 ";
|
||||
break;
|
||||
case "GOODS_HALF_PRICE":
|
||||
if (obj != null)
|
||||
msg = "第" + obj["num"].ObjectToString() + "件" + obj["money"].ObjectToString() + "元";
|
||||
break;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据条件类型返回相应的参数数据
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="json"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetConditionMsg(string code, string json)
|
||||
{
|
||||
string msg = string.Empty;
|
||||
var obj = (JObject)JsonConvert.DeserializeObject(json);
|
||||
switch (code)
|
||||
{
|
||||
case "GOODS_ALL":
|
||||
msg = "购买任意商品 ";
|
||||
break;
|
||||
case "GOODS_IDS":
|
||||
msg = "购买指定商品 ";
|
||||
break;
|
||||
case "GOODS_CATS":
|
||||
msg = "购买指定分类商品 ";
|
||||
break;
|
||||
case "GOODS_BRANDS":
|
||||
msg = "购买指定品牌商品 ";
|
||||
break;
|
||||
case "ORDER_FULL":
|
||||
if (obj != null) msg = "购买订单满" + obj["money"].ObjectToString() + "元 ";
|
||||
break;
|
||||
case "USER_GRADE":
|
||||
msg = "用户符合指定等级";
|
||||
break;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
170
CoreCms.Net.Utility/Helper/ReportsHelper.cs
Normal file
170
CoreCms.Net.Utility/Helper/ReportsHelper.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-08-31 0:46:50
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 报表帮助类
|
||||
/// </summary>
|
||||
public static class ReportsHelper
|
||||
{
|
||||
|
||||
//根据时间,返回时间段
|
||||
public static WebApiCallBack GetDate(string data, int section)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
var reportsBackForGetDate = new ReportsBackForGetDate();
|
||||
if (!string.IsNullOrEmpty(data))
|
||||
{
|
||||
var dts = data.Split("到");
|
||||
if (dts.Length == 2)
|
||||
{
|
||||
reportsBackForGetDate.start = dts[0].Trim().ObjectToDate();
|
||||
reportsBackForGetDate.start = new DateTime(reportsBackForGetDate.start.Year, reportsBackForGetDate.start.Month, reportsBackForGetDate.start.Day, 0, 0, 0);
|
||||
reportsBackForGetDate.end = dts[1].Trim().ObjectToDate();
|
||||
reportsBackForGetDate.end = new DateTime(reportsBackForGetDate.end.Year, reportsBackForGetDate.end.Month, reportsBackForGetDate.end.Day, 23, 59, 59);
|
||||
reportsBackForGetDate.section = 1;
|
||||
jm.data = reportsBackForGetDate;
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.msg = "时间段格式不正确";
|
||||
return jm;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code10000;
|
||||
return jm;
|
||||
}
|
||||
//切片维度,1是小时,2是天,3是周,4是月,5是季度,6是半年,7是年
|
||||
if (section > 0)
|
||||
{
|
||||
reportsBackForGetDate.section = section;
|
||||
}
|
||||
//算统计需要的参数
|
||||
return getTmp(reportsBackForGetDate);
|
||||
|
||||
}
|
||||
|
||||
//根据时间节点和时间粒度算x轴个数
|
||||
public static WebApiCallBack getTmp(ReportsBackForGetDate dateArr)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
if (dateArr.end <= dateArr.start)
|
||||
{
|
||||
jm.msg = "开始时间必须小于结束时间";
|
||||
return jm;
|
||||
}
|
||||
TimeSpan diffDt = dateArr.end - dateArr.start; //两个时间相减 。默认得到的是两个的时间差
|
||||
switch (dateArr.section)
|
||||
{
|
||||
case 1: //小时
|
||||
dateArr.section = 60 * 60;
|
||||
dateArr.num = Convert.ToInt32(diffDt.TotalHours);
|
||||
break;
|
||||
case 2: //天
|
||||
dateArr.section = 60 * 60 * 24;
|
||||
dateArr.num = Convert.ToInt32(diffDt.TotalDays);
|
||||
break;
|
||||
default:
|
||||
jm.msg = "没有此时间粒度";
|
||||
return jm;
|
||||
}
|
||||
//算x轴数据个数
|
||||
jm.status = true;
|
||||
jm.data = dateArr;
|
||||
return jm;
|
||||
}
|
||||
|
||||
public static WebApiCallBack GetXdata(ReportsBackForGetDate dateArr)
|
||||
{
|
||||
var jm = new WebApiCallBack();
|
||||
|
||||
//校验,x轴最多1000个
|
||||
if (dateArr.num > 1000)
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code13226;
|
||||
return jm;
|
||||
}
|
||||
|
||||
var xType = "";
|
||||
switch (dateArr.section)
|
||||
{
|
||||
case 3600: //小时
|
||||
if (dateArr.num <= 24)
|
||||
{
|
||||
xType = "H时";
|
||||
}
|
||||
else if (dateArr.num <= 720)
|
||||
{
|
||||
xType = "d日H时";
|
||||
}
|
||||
else
|
||||
{
|
||||
xType = "m月d日H时";
|
||||
}
|
||||
break;
|
||||
case 86400: //天
|
||||
if (dateArr.num <= 31)
|
||||
{
|
||||
xType = "d号";
|
||||
}
|
||||
else if (dateArr.num <= 365)
|
||||
{
|
||||
xType = "m.d";
|
||||
}
|
||||
else
|
||||
{
|
||||
xType = "Y.m.d";
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (xType == "")
|
||||
{
|
||||
jm.msg = GlobalErrorCodeVars.Code10000;
|
||||
return jm;
|
||||
}
|
||||
|
||||
var arr = new List<string>();
|
||||
if (dateArr.section == 3600)
|
||||
{
|
||||
var dtStart = dateArr.start;
|
||||
for (int i = 0; i < dateArr.num; i++)
|
||||
{
|
||||
arr.Add(dtStart.AddHours(i).ToString(xType));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var dtStart = dateArr.start;
|
||||
for (int i = 0; i < dateArr.num; i++)
|
||||
{
|
||||
arr.Add(dtStart.AddDays(i).ToString(xType));
|
||||
}
|
||||
}
|
||||
|
||||
jm.status = true;
|
||||
jm.data = arr;
|
||||
jm.otherData = dateArr;
|
||||
return jm;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
61
CoreCms.Net.Utility/Helper/SKUHelper.cs
Normal file
61
CoreCms.Net.Utility/Helper/SKUHelper.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-03-05 1:54:55
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 商品规格sku计算
|
||||
/// </summary>
|
||||
public class SkuHelper
|
||||
{
|
||||
public static String[] process(string[][] sku)
|
||||
{
|
||||
int len = sku.Length;
|
||||
if (len >= 2)
|
||||
{
|
||||
var s1 = sku[0];
|
||||
int len1 = s1.Length;
|
||||
var s2 = sku[1];
|
||||
int len2 = s2.Length;
|
||||
|
||||
int len3 = len1 * len2;
|
||||
int index = 0;
|
||||
string[] items = new string[len3];
|
||||
for (int i = 0; i < len1; i++)
|
||||
{
|
||||
for (int j = 0; j < len2; j++)
|
||||
{
|
||||
items[index] = sku[0][i] + "," + sku[1][j];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
// 将新组合的数组并到原数组中
|
||||
string[][] newArr = new string[len - 1][];
|
||||
for (int i = 2; i < sku.Length; i++)
|
||||
{
|
||||
newArr[i - 1] = sku[i];
|
||||
}
|
||||
newArr[0] = items;
|
||||
return process(newArr);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (String[])sku[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
117
CoreCms.Net.Utility/Helper/SMSHelper.cs
Normal file
117
CoreCms.Net.Utility/Helper/SMSHelper.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-02-26 0:57:51
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using CoreCms.Net.Configuration;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 短信相关帮助类
|
||||
/// </summary>
|
||||
public class SmsHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据消息分类和传输参数,获取要发送的内容
|
||||
/// </summary>
|
||||
/// <param name="type">类型</param>
|
||||
/// <param name="parameters">参数类型</param>
|
||||
/// <returns></returns>
|
||||
public static string GetTemp(string type, JObject parameters)
|
||||
{
|
||||
var msg = string.Empty;
|
||||
if (type == GlobalEnumVars.SmsMessageTypes.Reg.ToString())
|
||||
{
|
||||
// 账户注册
|
||||
var code = string.Empty;
|
||||
if (parameters.ContainsKey("code"))
|
||||
{
|
||||
code = parameters["code"]?.ToString();
|
||||
}
|
||||
msg = "您正在注册账号,验证码是" + code + ",请勿告诉他人。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.SmsMessageTypes.Login.ToString())
|
||||
{
|
||||
// 账户登录
|
||||
var code = string.Empty;
|
||||
if (parameters.ContainsKey("code"))
|
||||
{
|
||||
code = parameters["code"]?.ToString();
|
||||
}
|
||||
msg = "您正在登陆账号,验证码是" + code + ",请勿告诉他人。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.SmsMessageTypes.Veri.ToString())
|
||||
{
|
||||
// 验证验证码
|
||||
var code = string.Empty;
|
||||
if (parameters.ContainsKey("code"))
|
||||
{
|
||||
code = parameters["code"]?.ToString();
|
||||
}
|
||||
msg = "您的验证码是" + code + ",请勿告诉他人。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.CreateOrder.ToString())
|
||||
{
|
||||
// 订单创建
|
||||
msg = "恭喜您,订单创建成功,祝您购物愉快。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.OrderPayed.ToString())
|
||||
{
|
||||
// 订单支付通知买家
|
||||
msg = "恭喜您,订单支付成功,祝您购物愉快。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.RemindOrderPay.ToString())
|
||||
{
|
||||
// 未支付催单
|
||||
msg = "您的订单还有1个小时就要取消了,请及时进行支付。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.DeliveryNotice.ToString())
|
||||
{
|
||||
// 订单发货
|
||||
msg = "您好,您的订单已经发货。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.AfterSalesPass.ToString())
|
||||
{
|
||||
// 售后审核通过
|
||||
msg = "您好,您的售后已经通过。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.RefundSuccess.ToString())
|
||||
{
|
||||
// 退款已处理
|
||||
msg = "用户您好,您的退款已经处理,请确认。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.SellerOrderNotice.ToString())
|
||||
{
|
||||
// 订单支付通知卖家
|
||||
msg = "您有新的订单了,请及时处理。";
|
||||
}
|
||||
else if (type == GlobalEnumVars.PlatformMessageTypes.Common.ToString())
|
||||
{
|
||||
//通用类型
|
||||
var tpl = string.Empty;
|
||||
if (parameters.ContainsKey("tpl"))
|
||||
{
|
||||
tpl = parameters["tpl"]?.ToString();
|
||||
}
|
||||
msg = tpl;
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// //记录哪里需要发送消息,统一处理
|
||||
/// </summary>
|
||||
public static void SendMessage()
|
||||
{
|
||||
//记录哪里需要发送消息,统一处理
|
||||
}
|
||||
}
|
||||
}
|
||||
38
CoreCms.Net.Utility/Helper/ShareHelper.cs
Normal file
38
CoreCms.Net.Utility/Helper/ShareHelper.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
public static class ShareHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 分享URL压缩(type-invite-id-teamId type=场景类型 invite=邀请码 id=场景ID值 teamId=拼团ID)
|
||||
/// </summary>
|
||||
/// <param name="type">场景类型</param>
|
||||
/// <param name="invite">邀请码</param>
|
||||
/// <param name="id">场景ID值</param>
|
||||
/// <param name="teamId">拼团ID</param>
|
||||
/// <returns></returns>
|
||||
public static string share_parameter_encode(string type, string invite, string id, string teamId)
|
||||
{
|
||||
var newUrl = type + "-" + invite + "-" + id + "-" + teamId;
|
||||
return newUrl;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分享URL解压缩
|
||||
/// </summary>
|
||||
/// <param name="url">已经压缩的url,多个-组成的url</param>
|
||||
/// <returns></returns>
|
||||
public static string share_parameter_decode(string url)
|
||||
{
|
||||
var urlArr = url.Split("-");
|
||||
var newUrl = "type=" + urlArr[0] + "&invite=" + urlArr[1] + "&id=" + urlArr[2] + "&teamId=" + urlArr[3];
|
||||
return newUrl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
47
CoreCms.Net.Utility/Helper/SysOrganizationHelper.cs
Normal file
47
CoreCms.Net.Utility/Helper/SysOrganizationHelper.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-07-16 1:39:49
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 组织机构帮助类
|
||||
/// </summary>
|
||||
public static class SysOrganizationHelper
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 获取组织结构树
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="treeNodes"></param>
|
||||
/// <returns></returns>
|
||||
public static void GetOrganizeChildIds(List<SysOrganization> list, int id, ref List<int> treeNodes)
|
||||
{
|
||||
treeNodes.Add(id);
|
||||
if (list == null) return;
|
||||
List<SysOrganization> sublist;
|
||||
sublist = list.Where(t => t.parentId == id).ToList();
|
||||
if (!sublist.Any()) return;
|
||||
foreach (var item in sublist)
|
||||
{
|
||||
GetOrganizeChildIds(list, item.id, ref treeNodes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
49
CoreCms.Net.Utility/Helper/UpLoadHelper.cs
Normal file
49
CoreCms.Net.Utility/Helper/UpLoadHelper.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/8/16 12:44:16
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using CoreCms.Net.Configuration;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 上传帮助类
|
||||
/// </summary>
|
||||
public static class UpLoadHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 上传路径格式化操作,防止不同类型下上传路径写入失败问题。
|
||||
/// </summary>
|
||||
/// <param name="storageType">上传类型</param>
|
||||
/// <param name="oldFilePath">原始路径</param>
|
||||
/// <returns></returns>
|
||||
public static string PathFormat(string storageType, string oldFilePath)
|
||||
{
|
||||
string newPath;
|
||||
switch (storageType)
|
||||
{
|
||||
case "LocalStorage":
|
||||
newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath;
|
||||
break;
|
||||
case "AliYunOSS":
|
||||
newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath;
|
||||
break;
|
||||
case "QCloudOSS":
|
||||
newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath;
|
||||
break;
|
||||
default:
|
||||
newPath = "/upload/";
|
||||
break;
|
||||
}
|
||||
newPath = newPath.EndsWith("/") ? newPath : newPath + "/";
|
||||
return newPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
130
CoreCms.Net.Utility/Helper/UserHelper.cs
Normal file
130
CoreCms.Net.Utility/Helper/UserHelper.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-02-26 0:58:28
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using CoreCms.Net.Configuration;
|
||||
|
||||
namespace CoreCms.Net.Utility.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户帮助类
|
||||
/// </summary>
|
||||
public static class UserHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取金额来源备注
|
||||
/// </summary>
|
||||
/// <param name="tpye">类型</param>
|
||||
/// <param name="money">金额</param>
|
||||
/// <param name="cateMoney">手续费</param>
|
||||
/// <returns></returns>
|
||||
public static string GetMemo(int tpye, decimal money, decimal cateMoney = 0)
|
||||
{
|
||||
var str = string.Empty;
|
||||
switch (tpye)
|
||||
{
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Pay:
|
||||
str += "消费了" + money + "元";
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Refund:
|
||||
str += "收到了退款" + money + "元";
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Recharge:
|
||||
str += "充值了" + money + "元";
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Tocash:
|
||||
str += "提现了" + money + "元";
|
||||
if (cateMoney > 0)
|
||||
{
|
||||
str += ",手续费" + cateMoney + "元";
|
||||
}
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Distribution:
|
||||
str += "佣金" + money + "元";
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Agent:
|
||||
str += "佣金" + money + "元";
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Admin:
|
||||
str += "后台操作" + money + "元";
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Prize:
|
||||
str += "抽奖活动奖励" + money + "元";
|
||||
break;
|
||||
case (int)GlobalEnumVars.UserBalanceSourceTypes.Service:
|
||||
str += "购买服务消费了" + money + "元";
|
||||
break;
|
||||
}
|
||||
//::todo 这里还可以做一些其他的校验
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户分享码(刻意封装)
|
||||
/// </summary>
|
||||
public static int GetShareCodeByUserId(int userId)
|
||||
{
|
||||
return (userId + 1234) * 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解码获取用户ID(刻意封装)
|
||||
/// </summary>
|
||||
public static int GetUserIdByShareCode(int userId)
|
||||
{
|
||||
return (userId / 3) - 1234;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将传入的字符串中间部分字符替换成特殊字符
|
||||
/// </summary>
|
||||
/// <param name="value">需要替换的字符串</param>
|
||||
/// <param name="startLen">前保留长度</param>
|
||||
/// <param name="endLen">尾保留长度</param>
|
||||
/// <param name="replaceChar">特殊字符</param>
|
||||
/// <returns>被特殊字符替换的字符串</returns>
|
||||
public static string BankCardNoFormat(string value, int startLen = 4, int endLen = 4, char specialChar = '*')
|
||||
{
|
||||
|
||||
int lenth = value.Length - startLen - endLen;
|
||||
|
||||
string replaceStr = value.Substring(startLen, lenth);
|
||||
|
||||
string specialStr = string.Empty;
|
||||
|
||||
for (int i = 0; i < replaceStr.Length; i++)
|
||||
{
|
||||
specialStr += specialChar;
|
||||
}
|
||||
|
||||
value = value.Replace(replaceStr, specialStr);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 格式化用户手机号码
|
||||
/// </summary>
|
||||
/// <param name="mobile"></param>
|
||||
/// <returns></returns>
|
||||
public static string FormatMobile(string mobile)
|
||||
{
|
||||
try
|
||||
{
|
||||
return mobile.Substring(0, 5) + "****" + mobile.Substring(9, 2);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return mobile.Substring(0, 5) + "****";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
103
CoreCms.Net.Utility/Hub/ChatHub.cs
Normal file
103
CoreCms.Net.Utility/Hub/ChatHub.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-09-06 23:39:37
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CoreCms.Net.Utility.Hub
|
||||
{
|
||||
public class ChatHub : Hub<IChatClient>
|
||||
{
|
||||
/// <summary>
|
||||
/// 向指定群组发送信息
|
||||
/// </summary>
|
||||
/// <param name="groupName">组名</param>
|
||||
/// <param name="message">信息内容</param>
|
||||
/// <returns></returns>
|
||||
public async Task SendMessageToGroupAsync(string groupName, string message)
|
||||
{
|
||||
await Clients.Group(groupName).ReceiveMessage(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加入指定组
|
||||
/// </summary>
|
||||
/// <param name="groupName">组名</param>
|
||||
/// <returns></returns>
|
||||
public async Task AddToGroup(string groupName)
|
||||
{
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出指定组
|
||||
/// </summary>
|
||||
/// <param name="groupName">组名</param>
|
||||
/// <returns></returns>
|
||||
public async Task RemoveFromGroup(string groupName)
|
||||
{
|
||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, groupName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向指定成员发送信息
|
||||
/// </summary>
|
||||
/// <param name="user">成员名</param>
|
||||
/// <param name="message">信息内容</param>
|
||||
/// <returns></returns>
|
||||
public async Task SendPrivateMessage(string user, string message)
|
||||
{
|
||||
await Clients.User(user).ReceiveMessage(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当连接建立时运行
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override Task OnConnectedAsync()
|
||||
{
|
||||
//TODO..
|
||||
return base.OnConnectedAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当链接断开时运行
|
||||
/// </summary>
|
||||
/// <param name="ex"></param>
|
||||
/// <returns></returns>
|
||||
public override Task OnDisconnectedAsync(System.Exception ex)
|
||||
{
|
||||
//TODO..
|
||||
return base.OnDisconnectedAsync(ex);
|
||||
}
|
||||
|
||||
|
||||
public async Task SendMessage(string user, string message)
|
||||
{
|
||||
await Clients.All.ReceiveMessage(user, message);
|
||||
}
|
||||
|
||||
//定于一个通讯管道,用来管理我们和客户端的连接
|
||||
//1、客户端调用 GetLatestCount,就像订阅
|
||||
public async Task GetLatestCount(string random)
|
||||
{
|
||||
//2、服务端主动向客户端发送数据,名字千万不能错
|
||||
var dt = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
await Clients.All.ReceiveUpdate(dt);
|
||||
//3、客户端再通过 ReceiveUpdate ,来接收
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
38
CoreCms.Net.Utility/Hub/IChatClient.cs
Normal file
38
CoreCms.Net.Utility/Hub/IChatClient.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-09-06 23:39:07
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CoreCms.Net.Utility.Hub
|
||||
{
|
||||
public interface IChatClient
|
||||
{
|
||||
/// <summary>
|
||||
/// SignalR接收信息
|
||||
/// </summary>
|
||||
/// <param name="message">信息内容</param>
|
||||
/// <returns></returns>
|
||||
Task ReceiveMessage(object message);
|
||||
|
||||
/// <summary>
|
||||
/// SignalR接收信息
|
||||
/// </summary>
|
||||
/// <param name="user">指定接收客户端</param>
|
||||
/// <param name="message">信息内容</param>
|
||||
/// <returns></returns>
|
||||
Task ReceiveMessage(string user, string message);
|
||||
|
||||
Task ReceiveUpdate(object message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user