增加项目,分层

This commit is contained in:
chfei committed 2026-09-11 19:11:12 +08:00
1 parent 6e995a5bdb
commit 0a3e5af6a9
234 files changed
+26994 -1

No files matched your search

@@ -0,0 +1,47 @@
using MAX.Core.DependencyInjection;
using Newtonsoft.Json.Linq;
using NLog;
using Store.Client.Apis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Store.Client.Services
{
/// <summary>
/// 缓存服务集群负载
/// </summary>
public class CacheServerService : ITransientDependency
{
private readonly CommonApi _commonApi;
private readonly ILogger _logger;
private readonly CommonApi _commonApi1;
/// <summary>
/// 缓存服务集群负载占比
/// </summary>
private static Dictionary<string, int> _cacheServerRatio { get; set; } = new Dictionary<string, int>();
public CacheServerService(ILogger logger, CommonApi commonApi)
{
_commonApi = IocManager.Resolve<CommonApi>();// commonApi;
_logger = logger;
_commonApi1 = commonApi;
}
/// <summary>
/// 默认数据
/// </summary>
private void SetDefaultData()
{
_cacheServerRatio.Add("https://temp-new1.taojinhu.com:10019", 5);
_cacheServerRatio.Add("https://t3.1n11.com", 5);
}
}
}
+83
View File
@@ -0,0 +1,83 @@
using MAX.Core.DependencyInjection;
using MAX.Core.Helpers;
using Store.Client;
using Store.Client.Apis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Store.Client.Services
{
internal class CommonService : ITransientDependency
{
private readonly CommonApi _commonApi;
public CommonService(CommonApi commonApi)
{
_commonApi = commonApi;
}
/// <summary>
/// 获取签名配置
/// </summary>
public void LoadAuthConfig()
{
var value = _commonApi.GetAuthConfig();
if (!string.IsNullOrEmpty(value))
{
ServerConfig.IsNewSignatureAuth = value.Equals("1");
}
}
/// <summary>
/// 获取本地与服务器时间差
/// </summary>
public void LoadServerTimeSpan()
{
DateTime SDateTime = _commonApi.GetServerTime();
long s = DateHelper.GetUnixTimestampInSeconds(SDateTime);
long a = DateHelper.GetUnixTimestampInSeconds(DateTime.Now);
ServerConfig.TimeDifferent = s - a;
}
/// <summary>
/// 获取服务器时间戳
/// </summary>
/// <returns></returns>
public static long GetServerUnix()
{
return DateHelper.GetUnixTimestampInSeconds(DateTime.Now) + ServerConfig.TimeDifferent;
}
/// <summary>
/// 获取服务器时间
/// </summary>
/// <returns></returns>
public static DateTime GetServerDataTime()
{
return DateHelper.ConvertFromUnixTimestampInSeconds(GetServerUnix());
}
///// <summary>
///// 获取服务器图片缓存
///// </summary>
///// <param name="imgUrl"></param>
///// <returns></returns>
//public string GetImageCache(string imgUrl)
//{
// string imgurl = "";
// HttpResult result = _commonApi.GetImageCache(imgUrl);
// if (result.StatusCode == System.Net.HttpStatusCode.OK)
// {
// result.Html = result.Html.Trim();
// if (Regex.IsMatch(result.Html, "^http"))
// {
// imgurl = result.Html;
// }
// }
// return imgurl;
//}
}
}
@@ -0,0 +1,37 @@
using MAX.Core.DependencyInjection;
using MediatR;
using Store.Framework.Inerterfaces;
using Store.Framework.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Store.Framework.Services;
public record UserNotification(UserInfo user) : INotification;
/// <summary>
/// 当前用户
/// </summary>
internal class CurrentUserService : ICurrentUser, ISingletonDependency, INotificationHandler<UserNotification>
{
public string UserName => User?.UserName;
public int GroupId => User.GroupId;
public UserInfo User { get; private set; }
public bool IsSuperAdmin => User.IsSa;
public bool IsAuthorized(string code)
{
return User.UserAuthority.Contains(code);
}
Task INotificationHandler<UserNotification>.Handle(UserNotification notification, CancellationToken cancellationToken)
{
User = notification.user;
return Task.CompletedTask;
}
}
+134
View File
@@ -0,0 +1,134 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
//using FkServices = LittleCow.Framework.Services;
namespace Store.Client.Services
{
///// <summary>
///// 商铺服务
///// </summary>
//internal class ShopService : ITransientDependency
//{
// private readonly ShopApi _shopApi;
// private readonly IEventBus _eventBus;
// public ShopService(ShopApi shopApi, IEventBus eventBus)
// {
// _shopApi = shopApi;
// _eventBus = eventBus;
// }
// /// <summary>
// /// 获取所有商铺信息
// /// </summary>
// /// <typeparam name="T"></typeparam>
// /// <returns></returns>
// public List<T> GetShops<T>() where T : ShopBase
// {
// HttpResult result = _shopApi.GetShops();
// if (result.StatusCode == System.Net.HttpStatusCode.OK)
// {
// StringBuilder sb = new StringBuilder();
// sb.Append("[");
// Regex regShopList = new Regex("<shop([^>]+?)>");
// if (regShopList.IsMatch(result.Html))
// {
// int index = 0;
// MatchCollection matchs = regShopList.Matches(result.Html);
// foreach (Match item in matchs)
// {
// string value = item.Value;
// value = value.Replace("<shop '", "{\"");
// value = value.Replace("'>", "\"}");
// value = value.Replace("':'", "\":\"");
// value = value.Replace("' '", "\",\"");
// if (index > 0)
// {
// sb.Append(",");
// }
// sb.Append(value);
// index++;
// }
// sb.Append("]");
// List<T> list = JsonConvert.DeserializeObject<List<T>>(sb.ToString());
// list.RemoveAll(a => string.IsNullOrEmpty(a.Name));
// return list;
// }
// }
// return new List<T>();
// }
// public string GetShopCookie(List<ShopBase> shops)
// {
// HttpResult result = _shopApi.GetShopsCookie(shops);
// if (result.StatusCode == System.Net.HttpStatusCode.OK)
// {
// MatchCollection matchs = Regex.Matches(result.Html, @"<shop id=""([^""]+?)"">([\w\W]+?)</shop>");
// if (matchs != null)
// {
// foreach (Match item in matchs)
// {
// string shopId = item.Groups[1].Value;
// string json = item.Groups[2].Value;
// var rootToken = JToken.Parse(json);
// string cookie = rootToken["Cookies"]?.ToString() ?? "";
// var shop = shops.FirstOrDefault(a => a.Id == shopId);
// if (shop != null)
// {
// shop.Cookie = new Cookies(cookie);
// }
// }
// }
// }
// return null;
// }
// /// <summary>
// /// 检测商铺登录状态
// /// </summary>
// public void CheckShopStatus(ShopBase shop)
// {
// HttpItem item = new HttpItem();
// item.URL = "https://myseller.taobao.com/ajaxProxy.do?_ksTS=1548152154745_13&callback=seller_layout_head&action=FrameworkLayoutAction&event_submit_do_layout_data=true";
// item.Referer = "https://myseller.taobao.com";
// item.Method = MethodType.Post;
// item.Cookie = shop.Cookie.GetCookieString();
// HttpResult result = HttpHelper.Request(item);
// if (result.StatusCode == System.Net.HttpStatusCode.OK)
// {
// string a = result.Html.Contains("\"shopName\":\"") ? "登录成功" : "会话已过期";
// }
// //string urlx =
// //string refere =
// //string htmlx = GetPostTaobaoHtml.GetUrl(urlx, refere, true, "", Shop.Cookies);
// //Shop.MsgForCookiesLogin = htmlx.Contains("\"shopName\":\"") ? "登录成功" : "会话已过期";
// //GetTaobaoShops.ShopsTemp.Add(Shop);
// }
// /// <summary>
// /// 获取值
// /// </summary>
// /// <param name="html"></param>
// /// <param name="reg"></param>
// /// <returns></returns>
// private string GetUserValue(string html, string reg)
// {
// string temp = Regex.Match(html, @"[""]" + reg + @"[""][\s]*:[\s]*[""]([^""]*?)[""]")?.Value;
// if (string.IsNullOrEmpty(temp))
// temp = Regex.Match(html, @"[']" + reg + @"['][\s]*:[\s]*[']([^']*?)[']")?.Groups[1].Value;
// if (string.IsNullOrEmpty(temp))
// temp = Regex.Match(html, @"['""]" + reg + @"['""][\s]*:[\s]*([\d]+)")?.Value;
// return temp;
// }
//}
}
+132
View File
@@ -0,0 +1,132 @@
using MAX.Core.Commons;
using MAX.Core.Cryptography;
using MAX.Core.DependencyInjection;
using MAX.Core.Helpers;
using Newtonsoft.Json;
using Store.Client.Apis;
using Store.Framework.Apis;
using Store.Framework.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace Store.Client.Services
{
/// <summary>
/// 用户操作
/// </summary>
public class UserService : ITransientDependency
{
private readonly UserApi _userApi;
public UserService(UserApi userApi)
{
_userApi = userApi;
}
/// <summary>
/// 用户登录
/// </summary>
/// <param name="user"></param>
public Result<HttpResult> Login(UserInfo user)
{
Result<HttpResult> ret = new Result<HttpResult>();
user.Password = MD5Helper.Md5_Lower32(user.Password);
HttpResult result = _userApi.Login(user.UserName, user.Password);
if (result.StatusCode == HttpStatusCode.Unauthorized)
{
ret.Msg = "登录失败\r\n链接异常请重试";
return ret;
}
if (string.IsNullOrEmpty(result.Html))
{
ret.Msg = "链接服务器失败";
return ret;
}
ApiResponse<UserInfo> apiResponse = null;
try
{
apiResponse = JsonConvert.DeserializeObject<ApiResponse<UserInfo>>(result.Html);
}
catch (JsonException)
{
}
if (apiResponse == null)
{
ret.Msg = result.Html;
return ret;
}
ret.Code = apiResponse.Code;
if (apiResponse.Code != 200 || apiResponse.Data == null)
{
ret.Msg = string.IsNullOrEmpty(apiResponse.Msg) ? result.Html : apiResponse.Msg;
return ret;
}
FillUserInfo(user, apiResponse.Data);
ret.Success = true;
ret.Msg = apiResponse.Msg;
ret.Data = result;
return ret;
}
/// <summary>
/// 将接口返回的登录用户信息回填到调用方对象。
/// </summary>
private static void FillUserInfo(UserInfo target, UserInfo source)
{
target.UserId = source.UserId;
target.UserName = source.UserName;
target.Password = source.Password;
target.GroupId = source.GroupId;
target.UserKey = source.UserKey;
target.CompanyId = source.CompanyId;
target.CompanyName = source.CompanyName;
target.NickName = source.NickName;
target.ParentUserName = source.ParentUserName;
target.SaLevel = source.SaLevel;
target.UserAuthority = source.UserAuthority;
target.ParentAuthority = source.ParentAuthority;
target.ForbiddenPage = source.ForbiddenPage;
target.Mobile = source.Mobile;
target.UserVersion = source.UserVersion;
target.UserVersionString = source.UserVersionString;
target.AuthorizedAmount = source.AuthorizedAmount;
target.Points = source.Points;
target.ShopPointsPerMonth = source.ShopPointsPerMonth;
target.Balance = source.Balance;
target.RechargeAmountTotal = source.RechargeAmountTotal;
target.PostagePerOrder = source.PostagePerOrder;
target.RefundPostagePerOrder = source.RefundPostagePerOrder;
target.GiftOemAmountPerOrder = source.GiftOemAmountPerOrder;
target.OemId = source.OemId;
target.OemName = source.OemName;
target.IsOemOwner = source.IsOemOwner;
target.EndDate = source.EndDate;
target.QqGroupNum = source.QqGroupNum;
target.QqGroupUrl = source.QqGroupUrl;
target.WechatUrl = source.WechatUrl;
target.Pinduoduo = source.Pinduoduo;
target.AlimamaDomain = source.AlimamaDomain;
target.AlimamaPid = source.AlimamaPid;
target.LockUserName = source.LockUserName;
target.WeakPassword = source.WeakPassword;
target.MessageInfo = source.MessageInfo;
target.AgentAuth = source.AgentAuth;
target.IsImport = source.IsImport;
target.CardId = source.CardId;
target.IsSa = source.IsSa;
target.AddTime = source.AddTime;
target.MdyTime = source.MdyTime;
target.Notes = source.Notes;
}
}
}