添加项目文件。

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

View File

@@ -0,0 +1,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;
}
}
}

View 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
}
}

View 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 32md5加密
/// <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 16md5加密
/// <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
}
}

View 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;
}
}
}

View 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 "";
}
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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
}
}

View 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;
}
}
}

View 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);
}
}
}
}

View 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;
}
}
}

View 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
{
}
}

View 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
{
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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];
}
}
}
}

View 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()
{
//记录哪里需要发送消息,统一处理
}
}
}

View 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;
}
}
}

View 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);
}
}
}
}

View 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;
}
}
}

View 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) + "****";
}
}
}
}