123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- using System;
- using System.Linq;
- using System.Web;
- using System.Text.RegularExpressions;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using MySystem.MainModels;
- using Library;
- namespace MySystem.Areas.Api.Controllers
- {
- public class BaseController : Controller
- {
- public IHttpContextAccessor _accessor;
- public readonly ILogger<BaseController> _logger;
- public readonly IOptions<Setting> _setting;
- public Setting AppSetting;
- public WebCMSEntities maindb = new WebCMSEntities();
- public MainModels2.WebCMSEntities maindb2 = new MainModels2.WebCMSEntities();
- public MiniModels.WebCMSEntities minidb = new MiniModels.WebCMSEntities();
- public string ApiKey = "G6H7@J8%";
- public string Host = Library.ConfigurationManager.AppSettings["Host"].ToString();
- public string SourceHost = Library.ConfigurationManager.AppSettings["SourceHost"].ToString();
- public string SpHost = Library.ConfigurationManager.AppSettings["SpHost"].ToString();
- public string OssHost = Library.ConfigurationManager.AppSettings["OssHost"].ToString();
- public string OssKey = Library.ConfigurationManager.AppSettings["OSSKey"].ToString();
- public string OssSecret = Library.ConfigurationManager.AppSettings["OSSSecret"].ToString();
- public string OssEndpoint = Library.ConfigurationManager.AppSettings["OSSEndpoint"].ToString();
- public string Database = Library.ConfigurationManager.AppSettings["Database"].ToString();
- public string defaultImage = Library.ConfigurationManager.AppSettings["Host"].ToString() + "/skin/app/default/static/images/header.png";
- //jwt参数
- public string JwtSecret = Library.ConfigurationManager.AppSettings["JwtSecret"].ToString();
- public string JwtIss = Library.ConfigurationManager.AppSettings["JwtIss"].ToString();
- public string JwtAud = Library.ConfigurationManager.AppSettings["JwtAud"].ToString();
- public int SysId;
- public int SysRealRole;
- public string SysUserName = "";
- public string SysRealName = "";
- public string RightInfo = "";
- public BaseController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting)
- {
- _accessor = accessor;
- _logger = logger;
- _setting = setting;
- AppSetting = setting.Value;
- Host = AppSetting.Host;
- Database = AppSetting.Database;
- }
- #region 接口通用DES解密
- public string DesDecrypt(string content)
- {
- content = HttpUtility.UrlDecode(content);
- return dbconn.DesDecrypt(content, "*ga34|^7");
- }
- #endregion
- #region 根据数字获取订单状态名称
- public string getOrderStatus(int status)
- {
- string result = "";
- switch (status)
- {
- case -1:
- result = "已取消";
- break;
- case 0:
- result = "未付款";
- break;
- case 1:
- result = "待发货";
- break;
- case 2:
- result = "待确认";
- break;
- case 3:
- result = "已完成";
- break;
- case 4:
- result = "已评价";
- break;
- case 5:
- result = "退款中";
- break;
- case 6:
- result = "已退款";
- break;
- default: break;
- }
- return result;
- }
- #endregion
- #region 根据数字获取报名状态名称
- public string getSignUpStatus(int status)
- {
- string result = "";
- switch (status)
- {
- case -1:
- result = "已取消";
- break;
- case 0:
- result = "未付款";
- break;
- case 1:
- result = "已付款";
- break;
- default: break;
- }
- return result;
- }
- #endregion
- #region 根据数字获取配送方式
- public string getMeterMode(int num)
- {
- string result = "";
- switch (num)
- {
- case 1:
- result = "快递";
- break;
- case 2:
- result = "EMS";
- break;
- case 3:
- result = "平邮";
- break;
- default:
- break;
- }
- return result;
- }
- #endregion
- #region 两点距离
- public double GetDistanceNumber(string start, string end)
- {
- if (!string.IsNullOrEmpty(start) && !string.IsNullOrEmpty(end))
- {
- string[] startpos = start.Split(',');
- string[] endpos = end.Split(',');
- double lng1 = double.Parse(startpos[0]);
- double lat1 = double.Parse(startpos[1]);
- double lng2 = double.Parse(endpos[0]);
- double lat2 = double.Parse(endpos[1]);
- double radLat1 = rad(lat1);
- double radLat2 = rad(lat2);
- double a = radLat1 - radLat2;
- double b = rad(lng1) - rad(lng2);
- double s = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2)));
- s = s * EARTH_RADIUS;
- s = Math.Round(s * 10000) / 10000;
- return s;
- }
- return 10000000;
- }
- private double rad(double d)
- {
- return d * Math.PI / 180.0;
- }
- private double EARTH_RADIUS = 6378.137;
- #endregion
- #region 默认姓名
- public string DefaultRealName(MainModels.Users user)
- {
- return string.IsNullOrEmpty(user.RealName) ? "码牌" + user.MakerCode : user.RealName;
- }
- #endregion
- #region 默认图片
- public string DefaultPic(string picpath)
- {
- if (!string.IsNullOrEmpty(picpath))
- {
- if (picpath.StartsWith("http"))
- {
- return picpath;
- }
- if (picpath.StartsWith("/miniappHeadPhoto"))
- {
- return OssHost + picpath;
- }
- }
- return OssHost + "/default.png";
- }
- #endregion
- #region 创客学堂/晨会图片
- public string StudyOrMeetDefaultPic(string picpath)
- {
- if (!string.IsNullOrEmpty(picpath))
- {
- if (picpath.StartsWith("http"))
- {
- return picpath;
- }
- if (picpath.Contains("/v2/"))
- {
- return OssHost + picpath;
- }
- return SourceHost + picpath;
- }
- return "";
- }
- #endregion
- #region 解析编辑器中的图片
- public string CheckContentImage(string content)
- {
- if (string.IsNullOrEmpty(content))
- {
- return "";
- }
- MatchCollection mc = Regex.Matches(content, "<img.*?/>");
- foreach (Match match in mc)
- {
- Match m = Regex.Match(match.Value, "src=\".*?\"");
- if (m.Success)
- {
- string srcString = m.Value;
- string picPath = srcString.Replace("src=\"", "").Replace("\"", "");
- if (!picPath.StartsWith("http"))
- {
- if (picPath.Contains("/v2/") || picPath.Contains("/up/"))
- {
- picPath = OssHost + picPath;
- }
- else
- {
- picPath = SourceHost + picPath;
- }
- content = content.Replace(srcString, "src=\"" + picPath + "\"");
- }
- }
- }
- return content;
- }
- #endregion
- }
- }
|