diff --git a/Server.sln b/Server.sln new file mode 100644 index 0000000..6fdabaa --- /dev/null +++ b/Server.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32112.339 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{1E0C7B53-1915-461F-99CA-3923BD35F849}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1E0C7B53-1915-461F-99CA-3923BD35F849}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E0C7B53-1915-461F-99CA-3923BD35F849}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E0C7B53-1915-461F-99CA-3923BD35F849}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E0C7B53-1915-461F-99CA-3923BD35F849}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F76D52ED-3117-4046-8E8D-3790DC325982} + EndGlobalSection +EndGlobal diff --git a/Server/App.config b/Server/App.config new file mode 100644 index 0000000..51c2b17 --- /dev/null +++ b/Server/App.config @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Server/Client.cs b/Server/Client.cs new file mode 100644 index 0000000..519ed0e --- /dev/null +++ b/Server/Client.cs @@ -0,0 +1,261 @@ +using Common.Models; +using Common.Models.UnqTables; +using Common.Utils; +using Microsoft.Owin.Hosting; +using Server.MyClass.Class; +using Server.Timers; +using Server.Winforms; +using SqlSugar; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.DbExtends; +using Common.Requests.Lianmengs; +using Common.DbExtends.Extends; +using System.Threading; +using Common.Models.PubClass; +using Common.Models.Enums; +using Server.MyClass.Caches; +using Server.Events; +using Server.Services.DataMigration; + +namespace Server +{ + internal class Client + { + public EventManager Events { get; private set; } + + private static Client _client; + public static Client SingleClient { get { if (_client == null) _client = new Client(); return _client; } } + + public string InternetIP { get; private set; } + public Config Config { get; private set; } + + public OwinServer OwinServer { get; private set; } + public string Url { get; set; } + private SessionTimer DeviceSessionTimer = null; + private TbUpdateorderTimer TbUpdateorderTimer = null; + private TbSpecialTimer TbSpecialTimer = null; + private OldUserActivationTimer OldUserActivationTimer = null; + private FinishOrderTimer FinishOrderTimer = null; + private MtOrderTimer MtOrderTimer = null; + private JDOrderTimer JDOrderTimer = null; + private PDDOrderTimer PDDOrderTimer = null; + private TbUpdateRefundOrderTimer TbUpdateRefundOrderTimer = null; + private UpdateCookiesTimer UpdateCookiesTimer = null; + private WeiPinHuiTimer WeiPinHuiTimer = null; + private SystemTimer SystemTimer = null; + /// + /// 收到的消息 + /// + public Dictionary ReplyMessages { get; set; } + private Client() + { + Config = new Config(); + InternetIP = Util.QueryInternetIP(); + } + public bool IsDebug { get; private set; } + + public void InitSystem() + { + this.Db.SetDefaultConnection(); + this.Db.InitTables(); + this.Db.InitDefaultData(); + this.Config.RuntimeCache = Db.GetMapValue("系统缓存", () => new RuntimeCache()); + this.Events = new EventManager(this); + OwinServer = new OwinServer(); + //MtOrderTimer = MyTimer.NewTimer(60); + JDOrderTimer = MyTimer.NewTimer(60); + //PDDOrderTimer = MyTimer.NewTimer(60); + //WeiPinHuiTimer = MyTimer.NewTimer(60); + //OldUserActivationTimer = MyTimer.NewTimer(60 * 60); + ReplyMessages = new Dictionary(); + //UpdateCookiesTimer = MyTimer.NewTimer(60); + //TbUpdateRefundOrderTimer = MyTimer.NewTimer(60 * 60); + //MyTimer.NewTimer(1); + //MyTimer.NewTimer(60); + //同步黑名单 + //MyTimer.NewTimer(1); + //同步商品黑名单 + //MyTimer.NewTimer(1); + //同步商店黑名单 + //MyTimer.NewTimer(60); + //同步抖音 + //MyTimer.NewTimer(60); + string baseAddress = $"http://*:{Config.Port}/"; + + WebApp.Start(url: baseAddress); + + var flag = false; + if (flag) //是否创建测试数据 + { + Db.CreateTestData(); + } + + //var u = Db.GetUser(1); + //if (u == null) u = new User() { Username = "test", UserType = Common.Models.Enums.UserType.微信用户, Headurl = String.Empty }; + //Db.Save(u); + EO.WebBrowser.Runtime.AddLicense( + "N4SOscufWbPw+g7kp+rp9um7aOPt9BDtrNzpz7iJWZeksefgpePzCOmMQ5ek" + + "scufWZekzQzjnZf4ChvkdpnJ4NnCoenz/hChWe3pAx7oqOXBs92wZ6emsdq9" + + "RoGkscufdabl/RfusLWRm8ufWZfAAB3jnunN/xHuWdvlBRC8W6i2wNywaKm0" + + "w9uhWer58/D3qeD29h7ArbSmwt2uaqizw9uxapmkBxDxrODz/+iha6emsdq9" + + "RoGkscufdert+Bngrez29unLn9D7BR7Wb8T66/nCm6y40hu2b8zFzui7aOrt" + + "+Bngrez29umMQ7Oz/RTinuX39umMQ3Xj7fQQ7azcwp61n1mXpM0X6Jzc8gQQ" + + "yJ21uur5sXGqusrz0XCwtMTis4+zs/0U4p7l9/b043c="); + + this.Url = $"http://{InternetIP}"; +#if DEBUG + IsDebug = true; + Url = $"http://127.0.0.1"; +#endif + if (Config.Port != 80) Url += ":" + Config.Port; + + Events.OrderChange += Events_OrderChange; + //new Thread(() => + //{ + // DataMigrationManageSerivce.Instance.Test(); + //}).Start(); + } + + private void Events_OrderChange(object sender, OrderChangeEventArgs e) + { + if (e.UserId != 0) + { + try + { + var User = Db.GetUser(e.UserId); + if (User != null) + { + SendClientMsg(User.RobotId, DeviceMessageType.订单状态改变, e); + } + } + catch (Exception ex) + { + Db.OnLog("通知用户订单状态", ex); + } + } + } + + public MainForm Form { get; set; } + public HttpRuntimeCache Cache { get; set; } = new HttpRuntimeCache(); + + public SqlSugarClient Db + { + get + { + var db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = $"Data Source={Config.MysqlHost};Initial Catalog={Config.MysqlName};Persist Security Info=True;User ID={Config.MysqlUser};Password={Config.MysqlPass};Port={Config.MysqlPort};Min Pool Size = 3; Max Pool Size = 100;CharSet=utf8mb4;AllowLoadLocalInfile=true;Allow Zero Datetime=True;SslMode=none;Convert Zero Datetime=True;",//连接符字串 + DbType = SqlSugar.DbType.MySql, //数据库类型 + IsAutoCloseConnection = true, + MoreSettings = new ConnMoreSettings() + { + IsAutoRemoveDataCache = true, + DefaultCacheDurationInSeconds = 86400, + }, + ConfigureExternalServices = new ConfigureExternalServices() + { + DataInfoCacheService = Cache, //配置我们创建的缓存类, + }, + }); + db.Aop.DataExecuting = (oldValue, entityInfo) => + { + db.SetSplitTableService(entityInfo.EntityName); + }; + + db.Aop.OnError = (ex) => + { + try + { + var temp = ex.Sql; + var time = db.Ado.SqlExecutionTime; + db.OnLog("SQL错误", $"{ex.Message},SQL => {ex.Sql}", Common.Models.Enums.LogType.错误); + } + catch (Exception) + { + } + }; + + db.Aop.OnLogExecuted = (sql, pars) => + { + if (db.Ado.SqlExecutionTime.TotalSeconds > 60) + { + try + { + var temp = sql; + + var time = db.Ado.SqlExecutionTime; + + } + catch (Exception) + { + // ignored + } + } + else if (IsDebug) + { + var temp = sql; + + foreach (var item in pars) temp = temp.Replace(item.ParameterName, $"'{item.Value}'"); + var time = db.Ado.SqlExecutionTime; + //Console.WriteLine($"SQL耗时:{time.TotalSeconds}、SQL => {sql}"); } + //WWW Console.WriteLine(sql,pars); + } + }; + return db; + } + } + + + + + public ConcurrentDictionary OnlineDevices { get { return Config.RuntimeCache.DeviceSessions; } } + public ConcurrentDictionary OnlineUsers { get { return Config.RuntimeCache.UserSessions; } } + public void SendAllClientMsg(DeviceMessageType Type, object Data) + { + var list = this.OnlineDevices.ToArray(); + foreach (var item in list) + { + SendClientMsg(item.Key, Type, Data); + } + } + + public DeviceMessage SendClientMsg(int RobotId, DeviceMessageType Type, Object Data = null) + { + var deviceId = OnlineDevices.FirstOrDefault(f => f.Value.RobotId == RobotId).Key; + if (!string.IsNullOrEmpty(deviceId)) + { + return SendClientMsg(deviceId, Type, Data); + } + return null; + } + public DeviceMessage SendClientMsg(string DeviceId, DeviceMessageType Type, Object Data = null) + { + if (OnlineDevices.ContainsKey(DeviceId)) + { + var msg = new DeviceMessage() { Type = Type, Content = Data, Time = Util.GetTimespan(DateTime.Now) }; + OnlineDevices[DeviceId].Messages.Enqueue(msg); + return msg; + } + return null; + } + public Task GetClientMsg(string Msgid, int Timeout = 60) + { + return Task.Factory.StartNew(() => + { + var ExpirationTime = DateTime.Now.AddSeconds(Timeout); + do + { + Thread.Sleep(1000); + if (ReplyMessages.ContainsKey(Msgid)) return ReplyMessages[Msgid]; + } while (ExpirationTime > DateTime.Now); + return null; + }); + } + + } +} diff --git a/Server/Config.cs b/Server/Config.cs new file mode 100644 index 0000000..4a9c128 --- /dev/null +++ b/Server/Config.cs @@ -0,0 +1,45 @@ +using CsharpHttpHelper; +using Server.Configs; +using Server.MyClass.Caches; +using Server.MyClass.Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server +{ + internal class Config + { + public int Port { get; set; } + public string Appsecret { get; set; } + + public string MysqlName { get; set; } + public string MysqlUser { get; set; } + public string MysqlPass { get; set; } + public string MysqlHost { get; set; } + public int MysqlPort { get; set; } + + public RuntimeCache RuntimeCache { get; set; } + + public IniHelper Ini { get; private set; } = new IniHelper(HttpExtend.MapFile("配置.ini","Config")); + public Config() + { + + Port = string.IsNullOrEmpty(Ini.GetValue("终端", "端口")) ? 80 : int.Parse(Ini.GetValue("终端", "端口")); + Appsecret = Ini.GetValue("终端", "密钥"); + if (string.IsNullOrEmpty(Appsecret)) + { + Appsecret = HttpExtend.GetMD5String(Guid.NewGuid().ToString()); + Ini.SetValue("终端", "密钥", Appsecret); + Ini.SetValue("终端", "端口", Port.ToString()); + } + MysqlName = Ini.GetValue("Mysql", "名称"); + MysqlUser = Ini.GetValue("Mysql", "账号"); + MysqlPass = Ini.GetValue("Mysql", "密码"); + MysqlHost = Ini.GetValue("Mysql", "IP"); + MysqlPort = string.IsNullOrEmpty(Ini.GetValue("Mysql", "端口")) ? 3306 : int.Parse(Ini.GetValue("Mysql", "端口")); + } + } +} diff --git a/Server/Controllers/AccountManagement/LianmengController(老妖).cs b/Server/Controllers/AccountManagement/LianmengController(老妖).cs new file mode 100644 index 0000000..f797c7e --- /dev/null +++ b/Server/Controllers/AccountManagement/LianmengController(老妖).cs @@ -0,0 +1,168 @@ +using Common.DbExtends.Extends; +using Common.DbExtends.Others; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.AccountManagement +{ + public partial class LianmengController + { + #region 抖音代码 + /// + /// 抖音- 查询 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetDouyinMedias() + { + try + { + var pageSize = GetInt("PageSize", true); + var index = GetInt("PageIndex", true); + + var LianmengId = GetInt("LianmengId"); + + var KeyWord = GetString("KeyWord"); + + var exp = Expressionable.Create(); + if (LianmengId > 0) + { + exp.And(f => f.LianmengId == LianmengId); + } + + if (!string.IsNullOrEmpty(KeyWord)) + { + exp.And(f => f.Pid.Contains(KeyWord) || f.AdzoneName.Contains(KeyWord) || f.Remark.Contains(KeyWord)); + } + + exp.And(f => f.IsDelete == false); + var tNumber = 0; + + var DataList = Db.Queryable() + .LeftJoin((f, r) => f.LianmengId == r.Id) + .Where(exp.ToExpression()) + .Select((f, r) => new DyMediaShow + { + Id = f.Id, + LianmengId = f.LianmengId, + LianmengNick = r.Nickname, + Pid = f.Pid, + AdzoneName = f.AdzoneName, + MediaType = f.MediaType, + MediaName = f.MediaName, + Remark = f.Remark + + }) + .ToPageList(index, pageSize, ref tNumber); + + //计算使用人数 + foreach (var item in DataList) + { + item.UseCnt = Db.Queryable().Count(p => p.TbMediaId1 == item.Id || p.TbMediaId2 == item.Id); + } + + return PutData(new PageResult(DataList, tNumber, pageSize, index)); + + } + catch (Exception ex) + { + return PutData(ex); + } + } + + /// + /// 抖音-新增 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddDouyinMedia() + { + var LianmengId = GetInt("LianmengId", true); + var AdzoneName = GetString("AdzoneName", true); + var MediaName = GetString("MediaName", true); + var MediaType = GetEnum("MediaType", true); + var Remark = GetString("Remark", false); + var lm = Db.GetLianmeng(LianmengId); + DouyinRequest req = new DouyinRequest(lm); + var Pid = req.CreateDouyinPidAdzone(AdzoneName, MediaName, MediaType, true); + var media = new DyMedia() + { + AdzoneName = AdzoneName, + MediaName = MediaName, + IsDelete = false, + LianmengId = LianmengId, + MediaType = MediaType, + Pid = Pid, + Remark = Remark, + UpdateTime = 0 + }; + Db.Save(media); + return PutData(media); + } + + /// + /// 抖音-修改推广位名称 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdDouyinAdzoneName() + { + var id = GetInt("MediaId", true); + var dyMedia = Db.GetDyMedia(id); + if (dyMedia == null) return PutData("编辑失败,未找到该推广位信息"); + + var dyLianmeng = Db.GetLianmeng(dyMedia.LianmengId); + if (dyLianmeng == null) return PutData("编辑失败,未找到该联盟信息"); + + + var AdzoneName = GetString("AdzoneName", true); + + DouyinRequest req = new DouyinRequest(dyLianmeng, dyMedia); + + + req.UpdateDouyinPidAdzone(dyMedia.Pid, AdzoneName, true); + + dyMedia.AdzoneName = AdzoneName; + var remark = GetString("Remark"); + if (!string.IsNullOrEmpty(remark)) + dyMedia.Remark = remark; + Db.Save(dyMedia); + return PutSuccess; + + } + + /// + /// 抖音 - 删除推广位 + /// + /// + public WebResult DelDouyinMedia() + { + var lianmengId = GetInt("LianmengId", true); + var dyPids = GetStringList("DyPids", true); + if (dyPids != null && dyPids.Count > 0) + { + //去抖音API执行真实删除 + var dyLianmeng = Db.GetLianmeng(lianmengId); + if (dyLianmeng != null) + { + var req = new DouyinRequest(dyLianmeng); + req.DeleteDouyinPidAdzone(dyPids.ToArray(), false); + } + + var rst =Db.Deleteable().Where(f => dyPids.Contains(f.Pid) && f.LianmengId == lianmengId).ExecuteCommand(); + DataCache.RemoveByPattern(@"cache_dymedia_[\d]+"); + } + return PutSuccess; + } + #endregion + } +} diff --git a/Server/Controllers/AccountManagement/LianmengController.cs b/Server/Controllers/AccountManagement/LianmengController.cs new file mode 100644 index 0000000..3f2717c --- /dev/null +++ b/Server/Controllers/AccountManagement/LianmengController.cs @@ -0,0 +1,1355 @@ +using Common.DbExtends; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using CsharpHttpHelper; +using Newtonsoft.Json.Linq; +using Server.MyClass.Views; +using Server.MyClass.Views.medias; +using Server.Utils; +using Server.Winforms.LoginForms; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Web.Http; + +namespace Server.Controllers.AccountManagement +{ + public partial class LianmengController : DefaultController + { + private const string VipAppId = "9f7a9b3d"; + private const string VipAppSecret = "074B0E1FFB94334FDEC993913884EC7F"; + + static object lockObj = new object(); + /// + /// 登录联盟 - 未完成 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult Login() + { + ///TODO:未完成联盟登录 + var type = GetEnum("LianmengType"); + var callBack = GetUrl() + "lianmeng/"; + string url = ""; + var token = Guid.NewGuid().ToString("N"); + + switch (type) + { + case LianmengType.淘宝联盟: + { + var time = DateTime.Now.AddSeconds(30); + var login = LianMengWebViewLoginHelper.Instance.GetViewLogin(); + if (login == null) + { + return PutData("服务启动失败,请重试。"); + } + + login.Start(LianmengType.淘宝联盟); + while (DateTime.Now < time) + { + if (!string.IsNullOrEmpty(login.QRCodeUrl)) + { + CacheHelper.GetIntance().SetCache(login.Msgid, login, 60 * 5); + return PutData(new { Msgid = login.Msgid, QRCodeUrl = login.QRCodeUrl }); + } + Thread.Sleep(100); + } + login.Dispose(); + return PutData("获取二维码失败,请稍后重试!"); + } + case LianmengType.京东联盟: + try + { + var authId = GetLong("authId", true); + var authUser = authId.ToString(); + var authKey = GetString("authKey", true).Trim(); + var remark = GetString("remark"); + var et = GetString("et", true); + var exTime = DateTime.ParseExact(et, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); + var jdApi = new JingdongRequest(new Lianmeng() { Username = authId.ToString(), Token = authKey, LianmengType = LianmengType.京东联盟 }); + var result = jdApi.SendData("jd.union.open.position.query", new { positionReq = new { unionType = 1, pageSize = 1, pageIndex = 1, unionId = authId, key = authKey } }); + JObject res = JObject.Parse(result.ToString()); + if ((int)res["code"] == 200) + { + string auIdStr = authId.ToString(); + + var tar = Db.Queryable().First(p => p.Username == auIdStr && p.LianmengType == LianmengType.京东联盟); + if (tar == null) + { + tar = new Lianmeng() { LianmengType = LianmengType.京东联盟, ExpirationTime = exTime, Nickname = authUser, Username = authUser, Token = authKey, Cookies = "", Remark = remark }; + } + else + { + tar.Username = authUser; + tar.Nickname = authUser; + tar.Token = authKey; + tar.Remark = remark; + tar.ExpirationTime = exTime; + } + Db.Save(tar); + if (tar.Id != 0) + { + GetJdAds(authUser, authKey, jdApi, tar); + return PutSuccess; + } + } + return PutError; + } + catch (Exception ex) + { + return PutData(ex); + } + case LianmengType.拼多多联盟: + callBack += "Pinduoduo"; + url = $"https://jinbao.pinduoduo.com/open.html?client_id=4ca7ddf2678b4ba39ecbc60c9d60b4ed&response_type=code&redirect_uri={HttpUtility.UrlEncode(callBack)}"; + break; + case LianmengType.唯品会联盟: + callBack += "vip"; + url = $"https://auth.vip.com/oauth2/authorize?client_id={VipAppId}&response_type=code&redirect_uri={HttpUtility.UrlEncode(callBack)}"; + break; + case LianmengType.苏宁联盟: + { + LoginSuningClass login = new LoginSuningClass(); + var qrurl = login.GetQRCodeUrl(); + if (!string.IsNullOrEmpty(qrurl)) + { + var guid = Guid.NewGuid().ToString("N"); + CacheHelper.GetIntance().SetCache(guid, login, 60 * 5); + return PutData(new { Msgid = guid, QRCodeUrl = login.QRCodeUrl }); + } + return PutData("获取二维码失败,请稍后重试!"); + } + + case LianmengType.抖音联盟: + { + var time = DateTime.Now.AddSeconds(30); + var login = LianMengWebViewLoginHelper.Instance.GetViewLogin(); + if (login == null) + { + return PutData("服务启动失败,请重试。"); + } + login.Start(LianmengType.抖音联盟); + while (DateTime.Now < time) + { + if (!string.IsNullOrEmpty(login.QRCodeUrl)) + { + CacheHelper.GetIntance().SetCache(login.Msgid, login, 60 * 5); + return PutData(new { Msgid = login.Msgid, QRCodeUrl = login.QRCodeUrl }); + } + Thread.Sleep(1000); + } + login.Dispose(); + //var login = Client.Form.GetLoginForm(); + //Client.Form.Invoke(new Action(delegate () + //{ + // login.Show(); + // login.Hide(); + // login.Start(LianmengType.抖音联盟); + //})); + //while (DateTime.Now < time) + //{ + // if (!string.IsNullOrEmpty(login.QRCodeUrl)) + // { + // CacheHelper.GetIntance().SetCache(login.Msgid, login, 60 * 5); + // return PutData(new { Msgid = login.Msgid, QRCodeUrl = login.QRCodeUrl }); + + // } + // Thread.Sleep(100); + //} + //login?.CloseUI(); + //if (string.IsNullOrEmpty(login.ErrorMsg)) return PutData(login.ErrorMsg); + return PutData("获取二维码失败,请稍后重试!"); + } + case LianmengType.美团联盟: + try + { + #region 第二版、自动登录 聂红利 + var loginType = GetInt("LoginType"); + if (loginType == 1) + { + var telNumber = GetString("TelNumber", true); + var mtLoginReq = new LoginMeituanClass(); + var errorMsg = mtLoginReq.SendLoginCode(telNumber); + if (!string.IsNullOrWhiteSpace(errorMsg)) return PutData(errorMsg); + var guid = Guid.NewGuid().ToString("N"); + CacheHelper.GetIntance().SetCache(guid, mtLoginReq, 60 * 5); + return PutData(new { Msgid = guid, QRCodeUrl = string.Empty }); + } + else if (loginType == 2) + { + var Msgid = GetString("Msgid", true); + var Code = GetString("Code", true); + var req = CacheHelper.GetIntance().GetCache(Msgid); + if (req == null) return PutData("登录失败,验证码已过期!"); + var mtReq = req as LoginMeituanClass; + if (mtReq == null) return PutData("登录失败,验证码已过期!"); + var loginResult = mtReq.VerifyLoginCode(Code); + if (!string.IsNullOrEmpty(loginResult)) return PutData(loginResult); + var tar = Db.Queryable().First(p => p.Username == mtReq.mobile && p.LianmengType == LianmengType.美团联盟); + if (tar == null) + { + tar = new Lianmeng() + { + LianmengType = LianmengType.美团联盟, + Username = mtReq.mobile + }; + } + + tar.Nickname = mtReq.nickName; + tar.Cookies = mtReq.Cookies; + tar.ExpirationTime = DateTime.Now.AddYears(100); + tar.Token = mtReq.appkey; + tar.ReToken = mtReq.utmSource; + Db.Save(tar); + + Task.Factory.StartNew(() => + { + var db = Db; + try + { + db.BeginTran(); + var medias = mtReq.GetMedias(); + foreach (var item in medias) + { + var media = db.Queryable().Where(f => f.LianmengId == tar.Id && f.AdzoneId == item.promotionId && f.MediaPId == item.mediaId).First(); + if (media == null) + media = new MtMedia() { LianmengId = tar.Id, AdzoneId = item.promotionId, MediaPId = item.mediaId }; + else if (media.UpdateTime == item.updateTime) continue; + + media.MediaType = (MTMediaType)item.mediaType; + media.AdzoneName = item.promotionName; + media.MediaName = item.mediaName; + media.UpdateTime = item.updateTime; + if (media.Id == 0) + db.Insertable(media).ExecuteCommand(); + else + db.Updateable(media).ExecuteCommand(); + } + db.CommitTran(); + } + catch (Exception) + { + db.RollbackTran(); + } + }); + return PutData(tar); + } + + #endregion + + #region 第一版、人工录入 赵家保 + else + { + + var appKey = GetString("appKey", true); + var utmSource = GetString("utmSource", true); + var username = GetString("username", true); + var remark = GetString("remark", false); + var item = Db.Queryable().First(p => p.Username == username && p.LianmengType == LianmengType.美团联盟); + if (item == null) + { + item = new Lianmeng() + { + LianmengType = LianmengType.美团联盟, + ExpirationTime = DateTime.Now.AddYears(100), + Cookies = "", + Username = username, + Nickname = "", + Remark = remark, + ReToken = utmSource, + Token = appKey + }; + } + else + { + item.Username = username; + item.Remark = remark; + item.ReToken = utmSource; + item.Token = appKey; + } + var res = new MTRequest(item).CPSOrderList(DateTime.Now, DateTime.Now, 1, 50, out _); + if (res == null) + { + return PutData("登录失败,您输入的appKey或utmSource不正确!"); + } + Db.Save(item); + if (item.Id != 0) + { + return PutSuccess; + } + return PutError; + + } + #endregion + + } + catch (Exception ex) + { + return PutData(ex); + } + default: + return PutData("暂不支持该联盟账号登录"); + } + return PutData(new { Url = url, Token = token }); + + } + + + + + /// + /// 获取京东的推广位(同步获取) + /// + /// + /// + /// + /// + private void GetJdAds(string authUser, string authKey, JingdongRequest jdApi, Lianmeng lianmeng) + { + Task.Factory.StartNew(() => + { + //TODO 使用API获取京东推广位 + var req = new JingdongRequest(lianmeng); + req.GetPositionListAll(items => + { + var db = Db; + db.BeginTran(); + try + { + foreach (JToken token in items) + { + var adzoneId = token["id"].Value(); + var adzonename = token["spaceName"].Value(); + var info = db.Queryable().Where(w => w.LianmengId == lianmeng.Id && w.AdzoneId == adzoneId).First(); + if (info == null) + { + info = new JdMedia(); + info.AdzoneId = adzoneId; + info.LianmengId = lianmeng.Id; + info.AdzoneName = adzonename; + info.IsRemove = false; + info.Remark = ""; + db.Insertable(info).ExecuteCommand(); + } + else if (info.AdzoneName != adzonename) + { + info.AdzoneName = adzonename; + db.Updateable(info).ExecuteCommand(); + } + } + db.CommitTran(); + } + catch (Exception e) + { + Db.OnLog("同步推广位", e); + db.RollbackTran(); + } + return false; + }); + }); + } + + /// + /// 获得登录状态 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetLoginStatus() + { + var msgId = GetString("Msgid", true); + var result = CacheHelper.GetIntance().GetCache(msgId); + if (result == null) + { + return PutData(new { Msgid = msgId, QRCodeStatus = LoginQRCodeStatus.操作超时 }); + } + var login = result as LianmengWebViewLogin; + + if (login == null) + { + if (result is LoginSuningClass login2) + { + return PutData(new { Msgid = msgId, QRCodeStatus = login2.QRCodeStatus, ErrorMsg = login2.ErrorMsg }); + } + return PutData("二维码获取失败!"); + } + else + { + return PutData(new { Msgid = login.Msgid, QRCodeStatus = login.QRCodeStatus, ErrorMsg = login.ErrorMsg }); + } + } + private string GetUrl() + { + var url = $"http://{Client.InternetIP}:{Client.Config.Port}/"; +#if DEBUG + url = $"http://127.0.0.1/"; +#endif + return url; + } + + /// + /// 拼多多回调 + /// + [HttpGet] + public IHttpActionResult Pinduoduo() + { + var url = GetUrl(); + try + { + var Params = HttpUtility.ParseQueryString(Request.RequestUri.Query); + var code = Params.Get("code"); + var state = Params.Get("state"); + + string json = HttpHelper.ObjectToJson(new + { + client_id = "4ca7ddf2678b4ba39ecbc60c9d60b4ed", + code = code, + grant_type = "authorization_code", + client_secret = "c05574e5bbb450bb1ad66e08cdccf05a8a274161" + }); + + HttpHelper http = new HttpHelper(); + var item = http.GetItem("http://open-api.pinduoduo.com/oauth/token", "", json); + item.ContentType = "application/json"; + var html = http.GetHtml(item).Html; + Newtonsoft.Json.Linq.JObject target = Newtonsoft.Json.Linq.JObject.Parse(html); + var UserId = target["owner_id"].ToString(); + var Lianmeng = Db.Queryable().First(f => f.Username == UserId && f.LianmengType == LianmengType.拼多多联盟); + if (Lianmeng == null) + { + Lianmeng = new Lianmeng() { Username = UserId, LianmengType = LianmengType.拼多多联盟 }; + } + Lianmeng.Nickname = target["owner_name"].ToString(); + Lianmeng.Token = target["access_token"].ToString(); + Lianmeng.ExpirationTime = DateTime.Now.AddDays(30); + Lianmeng.ReToken = target["refresh_token"].ToString(); + Db.Save(Lianmeng); + //同步推广位 + var req = new PinduoRequest(Lianmeng); + req.GetPositionList(items => + { + var db = Db; + db.BeginTran(); + try + { + foreach (JToken token in items) + { + //var adzoneId = token["p_id_list"].First["p_id"].Value(); + //var adzonename = token["p_id_list"].First["pid_name"].Value(); + var adzoneId = token["p_id"].Value(); + var adzonename = token["pid_name"].Value(); + var info = db.Queryable().Where(w => w.LianmengId == Lianmeng.Id && w.AdzoneId == adzoneId).First(); + if (info == null) + { + info = new PddMedia(); + info.AdzoneId = adzoneId; + info.LianmengId = Lianmeng.Id; + info.AdzoneName = adzonename; + info.IsRemove = false; + info.Remark = ""; + db.Insertable(info).ExecuteCommand(); + } + else if (info.AdzoneName != adzonename) + { + info.AdzoneName = adzonename; + db.Updateable(info).ExecuteCommand(); + } + } + db.CommitTran(); + } + catch (Exception e) + { + Db.OnLog("同步推广位", e); + db.RollbackTran(); + } + return false; + }); + + return Redirect($"{url}?t={LianmengType.拼多多联盟}&f=true"); + } + catch + { + return Redirect($"{url}?t={LianmengType.拼多多联盟}&f=false"); + } + + + } + + /// + /// 淘宝回调 + /// + /// + [HttpGet] + public WebResult LoginTaobaoCallback() + { + var url = GetUrl(); + try + { + //http://127.0.0.1:81/lianmeng/logintaobaoresult/?access_token=6100a011713579cffde010fc5c5faa734a72a17bcf96283824166474&token_type=Bearer&expires_in=2592000&refresh_token=6100a01171d612063de010fc5c5faa734a72a17bcf96283824166474&re_expires_in=2592000&r1_expires_in=2592000&r2_expires_in=86400&taobao_open_uid=AAHwsrlwAJVa5gTotY3c-Pas&taobao_user_id=824166474&taobao_user_nick=oreoa&w1_expires_in=2592000&w2_expires_in=300&state=http%3A%2F%2F127.0.0.1%3A81%2Flianmeng%2Flogintaobaoresult&top_sign=37E502E07685C07A0DFB104A30837A6B + var Params = HttpUtility.ParseQueryString(Request.RequestUri.Query); + var Token = Params.Get("access_token"); + var UserId = Params.Get("taobao_user_id"); + var UserNick = Params.Get("taobao_user_nick"); + + var Lianmeng = Db.Queryable().WithCache().First(f => f.Username == UserId && f.LianmengType == LianmengType.淘宝联盟); + if (Lianmeng == null) + { + Lianmeng = new Lianmeng() { Username = UserId, LianmengType = LianmengType.淘宝联盟 }; + } + + Lianmeng.Nickname = UserNick; + Lianmeng.Token = Token; + Lianmeng.ExpirationTime = DateTime.Now.AddDays(30); + Db.Storageable(Lianmeng).ExecuteCommand(); + //Db.Save(Lianmeng); + return PutSuccess; + } + catch (Exception) + { + return PutError; + } + } + + /// + /// 唯品会回调 + /// + [HttpGet] + public IHttpActionResult Vip() + { + var url = GetUrl(); + try + { + var Params = HttpUtility.ParseQueryString(Request.RequestUri.Query); + var code = Params.Get("code"); + var state = Params.Get("state"); + + var http = new HttpHelper(); + var item = new HttpItem() { Method = "post", URL = $"https://auth.vip.com/oauth2/token?client_id={VipAppId}&client_secret={VipAppSecret}&grant_type=authorization_code&redirect_uri={HttpUtility.UrlEncode(url)}&request_client_ip=127.0.0.1&code={code}" }; + var html = http.GetHtml(item).Html; + + Newtonsoft.Json.Linq.JObject target = Newtonsoft.Json.Linq.JObject.Parse(html); + + var UserId = target["open_id"].ToString(); + + var Lianmeng = Db.Queryable().First(f => f.Username == UserId && f.LianmengType == LianmengType.唯品会联盟); + if (Lianmeng == null) + { + Lianmeng = new Lianmeng() { Username = UserId, LianmengType = LianmengType.唯品会联盟 }; + } + + Lianmeng.Nickname = ""; + Lianmeng.Token = target["access_token"].ToString(); + Lianmeng.ExpirationTime = DateTime.Now.AddSeconds((int)target["expires_in"]); + Lianmeng.ReToken = target["refresh_token"].ToString(); + + Db.Save(Lianmeng); + GetVipAds(Lianmeng); + + return Redirect($"{url}?t={LianmengType.唯品会联盟}&f=true"); + } + catch + { + return Redirect($"{url}?t={LianmengType.唯品会联盟}&f=false"); + } + } + + /// + /// 获取唯品会推广位信息 + /// + private void GetVipAds(Lianmeng Lianmeng) + { + Task.Factory.StartNew(() => + { + var req = new WeipinhuiRequest(Lianmeng); + req.GetWphTgwAll(items => + { + var db = Db; + db.UseTran(() => + { + foreach (var token in items) + { + string adzoneName = token["pidName"].Value(); + var item = Db.Queryable().Where(f => f.AdzoneName == adzoneName && f.LianmengId == Lianmeng.Id).First(); + if (item != null) + { + continue; + } + item = new WphMedia(); + item.AdzoneId = token["pid"].Value(); + item.AdzoneName = adzoneName; + item.LianmengId = Lianmeng.Id; + item.Remark = ""; + Db.Insertable(item).ExecuteCommand(); + } + }, (ex) => + { + db.OnLog("登陆同步唯品会推广位", ex); + }); + return false; + }); + }); + } + + /// + /// 分页查询联盟 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetLianmengs() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var LmType = GetEnum("Type"); + if (PageSize > 100) PageSize = 100; + var TotalNumber = 0; + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword) || f.Username.Contains(Keyword) || f.Remark.Contains(Keyword)); + } + if (LmType != LianmengType.无) + { + exp.And(f => f.LianmengType == LmType); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + + /// + /// 更新联盟 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult UpdLianmeng() + { + //TODO:编辑联盟信息,目前值做了备注修改 + var Id = GetInt("Id", true); + var Remark = GetString("Remark"); + var Lianmeng = Db.GetLianmeng(Id); + if (Lianmeng == null) return PutData("联盟账号不存在!"); + Lianmeng.Remark = Remark; + Db.Save(Lianmeng); + return PutSuccess; + } + + /// + /// 删除联盟 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult DelLianmeng() + { + var Id = GetInt("Id", true); + var Data = Db.GetLianmeng(Id); + if (Data != null && Db.Delete(Data) > 0) return PutSuccess; + else return PutData("删除失败,未找到数据!"); + } + + /// + /// 新增推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddTaobaoMedia() + { + try + { + var LianmengId = GetInt("LianmengId", true); + var SiteId = GetString("SiteId", true); + var AdzoneId = GetString("AdzoneId", true); + var Remark = GetString("Remark"); + var AppKey = GetString("AppKey"); + var AppSecret = GetString("AppSecret"); + + var Lianmeng = Db.Queryable().Where(f => f.Id == LianmengId).First(); + if (Lianmeng == null) return PutData("新增失败,联盟ID不存在!"); + + var TbMedia = Db.Queryable().Where(f => f.LianmengId == LianmengId && f.SiteId == SiteId && f.AdzoneId == AdzoneId).First(); + if (TbMedia != null) return PutData("新增失败,该推广位已存在!"); + + TbMedia = new TbMedia() + { + LianmengId = LianmengId, + SiteId = SiteId, + AdzoneId = AdzoneId, + Remark = Remark, + AppKey = AppKey, + AppSecret = AppSecret + }; + + Db.Save(TbMedia); + return PutData(TbMedia); + } + catch (Exception ex) + { + return PutData(ex); + } + } + + /// + /// 修改推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult UpdTaobaoMedia() + { + try + { + var MediaId = GetInt("MediaId", true); + var TbMedia = Db.GetTbMedia(MediaId); + if (TbMedia == null) return PutData("修改失败,该推广位不存在!"); + + + var LianmengId = GetInt("LianmengId", true); + var SiteId = GetString("SiteId", true); + var AdzoneId = GetString("AdzoneId", true); + var Remark = GetString("Remark"); + var AppKey = GetString("AppKey"); + var AppSecret = GetString("AppSecret"); + + var Lianmeng = Db.Queryable().Where(f => f.Id == LianmengId).First(); + if (Lianmeng == null) return PutData("修改失败,联盟ID不存在!"); + + var DbTbMedia = Db.Queryable().Where(f => f.LianmengId == LianmengId && f.SiteId == SiteId && f.AdzoneId == AdzoneId).First(); + if (DbTbMedia != null) + { + if (DbTbMedia.Id != MediaId) + return PutData("修改失败,该推广位已存在!"); + } + + TbMedia.LianmengId = LianmengId; + TbMedia.SiteId = SiteId; + TbMedia.AdzoneId = AdzoneId; + TbMedia.Remark = Remark; + TbMedia.AppKey = AppKey; + TbMedia.AppSecret = AppSecret; + + + Db.Save(TbMedia); + return PutData(TbMedia); + } + catch (Exception ex) + { + return PutData(ex); + } + } + + /// + /// 删除推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult DelTaobaoMedia() + { + var MediaId = GetInt("MediaId", true); + Db.Updateable() + .Where(f => f.Id == MediaId) + .SetColumns(f => f.IsRemove == true) + .ExecuteCommand(); + return PutSuccess; + } + + /// + /// 删除推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult DelTaobaoMedias() + { + try + { + var Ids = GetIntList("Ids", true); + Db.Updateable() + .Where(f => Ids.Contains(f.Id)) + .SetColumns(f => f.IsRemove == true) + .ExecuteCommand(); + return PutSuccess; + } + catch (Exception ex) + { + return PutData(ex); + } + } + + /// + /// 查询推广位列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetTaobaoMedias() + { + try + { + var pageSize = GetInt("PageSize", true); + var index = GetInt("PageIndex", true); + + var LianmengId = GetInt("LianmengId"); + var SiteId = GetString("SiteId"); + var AdzoneId = GetString("AdzoneId"); + var Remark = GetString("Remark"); + + + + + var exp = Expressionable.Create(); + if (LianmengId > 0) + { + exp.And(f => f.LianmengId == LianmengId); + } + + if (!string.IsNullOrEmpty(SiteId)) + { + exp.And(f => f.SiteId == SiteId); + } + + if (!string.IsNullOrEmpty(AdzoneId)) + { + exp.And(f => f.AdzoneId == AdzoneId); + } + + if (!string.IsNullOrEmpty(Remark)) + { + exp.And(f => f.Remark.Contains(Remark)); + } + + + exp.And(f => f.IsRemove == false); + var tNumber = 0; + + var DataList = Db.Queryable() + .LeftJoin((f, r) => f.LianmengId == r.Id) + .Where(exp.ToExpression()) + .Select((f, r) => new TbMediaShow + { + Id = f.Id, + LianmengId = f.LianmengId, + SiteName = f.SiteName, + AdzoneId = f.AdzoneId, + AdzoneName = f.AdzoneName, + AppKey = f.AppKey, + AppSecret = f.AppSecret, + IsSpecial = f.IsSpecial, + IsTlj = !string.IsNullOrEmpty(f.AppKey) && !string.IsNullOrEmpty(f.AppSecret), + LmName = r.Nickname, + LmAcc = r.Username, + Pid = f.Pid, + Remark = f.Remark, + SiteId = f.SiteId, + //UseCnt = Db.Queryable().Where(p => p.TbMediaId1 == f.Id || p.TbMediaId2 == f.Id).Count(), + //Db.Queryable().Count(p=>p.TbMediaId1 == f.Id || p.TbMediaId2 == f.Id) + }) + .ToPageList(index, pageSize, ref tNumber); + foreach (var item in DataList) + { + item.UseCnt = Db.Queryable().Count(p => p.TbMediaId1 == item.Id || p.TbMediaId2 == item.Id); + } + + + return PutData(new PageResult(DataList, tNumber, pageSize, index)); + + } + catch (Exception ex) + { + return PutData(ex); + } + } + /// + /// 新增美团推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddMtMedia() + { + try + { + var adzoneId = GetString("AdzoneId", true); + var lianmengId = GetInt("LianmengId", true); + var adzoneName = GetString("AdzoneName", true); + var remark = GetString("Remark", false); + var mediaType = GetEnum("MediaType", true); + var mediaPId = GetString("MediaPId", true); + var mediaName = GetString("MediaName", true); + var item = Db.Queryable().Where(f => f.AdzoneId == adzoneId && f.LianmengId == lianmengId).First(); + if (item != null) + { + return PutData("新增失败,该推广位已存在!"); + } + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + + var req = new MTRequest(lianmeng); + var result = req.PromotionLink("吃货天天省", "0AlN4OtEIa", adzoneId, 2, 1, false); + if (result.code != 200) + { + return PutData(result.msg); + } + + + item = new MtMedia() + { + AdzoneId = adzoneId, + AdzoneName = adzoneName, + LianmengId = lianmengId, + MediaName = mediaName, + MediaPId = mediaPId, + MediaType = mediaType, + Remark = remark + }; + Db.Insertable(item).ExecuteReturnEntityAsync(); + return PutData(new MTMediaShow() + { + Id = item.Id, + LianmengId = item.LianmengId, + AdzoneId = item.AdzoneId, + AdzoneName = item.AdzoneName, + Remark = item.Remark, + MediaName = item.MediaName, + MediaPId = item.MediaPId, + MediaType = item.MediaType + }); + } + catch (Exception ex) + { + return PutData(ex); + } + } + + + /// + /// 编辑美团推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult UdpMtMedia() + { + try + { + var adzoneId = GetString("AdzoneId", true); + var lianmengId = GetInt("LianmengId", true); + var adzoneName = GetString("AdzoneName", true); + var remark = GetString("Remark", false); + var mediaType = GetEnum("MediaType", true); + var mediaPId = GetString("MediaPId", true); + var mediaName = GetString("MediaName", true); + var item = Db.Queryable().Where(f => f.AdzoneId == adzoneId && f.LianmengId == lianmengId).First(); + if (item == null) + { + return PutData("编辑失败,该推广位不存在!"); + } + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + var req = new MTRequest(lianmeng); + var result = req.PromotionLink("吃货天天省", "0AlN4OtEIa", adzoneId, 2, 1, false); + if (result.code != 200) + { + return PutData(result.msg); + } + item.AdzoneId = adzoneId; + item.AdzoneName = adzoneName; + item.LianmengId = lianmengId; + item.MediaName = mediaName; + item.MediaPId = mediaPId; + item.MediaType = mediaType; + item.Remark = remark; + Db.Insertable(item).ExecuteReturnEntityAsync(); + return PutSuccess; + } + catch (Exception ex) + { + return PutData(ex); + } + } + /// + /// 删除美团推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult RemoveMtMedia() + { + try + { + var adzoneId = GetString("AdzoneId", true); + var lianmengId = GetInt("LianmengId", true); + var item = Db.Queryable().Where(f => f.AdzoneId == adzoneId && f.LianmengId == lianmengId).First(); + if (item == null) + { + return PutData("推广位不存在"); + } + else + { + item.IsDelete = true; + Db.Updateable(item).ExecuteCommand(); + } + + return PutSuccess; + } + catch (Exception ex) + { + return PutData(ex); + } + } + /// + /// 查询美团推广位列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetMTMedias() + { + try + { + var pageSize = GetInt("PageSize", true); + var index = GetInt("PageIndex", true); + var lianmengId = GetInt("LianmengId"); + var keyword = GetString("Keyword"); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(keyword)) + { + exp.And(f => f.AdzoneName.Contains(keyword) || f.Remark.Contains(keyword)); + } + exp.And(f => f.IsDelete == false); + var tNumber = 0; + var DataList = Db.Queryable() + .Where(f => f.LianmengId == lianmengId) + .Where(exp.ToExpression()) + .Select(f => new MTMediaShow + { + Id = f.Id, + LianmengId = f.LianmengId, + AdzoneId = f.AdzoneId, + AdzoneName = f.AdzoneName, + Remark = f.Remark, + MediaName = f.MediaName, + MediaPId = f.MediaPId, + MediaType = f.MediaType + }) + .ToPageList(index, pageSize, ref tNumber); + foreach (var item in DataList) + { + item.UseCnt = Db.Queryable().Count(p => p.MtMediaId1 == item.Id || p.MtMediaId2 == item.Id); + } + return PutData(new PageResult(DataList, tNumber, pageSize, index)); + } + catch (Exception ex) + { + return PutData(ex); + } + } + + + /// + /// 新增京东推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddJDMedia() + { + try + { + var lianmengId = GetInt("LianmengId", true); + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + var adzoneName = GetString("AdzoneName", true); + var siteId = GetLong("SiteId"); + var remark = GetString("Remark"); + var item = Db.Queryable().Where(f => f.AdzoneName == adzoneName && f.LianmengId == lianmengId).First(); + if (item != null) + { + return PutData("新增失败,该推广位名称相同!"); + } + var req = new JingdongRequest(lianmeng); + var jobj = req.CreatePosition(4, 4, new string[] { adzoneName }, siteId); + if (jobj["code"].Value() != 200) + { + return PutData(jobj["message"].Value()); + } + item = new JdMedia(); + var property = jobj["data"]["resultList"][adzoneName] as JValue; + item.AdzoneId = property.Value?.ToString(); + item.AdzoneName = adzoneName; + item.LianmengId = lianmengId; + item.Remark = remark; + item.PId = jobj["data"]["pid"][adzoneName].Value(); + item.IsRemove = false; + Db.Insertable(item).ExecuteReturnEntityAsync(); + return PutSuccess; + } + catch (Exception ex) + { + return PutData(ex); + } + } + /// + /// 删除京东推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult RemoveJDMedia() + { + var lianmengId = GetInt("LianmengId", true); + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + var adzoneName = GetString("AdzoneName", true); + var item = Db.Queryable().Where(f => f.AdzoneName == adzoneName && f.LianmengId == lianmengId).First(); + if (item == null) + { + return PutData("删除失败,推广位不存在"); + } + item.IsRemove = true; + Db.Updateable(item).ExecuteCommand(); + return PutSuccess; + } + + /// + /// 查询京东推广位列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetJDMedias() + { + try + { + var pageSize = GetInt("PageSize", true); + var index = GetInt("PageIndex", true); + var lianmengId = GetInt("LianmengId"); + var keyword = GetString("Keyword"); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(keyword)) + { + exp.And(f => f.AdzoneName.Contains(keyword) || f.Remark.Contains(keyword)); + } + var tNumber = 0; + var DataList = Db.Queryable() + .Where(f => f.LianmengId == lianmengId && f.IsRemove == false) + .Where(exp.ToExpression()) + .Select(f => f) + .ToPageList(index, pageSize, ref tNumber); + return PutData(new PageResult(DataList, tNumber, pageSize, index)); + } + catch (Exception ex) + { + return PutData(ex); + } + } + /// + /// 新增拼多多推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddPDDMedia() + { + try + { + var lianmengId = GetInt("LianmengId", true); + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + var adzoneName = GetString("AdzoneName", true); + var remark = GetString("Remark", false); + var item = Db.Queryable().Where(f => f.AdzoneName == adzoneName && f.LianmengId == lianmengId).First(); + if (item != null) + { + return PutData("新增失败,该推广位名称相同!"); + } + var req = new PinduoRequest(lianmeng); + var jobj = req.CreatePosition(adzoneName); + if (jobj["sub_code"] != null && jobj["sub_code"]?.Value() != 200) + { + return PutData(jobj["sub_msg"].Value()); + } + item = new PddMedia(); + item.AdzoneId = jobj["p_id_list"].First["p_id"].Value(); + item.AdzoneName = adzoneName; + item.LianmengId = lianmengId; + item.Remark = remark; + item.IsRemove = false; + Db.Insertable(item).ExecuteReturnEntityAsync(); + return PutSuccess; + } + catch (Exception ex) + { + return PutData(ex); + } + } + /// + /// 删除拼多多推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult RemovePDDMedia() + { + var lianmengId = GetInt("LianmengId", true); + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + var adzoneName = GetString("AdzoneName", true); + var item = Db.Queryable().Where(f => f.AdzoneName == adzoneName && f.LianmengId == lianmengId).First(); + if (item == null) + { + return PutData("删除失败,推广位不存在"); + } + item.IsRemove = true; + Db.Updateable(item).ExecuteCommand(); + return PutSuccess; + } + + /// + /// 查询拼多多推广位列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetPDDMedias() + { + try + { + var pageSize = GetInt("PageSize", true); + var index = GetInt("PageIndex", true); + var lianmengId = GetInt("LianmengId"); + var keyword = GetString("Keyword"); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(keyword)) + { + exp.And(f => f.AdzoneName.Contains(keyword) || f.Remark.Contains(keyword)); + } + var tNumber = 0; + var DataList = Db.Queryable() + .Where(f => f.LianmengId == lianmengId && f.IsRemove == false) + .Where(exp.ToExpression()) + .Select(f => f) + .ToPageList(index, pageSize, ref tNumber); + return PutData(new PageResult(DataList, tNumber, pageSize, index)); + } + catch (Exception ex) + { + return PutData(ex); + } + } + + + /// + /// 新增唯品会推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddWPHMedia() + { + try + { + var lianmengId = GetInt("LianmengId", true); + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + var adzoneName = GetString("AdzoneName", true); + var remark = GetString("Remark", false); + var item = Db.Queryable().Where(f => f.AdzoneName == adzoneName && f.LianmengId == lianmengId).First(); + if (item != null) + { + return PutData("新增失败,该推广位名称相同!"); + } + var req = new WeipinhuiRequest(lianmeng); + var jobj = req.CreateWphTgw(new List() { adzoneName }); + if (jobj["returnCode"] != null && jobj["returnCode"]?.Value() != 0) + { + return PutData("创建推广位失败"); + } + item = new WphMedia(); + item.AdzoneId = jobj["result"]["pidInfoList"].First["pid"].Value(); + item.AdzoneName = adzoneName; + item.LianmengId = lianmengId; + item.Remark = remark; + Db.Insertable(item).ExecuteCommand(); + return PutSuccess; + } + catch (Exception ex) + { + return PutData(ex); + } + } + + + /// + /// 删除唯品会推广位 + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult RemoveWPHMedia() + { + var lianmengId = GetInt("LianmengId", true); + var lianmeng = Db.Queryable().Where(w => w.Id == lianmengId).First(); + if (lianmeng == null) + { + return PutData("联盟不存在!"); + } + var adzoneName = GetString("AdzoneName", true); + var item = Db.Queryable().Where(f => f.AdzoneName == adzoneName && f.LianmengId == lianmengId).First(); + if (item == null) + { + return PutData("删除失败,推广位不存在"); + } + Db.Deleteable(item).ExecuteCommand(); + return PutSuccess; + } + + /// + /// 查询唯品会推广位列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetWPHMedias() + { + try + { + var pageSize = GetInt("PageSize", true); + var index = GetInt("PageIndex", true); + var lianmengId = GetInt("LianmengId"); + var keyword = GetString("Keyword"); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(keyword)) + { + exp.And(f => f.AdzoneName.Contains(keyword) || f.Remark.Contains(keyword)); + } + var tNumber = 0; + var DataList = Db.Queryable() + .Where(f => f.LianmengId == lianmengId) + .Where(exp.ToExpression()) + .Select(f => new VipMediaShow() { + Remark = f.Remark, + AdzoneId = f.AdzoneId, + AdzoneName = f.AdzoneName, + Id = f.Id, + LianmengId = f.LianmengId, + UseCnt = Db.Queryable().Count(p => p.TbMediaId1 == f.Id || p.TbMediaId2 == f.Id) + }) + .ToPageList(index, pageSize, ref tNumber); + //var result = new List(); + //DataList.ForEach(f => + //{ + // var data = new VipMediaShow() + // { + // Remark = f.Remark, + // AdzoneId = f.AdzoneId, + // AdzoneName = f.AdzoneName, + // Id = f.Id, + // LianmengId = f.LianmengId, + // UseCnt = Db.Queryable().Count(p => p.TbMediaId1 == f.Id || p.TbMediaId2 == f.Id) + // }; + // result.Add(data); + //}); + return PutData(new PageResult(DataList, tNumber, pageSize, index)); + } + catch (Exception ex) + { + return PutData(ex); + } + } + } +} diff --git a/Server/Controllers/AccountManagement/RobotController.cs b/Server/Controllers/AccountManagement/RobotController.cs new file mode 100644 index 0000000..d0c3ddc --- /dev/null +++ b/Server/Controllers/AccountManagement/RobotController.cs @@ -0,0 +1,435 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace Server.Controllers.AccountManagement +{ + public class RobotController : DefaultController + { + /// + /// 分页查询机器人 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetRobots() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + if (PageSize > 100) PageSize = 100; + var TotalNumber = 0; + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword) || f.Username.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).ToPageList(PageIndex, PageSize, ref TotalNumber); + + + foreach (var item in DataList) + { + var data = Client.SingleClient.OnlineDevices.FirstOrDefault(f => f.Value.RobotId == item.Id).Value; + item.IsOnlineRobot = data != null; + } + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + + /// + /// 删除机器人 + /// + /// + + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult DelRobot() + { + + var Data = Db.GetRobot(GetInt("Id", true)); + if (Data != null && Db.Delete(Data) > 0) + { + Client.SendClientMsg(Data.Id, DeviceMessageType.退出机器人, new { RobotId = Data.Id }); + return PutSuccess; + } + else return PutData("删除失败,机器人信息不存在!"); + + } + + /// + /// 登录机器人 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult LoginRobot() + { + + var Id = GetInt("RobotId", true); + var Robot = Db.Queryable().Single(f => f.Id == Id); + if (Robot == null) return PutData("找不到该机器人数据!"); + + var device = Db.Queryable().Where(f => f.RobotId == Robot.Id).OrderBy(f => f.LoginTime, OrderByType.Desc).First(); + if (device == null) + return PutData("登录失败,未发现该机器人上次登录的设备信息"); + + var Msg = Client.SendClientMsg(device.Id, DeviceMessageType.登录机器人, new { RobotId = Id }); + if (Msg == null) + return PutData("登录失败,设备离线请检查软件状态"); + + var Rst = Client.GetClientMsg(Msg.Msgid).Result; + if (Rst == null) return PutData("登录失败,未获取到二维码信息请检查软件状态"); + + return PutData(new { Type = Robot.UserType, Qrcode = Rst.Content }); + } + + /// + /// 退出机器人 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult LogoutRobot() + { + var Id = GetInt("RobotId",true); + var Robot = Db.Queryable().Single(f => f.Id == Id); + if (Robot == null) return PutData("找不到该机器人数据!"); + Robot.LoginTime = DateTime.MinValue; + Db.Updateable(Robot).ExecuteCommand(); + Client.SendClientMsg(Robot.Id, DeviceMessageType.退出机器人, new { RobotId = Robot.Id }); + return PutSuccess; + } + + /// + /// 查询机器人详细信息 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetRobot() + { + var Id = GetInt("RobotId",true); + var Robot = Db.Queryable().Single(f => f.Id == Id); + if (Robot == null) return PutData("找不到该机器人数据!"); + + return null; + } + + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetConfig() + { + var Id = GetInt("RobotId", true); + var Robot = Db.Queryable().Single(f => f.Id == Id); + if (Robot == null) return PutData("查询失败,找不到该机器人信息!"); + RobotSettingShow config = new RobotSettingShow(); + + var tbMedia1 = Robot.TbMediaId1 > 0 ? Db.GetTbMedia(Robot.TbMediaId1) : null; + var tbMedia2 = Robot.TbMediaId2 > 0 ? Db.GetTbMedia(Robot.TbMediaId2) : null; + var tbLianmeng1 = tbMedia1 != null ? Db.GetLianmeng(tbMedia1.LianmengId) : null; + var tbLianmeng2 = tbMedia2 != null ? Db.GetLianmeng(tbMedia2.LianmengId) : null; + config.TbLianmengId1 = tbLianmeng1 != null ? tbLianmeng1.Id : 0; + config.TbLianmengId2 = tbLianmeng2 != null ? tbLianmeng2.Id : 0; + config.TbLianmengNick1 = tbLianmeng1 != null ? tbLianmeng1.Showname : String.Empty; + config.TbLianmengNick2 = tbLianmeng2 != null ? tbLianmeng2.Showname : String.Empty; + config.TbMediaNick1 = tbMedia1 != null ? tbMedia1.AdzoneName : String.Empty; + config.TbMediaNick2 = tbMedia2!=null? tbMedia2.AdzoneName :String.Empty; + config.TbMediaId1 = tbMedia1!=null ? tbMedia1.Id : 0; + config.TbMediaId2 = tbMedia2!=null? tbMedia2.Id : 0; + + + var dyMedia1 = Robot.DyMediaId1 > 0 ? Db.GetDyMedia(Robot.DyMediaId1) : null; + var dyMedia2 = Robot.DyMediaId2 > 0 ? Db.GetDyMedia(Robot.DyMediaId2) : null; + var dyLianmeng1 = dyMedia1 != null ? Db.GetLianmeng(dyMedia1.LianmengId) : null; + var dyLianmeng2 = dyMedia2 != null ? Db.GetLianmeng(dyMedia2.LianmengId) : null; + config.DyLianmengId1 = dyLianmeng1 != null ? dyLianmeng1.Id : 0; + config.DyLianmengId2 = dyLianmeng2 != null ? dyLianmeng2.Id : 0; + config.DyLianmengNick1 = dyLianmeng1 != null ? dyLianmeng1.Showname : String.Empty; + config.DyLianmengNick2 = dyLianmeng2 != null ? dyLianmeng2.Showname : String.Empty; + config.DyMediaNick1 = dyMedia1 != null ? dyMedia1.AdzoneName : String.Empty; + config.DyMediaNick2 = dyMedia2 != null ? dyMedia2.AdzoneName : String.Empty; + config.DyMediaId1 = dyMedia1 != null ? dyMedia1.Id : 0; + config.DyMediaId2 = dyMedia2 != null ? dyMedia2.Id : 0; + + + var jdMedia1 = Robot.JdMediaId1 > 0 ? Db.GetJdMedia(Robot.JdMediaId1) : null; + var jdMedia2 = Robot.JdMediaId2 > 0 ? Db.GetJdMedia(Robot.JdMediaId2) : null; + var jdLianmeng1 = jdMedia1 != null ? Db.GetLianmeng(jdMedia1.LianmengId) : null; + var jdLianmeng2 = jdMedia2 != null ? Db.GetLianmeng(jdMedia2.LianmengId) : null; + config.JdLianmengId1 = jdLianmeng1 != null ? jdLianmeng1.Id : 0; + config.JdLianmengId2 = jdLianmeng2 != null ? jdLianmeng1.Id : 0; + config.JdLianmengNick1 = jdLianmeng1 != null ? jdLianmeng1.Showname : String.Empty; + config.JdLianmengNick2 = jdLianmeng2 != null ? jdLianmeng2.Showname : String.Empty; + config.JdMediaNick1 = jdMedia1 != null ? jdMedia1.AdzoneName : String.Empty; + config.JdMediaNick2 = jdMedia2 != null ? jdMedia2.AdzoneName : String.Empty; + config.JdMediaId1 = jdMedia1 != null ? jdMedia1.Id : 0; + config.JdMediaId2 = jdMedia2 != null ? jdMedia2.Id : 0; + + + var wphMedia1 = Robot.WphMediaId1 > 0 ? Db.GetWphMedia(Robot.WphMediaId1) : null; + var wphMedia2 = Robot.WphMediaId2 > 0 ? Db.GetWphMedia(Robot.WphMediaId2) : null; + var wphLianmeng1 = wphMedia1 != null ? Db.GetLianmeng(wphMedia1.LianmengId) : null; + var wphLianmeng2 = wphMedia1 != null ? Db.GetLianmeng(wphMedia2.LianmengId) : null; + config.WphLianmengId1 = wphLianmeng1 != null ? wphLianmeng1.Id : 0; + config.WphLianmengId2 = wphLianmeng2 != null ? wphLianmeng1.Id : 0; + config.WphLianmengNick1 = wphLianmeng1 != null ? wphLianmeng1.Showname : String.Empty; + config.WphLianmengNick2 = wphLianmeng2 != null ? wphLianmeng2.Showname : String.Empty; + config.WphMediaNick1 = wphMedia1 != null ? wphMedia1.AdzoneName : String.Empty; + config.WphMediaNick2 = wphMedia2 != null ? wphMedia2.AdzoneName : String.Empty; + config.WphMediaId1 = wphMedia1 != null ? wphMedia1.Id : 0; + config.WphMediaId2 = wphMedia2 != null ? wphMedia2.Id : 0; + + + var pddMedia1 = Robot.PddMediaId1 > 0 ? Db.GetPddMedia(Robot.PddMediaId1) : null; + var pddMedia2 = Robot.PddMediaId2 > 0 ? Db.GetPddMedia(Robot.PddMediaId2) : null; + var pddLianmeng1 = pddMedia1 != null ? Db.GetLianmeng(pddMedia1.LianmengId) : null; + var pddLianmeng2 = pddMedia2 != null ? Db.GetLianmeng(pddMedia2.LianmengId) : null; + config.PddLianmengId1 = pddLianmeng1 != null ? pddLianmeng1.Id : 0; + config.PddLianmengId2 = pddLianmeng2 != null ? pddLianmeng1.Id : 0; + config.PddLianmengNick1 = pddLianmeng1 != null ? pddLianmeng1.Showname : String.Empty; + config.PddLianmengNick2 = pddLianmeng2 != null ? pddLianmeng2.Showname : String.Empty; + config.PddMediaNick1 = pddMedia1 != null ? pddMedia1.AdzoneName : String.Empty; + config.PddMediaNick2 = pddMedia2 != null ? pddMedia2.AdzoneName : String.Empty; + config.PddMediaId1 = pddMedia1 != null ? pddMedia1.Id : 0; + config.PddMediaId2 = pddMedia2 != null ? pddMedia2.Id : 0; + + + var snLianmeng1 = Robot.SnLianmengId1 > 0 ? Db.GetLianmeng(Robot.SnLianmengId1) : null; + var snLianmeng2 = Robot.SnLianmengId2 > 0 ? Db.GetLianmeng(Robot.SnLianmengId2) : null; + config.SnLianmengId1 = snLianmeng1 != null ? snLianmeng1.Id : 0; + config.SnLianmengId2 = snLianmeng2 != null ? snLianmeng1.Id : 0; + config.SnLianmengNick1 = snLianmeng1 != null ? snLianmeng1.Showname : String.Empty; + config.SnLianmengNick2 = snLianmeng2 != null ? snLianmeng2.Showname : String.Empty; + + + + var mtMedia1 = Robot.MtMediaId1 > 0 ? Db.GetMtMedia(Robot.MtMediaId1) : null; + var mtMedia2 = Robot.MtMediaId2 > 0 ? Db.GetMtMedia(Robot.MtMediaId2) : null; + var mtLianmeng1 = mtMedia1 != null ? Db.GetLianmeng(mtMedia1.LianmengId) : null; + var mtLianmeng2 = mtMedia2 != null ? Db.GetLianmeng(mtMedia2.LianmengId) : null; + config.MtLianmengId1 = mtLianmeng1 != null ? mtLianmeng1.Id : 0; + config.MtLianmengId2 = mtLianmeng2 != null ? mtLianmeng1.Id : 0; + config.MtLianmengNick1 = mtLianmeng1 != null ? mtLianmeng1.Showname : String.Empty; + config.MtLianmengNick2 = mtLianmeng2 != null ? mtLianmeng2.Showname : String.Empty; + config.MtMediaNick1 = mtMedia1 != null ? mtMedia1.AdzoneName : String.Empty; + config.MtMediaNick2 = mtMedia2 != null ? mtMedia2.AdzoneName : String.Empty; + config.MtMediaId1 = mtMedia1 != null ? mtMedia1.Id : 0; + config.MtMediaId2 = mtMedia2 != null ? mtMedia2.Id : 0; + + + config.ConfigRebateName = Robot.ConfigRebateId>0? Db.Queryable().Where(f => f.Id == Robot.ConfigRebateId).Select(f=>f.Name).First():String.Empty; + config.ConfigReplyName = Robot.ConfigReplyId > 0 ? Db.Queryable().Where(f => f.Id == Robot.ConfigReplyId).Select(f => f.Name).First() : String.Empty; + config.ConfibBaseName = Robot.ConfigBaseId > 0 ? Db.Queryable().Where(f => f.Id == Robot.ConfigBaseId).Select(f => f.Name).First() : String.Empty; + config.ConfigBaseId = Robot.ConfigBaseId; + config.ConfigRebateId = Robot.ConfigRebateId; + config.ConfigReplyId = Robot.ConfigReplyId; + + return PutData(config); + } + + /// + /// 保存配置 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult SetConfig() + { + var Id = GetInt("RobotId", true); + var Robot = Db.Queryable().Single(f => f.Id == Id); + if (Robot == null) return PutData("保存失败,找不到该机器人信息!"); + + Robot.ConfigBaseId = GetInt("ConfigBaseId",true); + Robot.ConfigRebateId = GetInt("ConfigRebateId", true); + Robot.ConfigReplyId = GetInt("ConfigReplyId", true); + Robot.TbMediaId1 = GetInt("TbMediaId1",true); + Robot.TbMediaId2 = GetInt("TbMediaId2", true); + Robot.DyMediaId1 = GetInt("DyMediaId1", true); + Robot.DyMediaId2 = GetInt("DyMediaId2", true); + Robot.JdMediaId1 = GetInt("JdMediaId1", true); + Robot.JdMediaId1 = GetInt("JdMediaId2", true); + Robot.MtMediaId1 = GetInt("MtMediaId1", true); + Robot.MtMediaId2 = GetInt("MtMediaId2", true); + Robot.WphMediaId1 = GetInt("WphMediaId1", true); + Robot.WphMediaId2 = GetInt("WphMediaId2", true); + Robot.PddMediaId1 = GetInt("PddMediaId1", true); + Robot.PddMediaId2 = GetInt("PddMediaId2", true); + Robot.SnLianmengId1 = GetInt("SnLianmengId1", true); + Robot.SnLianmengId2 = GetInt("SnLianmengId2", true); + Db.Save(Robot); +Client.SendClientMsg(Robot.Id, DeviceMessageType.机器人配置更新, new { RobotId = Robot.Id }); return PutSuccess; + } + + /// + /// 获取联盟 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetLianmengs() + { + var Keyword = GetString("Keyword"); + var LianmengType = GetEnum("LianmengType",true); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword) || f.Username.Contains(Keyword)); + } + + exp.And(f=>f.LianmengType == LianmengType); + var Lianmengs = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f => new NameShow { Id = f.Id, Name = f.Nickname }) + .Take(20). + OrderBy(f => f.Id, OrderByType.Desc) + .ToList(); + ; + return PutData(Lianmengs); + } + + /// + /// 获取联盟 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetMedias() + { + var Keyword = GetString("Keyword"); + var LianmengId = GetInt("LianmengId",true); + var lianmeng = Db.GetLianmeng(LianmengId); + if (lianmeng == null) return PutData("查询失败,当前联盟账号不存在!"); + switch (lianmeng.LianmengType) + { + case Common.Models.Enums.LianmengType.淘宝联盟: + { + var exp = Expressionable.Create(); + exp.And(f => f.LianmengId == LianmengId); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.AdzoneName.Contains(Keyword) || f.Pid.Contains(Keyword)); + } + exp.And(f=>f.IsRemove == false); + var Results = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f => new NameShow { Id = f.Id, Name = f.AdzoneName }) + .Take(20) + .OrderBy(f => f.Id, OrderByType.Desc) + .ToList(); + return PutData(Results); + } + case Common.Models.Enums.LianmengType.京东联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.AdzoneName.Contains(Keyword)); + } + exp.And(f => f.LianmengId == LianmengId); + var Results = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f => new NameShow { Id = f.Id, Name = f.AdzoneName }) + .Take(20) + .OrderBy(f => f.Id, OrderByType.Desc) + .ToList(); + return PutData(Results); + } + + case Common.Models.Enums.LianmengType.拼多多联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.AdzoneName.Contains(Keyword)); + } + exp.And(f => f.LianmengId == LianmengId); + var Results = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f => new NameShow { Id = f.Id, Name = f.AdzoneName }) + .Take(20) + .OrderBy(f => f.Id, OrderByType.Desc) + .ToList(); + return PutData(Results); + } + case Common.Models.Enums.LianmengType.唯品会联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.AdzoneName.Contains(Keyword)); + } + exp.And(f => f.LianmengId == LianmengId); + var Results = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f => new NameShow { Id = f.Id, Name = f.AdzoneName }) + .Take(20) + .OrderBy(f => f.Id, OrderByType.Desc) + .ToList(); + return PutData(Results); + } + + case Common.Models.Enums.LianmengType.苏宁联盟: + return PutData("查询失败,苏宁无需设置推广位!"); + + case Common.Models.Enums.LianmengType.抖音联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.AdzoneName.Contains(Keyword)); + } + exp.And(f => f.LianmengId == LianmengId); + var Results = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f => new NameShow { Id = f.Id, Name = f.AdzoneName }) + .Take(20) + .OrderBy(f => f.Id, OrderByType.Desc) + .ToList(); + return PutData(Results); + } + case LianmengType.美团联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.AdzoneName.Contains(Keyword)); + } + exp.And(f => f.LianmengId == LianmengId); + var Results = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f => new NameShow { Id = f.Id, Name = f.AdzoneName }) + .Take(20) + .OrderBy(f => f.Id, OrderByType.Desc) + .ToList(); + return PutData(Results); + } + default: + break; + } + + return PutError; + + } + + /// + /// 获取配置表 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetConfigNames() + { + var Keyword = GetString("Keyword"); + var ConfigType = GetEnum("ConfigType", true); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Name.Contains(Keyword)); + } + exp.And(f=>f.Type == ConfigType); + var result = Db.Queryable() + .Where(exp.ToExpression()) + .Select(f=>new NameShow{ Id = f.Id,Name = f.Name }) + .Take(20) + .OrderBy(f=>f.Id, OrderByType.Desc) + .ToList(); + return PutData(result); + } + } +} diff --git a/Server/Controllers/AccountManagement/StaffController.cs b/Server/Controllers/AccountManagement/StaffController.cs new file mode 100644 index 0000000..82fc5b7 --- /dev/null +++ b/Server/Controllers/AccountManagement/StaffController.cs @@ -0,0 +1,259 @@ +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Controllers.AccountManagement +{ + public class StaffController:DefaultController + { + + + /// + /// 查询子账号 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetStaffs() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + if (PageSize > 100) PageSize = 100; + var TotalNumber = 0; + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(a => a.Username.Contains(Keyword) || a.Remark.Contains(Keyword)); + } + + var DataList = Db.Queryable() + .LeftJoin((a,b)=>a.RoleId == b.Id) + .Where(exp.ToExpression()) + .Select((a,b)=>new StaffShow() { Id = a.Id, CreateTime = a.CreateTime,IsCreator = a.IsCreator,Password = a.IsCreator?String.Empty:a.Password ,Remark = a.Remark ,RoleId = b.Id,RoleName = b.Name,Username = a.Username, IsEnable = a.IsEnable}) + .ToPageList(PageIndex, PageSize, ref TotalNumber); + + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + + + } + + /// + /// 新增子账号 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddStaff() + { + var Username = GetString("Username",true); + var Remark = GetString("Remark"); + var Password = GetString("Password",true); + var RoleId = GetInt("RoleId",true); + + var Role = Db.Queryable().Single(f => f.Id == RoleId); + if (Role == null) return PutData("对不起,该权限不存在!"); + + var Staff = Db.Queryable().Where(f=>f.Username == Username).First(); + if(Staff!=null) return PutData("对不起,该子账号名称已存在!"); + var IsEnable = GetBoolean("IsEnable"); + Staff = new Staff() + { + Username = Username, + CreateTime = DateTime.Now, + Password = Password, + Remark = Remark, + RoleId = RoleId, + IsEnable = IsEnable, + IsCreator = false + }; + Staff.Id = (int)Db.Insertable(Staff).ExecuteReturnBigIdentity(); + return PutData(Staff); + + } + + /// + /// 启用或禁用员工 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult EnableStaff() + { + var StaffId = GetInt("StaffId",true); + //var Remark = GetString("Remark"); + //var Password = GetString("Password"); + //var RoleId = GetInt("RoleId"); + var IsEnable = GetBoolean("IsEnable",true); + + //var Role = Db.Queryable().Single(f => f.Id == RoleId); + //if (Role == null) return PutData("对不起,该权限不存在!"); + + + var Staff = Db.Queryable().Single(f => f.Id == StaffId); + if (Staff == null) return PutData("对不起,该子账号不存在!"); + else if (Staff.IsCreator) return PutData("操作失败,管理员账号禁止操作"); + + //Staff.Remark = Remark; + //Staff.Password = Password; + //Staff.RoleId = RoleId; + Staff.IsEnable = IsEnable; + Db.Updateable(Staff).ExecuteCommand(); + return PutSuccess; + + } + + /// + /// 编辑子账号 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult UpdStaff() + { + var StaffId = GetInt("StaffId",true); + var Remark = GetString("Remark"); + var Password = GetString("Password"); + var RoleId = GetInt("RoleId"); + var IsEnable = GetBoolean("IsEnable"); + + var Role = Db.Queryable().Single(f => f.Id == RoleId); + if (Role == null) return PutData("对不起,该权限不存在!"); + + + var Staff = Db.Queryable().Single(f => f.Id == StaffId); + if (Staff == null) return PutData("对不起,该子账号不存在!"); + else if (Staff.IsCreator) return PutData("操作失败,管理员账号禁止编辑"); + + + Staff.Remark = Remark; + Staff.Password = String.IsNullOrEmpty(Password)?Staff.Password: Password; + Staff.RoleId = RoleId; + Staff.IsEnable = IsEnable; + Db.Updateable(Staff).ExecuteCommand(); + return PutSuccess; + + } + + /// + /// 删除子账号 + /// + /// + + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult DelStaff() + { + var Id = GetInt("StaffId"); + var Rst = Db.Deleteable().Where(f => f.Id == Id && f.IsCreator == false).ExecuteCommand(); + if (Rst > 0) return PutSuccess; + else return PutData("删除失败,未找到数据!"); + } + + + + private static List AllRoles = new List { "Anlyze", "Data", "Tools", "Artificial", "Qunfa", "Social", "Account", "Lianmeng", "Robot", "Staff", "Member", "Grouping", "WechatUser", "Fans", "Blacklist", "Reminder", "Func", "Pub", "Base", "Rebate", "Feed", "Keywords", "Order", "TbOrder", "JdOrder", "DyOrder", "MtOrder", "SnOrder", "WphOrder", "PddOrder", "Financial", "CashList", "PayRecord", "IntegralRecord", "Help", "RunLog", "QA", "Guide", "About" }; + + /// + /// 查询权限 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetRoles() + { + var List = Db.Queryable().OrderBy(f => f.Id, OrderByType.Desc).ToList(); + var superRole = List.FirstOrDefault(f => f.Name == "超级管理员"); + if (superRole != null) + { + superRole.ControllerNames = AllRoles; + } + return PutData(List); + } + + /// + /// 根据角色ID获取角色权限列表 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetRole() + { + var RoleId = Session.RoleId; + + var Role = Db.Queryable().Single(f => f.Id == RoleId); + if (Role == null) return PutData("对不起,该权限不存在!"); + else if(Role.Name=="超级管理员") Role.ControllerNames = AllRoles; + return PutData(Role); + } + + /// + /// 删除权限 + /// + /// + + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult DelRole() + { + var Id = GetInt("RoleId",true); + + + var Role = Db.Queryable().Single(f=>f.Id ==Id); + if (Role != null && Role.Name == "超级管理员") return PutData("对不起,超级管理员权限禁止删除"); + + var Rst = Db.Deleteable().RemoveDataCache().Where(f => f.Id == Id).ExecuteCommand(); + if (Rst > 0) + { + return PutSuccess; + } + else return PutData("删除失败,未找到数据!"); + } + + /// + /// 编辑权限 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult UpdRole() + { + var RoleId = GetInt("RoleId",true); + + var Name = GetString("Name",true); + var Roles = GetString("ControllerNames",true); + + var Role = Db.Queryable().Single(f => f.Id == RoleId); + if (Role == null) return PutData("对不起,该权限不存在!"); + else if (Role != null && Role.Name == "超级管理员") return PutData("对不起,超级管理员权限禁止修改"); + + Role.Name = Name; + Role.ControllerNames = Roles.Split(',').ToList(); + + Db.Updateable(Role).RemoveDataCache().ExecuteCommand(); + return PutSuccess; + + } + + + /// + /// 新增权限 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddRole() + { + + var Name = GetString("Name"); + var Roles = GetString("ControllerNames"); + + var Role = Db.Queryable().Where(f => f.Name == Name).First(); + if (Role != null) return PutData("对不起,该权限已存在!"); + Role = new Role() + { + Name = Name, + CreateTime = DateTime.Now, + ControllerNames = Roles.Split(',').ToList() + }; + + Role = Db.Insertable(Role).RemoveDataCache().ExecuteReturnEntity(); + return PutData(Role); + } + } +} diff --git a/Server/Controllers/ClientManagement/ClientController.cs b/Server/Controllers/ClientManagement/ClientController.cs new file mode 100644 index 0000000..79e735f --- /dev/null +++ b/Server/Controllers/ClientManagement/ClientController.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Controllers.ClientManagement +{ + public class ClientController:DefaultController + { + public WebResult Connection() + { + return null; + } + + /// + /// 关闭 + /// + /// + public WebResult Close() + { + return null; + } + + + } +} diff --git a/Server/Controllers/DataOverview/DataOverviewController.cs b/Server/Controllers/DataOverview/DataOverviewController.cs new file mode 100644 index 0000000..d597fad --- /dev/null +++ b/Server/Controllers/DataOverview/DataOverviewController.cs @@ -0,0 +1,75 @@ +using Common.Models.UnqTables; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.DataOverviewController +{ + public class DataViewController : DefaultController + { + /// + /// 今日数据 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetData() + { + //var MaxTimeToday = DateTime.Now; //当前时间 + //var MinTimeToday = Convert.ToDateTime(DateTime.Now.ToString("D").ToString());//当天0点 + + //今日数据 + var Today = DateTime.Now.Date; + var dataToday = Db.Queryable().Where(f=>f.CreateTime.Date == Today).First(); + + if (dataToday == null) + dataToday = new DataOverview(); + + //var MinTimeYesterday = Convert.ToDateTime(DateTime.Now.ToString("D")).AddDays(-1);//昨天0点 + //var MaxTimeYesterday = Convert.ToDateTime(DateTime.Now.ToString("D")).AddSeconds(-1);//昨天23点59分59秒 + + //昨日数据 + var Yesterday = DateTime.Now.AddDays(-1).Date; + var dataYesterday = Db.Queryable().Where(f => f.CreateTime.Date == Yesterday).First(); + + if (dataYesterday == null) + dataYesterday = new DataOverview(); + + return PutData(new { + Today = dataToday, + Yesterday = dataYesterday, + }); + } + + /// + /// 指定范围时间数据 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetDataOverview() + { + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-2); + + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + var exp = Expressionable.Create(); + + exp.And(f => f.CreateTime >= MinTime && f.CreateTime <= MaxTime); + + var PageIndex = GetInt("PageIndex", true); + var PageSzie = GetInt("PageSize", true); + var tNumber = 0; + + var DataList = Db.Queryable().Where(exp.ToExpression()) + .ToPageList(PageIndex, PageSzie, ref tNumber); + + return PutData(new PageResult(DataList, tNumber, PageSzie, PageIndex)); + } + } +} diff --git a/Server/Controllers/DataOverview/DataViewController.cs b/Server/Controllers/DataOverview/DataViewController.cs new file mode 100644 index 0000000..9dc070b --- /dev/null +++ b/Server/Controllers/DataOverview/DataViewController.cs @@ -0,0 +1,103 @@ +using Common.Models.SubTables; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.DataOverviewController +{ + public class DataViewController : DefaultController + { + /// + /// 今日数据 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetTodayData() + { + var MaxTime = DateTime.Now; //当前时间 + var MinTime = Convert.ToDateTime(DateTime.Now.ToString("D").ToString());//当天0点 + + var data = Db.Queryable().Where(f => f.Date == DateTime.Now.Date) + .SplitTable(MinTime, MaxTime).First(); + + if (data == null) data = new DataOverview(); + + return PutData(data); + } + + /// + /// 昨日数据 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetYesterdayData() + { + var data = Db.Queryable().Where(f => f.Date == DateTime.Now.AddDays(-1)).First(); + + if (data == null) + data = new DataOverview(); + + + return PutData(data); + } + + /// + /// 获取昨日/今日数据对比 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetViewData() + { + var yestoday = Db.Queryable().Where(f => f.Date == DateTime.Now.AddDays(-1)).First(); + if (yestoday == null) + { + yestoday = new DataOverview(); + } + var MaxTime = DateTime.Now; + var MinTime = Convert.ToDateTime(DateTime.Now.ToString("D").ToString()); + + var today = Db.Queryable().Where(f => f.Date == DateTime.Now.Date) + .SplitTable(MinTime, MaxTime).First(); + + if (today == null) today = new DataOverview(); + + return PutData(new {today = today, yestoday = yestoday }); + } + + /// + /// 指定范围时间数据 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetDataOverview() + { + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-2); + + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + var exp = Expressionable.Create(); + + exp.And(f => f.Date > MinTime && f.Date < MaxTime); + + var PageIndex = GetInt("PageIndex"); + var PageSzie = GetInt("PageSize"); + var tNumber = 0; + + var DataList = Db.Queryable().Where(exp.ToExpression()) + .SplitTable(MinTime,MaxTime) + .ToPageList(PageIndex, PageSzie, ref tNumber); + + if (DataList == null) + return PutData(new PageResult(new List(), tNumber, PageSzie, PageIndex)); + + return PutData(new PageResult(DataList, tNumber, PageSzie, PageIndex)); + } + } +} diff --git a/Server/Controllers/DefaultController.cs b/Server/Controllers/DefaultController.cs new file mode 100644 index 0000000..17b031c --- /dev/null +++ b/Server/Controllers/DefaultController.cs @@ -0,0 +1,364 @@ +using Common.Models.UnqTables; +using Common.Utils; +using Newtonsoft.Json; +using Server.MyClass.Class; +using Server.Utils; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Web.Http; +using System.Web.Http.Controllers; +using System.Web.Http.Filters; + +namespace Server.Controllers +{ + public class PageResult + { + /// + /// 下一页 + /// + public bool IsNext { get; set; } + + /// + /// 上一页 + /// + public bool IsBack { get; set; } + + /// + /// 数据 + /// + public Object Datas { get; set; } + + /// + /// 总数量 + /// + public int TotalNumber { get; set; } + + /// + /// 每页显示条数 + /// + public int PageSize { get; set; } + + /// + /// 总页码 + /// + public int PageNumber { get; set; } + + /// + /// 当前页码 + /// + public int PageIndex { get; set; } + + + public PageResult(List Datas, int TotalNumber, int PageSize, int PageIndex) + { + if (PageIndex <= 0 || PageSize <= 0) throw new Exception("Index或PageSize 有问题,请检查"); + if (PageSize > 100) throw new Exception("每页查询数量,不能超过100"); + + PageNumber = 1; + if (TotalNumber != 0 && PageSize > 0) + { + PageNumber = TotalNumber / PageSize; + if (TotalNumber % PageSize != 0) PageNumber++; + } + this.Datas = Datas; + this.TotalNumber = TotalNumber; + this.PageNumber = PageNumber; + this.PageSize = PageSize; + this.PageIndex = PageIndex; + this.IsBack = PageIndex > 1; + this.IsNext = PageIndex < PageNumber; + } + } + public class WebResult + { + /// + /// 请求是否成功 + /// + public bool Ok { get; set; } + + /// + /// 返回信息 + /// + public object Data { get; set; } + + /// + /// 消耗时长 + /// + public double Time { get; set; } + } + internal class ErrorFilterAttribute : ExceptionFilterAttribute + { + private DateTime startTime = DateTime.Now; + public override void OnException(HttpActionExecutedContext actionExecutedContext) + { + var rst = new WebResult() { Ok = false, Data = actionExecutedContext.Exception.Message }; + rst.Time = Math.Round((DateTime.Now - startTime).TotalSeconds, 5); + HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(rst), Encoding.GetEncoding("UTF-8"), "application/json") }; + actionExecutedContext.Response = result; + } + } + + public class DefaultController : ApiController + { + protected UserSession Session { get; set; } + public string ControllerName { get; private set; } + private const string WebAppsecret = "d3913942-3c9f-1340-2091-c384196b6111"; + private static List NotloginActions = new List() { "login", "logintaobaoresult", "getcaptch", "checkcaptch", "upload", "getwebinfo" }; + private static List NotCheckAcions = new List() { "logintaobaocallback", "pinduoduo", "vip" }; + private static List NotCheckRoleController = new List() { "Com", "Resources" }; + public override async Task ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken) + { + + /* + 验证逻辑:从header中提取type,如果是web表示正常浏览器请求用默认的appsecret验证签名,如果是api是免登录api验证 + */ + + + var req = controllerContext.Request; + ControllerName = req.RequestUri.AbsolutePath.Split(new char[] { '/' }).FirstOrDefault(p => !string.IsNullOrEmpty(p)).ToLower(); + var ActionName = req.RequestUri.Segments.LastOrDefault(p => !string.IsNullOrEmpty(p)).ToLower().Replace("/", "").Replace("&", ""); + + if (NotCheckAcions.Any(p => p.ToLower() == ActionName)) + { + return await base.ExecuteAsync(controllerContext, cancellationToken); + } + try + { + if (!req.Headers.Contains("type")) + { + throw new Exception("Illegal request 1"); + } + var type = req.Headers.GetValues("type").FirstOrDefault(); + if (type != "api" && type != "web") + { + throw new Exception("Illegal request 2"); + } + Dictionary param = new Dictionary(); + var contentType = req.Content.Headers.ContentType; + if (contentType.MediaType != "multipart/form-data") + { + //获取请求参数 + Param = await req.Content.ReadAsFormDataAsync(cancellationToken); + foreach (var item in Param.AllKeys) + { + var v = Param.Get(item); + if (!string.IsNullOrEmpty(v)) + { + param.Add(item, v); + } + } + } + else + { + Param = new NameValueCollection(); + var paras = req.GetQueryNameValuePairs(); + foreach (var item in paras) + { + param[item.Key] = item.Value; + Param[item.Key] = item.Value; + } + } + + var time = req.Headers.GetValues("time").FirstOrDefault(); + //设置appsecret,如果是web需要增加token和uid的值纳入sign判断条件 + string token = string.Empty; + int uid = 0; + var appsecret = string.Empty; + if (type == "web") + { + appsecret = WebAppsecret; + //如果是web请求一定会携带uid和token,但未登录可能是空字符串不参与sign验证 + if (!req.Headers.Contains("u_token") || !req.Headers.Contains("u_id")) throw new Exception("Illegal request 3"); + token = req.Headers.GetValues("u_token").FirstOrDefault(); + if (!string.IsNullOrEmpty(token)) param.Add("u_token", token); + var uidstr = req.Headers.GetValues("u_id").FirstOrDefault(); + if (!string.IsNullOrEmpty(uidstr)) + { + uid = int.Parse(uidstr); + param.Add("u_id", uidstr); + } + } + else if (type == "api") + { + appsecret = Client.Config.Appsecret; + } + //验证sign + if (contentType.MediaType != "multipart/form-data") + { + var sign = Util.SignTopRequest(param, appsecret, time); + if (sign != req.Headers.GetValues("sign").FirstOrDefault()) + { + throw new Exception("Sign Error!!!"); + } + } + //如果是web请求,需要验证是否登录 + if (type == "web" && !NotloginActions.Any(p => p.ToLower() == ActionName)) + { + if (Client.OnlineUsers.TryGetValue(uid, out var session) && session != null) + { + Session = session; + + Session.RequestTime = DateTime.Now; + if (session.RoleId != 0 && session.RoleId != 1) + { + + //权限验证 + if (!NotCheckRoleController.Contains(ControllerName)) + { + var Role = Db.Queryable().Where(f => f.Id == session.RoleId).WithCache().First(); + if (Role.Name != "超级管理员" && !Role.ControllerNames.Any(p => p.ToLower() == ControllerName)) + { + throw new Exception("权限不足,暂时无法访问此接口!"); + } + } + } + } + else + { + throw new Exception("登录失效,请重新登录!"); + } + } + return await base.ExecuteAsync(controllerContext, cancellationToken); + } + catch (Exception ex) + { + var rst = PutData(ex.Message); + HttpResponseMessage result = new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(rst), Encoding.GetEncoding("UTF-8"), "application/json") }; + return await Task.FromResult(result); + } + } + internal Client Client { get { return Client.SingleClient; } } + internal SqlSugar.SqlSugarClient Db { get { return Client.Db; } } + + + protected NameValueCollection Param { get; private set; } + + + protected string GetString(string Name, bool NotNull = false) + { + + var v = Param?.Get(Name); + if (string.IsNullOrEmpty(v) && NotNull) throw new Exception("错误,缺少必要参数未输入!"); + return v; + } + protected List GetStringList(string Name, bool NotNull = false) + { + var v = Param?.Get(Name); + if (string.IsNullOrEmpty(v) && NotNull) throw new Exception("错误,缺少必要参数未输入!"); + + if (string.IsNullOrEmpty(v)) + return new List(); + else + return JsonConvert.DeserializeObject>(v); + + } + + protected List GetIntList(string Name, bool NotNull = false) + { + var v = Param?.Get(Name); + if (string.IsNullOrEmpty(v) && NotNull) throw new Exception("错误,缺少必要参数未输入!"); + + if (string.IsNullOrEmpty(v)) + return new List(); + + else + return JsonConvert.DeserializeObject>(v); + } + protected DateTime GetTime(string Name, bool NotNull = false) + { + var time = DateTime.MinValue; + DateTime.TryParse(GetString(Name, NotNull), out time); + return time; + } + + protected T GetEnum(string Name, bool NotNull = false) + { + var v = GetString(Name, NotNull); + if (!string.IsNullOrEmpty(v)) + return (T)Enum.Parse(typeof(T), v); + else + return (T)Enum.Parse(typeof(T), "0"); + + } + protected int GetInt(string Name, bool NotNull = false) + { + var rst = GetString(Name, NotNull); + int outRst = -1; + var flag = int.TryParse(rst, out outRst); + if (NotNull && !flag) throw new Exception("您输入的【" + rst + "】不是一个有效的Int类型!"); + return outRst; + } + + protected double GetDouble(string Name, bool NotNull = false) + { + var rst = GetString(Name, NotNull); + double outRst = -1; + var flag = Double.TryParse(rst, out outRst); + if (NotNull && !flag) throw new Exception("您输入的【" + rst + "】不是一个有效的Double类型!"); + return outRst; + } + protected long GetLong(string Name, bool NotNull = false) + { + var rst = GetString(Name, NotNull); + long outRst = 0; + var flag = long.TryParse(rst, out outRst); + if (NotNull && !flag) throw new Exception("您输入的【" + rst + "】不是一个有效的Long类型!"); + return outRst; + } + protected bool GetBoolean(string Name, bool NotNull = false) + { + var rst = GetString(Name, NotNull); + bool outRst = false; + bool.TryParse(rst, out outRst); + return outRst; + } + + private DateTime startTime = DateTime.Now; + public WebResult PutData(object Data) + { + WebResult Ret = null; + if (Data == null) + { + Ret = new WebResult(); + Ret.Ok = true; + Ret.Data = null; + } + else if (Data.GetType() == typeof(Exception)) + { + Ret = new WebResult(); + var e = Data as Exception; + Ret.Ok = false; + Ret.Data = e.Message; + } + else if (Data is string) + { + Ret = new WebResult(); + Ret.Ok = false; + Ret.Data = Data; + } + else if (Data.GetType() == typeof(WebResult)) + { + Ret = Data as WebResult; + } + else + { + Ret = new WebResult(); + Ret.Ok = true; + Ret.Data = Data; + } + Ret.Time = Math.Round((DateTime.Now - startTime).TotalSeconds, 5); + return Ret; + } + public WebResult PutSuccess { get { return PutData(new WebResult() { Ok = true, Data = "操作成功" }); } } + public WebResult PutError { get { return PutData(new WebResult() { Ok = false, Data = "系统繁忙,请稍后重试" }); } } + + + + } +} diff --git a/Server/Controllers/FinancialManagement/CashListController.cs b/Server/Controllers/FinancialManagement/CashListController.cs new file mode 100644 index 0000000..3e20b93 --- /dev/null +++ b/Server/Controllers/FinancialManagement/CashListController.cs @@ -0,0 +1,142 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Web.Http; + +namespace Server.Controllers.FinancialManagement +{ + public class CashListController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 查询提现记录 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetCashList() + { + var RobotId = GetInt("RobotId");//机器人Id:0:所有机器人 不为0:指定机器人 + var MinTime = GetTime("MinTime");//起始时间 + var MaxTime = GetTime("MaxTime");//结束时间 + var VerifyStatus = GetEnum("VerifyStatus");//审核状态:1: 未审核 2:已审核 + /* + 微信昵称 = 1, 微信ID = 2 + */ + var KeywordType = GetInt("KeywordType"); + var Keyword = GetString("Keyword"); + + + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + var tNumber = 0; + + var exp = Expressionable.Create(); + + if (MinTime == DateTime.MinValue) + MinTime = DateTime.Now.AddMonths(-6); + + if (MaxTime == DateTime.MinValue) + MaxTime = DateTime.Now; + + exp.And(a => a.ApplyTime > MinTime && a.ApplyTime < MaxTime); + + if (RobotId > 0) + exp.And(a => a.RobotId == RobotId); + + + if (VerifyStatus != 0) + exp.And(a => a.VerifyStatus == VerifyStatus); + + if (!string.IsNullOrEmpty(Keyword)) + { + /* + 微信昵称 = 1, 微信ID = 2, 推荐人微信ID = 3,推荐人昵称 = 4 + */ + if (KeywordType == 1) + { + var nickNames = Db.Queryable().Where(f => f.NickName.Contains(Keyword)) + .Select(f => f.Id).Take(20).ToList(); + + if (nickNames == null) + { + return PutData(new PageResult(new List(), tNumber, PageSize, PageIndex)); + } + + exp.And(a => nickNames.Contains(a.UserId)); + } + + else if (KeywordType == 2) + { + var user = Db.Queryable().Where(f => f.Username == Keyword && f.UserType == Common.Models.Enums.UserType.微信用户).First(); + + if (user == null) + { + return PutData(new PageResult(new List(), tNumber, PageSize, PageIndex)); + } + + exp.And(a => a.UserId == user.Id); + } + + } + + var DataList = Db.Queryable() + .Where(exp.ToExpression()) + + .LeftJoin((a, b) => a.RobotId == b.Id) + .LeftJoin((a, b, c) => a.UserId == c.Id) + .Select((a, b, c) => new CashListShow + { + Id = a.Id, + UserId = c.Id, + NickName = c.NickName, + RobotId = b.Id, + RobotName = b.Nickname, + CashAmount = a.CashAmount, + TotalCash = a.TotalCash, + TotalConfirm = a.TotalConfirm, + TotalRefund = a.TotalRefund, + ApplyTime = a.ApplyTime, + VerifyStatus = a.VerifyStatus, + VerifyTime = a.VerifyTime, + Remark = a.Remark, + }) + .SplitTable(MinTime, MaxTime) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + } +} diff --git a/Server/Controllers/FinancialManagement/IntegralRecordController.cs b/Server/Controllers/FinancialManagement/IntegralRecordController.cs new file mode 100644 index 0000000..338d6ad --- /dev/null +++ b/Server/Controllers/FinancialManagement/IntegralRecordController.cs @@ -0,0 +1,130 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.FinancialManagement +{ + + public class IntegralRecordController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + + /// + /// 查询积分记录 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetIntegralRecord() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + if (PageSize > 100) PageSize = 100; + + var tNumber = 0; + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + if (MinTime == DateTime.MinValue) + MinTime = DateTime.Now.AddMonths(-6); + if (MaxTime == DateTime.MinValue) + MaxTime = DateTime.Now; + + var exp = Expressionable.Create(); + + exp.And(f => f.CreateTime > MinTime && f.CreateTime < MaxTime); + + var RobotId = GetInt("RobotId"); + if (RobotId != 0) + exp.And(f => f.RobotId == RobotId); + + var IntegralType = GetEnum("IntegralType"); + if (IntegralType != PointType.未知) + exp.And(f => f.PointType == IntegralType); + + var Keyword = GetString("Keyword"); + + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType");//搜索类型 1:微信账号 2:微信昵称 + + switch (KeywordType) + { + case 1://微信账号搜索 + var user = Db.Queryable().Where(u => u.Username == Keyword).First(); + + if (user == null) + return PutData(new PageResult(new List(), tNumber, PageSize, PageIndex)); + + exp.And(f => user.Id == f.Id); + break; + + case 2://微信昵称搜索 + var Ids = Db.Queryable().Where(u => u.NickName.Contains(Keyword)).Select(u => u.Id).Take(20).ToList(); + + exp.And(f => Ids.Contains(f.UserId)); + break; + } + } + + var DataList = Db.Queryable() + .Where(exp.ToExpression()) + .SplitTable(MinTime, MaxTime) + .LeftJoin((f, b) => f.RobotId == b.Id) + .LeftJoin((f, b, u) => f.UserId == u.Id) + .Select((f, b, u) => new IntegralShow + { + Id = f.Id, + UserId = f.UserId, + NickName = u.NickName, + RobotName = b.Username, + BeforeModify = f.BeforeModify, + AfterModify = f.AfterModify, + ChangeAmount = f.ChangeAmount, + PointType = f.PointType, + CreateTime = f.CreateTime, + Remark = f.Remark + }) + + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + } +} diff --git a/Server/Controllers/FinancialManagement/PayRecordController.cs b/Server/Controllers/FinancialManagement/PayRecordController.cs new file mode 100644 index 0000000..1e3a83d --- /dev/null +++ b/Server/Controllers/FinancialManagement/PayRecordController.cs @@ -0,0 +1,127 @@ +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.FinancialManagement +{ + public class PayRecordController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 查询支付记录 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetPayRecord() + { + var RobotId = GetInt("RobotId");//机器人Id:0:所有机器人 不为0:指定机器人 + var MinTime = GetTime("MinTime");//起始时间 + var MaxTime = GetTime("MaxTime");//结束时间 + var RecieveStatus = GetInt("RecieveStatus");//领取状态:1: 未领取 2:已领取 + /* + 微信昵称 = 1, 微信ID = 2 + */ + var KeywordType = GetInt("KeywordType"); + var Keyword = GetString("Keyword"); + + + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize>100) PageSize = 100; + var tNumber = 0; + + var exp = Expressionable.Create(); + + if (RobotId > 0) + exp.And(a => a.RobotId == RobotId); + + if (MinTime == DateTime.MinValue) + MinTime = DateTime.Now.AddMonths(-6); + + if (MaxTime == DateTime.MinValue) + MaxTime = DateTime.Now; + + exp.And(a=>a.PayTime>MinTime && a.PayTime < MaxTime); + + if (RecieveStatus != 0) + exp.And(a => a.RecieveStatus == RecieveStatus); + + if (!string.IsNullOrEmpty(Keyword)) + { + /* + 微信昵称 = 1, 微信ID = 2, 推荐人微信ID = 3,推荐人昵称 = 4 + */ + if (KeywordType == 1) + { + var nickNames = Db.Queryable().Where(f => f.NickName.Contains(Keyword)) + .Select(f => f.Username).Take(20).ToList(); + + if (nickNames == null) + return PutData(new PageResult(new List(), tNumber, PageSize, PageIndex)); + exp.And(a => nickNames.Contains(a.Wxid)); + } + + if (KeywordType == 2) + exp.And(a => a.Wxid.Contains(Keyword)); + } + + var DataList = Db.Queryable() + .Where(exp.ToExpression()) + .LeftJoin((a, b) => a.RobotId == b.Id) + .LeftJoin((a, b, c) => a.Wxid == c.Username) + .Select((a, b, c) => new PayRecordShow + { + Id = a.Id, + Wxid = a.Wxid, + NickName = c.NickName, + RobotId = b.Id, + CashAmount = a.CashAmount, + RobotName = b.Nickname, + PayType = a.PayType, + PayTime = a.PayTime, + RecieveStatus = a.RecieveStatus, + Remark = a.Remark, + }) + .SplitTable(MinTime, MaxTime) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + } +} diff --git a/Server/Controllers/FinancialManagement/ShopController.cs b/Server/Controllers/FinancialManagement/ShopController.cs new file mode 100644 index 0000000..f62f87e --- /dev/null +++ b/Server/Controllers/FinancialManagement/ShopController.cs @@ -0,0 +1,140 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.FinancialManagement +{ + public class ShopController:DefaultController + { + /// + /// 获取商户信息信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetShops() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 新增商户 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddShop() + { + var Remark = GetString("Remark"); + var AppId = GetString("AppId", true); + var AppSecret = GetString("AppSecret", true); + var PartnerId = "";//GetString("PartnerId", true); + var PartnerKey = GetString("PartnerKey", true); + var FootTxt = GetString("FootTxt"); + var CertPath = GetString("CertPath", true); + var shopType = GetEnum("ShopType", true); + bool isExist = false; + if (shopType == ShopType.微信商户) + { + PartnerId = GetString("PartnerId", true); + isExist = Db.Queryable().Any(x => x.PartnerId == PartnerId); + } + else + { + isExist = Db.Queryable().Any(x => x.AppId == AppId); + } + if (isExist) + { + return PutData("当前商户ID已存在"); + } + + var shop = new Shop() + { + AppId = AppId, + AppSecret = AppSecret, + PartnerId = PartnerId, + PartnerKey = PartnerKey, + FootTxt = FootTxt, + CertPaths = CertPath, + Remark = Remark, + ShopType = shopType + }; + Db.Insertable(shop).ExecuteCommand(); + + return PutSuccess; + } + + /// + /// 编辑商户 + /// + /// + [HttpPost, ErrorFilter] + public WebResult SaveShop() + { + var Id = GetInt("Id", true); + var Remark = GetString("Remark"); + var AppId = GetString("AppId", true); + var AppSecret = GetString("AppSecret", true); + var PartnerKey = GetString("PartnerKey", true); + var FootTxt = GetString("FootTxt"); + var CertPath = GetString("CertPath", true); + //var shopType = GetEnum("ShopType", true); + var shop = Db.Queryable().First(x => x.Id == Id); + if (shop == null) + { + return PutData("目标商户ID不存在"); + } + if (shop.ShopType == ShopType.微信商户) + { + shop.PartnerId = GetString("PartnerId", true); + } + + shop.AppId = AppId; + shop.AppSecret = AppSecret; + shop.PartnerKey = PartnerKey; + shop.FootTxt = FootTxt; + shop.CertPaths = CertPath; + shop.Remark = Remark; + Db.Saveable(shop).ExecuteCommand(); + return PutSuccess; + } + + /// + /// 删除商户 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelShop() + { + var Id = GetInt("Id", true); + var shop = Db.Queryable().First(x => x.Id == Id); + if (shop == null) + { + return PutData("目标商户ID不存在"); + } + Db.Deleteable(shop).ExecuteCommand(); + return PutSuccess; + } + } +} diff --git a/Server/Controllers/FunctionSetting/BaseController.cs b/Server/Controllers/FunctionSetting/BaseController.cs new file mode 100644 index 0000000..ff39085 --- /dev/null +++ b/Server/Controllers/FunctionSetting/BaseController.cs @@ -0,0 +1,154 @@ +using Common.DbExtends; +using Common.DbExtends.Extends; +using Common.Models; +using Common.Models.Enums; +using Common.Models.JsonModels; +using Common.Models.UnqTables; +using Common.Utils; +using Model.JsonModels; +using Newtonsoft.Json; +using Server.MyClass.Views; +using Server.Utils; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.FunctionSetting +{ + public class BaseController : DefaultController + { + /// + /// 获取基础配置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetConfig() + { + var Id = GetInt("Id", true); + + var baseConfig = Db.GetBaseConfigById(Id); + if (baseConfig == null) baseConfig = new BaseConfig(); + + return PutData(baseConfig); + } + + /// + /// 新增基础配置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddBaseConfig() + { + string Name = GetString("Name", true); + string Cfg = GetString("Cfg", true); + var config = Db.Queryable().Where(f => f.Name == Name && f.Type == Common.Models.Enums.ConfigType.基础).First(); + + if (config != null) + return PutData("新增失败,此模板名称已存在"); + config = new ConfigData(); + config.Type = ConfigType.基础; + config.JsonContent = Cfg; + config.Name = Name; + Db.Save(config); + + return PutSuccess; + } + + /// + /// 编辑基础设置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdBaseConfig() + { + var Id = GetInt("Id", true); + string Cfg = GetString("Cfg", true); + var config = Db.GetConfigData(Id); + + if (config == null) + return PutData("编辑失败,没有此模板"); + + if (config.Type != Common.Models.Enums.ConfigType.基础) + { + return PutData("编辑失败,此模板类型不匹配"); + } + + config.JsonContent = Cfg; + Db.Save(config); + + //通知应用了配置的机器人 + var robots = Db.Queryable().Where(f => f.ConfigBaseId == config.Id).ToList(); + foreach (var robot in robots) + Client.SendClientMsg(robot.Id, DeviceMessageType.基础配置修改, new { ConfigId = config.Id }); + + return PutSuccess; + } + + + /// + /// 获取基础设置模板的名称 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetBaseNames() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + + var keyword = GetString("keyword"); + var totalNumber = 0; + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(keyword)) + { + exp.And(f => f.Name.Contains(keyword) && f.Type == Common.Models.Enums.ConfigType.基础); + } + + else + { + exp.And(f => f.Type == Common.Models.Enums.ConfigType.基础); + } + + var DataList = Db.Queryable() + .Where(exp.ToExpression()) + .Select(M => new BaseConfigShow + { + BaseConfigId = M.Id, + BaseConfigName = M.Name, + }) + .ToPageList(PageIndex, PageSize, ref totalNumber); + + var res = new PageResult(DataList, totalNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 删除基础设置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelBaseConfig() + { + var Id = GetInt("Id", true); + var config = Db.Queryable().Single(f => f.Id == Id); + + if (config != null) + { + var res = Db.Delete(config); + + if (res > 0) return PutSuccess; + } + + return PutData("删除失败,此模板不存在"); + } + } +} diff --git a/Server/Controllers/FunctionSetting/KeywordsController.cs b/Server/Controllers/FunctionSetting/KeywordsController.cs new file mode 100644 index 0000000..7e38cc0 --- /dev/null +++ b/Server/Controllers/FunctionSetting/KeywordsController.cs @@ -0,0 +1,170 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System.Web.Http; + +namespace Server.Controllers.FunctionSetting +{ + public class KeywordsController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 回复关键字查询 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetKeyword() + { + var RobotId = GetInt("RobotId", true); + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + + var tNumber = 0; + + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) exp.And(f => f.KeyWord.Contains(Keyword)); + if (RobotId >= 0) exp.And(f => f.RobotId == RobotId); + + var DataList = Db.Queryable() + .LeftJoin((f, r) => f.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((f, r) => new KeywordShow + { + KeyWord = f.KeyWord, + RobotId = r.Id, + Content = f.Content, + Id = f.Id, + KeywordType = f.KeywordType, + RobotName = r.Nickname + }) + .ToPageList(PageIndex, PageSize, ref tNumber); + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + + } + + /// + /// 新增关键词 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddKeyword() + { + var Keyword = GetString("Keyword", true); + var KeywordType = GetEnum("KeywordType", true);//2:模糊匹配 1:精准匹配 + var RobotId = GetInt("RobotId");//支持的机器人Id:0为通用消息,其他则为某个机器人 + var Content = GetString("Content"); + + var keywords = Db.Queryable().Where(f => f.KeyWord == Keyword && f.RobotId == RobotId).First(); + + if (keywords != null) + { + return PutData("添加失败,关键词已存在"); + } + + if (RobotId != 0) + { + var robot = Db.Queryable().Single(f => f.Id == RobotId); + + if (robot == null) return PutData("没有此机器人ID"); + } + else + { + keywords = new Keyword() + { + KeyWord = Keyword, + KeywordType = KeywordType, + RobotId = RobotId, + Content = Content + }; + + Client.SendClientMsg(RobotId, DeviceMessageType.修改关键词回复, new { RobotId = RobotId }); + + Db.Insertable(keywords).ExecuteCommand(); + } + + return PutSuccess; + } + + /// + /// 编辑关键字 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdKeyword() + { + var Id = GetInt("Id", true); + var Keyword = GetString("Keyword"); + var KeywordType = GetEnum("KeywordType");//2:模糊匹配 1:精准匹配 + var RobotId = GetInt("RobotId");//支持的机器人Id:0为通用消息,-1为所有机器人,其他则为某个机器人 + var Content = GetString("Content"); + + var Keywords = Db.Queryable().Single(f => f.Id == Id); + + if (Keywords == null) + { + return PutData("编辑失败,没有此关键词"); + } + + var keyword = Db.Queryable().Where(f => f.KeyWord == Keyword && f.RobotId == RobotId).First(); + if (keyword != null) return PutData("此关键词已存在,请重新输入"); + + Keywords.KeyWord = Keyword; + Keywords.KeywordType = KeywordType; + Keywords.RobotId = RobotId; + Keywords.Content = Content; + + Db.Updateable(Keywords).ExecuteCommand(); + return PutSuccess; + } + + /// + /// 删除关键词 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelKeyowrd() + { + var Id = GetInt("Id", true); + var res = Db.Deleteable().Where(f => f.Id == Id).ExecuteCommand(); + + if (res > 0) + { + Db.OnLog("服务端", "删除关键词"); + return PutSuccess; + } + + else return PutData("删除失败,没有此关键词"); + } + } +} \ No newline at end of file diff --git a/Server/Controllers/FunctionSetting/PubController.cs b/Server/Controllers/FunctionSetting/PubController.cs new file mode 100644 index 0000000..28d3994 --- /dev/null +++ b/Server/Controllers/FunctionSetting/PubController.cs @@ -0,0 +1,487 @@ +using Common.DbExtends; +using Common.DbExtends.Extends; +using Common.Models; +using Common.Models.Enums; +using Common.Models.JsonModels; +using Common.Models.UnqTables; +using Common.Utils; +using Newtonsoft.Json; +using Server.Utils; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web.Http; +namespace Server.Controllers.FunctionSetting +{ + /// + /// 全局设置 + /// + public class PubController : DefaultController + { + #region 配置存储相关 + [HttpPost, ErrorFilter] + public WebResult GetConfig() + { + var pubConfig = Db.GetPubConfig(); + if (pubConfig == null) pubConfig = new PublicConfig(); + return PutData(pubConfig); + } + + [HttpPost, ErrorFilter] + public WebResult SaveConfig() + { + //var pubConfig = Db.GetPubConfig(); + + //if (pubConfig == null) pubConfig = new PublicConfig(); + + //Util.CopyToObj(this.Param, pubConfig); + var ConfigStr = GetString("Cfg", true); + var PubConfig = JsonConvert.DeserializeObject(ConfigStr); + if (PubConfig == null) return PutData("保存失败,未能识别到您的数据"); + if (PubConfig.CashNewPrevious < 0.3 || PubConfig.CashNewNext < 0.3) return PutData("保存失败,提现金额不能低于0.3元"); + + if (PubConfig.UserStatus == UserStatus.未知 || PubConfig.KeywordStatus == UserStatus.未知 || PubConfig.RefundStatus == UserStatus.未知 || PubConfig.SameSellStatus == UserStatus.未知) + return PutData("保存失败,用户状态未设置"); + + if (!PubConfig.ShDefault && PubConfig.ShId == 0) return PutData("保存失败,您尚未选择支付的商户号"); + + var config = Db.Queryable().Where(f => f.Type == ConfigType.全局).First(); + if (config == null) config = new ConfigData() { Type = ConfigType.全局, Name = "" }; + + config.JsonContent = ConfigStr; + Db.Save(config); + + var RobotIds = Db.Queryable().Select(f => f.Id).ToList(); + if (RobotIds.Count == 0) + return PutData("添加失败,暂未发现有任何可用的机器人"); + + foreach (var RobotId in RobotIds) + Client.SendClientMsg(RobotId, DeviceMessageType.全局配置修改, new { }); + + return PutSuccess; + } + #endregion + + #region 通知API相关 + + /// + /// 查询机器人通知接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotNotify() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Name.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 编辑通知接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdRobotNotify() + { + var Id = GetInt("Id", true); + var notify = Db.Queryable() + .Single(f => f.Id == Id); + + if (notify == null) + return PutData("编辑失败,此通知接口不存在"); + + var Name = GetString("Name", true); + if (notify.Name == Name) + return PutData("编辑失败,此名称已存在"); + + notify.Name = Name; + + var ApiLocation = GetString("ApiLocation", true); + notify.ApiLocation = ApiLocation; + + var Appsecret = GetString("Appsecret"); + notify.Appsecret = Appsecret; + + if (ApiLocation.Contains("weixin")) + notify.NoticeApiType = NoticeApiType.企业微信机器人API; + + else if (ApiLocation.Contains("dingding")) + notify.NoticeApiType = NoticeApiType.企业钉钉机器人API; + + else if (ApiLocation.Contains("feishu")) + notify.NoticeApiType = NoticeApiType.飞书机器人API; + + else return PutData("编辑失败,无法识别链接类型"); + + var res = Db.Updateable(notify).ExecuteCommand(); + + if (res > 0) + return PutSuccess; + + else return PutError; + } + + /// + /// 删除通知接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DeleteNotify() + { + var Id = GetInt("Id", true); + + var res = Db.Deleteable() + .Where(f => f.Id == Id).ExecuteCommand(); + + if (res > 0) + return PutSuccess; + + return PutData("删除失败,此通知接口不存在"); + } + + /// + /// 新增通知接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddNotify() + { + var Name = GetString("Name", true); + //var NoticeApiType = GetEnum("NoticeApiType", true);//通知接口类型 : 企业钉钉机器人API =1, 企业微信机器人API = 2, 飞书机器人API = 3 + + var ApiLocation = GetString("ApiLocation", true); + + var Appsecret = GetString("Appsecret"); + + var notify = Db.Queryable().Where(f => f.Name == Name).First(); + + if (notify != null) + return PutData("新增失败,此名称已存在"); + + notify = new RobotNotify() + { + Name = Name, + Appsecret = Appsecret, + ApiLocation = ApiLocation + }; + + if (ApiLocation.Contains("weixin")) + notify.NoticeApiType = NoticeApiType.企业微信机器人API; + + else if (ApiLocation.Contains("dingding")) + notify.NoticeApiType = NoticeApiType.企业钉钉机器人API; + + else if (ApiLocation.Contains("feishu")) + notify.NoticeApiType = NoticeApiType.飞书机器人API; + + else return PutData("编辑失败,无法识别链接类型"); + + + var res = Db.Insertable(notify).ExecuteCommand(); + + if (res > 0) return PutSuccess; + + return PutError; + } + + /// + /// 测试通知接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult TestNotify() + { + var Message = GetString("Message", true); + var ApiLocation = GetString("ApiLocation", true); + var Appsecret = GetString("Appsecret"); + + var noticeApiType = NoticeApiType.其他; + + if (ApiLocation.Contains("weixin")) + noticeApiType = NoticeApiType.企业微信机器人API; + + else if (ApiLocation.Contains("dingding")) + noticeApiType = NoticeApiType.企业钉钉机器人API; + + else if (ApiLocation.Contains("feishu")) + noticeApiType = NoticeApiType.飞书机器人API; + + else return PutData("编辑失败,无法识别链接类型"); + + var result = Util.RobotNotify(Message, ApiLocation, noticeApiType, Appsecret); + if (!string.IsNullOrEmpty(result)) + return PutData(result); + + else + return PutSuccess; + } + #endregion + + + + #region 商户配置相关 + /// + /// 获取商户信息信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetShops() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 新增商户 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddShop() + { + var Remark = GetString("Remark"); + var AppId = GetString("AppId", true); + var AppSecret = GetString("AppSecret", true); + var PartnerId = "";//GetString("PartnerId", true); + var PartnerKey = GetString("PartnerKey", true); + var FootTxt = GetString("FootTxt"); + var CertPath = GetString("CertPath", true); + var shopType = GetEnum("ShopType", true); + bool isExist = false; + if (shopType == ShopType.微信商户) + { + PartnerId = GetString("PartnerId", true); + isExist = Db.Queryable().Any(x => x.PartnerId == PartnerId); + } + else + { + isExist = Db.Queryable().Any(x => x.AppId == AppId); + } + if (isExist) + { + return PutData("当前商户ID已存在"); + } + + var shop = new Shop() + { + AppId = AppId, + AppSecret = AppSecret, + PartnerId = PartnerId, + PartnerKey = PartnerKey, + FootTxt = FootTxt, + CertPaths = CertPath, + Remark = Remark, + ShopType = shopType + }; + Db.Insertable(shop).ExecuteCommand(); + + return PutSuccess; + } + + /// + /// 编辑商户 + /// + /// + [HttpPost, ErrorFilter] + public WebResult SaveShop() + { + var Id = GetInt("Id", true); + var Remark = GetString("Remark"); + var AppId = GetString("AppId", true); + var AppSecret = GetString("AppSecret", true); + //var PartnerId = GetString("PartnerId", true); + var PartnerKey = GetString("PartnerKey", true); + var FootTxt = GetString("FootTxt"); + var CertPath = GetString("CertPath", true); + //var shopType = GetEnum("ShopType", true); + var shop = Db.Queryable().First(x => x.Id == Id); + if (shop == null) + { + return PutData("目标商户ID不存在"); + } + if (shop.ShopType == ShopType.微信商户) + { + shop.PartnerId = GetString("PartnerId", true); + } + + shop.AppId = AppId; + shop.AppSecret = AppSecret; + //shop.PartnerId = PartnerId; + shop.PartnerKey = PartnerKey; + shop.FootTxt = FootTxt; + shop.CertPaths = CertPath; + shop.Remark = Remark; + Db.Storageable(shop).ExecuteCommand(); + return PutSuccess; + } + + /// + /// 删除商户 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelShop() + { + var Id = GetInt("Id", true); + var shop = Db.Queryable().First(x => x.Id == Id); + if (shop == null) + { + return PutData("目标商户ID不存在"); + } + Db.Deleteable(shop).ExecuteCommand(); + return PutSuccess; + } + #endregion + + + /// + /// 新增全局变量 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddGlobalVariable() + { + var name = GetString("Name", true); + var value = GetString("Value", true); + var item = this.Db.Queryable().Where(w => w.Name == name).First(); + if (item == null) + { + item = new GlobalVariable(); + item.Name = name; + item.Value = value; + } + else + { + return PutData("数据已经存在"); + } + this.Db.Storageable(item).ExecuteCommand(); + return PutSuccess; + } + /// + /// 编辑全局变量 + /// + /// + [HttpPost, ErrorFilter] + public WebResult EditGlobalVariable() + { + var id = GetInt("Id", true); + var name = GetString("Name", true); + var value = GetString("Value", true); + var item = this.Db.Queryable().Where(w => w.Id == id).First(); + if (item == null) + { + return PutData("数据不存在"); + } + else + { + item.Name = name; + item.Value = value; + } + this.Db.Storageable(item).ExecuteCommand(); + return PutSuccess; + } + /// + /// 分页获取全局变量 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetGlobalVariableList() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + + if (PageSize > 100) PageSize = 100; + var tNumber = 0; + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Name.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).ToPageList(PageIndex, PageSize, ref tNumber); + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + /// + /// 删除全局变量 + /// + /// + [HttpPost, ErrorFilter] + public WebResult RemoveGlobalVariable() + { + var name = GetString("Name", true); + var item = this.Db.Queryable().Where(w => w.Name == name).First(); + if (item != null) + { + this.Db.Deleteable(item).ExecuteCommand(); + } + return PutSuccess; + } + + /// + /// 设置网站信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult SetWebInfo() + { + //如果是网站上登录,但是不是创建者 + if (this.Session != null && !this.Session.IsCreator) + { + return PutData("无权操作"); + } + var logo = GetString("Logo", true); + var webColorType = GetString("WebColorType", true); + var webName = GetString("WebName", true); + var webNaviType = GetString("WebNaviType", true); + var webThemeColor = GetString("WebThemeColor"); + var copyright = GetString("Copyright"); + var data = new WebInfo() + { + Logo = logo, + WebColorType = webColorType, + WebName = webName, + WebNaviType = webNaviType, + WebThemeColor = webThemeColor, + Copyright = copyright + }; + Db.Save(data); + return PutSuccess; + } + } +} diff --git a/Server/Controllers/FunctionSetting/RebateController.cs b/Server/Controllers/FunctionSetting/RebateController.cs new file mode 100644 index 0000000..03f15ad --- /dev/null +++ b/Server/Controllers/FunctionSetting/RebateController.cs @@ -0,0 +1,350 @@ +using Common.DbExtends; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.JsonModels; +using Common.Models.UnqTables; +using Common.Utils; +using Newtonsoft.Json; +using Server.MyClass.Views; +using Server.Utils; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.FunctionSetting +{ + public class RebateController : DefaultController + { + /// + /// 获取返利配置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRebateConfig() + { + var Id = GetInt("Id", true); + + var rebateConfig = Db.GetRebateConfigById(Id); + + + if (rebateConfig == null) + { + rebateConfig = new RebateConfig(); + + return PutData(new + { + Config = rebateConfig + }); + } + + else + { + #region 返利比例ID + + List IdList = new List(); + + if (!IdList.Contains(rebateConfig.TbRebateId)) IdList.Add(rebateConfig.TbRebateId); + if (!IdList.Contains(rebateConfig.SnRebateId)) IdList.Add(rebateConfig.SnRebateId); + if (!IdList.Contains(rebateConfig.PddRebateId)) IdList.Add(rebateConfig.PddRebateId); + if (!IdList.Contains(rebateConfig.JdRebateId)) IdList.Add(rebateConfig.JdRebateId); + if (!IdList.Contains(rebateConfig.DyRebateId)) IdList.Add(rebateConfig.DyRebateId); + if (!IdList.Contains(rebateConfig.WphRebateId)) IdList.Add(rebateConfig.WphRebateId); + if (!IdList.Contains(rebateConfig.MtRebateId)) IdList.Add(rebateConfig.MtRebateId); + if (!IdList.Contains(rebateConfig.PyqRebateId)) IdList.Add(rebateConfig.PyqRebateId); + + if (IdList.Contains(0)) IdList.Remove(0); + + var ResList = Db.Queryable().Where(f => IdList.Contains(f.Id)) + .Select(f => new RebateIdsShow + { + Id = f.Id, + Name = f.Name, + + }).ToList(); + #endregion + + + return PutData(new + { + Config = rebateConfig, + RebateIds = ResList + }); + } + + } + + /// + /// 新增返利设置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddRebateConfig() + { + var Name = GetString("Name", true); + var JsonContent = GetString("JsonContent", true); + + var configData = Db.Queryable().Where(f => f.Name == Name && f.Type == Common.Models.Enums.ConfigType.返利).First(); + if (configData == null) + { + configData = new ConfigData() + { + Name = Name, + Type = Common.Models.Enums.ConfigType.返利, + JsonContent = JsonContent + }; + + Db.Save(configData); + + return PutSuccess; + } + + else + { + return PutData("添加失败,已存在该模板"); + } + } + + /// + /// 编辑返利设置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdRebateConfig() + { + var Id = GetInt("Id", true); + + var configData = Db.GetConfigData(Id); + + var JsonContent = GetString("JsonContent", true); + if (configData == null) + { + return PutData("编辑失败,此模板不存在"); + } + + if (configData.Type != ConfigType.返利) + { + return PutData("编辑失败,此模板类型不匹配"); + } + + configData.JsonContent = JsonContent; + + Db.Save(configData); + + var Robots = Db.Queryable().Where(f => f.ConfigRebateId == Id).Select(f => f.Id).ToList(); + if (Robots.Count != 0) + { + foreach (var RobotId in Robots) + Client.SendClientMsg(RobotId, DeviceMessageType.返利配置修改, new { ConfigId = Id }); + } + + return PutSuccess; + } + + /// + /// 获取返利设置模板名称 + /// + /// 返利设置模板名称 + [HttpPost, ErrorFilter] + public WebResult GetRebateInfos() + { + string KeyWord = GetString("KeyWord"); + int PageIndex = GetInt("PageIndex", true); + int PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + + int tNumber = 0; + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(KeyWord)) + { + exp.And(f => f.Name.Contains(KeyWord) && f.Type == Common.Models.Enums.ConfigType.返利); + } + + else + exp.And(f => f.Type == Common.Models.Enums.ConfigType.返利); + + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RebateConfigShow + { + Id = m.Id, + Name = m.Name, + }).ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + + return PutData(res); + } + + /// + /// 删除返利设置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelRebateConfig() + { + var Id = GetInt("Id", true); + var config = Db.Queryable().Single(f => f.Id == Id); + + if (config != null) + { + var res = Db.Delete(config); + + var Robots = Db.Queryable().Where(f => f.ConfigRebateId == Id).Select(f => f.Id).ToList(); + if (Robots.Count != 0) + { + foreach (var RobotId in Robots) + Client.SendClientMsg(RobotId, DeviceMessageType.返利配置修改, new { ConfigId = Id }); + } + + if (res > 0) return PutSuccess; + } + + return PutData("删除失败,此模板不存在"); + } + + /// + /// 查询返利模式 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRebate() + { + //关键词 + string KeyWord = GetString("KeyWord"); + int pageIndex = GetInt("PageIndex", true); + int pageSize = GetInt("PageSize", true); + int tNumber = 0; + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(KeyWord)) + { + exp.And(f => f.Name.Contains(KeyWord)); + } + + var DataList = Db.Queryable().Where(exp.ToExpression()) + .ToPageList(pageIndex, pageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, pageSize, pageIndex); + + return PutData(res); + } + + /// + /// 返回用户组ID和Name + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetUserGrouInfo() + { + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Name.Contains(Keyword)); + } + + var usergroup = Db.Queryable().Where(exp.ToExpression()) + .Select(a => new UserGroupInfo + { + Id = a.Id, + Name = a.Name, + }).ToList(); + + return PutData(usergroup); + } + + /// + /// 新增返利模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddRebate() + { + //CommissionSetting commissionSetting = new CommissionSetting(); + var Name = GetString("Name"); + var CommissionInfoStr = GetString("CommissionInfoStr", true); + + var rebate = Db.Queryable().Where(f => f.Name == Name).First(); + if (rebate != null) + { + return PutData("此模板已经存在,请重新输入"); + } + + rebate = new Rebate() + { + Name = Name, + CreateTime = DateTime.Now, + UpdateTime = DateTime.Now, + CommissionInfo = JsonConvert.DeserializeObject>(CommissionInfoStr) + }; + + Db.Save(rebate); + + return PutSuccess; + } + + /// + /// 编辑返利模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdRebate() + { + int Id = GetInt("Id", true); + string Name = GetString("Name", true); + string CommissionInfoStr = GetString("CommissionInfoStr", true); + + + var model = Db.GetRebateById(Id); + if (model == null) + { + return PutData("修改失败,此模板不存在,可能已被删除"); + } + + else + { + model.CommissionInfo = JsonConvert.DeserializeObject>(CommissionInfoStr); + model.UpdateTime = DateTime.Now; + model.Name = Name; + + Db.Save(model); + return PutSuccess; + } + } + + /// + /// 删除返利模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelRebate() + { + int Id = GetInt("Id", true); + + var rebate = Db.Deleteable().Where(x => x.Id == Id).ExecuteCommand(); + + if (rebate > 0) + return PutSuccess; + + return PutData("删除失败,没有此返利模板"); + } + } + + public class GetRebateModels + { + public int Id { get; set; } + public string Name { get; set; } + public DateTime CreateTime { get; set; } + public DateTime EditTime { get; set; } + } +} diff --git a/Server/Controllers/FunctionSetting/ReplyController.cs b/Server/Controllers/FunctionSetting/ReplyController.cs new file mode 100644 index 0000000..86f05f3 --- /dev/null +++ b/Server/Controllers/FunctionSetting/ReplyController.cs @@ -0,0 +1,211 @@ +using Common.Models.JsonModels; +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using SqlSugar; +using Common.DbExtends.Extends; +using System.Reflection; +using static Common.DbExtends.Extends.ReplyExtend; +using Server.MyClass.Views; +using Newtonsoft.Json; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Common.Models.Enums; + +namespace Server.Controllers.FunctionSetting +{ + public class ReplyController : DefaultController + { + + /// + /// 查询变量 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetReply() + { + var Id = GetInt("ConfigId", true); + var Config = Db.GetReplyConfigById(Id); + var List = TranslationByObj(Config); + return PutData(List); + } + + + + + /// + /// 新增基础配置模板 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddConfig() + { + string Name = GetString("Name", true); + var json = JObject.Parse(GetString("Cfg", true)); + var config = Db.Queryable().Where(f => f.Name == Name && f.Type == Common.Models.Enums.ConfigType.文案).First(); + if (config != null) return PutData("新增失败,此模板名称已存在"); + ReplyConfig wenan_config = new ReplyConfig(); + Util.CopyToObj(json, wenan_config); + var Cfg = JsonConvert.SerializeObject(wenan_config); + + config = new ConfigData(); + config.Type = ConfigType.文案; + config.JsonContent = Cfg; + config.Name = Name; + Db.Save(config); + + return PutSuccess; + } + + /// + /// 编辑配置 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdConfig() + { + var Id = GetInt("Id", true); + var jsondata = GetString("Cfg", true); + + var config = Db.GetConfigData(Id); + if (config == null) return PutData("编辑失败,没有此模板"); + if (config.Type != Common.Models.Enums.ConfigType.文案) + { + return PutData("编辑失败,此模板类型不匹配"); + } + + ReplyConfig wenan_config = TranslationByJson(jsondata); + + var Cfg = JsonConvert.SerializeObject(wenan_config); + config.JsonContent = Cfg; + Db.Save(config); + + + var Robots = Db.Queryable().Where(f => f.ConfigReplyId == Id).Select(f => f.Id).ToList(); + if (Robots.Count != 0) + { + foreach (var RobotId in Robots) + Client.SendClientMsg(RobotId, DeviceMessageType.返利配置修改, new { ConfigId = Id }); + } + + + return PutSuccess; + } + + private ReplyConfig TranslationByJson(string json) + { + var jArray = JsonConvert.DeserializeObject(json); + var replyConfig = new ReplyConfig(); + + + foreach (var item in jArray) + { + var pname = item["Name"].Value(); + var property = replyConfig.GetType().GetProperty(pname); + if (property != null) + { + var pobj = Activator.CreateInstance(property.PropertyType); + property.SetValue(replyConfig, pobj); + TranslationByJson(item, pobj); + } + } + return replyConfig; + } + + private void TranslationByJson(JToken token, object obj) + { + var menuTokens = token["Menus"].ToArray(); + if (!menuTokens.Any()) + { + return; + } + foreach (var item in menuTokens) + { + var pname = item["Name"].Value(); + var context = item["Content"].Value(); + var property = obj.GetType().GetProperty(pname); + if (property == null) + { + continue; + } + if (property.PropertyType == typeof(string)) + { + property.SetValue(obj, context); + } + else + { + var pobj = Activator.CreateInstance(property.PropertyType); + property.SetValue(obj, pobj); + TranslationByJson(item, pobj); + } + } + } + //private ReplyConfig TranslationByJson(ReplyShowClass obj, ReplyConfig config) + //{ + // PropertyInfo[] propertys = obj.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); + // foreach (PropertyInfo item in propertys) + // { + // var value = item.GetValue(obj) as ReplyShowClass; + // if (value == null) continue; + + // //有子菜单 + // if (value.Menus != null && value.Menus.Count > 0) + // { + // TranslationByJson(obj, config); + // } + // //没有子菜单,到了跟类 + // else + // { + + // } + // } + //} + + + + private List TranslationByObj(object obj) + { + if (obj == null) + { + return new List(); + } + var replys = new List(); + var stringType = typeof(string); + var atrType = typeof(ReplyAttribute); + PropertyInfo[] propertys = obj.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public); + foreach (var item in propertys) + { + if (item.IsDefined(atrType, true)) + { + var curAttribute = item.GetCustomAttribute(); + if (curAttribute == null)//防止异常 + { + continue; + } + var respose = new ReplyShowClass() + { + Name = item.Name, + Description = curAttribute.Describe + }; + var propertyValue = item.GetValue(obj); + if (item.PropertyType == stringType) + { + respose.PrivateVariables = curAttribute.PrivateVariables; + respose.Content = propertyValue?.ToString(); + } + else + { + respose.Menus = new List(); + respose.Menus.AddRange(TranslationByObj(propertyValue)); + } + replys.Add(respose); + } + } + return replys; + } + } +} diff --git a/Server/Controllers/FunctionSetting/ResourcesController.cs b/Server/Controllers/FunctionSetting/ResourcesController.cs new file mode 100644 index 0000000..3a3ecbe --- /dev/null +++ b/Server/Controllers/FunctionSetting/ResourcesController.cs @@ -0,0 +1,184 @@ +using Common.Models.Enums; +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Common.Utils; +using Org.BouncyCastle.Asn1.Cms; +using SqlSugar; + +namespace Server.Controllers.FunctionSetting +{ + public class ResourcesController : DefaultController + { + /// + /// 上传资源,迁移到ComControoller下面了 + /// + /// + + /// + /// 获取文件列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetList() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var fileType = GetEnum("FileType"); + var fileUse = GetEnum("FileUse"); + + if (PageSize > 100) PageSize = 100; + var tNumber = 0; + var exp = Expressionable.Create(); + if (fileType != ResourcesType.未知) + { + exp.And(w => w.FileType == fileType); + } + if (fileUse != ResourcesUse.未知) + { + exp.And(w => w.FileUse == fileUse); + } + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Filename.Contains(Keyword) || f.Filename.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).OrderBy(o => o.CreateTime, OrderByType.Desc).ToPageList(PageIndex, PageSize, ref tNumber); + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 删除文件 + /// + /// + [HttpPost, ErrorFilter] + public WebResult Remove() + { + var ids = GetIntList("Ids"); + var items = Db.Queryable().In(ids).ToList(); + if (items.Count==0) + { + return PutData("删除失败,未发现任何有关文件"); + } + var db = Db; + + bool isNotRemove = false; + db.UseTran(() => + { + foreach (var item in items) + { + if (item.FileUse == ResourcesUse.凭证 ) + { + //如果不是超级管理员 + if (Session == null || !Session.IsCreator) + { + //这个不能被删除 + isNotRemove = true; + return; + } + } + db.Deleteable(item).ExecuteCommand(); + } + }, ex => throw ex); + + + if (isNotRemove) + { + return PutData("操作失败,凭证文件非管理员不允许删除"); + } + else + { + //删除历史文件 + foreach (var item in items) + { + Util.DeleteFile(Util.MapFile(item.FileId,defaultResourcesPath)); + } + } + return PutSuccess; + } + + /// + /// 设置文件名 + /// + /// + [HttpPost, ErrorFilter] + public WebResult SetFilename() + { + var FileName = GetString("FileName"); + var id = GetLong("Id"); + var item = Db.Queryable().Where(w => w.Id == id).First(); + if (item == null) + { + return PutData("设置失败,文件不存在"); + } + item.Filename = FileName; + Db.Updateable(item).ExecuteCommand(); + return PutSuccess; + } + + private const string defaultResourcesPath = "网站\\resources"; + [HttpPost, ErrorFilter] + public WebResult ReplaceFile() + { + var Id = GetInt("Id",true); + var resources = Db.Queryable().Single(f=>f.Id == Id); + if (resources == null) return PutData("替换失败,该资源不存在或已被删除"); + + //替换只允许修改文件 + var provider = new MultipartMemoryStreamProvider(); + var r = Request.Content.ReadAsMultipartAsync(provider).Result; + System.Net.Http.StreamContent item = null; + foreach (var content in r.Contents) + { + switch (content.Headers.ContentDisposition.Name.Replace("\"", "")) + { + case "File": + item = content as System.Net.Http.StreamContent; + break; + } + } + + + using (var ms = item.ReadAsStreamAsync().Result) + { + + var oldFilename = Util.MapFile(resources.FileId, defaultResourcesPath); + + //重新修改文件ID + resources.FileId = Guid.NewGuid().ToString("N"); + resources.UpdateTime = DateTime.Now; + + //以随机数为文件名,防止同名文件被覆盖 + var fileName = Util.MapFile(resources.FileId, defaultResourcesPath); + try + { + using (var filems = File.OpenWrite(fileName)) + { + ms.CopyTo(filems); + } + } + catch (Exception ex) + { + //如果新增失败,删掉无效文件 + Util.DeleteFile(fileName); + return PutData(ex); + } + + Db.Updateable(resources).ExecuteCommand(); + + + //更新成功,删掉老文件 + Util.DeleteFile(oldFilename); + } + + return PutData(resources); + } + } +} diff --git a/Server/Controllers/FunctionSetting/nouse.cs b/Server/Controllers/FunctionSetting/nouse.cs new file mode 100644 index 0000000..ea08d5d --- /dev/null +++ b/Server/Controllers/FunctionSetting/nouse.cs @@ -0,0 +1,71 @@ +using CsharpHttpHelper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Controllers.FunctionSetting +{ + public class nouse + { + public void nouse() + { + + try + { + var http = new HttpHelper(); + var item = http.GetItem(_info.api_location); + item.Method = "post"; + item.ContentType = "application/json;";//返回类型 可选项有默认值 + switch (_info.notice_apitype) + { + case NoticeApiType.企业钉钉机器人API: + { + if (!string.IsNullOrEmpty(_info.token)) + { + long dingTimestamp = (DateTime.UtcNow.Ticks - new DateTime(1970, 1, 1, 0, 0, 0, 0).Ticks) / 10000; + string canonicalString = $"{dingTimestamp}\n{_info.token}"; + string signature = Convert.ToBase64String(Sign(Encoding.UTF8.GetBytes(canonicalString), Encoding.UTF8.GetBytes(_info.token))); + item.URL = item.URL + $"×tamp={dingTimestamp}&sign={signature}"; + } + item.PostDataType = CsharpHttpHelper.Enum.PostDataType.Byte; + item.PostdataByte = Encoding.UTF8.GetBytes(HttpHelper.ObjectToJson(new { msgtype = "text", text = new { content = _message } })); + } + break; + case NoticeApiType.企业微信机器人API: + { + item.PostDataType = CsharpHttpHelper.Enum.PostDataType.Byte; + item.PostdataByte = Encoding.UTF8.GetBytes(HttpHelper.ObjectToJson(new { msgtype = "text", text = new { content = _message } })); + } + break; + case NoticeApiType.飞书机器人API: + { + item.PostDataType = CsharpHttpHelper.Enum.PostDataType.Byte; + if (_info.api_location.Contains("bot/v2/hook")) + item.PostdataByte = Encoding.UTF8.GetBytes(HttpHelper.ObjectToJson(new { msg_type = "text", content = new { text = _message } })); + else + item.PostdataByte = Encoding.UTF8.GetBytes(HttpHelper.ObjectToJson(new { title = "", text = _message })); + } + break; + default: throw new Exception("无法识别的API类型!" + _info.notice_apitype.ToString()); + } + + var html = http.GetHtml(item).Html; + if (html.Contains("ok") || html.Contains("success")) + return; + throw new Exception(html); + } + catch (Exception ex) + { + if (ex.Message.Contains("sign not match")) + { + Thread.Sleep(370); + continue; + } + exception = ex; + EventClient.OnEvent(null, $"{_info.name}提醒失败:" + ex.Message); + } + } + } +} diff --git a/Server/Controllers/Help/RunLogController.cs b/Server/Controllers/Help/RunLogController.cs new file mode 100644 index 0000000..cd78904 --- /dev/null +++ b/Server/Controllers/Help/RunLogController.cs @@ -0,0 +1,124 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.Help +{ + public class RunLogController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 查询运行日志 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRunLog() + { + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddDays(-7); + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + var exp = Expressionable.Create(); + exp.And(f => f.CreateTime > MinTime && f.CreateTime < MaxTime); + + + var RobotId = GetInt("RobotId"); + if (RobotId > 0) exp.And(f => f.RobotId == RobotId); + + /* + * 日志类型:1:正常 2:错误 3:警告 + */ + var LogType = GetEnum("LogType"); + if (LogType > 0) exp.And(f => f.LogType == LogType); + + var Keyword = GetString("Keyword"); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Message.Contains(Keyword)); + } + + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var DataList = Db.Queryable() + .SplitTable(MinTime, MaxTime) + .LeftJoin((f, r) => f.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((f, r) => new RunLogShow + { + Id = f.Id, + CreateTime = f.CreateTime, + LogType = f.LogType, + Message = f.Message, + RobotId = f.RobotId, + RobotName = r.Nickname, + Sender = f.Sender + }) + + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + [HttpPost, ErrorFilter] + public WebResult DeleteLog() + { + var Id = GetLong("Id", true); + var CreateTime = GetTime("CreateTime", true); + + var tableName = Db.GetTableName(CreateTime); + + var res = Db.Deleteable().Where(f=>f.Id == Id).SplitTable(i => i.InTableNames(tableName)).ExecuteCommand(); + + if (res > 0) + { + Db.OnLog("服务端", "删除日志"); + return PutSuccess; + } + else + return PutData("删除失败,没有此日志"); + } + } +} diff --git a/Server/Controllers/MemberManagement/BlackListController.cs b/Server/Controllers/MemberManagement/BlackListController.cs new file mode 100644 index 0000000..80e5a0c --- /dev/null +++ b/Server/Controllers/MemberManagement/BlackListController.cs @@ -0,0 +1,248 @@ +using Common.DbExtends; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Server.Controllers.Help; +using Server.Services; +using Server.Utils; + +namespace Server.Controllers.MemberManagement +{ + public class BlacklistController : DefaultController + { + + /// + /// 获取黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetBlacklist() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + + var tNumber = 0; + + var exp = Expressionable.Create(); + exp.And(f => !f.IsDel); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.NickName.Contains(Keyword) || f.Username.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).ToPageList(PageIndex, PageSize, ref tNumber); + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + /// + /// 加白名单 + /// + /// + public WebResult AddWhite() + { + var Username = GetString("Username", true); + var userType = GetEnum("UserType", true); + + var user = Db.Queryable().Where(f => f.Username == Username && f.UserType == userType).First(); + + if (user == null) + { + user = new User() + { + Username = Username, + UserType = userType, + CreateTime = DateTime.Now, + }; + + Db.Save(user); + } + + var userData = Db.GetUserData(user.Id); + if (userData.UserStatus == UserStatus.白名单) + { + return PutData("该用户已在白名单中,请勿重复操作"); + } + + userData.UserStatus = UserStatus.白名单; + Db.Save(userData); + + return PutSuccess; + } + /// + /// 删除用户黑名单 + /// + /// + public WebResult RemoveBlack() + { + var username = GetString("Username", true); + var userType = GetEnum("UserType", true); + var isCloud = GetBoolean("IsCloud"); + + var blacklistService = new BlacklistService(); + var result = blacklistService.RemoveUserBlack(username, userType, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData("删除失败"); + } + + /// + /// 加用户黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddBlack() + { + //加黑类型 + var type = GetEnum("Type", true); + var userId = GetString("UserName", true); + var nickName = GetString("NickName"); + var blackType = GetEnum("BlackType", true); + var remark = GetString("Remark"); + var avatar = GetString("Avatar"); + var isCloud = GetBoolean("IsCloud"); + var blacklistService = new BlacklistService(); + var result = blacklistService.AddUserBlack(type, userId, nickName, blackType, avatar, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 加商品黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddGoodsBlack() + { + //加黑类型 + var goodsId = GetString("GoodsId", true); + var platform = GetEnum("Platform", true); + var storeName = GetString("StoreName"); + var remark = GetString("Remark"); + var isCloud = GetBoolean("IsCloud"); + var blacklistService = new BlacklistService(); + var result = blacklistService.AddGoodsBlack(goodsId, platform, storeName, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 删除商品黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult RemoveGoodsBlack() + { + //加黑类型 + var goodsId = GetString("GoodsId", true); + var platform = GetEnum("Platform", true); + var isCloud = GetBoolean("IsCloud"); + var blacklistService = new BlacklistService(); + var result = blacklistService.RemoveGoodsBlack(goodsId, platform, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 加店铺黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddStoreBlack() + { + //加黑类型 + var platform = GetEnum("Platform", true); + var storeId = GetString("StoreId", true); + var storeName = GetString("StoreName"); + var remark = GetString("Remark"); + var isCloud = GetBoolean("IsCloud"); + var blacklistService = new BlacklistService(); + var result = blacklistService.AddStoreBlack(platform, storeId, storeName, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 删除商店黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult RemoveStoreBlack() + { + //加黑类型 + var storeId = GetString("StoreId", true); + var platform = GetEnum("Platform", true); + var isCloud = GetBoolean("IsCloud"); + var blacklistService = new BlacklistService(); + var result = blacklistService.RemoveStoreBlack(storeId, platform, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 获取商店黑名单列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetGoodsBlacklist() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + var tNumber = 0; + var exp = Expressionable.Create(); + exp.And(f => !f.IsDel); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.StoreName.Contains(Keyword) || f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).ToPageList(PageIndex, PageSize, ref tNumber); + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + /// + /// 获取店铺黑名单列表 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetStoreBlacklist() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + var tNumber = 0; + var exp = Expressionable.Create(); + exp.And(f => !f.IsDel); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.StoreName.Contains(Keyword) || f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).ToPageList(PageIndex, PageSize, ref tNumber); + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + } +} diff --git a/Server/Controllers/MemberManagement/FansController.cs b/Server/Controllers/MemberManagement/FansController.cs new file mode 100644 index 0000000..780e49f --- /dev/null +++ b/Server/Controllers/MemberManagement/FansController.cs @@ -0,0 +1,162 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.MemberManagement +{ + /// + /// 进粉记录 + /// + public class FansController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var robotInfos = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }).Take(20).ToList(); + + return PutData(robotInfos); + } + + /// + /// 查询进粉记录 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetFansRecord() + { + var RobotId = GetInt("RobotId"); + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + + var tNumber = 0; + + var exp = Expressionable.Create(); + + if (RobotId > 0) + exp.And(f => f.RobotId == RobotId); + + if (MinTime != DateTime.MinValue) + exp.And(f => f.CreateTime > MinTime); + + if (MaxTime != DateTime.MinValue) + exp.And(f => f.CreateTime < MaxTime); + + var list = Db.Queryable() + .SplitTable(MinTime, MaxTime) + .LeftJoin((f, b) => f.RobotId == b.Id) + .Where(exp.ToExpression()) + .Select((f, b) => new FansRecordShow + { + Id = f.Id, + ApplyRemark = f.ApplyRemark, + CreateTime = f.CreateTime, + Nickname = f.Nickname, + Username = f.Username, + SourceNickname = f.SourceNickname, + SourceUsername = f.SourceUsername, + Type = f.Type, + RobotId = f.RobotId, + RobotName = b.Nickname, + Gender = f.Gender, + Operation = f.Operation, + }).ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(list, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + /// + /// 设置进粉状态 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddMoniData() + { + FansRecord f = new FansRecord() + { + ApplyRemark = "aa", + CreateTime = DateTime.Now, + Gender = SexType.未知, + Nickname = GetString("Nickname", true), + Operation = OperationStatus.待审核, + RobotId = 1, + SourceNickname = "", + SourceUsername = "", + Type = UserType.微信用户, + Username = Guid.NewGuid().ToString("N"), + }; + f.Id = Util.CreateID(f.CreateTime);//自己写的一个算法ID,可以根据时间计算出表名 + Db.Insertable(f).SplitTable().ExecuteCommand(); + return PutData(f); + } + + /// + /// 设置进粉状态 + /// + /// + [HttpPost, ErrorFilter] + public WebResult SetRecordStatus() + { + + //需要读long,否则越界 + var Id = GetLong("Id", true); + //获取表名 + var TableName = Db.GetTableNameById(Id); + var record = Db.Queryable().Where(f => f.Id == Id).SplitTable(tab => tab.InTableNames(TableName)).First(); + + if (record == null) return PutData("操作失败,当前数据不存在!"); + + //var MinTime = GetTime("MinTime", true); + //var MaxTime = GetTime("MaxTime", true); + //var record = Db.Queryable().SplitTable(MinTime, MaxTime).Single(f => f.Id == Id); + //if (record == null) + //{ + // return PutError; + //} + + var op = GetEnum("State", true); + record.Operation = op; + Db.Updateable(record).SplitTable(tab => tab.InTableNames(TableName)).ExecuteCommand(); + + //if (op == record.Operation) + //{ + // return PutError; + //} + + ////TODO 向机器人发送同步好友状态消息 + //record.Operation = op; + ////TODO 同步分表数据库 + ////Db.Updateable(record).SplitTable(MinTime, MaxTime).ExecuteCommand(); + + return PutSuccess; + } + } +} diff --git a/Server/Controllers/MemberManagement/GroupingController.cs b/Server/Controllers/MemberManagement/GroupingController.cs new file mode 100644 index 0000000..b4f9e81 --- /dev/null +++ b/Server/Controllers/MemberManagement/GroupingController.cs @@ -0,0 +1,155 @@ +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.MemberManagement +{ + + public class GroupingController : DefaultController + { + /// + /// 查询用户分组 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetUserGroups() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + + var tNumber = 0; + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + exp.And(f => f.Name.Contains(Keyword)); + + var DataList = Db.Queryable() + .LeftJoin((f, g) => f.ReplyId == g.Id) + .Where(exp.ToExpression()) + .Select((f, g) => new UserGroupView() { + AotuSort = f.AotuSort, + ConfigName = g.Name, + Describe = f.Describe, + Id = f.Id, + MaximumOrder = f.MaximumOrder, + Name = f.Name, + ReplyId = f.ReplyId + }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + /// + /// 编辑用户分组 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdUserGroup() + { + var Id = GetInt("Id", true); + var Name = GetString("Name",true); + var Describe = GetString("Describe"); + var AotuSort = GetBoolean("AotuSort"); + var MaximumOrder = GetInt("MinOrder"); + var ReplyId = GetInt("ReplyId"); + + + var user = Db.Queryable().Single(f => f.Id == Id); + + if (user == null) + { + return PutData("编辑失败,此用户组不存在或已被删除"); + } + + var cacheGroup = Db.Queryable().Where(f=>f.Name == Name).First(); + if (cacheGroup != null && cacheGroup.Id!=Id) + { + return PutData("此用户组名称已存在,请重新输入"); + } + var temp = Db.Queryable().Where(f => f.MaximumOrder == MaximumOrder).First(); + if (temp != null && temp.Id!= Id) return PutData($"编辑失败,已存在订单要求为“{MaximumOrder}”的分组!"); + user.Name = Name; + user.Describe = Describe; + user.AotuSort = AotuSort; + user.MaximumOrder = MaximumOrder; + user.ReplyId = ReplyId; + + Db.Updateable(user).ExecuteCommand(); + return PutSuccess; + } + + /// + /// 新增用户分组 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddUserGroup() + { + var Name = GetString("Name", true); + var Describe = GetString("Describe"); + var AotuSort = GetBoolean("AotuSort"); + var MaximumOrder = GetInt("MaximumOrder"); + var ReplyId = GetInt("ReplyId"); + var userGroup = Db.Queryable().Where(f =>f.Name == Name).First(); + + if (userGroup != null) + { + return PutData("已存在此名称,请重新输入"); + } + + if (AotuSort) + { + var temp = Db.Queryable().Where(f => f.MaximumOrder == MaximumOrder).First(); + if (temp != null) return PutData($"添加失败,已存在订单要求为“{MaximumOrder}”的分组!"); + } + Db.Queryable(); + + userGroup = new UserGroup() + { + Name = Name, + Describe = Describe, + AotuSort = AotuSort, + MaximumOrder = MaximumOrder, + ReplyId = ReplyId + }; + + Db.Insertable(userGroup).ExecuteCommand(); + return PutSuccess; + } + + + /// + /// 删除用户分组 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelUserGroup() + { + var Id = GetInt("Id", true); + + var user = Db.Queryable().Single(f => f.Id == Id); + + if (user == null) + { + return PutData("删除失败,此用户组不存在或已被删除"); + } + + Db.Deleteable(user).ExecuteCommand(); + + return PutSuccess; + } + } +} diff --git a/Server/Controllers/MemberManagement/ReminderController.cs b/Server/Controllers/MemberManagement/ReminderController.cs new file mode 100644 index 0000000..06a7ca5 --- /dev/null +++ b/Server/Controllers/MemberManagement/ReminderController.cs @@ -0,0 +1,126 @@ +using Common.Models.Enums; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.MemberManagement +{ + public class ReminderController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var robotInfos = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }).Take(20).ToList(); + + return PutData(robotInfos); + } + + + /// + /// 查询催单记录 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetReminder() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + var tNumber = 0; + + var RobotId = GetInt("RobotId");//机器人Id + var ReminderStatus = GetEnum("ReminderStatus");//催单状态分组ID 1:未催单 2:催单中 3:已催单 4:已下单 + var KeywordType = GetInt("KeywordType");//昵称搜索方式ID :1.用户昵称, 2.用户名 3.用户ID + + var exp = Expressionable.Create(); + + if (RobotId > 0) + exp.And((a, u, r) => r.Id == RobotId); + + if (ReminderStatus != 0) + exp.And((a, u, r) => a.RemindStatus == ReminderStatus); + + if (!string.IsNullOrEmpty(Keyword)) + { + /* + 昵称搜索方式:1.用户昵称, 2.用户名 3.用户ID + */ + if (KeywordType == 1) + exp.And((a, u, r) => u.NickName.Contains(Keyword)); + + else if (KeywordType == 2) + { + exp.And((a, u, r) => u.Username.Contains(Keyword)); + } + + else if (KeywordType == 3) + { + exp.And((a, u, r) => a.UserId == Convert.ToInt32(Keyword)); + } + } + + var DataList = Db.Queryable() + .LeftJoin((a, u) => a.UserId == u.Id) + .LeftJoin((a, u, r) => a.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((a, u, r) => new ReminderShow + { + Id = a.Id, + UserId = a.UserId, + Username = u.Username, + Nickname = u.NickName, + RobotId = r.Id, + RobotName = r.Nickname, + ReminderType = a.ReminderType, + FirstRemind = a.FirstRemind, + SecRemind = a.SecRemind, + THirRemind = a.THirRemind, + RemindStatus = a.RemindStatus, + }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + /// + /// 删除催单记录 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelReminder() + { + var Id = GetInt("Id", true); + + var reminder = Db.Queryable().Single(r => r.Id == Id); + + if (reminder == null) + return PutData("删除失败,没有此催单记录"); + + Db.Deleteable(reminder).ExecuteCommand(); + + return PutSuccess; + } + } +} diff --git a/Server/Controllers/MemberManagement/UserController.cs b/Server/Controllers/MemberManagement/UserController.cs new file mode 100644 index 0000000..a3eb187 --- /dev/null +++ b/Server/Controllers/MemberManagement/UserController.cs @@ -0,0 +1,400 @@ +using Common.DbExtends.Extends; +using Common.DbExtends.Others; +using Common.Models.SubCountTables; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Common.Models.Enums; +using Common.Models.SubTables; +using Server.Services; + +namespace Server.Controllers.MemberManagement +{ + public class UserController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var robotInfos = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname, RobotType = m.UserType }).Take(20).ToList(); + + return PutData(robotInfos); + } + + /// + /// 获取用户组信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetUserGrouInfo() + { + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Name.Contains(Keyword)); + } + + var usergroup = Db.Queryable().Where(exp.ToExpression()) + .Select(a => new UserGroupInfo + { + Id = a.Id, + Name = a.Name, + }).Take(20).ToList(); + + return PutData(usergroup); + } + + + [HttpPost, ErrorFilter] + public WebResult GetData() + { + var db = Db; + db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new MySplitService(MySplitService.MySplitType.数量); + + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + var tNumber = 0; + + var RobotId = GetInt("RobotId");//机器人Id + var GroupId = GetInt("GroupId");//分组ID + + var userExp = Expressionable.Create(); + var exp = Expressionable.Create(); + + var Keyword = GetString("Keyword"); + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType"); + + switch (KeywordType) + { + case 1://昵称搜索 + userExp.And(u => u.NickName.Contains(Keyword)); + exp.And((u1, d, g, u2, r) => u1.NickName.Contains(Keyword)); + break; + + case 2://账号搜索 + userExp.And(u1 => u1.Username.Contains(Keyword)); + exp.And((u1, d, g, u2, r) => u1.Username.Contains(Keyword)); + break; + + //case 3://账号ID搜索 + // exp.And((d, g, u1, u2, r) => d.UserId == Convert.ToInt32(Keyword)); + // break; + + //case 4://上级昵称搜索 + // exp.And((d, g, u1, u2, r) => u2.NickName == Keyword); + // break; + + //case 5://上级账号搜索 + // exp.And((d, g, u1, u2, r) => u2.Username == Keyword); + // break; + + //case 6://上级账号ID搜索 + // exp.And((d, g, u1, u2, r) => u2.Id == Convert.ToInt32(Keyword)); + // break; + default: + return PutData("查询失败,暂不支持该搜索条件"); + } + + } + + if (RobotId > 0) + exp.And((u1, d, g, u2, r) => r.Id == RobotId); + + if (GroupId > 0) + exp.And((u1, d, g, u2, r) => g.Id == GroupId); + + var ids = db.Queryable() + .Where(userExp.ToExpression()) + .OrderBy(o => o.Id) + .Select(s => s.Id) + .ToPageList(PageIndex, PageSize); + if (ids.Count <= 0) + { + return PutData(new PageResult(new List(), tNumber, PageSize, PageIndex)); + } + //var idmax = db.Queryable() + // .Where(userExp.ToExpression()) + // .OrderBy(o => o.Id) + // .Select(s => s.Id) + // .Skip(PageIndex) + // .Take(PageSize) + // .Max("Id"); + //根据最大ID,选择分页的表 + var rightQuery = db.Queryable().SplitTableById(ids.Max(s => s)); + var dataList = db.Queryable() + .LeftJoin(rightQuery, (u1, d) => d.UserId == u1.Id)//获取分组 + .LeftJoin((u1, d, g) => d.GroupId == g.Id)//获取分组 + .LeftJoin((u1, d, g, u2) => d.RecommendId == u2.Id)//获取用户的邀请人信息 + .LeftJoin((u1, d, g, u2, r) => u1.RobotId == r.Id)//获取机器人信息 + .LeftJoin((u1,d,g,u2,r,black)=> u1.Username == black.Username && u1.UserType == black.UserType) + .Where(exp.ToExpression()) + .OrderBy(u1 => u1.Id, OrderByType.Desc) + .Select((u1, d, g, u2, r, black) => new UserShow + { + Id = u1.Id, + UserId = d.UserId, + Nickname = u1.NickName, + Username = u1.Username, + RecommendId = d.RecommendId, + InviterNickname = u2.NickName, + InviterHeadurl = u2.Headurl, + InviterUsername = u2.Username, + InviterId = u2.Id, + RobotName = r.Username, + TixianAmount = d.TixianAmount, + CurPoint = d.CurPoint, + EstimateCoupon = d.EstimateCoupon, + EstimateRebate = d.EstimateRebate, + GroupId = d.GroupId, + GroupName = g.Name, + PayOrderCount = d.PayOrderCount, + QueryCount = d.QueryCount, + RecommendCount = d.RecommendCount, + TixianCount = d.TixianCount, + UserStatus = d.UserStatus, + BlackInfo = black, + Headurl = u1.Headurl, + UserType = u1.UserType + }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + foreach (var item in dataList) + { + if (item.BlackInfo != null && item.BlackInfo.Id != 0) + { + if (!item.BlackInfo.IsDel) + { + if (item.BlackInfo.IsCloud) + item.UserStatus = UserStatus.云黑名单; + else + item.UserStatus = UserStatus.黑名单; + } + } + else + { + item.BlackInfo = null; + } + } + var res = new PageResult(dataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + /// + /// 添加微信用户 + /// + /// + //[HttpPost, ErrorFilter] + //public WebResult AddWechatUser() + //{ + // var Wxid = GetString("Wxid"); + + // var user = Db.Queryable().Where(f => f.Username == Wxid).First(); + + // if (user != null) return PutData("该微信用户已存在,请勿重复添加"); + + // user = new User(); + + // Util.CopyToObj(this.Param, user); + + // Db.Insertable(user).ExecuteCommand(); + + // return PutSuccess; + //} + + + /// + /// 编辑微信用户 + /// + /// + [HttpPost, ErrorFilter] + public WebResult UpdWechatUser() + { + var Id = GetInt("Id", true); + + var wechatuser = Db.Queryable().Where(f => f.Id == Id).First(); + + if (wechatuser == null) + { + return PutData("编辑失败,没有此用户"); + } + + Util.CopyToObj(this.Param, wechatuser); + //TODO: + Db.Updateable(wechatuser) + .IgnoreColumns(it => new { it.Id, it.IsFriend, it.CreateTime, }) + .ExecuteCommand(); + + return PutSuccess; + } + + /// + /// 删除微信用户 + /// + /// + //[HttpPost, ErrorFilter] + //public WebResult DelWechatUser() + //{ + // var Id = GetInt("Id", true); + + // var wechatuser = Db.Queryable().Where(f => f.Id == Id).First(); + + // if (wechatuser == null) + // { + // return PutData("删除失败,没有此微信用户"); + // } + + // Db.Deleteable(wechatuser).ExecuteCommand(); + + // return PutSuccess; + //} + + + /// + /// 加用户黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddBlack() + { + //加黑类型 + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var blackType = GetEnum("BlackType", true); + var remark = GetString("Remark", true); + var user = Db.Queryable().Where(w => w.Id == id).First(); + if (user == null) + { + return PutData("用户不存在"); + } + + var userData = Db.GetUserData(user.Id); + //如果用户在白名单,需要恢复到正常名单 + if (userData.UserStatus == UserStatus.白名单) + { + userData.UserStatus = UserStatus.正常; + Db.Save(userData); + } + + var blacklistService = new BlacklistService(); + var result = blacklistService.AddUserBlack(user.UserType, user.Username, user.NickName, blackType, user.Headurl, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + + + /// + /// 删除用户黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DelBlack() + { + var id = GetLong("Id"); + var user = Db.Queryable().Where(w => w.Id == id).First(); + if (user == null) + { + return PutData("删除失败,用户不存在"); + } + + var blacklistService = new BlacklistService(); + var result = blacklistService.RemoveUserBlack(user.Username, user.UserType, true); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutError; + } + + + /// + /// 加白名单 + /// + /// + public WebResult AddWhite() + { + var Id = GetLong("Id",true); + + var user = Db.Queryable().Where(f => f.Id == Id).First(); + if (user == null) return PutData("操作失败,用户数据不存在"); + + var userData = Db.GetUserData(user.Id); + if (userData.UserStatus == UserStatus.白名单) return PutData("操作失败,用户已在白名单中"); + userData.UserStatus = UserStatus.白名单; + Db.Save(userData); + + //尝试删除云端的黑名单,防止用户故意拉黑后,又把自己的用户变白名单 + var blacklistService = new BlacklistService(); + var result = blacklistService.RemoveUserBlack(user.Username, user.UserType, true); + return PutSuccess; + } + + + /// + /// 删白名单 + /// + /// + public WebResult DelWhite() + { + var Id = GetLong("Id", true); + + var user = Db.Queryable().Where(f => f.Id == Id).First(); + if (user == null) return PutData("操作失败,用户数据不存在"); + + + var userData = Db.GetUserData(user.Id); + if (userData.UserStatus != UserStatus.白名单) return PutData("操作失败,用户不在白名单中"); + + userData.UserStatus = UserStatus.正常; + Db.Save(userData); + + return PutSuccess; + } + + /// + /// 修改用户积分 + /// + /// + [HttpPost, ErrorFilter] + public WebResult ChangeUserPoint() + { + var userid = GetInt("UserId", true); + var point = GetDouble("Point", true); + var remark = GetString("Remark", true); + var ResIds = GetIntList("ResIds"); + + //var voucherUrlArr = voucherUrls.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries); + Db.ChangePoint(userid, point, PointType.后台修改, remark, 0, Session==null?0:Session.Uid, ResIds.ToArray()); + return PutSuccess; + } + + + + } +} diff --git a/Server/Controllers/OnlineTools/ArtificialController.cs b/Server/Controllers/OnlineTools/ArtificialController.cs new file mode 100644 index 0000000..3000147 --- /dev/null +++ b/Server/Controllers/OnlineTools/ArtificialController.cs @@ -0,0 +1,314 @@ +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils.CpsTurns; +using Common.Utils.CpsTurns.Entitys; +using Server.Timers; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace Server.Controllers.OnlineTools +{ + ///TODO:只兼容了淘宝联盟,其他平台尚未兼容 + public class ArtificialController : DefaultController + { + + /// + /// 查询推广位 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetMedias() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + var TotalNumber = 0; + + var LianmengType = GetEnum("LianmengType", true); + switch (LianmengType) + { + case Common.Models.Enums.LianmengType.淘宝联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).OrderBy(f => f.Id, OrderByType.Desc).ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + case Common.Models.Enums.LianmengType.京东联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).OrderBy(f => f.Id, OrderByType.Desc).ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + case Common.Models.Enums.LianmengType.拼多多联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).OrderBy(f => f.Id, OrderByType.Desc).ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + case Common.Models.Enums.LianmengType.唯品会联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).OrderBy(f => f.Id, OrderByType.Desc).ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + case Common.Models.Enums.LianmengType.苏宁联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).OrderBy(f => f.Id, OrderByType.Desc).ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + case Common.Models.Enums.LianmengType.抖音联盟: + { + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Remark.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()).OrderBy(f => f.Id, OrderByType.Desc).ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + } + default: + break; + } + return PutData("暂不支持,该商品类型的推广位查询!"); + } + + + /// + /// 获得字符串中开始和结束字符串中间得值 + /// + /// 字符串 + /// 开始 + /// 结束 + /// + public static string GetValue(string str, string s, string e) + { + Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline); + return rg.Match(str).Value; + } + + /// + /// 解析宝贝 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AnalysisItem() + { + var LianmengType = GetEnum("LianmengType", true); + var Content = GetString("Content", true); + + int DataId = 0; + + switch (LianmengType) + { + case LianmengType.淘宝联盟: + case LianmengType.京东联盟: + case LianmengType.拼多多联盟: + case LianmengType.唯品会联盟: + case LianmengType.抖音联盟: + DataId = GetInt("MediaId", true); + break; + case LianmengType.苏宁联盟: + DataId = GetInt("LianmengId", true); + break; + case LianmengType.美团联盟: + break; + case LianmengType.无: + break; + default: + break; + } + + switch (LianmengType) + { + case LianmengType.淘宝联盟: + { + #region 老妖 xxx + //var tbMedia = Db.Queryable().Single(f => f.Id == MediaId); + //if (tbMedia == null) return PutData("对不起,推广位信息不存在,请先添加!"); + + //var tbLianmeng = Db.Queryable().Single(f => f.Id == tbMedia.LianmengId); + //if (tbLianmeng == null) return PutData("对不起,找不到联盟数据!"); + + //if (tbLianmeng.ExpirationTime < DateTime.Now) return PutData($"对不起,该联盟账号已过期,请重新登录!{tbLianmeng.Nickname}({tbLianmeng.Username})"); + + //TaobaoRequest req = new TaobaoRequest(tbLianmeng, tbMedia); + //var ItemId = req.AnalysisItemid(Content); + //if (string.IsNullOrEmpty(ItemId)) + //{ + // ItemId = req.ConvertItemid(Content); + //} + + //if (!string.IsNullOrEmpty(ItemId)) + //{ + // var ItemInfo = req.FindItemInfoByItemId(ItemId); + // if (ItemInfo != null) + // { + // var counpInfo = req.CreateExtUrl(ItemId); + // if (!string.IsNullOrEmpty(counpInfo.coupon_click_url)) + // { + // var r = GetValue(counpInfo.coupon_info, "减", "元"); + // //var counpAmount = 1; + // var tkl = req.CreateTkl(counpInfo.coupon_click_url); + // var rtn = new { itemId = ItemId, title = ItemInfo.n_tbk_item.FirstOrDefault().title, oriPrice = ItemInfo.n_tbk_item.FirstOrDefault().zk_final_price, counpAmount = r, link = counpInfo.coupon_click_url, tkl = tkl.password_simple, imgSrc = ItemInfo.n_tbk_item.FirstOrDefault().pict_url, orderLink = counpInfo.coupon_click_url, middleLink = "" }; + // return PutData(rtn); + + // } + // } + // else + // { + // return PutData(ItemInfo); + // } + + + //} + + ////TODO 疑似 有文案处理 + ////TODO 中间页地址 + //else return PutData("对不起,暂时无法识别您的“淘宝”文案信息!"); + #endregion + + #region 老道 + var media = Db.Queryable().Single(f => f.Id == DataId); + if (media == null) return PutData("对不起,推广位信息不存在,请先添加!"); + + var lianmeng = Db.Queryable().Single(f => f.Id == media.LianmengId); + if (lianmeng == null) return PutData("对不起,找不到联盟数据!"); + + if (lianmeng.ExpirationTime < DateTime.Now) return PutData($"对不起,该联盟账号已过期,请重新登录!{lianmeng.Nickname}({lianmeng.Username})"); + + TaobaoRequest req = new TaobaoRequest(lianmeng, media); + + var itemInfo = new TbTurn().Invoke(req, new TurnParamInfo() { DB = Db, IsComputeCommission = false, IsCreatePromotionImage = true, ItemData = Content }); + if (itemInfo != null) + return PutData(itemInfo as TbCpsInfo); + //TODO 疑似 有文案处理??这个不知道指的啥 - 需要问老妖 + else + return PutData("对不起,暂时无法识别您的“淘宝”文案信息!"); + #endregion + } + case LianmengType.京东联盟: + { + var media = Db.Queryable().Single(f => f.Id == DataId); + if (media == null) return PutData("对不起,推广位信息不存在,请先添加!"); + + var lianmeng = Db.Queryable().Single(f => f.Id == media.LianmengId); + if (lianmeng == null) return PutData("对不起,找不到联盟数据!"); + + if (lianmeng.ExpirationTime < DateTime.Now) return PutData($"对不起,该联盟账号已过期,请重新登录!{lianmeng.Nickname}({lianmeng.Username})"); + + JingdongRequest req = new JingdongRequest(lianmeng, media); + + var itemInfo = new JdTurn().Invoke(req, new TurnParamInfo() { DB = Db, IsComputeCommission = false, IsCreatePromotionImage = true, ItemData = Content }); + if (itemInfo != null) + return PutData(itemInfo as JdCpsInfo); + else + return PutData("对不起,暂时无法识别您的“京东”文案信息!"); + } + case LianmengType.拼多多联盟: + { + var media = Db.Queryable().Single(f => f.Id == DataId); + if (media == null) return PutData("对不起,推广位信息不存在,请先添加!"); + + var lianmeng = Db.Queryable().Single(f => f.Id == media.LianmengId); + if (lianmeng == null) return PutData("对不起,找不到联盟数据!"); + + if (lianmeng.ExpirationTime < DateTime.Now) return PutData($"对不起,该联盟账号已过期,请重新登录!{lianmeng.Nickname}({lianmeng.Username})"); + + PinduoRequest req = new PinduoRequest(lianmeng, media); + + var itemInfo = new PddTurn().Invoke(req, new TurnParamInfo() { DB = Db, IsComputeCommission = false, IsCreatePromotionImage = true, ItemData = Content }); + if (itemInfo != null) + return PutData(itemInfo as PddCpsInfo); + else + return PutData("对不起,暂时无法识别您的“拼多多”文案信息!"); + } + case LianmengType.唯品会联盟: + { + var media = Db.Queryable().Single(f => f.Id == DataId); + if (media == null) return PutData("对不起,推广位信息不存在,请先添加!"); + + var lianmeng = Db.Queryable().Single(f => f.Id == media.LianmengId); + if (lianmeng == null) return PutData("对不起,找不到联盟数据!"); + + if (lianmeng.ExpirationTime < DateTime.Now) return PutData($"对不起,该联盟账号已过期,请重新登录!{lianmeng.Nickname}({lianmeng.Username})"); + + WeipinhuiRequest req = new WeipinhuiRequest(lianmeng, media); + + var itemInfo = new WphTurn().Invoke(req, new TurnParamInfo() { DB = Db, IsComputeCommission = false, IsCreatePromotionImage = true, ItemData = Content }); + if (itemInfo != null) + return PutData(itemInfo as WphCpsInfo); + else + return PutData("对不起,暂时无法识别您的“唯品会”文案信息!"); + } + case LianmengType.苏宁联盟: + { + //var media = Db.Queryable().Single(f => f.Id == MediaId); + //if (media == null) return PutData("对不起,推广位信息不存在,请先添加!"); + + var lianmeng = Db.Queryable().Single(f => f.Id == DataId); + if (lianmeng == null) return PutData("对不起,找不到联盟数据!"); + + if (lianmeng.ExpirationTime < DateTime.Now) return PutData($"对不起,该联盟账号已过期,请重新登录!{lianmeng.Nickname}({lianmeng.Username})"); + + SuningRequest req = new SuningRequest(lianmeng); + + var itemInfo = new SnTurn().Invoke(req, new TurnParamInfo() { DB = Db, IsComputeCommission = false, IsCreatePromotionImage = true, ItemData = Content }); + if (itemInfo != null) + return PutData(itemInfo as SnCpsInfo); + else + return PutData("对不起,暂时无法识别您的“苏宁”文案信息!"); + } + case LianmengType.抖音联盟: + { + var media = Db.Queryable().Single(f => f.Id == DataId); + if (media == null) return PutData("对不起,推广位信息不存在,请先添加!"); + + var lianmeng = Db.Queryable().Single(f => f.Id == media.LianmengId); + if (lianmeng == null) return PutData("对不起,找不到联盟数据!"); + + if (lianmeng.ExpirationTime < DateTime.Now) return PutData($"对不起,该联盟账号已过期,请重新登录!{lianmeng.Nickname}({lianmeng.Username})"); + + DouyinRequest req = new DouyinRequest(lianmeng, media); + + var itemInfo = new DyTurn().Invoke(req, new TurnParamInfo() { DB = Db, IsComputeCommission = false, IsCreatePromotionImage = true, ItemData = Content }); + if (itemInfo != null) + return PutData(itemInfo as DyCpsInfo); + else + return PutData("对不起,暂时无法识别您的“抖音”文案信息!"); + } + default: + break; + } + + return PutData("对不起,暂时不支持该联盟操作!"); + } + } +} diff --git a/Server/Controllers/OnlineTools/FileController.cs b/Server/Controllers/OnlineTools/FileController.cs new file mode 100644 index 0000000..0ab32cf --- /dev/null +++ b/Server/Controllers/OnlineTools/FileController.cs @@ -0,0 +1,55 @@ +using Common.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.OnlineTools +{ + public class FileController : ApiController + { + [HttpPost, ErrorFilter] + public WebResult Upload() + { + WebResult result = new WebResult(); + Console.WriteLine(Request); + + var provider = new MultipartMemoryStreamProvider(); + + //读取文件数据 + var r = Request.Content.ReadAsMultipartAsync(provider).Result; + var item = provider.Contents[0]; + if (item.Headers.ContentDisposition.FileName != null) + { + var ms = item.ReadAsStreamAsync().Result; + using (var br = new BinaryReader(ms)) + { + if (ms.Length <= 0) + { + result.Data = "文件长度为空"; + } + byte[] data = br.ReadBytes((int)ms.Length); + + var fileName = Guid.NewGuid().ToString("N") + Path.GetExtension(item.Headers.ContentDisposition.FileName.Replace("\"", "")); + var path = CsharpHttpHelper.HttpExtend.MapFile(fileName, "网站\\Cache\\Images"); + + File.WriteAllBytes(path, data); + result.Ok = true; + result.Data = $"http://{Util.QueryInternetIP()}/Cache/Images/{fileName}"; + return result; + } + } + else + { + result.Data = "未知的上传内容"; + } + return result; + } + + + } +} diff --git a/Server/Controllers/OnlineTools/PyqController.cs b/Server/Controllers/OnlineTools/PyqController.cs new file mode 100644 index 0000000..c43c35f --- /dev/null +++ b/Server/Controllers/OnlineTools/PyqController.cs @@ -0,0 +1,206 @@ +using Common.Models.Enums; +using Common.Models.JsonModels; +using Common.Models.UnqTables; +using Newtonsoft.Json; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.OnlineTools +{ + public class PyqController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + /// + /// 上传图片 + /// + /// + public WebResult UploadImgUrl() + { + var Img = GetString("Img", true); + var Name = GetString("Name", true); + var fileName = Guid.NewGuid().ToString("N") + Path.GetExtension(Name); + var path = CsharpHttpHelper.HttpExtend.MapFile(fileName, "网站\\Cache\\Images"); + Img = Img.Replace("data:image/jpeg;base64,", ""); + byte[] bytes = Convert.FromBase64String(Img); + File.WriteAllBytes(path, bytes); + return PutData(new { url = $"http://{Client.InternetIP}/Cache/Images/{fileName}" }); + } + + /// + /// 删除图片 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DeleteImage() + { + var ImgUrl = GetString("ImgUrl", true); + + ImgUrl = ImgUrl.Replace('/', '\\'); + + var reg = Regex.Match(ImgUrl, @"(Cache[\w\W]+)"); + if (reg.Success) + { + var path = CsharpHttpHelper.HttpExtend.MapPath("网站\\") + reg.Groups[1].Value; + + if (File.Exists(path)) + { + File.Delete(path); + return PutSuccess; + } + } + + return PutData("删除失败,此文件不存在或无法识别路径"); + } + + /// + /// 添加到发布朋友圈 + /// + /// + public WebResult AddPyqPublish() + { + var Name = GetString("Name"); + var ResIds = GetIntList("ResIds"); + + var Copywriting = GetString("Copywriting"); + var Comment = GetString("Comment"); + var SendTime = GetTime("SendTime"); + var RobotIds = GetIntList("RobotIds"); + var IsSendAll = GetBoolean("IsSendAll"); + + if (SendTime == DateTime.MinValue) + SendTime = DateTime.Now; + + + if (IsSendAll) + { + RobotIds.Clear(); + RobotIds = Db.Queryable().Select(f => f.Id).ToList(); + } + else if (RobotIds.Count <= 0) return PutData("添加失败,至少需要选择一个机器人"); + + if (RobotIds.Count == 0) + { + return PutData("添加失败,暂未发现有任何可用的机器人"); + } + + foreach (var RobotId in RobotIds) + { + var publish = new PyqPublish() + { + Name = Name, + SendTime = SendTime, + Comment = Comment, + Copywriting = Copywriting, + ResIds = ResIds.ToArray(), + CreateTime = DateTime.Now, + RobotId = RobotId + }; + publish.Id = Db.Insertable(publish).ExecuteReturnIdentity(); + + Client.SendClientMsg(RobotId, DeviceMessageType.添加定时发送朋友圈, new { Id = publish.Id }); + } + return PutSuccess; + } + + /// + /// 删除朋友圈任务 + /// + /// + public WebResult DelSendRecord() + { + var Id = GetInt("Id", true); + + var pyqPublish = Db.Queryable().First(p => p.Id == Id); + if (pyqPublish != null) + { + Client.SendClientMsg(pyqPublish.RobotId, DeviceMessageType.删除定时发送朋友圈, new { Id = Id }); + + return Db.Deleteable(pyqPublish).ExecuteCommandHasChange() ? PutSuccess : PutError; + } + return PutError; + } + + + + /// + /// 查询发送记录 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetSendRecord() + { + var RobotId = GetInt("RobotId"); + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + //var pp = Db.Queryable().First(); + + if (RobotId > 0) + exp.And(f => f.RobotId == RobotId); + + if (!string.IsNullOrEmpty(Keyword)) + exp.And(f => f.Name.Contains(Keyword)); + + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var DataList = Db.Queryable() + .LeftJoin((f, r) => f.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((f, r) => new PyqPublishShow + { + Id = f.Id, + Name = f.Name, + RobotId = f.RobotId, + RobotNickname = r.Nickname, + SendTime = f.SendTime, + IsSend = f.IsSend, + RobotUserName = r.Username, + UserType = r.UserType, + ResIds = f.ResIds, + Comment = f.Comment, + Copywriting = f.Copywriting + }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + } +} diff --git a/Server/Controllers/OnlineTools/QunfaController.cs b/Server/Controllers/OnlineTools/QunfaController.cs new file mode 100644 index 0000000..c889c7d --- /dev/null +++ b/Server/Controllers/OnlineTools/QunfaController.cs @@ -0,0 +1,232 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Newtonsoft.Json; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.OnlineTools +{ + public class QunfaController : DefaultController + { + /// + /// 上传图片 + /// + /// + public WebResult UploadImgUrl() + { + var Img = GetString("Img", true); + var Name = GetString("Name", true); + var fileName = Guid.NewGuid().ToString("N") + Path.GetExtension(Name); + var path = CsharpHttpHelper.HttpExtend.MapFile(fileName, "网站\\Cache\\Images"); + Img = Img.Replace("data:image/jpeg;base64,", ""); + byte[] bytes = Convert.FromBase64String(Img); + File.WriteAllBytes(path, bytes); + return PutData(new { url = $"http://{Client.InternetIP}/Cache/Images/{fileName}" }); + } + + /// + /// 删除图片 + /// + /// + [HttpPost, ErrorFilter] + public WebResult DeleteImage() + { + var ImgUrl = GetString("ImgUrl", true); + + ImgUrl = ImgUrl.Replace('/', '\\'); + + var reg = Regex.Match(ImgUrl, @"(Cache[\w\W]+)"); + if (reg.Success) + { + var path = CsharpHttpHelper.HttpExtend.MapPath("网站\\") + reg.Groups[1].Value; + + if (File.Exists(path)) + { + File.Delete(path); + return PutSuccess; + } + } + + return PutData("删除失败,此文件不存在或无法识别路径"); + } + + /// + /// 查询群发任务 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult GetQunfas() + { + var Keyword = GetString("Keyword"); + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + if (PageSize > 100) PageSize = 100; + var TotalNumber = 0; + var RobotId = GetInt("RobotId"); + + var exp = Expressionable.Create(); + + if (RobotId != 0) + { + exp.And((q, r) => q.RobotId == RobotId); + } + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And((q, r) => q.Name.Contains(Keyword)); + } + + var DataList = Db.Queryable() + .LeftJoin((q, r) => q.Id == r.Id) + .Where(exp.ToExpression()) + .Select((q, r) => new QunfaShow() + { + Id = q.Id, + BuyOrderDay = q.BuyOrderDay, + Content = q.Content, + CreateTime = q.CreateTime, + FinishTime = q.FinishTime, + GroupId = q.GroupId, + Name = q.Name, + NotBuy = q.NotBuy, + NotInvitation = q.NotInvitation, + RobotId = RobotId, + RobotNick = r.Nickname, + SendMaxSleepInterval = q.SendMaxSleepInterval, + SendMinSleepInterval = q.SendMinSleepInterval, + SendNumberInterval = q.SendNumberInterval, + StartTime = q.StartTime, + Status = q.Status, + TodayMaxNumber = q.TodayMaxNumber, + Type = q.Type, + RobotUserName = r.Username, + UserType = r.UserType + }) + .ToPageList(PageIndex, PageSize, ref TotalNumber); + return PutData(new PageResult(DataList, TotalNumber, PageSize, PageIndex)); + + } + + /// + /// 新增群发 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult AddQunfa() + { + try + { + Qunfa qunfa = new Qunfa(); + qunfa.Name = GetString("Name", true); + qunfa.StartTime = GetTime("StartTime", true); + qunfa.SendNumberInterval = GetInt("SendNumberInterval", true); + qunfa.SendMinSleepInterval = GetInt("SendMinSleepInterval", true); + qunfa.SendMaxSleepInterval = GetInt("SendMaxSleepInterval", true); + qunfa.TodayMaxNumber = GetInt("TodayMaxNumber", true); + qunfa.Type = GetEnum("Type", true); + switch (qunfa.Type) + { + case QunfaType.全部好友: + break; + case QunfaType.分组好友: + qunfa.GroupId = GetIntList("GroupId", true); + break; + case QunfaType.长时间未下单: + qunfa.BuyOrderDay = GetInt("BuyOrderDay", true); + break; + case QunfaType.满足指定条件: + qunfa.NotBuy = GetBoolean("NotBuy", true); + qunfa.NotInvitation = GetBoolean("NotInvitation", true); + break; + default: + break; + } + + qunfa.Content = GetString("Content", true); + + List RobotIds = null; + if (qunfa.Type == QunfaType.全部好友) + { + RobotIds = Db.Queryable().Select(f => f.Id).ToList(); + } + else + { + RobotIds = GetIntList("RobotIds"); + } + + if (RobotIds != null && RobotIds.Count > 0) + { + foreach (var RobotId in RobotIds) + { + var qf = qunfa.CopyQunfa(RobotId);//克隆一个自己 + if (qf.GroupId == null) + { + qf.GroupId = new List(); + } + qf.Id = Db.Insertable(qf).ExecuteReturnIdentity(); + Client.SendClientMsg(RobotId, DeviceMessageType.添加群发任务, new { Id = qf.Id }); + } + + } + else return PutData("暂未发现,可用的机器人!"); + + return PutSuccess; + + + } + catch (Exception ex) + { + return PutData(ex.Message); + } + } + + /// + /// 设置群发任务状态 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult SetQunfaStatus() + { + var QunfaId = GetInt("QunfaId", true); + var Qunfa = Db.Queryable().Single(f => f.Id == QunfaId); + if (Qunfa == null) return PutData("对不起,任务不存在!"); + if (Qunfa.Status == QunfaStatus.完成) return PutData("该任务已完成,无法修改!"); + + var Status = GetEnum("QunfaStatus"); + Qunfa.Status = Status; + if (Qunfa.Status == QunfaStatus.完成) Qunfa.FinishTime = DateTime.Now; + + Db.Updateable(Qunfa).UpdateColumns(f => new { f.Status, f.FinishTime }).ExecuteCommand(); + + Client.SendClientMsg(Qunfa.RobotId, DeviceMessageType.修改群发任务状态, new { Id = QunfaId }); + return PutSuccess; + } + + /// + /// 删除群发任务 + /// + /// + [System.Web.Http.HttpPost, ErrorFilter] + public WebResult DelQunfa() + { + var Id = GetInt("Id", true); + var Qunfa = Db.Queryable().Single(f => f.Id == Id); + if (Qunfa == null) return PutData("删除失败,未找到数据!"); + + Client.SendClientMsg(Qunfa.RobotId, DeviceMessageType.删除群发任务, new { Id = Id }); + + Db.Deleteable().Where(f => f.Id == Id).ExecuteCommand(); + var TableName = Db.SplitHelper().GetTableName(Qunfa.CreateTime);//根据时间获取表名; + Db.Deleteable().Where(f => f.QunfaId == Qunfa.Id).SplitTable(tas => tas.InTableNames(TableName)).ExecuteCommand(); + return PutSuccess; + } + } +} diff --git a/Server/Controllers/OpenManagement/ComController.cs b/Server/Controllers/OpenManagement/ComController.cs new file mode 100644 index 0000000..38ee24b --- /dev/null +++ b/Server/Controllers/OpenManagement/ComController.cs @@ -0,0 +1,240 @@ +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.OpenManagement +{ + + public class ComController:DefaultController + { + private const int DefaultMaxNumber = 20; + /// + /// 搜索机器人 + /// + [HttpPost, ErrorFilter] + public WebResult SerchRobots() + { + var Keyword = GetString("Keyword"); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword) || f.Username.Contains(Keyword)); + } + + var RobotType = GetInt("RobotType"); + if (RobotType != 0) + { + exp.And(f => f.UserType == (UserType)RobotType); + } + + var DataList = Db.Queryable() + .Where(exp.ToExpression()) + .OrderBy(f=>f.Id, OrderByType.Desc) + .Select(m => new { Id = m.Id, Nickname = m.Nickname, Username = m.Username }) + .Take(DefaultMaxNumber) + .ToList(); + return PutData(DataList); + } + + /// + /// 搜索配置模板 + /// + [HttpPost, ErrorFilter] + public WebResult SerchConfigs() + { + var Keyword = GetString("Keyword"); + var exp = Expressionable.Create(); + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Name.Contains(Keyword) ); + } + + var RobotType = GetInt("ConfigType",true); + if (RobotType != 0) + { + exp.And(f => f.Type == (ConfigType)RobotType); + } + + var DataList = Db.Queryable() + .Where(exp.ToExpression()) + .OrderBy(f => f.Id, OrderByType.Desc) + .Select(m => new { Id = m.Id, Name = m.Name}) + .Take(DefaultMaxNumber) + .ToList(); + return PutData(DataList); + } + + + #region 之前的代码 + ///// + ///// 上传资源 + ///// + ///// + //[HttpPost, ErrorFilter] + //public WebResult Upload() + //{ + // //Tabale 填充这个数据,Resources + // ResourcesType fileType = ResourcesType.未知; + // ResourcesUse fileUse = ResourcesUse.未知; + // var remark = GetString("Remark", false); + // var id = GetLong("Id", false); + + + // var provider = new MultipartMemoryStreamProvider(); + // //读取文件数据 + // var r = Request.Content.ReadAsMultipartAsync(provider).Result; + // System.Net.Http.StreamContent item = null; + // foreach (var content in r.Contents) + // { + // switch (content.Headers.ContentDisposition.Name.Replace("\"", "")) + // { + // case "FileType": + // fileType = (ResourcesType)Enum.Parse(typeof(ResourcesType), content.ReadAsStringAsync().Result); + // break; + // case "FileUse": + // fileUse = (ResourcesUse)Enum.Parse(typeof(ResourcesUse), content.ReadAsStringAsync().Result); + // break; + // case "Remark": + // remark = content.ReadAsStringAsync().Result; + // break; + // case "File": + // item = content as System.Net.Http.StreamContent; + // break; + // } + // } + // //var item = provider.Contents[0]; + // if (string.IsNullOrWhiteSpace(item.Headers.ContentDisposition.FileName)) + // { + // return PutData("文件名不存在"); + // } + // string upfileName = item.Headers.ContentDisposition.FileName.Replace("\"", ""); + // var resources = this.Db.Queryable().Where(w => w.Id == id).First(); + // if (id == 0) + // { + // resources = new Resources(); + // resources.Remark = remark; + // resources.CreateTime = DateTime.Now; + // resources.FileType = fileType; + // resources.FileUse = fileUse; + // resources.Filename = upfileName; + // resources.UpdateTime = DateTime.Now; + // resources.FileId = Guid.NewGuid().ToString("N"); + // } + // else + // { + // if (resources == null) + // { + // return PutData("更新失败,数据不存在。"); + // } + // resources.Remark = remark; + // resources.FileType = fileType; + // resources.FileUse = fileUse; + // resources.Filename = upfileName; + // resources.UpdateTime = DateTime.Now; + // resources.FileId = Guid.NewGuid().ToString("N"); + // } + // using (var ms = item.ReadAsStreamAsync().Result) + // { + // if (ms.Length <= 0) + // { + // return PutData("文件长度为空"); + // } + // if (resources.Id == 0) + // { + // this.Db.Insertable(resources).ExecuteReturnEntity(); + // } + // else + // { + // this.Db.Updateable(resources).ExecuteCommand(); + // //删除老文件 + // //var oldfileName = resources.FileId + Path.GetExtension(resources.Filename); + // var oldfileName = resources.Filename; + // var oldpath = CsharpHttpHelper.HttpExtend.MapFile(oldfileName, "网站\\resources"); + // if (File.Exists(oldpath)) + // { + // File.Delete(oldpath); + // } + // } + // //var fileName = resources.FileId + Path.GetExtension(upfileName); + // var fileName = resources.Filename; + // var path = CsharpHttpHelper.HttpExtend.MapFile(fileName, "网站\\resources"); + // using (var filems = File.OpenWrite(path)) + // { + // ms.CopyTo(filems); + // } + + // return new WebResult() + // { + // Ok = true, + // Data = resources + // }; + // } + //} + #endregion + + + private const string defaultResourcesPath = "网站\\resources"; + [HttpPost, ErrorFilter] + public WebResult UploadFile() + { + Resources resources = new Resources(); + + //读取文件数据 + var provider = new MultipartMemoryStreamProvider(); + var r = Request.Content.ReadAsMultipartAsync(provider).Result; + System.Net.Http.StreamContent item = null; + foreach (var content in r.Contents) + { + switch (content.Headers.ContentDisposition.Name.Replace("\"", "")) + { + case "FileType": + resources.FileType = (ResourcesType)Enum.Parse(typeof(ResourcesType), content.ReadAsStringAsync().Result); + break; + case "FileUse": + resources.FileUse = (ResourcesUse)Enum.Parse(typeof(ResourcesUse), content.ReadAsStringAsync().Result); + break; + case "File": + item = content as System.Net.Http.StreamContent; + break; + } + } + + using (var ms = item.ReadAsStreamAsync().Result) + { + resources.FileId = Guid.NewGuid().ToString("N"); + resources.UpdateTime = DateTime.Now; + resources.CreateTime = DateTime.Now; + resources.Filename = item.Headers.ContentDisposition.FileName.Replace("\"", ""); + + //以随机数为文件名,防止同名文件被覆盖 + var fileName = Util.MapFile(resources.FileId, defaultResourcesPath); + try + { + using (var filems = File.OpenWrite(fileName)) + { + ms.CopyTo(filems); + } + } + catch (Exception ex) + { + //写入失败,删除无效文件 + Util.DeleteFile(fileName); + return PutData(ex); + } + resources.Id = Db.Insertable(resources).ExecuteReturnIdentity(); + } + + return PutData(resources); + } + } +} diff --git a/Server/Controllers/OpenManagement/DataMigrationController.cs b/Server/Controllers/OpenManagement/DataMigrationController.cs new file mode 100644 index 0000000..380e3dc --- /dev/null +++ b/Server/Controllers/OpenManagement/DataMigrationController.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Net.Http; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Common.Utils; +using Server.Services.DataMigration; + +namespace Server.Controllers.OpenManagement +{ + /// + /// 数据迁移Api + /// + public class DataMigrationController : DefaultController + { + private const string defaultTempPath = "Temp"; + + /// + /// 上传数据 + /// + /// + [HttpPost, ErrorFilter] + public WebResult Upload() + { + //替换只允许修改文件 + var provider = new MultipartMemoryStreamProvider(); + var r = Request.Content.ReadAsMultipartAsync(provider).Result; + System.Net.Http.StreamContent item = null; + foreach (var content in r.Contents) + { + switch (content.Headers.ContentDisposition.Name.Replace("\"", "")) + { + case "File": + item = content as System.Net.Http.StreamContent; + break; + } + } + var fileName = Util.MapFile("datamigration.zip", defaultTempPath); + //删除旧数据 + Util.DeleteFile(fileName); + using (var ms = item.ReadAsStreamAsync().Result) + { + try + { + using (var filems = File.OpenWrite(fileName)) + { + ms.CopyTo(filems); + } + } + catch (Exception ex) + { + //如果新增失败,删掉无效文件 + Util.DeleteFile(fileName); + return PutData(ex); + } + } + return PutSuccess; + } + /// + /// 检查上传的数据 + /// + /// + [HttpPost, ErrorFilter] + public WebResult Check() + { + var fileName = Util.MapFile("datamigration.zip", defaultTempPath); + if (!File.Exists(fileName)) + { + return PutData("请先上传数据。"); + } + var err = DataMigrationManageSerivce.Instance.Check(fileName); + if (string.IsNullOrWhiteSpace(err)) + { + return PutSuccess; + } + return PutData(err); + } + /// + /// 开始导入 + /// + /// + [HttpPost, ErrorFilter] + public WebResult OpenImport() + { + var state = DataMigrationProgressService.Instance.GetState(); + if (state != null && state.State == 1) + { + return PutData("后台已经正在处理中,请不要重复操作。"); + } + var fileName = Util.MapFile("datamigration.zip", defaultTempPath); + if (!File.Exists(fileName)) + { + return PutData("请先上传数据。"); + } + var err = DataMigrationManageSerivce.Instance.Start(fileName); + if (string.IsNullOrWhiteSpace(err)) + { + return PutSuccess; + } + return PutData(err); + } + /// + /// 获取进度 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetProgress() + { + var state = DataMigrationProgressService.Instance.GetState(); + if (state == null) + { + return PutData("当前还未开始"); + } + return PutData(new + { + StartDateTime = state.StartDateTime, + EndDateTime = state.EndDateTime, + Logs = state.Logs.ToArray(), + State = state.State, + ElapsedTime = state.ElapsedTime.ToString("0.00") + }); + } + } +} diff --git a/Server/Controllers/OpenManagement/DeviceController.cs b/Server/Controllers/OpenManagement/DeviceController.cs new file mode 100644 index 0000000..f2b7d69 --- /dev/null +++ b/Server/Controllers/OpenManagement/DeviceController.cs @@ -0,0 +1,159 @@ +using Common.Models.PubClass; +using Common.Models.UnqTables; +using Server.MyClass.Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.OpenManagement +{ + public class DeviceController : DefaultController + { + /// + /// 连接客户端 + /// + /// + [HttpPost, ErrorFilter] + public WebResult Connection() + { + var Id = GetString("Id", true); + var InternetIP = GetString("InternetIP", true); + var ClientVersion = GetString("ClientVersion", true); + Version v = null; + if (Id.Length != 32) return PutData("Id 建议生成32位的唯一数,保证设备的准确性!"); + if (!Regex.Match(InternetIP, @"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})").Success) return PutData("IP信息不准确,请务必查询真实外网IP!"); + if (!Version.TryParse(ClientVersion, out v)) return PutData("您的版本信息有误,请输入一个正确的版本信息!"); + + Device Device = Db.Queryable().Single(f => f.Id == Id); + if (Device == null) + { + Device = new Device() + { + Id = Id + }; + } + Device.Version = ClientVersion; + Device.InternetIP = InternetIP; + Device.Token = System.Guid.NewGuid().ToString(); + Device.LoginTime = DateTime.Now; + Db.Storageable(Device).ExecuteCommand(); + + if (Client.OnlineDevices.ContainsKey(Id)) + { + Client.OnlineDevices[Id] = new MyClass.Class.DeviceSession(); + } + else + { + if (!Client.OnlineDevices.TryAdd(Id, new MyClass.Class.DeviceSession())) return PutError; + } + + return PutData(new + { + Token = Device.Token, + MysqlName = Client.Config.MysqlName, + MysqlHost = Client.Config.MysqlHost, + MysqlPort = Client.Config.MysqlPort, + MysqlPass = Client.Config.MysqlPass, + MysqlUser = Client.Config.MysqlUser + }); + } + + + [HttpPost, ErrorFilter] + public WebResult Reading() + { + + var session = CheckLoginDevice(); + if (session == null) return PutData("机器人登录失效,请重新登录"); + + //如果服务端重启了,有可能就找不到,所以这里需要自动添加 + try + { + session.IsReading = true; + session.ReadTime = DateTime.Now; + List ResposeMsgs = new List(); + var time = DateTime.Now.AddSeconds(180); + while (time > DateTime.Now) + { + if (session.Messages.Count > 0) + { + var Msg = session.Messages.Dequeue(); + if (Msg != null) ResposeMsgs.Add(Msg); + } + else + { + if (ResposeMsgs.Count > 0) break; + Thread.Sleep(100); + continue; + } + } + + return PutData(ResposeMsgs); + } + finally + { + session.IsReading = false; + } + + + } + + [HttpPost, ErrorFilter] + public WebResult Reply() + { + var device = CheckLoginDevice(); + if (device == null) return PutData("机器人登录失效,请重新登录"); + + //要回复的ID + var Replyid = GetString("Msgid", true); + var Content = GetString("Content", true); + Client.ReplyMessages.Add(Replyid, new DeviceReplyMessage() { Replyid = Replyid, Content = Content, CreateTime = DateTime.Now }); + return PutSuccess; + + } + + [HttpPost, ErrorFilter] + public WebResult SetRobotId() + { + var session = CheckLoginDevice(); + if (session == null) return PutData("机器人登录失效,请重新登录"); + + var robotId = GetInt("RobotId", true); + if (robotId == 0) return PutData("设置失败,机器人的编号不能为0"); + if (robotId != device.RobotId) + { + var oldRobots = Client.OnlineDevices.Where(x => x.Value.RobotId == robotId && x.Key != device.Id).ToList(); + foreach (var item in oldRobots) + { + Client.OnlineDevices.TryRemove(item.Key, out _); + } + session.RobotId = robotId; + device.RobotId = robotId; + session.RobotId = robotId; + Db.Storageable(device).ExecuteCommand(); + } + return PutSuccess; + } + + private Device device; + private DeviceSession CheckLoginDevice() + { + var Id = GetString("Id", true); + var Token = GetString("Token", true); + device = Db.Queryable().WithCache().Single(f => f.Id == Id); + if (Client.OnlineDevices.ContainsKey(Id) && device != null && device.Token == Token) + { + return Client.OnlineDevices[Id]; + } + return null; + + + + } + } +} diff --git a/Server/Controllers/OpenManagement/OpenController.cs b/Server/Controllers/OpenManagement/OpenController.cs new file mode 100644 index 0000000..1d4f9f1 --- /dev/null +++ b/Server/Controllers/OpenManagement/OpenController.cs @@ -0,0 +1,159 @@ +using Common.Models.UnqTables; +using CsharpHttpHelper; +using Newtonsoft.Json; +using Server.MyClass.Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.JsonModels; + +namespace Server.Controllers.OpenManagement +{ + public class OpenController:DefaultController + { + + public class Slider + { + public bool sliderSuccessed { get; set; } + + public int y { get; set; } + + public string src { get; set; } + + public bool sliderVisible { get; set; } + + public int sliderMx { get; set; } + } + /// + /// 登录接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult Login() + { + var Username = GetString("Username",true); + var Password = GetString("Password",true); + var user = Db.Queryable().Where(f=>f.Username == Username).First(); + if (user == null || Password != user.Password) + { + return PutData("登录失败,用户名或密码错误!"); + } + if (Client.OnlineUsers.ContainsKey(user.Id)) + { + if (!Client.OnlineUsers.TryRemove(user.Id, out var oldUser)) + { + return PutError; + } + } + var session = new UserSession(user); + session.IsCreator = user.IsCreator; + if (!Client.OnlineUsers.TryAdd(user.Id, session)) + { + return PutError; + } + + return PutData(session); + } + /// + /// 背景图 + /// + private static readonly List bgs = new List() { "/imgs/clouds.jpg", "/imgs/leafs.jpg", "/imgs/moon.jpg", "/imgs/mountains.jpg", "/imgs/rocks.jpg" }; + /// + /// 登录接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetCaptch() + { + Random random = new Random(); + + var slider = new Slider() + { + sliderSuccessed = false, + sliderMx = random.Next(130, 230), + y = random.Next(10,99), + sliderVisible = true, + src = bgs[random.Next(0,bgs.Count - 1)] + }; + var base64Str = HttpExtend.StringToBase64String(JsonConvert.SerializeObject(slider)); + var Id = Guid.NewGuid().ToString("N"); + Client.Cache.Add(Id, slider, 60*2); + return PutData(new {Id = Id, Data = base64Str }); + } + + /// + /// 登录接口 + /// + /// + [HttpPost, ErrorFilter] + public WebResult CheckCaptch() + { + var Id = GetString("Id", true); + var time = GetDouble("Time", true); + var X = GetInt("X", true); + try + { + var target = Client.Cache.Get(Id); + var min = target.sliderMx - 10; + var max = target.sliderMx + 10; + time = time / 1000; + if (X > min && X < max) + { + if (time < 0.5) + { + return PutData("哎呀,手速太快啦"); + } + else if (time > 5) + { + return PutData("哎呀,手速太慢啦"); + } + else + { + return PutSuccess; + } + } + else + { + return PutData("出现错误"); + } + } + catch (Exception ) + { + return PutError; + } + } + + /// + /// 退出登录 + /// + + [HttpPost, ErrorFilter] + public WebResult Logout() + { + if (Session != null) + { + if (!Client.OnlineUsers.TryRemove(Session.Uid, out _)) + { + + return PutError; + } + } + return PutSuccess; + } + /// + /// 获取网站信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetWebInfo() + { + return PutData(Db.GetMapValue("WebInfo", () => null)); + } + + } +} diff --git a/Server/Controllers/OrderManagement/DyOrderController.cs b/Server/Controllers/OrderManagement/DyOrderController.cs new file mode 100644 index 0000000..bc33037 --- /dev/null +++ b/Server/Controllers/OrderManagement/DyOrderController.cs @@ -0,0 +1,132 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; + +namespace Server.Controllers.OrderManagement +{ + public class DyOrderController:DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 查询京东订单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetDyOrders() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + var exp = Expressionable.Create(); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-3); + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + exp.And((o, u, r) => o.pay_success_time > MinTime && o.pay_success_time < MaxTime); + + var RobotId = GetInt("RobotId"); + if (RobotId > 0) + exp.And((o, u, r) => r.Id == RobotId); + + var OrderStatus = GetEnum("OrderStatus"); + + if (OrderStatus != SystemOrderStatus.未知) + exp.And((o, u, r) => o.SystemOrderStatus == OrderStatus); + + var Keyword = GetString("Keyword"); + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType", true); + + switch (KeywordType) + { + case 1://用户账号查询 + exp.And((o, u, r) => u.Username.Contains(Keyword)); + break; + case 2://用户昵称查询 + exp.And((o, u, r) => u.NickName.Contains(Keyword)); + break; + case 3://订单编号查询 + exp.And((o, u, r) => o.order_id.ToString().Contains(Keyword)); + break; + case 4://商品编号查询 + exp.And((o, u, r) => o.item_num.ToString().Contains(Keyword)); + break; + case 5://商品名称 + exp.And((o, u, r) => o.product_name.Contains(Keyword)); + break; + default: + break; + } + } + + var DataList = Db.Queryable() + .SplitTable(it => it.Take(6)) + .LeftJoin((o, u) => o.UserId == u.Id) + .LeftJoin((o, u, r) => u.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((o, u, r) => new DyOrderShow + { + //ItemCount = Convert.ToInt32(o.), //? + //Itemid = o.item_num.ToString(), + //ItemTitle = o.product_name, + //OrderStatus = o.SystemOrderStatus, + //PayPrice = o.settled_tech_service_fee, + //UserHeadurl = u.Headurl, + //UserId = o.UserId, + //UsOrderNumber = o.orderId.ToString(), + //UserNickname = u.NickName, + //RobotName = r.Nickname, + //PartnerPoint = 0.00, //? + //RebatePoint = o.subSideRate, //? + //TkOrderNumber = null, // 联盟订单编号 ? + //RecommendPoint = 0.00, //? + //Commission = o.commissionRate,//? + //GrossProfit = o.estimateCosPrice, //? + }).ToPageList(PageIndex, PageSize, ref tNumber); + + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + } +} diff --git a/Server/Controllers/OrderManagement/JdOrderController.cs b/Server/Controllers/OrderManagement/JdOrderController.cs new file mode 100644 index 0000000..b17527b --- /dev/null +++ b/Server/Controllers/OrderManagement/JdOrderController.cs @@ -0,0 +1,180 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Server.Services; + +namespace Server.Controllers.OrderManagement +{ + public class JdOrderController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 查询京东订单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetJdOrders() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + var exp = Expressionable.Create(); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-3); + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + exp.And((o, u, r) => o.orderTime > MinTime && o.orderTime < MaxTime); + + var RobotId = GetInt("RobotId"); + if (RobotId > 0) + exp.And((o, u, r) => r.Id == RobotId); + + var OrderStatus = GetEnum("OrderStatus"); + + if (OrderStatus != SystemOrderStatus.未知) + exp.And((o, u, r) => o.SystemOrderStatus == OrderStatus); + + var Keyword = GetString("Keyword"); + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType", true); + + switch (KeywordType) + { + case 1://用户账号查询 + exp.And((o, u, r) => u.Username.Contains(Keyword)); + break; + case 2://用户昵称查询 + exp.And((o, u, r) => u.NickName.Contains(Keyword)); + break; + case 3://订单编号查询 + exp.And((o, u, r) => o.orderId.ToString().Contains(Keyword)); + break; + case 4://商品编号查询 + exp.And((o, u, r) => o.skuId.ToString().Contains(Keyword)); + break; + case 5://商品名称 + exp.And((o, u, r) => o.skuName.Contains(Keyword)); + break; + } + } + + var DataList = Db.Queryable() + .SplitTable(it => it.Take(6)) + .LeftJoin((o, u) => o.UserId == u.Id) + .LeftJoin((o, u, r) => u.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((o, u, r) => new JdOrderShow + { + ItemCount = Convert.ToInt32(o.skuNum), //? + Itemid = o.skuId.ToString(), + ItemTitle = o.skuName, + OrderStatus = o.SystemOrderStatus, + PayPrice = o.price, + UserHeadurl = u.Headurl, + UserId = o.UserId, + UsOrderNumber = o.orderId.ToString(), + UserNickname = u.NickName, + RobotName = r.Nickname, + PartnerPoint = 0.00, //? + RebatePoint = o.subSideRate, //? + TkOrderNumber = null, // 联盟订单编号 ? + RecommendPoint = 0.00, //? + Commission = o.commissionRate,//? + GrossProfit = o.estimateCosPrice, //? + }).ToPageList(PageIndex, PageSize, ref tNumber); + + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + + + /// + /// 加京东商店黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddGoodsBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddGoodsBlack(order.skuId, LianmengType.京东联盟, order.skuName, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 加京东店铺黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddStoreBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddStoreBlack(LianmengType.京东联盟, order.popId + "", "", remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + } +} diff --git a/Server/Controllers/OrderManagement/PddOrderController.cs b/Server/Controllers/OrderManagement/PddOrderController.cs new file mode 100644 index 0000000..5f05183 --- /dev/null +++ b/Server/Controllers/OrderManagement/PddOrderController.cs @@ -0,0 +1,175 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Server.Services; + +namespace Server.Controllers.OrderManagement +{ + public class PddOrderController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + [HttpPost, ErrorFilter] + public WebResult GetPddOrders() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + var exp = Expressionable.Create(); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-3); + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + exp.And((o, u, r) => o.order_create_time > MinTime && o.order_create_time < MaxTime); + + var RobotId = GetInt("RobotId"); + if (RobotId > 0) + exp.And((o, u, r) => r.Id == RobotId); + + var OrderStatus = GetEnum("OrderStatus"); + + if (OrderStatus != SystemOrderStatus.未知) + exp.And((o, u, r) => o.SystemOrderStatus == OrderStatus); + + var Keyword = GetString("Keyword"); + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType", true); + + switch (KeywordType) + { + case 1://用户账号查询 + exp.And((o, u, r) => u.Username.Contains(Keyword)); + break; + case 2://用户昵称查询 + exp.And((o, u, r) => u.NickName.Contains(Keyword)); + break; + case 3://订单编号查询 + exp.And((o, u, r) => o.order_sn.ToString().Contains(Keyword)); + break; + case 4://商品编号查询 + exp.And((o, u, r) => o.goods_id.ToString().Contains(Keyword)); + break; + case 5://商品名称 + exp.And((o, u, r) => o.goods_name.Contains(Keyword)); + break; + default: + break; + } + } + + var DataList = Db.Queryable() + .SplitTable(it => it.Take(6)) + .LeftJoin((o, u) => o.UserId == u.Id) + .LeftJoin((o, u, r) => u.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((o, u, r) => new PddOrderShow + { + ItemCount = o.goods_quantity, //? + Itemid = o.goods_id.ToString(), + ItemTitle = o.goods_name, + OrderStatus = o.SystemOrderStatus, + PayPrice = o.order_amount, + UserHeadurl = u.Headurl, + UserId = o.UserId, + UsOrderNumber = o.order_sn.ToString(), + UserNickname = u.NickName, + RobotName = r.Nickname, + PartnerPoint = 0.00, //? + RebatePoint = o.promotion_amount, //? + TkOrderNumber = null, // 联盟订单编号 ? + RecommendPoint = 0.00, //? + Commission = o.promotion_amount,//? + GrossProfit = o.promotion_rate, //? + }).ToPageList(PageIndex, PageSize, ref tNumber); + + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + /// + /// 加拼多多商店黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddGoodsBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddGoodsBlack(order.goods_id + "", LianmengType.拼多多联盟, order.goods_name, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 加拼多多店铺黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddStoreBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddStoreBlack(LianmengType.拼多多联盟, order.mall_id + "", "", remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + } +} diff --git a/Server/Controllers/OrderManagement/SnOrderController.cs b/Server/Controllers/OrderManagement/SnOrderController.cs new file mode 100644 index 0000000..2265cf0 --- /dev/null +++ b/Server/Controllers/OrderManagement/SnOrderController.cs @@ -0,0 +1,177 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Server.Services; + +namespace Server.Controllers.OrderManagement +{ + public class SnOrderController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + [HttpPost, ErrorFilter] + public WebResult GetSnOrders() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + var exp = Expressionable.Create(); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-3); + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + exp.And((o, u, r) => o.orderSubmitTime > MinTime && o.orderSubmitTime < MaxTime); + + var RobotId = GetInt("RobotId"); + if (RobotId > 0) + exp.And((o, u, r) => r.Id == RobotId); + + var OrderStatus = GetEnum("OrderStatus"); + + if (OrderStatus != SystemOrderStatus.未知) + exp.And((o, u, r) => o.SystemOrderStatus == OrderStatus); + + var Keyword = GetString("Keyword"); + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType", true); + + switch (KeywordType) + { + case 1://用户账号查询 + exp.And((o, u, r) => u.Username.Contains(Keyword)); + break; + case 2://用户昵称查询 + exp.And((o, u, r) => u.NickName.Contains(Keyword)); + break; + case 3://订单编号查询 + exp.And((o, u, r) => o.orderCode.ToString().Contains(Keyword)); + break; + case 4://商品编号查询 + exp.And((o, u, r) => o.goodsNum.ToString().Contains(Keyword)); + break; + case 5://商品名称 + exp.And((o, u, r) => o.productName.Contains(Keyword)); + break; + default: + break; + } + } + + var DataList = Db.Queryable() + .SplitTable(it => it.Take(6)) + .LeftJoin((o, u) => o.UserId == u.Id) + .LeftJoin((o, u, r) => u.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((o, u, r) => new SnOrderShow + { + ItemCount = Convert.ToInt32(o.saleNum), //? + Itemid = o.goodsNum.ToString(), + ItemTitle = o.productName, + OrderStatus = o.SystemOrderStatus, + PayPrice = double.Parse(o.payAmount), + UserHeadurl = u.Headurl, + UserId = o.UserId, + UsOrderNumber = o.orderCode.ToString(), + UserNickname = u.NickName, + RobotName = r.Nickname, + PartnerPoint = 0.00, //? + RebatePoint = 0.00, //? + TkOrderNumber = null, // 联盟订单编号 ? + RecommendPoint = 0.00, //? + Commission = double.Parse(o.prePayCommission),//? + GrossProfit = double.Parse(o.commissionRatio), //? + }).ToPageList(PageIndex, PageSize, ref tNumber); + + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + + /// + /// 加苏宁商店黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddGoodsBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddGoodsBlack(order.goodsNum + "", LianmengType.苏宁联盟, order.productName, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 加苏宁店铺黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddStoreBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddStoreBlack(LianmengType.苏宁联盟, order.mallId + "", order.sellName, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + } +} diff --git a/Server/Controllers/OrderManagement/TbOrderController.cs b/Server/Controllers/OrderManagement/TbOrderController.cs new file mode 100644 index 0000000..7a8aa5a --- /dev/null +++ b/Server/Controllers/OrderManagement/TbOrderController.cs @@ -0,0 +1,179 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Server.Services; + +namespace Server.Controllers.OrderManagement +{ + public class TbOrderController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + /// + /// 查询淘宝订单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetTbOrders() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + var exp = Expressionable.Create(); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-3); + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + exp.And((o, u, r) => o.tk_create_time > MinTime && o.tk_create_time < MaxTime); + + var RobotId = GetInt("RobotId"); + if (RobotId > 0) + exp.And((o, u, r) => r.Id == RobotId); + + var OrderStatus = GetEnum("OrderStatus"); + + if (OrderStatus != SystemOrderStatus.未知) + exp.And((o, u, r) => o.SystemOrderStatus == OrderStatus); + + var Keyword = GetString("Keyword"); + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType", true); + + switch (KeywordType) + { + case 1://用户账号查询 + exp.And((o, u, r) => u.Username.Contains(Keyword)); + break; + case 2://用户昵称查询 + exp.And((o, u, r) => u.NickName.Contains(Keyword)); + break; + case 3://订单编号查询 + exp.And((o, u, r) => o.trade_id.Contains(Keyword) || o.trade_parent_id.Contains(Keyword)); + break; + case 4://商品编号查询 + exp.And((o, u, r) => o.item_id.Contains(Keyword)); + break; + case 5://商品名称 + exp.And((o, u, r) => o.item_title.Contains(Keyword)); + break; + default: + break; + } + } + + var DataList = Db.Queryable() + .SplitTable(it=>it.Take(6)) + .LeftJoin((o, u) => o.UserId == u.Id) + .LeftJoin((o, u, r) => u.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((o, u, r) => new TboderShow + { + ItemCount = o.item_num, + Itemid = o.item_id, + ItemTitle = o.item_title, + OrderStatus = o.SystemOrderStatus, + PayPrice = double.Parse(o.pay_price), + UserHeadurl = u.Headurl, + UserId = o.UserId, + UsOrderNumber = o.trade_id, + UserNickname = u.NickName, + RobotName = r.Nickname, + PartnerPoint = 0.00, //? + RebatePoint = double.Parse(o.pub_share_fee), //? + TkOrderNumber = null, // 联盟订单编号 ? + RecommendPoint = 0.00, //? + Commission = double.Parse(o.pub_share_fee),//? + GrossProfit = o.pub_share_pre_fee, //? + }).ToPageList(PageIndex, PageSize, ref tNumber); + + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + /// + /// 加淘宝商店黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddGoodsBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddGoodsBlack(order.item_id + "", LianmengType.淘宝联盟, order.item_title, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 加淘宝店铺黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddStoreBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddStoreBlack(LianmengType.淘宝联盟, order.shop_id + "", order.seller_shop_title, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + } +} diff --git a/Server/Controllers/OrderManagement/WphOrderController .cs b/Server/Controllers/OrderManagement/WphOrderController .cs new file mode 100644 index 0000000..3fcd371 --- /dev/null +++ b/Server/Controllers/OrderManagement/WphOrderController .cs @@ -0,0 +1,176 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Server.MyClass.Views; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using Server.Services; + +namespace Server.Controllers.OrderManagement +{ + public class WphOrderController : DefaultController + { + /// + /// 获取机器人信息 + /// + /// + [HttpPost, ErrorFilter] + public WebResult GetRobotInfo() + { + var PageIndex = GetInt("PageIndex"); + var PageSize = GetInt("PageSize"); + var tNumber = 0; + + var Keyword = GetString("Keyword"); + + var exp = Expressionable.Create(); + + if (!string.IsNullOrEmpty(Keyword)) + { + exp.And(f => f.Nickname.Contains(Keyword)); + } + var DataList = Db.Queryable().Where(exp.ToExpression()) + .Select(m => new RobotInfo { RobotId = m.Id, RobotName = m.Nickname }) + .ToPageList(PageIndex, PageSize, ref tNumber); + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + return PutData(res); + } + + [HttpPost, ErrorFilter] + public WebResult GetWphOrders() + { + var PageIndex = GetInt("PageIndex", true); + var PageSize = GetInt("PageSize", true); + var tNumber = 0; + + var MinTime = GetTime("MinTime"); + var MaxTime = GetTime("MaxTime"); + + var exp = Expressionable.Create(); + + if (MinTime == DateTime.MinValue) MinTime = DateTime.Now.AddMonths(-3); + if (MaxTime == DateTime.MinValue) MaxTime = DateTime.Now; + + exp.And((o, u, r) => o.orderTime > MinTime && o.orderTime < MaxTime); + + var RobotId = GetInt("RobotId"); + if (RobotId > 0) + exp.And((o, u, r) => r.Id == RobotId); + + var OrderStatus = GetEnum("OrderStatus"); + + if (OrderStatus != SystemOrderStatus.未知) + exp.And((o, u, r) => o.SystemOrderStatus == OrderStatus); + + var Keyword = GetString("Keyword"); + if (!string.IsNullOrEmpty(Keyword)) + { + var KeywordType = GetInt("KeywordType", true); + + switch (KeywordType) + { + case 1://用户账号查询 + exp.And((o, u, r) => u.Username.Contains(Keyword)); + break; + case 2://用户昵称查询 + exp.And((o, u, r) => u.NickName.Contains(Keyword)); + break; + case 3://订单编号查询 + exp.And((o, u, r) => o.orderSn.ToString().Contains(Keyword)); + break; + case 4://商品编号查询 + exp.And((o, u, r) => o.goodsId.ToString().Contains(Keyword)); + break; + case 5://商品名称 + exp.And((o, u, r) => o.goodsName.Contains(Keyword)); + break; + default: + break; + } + } + + var DataList = Db.Queryable() + .SplitTable(it => it.Take(6)) + .LeftJoin((o, u) => o.UserId == u.Id) + .LeftJoin((o, u, r) => u.RobotId == r.Id) + .Where(exp.ToExpression()) + .Select((o, u, r) => new WphOrderShow + { + ItemCount = o.goodsCount, + Itemid = o.goodsId.ToString(), + ItemTitle = o.goodsName, + OrderStatus = o.SystemOrderStatus, + PayPrice = o.goodsFinalPrice, + UserHeadurl = u.Headurl, + UserId = o.UserId, + UsOrderNumber = o.orderSn.ToString(), + UserNickname = u.NickName, + RobotName = r.Nickname, + PartnerPoint = 0.00, //? + RebatePoint = o.commission, //? + TkOrderNumber = null, // 联盟订单编号 ? + RecommendPoint = 0.00, //? + Commission = o.commission,//? + GrossProfit = o.commissionRate, //? + }).ToPageList(PageIndex, PageSize, ref tNumber); + + + var res = new PageResult(DataList, tNumber, PageSize, PageIndex); + + return PutData(res); + } + + /// + /// 加唯品会商店黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddGoodsBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddGoodsBlack(order.goodsId + "", LianmengType.唯品会联盟, order.goodsName, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + /// + /// 加唯品会店铺黑名单 + /// + /// + [HttpPost, ErrorFilter] + public WebResult AddStoreBlack() + { + var id = GetLong("Id"); + var isCloud = GetBoolean("IsCloud"); + var remark = GetString("Remark"); + var order = Db.Queryable().SplitTable(it => it.Take(6)).Where(w => w.Id == id).First(); + if (order == null) + { + return PutData("订单不存在"); + } + var ser = new BlacklistService(); + var result = ser.AddStoreBlack(LianmengType.唯品会联盟, order.mallId + "", order.brandStoreName, remark, isCloud); + if (string.IsNullOrWhiteSpace(result)) + { + return PutSuccess; + } + return PutData(result); + } + } +} diff --git a/Server/Dlls/HttpHelper.dll b/Server/Dlls/HttpHelper.dll new file mode 100644 index 0000000..3b35788 Binary files /dev/null and b/Server/Dlls/HttpHelper.dll differ diff --git a/Server/EventManager.cs b/Server/EventManager.cs new file mode 100644 index 0000000..4c715a3 --- /dev/null +++ b/Server/EventManager.cs @@ -0,0 +1,45 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Server.Events; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server +{ + internal class EventManager + { + private Client client; + internal EventManager(Client client) { this.client = client; } + + /// + /// 关闭程序 + /// + public event EventHandler ExitWinform; + + /// + /// 订单发生改变 + /// + public event EventHandler OrderChange; + + public void OnExitWinform(object sender) + { + ExitWinform?.Invoke(sender, null); + } + + + /// + /// 订单改变 + /// + /// 调用的类 + /// 订单相关信息 + public void OnOrderChange(object sender, OrderChangeEventArgs e) + { + OrderChange?.BeginInvoke(sender, e, null, null); + } + + + } +} diff --git a/Server/Events/OrderChangeEventArgs.cs b/Server/Events/OrderChangeEventArgs.cs new file mode 100644 index 0000000..528f96b --- /dev/null +++ b/Server/Events/OrderChangeEventArgs.cs @@ -0,0 +1,40 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Events +{ + /// + /// 订单状态发生改变 + /// + public class OrderChangeEventArgs : EventArgs + { + /// + /// 联盟类型 + /// + public LianmengType LianmengType { get; set; } + + /// + /// 订单编号(注意,是数据库内的ID) + /// + public long OrderId { get; set; } + + /// + /// 用户编号 + /// + public int UserId { get; set; } + + /// + /// 老状态 + /// + public SystemOrderStatus OldStatus { get; set; } + + /// + /// 最新状态 + /// + public SystemOrderStatus NewStatus { get; set; } + } +} diff --git a/Server/HttpRequests/TaobaoRequest.cs b/Server/HttpRequests/TaobaoRequest.cs new file mode 100644 index 0000000..05feb12 --- /dev/null +++ b/Server/HttpRequests/TaobaoRequest.cs @@ -0,0 +1,867 @@ +using CsharpHttpHelper; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; + +namespace Server.HttpRequests +{ + public class TaobaoRequest + { + public delegate bool OrderChange(TaobaoRequest Req, JToken Order); + public static event OrderChange OrderChangeEvent; + + #region 阿里妈妈请求类 + public TaobaoRequest() { } + + + + public Lianmeng Lianmeng { get; private set; } + + public string Token { get { return Lianmeng.Token; } } + + public TaobaoRequest(Lianmeng Lianmeng) + { + if (Lianmeng.LianmengType != LianmengType.淘宝联盟) throw new Exception($"当前账号{Lianmeng.LianmengType},不支持!"); + this.Lianmeng = Lianmeng; + } + + TbMedia Meadia; + public TaobaoRequest(Lianmeng Lianmeng, TbMedia Media) + { + if (Lianmeng.LianmengType != LianmengType.淘宝联盟) throw new Exception($"当前账号{Lianmeng.LianmengType},不支持!"); + this.Lianmeng = Lianmeng; + this.Meadia = Media; + + } + + private string Appid { get; set; } = "27754179"; + private string Appsecret { get; set; } = "2ee7beffe4752708564bf110971c262f"; + + + + + private const string SIGN_METHOD_MD5 = "md5"; + private const string SIGN_METHOD_HMAC = "hmac"; + private string SignTopRequest(Dictionary parameters, string secret, string signMethod = "hmac") + { + // 第一步:把字典按Key的字母顺序排序 + IDictionary sortedParams = new SortedDictionary(parameters, StringComparer.Ordinal); + + // 第二步:把所有参数名和参数值串在一起 + StringBuilder query = new StringBuilder(); + if (SIGN_METHOD_MD5.Equals(signMethod)) + { + query.Append(secret); + } + foreach (KeyValuePair kv in sortedParams) + { + if (!string.IsNullOrEmpty(kv.Key) && !string.IsNullOrEmpty(kv.Value) && kv.Key != "sign") + { + query.Append(kv.Key).Append(kv.Value); + } + } + + //// 第三步:把请求主体拼接在参数后面 + //if (!string.IsNullOrEmpty(body)) + //{ + // query.Append(body); + //} + + // 第四步:使用MD5/HMAC加密 + byte[] bytes; + if (SIGN_METHOD_HMAC.Equals(signMethod)) + { + HMACMD5 hmac = new HMACMD5(Encoding.UTF8.GetBytes(secret)); + bytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(query.ToString())); + } + else + { + query.Append(secret); + MD5 md5 = MD5.Create(); + bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(query.ToString())); + } + + // 第五步:把二进制转化为大写的十六进制 + StringBuilder result = new StringBuilder(); + for (int i = 0; i < bytes.Length; i++) + { + result.Append(bytes[i].ToString("X2")); + } + + return result.ToString(); + } + + /// + /// 计算签名,返回请求阿里妈妈服务器的参数 + /// + /// api名称 + /// 参数 + /// appkey + /// appsecret + /// + private string GetAlimamaRequestData(string _api, object _data, string appkey = "", string appsecret = "", string token = "") + { + try + { + var data = _data; + var api = _api; + Dictionary param = new Dictionary(); + var type = data.GetType().GetProperties(); + + foreach (var item in type) + { + var _value = item.GetValue(data).ToString(); + param[item.Name] = _value; + } + + param["method"] = api; + param["app_key"] = appkey; + param["session"] = token; + param["timestamp"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + param["format"] = "json"; + param["v"] = "2.0"; + param["sign_method"] = "md5"; + + //计算签名 + string sign = SignTopRequest(param, appsecret, param["sign_method"]); + param["sign"] = sign; + return HttpExtend.BuildQuery(param); + } + catch (Exception) + { + + } + return string.Empty; + } + + /// + /// 请求淘宝服务器端 + /// + /// api名称 + /// 参数 + /// 异常是否抛出 + /// + public JToken GetJSON(string ApiName, object Data, bool ThrowException = false) + { + var query = GetAlimamaRequestData(ApiName, Data, Appid, Appsecret, Token); + var html = string.Empty; + string _url = string.Empty; + try + { + HttpHelper http = new HttpHelper(); + + _url = "http://gw.api.taobao.com/router/rest?" + query; + HttpItem item = new HttpItem() + { + URL = _url,//URL 必需项 + Method = "GET",//URL 可选项 默认为Get + Timeout = 5000,//连接超时时间 可选项默认为100000 + ReadWriteTimeout = 5000,//写入Post数据超时时间 + Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值 + ContentType = "application/json",//返回类型 可选项有默认值 + }; + var result = http.GetHtml(item); + //{"tbk_dg_vegas_tlj_create_response":{"result":{"model":{"rights_id":"XvLXNwkX8HBQ8VZ2WS4DlNtN7m9cS4TU","send_url":"https:\/\/uland.taobao.com\/taolijin\/edetail?eh=5L6pfx5vldOZuQF0XRz0iAXoB%2BDaBK5LQS0Flu%2FfbSp4QsdWMikAalrisGmre1Id0BFAqRODu1004PvI5lqUzYTPq7zN5TtBXU4J7X2wljh7PW2ShemY2x1IRRpXndAncj8tXpgtxXzbOKxKSviYxsuv0da8KKt7WubOUkoI2Oa3HR2hP0JFSmjppH3xlrrJg8pBHJnzzOjd2vZvO6fEydXbwx4naJ6dk%2FBu2lJxZtMc7BMk%2FDH7wY2fDQKPuN9qcxwaWpDoQwfi%2B9ZUBfurmaewy3GJqMoK4342DlvX1ZVNOJlvqrE2h6J7%2BkHL3AEW&union_lens=lensId%3A0b14fbf4_0b3d_16f65a622fd_31b4%3Btraffic_flag%3Dlm","vegas_code":"N4HHV6HV"},"success":true},"request_id":"no8k8bbwsct2"}} + + if (result != null && result.StatusCode != System.Net.HttpStatusCode.OK) throw new Exception(result.Html); + html = result.Html; + + var JsonResult = JObject.Parse(html); + if (JsonResult == null) throw new Exception(html); + if (JsonResult["error_response"] != null) + throw new Exception(html); + //tbk_sc_order_details_get_response + //tbk_sc_order_details_get_response + var key = ApiName.Replace("taobao.", "").Replace(".", "_") + "_response"; + if (JsonResult[key] == null) throw new Exception($"key = {key},html = {html}"); + var ResultToken = JsonResult[key]; + if (ResultToken["result"] != null) return ResultToken["result"]; + if (ResultToken["results"] != null) return ResultToken["results"]; + if (ResultToken["data"] != null) return ResultToken["data"]; + return ResultToken; + } + catch (Exception ex) + { + if (ex.Message.Contains("过期")) + { + Lianmeng.ExpirationTime = DateTime.Now; + //Client.SigleClient.Db.Updateable(Lianmeng).UpdateColumns(f => new { f.ExpirationTime }).ExecuteCommand(); + } + + //Client.SigleClient.Event.OnLog($"请求API:{ApiName}发生错误,{ex.Message}", "系统", ex, true); + if (ThrowException) throw ex; + } + return null; + } + #endregion + + + /// + /// 更新订单 + /// + /// 开始时间 + /// 结束时间 + /// 同步的订单类型 + /// 返回错误原因 + public Task UpdateOrder(DateTime StartTime, DateTime EndTime, TBOrderScene orderScene = TBOrderScene.常规订单) + { + return Task.Factory.StartNew(() => + { + try + { + if (StartTime < DateTime.Now.AddMonths(-5)) StartTime = DateTime.Now.AddMonths(-5); + var time = StartTime; + + do + { + /* + 逻辑:从结束的时间,倒序更新 + */ + var sTime = time; + var eTime = time.AddHours(3); + //if (eTime > EndTime) eTime = StartTime; + + time = eTime; + + //是否还有下一页 + var page_on = 0; + var has_next = false; + var position_index = string.Empty; + do + { + page_on++; + var postData = new + { + query_type = 4,//查询时间类型,1:按照订单淘客创建时间查询,2:按照订单淘客付款时间查询,3:按照订单淘客结算时间查询,4:按照订单更新时间; + page_size = 100,//页大小 + start_time = sTime.ToString("yyyy-MM-dd HH:mm:ss"), + end_time = eTime.ToString("yyyy-MM-dd HH:mm:ss"),//这里是对应前面同步间隔的19分钟 //【订单查询结束时间,订单开始时间至订单结束时间,中间时间段日常要求不超过3个小时,但如618、双11、年货节等大促期间预估时间段不可超过20分钟,超过会提示错误,调用时请务必注意时间段的选择,以保证亲能正常调用!】 + page_no = page_on, + position_index = position_index, + order_scene = (int)orderScene, + }; + var Json = GetJSON("taobao.tbk.sc.order.details.get", postData); + if (Json != null && Json["data"] != null) + { + var Data = Json["data"]; + has_next = (bool)Data["has_next"]; + position_index = Data["position_index"].ToString(); + var orders = Data["results"]["publisher_order_dto"]; + if (orders == null) break; + + foreach (var item in orders) + { + item["LianmengId"] = Lianmeng.Id; + OrderChangeEvent?.Invoke(this, item); + } + + if (!has_next) + { + Lianmeng.ModifiedTime = sTime; + //Client.SigleClient.Db.SaveCache(Lianmeng); + //Client.SigleClient.Db.Updateable(Lianmeng).UpdateColumns(f => new { f.ModifiedTime }).ExecuteCommand(); + } + } + else + break; + + } while (has_next); + + + + } while (time < EndTime); + + + + } + catch (Exception ex) + { + //Client.SigleClient.Event.OnLog(ex.Message, "淘宝", ex); + return ex.Message; + } + return string.Empty; + }); + } + + /// + /// 淘口令解析并转链 返回商品ID 【淘宝客-服务商-淘口令解析&转链】 + /// + /// + public JToken TpwdConvert(string Content, string SiteId, string AdzoneId) + { + return GetJSON("taobao.tbk.sc.tpwd.convert", new { password_content = Content, adzone_id = AdzoneId, site_id = SiteId }); + } + /// + /// 正则获取Url链接 + /// + public const string RegexGetUrl = @"(?<链接>(?:(?:ht|f)tps?):\/\/[\w\-]+(?:\.[\w\-]+)+(?:[\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?)"; + public JToken TbUrlAnalysis(string Content) + { + try + { + var regs = Regex.Matches(Content, RegexGetUrl); + if (regs.Count == 0) return null; + foreach (Match reg in regs) + { + try + { + var url = reg.Groups["链接"].Value; + var jToken = GetJSON("taobao.tbk.item.click.extract", new { click_url = url }); + if (jToken != null) + { + + } + } + catch (Exception ex) + { + } + } + } + catch (Exception ex) + { + //Client.SigleClient.Event.OnLog($"解析内容中的url异常", Exception: ex, IsDebug: true); + } + return null; + } + + /// + /// 解析宝贝地址 + /// + /// + public string AnalysisItemid(string Content) + { + var itemid = AnalysisItemidByUrl(Content); + if (!string.IsNullOrWhiteSpace(itemid)) + return itemid; + + if (Meadia == null) throw new Exception("推广位信息不能为空!"); + var convertRst = TpwdConvert(Content, Meadia.SiteId, Meadia.AdzoneId); + if (convertRst != null) + { + return convertRst["num_iid"].ToString(); + } + + return String.Empty; + } + + /// + /// 判断是否为淘宝的相关域名,后续有新的在这个位置添加 + /// + private static string RegDomainMatch = @"((?:m.tb.cn))"; + + private string AnalysisItemidByUrl(string Content) + { + try + { + //判断是否为淘宝的相关域名 + if (!Regex.IsMatch(Content, RegDomainMatch, RegexOptions.IgnoreCase)) + return string.Empty; + + var regs = Regex.Matches(Content, RegexGetUrl); + if (regs.Count == 0) + return String.Empty; + + foreach (Match regTmp in regs) + { + try + { + var url = regTmp.Groups["链接"].Value; + var result = new HttpHelper().GetHtml(url); + if (result != null && result.StatusCode != System.Net.HttpStatusCode.OK) throw new Exception(result.Html); + var html = result.Html; + + var itemid = string.Empty; + var reg = Regex.Match(html, @"var url = '(?.+?)';", RegexOptions.IgnoreCase); + if (reg.Success) + { + itemid = GetItemIdByContent(html); + if (!string.IsNullOrWhiteSpace(itemid)) + return itemid; + itemid = GetItemIdByCoupon(reg.Groups["url"].Value); + if (!string.IsNullOrWhiteSpace(itemid)) + return itemid; + } + } + catch (Exception ex) + { + } + } + } + catch (Exception ex) + { + throw ex; + } + return String.Empty; + } + + /// + /// 查找宝贝Id的正则表达式 + /// 注:追加为最后一个括号前加|(?:新的正则) + /// + private static string RegItemId = @"((?:item[Ii]d=(?\d{5,}))|(?:item_id=(?\d{5,}))|(?:\?id=(?\d{5,}))|(?:&id=(?\d{5,}))|(?:/i(?\d{5,}))|(?:num[Ii]id=(?\d{5,})))"; + + /// + /// 正则表达式匹配商品Id + /// + /// 查找的内容 + /// 查找到的宝贝id + public string GetItemIdByContent(string Content) + { + var reg = Regex.Match(Content, RegItemId); + if (reg.Success) + return reg.Groups["itemid"].Value; + return string.Empty; + } + + /// + /// 通过优惠券链接获取淘宝宝贝的id + /// + /// + public string GetItemIdByCoupon(string url) + { + try + { + var urlTmp = url.ToLower(); + if (urlTmp.Contains(@"uland.taobao.com/coupon"))//这是针对淘宝联盟有优惠券的接口.//https://uland.taobao.com/coupon/edetail + { + var coupon = CheckCoupon(url);//将返利接口转成淘宝宝贝接口 + if (coupon != null) return coupon.itemId; + } + else if (url.Contains(@"s.click.taobao.com"))//这是针对淘宝联盟没有的接口.//https://s.click.taobao.com/t?e=m + { + var html = string.Empty; + + string locUrl = HttpExtend.GetLocationUrl(url); + + if (!string.IsNullOrWhiteSpace(locUrl) && locUrl.StartsWith("https://s.click.taobao.com/t?e=", StringComparison.OrdinalIgnoreCase)) + { + var locUrlTmp = HttpExtend.GetLocationUrl(locUrl); + if (!string.IsNullOrEmpty(locUrlTmp)) locUrl = locUrlTmp; + } + if (!string.IsNullOrEmpty(locUrl))//跳转地址存在 + { + if (locUrl.ToLower().Contains("uland.taobao.com/coupon/edetail?")) + { + + var reg = Regex.Match(locUrl, @"(?:&|\?)itemId=(\d+)", RegexOptions.IgnoreCase); + if (reg.Success) + return reg.Groups[1].Value; + + html = HttpHelper.URLDecode(new HttpHelper().GetHtml(locUrl).Html); + var reqUrl = Regex.Match(html, "&req_url=([^\"]+)", RegexOptions.IgnoreCase); + if (reqUrl.Success) + { + var param_e = Regex.Match(reqUrl.Groups[1].Value, "e=([^&]+)"); + if (!param_e.Success) + return string.Empty; + var coupon = CheckCoupon(reqUrl.Groups[1].Value); + if (coupon != null) + return coupon.itemId; + } + } + else if (locUrl.Contains("uland.taobao.com")) + { + var _reg = Regex.Match(locUrl, "itemId=(\\d+)", RegexOptions.IgnoreCase); + if (_reg.Success) + return _reg.Groups[1].Value; + } + else if (locUrl.Contains("tu=")) + { + //获得二次访问地址 + string next = HttpHelper.URLDecode(locUrl.Replace("http://s.click.taobao.com/t_js?tu=", "").Replace("https://s.click.taobao.com/t_js?tu=", "")); + html = HttpHelper.URLDecode(new HttpHelper().GetHtml(next, referer: locUrl).Html); + var reg = Regex.Match(html, @"(?:&|\?)itemId=(\d+)", RegexOptions.IgnoreCase); + if (reg.Success) + return reg.Groups[1].Value; + } + else + return GetItemIdByContent(new HttpHelper().GetHtml(locUrl).Html); + } + + #region + if (string.IsNullOrWhiteSpace(locUrl)) + { + html = new HttpHelper().GetHtml(url).Html; + var reg = Regex.Match(html, "real_jump_address = '(?<真正的跳转地址>[^']+)"); + if (reg.Success) + { + var address = reg.Groups["真正的跳转地址"].Value; + for (int i = 0; i < 3; i++) + { + html = new HttpHelper().GetHtml(address.Replace("&", "&"), referer: url).Html; + var itemid = GetItemIdByContent(html); + if (!string.IsNullOrWhiteSpace(itemid)) + return itemid; + else + { + //访问频繁,休息重试3次 + Thread.Sleep(500); + } + } + } + } + #endregion + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + return string.Empty; + } + + + private static DateTime NextTime = DateTime.MinValue; + + + /// + /// 淘宝优惠券 + /// + public class TaobaoCoupon + { + /// + /// 优惠券状态,!=0表示优惠券失效或没有优惠券 + /// + public int retStatus { get; set; } + + /// + /// 使用条件 + /// + public string startFee { get; set; } + + /// + /// 使用金额 + /// + public string amount { get; set; } + + /// + /// 店铺Logo + /// + public string shopLogo { get; set; } + + /// + /// 店铺名称 + /// + public string shopName { get; set; } + + /// + /// 使用时间 + /// + public DateTime effectiveStartTime { get; set; } + + /// + /// 活动截止时间 + /// + public DateTime effectiveEndTime { get; set; } + + /// + /// 点击下单 + /// + public string clickUrl { get; set; } + + /// + /// 分享地址 + /// + public string shareUrl { get; set; } + + /// + /// 软件标题 + /// + public string title { get; set; } + + /// + /// 原价 + /// + public string reservePrice { get; set; } + + /// + /// 折扣价格 + /// + public string discountPrice { get; set; } + + /// + /// 30天销量 + /// + public int biz30Day { get; set; } + + /// + /// 是否是天猫 ,1(是) + /// + public string tmall { get; set; } + + /// + /// 未知参数 + /// + public int postFree { get; set; } + + /// + /// 宝贝ID + /// + public string itemId { get; set; } + + /// + /// 未知参数 + /// + public string couponFlowLimit { get; set; } + } + + /// + /// 检测淘宝优惠券 + /// + /// 优惠券地址 + /// + public TaobaoCoupon CheckCoupon(string coupon_click_url) + { + string html = string.Empty; + try + { + if (coupon_click_url.Contains("coupon/details") || coupon_click_url.Contains("coupon/edetail")) + { + TaobaoCoupon c = new TaobaoCoupon(); + coupon_click_url = coupon_click_url.Replace("coupon/details", "cp/coupon/").Replace("coupon/edetail", "cp/coupon/"); + var http = new HttpHelper(); + + for (int i = 0; i < 4; i++) + { + if (NextTime > DateTime.Now) + return null; + + var item = http.GetItem(coupon_click_url); + item.Timeout = 30000; + item.ReadWriteTimeout = 20000; + item.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0"; + item.ContentType = "application/x-www-form-urlencoded"; + item.SetProxyipCDN(); + html = http.GetHtml(item).Html.Replace("\\", ""); + if (html.Contains("亲,小二正忙,滑动一下马上回来") || html.Contains("操作超时") || html == @"{""success"": false}") + { + if (i == 3) + { + NextTime = DateTime.Now.AddMinutes(2); + return null; + } + Thread.Sleep(500); + continue; + } + + var _obj = HttpExtend.JsonToDictionary(html);//转成字典 + if (_obj != null) + { + _obj = _obj["result"] as Dictionary; + _obj.ConvertToObj(c); + if (c.retStatus == 1) continue; + _obj = _obj["item"] as Dictionary; + if (_obj["clickUrl"] != null) _obj["clickUrl"] = "http:" + _obj["clickUrl"].ToString(); + if (_obj["shareUrl"] != null) _obj["shareUrl"] = "http:" + _obj["shareUrl"].ToString(); + _obj.ConvertToObj(c); + + if (c.retStatus == 2 || c.retStatus == 0 || c.retStatus == 4) return c; + } + } + } + } + catch (Exception ex) + { + // Client.SigleClient.Event.OnLog($@"检查淘宝优惠券异常", Exception: ex); + } + return null; + } + + + + + + + + + + + + + + + + public class TaobaoIteminfo + { + /// + /// 优惠券剩余量 + /// + public int coupon_remain_count { get; set; } + //coupon_remain_count Number 6859 优惠券剩余量 + + //优惠券总量 + public int coupon_total_count { get; set; } + //coupon_total_count Number 8000 优惠券总量 + + /// + /// 优惠券面额 + /// + public string coupon_info { get; set; } + //coupon_info String 满16元减10元 优惠券面额 + + /// + /// 优惠券结束时间 + /// + public DateTime coupon_end_time { get; set; } + // coupon_end_time String 2016-09-26 优惠券结束时间 + + /// + /// 优惠券开始时间 + /// + public DateTime coupon_start_time { get; set; } + // coupon_start_time String 2016-09-25 优惠券开始时间 + + /// + /// 优惠券(商品优惠券推广链接中的券)类型,1 公开券,2 私有券,3 妈妈券 + /// + public int coupon_type { get; set; } + //coupon_type Number 1 优惠券(商品优惠券推广链接中的券)类型,1 公开券,2 私有券,3 妈妈券 + + /// + /// 商品优惠券推广链接 + /// + public string coupon_click_url { get; set; } + //coupon_click_url String https://uland.taobao.com/coupon/edetail?e=nqUNB1NOF3Bt3vqbdXnGloankzPYmeEFkgNrw6YHQf9pZTj41Orn8MwBAs06HAOzqQomYNedOiHDYPmqkFXqLR0HgBdG%2FDDL%2F1M%2FBw7Sf%2FesGXLf%2BqX4cbeC%2F2cR0p0NlWH0%2BknxpnCJJP%2FQkZSsyo1HvKjXo4uz&pid=mm_26381042_12970066_52864659&af=1 商品优惠券推广链接 + + /// + /// 后台一级类目 + /// + public int category_id { get; set; } + //category_id Number 1 后台一级类目 + + /// + /// 展示常规佣金率 + /// + public double max_commission_rate { get; set; } + //max_commission_rate String 20.3 当不入参special_id、relation_id、external_id时,展示常规佣金率(%) + + /// + /// 商品id + /// + public string item_id { get; set; } + //item_id Number 524136796550 商品id + + /// + /// 商品地址 + /// + public string item_url { get; set; } + //item_url String https://s.click.taobao.com/t?spm=a2e2e.10720394/c.90202110.1.4399704cUUhhH0&e=m%3D2%26s%3D0NJS731SUEdw4vFB6t2Z2ueEDrYVVa64LKpWJ%2Bin0XLjf2vlNIV67uIA4kDYDopEpOjgxi0uT208hw4H8GMUew7uoRPWrIBwR7CIpaNCoiKr9WTFywb%2BCtGNFs53xi4QGSKqJrqeJvt5ArodCWjzv9fsai3uVirbXH%2BQH9e66Y4%3D 商品淘客链接 + + /// + /// 预售有礼-推广链接 + /// + public string ysyl_click_url { get; set; } + //ysyl_click_url String https://uland.taobao.com/coupon/edetail?e=nqUNB1NOF3Bt3vqbdXnGloankzPYmeEFkgNrw6YHQf9pZTj41Orn8MwBAs06HAOzqQomYNedOiHDYPmqkFXqLR0HgBdG%2FDDL%2F1M%2FBw7Sf%2FesGXLf%2BqX4cbeC%2F2cR0p0NlWH0%2BknxpnCJJP%2FQkZSsyo1HvKjXo4uz&pid=mm_26381042_12970066_52864659&af=1 预售有礼-推广链接 + + /// + /// 预售有礼-预估淘礼金(元) + /// + public string ysyl_tlj_face { get; set; } + //ysyl_tlj_face String 0.6 预售有礼-预估淘礼金(元) + + /// + /// 预售有礼-淘礼金发放时间 + /// + public string ysyl_tlj_send_time { get; set; } + //ysyl_tlj_send_time String 2019-11-10 21:59:59 预售有礼-淘礼金发放时间 + + /// + /// 预售有礼-淘礼金使用开始时间 + /// + public string ysyl_tlj_use_start_time { get; set; } + //ysyl_tlj_use_start_time String 2019-11-10 21:59:59 预售有礼-淘礼金使用开始时间 + + /// + /// 预售有礼-佣金比例 + /// + public string ysyl_commission_rate { get; set; } + //ysyl_commission_rate String 20.3 预售有礼-佣金比例(%)( 预售有礼活动享受的推广佣金比例,注:推广该活动有特殊分成规则,请详见:https://tbk.bbs.taobao.com/detail.html?appId=45301&postId=9334376 ) + + public string ysyl_tlj_use_end_time { get; set; } + //ysyl_tlj_use_end_time String 2019-11-10 21:59:59 预售有礼-淘礼金使用结束时间 + + /// + /// 预估最低佣金率 + /// + public double min_commission_rate { get; set; } + //min_commission_rate String 20.3 当入参special_id、relation_id、external_id时,该字段展示预估最低佣金率(%) + + /// + /// 比价场景专用 + /// + public int reward_info { get; set; } + //reward_info Number 1 比价场景专用,当系统检测到入参消费者ID购买当前商品会获得《天天开彩蛋》玩法的彩蛋时,该字段显示1,否则为0 + } + + /// + /// 单品券高效转链 + /// + /// 需要转链的产品ID + /// 会员运营ID + /// + public TaobaoIteminfo ConvertItemid(string ItemId, long? SpecialId = null) + { + object transportData; + if (SpecialId != null) + { + transportData = new { adzone_id = this.Meadia.AdzoneId, site_id = this.Meadia.SiteId, item_id = ItemId, special_id = SpecialId }; + } + else + { + transportData = new { adzone_id = this.Meadia.AdzoneId, site_id = this.Meadia.SiteId, item_id = ItemId }; + } + + var data = GetJSON("taobao.tbk.privilege.get", transportData); + TaobaoIteminfo obj = new TaobaoIteminfo(); + Utils.Util.CopyToObj(data,obj); + return obj; + } + + /// + /// 获取会员绑定的specialId + /// + /// 通常情况下为wxid + /// + public long GetSpecialId(string ExternalId) + { + var data = GetJSON("taobao.tbk.sc.publisher.info.get", new { info_type = 2, relation_app = "common", external_id = ExternalId, external_type = 1 }); + if (data["inviter_list"]["map_data"].Count() > 0) + { + return (long)data["inviter_list"]["map_data"].First["special_id"]; + } + return 0; + } + + /// + /// 获取私域标记链接 + /// + /// + /// + /// + /// + /// + public string GetRelationLink(string WxId, string RedirectUrl, int ExternalType = 1, int? UcRowdId = null) + { + object transportData; + if (UcRowdId != null) + { + transportData = new { external_id = WxId, external_type = ExternalType, op_type = 2, redirect_url = RedirectUrl, ucrowd_id = UcRowdId }; + } + else + { + transportData = new { external_id = WxId, external_type = ExternalType, op_type = 2, redirect_url = RedirectUrl }; + } + var data = GetJSON("taobao.tbk.sc.relation.record", transportData); + return data["url"].ToString(); + } + + } +} diff --git a/Server/MyClass/Caches/DouyinUpdateCache.cs b/Server/MyClass/Caches/DouyinUpdateCache.cs new file mode 100644 index 0000000..901baba --- /dev/null +++ b/Server/MyClass/Caches/DouyinUpdateCache.cs @@ -0,0 +1,21 @@ +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Caches +{ + [ProtoContract] + public class DouyinUpdateCache + { + + + /// + /// 最后更新时间 + /// + [global::ProtoBuf.ProtoMember(1)] + public DateTime UpdateTime1 { get; set; } = DateTime.Now.AddDays(-30); + } +} diff --git a/Server/MyClass/Caches/JDUpdateOrderItemCache.cs b/Server/MyClass/Caches/JDUpdateOrderItemCache.cs new file mode 100644 index 0000000..1ea9a5d --- /dev/null +++ b/Server/MyClass/Caches/JDUpdateOrderItemCache.cs @@ -0,0 +1,25 @@ +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Caches +{ + + [ProtoContract] + public class JDUpdateOrderItemCache + { + /// + /// ID + /// + [global::ProtoBuf.ProtoMember(1)] + public string Id { get; set; } + /// + /// 上次时间 + /// + [global::ProtoBuf.ProtoMember(2)] + public DateTime LastDateTime { get; set; } + } +} diff --git a/Server/MyClass/Caches/MtUpdateOrderCache.cs b/Server/MyClass/Caches/MtUpdateOrderCache.cs new file mode 100644 index 0000000..c0a3163 --- /dev/null +++ b/Server/MyClass/Caches/MtUpdateOrderCache.cs @@ -0,0 +1,24 @@ +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Caches +{ + [ProtoContract] + public class MtUpdateOrderItemCache + { + /// + /// ID + /// + [global::ProtoBuf.ProtoMember(1)] + public string Id { get; set; } + /// + /// 上次时间 + /// + [global::ProtoBuf.ProtoMember(2)] + public DateTime LastDateTime { get; set; } + } +} diff --git a/Server/MyClass/Caches/PDDUpdateOrderItemCache.cs b/Server/MyClass/Caches/PDDUpdateOrderItemCache.cs new file mode 100644 index 0000000..46a4055 --- /dev/null +++ b/Server/MyClass/Caches/PDDUpdateOrderItemCache.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProtoBuf; + +namespace Server.MyClass.Caches +{ + /// + /// 拼多多 + /// + [ProtoContract] + public class PDDUpdateOrderItemCache + { + /// + /// ID + /// + [global::ProtoBuf.ProtoMember(1)] + public string Id { get; set; } + /// + /// 上次时间 + /// + [global::ProtoBuf.ProtoMember(2)] + public DateTime LastDateTime { get; set; } + } +} diff --git a/Server/MyClass/Caches/RuntimeCache.cs b/Server/MyClass/Caches/RuntimeCache.cs new file mode 100644 index 0000000..69363d7 --- /dev/null +++ b/Server/MyClass/Caches/RuntimeCache.cs @@ -0,0 +1,107 @@ +using ProtoBuf; +using Server.Configs; +using Server.MyClass.Class; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Caches +{ + [ProtoContract] + public class RuntimeCache + { + [global::ProtoBuf.ProtoMember(1)] + public List TbDatas { get; set; } + /// + /// 抖音同步相关信息 + /// + [global::ProtoBuf.ProtoMember(2)] + public List DyDatas { get; set; } + + + [global::ProtoBuf.ProtoMember(3)] + public List MtDatas { get; set; } + /// + /// 京东 + /// + [global::ProtoBuf.ProtoMember(4)] + public List JDDatas { get; set; } + /// + /// 拼多多 + /// + [global::ProtoBuf.ProtoMember(5)] + public List PDDDatas { get; set; } + + /// + /// 唯品会 + /// + [global::ProtoBuf.ProtoMember(6)] + public List WeiPinHuiDatas { get; set; } + /// + /// 苏宁 + /// + [global::ProtoBuf.ProtoMember(7)] + public List SuningDatas { get; set; } + /// + /// 公共数据缓存配置 + /// + [global::ProtoBuf.ProtoMember(8)] + public Dictionary PublicCacheDic { get; set; } + + [global::ProtoBuf.ProtoMember(9)] + public ConcurrentDictionary DeviceSessions { get; set; } + public ConcurrentDictionary UserSessions { get; set; } + + /// + /// 用来缓存存储公共配置 + /// + /// + /// + /// + public bool SetPublicValue(string key, T value) + { + PublicCacheDic[key] = Newtonsoft.Json.JsonConvert.SerializeObject(value); + return true; + } + /// + /// 获取 用来缓存存储公共配置 + /// + /// + /// + /// + public T GetPublicValue(string key, Func def = null) + { + if (PublicCacheDic.ContainsKey(key)) + { + var val = PublicCacheDic[key]; + var obj = Newtonsoft.Json.JsonConvert.DeserializeObject(val); + return (T)Convert.ChangeType(obj, typeof(T)); + } + if (def == null) + { + return default; + } + return def(); + } + + + public RuntimeCache() + { + PublicCacheDic = new Dictionary(); + TbDatas = new List(); + DyDatas = new List(); + MtDatas = new List(); + JDDatas = new List(); + PDDDatas = new List(); + WeiPinHuiDatas = new List(); + SuningDatas = new List(); + DeviceSessions = new ConcurrentDictionary(); + UserSessions = new ConcurrentDictionary(); + } + + + } +} diff --git a/Server/MyClass/Caches/SuningUpdateOrderItemCache.cs b/Server/MyClass/Caches/SuningUpdateOrderItemCache.cs new file mode 100644 index 0000000..fb85b5d --- /dev/null +++ b/Server/MyClass/Caches/SuningUpdateOrderItemCache.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProtoBuf; + +namespace Server.MyClass.Caches +{ + + /// + /// 苏宁 + /// + [ProtoContract] + public class SuningUpdateOrderItemCache + { + /// + /// ID + /// + [global::ProtoBuf.ProtoMember(1)] + public string Id { get; set; } + /// + /// 上次时间 + /// + [global::ProtoBuf.ProtoMember(2)] + public DateTime LastDateTime { get; set; } + } +} diff --git a/Server/MyClass/Caches/TaobaoUpdateCache.cs b/Server/MyClass/Caches/TaobaoUpdateCache.cs new file mode 100644 index 0000000..b45e546 --- /dev/null +++ b/Server/MyClass/Caches/TaobaoUpdateCache.cs @@ -0,0 +1,65 @@ +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Configs +{ + [ProtoContract] + public class TaobaoUpdateCacheInfo + { + public TaobaoUpdateCacheInfo() + { + this.UpdateTime1 = DateTime.Now.AddMonths(-3); + this.UpdateTime3 = DateTime.Now.AddMonths(-3); + } + + /// + /// 常规订单更新时间 + /// + [global::ProtoBuf.ProtoMember(1)] + public DateTime UpdateTime1 { get; set; } + + /// + /// 渠道订单更新时间 + /// + [global::ProtoBuf.ProtoMember(2)] + public DateTime UpdateTime2 { get; set; } + + /// + /// 会员运营ID更新时间 + /// + [global::ProtoBuf.ProtoMember(3)] + public DateTime UpdateTime3 { get; set; } + + /// + /// 渠道退款时间更新时间 + /// + [global::ProtoBuf.ProtoMember(4)] + public DateTime UpdateTime4 { get; set; } + + /// + /// 会员运营更新时间 + /// + [global::ProtoBuf.ProtoMember(5)] + public DateTime UpdateTime5 { get; set; } + + /// + /// 更新处罚订单时间 + /// + [global::ProtoBuf.ProtoMember(6)] + public DateTime UpdateTime6 { get; set;} + + /// + /// 最后一次更新时间 + /// + [global::ProtoBuf.ProtoMember(7)] + public DateTime UpdateTimer7 { get; set; } + + + [global::ProtoBuf.ProtoMember(8)] + public int LianmengId { get; set; } + } +} diff --git a/Server/MyClass/Caches/WeiPinHuiUpdateOrderItemCache.cs b/Server/MyClass/Caches/WeiPinHuiUpdateOrderItemCache.cs new file mode 100644 index 0000000..c882447 --- /dev/null +++ b/Server/MyClass/Caches/WeiPinHuiUpdateOrderItemCache.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProtoBuf; + +namespace Server.MyClass.Caches +{ + /// + /// 唯品会 + /// + [ProtoContract] + public class WeiPinHuiUpdateOrderItemCache + { + /// + /// ID + /// + [global::ProtoBuf.ProtoMember(1)] + public string Id { get; set; } + /// + /// 上次时间 + /// + [global::ProtoBuf.ProtoMember(2)] + public DateTime LastDateTime { get; set; } + } +} diff --git a/Server/MyClass/Class/DeviceSession.cs b/Server/MyClass/Class/DeviceSession.cs new file mode 100644 index 0000000..05fac16 --- /dev/null +++ b/Server/MyClass/Class/DeviceSession.cs @@ -0,0 +1,41 @@ +using Common.Models.PubClass; +using Common.Models.UnqTables; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; + +namespace Server.MyClass.Class +{ + [ProtoBuf.ProtoContract] + public class DeviceSession + { + /// + /// 是否正在读取消息 + /// + [ProtoBuf.ProtoMember(1)] + public bool IsReading { get; set; } + + /// + /// 读取消息时间 + /// + [ProtoBuf.ProtoMember(2)] + public DateTime ReadTime { get; set; } + + /// + /// 登录的机器人 + /// + [ProtoBuf.ProtoMember(3)] + public int RobotId { get; set; } + + public DeviceSession() + { + Messages = new Queue(); + } + + /// + /// 发送的消息列表 + /// + public Queue Messages { get; set; } + + } +} diff --git a/Server/MyClass/Class/InitDbData.cs b/Server/MyClass/Class/InitDbData.cs new file mode 100644 index 0000000..56b1c9d --- /dev/null +++ b/Server/MyClass/Class/InitDbData.cs @@ -0,0 +1,22 @@ +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Class +{ + /// + /// 记录初始化表数据 + /// + [ProtoContract] + public class InitDbData + { + /// + /// 上次计算的MD5 + /// + [global::ProtoBuf.ProtoMember(1)] + public string LastMd5 { get; set; } + } +} diff --git a/Server/MyClass/Class/PackInfo.cs b/Server/MyClass/Class/PackInfo.cs new file mode 100644 index 0000000..53312f1 --- /dev/null +++ b/Server/MyClass/Class/PackInfo.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Class +{ + /// + /// 压缩包信息 + /// + public class PackInfo + { + /// + /// 类型 + /// + public string TypeName { get; set; } + /// + /// 时间 + /// + public DateTime AddDateTime { get; set; } + } +} diff --git a/Server/MyClass/Class/UserSession.cs b/Server/MyClass/Class/UserSession.cs new file mode 100644 index 0000000..b93852b --- /dev/null +++ b/Server/MyClass/Class/UserSession.cs @@ -0,0 +1,51 @@ +using Common.Models.UnqTables; +using ProtoBuf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Class +{ + [ProtoContract] + public class UserSession + { + public UserSession(Staff User) + { + this.Uid = User.Id; + this.Token = Guid.NewGuid().ToString(); + this.LoginTime = DateTime.Now; + this.RoleId = User.RoleId; + this.UserName = User.Username; + } + + public UserSession() + { + + } + + public int RoleId { get; set; } + + /// + /// 是否是超级管理员 + /// + public bool IsCreator { get; set; } + + public int Uid { get; set; } + + public string UserName { get; set; } + + /// + /// 登录时间 + /// + public DateTime LoginTime { get; set; } + /// + /// 请求时间 + /// + public DateTime RequestTime { get; set; } + + public string Token { get; set; } + + } +} diff --git a/Server/MyClass/Views/BaseConfigShow.cs b/Server/MyClass/Views/BaseConfigShow.cs new file mode 100644 index 0000000..2bd783b --- /dev/null +++ b/Server/MyClass/Views/BaseConfigShow.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class BaseConfigShow + { + public int BaseConfigId { get; set; } + + public string BaseConfigName { get; set; } + } +} diff --git a/Server/MyClass/Views/CashListShow.cs b/Server/MyClass/Views/CashListShow.cs new file mode 100644 index 0000000..6901533 --- /dev/null +++ b/Server/MyClass/Views/CashListShow.cs @@ -0,0 +1,18 @@ +using Common.Models.SubTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class CashListShow:TixianHist + { + public string NickName { get; set; } = string.Empty; + + public string RobotName { get; set; } = string.Empty; + + + } +} diff --git a/Server/MyClass/Views/CommonMediaShow.cs b/Server/MyClass/Views/CommonMediaShow.cs new file mode 100644 index 0000000..8ac59c5 --- /dev/null +++ b/Server/MyClass/Views/CommonMediaShow.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + internal class CommonMediaShow + { + + } +} diff --git a/Server/MyClass/Views/DyMediaShow.cs b/Server/MyClass/Views/DyMediaShow.cs new file mode 100644 index 0000000..f4ca26b --- /dev/null +++ b/Server/MyClass/Views/DyMediaShow.cs @@ -0,0 +1,23 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class DyMediaShow + { + public int Id { get; set; } + public int LianmengId { get; set; } + public string LianmengNick { get; set; } + + public string Remark { get; set; } + public string MediaName { get; set; } + public DouyinMediaType MediaType { get; set; } + public string AdzoneName { get; set; } + public string Pid { get; set; } + public int UseCnt { get; set; } + } +} diff --git a/Server/MyClass/Views/DyOrderShow.cs b/Server/MyClass/Views/DyOrderShow.cs new file mode 100644 index 0000000..3f59dd9 --- /dev/null +++ b/Server/MyClass/Views/DyOrderShow.cs @@ -0,0 +1,88 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class DyOrderShow + { + /// + /// 商品编号 + /// + public string Itemid { get; set; } + + /// + /// 商品标题 + /// + public string ItemTitle { get; set; } + + /// + /// 用户ID + /// + public int UserId { get; set; } + + /// + /// 用户头像地址 + /// + public string UserHeadurl { get; set; } + + /// + /// 用户昵称 + /// + public string UserNickname { get; set; } + public string RobotName { get; set; } + + /// + /// 订单状态 + /// + public SystemOrderStatus OrderStatus { get; set; } + + /// + /// 联盟订单编号 + /// + public string TkOrderNumber { get; set; } + + /// + /// 京东订单编号 + /// + public string UsOrderNumber { get; set; } + + /// + /// 商品预估佣金 + /// + public double Commission { get; set; } + + /// + /// 购买数量 + /// + public int ItemCount { get; set; } + + /// + /// 返利金额 + /// + public double RebatePoint { get; set; } + + /// + /// 推荐人提成 + /// + public double RecommendPoint { get; set; } + + /// + /// 合伙人分红 + /// + public double PartnerPoint { get; set; } + + /// + /// 毛利率 + /// + public double GrossProfit { get; set; } + + /// + /// 付款金额 + /// + public double PayPrice { get; set; } + } +} diff --git a/Server/MyClass/Views/FansRecordShow.cs b/Server/MyClass/Views/FansRecordShow.cs new file mode 100644 index 0000000..204c135 --- /dev/null +++ b/Server/MyClass/Views/FansRecordShow.cs @@ -0,0 +1,17 @@ +using Common.Models.SubTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class FansRecordShow:FansRecord + { + /// + /// 机器人名称 + /// + public string RobotName { get; set; } = string.Empty; + } +} diff --git a/Server/MyClass/Views/IntegralShow.cs b/Server/MyClass/Views/IntegralShow.cs new file mode 100644 index 0000000..f402bec --- /dev/null +++ b/Server/MyClass/Views/IntegralShow.cs @@ -0,0 +1,16 @@ +using Common.Models.SubTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class IntegralShow:PointHist + { + public string RobotName { get; set; } + public string NickName { get; set; } + + } +} diff --git a/Server/MyClass/Views/JdOrderShow.cs b/Server/MyClass/Views/JdOrderShow.cs new file mode 100644 index 0000000..19eaaaf --- /dev/null +++ b/Server/MyClass/Views/JdOrderShow.cs @@ -0,0 +1,89 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + internal class JdOrderShow + { + /// + /// 商品编号 + /// + public string Itemid { get; set; } + + /// + /// 商品标题 + /// + public string ItemTitle { get; set; } + + /// + /// 用户ID + /// + public int UserId { get; set; } + + /// + /// 用户头像地址 + /// + public string UserHeadurl { get; set; } + + /// + /// 用户昵称 + /// + public string UserNickname { get; set; } + public string RobotName { get; set; } + + /// + /// 订单状态 + /// + public SystemOrderStatus OrderStatus { get; set; } + + /// + /// 联盟订单编号 + /// + public string TkOrderNumber { get; set; } + + /// + /// 京东订单编号 + /// + public string UsOrderNumber { get; set; } + + /// + /// 商品预估佣金 + /// + public double Commission { get; set; } + + /// + /// 购买数量 + /// + public int ItemCount { get; set; } + + /// + /// 返利金额 + /// + public double RebatePoint { get; set; } + + /// + /// 推荐人提成 + /// + public double RecommendPoint { get; set; } + + /// + /// 合伙人分红 + /// + public double PartnerPoint { get; set; } + + /// + /// 毛利率 + /// + public double GrossProfit { get; set; } + + /// + /// 付款金额 + /// + public double PayPrice { get; set; } + } + +} diff --git a/Server/MyClass/Views/KeywordShow.cs b/Server/MyClass/Views/KeywordShow.cs new file mode 100644 index 0000000..fc43135 --- /dev/null +++ b/Server/MyClass/Views/KeywordShow.cs @@ -0,0 +1,14 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class KeywordShow: Keyword + { + public string RobotName { get; set; } + } +} diff --git a/Server/MyClass/Views/LoginQRCodeStatus.cs b/Server/MyClass/Views/LoginQRCodeStatus.cs new file mode 100644 index 0000000..d405015 --- /dev/null +++ b/Server/MyClass/Views/LoginQRCodeStatus.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public enum LoginQRCodeStatus :int + { + 正在获取二维码 = 1, + 获取二维码失败 = 2, + 二维码已过期 = 3, + 等待扫码 = 4, + 等待确认登录 = 5, + 正在授权 = 6, + 登录并授权成功 = 7, + + 登录失败 = 97, + 操作超时 = 99 + } + +} diff --git a/Server/MyClass/Views/MTMediaShow.cs b/Server/MyClass/Views/MTMediaShow.cs new file mode 100644 index 0000000..6d7331a --- /dev/null +++ b/Server/MyClass/Views/MTMediaShow.cs @@ -0,0 +1,47 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + /// + /// 返回给前端的美团推广位信息 + /// + public class MTMediaShow + { + public int Id { get; set; } + /// + /// 淘宝联盟的ID + /// + public int LianmengId { get; set; } + /// + /// PID + /// + public string AdzoneId { get; set; } = string.Empty; + /// + /// 推广位名称 + /// + public string AdzoneName { get; set; } = string.Empty; + /// + /// 备注 + /// + public string Remark { get; set; } = string.Empty; + /// + /// 媒体类型 + /// + public MTMediaType MediaType { get; set; } + /// + /// 媒体ID + /// + public string MediaPId { get; set; } = string.Empty; + /// + /// 媒体名称 + /// + public string MediaName { get; set; } = string.Empty; + + public int UseCnt { get; set; } + } +} diff --git a/Server/MyClass/Views/NameShow.cs b/Server/MyClass/Views/NameShow.cs new file mode 100644 index 0000000..4cd4748 --- /dev/null +++ b/Server/MyClass/Views/NameShow.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class NameShow + { + public int Id { get; set; } + public string Name { get; set; } + } +} diff --git a/Server/MyClass/Views/PayRecordShow.cs b/Server/MyClass/Views/PayRecordShow.cs new file mode 100644 index 0000000..b8ee2c1 --- /dev/null +++ b/Server/MyClass/Views/PayRecordShow.cs @@ -0,0 +1,17 @@ +using Common.Models.SubTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class PayRecordShow:PayRecord + { + public string NickName { get; set; } = string.Empty; + + public string RobotName { get; set; } = string.Empty; + + } +} diff --git a/Server/MyClass/Views/PddOrderShow.cs b/Server/MyClass/Views/PddOrderShow.cs new file mode 100644 index 0000000..bcc57b8 --- /dev/null +++ b/Server/MyClass/Views/PddOrderShow.cs @@ -0,0 +1,87 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class PddOrderShow + { /// + /// 商品编号 + /// + public string Itemid { get; set; } + + /// + /// 商品标题 + /// + public string ItemTitle { get; set; } + + /// + /// 用户ID + /// + public int UserId { get; set; } + + /// + /// 用户头像地址 + /// + public string UserHeadurl { get; set; } + + /// + /// 用户昵称 + /// + public string UserNickname { get; set; } + public string RobotName { get; set; } + + /// + /// 订单状态 + /// + public SystemOrderStatus OrderStatus { get; set; } + + /// + /// 联盟订单编号 + /// + public string TkOrderNumber { get; set; } + + /// + /// 拼多多订单编号 + /// + public string UsOrderNumber { get; set; } + + /// + /// 商品预估佣金 + /// + public double Commission { get; set; } + + /// + /// 购买数量 + /// + public int ItemCount { get; set; } + + /// + /// 返利金额 + /// + public double RebatePoint { get; set; } + + /// + /// 推荐人提成 + /// + public double RecommendPoint { get; set; } + + /// + /// 合伙人分红 + /// + public double PartnerPoint { get; set; } + + /// + /// 毛利率 + /// + public double GrossProfit { get; set; } + + /// + /// 付款金额 + /// + public double PayPrice { get; set; } + } +} diff --git a/Server/MyClass/Views/PyqPublishShow.cs b/Server/MyClass/Views/PyqPublishShow.cs new file mode 100644 index 0000000..c03c634 --- /dev/null +++ b/Server/MyClass/Views/PyqPublishShow.cs @@ -0,0 +1,22 @@ +using Common.Models.Enums; +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class PyqPublishShow:PyqPublish + { + [SqlSugar.SugarColumn()] + public string RobotNickname { get; set; } + + public string RobotUserName { get; set; } + + public UserType UserType { get; set; } + + public List Imgs { get; set; } + } +} diff --git a/Server/MyClass/Views/QunfaShow.cs b/Server/MyClass/Views/QunfaShow.cs new file mode 100644 index 0000000..e8c5b26 --- /dev/null +++ b/Server/MyClass/Views/QunfaShow.cs @@ -0,0 +1,19 @@ +using Common.Models.Enums; +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class QunfaShow:Qunfa + { + public string RobotNick { get; set; } + + public string RobotUserName { get; set; } + + public UserType UserType { get; set; } + } +} diff --git a/Server/MyClass/Views/RebateConfigShow.cs b/Server/MyClass/Views/RebateConfigShow.cs new file mode 100644 index 0000000..843a746 --- /dev/null +++ b/Server/MyClass/Views/RebateConfigShow.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class RebateConfigShow + { + public int Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Server/MyClass/Views/RebateIdsShow.cs b/Server/MyClass/Views/RebateIdsShow.cs new file mode 100644 index 0000000..308edbd --- /dev/null +++ b/Server/MyClass/Views/RebateIdsShow.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class RebateIdsShow + { + public int Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Server/MyClass/Views/ReminderShow.cs b/Server/MyClass/Views/ReminderShow.cs new file mode 100644 index 0000000..5f077b4 --- /dev/null +++ b/Server/MyClass/Views/ReminderShow.cs @@ -0,0 +1,16 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class ReminderShow:Reminder + { + public string Nickname { get; set; } + public string Username { get; set; } + public string RobotName { get; set; } = string.Empty; + } +} diff --git a/Server/MyClass/Views/ReplyShow.cs b/Server/MyClass/Views/ReplyShow.cs new file mode 100644 index 0000000..9d90610 --- /dev/null +++ b/Server/MyClass/Views/ReplyShow.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class ReplyShow + { + /// + /// 字段名 + /// + public string Name { get; set; } + + /// + /// 描述信息 + /// + public string Description { get; set; } + + /// + /// 内容 + /// + public string Content { get; set; } + + /// + /// 支持的变量 + /// + public string[] SpecialVariables { get; set; } + } +} diff --git a/Server/MyClass/Views/ReplyShowClass.cs b/Server/MyClass/Views/ReplyShowClass.cs new file mode 100644 index 0000000..4ab1a0f --- /dev/null +++ b/Server/MyClass/Views/ReplyShowClass.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class ReplyShowClass + { + public string Name { get; set; } + public string Description { get; set; } + public List Menus { get; set; } + public string[] PrivateVariables { get; set; } + public string Content { get; set; } + } +} diff --git a/Server/MyClass/Views/RobotInfo.cs b/Server/MyClass/Views/RobotInfo.cs new file mode 100644 index 0000000..3351a20 --- /dev/null +++ b/Server/MyClass/Views/RobotInfo.cs @@ -0,0 +1,21 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + /// + /// 机器人ID和name显示类 + /// + public class RobotInfo + { + public int RobotId { get; set; } + + public string RobotName { get; set; } + + public UserType RobotType { get; set; } + } +} diff --git a/Server/MyClass/Views/RobotSettingShow.cs b/Server/MyClass/Views/RobotSettingShow.cs new file mode 100644 index 0000000..388589d --- /dev/null +++ b/Server/MyClass/Views/RobotSettingShow.cs @@ -0,0 +1,80 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class RobotSettingShow:Robot + { + /// + /// 基础设置名称 + /// + public string ConfibBaseName { get; set; } + + /// + /// 返利设置名称 + /// + public string ConfigRebateName { get; set; } + + /// + /// 回复提示名称 + /// + public string ConfigReplyName { get; set; } + + + public int TbLianmengId1 { get; set; } + public string TbLianmengNick1 { get; set; } + public string TbMediaNick1 { get; set; } + public int TbLianmengId2 { get; set; } + public string TbLianmengNick2 { get; set; } + public string TbMediaNick2 { get; set; } + + + public int DyLianmengId1 { get; set; } + public string DyLianmengNick1 { get; set; } + public int DyLianmengId2 { get; set; } + public string DyLianmengNick2 { get; set; } + public string DyMediaNick1 { get; set; } + public string DyMediaNick2 { get; set; } + + + + public string SnLianmengNick1 { get; set; } + + public string SnLianmengNick2 { get; set; } + + + public int JdLianmengId1 { get; set; } + public string JdLianmengNick1 { get; set; } + public int JdLianmengId2 { get; set; } + public string JdLianmengNick2 { get; set; } + public string JdMediaNick1 { get; set; } + public string JdMediaNick2 { get; set; } + + + public int MtLianmengId1 { get; set; } + public string MtLianmengNick1 { get; set; } + public int MtLianmengId2 { get; set; } + public string MtLianmengNick2 { get; set; } + public string MtMediaNick1 { get; set; } + public string MtMediaNick2 { get; set; } + + public int WphLianmengId1 { get; set; } + public string WphLianmengNick1 { get; set; } + public int WphLianmengId2 { get; set; } + public string WphLianmengNick2 { get; set; } + public string WphMediaNick1 { get; set; } + public string WphMediaNick2 { get; set; } + + + public int PddLianmengId1 { get; set; } + public string PddLianmengNick1 { get; set; } + public int PddLianmengId2 { get; set; } + public string PddLianmengNick2 { get; set; } + public string PddMediaNick1 { get; set; } + public string PddMediaNick2 { get; set; } + } +} diff --git a/Server/MyClass/Views/RunLogShow.cs b/Server/MyClass/Views/RunLogShow.cs new file mode 100644 index 0000000..52d6828 --- /dev/null +++ b/Server/MyClass/Views/RunLogShow.cs @@ -0,0 +1,14 @@ +using Common.Models.SubTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class RunLogShow:Log + { + public string RobotName { get; set; } = string.Empty; + } +} diff --git a/Server/MyClass/Views/ShopInfo.cs b/Server/MyClass/Views/ShopInfo.cs new file mode 100644 index 0000000..6ebe269 --- /dev/null +++ b/Server/MyClass/Views/ShopInfo.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class ShopInfo + { + } +} diff --git a/Server/MyClass/Views/SnOrderShow.cs b/Server/MyClass/Views/SnOrderShow.cs new file mode 100644 index 0000000..a6bfbda --- /dev/null +++ b/Server/MyClass/Views/SnOrderShow.cs @@ -0,0 +1,88 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + internal class SnOrderShow + { + /// + /// 商品编号 + /// + public string Itemid { get; set; } + + /// + /// 商品标题 + /// + public string ItemTitle { get; set; } + + /// + /// 用户ID + /// + public int UserId { get; set; } + + /// + /// 用户头像地址 + /// + public string UserHeadurl { get; set; } + + /// + /// 用户昵称 + /// + public string UserNickname { get; set; } + public string RobotName { get; set; } + + /// + /// 订单状态 + /// + public SystemOrderStatus OrderStatus { get; set; } + + /// + /// 联盟订单编号 + /// + public string TkOrderNumber { get; set; } + + /// + /// 订单编号 + /// + public string UsOrderNumber { get; set; } + + /// + /// 商品预估佣金 + /// + public double Commission { get; set; } + + /// + /// 购买数量 + /// + public int ItemCount { get; set; } + + /// + /// 返利金额 + /// + public double RebatePoint { get; set; } + + /// + /// 推荐人提成 + /// + public double RecommendPoint { get; set; } + + /// + /// 合伙人分红 + /// + public double PartnerPoint { get; set; } + + /// + /// 毛利率 + /// + public double GrossProfit { get; set; } + + /// + /// 付款金额 + /// + public double PayPrice { get; set; } + } +} diff --git a/Server/MyClass/Views/StaffShow.cs b/Server/MyClass/Views/StaffShow.cs new file mode 100644 index 0000000..03fca6b --- /dev/null +++ b/Server/MyClass/Views/StaffShow.cs @@ -0,0 +1,15 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class StaffShow: Staff + { + public string RoleName { get; set; } + + } +} diff --git a/Server/MyClass/Views/TbOrderShow.cs b/Server/MyClass/Views/TbOrderShow.cs new file mode 100644 index 0000000..d7a8b27 --- /dev/null +++ b/Server/MyClass/Views/TbOrderShow.cs @@ -0,0 +1,90 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class TboderShow + { + /// + /// 商品编号 + /// + public string Itemid { get; set; } + + /// + /// 商品标题 + /// + public string ItemTitle { get; set; } + + /// + /// 用户ID + /// + public int UserId { get; set; } + + /// + /// 用户头像地址 + /// + public string UserHeadurl { get; set; } + + /// + /// 用户昵称 + /// + public string UserNickname { get; set; } + + public string RobotName { get; set; } + + /// + /// 订单状态 + /// + public SystemOrderStatus OrderStatus { get; set; } + + /// + /// 联盟订单编号 + /// + public string TkOrderNumber { get; set; } + + /// + /// 淘宝订单编号 + /// + public string UsOrderNumber { get; set; } + + /// + /// 商品预估佣金 + /// + public double Commission { get; set; } + + /// + /// 购买数量 + /// + public int ItemCount { get; set; } + + /// + /// 返利金额 + /// + public double RebatePoint { get; set; } + + /// + /// 推荐人提成 + /// + public double RecommendPoint { get; set; } + + /// + /// 合伙人分红 + /// + public double PartnerPoint { get; set; } + + /// + /// 毛利率 + /// + public double GrossProfit { get; set; } + + /// + /// 付款金额 + /// + public double PayPrice { get; set; } + } +} diff --git a/Server/MyClass/Views/UserGroupInfo.cs b/Server/MyClass/Views/UserGroupInfo.cs new file mode 100644 index 0000000..c4f8c17 --- /dev/null +++ b/Server/MyClass/Views/UserGroupInfo.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + /// + /// 用户组显示类 + /// + public class UserGroupInfo + { + public int Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Server/MyClass/Views/UserGroupView.cs b/Server/MyClass/Views/UserGroupView.cs new file mode 100644 index 0000000..329ab96 --- /dev/null +++ b/Server/MyClass/Views/UserGroupView.cs @@ -0,0 +1,14 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + public class UserGroupView: UserGroup + { + public string ConfigName { get; set; } + } +} diff --git a/Server/MyClass/Views/UserShow.cs b/Server/MyClass/Views/UserShow.cs new file mode 100644 index 0000000..da63a7b --- /dev/null +++ b/Server/MyClass/Views/UserShow.cs @@ -0,0 +1,36 @@ +using Common.Models.SubCountTables; +using Common.Models.UnqTables; + +namespace Server.MyClass.Views +{ + public class UserShow : UserData + { + public string Nickname { get; set; } + public string Username { get; set; } + /// + /// 推荐人昵称 + /// + public string InviterNickname { get; set; } = string.Empty; + public string InviterUsername { get; set; } + /// + /// 邀请人 + /// + public int InviterId { get; set; } + public string InviterHeadurl { get; set; } + + /// + /// 机器人名称 + /// + public string RobotName { get; set; } = string.Empty; + + public string GroupName { get; set; } = string.Empty; + /// + /// 头像 + /// + public string Headurl { get; set; } + public UserBlack BlackInfo { get; set; } + + } + + +} diff --git a/Server/MyClass/Views/WphOrderShow.cs b/Server/MyClass/Views/WphOrderShow.cs new file mode 100644 index 0000000..8b2fc60 --- /dev/null +++ b/Server/MyClass/Views/WphOrderShow.cs @@ -0,0 +1,88 @@ +using Common.Models.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views +{ + internal class WphOrderShow + { + /// + /// 商品编号 + /// + public string Itemid { get; set; } + + /// + /// 商品标题 + /// + public string ItemTitle { get; set; } + + /// + /// 用户ID + /// + public int UserId { get; set; } + + /// + /// 用户头像地址 + /// + public string UserHeadurl { get; set; } + + /// + /// 用户昵称 + /// + public string UserNickname { get; set; } + public string RobotName { get; set; } + + /// + /// 订单状态 + /// + public SystemOrderStatus OrderStatus { get; set; } + + /// + /// 联盟订单编号 + /// + public string TkOrderNumber { get; set; } + + /// + /// 订单编号 + /// + public string UsOrderNumber { get; set; } + + /// + /// 商品预估佣金 + /// + public double Commission { get; set; } + + /// + /// 购买数量 + /// + public int ItemCount { get; set; } + + /// + /// 返利金额 + /// + public double RebatePoint { get; set; } + + /// + /// 推荐人提成 + /// + public double RecommendPoint { get; set; } + + /// + /// 合伙人分红 + /// + public double PartnerPoint { get; set; } + + /// + /// 毛利率 + /// + public double GrossProfit { get; set; } + + /// + /// 付款金额 + /// + public double PayPrice { get; set; } + } +} diff --git a/Server/MyClass/Views/medias/DyMediaShow.cs b/Server/MyClass/Views/medias/DyMediaShow.cs new file mode 100644 index 0000000..37df661 --- /dev/null +++ b/Server/MyClass/Views/medias/DyMediaShow.cs @@ -0,0 +1,17 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views.medias +{ + internal class DyMediaShow:DyMedia + { + /// + /// 当前正在使用此推广位的机器人数量 + /// + public int UseCnt { get; set; } + } +} diff --git a/Server/MyClass/Views/medias/JdMediaShow.cs b/Server/MyClass/Views/medias/JdMediaShow.cs new file mode 100644 index 0000000..5ab09c4 --- /dev/null +++ b/Server/MyClass/Views/medias/JdMediaShow.cs @@ -0,0 +1,17 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views.medias +{ + internal class JdMediaShow:JdMedia + { + /// + /// 当前正在使用此推广位的机器人数量 + /// + public int UseCnt { get; set; } + } +} diff --git a/Server/MyClass/Views/medias/MtMediaShow.cs b/Server/MyClass/Views/medias/MtMediaShow.cs new file mode 100644 index 0000000..74554d1 --- /dev/null +++ b/Server/MyClass/Views/medias/MtMediaShow.cs @@ -0,0 +1,17 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views.medias +{ + internal class MtMediaShow:MtMedia + { + /// + /// 当前正在使用此推广位的机器人数量 + /// + public int UseCnt { get; set; } + } +} diff --git a/Server/MyClass/Views/medias/PddMediaShow.cs b/Server/MyClass/Views/medias/PddMediaShow.cs new file mode 100644 index 0000000..b21375d --- /dev/null +++ b/Server/MyClass/Views/medias/PddMediaShow.cs @@ -0,0 +1,17 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views.medias +{ + internal class PddMediaShow:MtMedia + { + /// + /// 当前正在使用此推广位的机器人数量 + /// + public int UseCnt { get; set; } + } +} diff --git a/Server/MyClass/Views/medias/SnMediaShow.cs b/Server/MyClass/Views/medias/SnMediaShow.cs new file mode 100644 index 0000000..e610558 --- /dev/null +++ b/Server/MyClass/Views/medias/SnMediaShow.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views.medias +{ + internal class SnMediaShow + { + /// + /// 当前正在使用此推广位的机器人数量 + /// + public int UseCnt { get; set; } + } +} diff --git a/Server/MyClass/Views/medias/TbMediaShow.cs b/Server/MyClass/Views/medias/TbMediaShow.cs new file mode 100644 index 0000000..5095c89 --- /dev/null +++ b/Server/MyClass/Views/medias/TbMediaShow.cs @@ -0,0 +1,32 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views.medias +{ + public class TbMediaShow : TbMedia + { + /// + /// 当前正在使用此推广位的机器人数量 + /// + public int UseCnt { get; set; } + + /// + /// 当前推广位归属的联盟名称 + /// + public string LmName { get; set; } + + /// + /// 联盟账号 + /// + public string LmAcc { get; set; } + + /// + /// 是否支持淘礼金 + /// + public bool IsTlj { get; set; } + } +} diff --git a/Server/MyClass/Views/medias/VipMediaShow.cs b/Server/MyClass/Views/medias/VipMediaShow.cs new file mode 100644 index 0000000..c6ff625 --- /dev/null +++ b/Server/MyClass/Views/medias/VipMediaShow.cs @@ -0,0 +1,17 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.MyClass.Views.medias +{ + internal class VipMediaShow:WphMedia + { + /// + /// 当前正在使用此推广位的机器人数量 + /// + public int UseCnt { get; set; } + } +} diff --git a/Server/OwinServer.cs b/Server/OwinServer.cs new file mode 100644 index 0000000..45767b2 --- /dev/null +++ b/Server/OwinServer.cs @@ -0,0 +1,236 @@ +using Microsoft.AspNetCore.Cors; +using Microsoft.Owin; +using Microsoft.Owin.Cors; +using Microsoft.Owin.FileSystems; +using Microsoft.Owin.Hosting; +using Microsoft.Owin.StaticFiles; +using Newtonsoft.Json; +using Owin; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Web.Http; +using System.Web.Mvc; + +namespace Server +{ + internal class OwinServer + { + + public static string RootDir = CsharpHttpHelper.HttpExtend.MapPath("网站");// Directory.GetCurrentDirectory() + "\\网站"; + /// + /// 查找本地数据,无数据 返回index + /// + /// + /// + public static string GetFilePath(string relPath) + { + if (string.IsNullOrEmpty(relPath) || relPath == "/") + { + relPath = "index.html"; + } + + return Path.Combine( + AppDomain.CurrentDomain.BaseDirectory + , RootDir + , relPath.TrimStart('/').Replace('/', '\\')); + } + + /// + /// 设置返回contenttype 并返回数据 + /// + /// + /// + /// + public Task SetResponse(IOwinContext context, string path) + { + var perfix = Path.GetExtension(path); + switch (perfix) + { + case ".html": + context.Response.ContentType = "text/html; charset=utf-8"; + break; + case ".js": + context.Response.ContentType = "application/x-javascript"; + break; + case ".css": + context.Response.ContentType = "text/css"; + break; + case ".jpg": + case ".jpeg": + context.Response.ContentType = "image/jpeg"; + break; + case ".png": + context.Response.ContentType = "application/x-png"; + break; + case ".mp4": + context.Response.ContentType = "video/mpeg4"; + break; + case ".webp": + context.Response.ContentType = "image/webp"; + break; + case ".gif": + context.Response.ContentType = "image/gif"; + break; + case ".woff2": + context.Response.ContentType = "application/x-font-woff"; + break; + case ".ico": + context.Response.ContentType = "image/x-icon"; + break; + } + return context.Response.WriteAsync(File.ReadAllText(path)); + } + + /// + /// 执行API + /// + /// + /// + /// + private Task TodoApi(IOwinContext context, Func next) + { + //var response = new WebResult(); + //try + //{ + // var query = context.Request.Query.ToString(); + + // //Dictionary Param = new Dictionary(); + // //var contentType = context.Request.ContentType; + // //if (context.Request.Method.ToLower() == "post") + // //{ + // // if (contentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase)) + // // { + // // string body = new StreamReader(context.Request.Body, Encoding.UTF8).ReadToEnd(); + // // var postdata =new NameValueCollection(StringComparer.OrdinalIgnoreCase); + // // ///Util.GetQueryString(body, Encoding.UTF8); + // // if (postdata != null) + // // { + // // foreach (var item in postdata.AllKeys) + // // { + // // Param[item] = HttpUtility.UrlEncode(postdata[item]); + // // } + // // } + // // } + // //} + + // //if (context.Request.Query != null && context.Request.Query.Count() > 0) + // //{ + // // foreach (var item in context.Request.Query) + // // { + // // if (item.Value != null && item.Value.Length > 0) Param[item.Key] = HttpUtility.UrlDecode(item.Value[0]); + // // } + // //} + + // //if (EventClient.StopParsing) return next(); + // //var plugins = PluginClient.Plugins.ToArray(); + // //var events = new WebRequestEvents(context, Param, response); + // ////正常事件解析 + // //foreach (var plugin in plugins) + // //{ + // // if (!plugin.IsRun) continue;//未运行 + // // if (events.Cancel) break;//已取消传递 + // // plugin.SDK.OnEvent(context, events); + // //} + //} + //catch (Exception ex) + //{ + // response.code = -1; + // response.errMsg = ex.Message; + //} + + //if (string.IsNullOrEmpty(response.)) + //{ + // response.ok = false; + // response.errMsg = $"请求成功,但未响应结果!{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"; + //} + + //var msg = JsonConvert.SerializeObject(response); + context.Response.StatusCode = (int)HttpStatusCode.OK; + return context.Response.WriteAsync("无响应结果"); + } + + /// + /// 挂载数据 分流静态文件及接口请求 + /// + /// + /// + /// + public async Task RequestHandler(IOwinContext context, Func next) + { + try + { + var path = GetFilePath(context.Request.Path.Value); + if (File.Exists(path)) + { + await SetResponse(context, path); + } + else + { + await TodoApi(context, next); + } + } + catch (Exception) + { + } + await next(); + } + + public void Configuration(Owin.IAppBuilder appBuilder) + { + appBuilder.UseCors(CorsOptions.AllowAll); + + var config = new HttpConfiguration(); + config.MapHttpAttributeRoutes(); + + // config.Routes.MapHttpRoute( + // name: "DefaultApi", + // routeTemplate: "api/{controller}/{id}" + //); + + config.Routes.MapHttpRoute( + name: "Default", + + routeTemplate: "{controller}/{action}/{id}", + defaults: new { controller = "abbb", action = "Index", id = UrlParameter.Optional } + ); + + ///@".\wwwroot" + var physicalFileSystem = new PhysicalFileSystem(RootDir); + var options = new FileServerOptions + { + EnableDefaultFiles = true, + FileSystem = physicalFileSystem + }; + + options.StaticFileOptions.FileSystem = physicalFileSystem; + options.StaticFileOptions.ServeUnknownFileTypes = true; + options.DefaultFilesOptions.DefaultFileNames = new[] { "Index.html" }; + appBuilder.UseFileServer(options); + appBuilder.UseWebApi(config); + + + + /* + app.UseHttpsRedirection(); +app.UseStaticFiles(); + +app.UseRouting(); + +app.UseAuthorization(); + +app.MapRazorPages(); + +app.Run(); + */ + } + + } +} diff --git a/Server/Program.cs b/Server/Program.cs new file mode 100644 index 0000000..febcca8 --- /dev/null +++ b/Server/Program.cs @@ -0,0 +1,81 @@ +using Common.Models.JsonModels; +using Common.Models.SubTables; +using Common.Requests.Lianmengs; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Server.Configs; +using Server.Winforms; +using Server.Winforms.LoginForms; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server +{ + internal static class Program + { + /// + /// 应用程序的主入口点。 + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + + if (string.IsNullOrEmpty(Client.SingleClient.Config.MysqlHost)) + { + if (new InitMysqlForm(Client.SingleClient).ShowDialog() != DialogResult.Yes) + { + return; + } + } + //线程池 + ThreadPool.SetMinThreads(10, 10); + ThreadPool.SetMaxThreads(150, 150); + //显示启动窗口 + var startForm = new StartForm(); + //Application.Run(new StartForm()); + var th = new Thread(() => + { + var mainForm = new MainForm(); + mainForm.InitCompleteAction = () => + { + startForm?.Invoke(new Action(() => + { + startForm.DialogResult = DialogResult.OK; + startForm.Close(); + startForm = null; + })); + }; + mainForm.Show(); + mainForm.Activate(); + Application.Run(mainForm); + //强制退出程序,防止意外驻留进程 + Environment.Exit(0); + }); + th.SetApartmentState(ApartmentState.STA); + th.Start(); + if (startForm.ShowDialog() == DialogResult.OK) + { + Application.Run(); + } + //强制退出程序,防止意外驻留进程 + Environment.Exit(0); + } + + public static void Test() + { + var json = @"{'data':{'data':{'cursor':'4737996432465788974','orders':[{'ads_estimated_commission':'100','ads_promotion_rate':'10','ads_real_commission':'100','ads_split_rate':'0','app':'抖音','author_account':'我的昵称','author_buyin_id':'123467','author_openid':'f190e172-5fd8-4b7b-babb-f32323e60f7b','author_short_id':'kodofo','buyer_openid':'f190e172-5fd8-4b7b-babb-f32323e60f7b','commission_rate':'2000','estimated_commission':'165','estimated_tech_service_fee':'12','estimated_total_commission':'2','flow_point':'PAY_SUCC','item_num':'2','media_type':'shop_list','order_id':'4737996432465788974','pay_goods_amount':'1100','pay_success_time':'2006-01-02 15:04:05','pick_source_client_key':'jifji32rnu3jit43','pid_info':{'external_info':'1222_2333','media_type_name':'Live','pid':'dy_1234_33_455'},'product_id':'3450632721376902816','product_img':'https://tosv.boe.byted.org/obj/temai/7e92a281163e33cedef99d8735d1e90bwww828-708','product_name':'测试商品','real_commission':'165','refund_time':'2006-01-02 15:04:05','settle_time':'2006-01-02 15:04:05','settled_goods_amount':'0','settled_tech_service_fee':'12','shop_estimated_commission':'12','shop_id':'1234','shop_name':'我的店铺','shop_real_commission':'12','total_pay_amount':'2100','update_time':'2006-01-02 15:04:05'}]}},'err_no':0,'message':'success','code':10000,'msg':'success','sub_code':'','sub_msg':''}"; + var rest = JObject.Parse(json)["data"]["data"]["orders"]; + foreach (var item in rest) + { + var order = new DyOrder(); + Common.Utils.Util.CopyToObj(item, order); + } + } + } +} diff --git a/Server/Properties/AssemblyInfo.cs b/Server/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1a33f70 --- /dev/null +++ b/Server/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的一般信息由以下 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Server")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 +//请将此类型的 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("1e0c7b53-1915-461f-99ca-3923bd35f849")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 生成号 +// 修订号 +// +//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 +//通过使用 "*",如下所示: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Server/Properties/Resources.Designer.cs b/Server/Properties/Resources.Designer.cs new file mode 100644 index 0000000..850f009 --- /dev/null +++ b/Server/Properties/Resources.Designer.cs @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// +// 此代码由工具生成。 +// 运行时版本:4.0.30319.42000 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace Server.Properties { + using System; + + + /// + /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// 返回此类使用的缓存的 ResourceManager 实例。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Server.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 重写当前线程的 CurrentUICulture 属性,对 + /// 使用此强类型资源类的所有资源查找执行重写。 + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// + internal static System.Drawing.Bitmap progress { + get { + object obj = ResourceManager.GetObject("progress", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Server/Properties/Resources.resx b/Server/Properties/Resources.resx new file mode 100644 index 0000000..dc062d5 --- /dev/null +++ b/Server/Properties/Resources.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\progress.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Server/Properties/Settings.Designer.cs b/Server/Properties/Settings.Designer.cs new file mode 100644 index 0000000..c2be829 --- /dev/null +++ b/Server/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Server.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Server/Properties/Settings.settings b/Server/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/Server/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Server/Properties/app.manifest b/Server/Properties/app.manifest new file mode 100644 index 0000000..da46558 --- /dev/null +++ b/Server/Properties/app.manifest @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Server/Resources/progress.gif b/Server/Resources/progress.gif new file mode 100644 index 0000000..4e303c2 Binary files /dev/null and b/Server/Resources/progress.gif differ diff --git a/Server/Server.csproj b/Server/Server.csproj new file mode 100644 index 0000000..d31d2dc --- /dev/null +++ b/Server/Server.csproj @@ -0,0 +1,512 @@ + + + + + Debug + AnyCPU + {1E0C7B53-1915-461F-99CA-3923BD35F849} + WinExe + Server + Server + v4.6.1 + 512 + true + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + LocalIntranet + + + false + + + Properties\app.manifest + + + + ..\packages\AutoMapper.10.0.0\lib\net461\AutoMapper.dll + + + ..\packages\BouncyCastle.1.8.5\lib\BouncyCastle.Crypto.dll + + + False + ..\..\..\yz_common\Common\Model\bin\Debug\Common.dll + + + ..\packages\EO.WebBrowser.21.3.18\lib\EO.Base.dll + + + ..\packages\EO.WebBrowser.21.3.18\lib\EO.WebBrowser.dll + + + ..\packages\EO.WebBrowser.WinForm.21.3.18\lib\EO.WebBrowser.WinForm.dll + + + ..\packages\EO.WebBrowser.21.3.18\lib\EO.WebEngine.dll + + + ..\packages\Google.Protobuf.3.19.4\lib\net45\Google.Protobuf.dll + + + Dlls\HttpHelper.dll + + + ..\packages\SharpZipLib.1.3.3\lib\net45\ICSharpCode.SharpZipLib.dll + + + ..\packages\K4os.Compression.LZ4.1.2.6\lib\net46\K4os.Compression.LZ4.dll + + + ..\packages\K4os.Compression.LZ4.Streams.1.2.6\lib\net46\K4os.Compression.LZ4.Streams.dll + + + ..\packages\K4os.Hash.xxHash.1.0.6\lib\net46\K4os.Hash.xxHash.dll + + + ..\packages\Microsoft.AspNetCore.Cors.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Cors.dll + + + ..\packages\Microsoft.AspNetCore.Hosting.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Hosting.Server.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Server.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Http.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll + + + ..\packages\Microsoft.AspNetCore.Http.Extensions.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Extensions.dll + + + ..\packages\Microsoft.AspNetCore.Http.Features.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Features.dll + + + ..\packages\Microsoft.AspNetCore.StaticFiles.2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.StaticFiles.dll + + + ..\packages\Microsoft.Extensions.Configuration.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll + + + ..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll + + + ..\packages\Microsoft.Extensions.FileProviders.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.FileProviders.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Hosting.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Hosting.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Logging.Abstractions.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll + + + ..\packages\Microsoft.Extensions.Options.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Options.dll + + + ..\packages\Microsoft.Extensions.Primitives.2.2.0\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll + + + ..\packages\Microsoft.Extensions.WebEncoders.2.2.0\lib\netstandard2.0\Microsoft.Extensions.WebEncoders.dll + + + ..\packages\Microsoft.Net.Http.Headers.2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll + + + ..\packages\Microsoft.Owin.4.2.0\lib\net45\Microsoft.Owin.dll + + + ..\packages\Microsoft.Owin.Cors.4.2.0\lib\net45\Microsoft.Owin.Cors.dll + + + ..\packages\Microsoft.Owin.FileSystems.4.2.0\lib\net45\Microsoft.Owin.FileSystems.dll + + + ..\packages\Microsoft.Owin.Host.HttpListener.4.2.0\lib\net45\Microsoft.Owin.Host.HttpListener.dll + + + ..\packages\Microsoft.Owin.Hosting.4.2.0\lib\net45\Microsoft.Owin.Hosting.dll + + + ..\packages\Microsoft.Owin.StaticFiles.4.2.0\lib\net45\Microsoft.Owin.StaticFiles.dll + + + ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + + ..\packages\MySql.Data.8.0.28\lib\net452\MySql.Data.dll + + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + + + ..\packages\Owin.1.0\lib\net40\Owin.dll + + + ..\packages\protobuf-net.3.0.101\lib\net461\protobuf-net.dll + + + ..\packages\protobuf-net.Core.3.0.101\lib\net461\protobuf-net.Core.dll + + + ..\packages\SqlSugar.5.0.7\lib\SqlSugar.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Collections.Immutable.1.7.1\lib\net461\System.Collections.Immutable.dll + + + + ..\packages\System.ComponentModel.Annotations.4.5.0\lib\net461\System.ComponentModel.Annotations.dll + + + + + + + Dlls\System.Data.SQLite.dll + + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + + ..\packages\System.Text.Encodings.Web.4.5.0\lib\netstandard2.0\System.Text.Encodings.Web.dll + + + + + ..\packages\Microsoft.AspNet.Cors.5.0.0\lib\net45\System.Web.Cors.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll + + + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll + + + ..\packages\Microsoft.AspNet.WebApi.Owin.5.2.7\lib\net45\System.Web.Http.Owin.dll + + + ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll + + + ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll + + + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll + + + + + + + + + + + + ..\packages\MySql.Data.8.0.28\lib\net452\Ubiety.Dns.Core.dll + + + ..\packages\MySql.Data.8.0.28\lib\net452\ZstdNet.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Form + + + DefaultForm.cs + + + Form + + + InitMysqlForm.cs + + + + Form + + + LoginBaseForm.cs + + + Form + + + LoginLianmengForm.cs + + + + + + + Form + + + MainForm.cs + + + Form + + + SetDefaultuserForm.cs + + + Form + + + StartForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + DefaultForm.cs + + + InitMysqlForm.cs + + + LoginBaseForm.cs + + + LoginLianmengForm.cs + + + MainForm.cs + + + SetDefaultuserForm.cs + + + StartForm.cs + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + + + + False + Microsoft .NET Framework 4.6.1 %28x86 和 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/Server/Services/BlacklistService.cs b/Server/Services/BlacklistService.cs new file mode 100644 index 0000000..baf19cb --- /dev/null +++ b/Server/Services/BlacklistService.cs @@ -0,0 +1,336 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Server.Controllers.Help; +using Server.Utils; +using SqlSugar; + +namespace Server.Services +{ + /// + /// 黑名单服务 + /// + public class BlacklistService + { + private SqlSugarClient Db { get; set; } + + public BlacklistService() + { + Db = Client.SingleClient.Db; + } + private int GetUserType(UserType userType) + { + switch (userType) + { + case UserType.微信用户: + return 0; + case UserType.企业微信: + return 2; + case UserType.QQ用户: + return 1; + default: + return 0; + } + } + /// + /// 删除用户黑名单 + /// + /// + /// + /// + /// + public string RemoveUserBlack(string username, UserType userType, bool isCloud) + { + if (isCloud) + { + var res = YZCloudApiHelper.RemoveBlacklist(new List() + { + new RemoveBlacklistInput() + { + Username = username, + Type = GetUserType( userType), + UserToken = "" + } + }); + //if (!res.Ok) + //{ + // return PutData("云端黑名单删除失败!" + res.Message); + //} + } + var item = Db.Queryable().Where(w => w.Username == username && w.UserType == userType).First(); + if (item != null) + { + item.IsDel = true; + Db.Updateable(item).ExecuteCommand(); + return null; + } + return null; + } + /// + /// 新增用户黑名单 + /// + /// + /// + /// + /// + /// + /// + /// + public string AddUserBlack(UserType type, string userName, string nickName, BlackType blackType,string avatar, string remark, bool isCloud) + { + BlacklistGroupType GetBlackType() + { + switch (blackType) + { + case BlackType.未分类: + return BlacklistGroupType.未分组; + case BlackType.薅羊毛: + return BlacklistGroupType.薅羊毛党; + case BlackType.同行: + return BlacklistGroupType.恶意举报; + case BlackType.恶意举报: + return BlacklistGroupType.恶意举报; + } + return BlacklistGroupType.未分组; + } + //是否上传到云端 + if (isCloud) + { + var res = YZCloudApiHelper.AddUserBlacklist(new List() + { + new SetBlacklistInput() + { + AddDateTime = DateTime.Now, + Avatar = avatar, + GroupType=GetBlackType(), + Remark = remark, + Type = GetUserType( type), + UserToken = "", + UserName = userName, + UserNick = nickName + } + }); + if (!res.Ok) + { + return "云端新增失败" + res.Message; + } + } + var item = Db.Queryable().Where(w => w.Username == userName && w.UserType == type).First(); + if (item != null) + { + item.NickName = nickName; + item.BlackType = blackType; + item.Remark = remark; + item.IsDel = false;//标记没有被删除 + Db.Updateable(item).ExecuteCommand(); + } + else + { + item = new UserBlack(); + item.UserType = type; + item.Username = userName; + item.NickName = nickName; + item.BlackType = blackType; + item.Remark = remark; + item.IsDel = false; + item.IsCloud = isCloud; + item.UpdateTime = DateTime.Now; + Db.Insertable(item).ExecuteCommand(); + } + return null; + } + /// + /// 新增商品黑名单 + /// + /// + /// + /// + /// + /// + /// + public string AddGoodsBlack(string goodsId, LianmengType platform, string storeName, string remark, + bool isCloud) + { + //上传到云 + void AddCloud() + { + if (!isCloud) + { + return; + } + YZCloudApiHelper.AddGoodsBlacklist(new List() + { + new SetGoodsBlacklistInput() + { + AddDateTime = DateTime.Now, + GoodsId = goodsId, + Platform = LianmengTypeHelper.GetPlatform(platform), + Remark = remark, + StoreName = storeName, + UserToken = "" + } + }); + } + var item = Db.Queryable().Where(w => w.GoodsId == goodsId && w.Platform == platform).First(); + if (item != null) + { + if (item.IsDel) + { + item.IsDel = false;//取消删除标记 + item.UpdateTime = DateTime.Now; + this.Db.Updateable(item).ExecuteCommand(); + AddCloud(); + return null; + } + return "已经存在"; + } + else + { + item = new GoodsBlacklist(); + item.GoodsId = goodsId; + item.Platform = platform; + item.StoreName = storeName; + item.Remark = storeName; + item.Remark = remark; + item.IsDel = false; + item.UpdateTime = DateTime.Now; + Db.Insertable(item).ExecuteCommand(); + AddCloud(); + } + return null; + } + /// + /// 删除商品黑名单 + /// + /// + /// + /// + /// + public string RemoveGoodsBlack(string goodsId, LianmengType platform, bool isCloud) + { + if (isCloud) + { + var res = YZCloudApiHelper.RemoveGoodsBlacklist(new List() + { + new RemoveGoodsBlacklistInput() + { + GoodsId = goodsId, + Platform = LianmengTypeHelper.GetPlatform(platform), + UserToken = "" + } + }); + //if (res.Ok) + //{ + // return PutData("云端黑名单删除失败!" + res.Message); + //} + } + var item = Db.Queryable().Where(w => w.GoodsId == goodsId && w.Platform == platform).First(); + if (item != null) + { + item.IsDel = true; + Db.Updateable(item).ExecuteCommand(); + return null; + } + return "删除失败"; + } + + /// + /// 新增商店黑名单 + /// + /// + /// + /// + /// + /// + public string AddStoreBlack(LianmengType platform, string storeId, string storeName, string remark, bool isCloud) + { + //上传到云 + void AddCloud() + { + if (!isCloud) + { + return; + } + YZCloudApiHelper.AddStoreBlacklist(new List() + { + new SetStoerBlacklistInput() + { + AddDateTime = DateTime.Now, + Platform = LianmengTypeHelper.GetPlatform(platform), + Remark = remark, + StoreName = storeName, + StoreId = storeId, + UserToken = "" + } + }); + } + var item = Db.Queryable().Where(w => w.StoreId == storeId && w.Platform == platform).First(); + if (item != null) + { + if (item.IsDel) + { + item.StoreName = storeName; + item.IsDel = false;//取消删除标记 + item.UpdateTime = DateTime.Now; + this.Db.Updateable(item).ExecuteCommand(); + AddCloud(); + return null; + } + return "已经存在了"; + } + else + { + item = new StoreBlacklist(); + item.Platform = platform; + item.StoreName = storeName; + item.StoreId = storeId; + item.Remark = storeName; + item.Remark = remark; + item.IsDel = false; + item.UpdateTime = DateTime.Now; + Db.Insertable(item).ExecuteCommand(); + AddCloud(); + } + return null; + } + /// + /// 删除商店黑名单 + /// + /// + /// + /// + /// + public string RemoveStoreBlack(string storeId, LianmengType platform, bool isCloud) + { + if (isCloud) + { + var res = YZCloudApiHelper.RemoveStoreBlacklist(new List() + { + new RemoveStoreBlacklistInput() + { + StoreId = storeId, + Platform = LianmengTypeHelper.GetPlatform(platform), + UserToken = "" + } + }); + //if (res.Ok) + //{ + // return PutData("云端黑名单删除失败!" + res.Message); + //} + } + var item = Db.Queryable().Where(w => w.StoreName == storeId && w.Platform == platform).First(); + if (item != null) + { + item.IsDel = true; + Db.Updateable(item).ExecuteCommand(); + return null; + } + return "删除失败"; + } + } +} diff --git a/Server/Services/DataMigration/DataMigrationManageSerivce.cs b/Server/Services/DataMigration/DataMigrationManageSerivce.cs new file mode 100644 index 0000000..a6eb536 --- /dev/null +++ b/Server/Services/DataMigration/DataMigrationManageSerivce.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.Utils; +using Newtonsoft.Json; +using Server.MyClass.Class; +using Server.Services.DataMigration.Services; +using Server.Services.DataMigration.Services.OldMDK; +using Server.Utils; + +namespace Server.Services.DataMigration +{ + /// + /// 数据迁移管理服务 + /// + public class DataMigrationManageSerivce + { + private DataMigrationManageSerivce() + { + + } + + private static DataMigrationManageSerivce _dataMigrationManageSerivce; + + private static object lockobj = new object(); + /// + /// 实例 + /// + public static DataMigrationManageSerivce Instance + { + get + { + if (_dataMigrationManageSerivce == null) + { + lock (lockobj) + { + if (_dataMigrationManageSerivce == null) + { + _dataMigrationManageSerivce = new DataMigrationManageSerivce(); + } + } + } + return _dataMigrationManageSerivce; + } + } + /// + /// 检查导入数据包,并且解压 + /// + /// + /// + public string Check(string path) + { + string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataMigration"); + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + //开始解压 + if (!ZipHelper.UnZipFile(path, dir, out var err)) + { + return err; + } + if (!File.Exists(Path.Combine(dir, "PackInfo.json"))) + { + return "打包信息不存在。"; + } + var json = File.ReadAllText(Path.Combine(dir, "PackInfo.json")); + if (string.IsNullOrWhiteSpace(json)) + { + return "打包信息不存在2"; + } + var packInfo = JsonConvert.DeserializeObject(json); + if (packInfo == null) + { + return "打包信息不存在3"; + } + return null; + } + /// + /// 开始启动 + /// + /// + public string Start(string path) + { + string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataMigration"); + if (!Directory.Exists(dir)) + { + return "请先调用检查数据包"; + } + if (!File.Exists(Path.Combine(dir, "PackInfo.json"))) + { + return "打包信息不存在"; + } + var json = File.ReadAllText(Path.Combine(dir, "PackInfo.json")); + if (string.IsNullOrWhiteSpace(json)) + { + return "打包信息不存在"; + } + var packInfo = JsonConvert.DeserializeObject(json); + if (packInfo == null) + { + return "打包信息不存在"; + } + var th = new Thread(() => + { + //迁移开始 + DataMigrationProgressService.Instance.Start(); + var state = DataMigrationProgressService.Instance.GetState(); + try + { + var ser = new GeneralHandleMigrationService(); + ser.RootDir = dir; + ser.Name = packInfo.TypeName; + ser.PackInfo = packInfo; + ser.Initialize(); + ser.Start(state.AddLog); + } + catch (Exception e) + { + state.AddLog("出现错误:" + e.ToString()); + } + finally + { + DataMigrationProgressService.Instance.Stop(); + } + }); + th.IsBackground = true; + th.Start(); + return null; + } + + + public void Test() + { + string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DataMigration"); + if (!Directory.Exists(dir)) + { + Start(@"C:\Code\yz_dataconvert\yz_dataconvert\bin\Debug\transition.zip"); + } + if (!File.Exists(Path.Combine(dir, "PackInfo.json"))) + { + return; + } + var json = File.ReadAllText(Path.Combine(dir, "PackInfo.json")); + if (string.IsNullOrWhiteSpace(json)) + { + return; + } + var packInfo = JsonConvert.DeserializeObject(json); + if (packInfo == null) + { + return; + } + var ser = new GeneralHandleMigrationService(); + ser.RootDir = dir; + ser.Name = packInfo.TypeName; + ser.PackInfo = packInfo; + ser.Initialize(); + ser.Start(Console.WriteLine); + } + } +} diff --git a/Server/Services/DataMigration/DataMigrationProgressService.cs b/Server/Services/DataMigration/DataMigrationProgressService.cs new file mode 100644 index 0000000..8660d14 --- /dev/null +++ b/Server/Services/DataMigration/DataMigrationProgressService.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.Utils; +using Server.Utils; +using SqlSugar; + +namespace Server.Services.DataMigration +{ + /// + /// 数据迁移进度监控服务 + /// + public class DataMigrationProgressService + { + private DataMigrationProgressService() + { + } + private static DataMigrationProgressService _migrationService; + private static object lockobj = new object(); + /// + /// 单例的属性 + /// + public static DataMigrationProgressService Instance + { + get + { + if (_migrationService == null) + { + lock (lockobj) + { + if (_migrationService == null) + { + _migrationService = new DataMigrationProgressService(); + } + } + } + return _migrationService; + } + } + /// + /// 迁移进度 + /// + private MigrationProgressState State { get; set; } + /// + /// 开始记录 + /// + public void Start() + { + State = new MigrationProgressState(); + this.State.StartDateTime = DateTime.Now; + this.State.State = 1; + } + /// + /// 停止 + /// + public void Stop() + { + this.State.EndDateTime=DateTime.Now; + this.State.ElapsedTime = (this.State.EndDateTime - this.State.StartDateTime).TotalMinutes; + this.State.State = 2; + } + /// + /// 获取当前迁移进度 + /// + /// + public MigrationProgressState GetState() + { + return this.State; + } + + } + /// + /// 迁移状态 + /// + public class MigrationProgressState + { + /// + /// 开始时间 + /// + public DateTime StartDateTime { get; set; } + /// + /// 结束时间 + /// + public DateTime EndDateTime { get; set; } + /// + /// 总耗时(分钟) + /// + public double ElapsedTime { get; set; } + /// + /// 处理状态 0未开始 1处理中 2完成 + /// + public int State { get; set; } + /// + /// 日志 + /// + public List Logs { get; set; } = new List(); + /// + /// 添加日志 + /// + /// + public void AddLog(string text) + { + if (Logs.Count > 10) + { + Logs.RemoveAt(0); + } + Logs.Add(text); + } + } +} diff --git a/Server/Services/DataMigration/MigrationAutoMapperProfile.cs b/Server/Services/DataMigration/MigrationAutoMapperProfile.cs new file mode 100644 index 0000000..c6ede2b --- /dev/null +++ b/Server/Services/DataMigration/MigrationAutoMapperProfile.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoMapper; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; + +namespace Server.Services.DataMigration +{ + /// + /// 数据迁移配置,实体映射 + /// + public class MigrationAutoMapperProfile : Profile + { + public MigrationAutoMapperProfile() + { + var tbMap = CreateMap(); + tbMap.Ignore(s => s.IsChange); + tbMap.ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + + + + var lianmengMap = CreateMap(); + lianmengMap.ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + lianmengMap.AfterMap((src, dest) => + { + if (dest.Nickname == null) + { + dest.Nickname = ""; + } + if (dest.Username == null) + { + dest.Username = ""; + } + }); + + var robotMap = CreateMap(); + robotMap.Ignore(s => s.IsOnlineRobot); + robotMap.ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + robotMap.AfterMap((src, dest) => + { + if (dest.Nickname == null) + { + dest.Nickname = ""; + } + if (dest.LoginAddress == null) + { + dest.LoginAddress = ""; + } + if (dest.LoginVersion == null) + { + dest.LoginVersion = ""; + } + }); + CreateMap() + .ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + CreateMap() + .Ignore(s => s.IsChange) + .ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + CreateMap() + .Ignore(s => s.IsChange) + .ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + CreateMap() + .Ignore(s => s.IsChange) + .ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + CreateMap() + .Ignore(s => s.IsChange) + .ForAllOtherMembers(s => + { + s.MapFromDynamic(s.DestinationMember.Name); + }); + } + } + + +} diff --git a/Server/Services/DataMigration/Services/GeneralHandleMigrationService.cs b/Server/Services/DataMigration/Services/GeneralHandleMigrationService.cs new file mode 100644 index 0000000..c56abe0 --- /dev/null +++ b/Server/Services/DataMigration/Services/GeneralHandleMigrationService.cs @@ -0,0 +1,558 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Linq.Expressions; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using AutoMapper; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubCountTables; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Class; +using Server.Services.DataMigration.Services.Model; +using SqlSugar; + +namespace Server.Services.DataMigration.Services +{ + /// + /// 通用数据迁移服务 + /// + public class GeneralHandleMigrationService : IDisposable + { + private IMapper Mapper { get; set; } + + public GeneralHandleMigrationService() + { + var config = new MapperConfiguration(cfg => + { + cfg.AddProfile(); + }); + Mapper = config.CreateMapper(); + } + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 打包信息 + /// + public PackInfo PackInfo { get; set; } + /// + /// 数据目录 + /// + public string RootDir { get; set; } + /// + /// 初始化 + /// + public void Initialize() + { + var files = Directory.GetFiles(this.RootDir, "*.db"); + foreach (var file in files) + { + CreateDb(Path.GetFileNameWithoutExtension(file), file); + } + } + + /// + /// 旧数据ID对应我们新的数据Userid + /// + private Dictionary OldCorrespondingNewUserIdDic { get; set; } = new Dictionary(); + /// + /// 旧的数据机器人ID与新系统的机器人ID + /// + private Dictionary OldCorrespondingNewRobotIdDic { get; set; } = new Dictionary(); + /// + /// 旧的数据机器人ID与新系统的机器人ID + /// + private Dictionary OldCorrespondingNewRobotIdByUsernameDic { get; set; } = + new Dictionary(); + /// + /// 机器人信息 + /// + private List Robots { get; set; } + + /// + /// 开始处理 + /// + public void Start(Action progressAction) + { + progressAction?.Invoke("开始导入"); + var startDateTime1 = DateTime.Now; + //这两个必须先导入 + //导入联盟数据 + HandleLianmeng(progressAction); + //导入机器人数据 + HandleRobot(progressAction); + var lianmengs = Client.SingleClient.Db.Queryable().Where(w => true).ToList(); + //HandleOrder("OldMdkTbOrder", progressAction, lianmengs.Where(w => w.LianmengType == LianmengType.淘宝联盟).ToList()); + //处理用户数据 + HandleUser(progressAction); + //用户信息处理完成,才能开始处理订单信息 + progressAction?.Invoke("淘宝订单数据 -- Start"); + HandleOrder("OldMdkTbOrder", progressAction, lianmengs.Where(w => w.LianmengType == LianmengType.淘宝联盟).ToList(), s => s.trade_id, s => s.trade_id, s => s.tk_create_time, s => s.trade_id, "tk_create_time"); + progressAction?.Invoke("淘宝订单数据 -- End"); + //抖音订单数据 + progressAction?.Invoke("抖音订单数据 -- Start"); + HandleOrder("OldMdkDyOrder", progressAction, lianmengs.Where(w => w.LianmengType == LianmengType.抖音联盟).ToList(), s => s.order_id, s => s.order_id, s => s.pay_success_time, s => s.order_id, "pay_success_time"); + progressAction?.Invoke("抖音订单数据 -- End"); + + //京东订单数据 + progressAction?.Invoke("京东订单数据 -- Start"); + HandleOrder("OldMdkJDOrder", progressAction, lianmengs.Where(w => w.LianmengType == LianmengType.京东联盟).ToList(), s => s.UniqueId, s => s.UniqueId, s => s.orderTime, s => s.UniqueId, "orderTime"); + progressAction?.Invoke("京东订单数据 -- End"); + //拼多多订单 + progressAction?.Invoke("拼多多订单 -- Start"); + HandleOrder("OldMdkPDDOrder", progressAction, lianmengs.Where(w => w.LianmengType == LianmengType.拼多多联盟).ToList(), s => s.order_id, s => s.order_id, s => s.order_create_time, s => s.order_id, "order_create_time"); + progressAction?.Invoke("拼多多订单 -- End"); + //苏宁 + progressAction?.Invoke("苏宁订单 -- Start"); + HandleOrder("OldMdkSnOrder", progressAction, lianmengs.Where(w => w.LianmengType == LianmengType.苏宁联盟).ToList(), s => s.orderCode, s => s.orderCode, s => s.payTime, s => s.orderCode, "payTime"); + progressAction?.Invoke("苏宁订单 -- End"); + //唯品会 + progressAction?.Invoke("唯品会订单 -- Start"); + HandleOrder("OldMdkWPHOrder", progressAction, lianmengs.Where(w => w.LianmengType == LianmengType.唯品会联盟).ToList(), s => s.OrderId, s => s.OrderId, s => s.orderTime, s => s.OrderId, "orderTime"); + progressAction?.Invoke("唯品会订单 -- End"); + Console.WriteLine("总时间:" + (DateTime.Now - startDateTime1).TotalSeconds); + } + /// + /// 处理用户数据 + /// + /// + private void HandleUser(Action progressAction) + { + var waitTaskThreadService = new WaitTaskThreadService(); + var size = 500; + //总分页数 + var totalPageCount = Util.GetPageSize(GetDb("data").Queryable().Count(), size); + var queues = new ConcurrentQueue(); + for (int i = 1; i <= totalPageCount; i++) + { + queues.Enqueue(i); + } + var startDateTime1 = DateTime.Now; + for (int i = 0; i < 1; i++) + { + waitTaskThreadService.StartThread(i + "", () => + { + var index = 1; + using (var db = Client.SingleClient.Db) + using (var userdb = GetDb("data")) + { + while (!queues.IsEmpty) + { + if (!queues.TryDequeue(out index)) + { + continue; + } + var startDateTime = DateTime.Now; + var users = userdb.Queryable().ToPageList(index, size); + if (users.Count <= 0) + { + continue; + } + progressAction?.Invoke("写入用户信息 - " + index + "/" + totalPageCount + "页"); + var ids = users.Select(s => s.Id).ToArray(); + db.UseTran(() => + { + foreach (var user in users) + { + var sql = "INSERT INTO User(Username,UserType,RobotId,NickName,Weixinhao,Headurl,IsFriend,RevTime,CreateTime,WxRemark,IsMigration) SELECT @Username,@UserType,@RobotId,@NickName,@Weixinhao,@Headurl,@IsFriend,@RevTime,@CreateTime,@WxRemark,@IsMigration FROM DUAL WHERE NOT EXISTS(SELECT id FROM User WHERE Username=@Username and UserType=@UserType)"; + db.Ado.ExecuteCommand(sql, new + { + Username = user.Username, + UserType = (int)user.UserType, + RobotId = OldCorrespondingNewRobotIdDic.ContainsKey(user.RobotId) ? OldCorrespondingNewRobotIdDic[user.RobotId] : 0, + NickName = user.NickName, + Weixinhao = user.Weixinhao, + Headurl = user.Headurl, + IsFriend = user.IsFriend, + RevTime = user.RevTime, + CreateTime = user.CreateTime, + WxRemark = user.WxRemark, + @IsMigration = user.IsMigration + }); + } + }); + var cusers = db.Queryable().In(w => w.Username, users.Select(s => s.Username).ToArray()) + .Select(s => new + { + Id = s.Id, + Username = s.Username, + UserType = s.UserType + }).ToList(); + var userdb2 = GetDb("data"); + var userdatas = userdb2.Queryable().In(w => w.UserId, ids).ToList(); + foreach (var user in users) + { + var cuser = cusers.FirstOrDefault(w => w.Username == user.Username && w.UserType == user.UserType); + if (cuser != null) + { + //记录对应数据 + OldCorrespondingNewUserIdDic[user.Id] = cuser.Id; + var userdata = userdatas.FirstOrDefault(w => w.UserId == user.Id); + if (userdata != null) + { + //我们自己数据库的用户ID + userdata.UserId = cuser.Id; + if (userdata.RecommendId > 0) + { + var recommendUser = userdb2.Queryable().Where(w => w.Id == userdata.RecommendId).First(); + if (recommendUser != null) + { + recommendUser.Id = 0; + var crecommendUser = db.Queryable().Where(w => + w.Username == recommendUser.Username && + w.UserType == recommendUser.UserType) + .Select(s => new + { + s.Id, + s.Username, + s.UserType + }).First(); + if (crecommendUser == null) + { + db.Insertable(recommendUser).ExecuteReturnEntity(); + } + else + { + recommendUser.Id = crecommendUser.Id; + } + userdata.RecommendId = recommendUser.Id; + } + } + } + } + } + var userids = userdatas.Select(s => s.UserId).ToArray(); + var cuserdatas = db.Queryable().SplitTableById(userdatas.Max(s => s.UserId)).In(s => s.UserId, userids).ToList(); + //插入userdatas + db.UseTran(() => + { + foreach (var userdata in userdatas) + { + var cuserData = cuserdatas.FirstOrDefault(w => w.UserId == userdata.UserId); + if (cuserData == null) + { + //userdata.Id = SnowFlakeSingle.instance.getID(); + userdata.Id = Util.CreateID(userdata.CreateTime); + db.Insertable(userdata).SplitTable().ExecuteCommand(); + } + else + { + cuserData.InvalidOrderAmount += userdata.InvalidOrderAmount; + cuserData.InvalidOrderCount += userdata.InvalidOrderCount; + cuserData.FinishOrderAmount += userdata.FinishOrderAmount; + cuserData.FinishOrderCount += userdata.FinishOrderCount; + cuserData.AllRecommendCount += userdata.AllRecommendCount; + cuserData.TixianAmount += userdata.TixianAmount; + cuserData.TixianCount += userdata.TixianCount; + cuserData.QueryCount += userdata.QueryCount; + cuserData.EstimateRebate += userdata.EstimateRebate; + cuserData.RefundOrderCount += userdata.RefundOrderCount; + cuserData.RecommendCount += userdata.RecommendCount; + cuserData.RecommendAward += userdata.RecommendAward; + cuserData.TaobaoLastid = userdata.TaobaoLastid; + cuserData.CreateTime = userdata.CreateTime; + cuserData.LastBuyTime = userdata.LastBuyTime; + var tableName = db.GetTableName(userdata.UserId); + db.Updateable(cuserData).SplitTable(t => t.InTableNames(tableName)).ExecuteCommand(); + } + } + }); + index++; + //Console.WriteLine("时间:" + (DateTime.Now - startDateTime).TotalSeconds); + } + } + }); + } + waitTaskThreadService.WaitAll(); + // Console.WriteLine("用户数据总时间:" + (DateTime.Now - startDateTime1).TotalSeconds); + } + + /// + /// 导入机器人数据 + /// + /// + private void HandleRobot(Action progressAction) + { + progressAction?.Invoke("机器人数据 -- 开始"); + using (var userdb = GetDb("data")) + { + var dyns = userdb.Queryable().AS("Robot").ToArray(); + if (dyns.Length <= 0) + { + return; + } + var items = Mapper.Map>(dyns); ; + var db = Client.SingleClient.Db; + db.UseTran(() => + { + foreach (var item in items) + { + if (!db.Queryable() + .Where(w => w.Username == item.Username && w.UserType == item.UserType).Any()) + { + var id = item.Id; + db.Insertable(item).ExecuteCommand(); + item.Id = id; + } + } + }); + this.Robots = Client.SingleClient.Db.Queryable().Where(w => true).ToList(); + foreach (var item in items) + { + var robotInfo = this.Robots.FirstOrDefault(w => w.Username == item.Username && w.UserType == item.UserType); + if (robotInfo != null) + { + OldCorrespondingNewRobotIdDic[item.Id] = robotInfo.Id; + OldCorrespondingNewRobotIdByUsernameDic[item.Username + item.UserType] = robotInfo.Id; + } + } + } + progressAction?.Invoke("机器人数据 -- 完成"); + } + /// + /// 导入联盟数据 + /// + /// + private void HandleLianmeng(Action progressAction) + { + progressAction?.Invoke("联盟数据 -- Start"); + using (var userdb = GetDb("data")) + { + var dyns = userdb.Queryable().AS("Lianmeng").ToArray(); + if (dyns.Length <= 0) + { + return; + } + var items = Mapper.Map>(dyns); + var db = Client.SingleClient.Db; + db.UseTran(() => + { + foreach (var lianmeng in items) + { + if (!db.Queryable() + .Where(w => w.Username == lianmeng.Username && w.LianmengType == lianmeng.LianmengType).Any()) + { + db.Insertable(lianmeng).ExecuteCommand(); + } + } + }); + } + progressAction?.Invoke("联盟数据 -- end"); + } + /// + /// 处理订单 + /// + /// + /// + private void HandleOrder(string tableName, Action progressAction, List lianmengs, Expression> selectOrderExpression, Func filtrationRepeat, Func selecttableTimeFunc, Func selectVerifyExpression, string fieldOrderTime) where T : class, new() + { + + + var startDateTime1 = DateTime.Now; + var orderids = Client.SingleClient.Db.Queryable().SplitTable(tabs => tabs).Select(selectOrderExpression).ToArray(); + var orderDic = new Dictionary(); + foreach (var item in orderids) + { + orderDic[item] = 0; + } + var orderDbs = new Dictionary(); + for (int i = 0; i < 100; i++) + { + var orderDb = GetDb(tableName + "-" + i); + if (orderDb == null) + { + break; + } + orderDbs[tableName + "-" + i] = orderDb; + } + //选择最小最大时间 + var minTime = DateTime.MinValue; + var maxTime = DateTime.MinValue; + foreach (var itemdb in orderDbs) + { + var oldMinTime = itemdb.Value.Queryable().AS(tableName).Min(fieldOrderTime); + if (oldMinTime != DateTime.MinValue) + { + if (oldMinTime < minTime || minTime == DateTime.MinValue) + { + minTime = oldMinTime; + } + } + var maxMinTime = itemdb.Value.Queryable().AS(tableName).Max(fieldOrderTime); + if (maxMinTime > maxTime || maxTime == DateTime.MinValue) + { + maxTime = maxMinTime; + } + } + minTime = Convert.ToDateTime(minTime.ToString("yyyy-MM-01")); + //生成表名 + var tableNames = new List(); + var entityInfo = Client.SingleClient.Db.EntityMaintenance.GetEntityInfo(); + while (true) + { + tableNames.Add(entityInfo.EntityName + "_" + minTime.ToString("yyyyMMdd")); + minTime = minTime.AddMonths(1); + if (minTime > maxTime) + { + break; + } + } + progressAction?.Invoke("生成数据库表"); + //生成数据库表 + using (var db = Client.SingleClient.Db) + { + db.UseTran(() => + { + foreach (var table in tableNames) + { + db.MappingTables.Add(entityInfo.EntityName, table); + db.Context.CodeFirst.InitTables(typeof(T)); + db.Context.MappingTables.Add(entityInfo.EntityName, entityInfo.DbTableName);//还原 + } + }); + } + var waitTaskThreadService = new WaitTaskThreadService(); + foreach (var itemdb in orderDbs) + { + waitTaskThreadService.StartThread(itemdb.Key, (orderDb) => + { + var index = 1; + var size = 5000; + while (true) + { + var startDateTime = DateTime.Now; + var oldbOrders = orderDb.Value.Queryable().AS(tableName).ToPageList(index, size); + if (oldbOrders.Count <= 0) + { + break; + } + oldbOrders.ForEach(item => + { + var lianmeng = lianmengs.FirstOrDefault(w => w.Username == item.LianmengName); + if (lianmeng != null) + { + item.LianmengId = lianmeng.Id; + } + if (item.UserId > 0) + { + var olduserid = Convert.ToInt32(item.UserId); + if (OldCorrespondingNewUserIdDic.ContainsKey(olduserid)) + { + item.UserId = OldCorrespondingNewUserIdDic[olduserid]; + } + } + if (!string.IsNullOrWhiteSpace(item.RobotName)) + { + string usernameandtype = item.RobotName + item.RobotType; + if (OldCorrespondingNewRobotIdByUsernameDic.ContainsKey(usernameandtype)) + { + item.RobotId = OldCorrespondingNewRobotIdByUsernameDic[usernameandtype]; + } + else + { + item.RobotId = 0; + } + } + }); + var orderdatas = Mapper.Map>(oldbOrders); + orderdatas.RemoveAll(w => orderDic.ContainsKey(filtrationRepeat(w))); + if (orderdatas.Count > 0) + { + using (var db = Client.SingleClient.Db) + { + var dic = new Dictionary(); + var ps = typeof(T).GetProperties(); + foreach (var p in ps) + { + dic[p.Name] = p; + } + string[] pnames = dic.Select(s => s.Key).ToArray(); + db.UseTran(() => + { + var sugarParameters = new SugarParameter[pnames.Length]; + foreach (var orderdata in orderdatas) + { + orderDic[selectVerifyExpression(orderdata)] = 0; + var selecttableName = entityInfo.EntityName + "_" + selecttableTimeFunc(orderdata).ToString("yyyyMM") + "01"; + var sql = $"INSERT ignore INTO {selecttableName} ({string.Join(",", pnames)}) values ({string.Join(",", pnames.Select(s => "@" + s))})"; + for (int i = 0; i < pnames.Length; i++) + { + sugarParameters[i] = new SugarParameter(pnames[i], dic[pnames[i]].GetValue(orderdata)); + } + db.Ado.ExecuteCommand(sql, sugarParameters); + } + }); + //Console.WriteLine(orderDb.Key + "-" + index + " => " + "插入数量:" + orderdatas.Count + "|" + (DateTime.Now - startDateTime).TotalSeconds); + progressAction?.Invoke(typeof(T).Name + "写入数据 - "+ orderdatas.Count+"条"); + + } + //db.Fastest().SplitTable().BulkCopy(orderdatas); + } + //orderids.AddRange(orderdatas.Select(s=>s.trade_id)); + //db.Fastest().SplitTable().BulkCopy(orderdatas); + index++; + } + }, itemdb); + } + //等待全部线程完成 + waitTaskThreadService.WaitAll(); + //Console.WriteLine(typeof(T).Name + "订单统计总耗时:" + (DateTime.Now - startDateTime1).TotalSeconds); + } + /// + /// 数据库 + /// + private Dictionary> DbDic = new Dictionary>(); + /// + /// 创建数据库 + /// + /// + /// + private void CreateDb(string filename, string path) + { + DbDic[filename] = () => + { + var db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = @"DataSource=" + path + @";Version=3;",//连接符字串 + DbType = SqlSugar.DbType.Sqlite, //数据库类型 + IsAutoCloseConnection = true, + }); + db.Aop.OnLogExecuted = (sql, prars) => + { + var temp = sql; + foreach (var item in prars) temp = temp.Replace(item.ParameterName, $"'{item.Value}'"); + var time = db.Ado.SqlExecutionTime; + // Console.WriteLine($"其他库SQL耗时:{time.TotalSeconds}、SQL => {temp.Substring(0, 10)}"); + }; + return db; + }; + } + /// + /// 获取BD + /// + /// + /// + public SqlSugarClient GetDb(string tablename) + { + if (DbDic.ContainsKey(tablename)) + { + return DbDic[tablename](); + } + return null; + } + + public void Dispose() + { + OldCorrespondingNewUserIdDic.Clear(); + } + } +} diff --git a/Server/Services/DataMigration/Services/Model/OldMdkTbOrder.cs b/Server/Services/DataMigration/Services/Model/OldMdkTbOrder.cs new file mode 100644 index 0000000..9ef0e38 --- /dev/null +++ b/Server/Services/DataMigration/Services/Model/OldMdkTbOrder.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.Models.Enums; +using Common.Models.SubTables; +using SqlSugar; + +namespace Server.Services.DataMigration.Services.Model +{ + public class OldMdkTbOrder : TbOrder + { + /// + /// 联盟账号 + /// + public string LianmengName { get; set; } + /// + /// 机器人账号 + /// + public string RobotName { get; set; } + /// + /// 机器人类型 + /// + public UserType RobotType { get; set; } + } +} diff --git a/Server/Services/DataMigration/Services/OldMDK/OldMDKMigrationService.cs b/Server/Services/DataMigration/Services/OldMDK/OldMDKMigrationService.cs new file mode 100644 index 0000000..5ee1f25 --- /dev/null +++ b/Server/Services/DataMigration/Services/OldMDK/OldMDKMigrationService.cs @@ -0,0 +1,375 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubCountTables; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Class; +using SqlSugar; + +namespace Server.Services.DataMigration.Services.OldMDK +{ + /// + /// 老的秒单客数据迁移服务V1 + /// + public class OldMDKMigrationService + { + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 打包信息 + /// + public PackInfo PackInfo { get; set; } + /// + /// 数据目录 + /// + public string RootDir { get; set; } + /// + /// 初始化 + /// + public void Initialize() + { + var files = Directory.GetFiles(this.RootDir, "*.db"); + foreach (var file in files) + { + CreateDb(Path.GetFileNameWithoutExtension(file), file); + } + } + /// + /// 开始处理 + /// + public void Start(Action progressAction) + { + var index = Client.SingleClient.Db.GetMapValue("数据迁移页数位置", () => 1); + // var index = 1; + var total = 0; + var size = 5; + while (true) + { + var memberinfos = GetDb("fl_member_info").Queryable().AS("fl_member_info").ToPageList(index, size, ref total); + if (memberinfos.Count <= 0) + { + //数据导入完成 + break; + } + + var startDateTime = DateTime.Now; + var tasks = new List(); + foreach (var item in memberinfos) + { + var task = Task.Run(() => + { + using (var db = Client.SingleClient.Db) + { + HandleUser(db, item, progressAction); + } + }); + tasks.Add(task); + } + Task.WaitAll(tasks.ToArray()); + Console.WriteLine("---------------------" + (DateTime.Now - startDateTime).TotalSeconds); + index++; + //var ids = memberinfos.Select(s => Convert.ToInt32(s.id)).ToArray(); + //var removeCount = 0; + //foreach (var tabname in tabnames) + //{ + // removeCount = GetDb(tabname).Deleteable().AS(tabname).Where("db_userid in (@db_userid)", new {db_userid= ids }).ExecuteCommand(); + // //Console.WriteLine("删除了:" + removeCount); + //} + //removeCount = GetDb("fl_point_hist").Deleteable().AS("fl_point_hist").Where("uid in (@id)", new { id = ids }).ExecuteCommand(); + //Console.WriteLine("删除了:" + removeCount); + Client.SingleClient.Db.SetMapValue("数据迁移页数位置", index); + } + } + + private static object lockobj = new object(); + /// + /// 处理User + /// + /// + /// + /// + private void HandleUser(SqlSugarClient db, dynamic useritem, Action progressAction) + { + + var startDateTime = DateTime.Now; + + string username = useritem.username; + UserType userType = GetUserType(Convert.ToInt32(useritem.robot_type)); + var user = db.Queryable().Where(w => w.Username == username && w.UserType == userType).First(); + if (user == null) + { + //账户不存在 + user = new User() + { + Username = useritem.username, + NickName = useritem.usernick, + Weixinhao = useritem.username, + Headurl = "", + IsFriend = false, + RevTime = useritem.upd_time, + CreateTime = useritem.crt_time, + WxRemark = useritem.remark, + UserType = userType, + }; + } + else + { + if (user.IsMigration) + { + return; + } + } + user.IsMigration = true; + if (user.Id == 0) + { + db.Insertable(user).ExecuteReturnEntity(); + } + else + { + db.Updateable(user).ExecuteCommand(); + } + var userdata = db.GetUserData(user.Id); + if (userdata == null) + { + userdata = new UserData() + { + UserId = user.Id, + }; + } + if (true) + { + //失效订单金额 + foreach (var tabname in tabnames) + { + //失效订单金额 + userdata.InvalidOrderAmount += Convert.ToInt32(GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }).Sum("db_userpoint")); + } + foreach (var tabname in tabnames) + { + //失效订单总数 + userdata.InvalidOrderCount += Convert.ToInt32(GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }).Select("count(id)").Count()); + } + foreach (var tabname in tabnames) + { + //完成订单金额 + userdata.FinishOrderAmount += Convert.ToInt32(GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }).Sum("db_userpoint")); + } + foreach (var tabname in tabnames) + { + //完成订单数量 + userdata.FinishOrderCount += GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }).Select("count(id)").Count(); + } + } + else + { + foreach (var tabname in tabnames) + { + //失效订单金额 + var tbdb = GetDb(tabname); + tbdb.AddQueue($"select sum(db_userpoint) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }); + tbdb.AddQueue($"select count(id) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }); + tbdb.AddQueue($"select sum(db_userpoint) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }); + tbdb.AddQueue($"select count(id) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }); + var resutl = tbdb.SaveQueues(); + Console.WriteLine(); + //if (resutl.Item!= null&&resutl.Item1.Count > 0) + //{ + // userdata.InvalidOrderAmount += resutl.Item1.FirstOrDefault(); + //} + //if (resutl.Item2!=null&&resutl.Item2.Count > 0) + //{ + // userdata.InvalidOrderCount += resutl.Item2.FirstOrDefault(); + //} + //if (resutl.Item3 != null && resutl.Item3.Count > 0) + //{ + // userdata.FinishOrderAmount += resutl.Item3.FirstOrDefault(); + //} + //if (resutl.Item4 != null && resutl.Item4.Count > 0) + //{ + // userdata.FinishOrderCount += resutl.Item4.FirstOrDefault(); + //} + } + } + userdata.AllRecommendCount = GetDb("fl_member_info").Queryable("fl_member_info", "") + .Where("inviter_id=@inviter_id", new { inviter_id = useritem.id }).Select("count(id)").Count(); + //累计提现现金,并且取正数 + userdata.TixianAmount = -GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where("uid=@id and type=@type", new { @type = "提现扣除", id = useritem.id }).Sum("point"); + //累计提现次数 + userdata.TixianCount = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where("uid=@id and type=@type", new { @type = "提现扣除", id = useritem.id }).Select("count(id)").Count(); + //用户的绑定数,玩家不会看这个 + userdata.QueryCount = Convert.ToInt32(useritem.bind_order); + //问老妖 + //userdata.EstimateCoupon = 0; + //按照累计提现金额 + userdata.EstimateRebate = userdata.TixianAmount; + //用户的绑定数,玩家不会看这个 + userdata.PayOrderCount = Convert.ToInt32(useritem.bind_order); + //维权扣除 + userdata.RefundOrderCount = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where(" uid=@id and type=@type", new { @type = "维权扣除", id = useritem.id }).Select("count(id)").Count(); + //累计有效邀请奖励(奖励都会叠加,并不是实时数据) + userdata.RecommendCount = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where(" uid=@id and type=@type", new { @type = "提成奖励", id = useritem.id }).Select("count(id)").Count(); + //累计有效邀请奖励(奖励都会叠加,并不是实时数据) + userdata.RecommendAward = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where("uid=@id and type=@type", new { @type = "提成奖励", id = useritem.id }).Sum("point"); + dynamic fl_alimama_order_lastnum = GetDb("fl_alimama_order_lastnum").Queryable("fl_alimama_order_lastnum", "").Where("userid=@userid", new { userid = useritem.id }).First(); + //淘宝后六位 + userdata.TaobaoLastid = fl_alimama_order_lastnum?.lastnumber; + //创建时间 + userdata.CreateTime = useritem.crt_time; + //最后购买时间 + var fl_statistics_recordItem = GetDb("fl_statistics_record").Queryable().AS("fl_statistics_record") + .Where("uid=@uid", new { uid = useritem.id }).First(); + if (fl_statistics_recordItem == null || fl_statistics_recordItem.ex5 <= 0) + { + userdata.LastBuyTime = DateTime.MinValue; + } + else + { + userdata.LastBuyTime = Util.TimespanToDatatime(fl_statistics_recordItem.ex5.ToString()); + } + var recommendUserInfo = GetDb("fl_member_info").Queryable().AS("fl_member_info") + .Where("id=@id", new { id = useritem.inviter_id }).First(); + if (recommendUserInfo != null) + { + lock (lockobj) + { + string recommendusername = recommendUserInfo.username; + UserType recommenduserType = GetUserType(Convert.ToInt32(recommendUserInfo.robot_type)); + var recommendUser = db.Queryable().Where(w => w.Username == recommendusername && w.UserType == recommenduserType).First(); + if (recommendUser == null) + { + recommendUser = new User() + { + Username = recommendUserInfo.username, + NickName = recommendUserInfo.usernick, + Weixinhao = recommendUserInfo.username, + Headurl = "", + IsFriend = false, + RevTime = recommendUserInfo.upd_time, + CreateTime = recommendUserInfo.crt_time, + WxRemark = recommendUserInfo.remark, + UserType = recommenduserType, + IsMigration = false + }; + db.Insertable(recommendUser).ExecuteReturnEntity(); + } + userdata.RecommendId = recommendUser.Id; + } + } + userdata.FinishOrderCount = Convert.ToInt32(useritem.finish_order); + userdata.CurPoint = Convert.ToInt32(useritem.cur_point); + userdata.UserStatus = GetUserStatus(Convert.ToInt32(useritem.status)); + userdata.FirstAdd = true; + userdata.FirstQuery = true; + userdata.FirstPay = true; + userdata.FirstReceive = true; + userdata.ReminderQuery = true; + userdata.ReminderOrder = true; + userdata.T1InvitePeople = true; + userdata.T2InvitePeople = true; + userdata.T3InvitePeople = true; + userdata.T4InvitePeople = true; + userdata.IsFristPayHourWithin = false; + userdata.IsFirstTiXian = userdata.TixianAmount > 0; + //------------------ + if (userdata.Id <= 0) + { + db.Insertable(userdata).SplitTable().ExecuteCommand(); + } + else + { + var tableName = db.GetTableName(user.Id); + db.Updateable(userdata).SplitTable(t => t.InTableNames(tableName)).ExecuteCommand(); + } + + + + Console.WriteLine(useritem.id + " - " + (DateTime.Now - startDateTime).TotalSeconds); + } + /// + /// 订单表名 + /// + private static string[] tabnames = new string[] { "fl_order_alimama", "fl_order_douyin", "fl_order_jingdong", "fl_order_pinduoduo", "fl_order_suning", "fl_order_weipinhui" }; + /// + /// 获取用户状态 + /// + /// + /// + private UserStatus GetUserStatus(int status) + { + switch (status) + { + case 1: return UserStatus.黑名单; + case 2: return UserStatus.白名单; + } + return UserStatus.正常; + } + /// + /// 获取用户类型 + /// + /// + /// + private UserType GetUserType(int robotType) + { + switch (robotType) + { + case 2: return UserType.微信用户; + case 1: return UserType.QQ用户; + case 0: return UserType.未知; + case 3: return UserType.公众号微信; + case 4: return UserType.企业微信; + } + return UserType.未知; + } + /// + /// 数据库 + /// + private Dictionary> DbDic = new Dictionary>(); + /// + /// 创建数据库 + /// + /// + /// + private void CreateDb(string filename, string path) + { + DbDic[filename] = () => + { + var db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = @"DataSource=" + path + @";Version=3;",//连接符字串 + DbType = SqlSugar.DbType.Sqlite, //数据库类型 + IsAutoCloseConnection = true, + }); + db.Aop.OnLogExecuted = (sql, prars) => + { + var temp = sql; + foreach (var item in prars) temp = temp.Replace(item.ParameterName, $"'{item.Value}'"); + var time = db.Ado.SqlExecutionTime; + //Console.WriteLine($"其他库SQL耗时:{time.TotalSeconds}、SQL => {temp}"); + }; + return db; + }; + } + /// + /// 获取BD + /// + /// + /// + public SqlSugarClient GetDb(string tablename) + { + if (DbDic.ContainsKey(tablename)) + { + return DbDic[tablename](); + } + return null; + } + } +} \ No newline at end of file diff --git a/Server/Services/DataMigration/Services/OldMDK/OldMDKMigrationServiceV2.cs b/Server/Services/DataMigration/Services/OldMDK/OldMDKMigrationServiceV2.cs new file mode 100644 index 0000000..67c5c12 --- /dev/null +++ b/Server/Services/DataMigration/Services/OldMDK/OldMDKMigrationServiceV2.cs @@ -0,0 +1,850 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubCountTables; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Class; +using SqlSugar; + +namespace Server.Services.DataMigration.Services.OldMDK +{ + /// + /// 老的秒单客数据迁移服务V1 + /// + public class OldMDKMigrationServiceV2 + { + /// + /// 名称 + /// + public string Name { get; set; } + /// + /// 打包信息 + /// + public PackInfo PackInfo { get; set; } + /// + /// 数据目录 + /// + public string RootDir { get; set; } + /// + /// 初始化 + /// + public void Initialize() + { + var files = Directory.GetFiles(this.RootDir, "*.db"); + foreach (var file in files) + { + CreateDb(Path.GetFileNameWithoutExtension(file), file); + } + } + /// + /// 开始处理 + /// + public void Start(Action progressAction) + { + //var index = Client.SingleClient.Db.GetMapValue("数据迁移页数位置", () => 1); + var index = 1; + var total = 0; + var size = 500;//这个值不能改变 + while (true) + { + var memberinfos = GetDb("fl_member_info").Queryable().AS("fl_member_info").ToPageList(index, size, ref total); + if (memberinfos.Count <= 0) + { + //数据导入完成 + break; + } + var startDateTime = DateTime.Now; + using (var db = Client.SingleClient.Db) + { + HandleUser(db, memberinfos, progressAction); + } + Console.WriteLine("---------------------" + (DateTime.Now - startDateTime).TotalSeconds); + index++; + return; + //var ids = memberinfos.Select(s => Convert.ToInt32(s.id)).ToArray(); + //var removeCount = 0; + //foreach (var tabname in tabnames) + //{ + // removeCount = GetDb(tabname).Deleteable().AS(tabname).Where("db_userid in (@db_userid)", new {db_userid= ids }).ExecuteCommand(); + // //Console.WriteLine("删除了:" + removeCount); + //} + //removeCount = GetDb("fl_point_hist").Deleteable().AS("fl_point_hist").Where("uid in (@id)", new { id = ids }).ExecuteCommand(); + //Console.WriteLine("删除了:" + removeCount); + Client.SingleClient.Db.SetMapValue("数据迁移页数位置", index); + } + } + + private static object lockobj = new object(); + + /// + /// 处理User + /// + /// + /// + /// + private void HandleUser(SqlSugarClient db, List useritems, Action progressAction) + { + var startDateTime = DateTime.Now; + List newUseritems = new List(); + var existUsers = new List(); + foreach (var useritem in useritems) + { + string username = useritem.username; + UserType userType = GetUserType(Convert.ToInt32(useritem.robot_type)); + var user = db.Queryable().Where(w => w.Username == username && w.UserType == userType).First(); + if (user != null) + { + //表示这个用户已经导入过 + if (user.IsMigration) + { + continue; + } + existUsers.Add(user); + } + newUseritems.Add(useritem); + } + if (newUseritems.Count <= 0) + { + return; + } + //插入user + var users = new List(); + foreach (var useritem in newUseritems) + { + string username = useritem.username; + UserType userType = GetUserType(Convert.ToInt32(useritem.robot_type)); + if (existUsers.Any(w => w.Username == username && w.UserType == userType)) + { + continue; + } + var user = new User() + { + Username = username, + NickName = useritem.usernick, + Weixinhao = username, + Headurl = "", + IsFriend = false, + RevTime = useritem.upd_time, + CreateTime = useritem.crt_time, + WxRemark = useritem.remark, + UserType = userType, + }; + users.Add(user); + } + //新增 + if (users.Count > 0) + { + db.Insertable(users).ExecuteReturnEntity(); + } + if (existUsers.Count > 0) + { + //更新 + db.Updateable(existUsers).ExecuteCommand(); + } + //合并 + users.AddRange(existUsers); + var userdatas = new List(); + foreach (var user in users) + { + var userdata = db.GetUserData(user.Id); + if (userdata == null) + { + userdata = new UserData() + { + UserId = user.Id + }; + } + userdatas.Add(userdata); + } + //开始分析数据 + StringBuilder sqlsb = new StringBuilder(); + //失效订单金额 + foreach (var tabname in tabnames) + { + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select sum(db_userpoint) from {tabname} where db_userid={memberinfo.id} and db_status=1004"); + sqlsb.AppendLine("union all"); + } + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + using (var orderdb = GetDb(tabname)) + { + var table = orderdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.InvalidOrderAmount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + } + //失效订单总数 + foreach (var tabname in tabnames) + { + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select count(*) from {tabname} where db_userid={memberinfo.id} and db_status=1004"); + sqlsb.AppendLine("union all"); + } + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + using (var orderdb = GetDb(tabname)) + { + var table = orderdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.InvalidOrderCount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + } + //完成订单金额 + foreach (var tabname in tabnames) + { + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select sum(db_userpoint) from {tabname} where db_userid={memberinfo.id} and db_status=1002"); + sqlsb.AppendLine("union all"); + } + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + using (var orderdb = GetDb(tabname)) + { + var table = orderdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.FinishOrderAmount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + } + //完成订单数量 + foreach (var tabname in tabnames) + { + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select count(*) from {tabname} where db_userid={memberinfo.id} and db_status=1002"); + sqlsb.AppendLine("union all"); + } + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + using (var orderdb = GetDb(tabname)) + { + var table = orderdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.FinishOrderCount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + } + //累计邀请统计数据 + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select count(*) from fl_member_info where inviter_id={memberinfo.id}"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_member_info")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.AllRecommendCount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + //累计提现现金,并且取正数 + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select sum(point) from fl_point_hist where uid={memberinfo.id} and type='提现扣除'"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_point_hist")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.TixianAmount += -Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + //累计提现次数 + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select count(*) from fl_point_hist where uid={memberinfo.id} and type='提现扣除'"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_point_hist")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.TixianCount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + //用户的绑定数,玩家不会看这个 + for (int i = 0; i < newUseritems.Count; i++) + { + var callback = new Action((userdata, val) => + { + userdata.QueryCount += Convert.ToInt32(val); + //按照累计提现金额 + userdata.EstimateRebate = userdata.TixianAmount; + }); + SetUserDataValue(users, userdatas, newUseritems[i], newUseritems[i].bind_order, callback); + } + //维权扣除 + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select count(*) from fl_point_hist where uid={memberinfo.id} and type='维权扣除'"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_point_hist")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.RefundOrderCount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + //累计有效邀请奖励(奖励都会叠加,并不是实时数据) + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select count(*) from fl_point_hist where uid={memberinfo.id} and type='提成奖励'"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_point_hist")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.RecommendCount += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + //累计有效邀请奖励(奖励都会叠加,并不是实时数据) + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select sum(point) from fl_point_hist where uid={memberinfo.id} and type='提成奖励'"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_point_hist")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + var callback = new Action((userdata, val) => + { + userdata.RecommendAward += Convert.ToInt32(val); + }); + for (int i = 0; i < newUseritems.Count; i++) + { + SetUserDataValue(users, userdatas, newUseritems[i], table.Rows[i][0], callback); + } + } + //淘宝后六位 + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select userid,lastnumber from fl_alimama_order_lastnum where userid={memberinfo.id}"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_alimama_order_lastnum")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + if (table.Rows.Count > 0) + { + var callback = new Action((userdata, val) => + { + userdata.TaobaoLastid = val.ToString(); + }); + for (int i = 0; i < table.Rows.Count; i++) + { + var userid = Convert.ToInt64(table.Rows[i][0]); + var lastnumber = table.Rows[i][1].ToString(); + var newUseritem = newUseritems.FirstOrDefault(w => w.id == userid); + if (newUseritem != null) + { + SetUserDataValue(users, userdatas, newUseritem, lastnumber, callback); + } + } + } + } + //创建时间 + for (int i = 0; i < newUseritems.Count; i++) + { + var callback = new Action((userdata, val) => + { + userdata.CreateTime = Convert.ToDateTime(val); + + }); + SetUserDataValue(users, userdatas, newUseritems[i], newUseritems[i].crt_time, callback); + } + //邀请人编号 + using (var localdb = GetDb("fl_member_info")) + { + var ids = newUseritems.Where(w => w.inviter_id > 0).Select(s => s.inviter_id).ToArray(); + var recommendUserInfos = localdb.Queryable().AS("fl_member_info").Where("id in (@id)", new { id = ids }).ToList(); + foreach (dynamic recommendUserInfo in recommendUserInfos) + { + if (recommendUserInfo != null) + { + lock (lockobj) + { + string recommendusername = recommendUserInfo.username; + UserType recommenduserType = GetUserType(Convert.ToInt32(recommendUserInfo.robot_type)); + var recommendUser = db.Queryable().Where(w => w.Username == recommendusername && w.UserType == recommenduserType).First(); + if (recommendUser == null) + { + recommendUser = new User() + { + Username = recommendUserInfo.username, + NickName = recommendUserInfo.usernick, + Weixinhao = recommendUserInfo.username, + Headurl = "", + IsFriend = false, + RevTime = recommendUserInfo.upd_time, + CreateTime = recommendUserInfo.crt_time, + WxRemark = recommendUserInfo.remark, + UserType = recommenduserType, + IsMigration = false + }; + db.Insertable(recommendUser).ExecuteReturnEntity(); + } + var user = users.FirstOrDefault(w => w.Username == recommendusername && w.UserType == recommenduserType); + if (user != null) + { + var userdata = userdatas.FirstOrDefault(w => w.UserId == user.Id); + if (userdata != null) + { + userdata.RecommendId = recommendUser.Id; + } + } + } + } + } + } + //最后购买时间 + sqlsb.Clear(); + foreach (var memberinfo in newUseritems) + { + sqlsb.AppendLine($"select uid,ex5 from fl_statistics_record where uid={memberinfo.id}"); + sqlsb.AppendLine("union all"); + } + using (var localdb = GetDb("fl_statistics_record")) + { + string sql = sqlsb.ToString(); + sql = sql.Remove(sql.Length - 11); + var table = localdb.Ado.GetDataTable(sql); + if (table.Rows.Count > 0) + { + var callback = new Action((userdata, val) => + { + userdata.LastBuyTime = Util.TimespanToDatatime(val.ToString()); + }); + for (int i = 0; i < table.Rows.Count; i++) + { + var userid = Convert.ToInt64(table.Rows[i][0]); + var val = table.Rows[i][1].ToString(); + var newUseritem = newUseritems.FirstOrDefault(w => w.id == userid); + if (newUseritem != null) + { + SetUserDataValue(users, userdatas, newUseritem, val, callback); + } + } + } + } + //统一初始化 + for (int i = 0; i < newUseritems.Count; i++) + { + var callback = new Action((userdata, val) => + { + dynamic useritemv = val; + userdata.FinishOrderCount = Convert.ToInt32(useritemv.finish_order); + userdata.CurPoint = Convert.ToInt32(useritemv.cur_point); + userdata.UserStatus = GetUserStatus(Convert.ToInt32(useritemv.status)); + userdata.FirstAdd = true; + userdata.FirstQuery = true; + userdata.FirstPay = true; + userdata.FirstReceive = true; + userdata.ReminderQuery = true; + userdata.ReminderOrder = true; + userdata.T1InvitePeople = true; + userdata.T2InvitePeople = true; + userdata.T3InvitePeople = true; + userdata.T4InvitePeople = true; + userdata.IsFristPayHourWithin = false; + userdata.IsFirstTiXian = userdata.TixianAmount > 0; + }); + SetUserDataValue(users, userdatas, newUseritems[i], newUseritems[i], callback); + } + + Console.WriteLine(newUseritems.Count + " - " + (DateTime.Now - startDateTime).TotalSeconds); + } + + /// + /// 设置userdata的值 + /// + /// + /// + /// + /// + /// + private void SetUserDataValue(List users, List userdatas, dynamic useritem1, object value, Action callback) + { + if (value != null && !(value is DBNull)) + { + string username = useritem1.username; + UserType userType = GetUserType(Convert.ToInt32(useritem1.robot_type)); + var user = users.FirstOrDefault(w => w.Username == username && w.UserType == userType); + if (user != null) + { + var userdata = userdatas.FirstOrDefault(w => w.UserId == user.Id); + if (userdata != null) + { + callback?.Invoke(userdata, value); + } + } + } + } + /// + /// 处理User + /// + /// + /// + /// + private void HandleUser(SqlSugarClient db, dynamic useritem, Action progressAction) + { + + var startDateTime = DateTime.Now; + + string username = useritem.username; + UserType userType = GetUserType(Convert.ToInt32(useritem.robot_type)); + var user = db.Queryable().Where(w => w.Username == username && w.UserType == userType).First(); + if (user == null) + { + //账户不存在 + user = new User() + { + Username = useritem.username, + NickName = useritem.usernick, + Weixinhao = useritem.username, + Headurl = "", + IsFriend = false, + RevTime = useritem.upd_time, + CreateTime = useritem.crt_time, + WxRemark = useritem.remark, + UserType = userType, + }; + } + else + { + if (user.IsMigration) + { + return; + } + } + user.IsMigration = true; + if (user.Id == 0) + { + db.Insertable(user).ExecuteReturnEntity(); + } + else + { + db.Updateable(user).ExecuteCommand(); + } + var userdata = db.GetUserData(user.Id); + if (userdata == null) + { + userdata = new UserData() + { + UserId = user.Id, + }; + } + if (true) + { + //失效订单金额 + foreach (var tabname in tabnames) + { + //失效订单金额 + userdata.InvalidOrderAmount += Convert.ToInt32(GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }).Sum("db_userpoint")); + } + foreach (var tabname in tabnames) + { + //失效订单总数 + userdata.InvalidOrderCount += Convert.ToInt32(GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }).Select("count(id)").Count()); + } + foreach (var tabname in tabnames) + { + //完成订单金额 + userdata.FinishOrderAmount += Convert.ToInt32(GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }).Sum("db_userpoint")); + } + foreach (var tabname in tabnames) + { + //完成订单数量 + userdata.FinishOrderCount += GetDb(tabname).Queryable(tabname, "").Where("db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }).Select("count(id)").Count(); + } + } + else + { + foreach (var tabname in tabnames) + { + //失效订单金额 + var tbdb = GetDb(tabname); + tbdb.AddQueue($"select sum(db_userpoint) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }); + tbdb.AddQueue($"select count(id) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1004 }); + tbdb.AddQueue($"select sum(db_userpoint) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }); + tbdb.AddQueue($"select count(id) from {tabname} where db_userid=@db_userid and db_status=@db_status", new { db_userid = useritem.id, db_status = 1002 }); + var resutl = tbdb.SaveQueues(); + Console.WriteLine(); + //if (resutl.Item!= null&&resutl.Item1.Count > 0) + //{ + // userdata.InvalidOrderAmount += resutl.Item1.FirstOrDefault(); + //} + //if (resutl.Item2!=null&&resutl.Item2.Count > 0) + //{ + // userdata.InvalidOrderCount += resutl.Item2.FirstOrDefault(); + //} + //if (resutl.Item3 != null && resutl.Item3.Count > 0) + //{ + // userdata.FinishOrderAmount += resutl.Item3.FirstOrDefault(); + //} + //if (resutl.Item4 != null && resutl.Item4.Count > 0) + //{ + // userdata.FinishOrderCount += resutl.Item4.FirstOrDefault(); + //} + } + } + userdata.AllRecommendCount = GetDb("fl_member_info").Queryable("fl_member_info", "") + .Where("inviter_id=@inviter_id", new { inviter_id = useritem.id }).Select("count(id)").Count(); + //累计提现现金,并且取正数 + userdata.TixianAmount = -GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where("uid=@id and type=@type", new { @type = "提现扣除", id = useritem.id }).Sum("point"); + //累计提现次数 + userdata.TixianCount = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where("uid=@id and type=@type", new { @type = "提现扣除", id = useritem.id }).Select("count(id)").Count(); + //用户的绑定数,玩家不会看这个 + userdata.QueryCount = Convert.ToInt32(useritem.bind_order); + //问老妖 + //userdata.EstimateCoupon = 0; + //按照累计提现金额 + userdata.EstimateRebate = userdata.TixianAmount; + //用户的绑定数,玩家不会看这个 + userdata.PayOrderCount = Convert.ToInt32(useritem.bind_order); + //维权扣除 + userdata.RefundOrderCount = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where(" uid=@id and type=@type", new { @type = "维权扣除", id = useritem.id }).Select("count(id)").Count(); + //累计有效邀请奖励(奖励都会叠加,并不是实时数据) + userdata.RecommendCount = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where(" uid=@id and type=@type", new { @type = "提成奖励", id = useritem.id }).Select("count(id)").Count(); + //累计有效邀请奖励(奖励都会叠加,并不是实时数据) + userdata.RecommendAward = GetDb("fl_point_hist").Queryable("fl_point_hist", "").Where("uid=@id and type=@type", new { @type = "提成奖励", id = useritem.id }).Sum("point"); + dynamic fl_alimama_order_lastnum = GetDb("fl_alimama_order_lastnum").Queryable("fl_alimama_order_lastnum", "").Where("userid=@userid", new { userid = useritem.id }).First(); + //淘宝后六位 + userdata.TaobaoLastid = fl_alimama_order_lastnum?.lastnumber; + //创建时间 + userdata.CreateTime = useritem.crt_time; + //最后购买时间 + var fl_statistics_recordItem = GetDb("fl_statistics_record").Queryable().AS("fl_statistics_record") + .Where("uid=@uid", new { uid = useritem.id }).First(); + if (fl_statistics_recordItem == null || fl_statistics_recordItem.ex5 <= 0) + { + userdata.LastBuyTime = DateTime.MinValue; + } + else + { + userdata.LastBuyTime = Util.TimespanToDatatime(fl_statistics_recordItem.ex5.ToString()); + } + var recommendUserInfo = GetDb("fl_member_info").Queryable().AS("fl_member_info") + .Where("id=@id", new { id = useritem.inviter_id }).First(); + if (recommendUserInfo != null) + { + lock (lockobj) + { + string recommendusername = recommendUserInfo.username; + UserType recommenduserType = GetUserType(Convert.ToInt32(recommendUserInfo.robot_type)); + var recommendUser = db.Queryable().Where(w => w.Username == recommendusername && w.UserType == recommenduserType).First(); + if (recommendUser == null) + { + recommendUser = new User() + { + Username = recommendUserInfo.username, + NickName = recommendUserInfo.usernick, + Weixinhao = recommendUserInfo.username, + Headurl = "", + IsFriend = false, + RevTime = recommendUserInfo.upd_time, + CreateTime = recommendUserInfo.crt_time, + WxRemark = recommendUserInfo.remark, + UserType = recommenduserType, + IsMigration = false + }; + db.Insertable(recommendUser).ExecuteReturnEntity(); + } + userdata.RecommendId = recommendUser.Id; + } + } + userdata.FinishOrderCount = Convert.ToInt32(useritem.finish_order); + userdata.CurPoint = Convert.ToInt32(useritem.cur_point); + userdata.UserStatus = GetUserStatus(Convert.ToInt32(useritem.status)); + userdata.FirstAdd = true; + userdata.FirstQuery = true; + userdata.FirstPay = true; + userdata.FirstReceive = true; + userdata.ReminderQuery = true; + userdata.ReminderOrder = true; + userdata.T1InvitePeople = true; + userdata.T2InvitePeople = true; + userdata.T3InvitePeople = true; + userdata.T4InvitePeople = true; + userdata.IsFristPayHourWithin = false; + userdata.IsFirstTiXian = userdata.TixianAmount > 0; + //------------------ + if (userdata.Id <= 0) + { + db.Insertable(userdata).SplitTable().ExecuteCommand(); + } + else + { + var tableName = db.GetTableName(user.Id); + db.Updateable(userdata).SplitTable(t => t.InTableNames(tableName)).ExecuteCommand(); + } + + + + Console.WriteLine(useritem.id + " - " + (DateTime.Now - startDateTime).TotalSeconds); + } + /// + /// 订单表名 + /// + private static string[] tabnames = new string[] { "fl_order_alimama", "fl_order_douyin", "fl_order_jingdong", "fl_order_pinduoduo", "fl_order_suning", "fl_order_weipinhui" }; + /// + /// 获取用户状态 + /// + /// + /// + private UserStatus GetUserStatus(int status) + { + switch (status) + { + case 1: return UserStatus.黑名单; + case 2: return UserStatus.白名单; + } + return UserStatus.正常; + } + /// + /// 获取用户类型 + /// + /// + /// + private UserType GetUserType(int robotType) + { + switch (robotType) + { + case 2: return UserType.微信用户; + case 1: return UserType.QQ用户; + case 0: return UserType.未知; + case 3: return UserType.公众号微信; + case 4: return UserType.企业微信; + } + return UserType.未知; + } + /// + /// 数据库 + /// + private Dictionary> DbDic = new Dictionary>(); + /// + /// 创建数据库 + /// + /// + /// + private void CreateDb(string filename, string path) + { + DbDic[filename] = () => + { + var db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = @"DataSource=" + path + @";Version=3;",//连接符字串 + DbType = SqlSugar.DbType.Sqlite, //数据库类型 + IsAutoCloseConnection = true, + }); + db.Aop.OnLogExecuted = (sql, prars) => + { + var temp = sql; + foreach (var item in prars) temp = temp.Replace(item.ParameterName, $"'{item.Value}'"); + var time = db.Ado.SqlExecutionTime; + Console.WriteLine($"其他库SQL耗时:{time.TotalSeconds}、SQL => {temp.Substring(0, 10)}"); + }; + return db; + }; + } + /// + /// 获取BD + /// + /// + /// + public SqlSugarClient GetDb(string tablename) + { + if (DbDic.ContainsKey(tablename)) + { + return DbDic[tablename](); + } + return null; + } + } +} \ No newline at end of file diff --git a/Server/Services/WaitTaskThreadService.cs b/Server/Services/WaitTaskThreadService.cs new file mode 100644 index 0000000..4695e30 --- /dev/null +++ b/Server/Services/WaitTaskThreadService.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; + +namespace Server.Services +{ + /// + /// 控制多线程任务等待帮助服务 + /// + public class WaitTaskThreadService + { + /// + /// 等待 + /// + private List manualEvents = new List(); + /// + /// 启动任务 + /// + /// + /// + /// + public void StartThread(string name, Action action, object stateObject) + { + var mre = new ManualResetEvent(false); + manualEvents.Add(mre); + var th = new Thread(o => + { + var result = o as WaitTaskThreadObject; + try + { + result?.Action?.Invoke(result.StateObject); + } + catch (Exception e) + { + Client.SingleClient.Db.OnLog("处理任务" + name, e); + throw e; + } + finally + { + result?.ManualResetEvent.Set(); + } + }); + th.Name = name; + th.Start(new WaitTaskThreadObject() + { + Name = name, + StateObject = stateObject, + Action = action, + ManualResetEvent = mre + }); + } + /// + /// 启动任务 + /// + /// + /// + /// + /// + public void StartThread(string name, Action action, T stateObject = default) + { + StartThread(name, (o) => + { + action?.Invoke((T)o); + }, (object)stateObject); + } + /// + /// 启动任务 + /// + /// + /// + public void StartThread(string name, Action action) + { + StartThread(name, (o) => + { + action?.Invoke(); + }, null); + } + /// + /// 等待全部任务完成 + /// + public void WaitAll() + { + WaitHandle.WaitAll(manualEvents.ToArray()); + } + } + + /// + /// 线程启动参数数据 + /// + public class WaitTaskThreadObject + { + /// + /// 线程名称,(调试用) + /// + public string Name { get; set; } + /// + /// 线程对象 + /// + public object StateObject { get; set; } + /// + /// 执行具体方法 + /// + public Action Action { get; set; } + /// + /// 线程同步事件 + /// + public ManualResetEvent ManualResetEvent { get; set; } + } +} diff --git a/Server/Timers/BlackTimer.cs b/Server/Timers/BlackTimer.cs new file mode 100644 index 0000000..b3b1f22 --- /dev/null +++ b/Server/Timers/BlackTimer.cs @@ -0,0 +1,166 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.Utils; + +namespace Server.Timers +{ + /// + /// 黑名单同步 + /// + public class BlackTimer : MyTimer + { + + readonly Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db => Client.Db; + /// + /// 运行 + /// + /// + /// + protected override void Run(object state, bool timedOut) + { + //YZCloudApiHelper.GetBlacklist() + ReadBlacklist(Client.Config.RuntimeCache.GetPublicValue("玩家黑名单同步时间", () => DateTime.MinValue), false, (items, index, total) => + { + //Console.WriteLine("输出:" + index + "|" + total + "|" + items.Count); + var db = Db; + var syncTime = Client.Config.RuntimeCache.GetPublicValue("玩家黑名单同步时间", () => DateTime.MinValue); + if (syncTime != DateTime.MinValue) + { + syncTime = syncTime.AddMinutes(-1); + } + bool issyncAdd = false; + db.UseTran(() => + { + foreach (var item in items) + { + if (item.UpdateDateTime >= syncTime) + { + issyncAdd = true; + var type = SetUserType(item.Type); + var info = db.Queryable().Where(w => w.Username == item.UserName && w.UserType == type).First(); + if (info == null) + { + info = new UserBlack(); + info.UserType = SetUserType(item.Type); + info.Username = item.UserName; + SetBlackType(info, item.GroupType); + info.NickName = item.UserNick; + info.Remark = item.Remark; + info.Avatar = item.Avatar; + info.UpdateTime = DateTime.Now; + info.IsDel = item.IsRemove; + info.IsCloud = true; + db.Insertable(info).ExecuteCommand(); + } + else + { + if (info.IsDel) + { + //如果本地已经删除,则忽略。 + continue; + } + SetBlackType(info, item.GroupType); + info.Avatar = item.Avatar; + info.IsDel = item.IsRemove; + info.UpdateTime = DateTime.Now; + info.Remark = item.Remark; + info.IsCloud = true; + db.Updateable(info).ExecuteCommand(); + } + } + } + }, ex => db.OnLog("同步黑名单", ex)); + if (issyncAdd) + { + Client.Config.RuntimeCache.SetPublicValue("玩家黑名单同步时间", items.LastOrDefault().UpdateDateTime); + } + return false; + }); + } + + private UserType SetUserType(int itemType) + { + + switch (itemType) + { + case 0: + return UserType.微信用户; + case 1: + return UserType.QQ用户; + case 2: + return UserType.企业微信; + } + + return UserType.微信用户; + } + + /// + /// 处理分组类型 + /// + /// + /// + private void SetBlackType(UserBlack info, BlacklistGroupType itemGroupType) + { + switch (itemGroupType) + { + case BlacklistGroupType.未分组: + info.BlackType = BlackType.未分类; + break; + case BlacklistGroupType.薅羊毛党: + info.BlackType = BlackType.薅羊毛; + break; + case BlacklistGroupType.恶意举报: + info.BlackType = BlackType.恶意举报; + break; + default: + info.BlackType = BlackType.未分类; + break; + } + } + /// + /// 读取黑名单 + /// + /// + /// + public static void ReadBlacklist(DateTime updateDateTime, bool isAsc, Func, int, int, bool> callback) + { + var size = 1000; + var index = 1; + while (true) + { + var res = YZCloudApiHelper.GetBlacklist(new BlacklistSearchPagingInput() + { + PageIndex = index, + PageSize = size, + UserToken = "", + IsAsc = isAsc, + UpdateDateTime = updateDateTime, + AuditState = AuditStateEmun.Succee + }); + if (res == null || res.Datas.Count <= 0) + { + break; + } + if (callback?.Invoke(res.Datas, index, res.PageNumber) == true) + { + break; + } + if (index <= 0) + { + break; + } + index++; + } + } + } +} diff --git a/Server/Timers/DyUpdateTimer.cs b/Server/Timers/DyUpdateTimer.cs new file mode 100644 index 0000000..1bf1ff3 --- /dev/null +++ b/Server/Timers/DyUpdateTimer.cs @@ -0,0 +1,279 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; +using Server.Events; +using SqlSugar; +namespace Server.Timers +{ + /// + /// 更新抖音订单 + /// + internal class DyUpdateTimer : MyTimer + { + public DyUpdateTimer() + { + DouyinRequest.OrderNoticeEvent += DouyinRequest_OrderNoticeEvent; + } + + private void DouyinRequest_OrderNoticeEvent(DouyinRequest req, Newtonsoft.Json.Linq.JToken Orders, bool NextPage) + { + var orderChangeEventArgsList = new List(); + var db = Db; + db.UseTran(() => + { + foreach (var item in Orders) + { + var pay_success_time = DateTime.Parse(item["pay_success_time"].ToString()); + var tab_name = Db.GetTableName(pay_success_time); + var order_id = item["order_id"].ToString(); + var product_id = item["product_id"].ToString(); + var update_time = item["update_time"]?.ToString(); + var order_status = item["order_status"].ToString(); + var tableNames = db.GetTableName(pay_success_time); + var order = db.Queryable().Where(f => f.order_id == order_id && f.product_id == product_id).SplitTable(t => t.InTableNames(tableNames)).First(); + if (order == null) + { + order = new DyOrder() + { + Id = Util.CreateID(pay_success_time), + order_id = order_id, + product_id = product_id, + LianmengId = req.Lianmeng.Id, + SystemOrderStatus = SystemOrderStatus.未知 + }; + } + else if (order.update_time == update_time) + { + continue; + } + //订单结算也需要进来,因为抖音结算时间要等很久 + else if ((int)order.SystemOrderStatus > 3001) + { + continue; + } + //旧的订单状态 + var oldSystemOrderStatus = order.SystemOrderStatus; + + + Util.CopyToObj(item, order); + SetChuChuangOrderState(db, order, order_status); + + //事件 + orderChangeEventArgsList.Add(new OrderChangeEventArgs() + { + LianmengType = req.Lianmeng.LianmengType, + NewStatus = order.SystemOrderStatus, + OldStatus = oldSystemOrderStatus, + OrderId = order.Id, + UserId = order.UserId + }); + } + + }, ex => + { + db.OnLog("抖音", ex); + throw ex; + }); + + //触发事件 + foreach (var orderArgs in orderChangeEventArgsList) + { + //Client.Events.OnOrderChange(this, orderArgs); + } + } + + private Client client = Client.SingleClient; + private Dictionary IsUpdateing = new Dictionary(); + public SqlSugar.SqlSugarClient Db { get { return client.Db; } } + + protected override void Run(object state, bool timedOut) + { + //第一步:获取可以更新的联盟集合 + var List = Db.Queryable().WithCache().Where(f => f.LianmengType == Common.Models.Enums.LianmengType.抖音联盟 && f.ExpirationTime > DateTime.Now && f.IsCookiValid).ToList(); + foreach (var item in List) + { + //var goodsid = req1.AnalysisKouLingOrLink("【茶杯马克杯带盖勺男女陶瓷杯子家用韩版学生情侣牛奶咖啡杯大容】长按复制此条消息,打开抖音搜索,查看商品详情##NBpa3VHI5r8##[抖:/ 音口令]"); + //req1.AddChuChuang(goodsid,out var pid); + //req1.UnBindGoods(pid); + //var dd = req1.GetPromotionUrl(goodsid); + //更新中跳过 + if (IsUpdateing.ContainsKey(item.Id) && IsUpdateing[item.Id]) + { + continue; + } + IsUpdateing[item.Id] = true; + Task.Factory.StartNew(() => + { + var req = new DouyinRequest(item); + var start_time = DateTime.Now.AddDays(-1); + var endTime = DateTime.Now; + try + { + req.UpdateDouyinOrder(start_time, DateTime.Now); + } + catch (Exception ex) + { + if (ex.Message.Contains("cookie已失效")) + { + Client.SingleClient.Db.Updateable(item).ExecuteCommand(); + } + Db.OnLog("更新抖音订单错误", ex); + } + try + { + //处理橱窗订单 + req.UpdateDouyinChuChuangOrder(start_time, endTime, items => + { + HandleChuChuangOrder(req, items); + return false; + }); + } + catch (Exception ex) + { + if (ex.Message.Contains("cookie已失效")) + { + Client.SingleClient.Db.Updateable(item).ExecuteCommand(); + } + Db.OnLog("更新抖音订单错误", ex); + } + }); + Thread.Sleep(1000); + } + } + /// + /// 处理橱窗订单 + /// + /// + /// + private void HandleChuChuangOrder(DouyinRequest req, JToken[] items) + { + var db = Db; + db.UseTran(() => + { + foreach (var token in items) + { + //付款时间 + var payTime = Util.TimespanToDatatime(token["pay_time"].Value()); + //订单ID + var orderId = token["order_id"].Value(); + //订单状态 + var orderStatus = token["order_status"].Value(); + //商品id + var productId = token["product_id"].Value(); + var tableNames = db.GetTableName(payTime); + var order = db.Queryable(). + Where(f => f.order_id == orderId && f.product_id == productId). + SplitTable(t => t.InTableNames(tableNames)). + First(); + if (order == null) + { + order = new DyOrder() + { + Id = Util.CreateID(payTime), + order_id = orderId, + product_id = productId, + LianmengId = req.Lianmeng.Id, + SystemOrderStatus = SystemOrderStatus.未知 + }; + } + //Todo 这里需要看看怎么处理 + //else if (order.update_time == update_time) + //{ + // continue; + //} + //订单结算也需要进来,因为抖音结算时间要等很久 + else if ((int)order.SystemOrderStatus > 3001) + { + continue; + } + Util.CopyToObj(token, order); + SetChuChuangOrderState(db, order, orderStatus); + } + + }, ex => db.OnLog("抖音橱窗订单", ex)); + } + /// + /// 设置橱窗订单状态 + /// + /// + /// + private void SetChuChuangOrderState(SqlSugarClient db, DyOrder order, string orderStatus) + { + if (string.IsNullOrWhiteSpace(orderStatus)) + { + return; + } + switch (orderStatus) + { + case "PAY_SUCC"://支付完成 + order.SystemOrderStatus = SystemOrderStatus.订单付款; + if (order.UserId == 0 && order.pid_info != null) + { + //通过扩展ID,查到了用户 + if (long.TryParse(order.pid_info.external_info, out var queryId)) + { + var queryTabName = Db.GetTableName(queryId); + var cache = db.Queryable().SplitTable(tab => tab.InTableNames(queryTabName)).Single(f => f.Id == queryId); + if (cache != null) + { + order.UserId = cache.UserId; + order.QueryCache = cache; + + var user = db.GetUserData(order.UserId); + user.PayOrderCount++; + db.Save(user); + } + } + } + break; + case "CONFIRM"://确认收货 + order.SystemOrderStatus = SystemOrderStatus.订单收货; + if (order.PayStatus == OrderPayStatus.未支付) + { + //插入支付队列,准备结算佣金 + FinishOrder frozen = null; + if (order.UserId > 0) + { + order.PayStatus = OrderPayStatus.支付中; + //判断订单是否在24小时内确认收货 + var TimeConsuming = DateTime.Now - order.pay_success_time; + DateTime ThawingTime = DateTime.Now; + if (TimeConsuming.TotalDays < 1) + { + var pubConfig = db.GetPubConfig(); + if (pubConfig != null && pubConfig.ExtendDay > 0) + { + ThawingTime = ThawingTime.AddDays(pubConfig.ExtendDay); + } + } + frozen = new FinishOrder() { CreateTime = DateTime.Now, LianmengType = LianmengType.抖音联盟, OrderId = order.Id, ThawingTime = ThawingTime, UserId = order.UserId }; + } + } + break; + case "SETTLE"://结算 + order.SystemOrderStatus = SystemOrderStatus.订单结算; + break; + case "REFUND"://订单退款 + order.SystemOrderStatus = SystemOrderStatus.全额退款; + if (order.PayStatus == OrderPayStatus.已支付 && order.UserId != 0) + { + db.GetUserData(order.UserId); + } + break; + default: + Db.OnLog("抖音订单更新", $"发现未知状态的订单:{order.order_id}"); + break; + } + } + } +} diff --git a/Server/Timers/FinishOrderTimer.cs b/Server/Timers/FinishOrderTimer.cs new file mode 100644 index 0000000..7aa2f24 --- /dev/null +++ b/Server/Timers/FinishOrderTimer.cs @@ -0,0 +1,365 @@ +using Common.DbExtends.Extends; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SqlSugar; +using Common.Models.Enums; +using Common.Models.JsonModels; +using Common.Models.SubCountTables; +using Common.DbExtends.Others; +using Common.Utils.Extends; + +namespace Server.Timers +{ + public class FinishOrderTimer : MyTimer + { + Client Client = Client.SingleClient; + private SqlSugarClient Db { get { return Client.Db; } } + + protected override void Run(object state, bool timedOut) + { + try + { + ///读取已经解冻的订单 + var Orders = Client.Db.Queryable().Where(f => f.ThawingTime <= DateTime.Now).OrderBy(f => f.CreateTime, OrderByType.Asc).Take(30).ToList(); + if (Orders.Count > 0) + { + foreach (var item in Orders) + { + + switch (item.LianmengType) + { + case LianmengType.淘宝联盟: + { + var tabName = Db.GetTableNameById(item.OrderId); + var order = Db.Queryable().Where(f => f.Id == item.OrderId).SplitTable(tab => tab.InTableNames(tabName)).First(); + + //如果佣金发生了变化 + if (order.total_commission_fee != order.QueryCache.TotalCommission) + { + //再不改变比例的情况下,重新计算 + order.QueryCache.TotalCommission = order.pub_share_pre_fee; + order.QueryCache.CalculationUserCommission(); + order.QueryCache.CalculationInviteeCommission(); + } + + + var user = Db.GetUserData(order.UserId); + + //没有查询记录,就自动创建一个 + var cache = order.QueryCache; + if (cache == null) + { + var robotData = Db.GetRobot(user.RobotId); + if (robotData != null) + { + var rConfig = Db.GetRebateConfigById(robotData.ConfigRebateId); + var query = new QueryHist(user, order.item_id, LianmengType.淘宝联盟, order.LianmengId, $"{order.site_id}_{order.adzone_id}", order.pub_share_pre_fee); + if (Db.CalculationData(query, rConfig)) + { + order.QueryCache = query; + var bConfig = Db.GetBaseConfigById(robotData.ConfigBaseId); + if (bConfig != null) + { + Db.CalculationData(query, bConfig); + } + } + } + } + + if (cache != null) + { + Db.PayPoint(order, cache, order.Id, order.item_title, true); + } + Db.Updateable(order).SplitTable(tab => tab.InTableNames(tabName)).ExecuteCommand(); + Db.Deleteable(item).ExecuteCommand(); + + Client.SendClientMsg(cache.RobotId, DeviceMessageType.淘宝订单更新, new { OrderId = order.Id, TableName = tabName }); + } + break; + case LianmengType.京东联盟: + { + var tabName = Db.GetTableNameById(item.OrderId); + var order = Db.Queryable().Where(f => f.Id == item.OrderId).SplitTable(tab => tab.InTableNames(tabName)).First(); + + //如果佣金发生了变化 + if (order.actualFee != order.QueryCache.TotalCommission) + { + //再不改变比例的情况下,重新计算 + order.QueryCache.TotalCommission = order.actualFee; + order.QueryCache.CalculationUserCommission(); + order.QueryCache.CalculationInviteeCommission(); + } + + + var user = Db.GetUserData(order.UserId); + + //没有查询记录,就自动创建一个 + var cache = order.QueryCache; + if (cache == null) + { + var robotData = Db.GetRobot(user.RobotId); + if (robotData != null) + { + var rConfig = Db.GetRebateConfigById(robotData.ConfigRebateId); + var query = new QueryHist(user, order.skuId, LianmengType.京东联盟, order.LianmengId, $"{order.positionId}", order.actualFee); + if (Db.CalculationData(query, rConfig)) + { + order.QueryCache = query; + var bConfig = Db.GetBaseConfigById(robotData.ConfigBaseId); + if (bConfig != null) + { + Db.CalculationData(query, bConfig); + } + } + } + } + + if (cache != null) + { + Db.PayPoint(order, cache, order.Id, order.skuName, true); + } + Db.Updateable(order).SplitTable(tab => tab.InTableNames(tabName)).ExecuteCommand(); + Db.Deleteable(item).ExecuteCommand(); + + Client.SendClientMsg(cache.RobotId, DeviceMessageType.京东订单更新, new { OrderId = order.Id, TableName = tabName }); + } + break; + case LianmengType.拼多多联盟: + { + var tabName = Db.GetTableNameById(item.OrderId); + var order = Db.Queryable().Where(f => f.Id == item.OrderId).SplitTable(tab => tab.InTableNames(tabName)).First(); + + //如果佣金发生了变化 + var totalComm = (double)order.promotion_amount.Divided100();//分转元 + if (totalComm != order.QueryCache.TotalCommission) + { + //再不改变比例的情况下,重新计算 + order.QueryCache.TotalCommission = totalComm; + order.QueryCache.CalculationUserCommission(); + order.QueryCache.CalculationInviteeCommission(); + } + + var user = Db.GetUserData(order.UserId); + + //没有查询记录,就自动创建一个 + var cache = order.QueryCache; + if (cache == null) + { + var robotData = Db.GetRobot(user.RobotId); + if (robotData != null) + { + var rConfig = Db.GetRebateConfigById(robotData.ConfigRebateId); + var query = new QueryHist(user, order.goods_id.ToString(), LianmengType.拼多多联盟, order.LianmengId, $"{order.p_id}", totalComm); + if (Db.CalculationData(query, rConfig)) + { + order.QueryCache = query; + var bConfig = Db.GetBaseConfigById(robotData.ConfigBaseId); + if (bConfig != null) + { + Db.CalculationData(query, bConfig); + } + } + } + } + + if (cache != null) + { + Db.PayPoint(order, cache, order.Id, order.goods_name, true); + } + Db.Updateable(order).SplitTable(tab => tab.InTableNames(tabName)).ExecuteCommand(); + Db.Deleteable(item).ExecuteCommand(); + + Client.SendClientMsg(cache.RobotId, DeviceMessageType.拼多多订单更新, new { OrderId = order.Id, TableName = tabName }); + } + break; + case LianmengType.唯品会联盟: + { + var tabName = Db.GetTableNameById(item.OrderId); + var order = Db.Queryable().Where(f => f.Id == item.OrderId).SplitTable(tab => tab.InTableNames(tabName)).First(); + + //如果佣金发生了变化 + if (order.commission != order.QueryCache.TotalCommission) + { + //再不改变比例的情况下,重新计算 + order.QueryCache.TotalCommission = order.commission; + order.QueryCache.CalculationUserCommission(); + order.QueryCache.CalculationInviteeCommission(); + } + + + var user = Db.GetUserData(order.UserId); + + //没有查询记录,就自动创建一个 + var cache = order.QueryCache; + if (cache == null) + { + var robotData = Db.GetRobot(user.RobotId); + if (robotData != null) + { + var rConfig = Db.GetRebateConfigById(robotData.ConfigRebateId); + var query = new QueryHist(user, order.goodsId, LianmengType.唯品会联盟, order.LianmengId, $"{order.pid}", order.commission); + if (Db.CalculationData(query, rConfig)) + { + order.QueryCache = query; + var bConfig = Db.GetBaseConfigById(robotData.ConfigBaseId); + if (bConfig != null) + { + Db.CalculationData(query, bConfig); + } + } + } + } + + if (cache != null) + { + Db.PayPoint(order, cache, order.Id, order.goodsName, true); + } + Db.Updateable(order).SplitTable(tab => tab.InTableNames(tabName)).ExecuteCommand(); + Db.Deleteable(item).ExecuteCommand(); + + Client.SendClientMsg(cache.RobotId, DeviceMessageType.唯品会订单更新, new { OrderId = order.Id, TableName = tabName }); + } + break; + case LianmengType.苏宁联盟: + { + var tabName = Db.GetTableNameById(item.OrderId); + var order = Db.Queryable().Where(f => f.Id == item.OrderId).SplitTable(tab => tab.InTableNames(tabName)).First(); + + //如果佣金发生了变化 + var totalComm = double.Parse(order.prePayCommission); + if (totalComm != order.QueryCache.TotalCommission) + { + //再不改变比例的情况下,重新计算 + order.QueryCache.TotalCommission = totalComm; + order.QueryCache.CalculationUserCommission(); + order.QueryCache.CalculationInviteeCommission(); + } + + + var user = Db.GetUserData(order.UserId); + + //没有查询记录,就自动创建一个 + var cache = order.QueryCache; + if (cache == null) + { + var robotData = Db.GetRobot(user.RobotId); + if (robotData != null) + { + var rConfig = Db.GetRebateConfigById(robotData.ConfigRebateId); + var query = new QueryHist(user, order.goodsNum, LianmengType.苏宁联盟, order.LianmengId, $"", totalComm); + if (Db.CalculationData(query, rConfig)) + { + order.QueryCache = query; + var bConfig = Db.GetBaseConfigById(robotData.ConfigBaseId); + if (bConfig != null) + { + Db.CalculationData(query, bConfig); + } + } + } + } + + if (cache != null) + { + Db.PayPoint(order, cache, order.Id, order.productName, true); + } + Db.Updateable(order).SplitTable(tab => tab.InTableNames(tabName)).ExecuteCommand(); + Db.Deleteable(item).ExecuteCommand(); + + Client.SendClientMsg(cache.RobotId, DeviceMessageType.苏宁订单更新, new { OrderId = order.Id, TableName = tabName }); + } + break; + case LianmengType.抖音联盟: + { + var tabName = Db.GetTableNameById(item.OrderId); + var order = Db.Queryable().Where(f => f.Id == item.OrderId).SplitTable(tab => tab.InTableNames(tabName)).First(); + + //如果佣金发生了变化 + var totalComm = (double)order.estimated_comission.Divided100(); + if (totalComm != order.QueryCache.TotalCommission) + { + //再不改变比例的情况下,重新计算 + order.QueryCache.TotalCommission = totalComm; + order.QueryCache.CalculationUserCommission(); + order.QueryCache.CalculationInviteeCommission(); + } + + + var user = Db.GetUserData(order.UserId); + + //没有查询记录,就自动创建一个 + var cache = order.QueryCache; + if (cache == null) + { + var robotData = Db.GetRobot(user.RobotId); + if (robotData != null) + { + var rConfig = Db.GetRebateConfigById(robotData.ConfigRebateId); + var query = new QueryHist(user, order.product_id, LianmengType.抖音联盟, order.LianmengId, $"", totalComm); + if (Db.CalculationData(query, rConfig)) + { + order.QueryCache = query; + var bConfig = Db.GetBaseConfigById(robotData.ConfigBaseId); + if (bConfig != null) + { + Db.CalculationData(query, bConfig); + } + } + } + } + + if (cache != null) + { + Db.PayPoint(order, cache, order.Id, order.product_name, true); + } + Db.Updateable(order).SplitTable(tab => tab.InTableNames(tabName)).ExecuteCommand(); + Db.Deleteable(item).ExecuteCommand(); + + Client.SendClientMsg(cache.RobotId, DeviceMessageType.抖音订单更新, new { OrderId = order.Id, TableName = tabName }); + } + break; + case LianmengType.美团联盟: + { + //TODO 美团是否有? + } + break; + case LianmengType.无: + break; + default: + break; + } + + } + } + } + catch (Exception ex) + { + Client.Db.OnLog("订单结算", ex); + } + + } + + /// + /// 百分之probability的中奖概率 + /// + /// + /// + private bool IsGetHb(int probability) + { + int a = new Random(Guid.NewGuid().GetHashCode()).Next(1, 100); // [1,100] + if (a <= probability) + { + return true; + } + + return false; + } + + } +} \ No newline at end of file diff --git a/Server/Timers/GoodsBlackTimer.cs b/Server/Timers/GoodsBlackTimer.cs new file mode 100644 index 0000000..6948db3 --- /dev/null +++ b/Server/Timers/GoodsBlackTimer.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.Controllers.Help; +using Server.Utils; + +namespace Server.Timers +{ + /// + /// 商品黑名单同步 + /// + public class GoodsBlackTimer : MyTimer + { + readonly Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db => Client.Db; + /// + /// 运行 + /// + /// + /// + protected override void Run(object state, bool timedOut) + { + //YZCloudApiHelper.GetBlacklist() + ReadBlacklist(Client.Config.RuntimeCache.GetPublicValue("玩家商品黑名单同步时间", () => DateTime.MinValue), false, (items, index, total) => + { + //Console.WriteLine("输出:" + index + "|" + total + "|" + items.Count); + var db = Db; + var syncTime = Client.Config.RuntimeCache.GetPublicValue("玩家商品黑名单同步时间", () => DateTime.MinValue); + if (syncTime != DateTime.MinValue) + { + syncTime = syncTime.AddMinutes(-1); + } + + bool issyncAdd = false; + db.UseTran(() => + { + foreach (var item in items) + { + if (item.UpdateDateTime >= syncTime) + { + issyncAdd = true; + var platform = GetPlatform(item); + var info = db.Queryable().Where(w => w.Platform == platform && w.GoodsId == item.GoodsId).First(); + if (info == null) + { + info = new GoodsBlacklist(); + info.Platform = platform; + info.StoreName = item.StoreName; + info.GoodsId = item.GoodsId; + info.Remark = item.Remark; + info.UpdateTime = DateTime.Now; + info.IsDel = item.IsRemove; + info.IsCloud = true; + db.Insertable(info).ExecuteCommand(); + } + else + { + if (info.IsDel) + { + //如果本地已经删除,则忽略。 + continue; + } + info.IsDel = item.IsRemove; + info.Remark = item.Remark; + info.UpdateTime = DateTime.Now; + info.IsCloud = true; + db.Updateable(info).ExecuteCommand(); + } + } + } + }, ex => db.OnLog("同步商品黑名单", ex)); + if (issyncAdd) + { + Client.Config.RuntimeCache.SetPublicValue("玩家商品黑名单同步时间", items.LastOrDefault().UpdateDateTime); + } + return false; + }); + } + + private LianmengType GetPlatform(CloudGoodsBlacklistResult item) + { + return LianmengTypeHelper.GetPlatformType(item.Platform); + } + + /// + /// 读取 + /// + /// + /// + public static void ReadBlacklist(DateTime updateDateTime, bool isAsc, Func, int, int, bool> callback) + { + var size = 1000; + var index = 1; + while (true) + { + var res = YZCloudApiHelper.GetGoodsBlacklist(new GoodsBlacklistSearchPagingInput() + { + PageIndex = index, + PageSize = size, + UserToken = "", + IsAsc = isAsc, + UpdateDateTime = updateDateTime, + AuditState = AuditStateEmun.Succee + }); + if (res == null || res.Datas.Count <= 0) + { + break; + } + if (callback?.Invoke(res.Datas, index, res.PageNumber) == true) + { + break; + } + if (index <= 0) + { + break; + } + index++; + } + } + } +} diff --git a/Server/Timers/JDOrderTimer.cs b/Server/Timers/JDOrderTimer.cs new file mode 100644 index 0000000..fe13129 --- /dev/null +++ b/Server/Timers/JDOrderTimer.cs @@ -0,0 +1,379 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.Events; +using Server.MyClass.Caches; +using SqlSugar; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Server.Timers +{ + /// + /// 京东订单定时读取 + /// + public class JDOrderTimer : MyTimer + { + public JDOrderTimer() + { + JingdongRequest.OrderNoticeEvent += JingdongRequest_OrderNoticeEvent; + } + + + + readonly Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db => Client.Db; + private readonly ConcurrentDictionary IsUpdateing = new ConcurrentDictionary(); + + protected override void Run(object state, bool timedOut) + { + var lianmengs = this.Db.Queryable().Where(w => w.LianmengType == Common.Models.Enums.LianmengType.京东联盟 && w.ExpirationTime > DateTime.Now).ToList(); + foreach (var lianmeng in lianmengs) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + continue; + } + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if ((DateTime.Now - lastDateTime).TotalSeconds <= 60)//60秒间隔读取 + { + continue; + } + //启动线程读取 + ThreadPool.QueueUserWorkItem((o) => + { + HandleOrderLianmeng(o as Lianmeng); + }, lianmeng); + } + } + /// + /// 读取订单 + /// + /// + private void HandleOrderLianmeng(Lianmeng lianmeng) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + return; + } + //标记防止重复读取 + IsUpdateing[lianmeng.Id] = true; + try + { + var req = new JingdongRequest(lianmeng); + //上次读取时间 + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if (lastDateTime == DateTime.MinValue) + { + //如果没有时间,读取最近1个月的数据 + lastDateTime = DateTime.Now.AddDays(-30); + } + //本次读取时间 + var datetime = DateTime.Now; + + //处理订单 + HandleOrder(lianmeng, req, lastDateTime, datetime); + + //记录本次读取时间 + SetLastDateTime(lianmeng.Id + "", datetime); + } + catch (Exception ex) + { + Db.OnLog("京东订单同步2", ex); + } + finally + { + //删除防止重复读取标记 + IsUpdateing.TryRemove(lianmeng.Id, out _); + if (lianmeng.ExpirationTime < DateTime.Now) + { + Db.Updateable(lianmeng).UpdateColumns(s => new { s.ExpirationTime }).ExecuteCommand(); + } + } + } + /// + /// 京东订单车处理请求 + /// + /// + /// + /// + /// + private void HandleOrder(Lianmeng lianmeng, JingdongRequest req, DateTime lastDateTime, DateTime datetime) + { + lastDateTime = lastDateTime.AddMinutes(-1); + req.OrderQuery(lastDateTime, datetime, (items) => + { + var db = this.Db; + var orderChangeEventArgsList = new List(); + db.UseTran(() => + { + foreach (var item in items) + { + var id = item["id"].Value(); + var orderTime = item["orderTime"].Value(); + var modifyTime = item["modifyTime"].Value(); + var orderStatus = (JDOrderCodeEnum)item["validCode"].Value(); + var tablenames = db.GetTableName(orderTime); + var info = db.Queryable().Where(w => w.UniqueId == id).SplitTable(t => t.InTableNames(tablenames)).First(); + if (info != null) + { + if (info.modifyTime == modifyTime) + { + continue; + } + else if ((int)info.SystemOrderStatus > 3000) + { + continue; + } + //旧的订单状态 + var oldSystemOrderStatus = info.SystemOrderStatus; + //复制对象 + Util.CopyToObj(item, info); + //设置订单状态 + SetOrderState(db, lianmeng, orderStatus, info); + //修改数据 + db.Updateable(info).SplitTable(t => t.InTableNames(tablenames)).ExecuteCommand(); + orderChangeEventArgsList.Add(new OrderChangeEventArgs() + { + LianmengType = lianmeng.LianmengType, + NewStatus = info.SystemOrderStatus, + OldStatus = oldSystemOrderStatus, + OrderId = info.Id, + UserId = info.UserId + }); + } + else + { + info = new JdOrder(); + info.LianmengId = lianmeng.Id; + info.Id = Util.CreateID(orderTime); + info.UniqueId = id; + Util.CopyToObj(item, info); + SetOrderState(db, lianmeng, orderStatus, info); + db.Insertable(info).SplitTable().ExecuteCommand(); + orderChangeEventArgsList.Add(new OrderChangeEventArgs() + { + LianmengType = lianmeng.LianmengType, + NewStatus = info.SystemOrderStatus, + OldStatus = SystemOrderStatus.未知, + OrderId = info.Id, + UserId = info.UserId + }); + } + } + }, ex => + { + Db.OnLog("京东订单同步", ex); + throw ex; + }); + //触发事件 + foreach (var orderArgs in orderChangeEventArgsList) + { + Client.Events.OnOrderChange(this, orderArgs); + } + return false; + }); + } + + /// + /// 设置订单状态 + /// + /// + /// + /// + private void SetOrderState(SqlSugarClient db, Lianmeng lianmeng, JDOrderCodeEnum orderStatus, JdOrder info) + { + switch (orderStatus) + { + case JDOrderCodeEnum.未知: + info.SystemOrderStatus = SystemOrderStatus.未知; + break; + case JDOrderCodeEnum.无效拆单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效取消: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效京东帮帮主订单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效账号异常: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效赠品类目不返佣: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效校园订单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效企业订单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效团购订单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效乡村推广员下单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效违规订单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效来源与备案网址不符: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.待付款: + info.SystemOrderStatus = SystemOrderStatus.订单创建; + CreateUserId(db, lianmeng, info); + break; + case JDOrderCodeEnum.已付款: + info.SystemOrderStatus = SystemOrderStatus.订单付款; + CreateUserId(db, lianmeng, info); + break; + case JDOrderCodeEnum.已完成: + info.SystemOrderStatus = SystemOrderStatus.订单收货; + CreateComplete(db, info); + break; + case JDOrderCodeEnum.无效佣金比例为0: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效此复购订单对应的首购订单无效: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效云店订单: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效PLUS会员佣金比例为0: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.无效支付有礼: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case JDOrderCodeEnum.已付定金: + info.SystemOrderStatus = SystemOrderStatus.订单付款; + break; + default: + break; + } + //判断是否退货 + if (info.frozenSkuNum == 1 && info.actualCosPrice <= 0 && info.actualFee <= 0) + { + if (info.PayStatus == OrderPayStatus.已支付) + { + db.PayPoint(info, info.QueryCache, info.Id, info.skuName, true); + } + } + } + /// + /// 生成订单完成信息 + /// + /// + private void CreateComplete(SqlSugarClient db, JdOrder info) + { + if (info.UserId <= 0) + { + return; + } + if (info.PayStatus == OrderPayStatus.未支付) + { + info.PayStatus = OrderPayStatus.支付中; + if (string.IsNullOrWhiteSpace(info.finishTime)) + { + info.finishTime = DateTime.Now.ToString(CultureInfo.InvariantCulture); + } + //时间截取 + var TimeConsuming = DateTime.Parse(info.finishTime) - info.orderTime; + DateTime ThawingTime = DateTime.Now; + if (TimeConsuming.TotalDays < 1) + { + var pubConfig = db.GetPubConfig(); + if (pubConfig != null && pubConfig.ExtendDay > 0) + { + ThawingTime = DateTime.Parse(info.finishTime).AddDays(pubConfig.ExtendDay); + } + } + var frozen = new FinishOrder() + { + CreateTime = DateTime.Now, + LianmengType = LianmengType.京东联盟, + OrderId = info.Id, + ThawingTime = ThawingTime, + UserId = info.UserId + }; + db.Insertable(frozen).ExecuteCommand(); + //发送通知 + var tablenames = db.GetTableName(info.orderTime); + if (info.UserId > 0 && info.QueryCache != null) + { + bool IsFreeze = (frozen.ThawingTime > DateTime.Now); + Client.SendClientMsg(info.QueryCache.RobotId, DeviceMessageType.京东订单更新, new { OrderId = info.Id, TableName = tablenames, IsFreeze = IsFreeze }); + } + } + } + /// + /// 创建用户ID,跟单用户 + /// + /// + /// + private void CreateUserId(SqlSugarClient db, Lianmeng lianmeng, JdOrder info) + { + if (info.UserId > 0) + return; + + string positionId = info.positionId + ""; + var cache = db.GetQueryHist(f => f.ItemId == info.skuId && f.Pid == positionId && f.LianmegnId == lianmeng.Id && f.ItemType == LianmengType.京东联盟); + if (cache != null) + { + info.QueryCache = cache; + info.UserId = cache.UserId; + } + else + { + //京东商品有多类型,该商品id的最后一位是不一样的直接截取最后一个数 + var skuIdTmp = info.skuId.Substring(0, info.skuId.Length - 1); + //如果查询出来,只有一条记录 + var cacheTmp = db.GetQueryHist(f => f.ItemId.StartsWith(skuIdTmp) && f.Pid == positionId && f.LianmegnId == lianmeng.Id && f.ItemType == LianmengType.京东联盟); + if (cacheTmp != null) + { + info.QueryCache = cacheTmp; + info.UserId = cacheTmp.UserId; + } + } + } + /// + /// 获取上次时间 + /// + /// + /// + private DateTime GetLastDateTime(string id) + { + return Client.Config.RuntimeCache.GetPublicValue("订单同步" + id, () => DateTime.MinValue); + } + /// + /// 记录上次时间 + /// + /// + /// + private void SetLastDateTime(string id, DateTime now) + { + Client.Config.RuntimeCache.SetPublicValue("订单同步" + id, now); + } + + + private void JingdongRequest_OrderNoticeEvent(Lianmeng lianmeng, DateTime start, DateTime end) + { + HandleOrder(lianmeng, new JingdongRequest(lianmeng), start, end); + } + } +} diff --git a/Server/Timers/MtOrderTimer.cs b/Server/Timers/MtOrderTimer.cs new file mode 100644 index 0000000..374010a --- /dev/null +++ b/Server/Timers/MtOrderTimer.cs @@ -0,0 +1,297 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.MyClass.Caches; +using SqlSugar; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Server.Timers +{ + /// + /// 美团订单定时同步 + /// + public class MtOrderTimer : MyTimer + { + public MtOrderTimer() + { + + MTRequest.OrderNoticeEvent += MTRequest_OrderNoticeEvent; + } + + + Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db { get { return Client.Db; } } + private ConcurrentDictionary IsUpdateing = new ConcurrentDictionary(); + + protected override void Run(object state, bool timedOut) + { + var lianmengs = this.Db.Queryable().Where(w => w.LianmengType == Common.Models.Enums.LianmengType.美团联盟&&w.ExpirationTime>DateTime.Now).ToList(); + foreach (var lianmeng in lianmengs) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + continue; + } + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if ((DateTime.Now - lastDateTime).TotalSeconds <= 60)//60秒间隔读取 + { + continue; + } + //启动线程读取 + ThreadPool.QueueUserWorkItem((o) => + { + HandleOrderLianmeng(o as Lianmeng); + }, lianmeng); + } + } + /// + /// 同步某个账号美团订单 + /// + /// + private void HandleOrderLianmeng(Lianmeng lianmeng) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + return; + } + //标记防止重复读取 + IsUpdateing[lianmeng.Id] = true; + try + { + var req = new MTRequest(lianmeng); + //上次读取时间 + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if (lastDateTime == DateTime.MinValue) + { + //如果没有时间,读取最近1个月的数据 + lastDateTime = DateTime.Now.AddDays(-30); + } + //本次读取时间 + var datetime = DateTime.Now; + //处理订单 + HandleOrder(lianmeng, req, lastDateTime, datetime); + //记录本次读取时间 + SetLastDateTime(lianmeng.Id + "", datetime); + } + catch (Exception ex) + { + Db.OnLog("美团订单同步2", ex); + } + finally + { + //删除防止重复读取标记 + IsUpdateing.TryRemove(lianmeng.Id, out _); + if (lianmeng.ExpirationTime < DateTime.Now) + { + Db.Updateable(lianmeng).UpdateColumns(s => new { s.ExpirationTime }).ExecuteCommand(); + } + } + } + /// + /// 处理订单 + /// + /// + /// + /// + /// + private void HandleOrder(Lianmeng lianmeng, MTRequest req, DateTime lastDateTime, DateTime datetime) + { + lastDateTime = lastDateTime.AddMinutes(-1); + req.GetCPSOrderList(lastDateTime, datetime, (items) => + { + var db = Db; + db.UseTran(() => + { + var addlist = new List(); + foreach (var item in items) + { + var uniqueItemId = item["uniqueItemId"].Value(); + var modifyTime = item["modifyTime"].Value(); + var orderPayTime = item["orderPayTime"].Value(); + var itemStatus = (MtItemOrderStatus)item["itemStatus"].Value(); + var itemBizStatus = (MtItemBizStatusEnum)item["itemBizStatus"].Value(); + var tablenames = db.GetTableName(orderPayTime); + var info = db.Queryable().Where(w => w.uniqueItemId == uniqueItemId).SplitTable(t => t.InTableNames(tablenames)).First(); + if (info != null) + { + if (info.modifyTime == modifyTime) + { + continue; + } + else if ((int)info.SystemOrderStatus > 3000) + { + continue; + } + //复制对象 + Util.CopyToObj(item, info); + //设置订单状态 + SetOrderState(itemStatus, itemBizStatus, info); + //修改数据 + db.Updateable(info).SplitTable(t => t.InTableNames(tablenames)).ExecuteCommand(); + } + else + { + var order = new MtOrder(); + order.Id = Util.CreateID(orderPayTime); + order.LianmengId = lianmeng.Id; + Util.CopyToObj(item, order); + SetOrderState(itemStatus, itemBizStatus, order); + addlist.Add(order); + } + } + if (addlist.Count > 0) + { + //批量插入到数据库 + db.Insertable(addlist).SplitTable().ExecuteCommand(); + } + }, ex => db.OnLog("美团订单同步", ex)); + return false; + }); + //处理异常订单 + HandleAbnormalOrderLianmeng(lianmeng, lastDateTime, datetime); + } + + /// + /// 设置订单状态 + /// + /// + /// + /// + private void SetOrderState(MtItemOrderStatus itemStatus, MtItemBizStatusEnum itemBizStatus, MtOrder order) + { + switch (itemStatus) + { + case MtItemOrderStatus.未使用: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.未知; + break; + case MtItemOrderStatus.已使用: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单收货; + break; + case MtItemOrderStatus.退款中: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单退款中; + break; + case MtItemOrderStatus.已退款: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.全额退款; + break; + case MtItemOrderStatus.已消费退款: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.全额退款; + break; + default: + break; + } + switch (itemBizStatus) + { + case MtItemBizStatusEnum.支付成功: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单付款; + break; + case MtItemBizStatusEnum.核销成功: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单收货; + break; + case MtItemBizStatusEnum.结算成功: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单结算; + break; + case MtItemBizStatusEnum.无效订单: + order.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单失效; + break; + case MtItemBizStatusEnum.未知状态: + break; + default: + break; + } + } + + /// + /// 读取异常订单处理 + /// + /// + /// + private void HandleAbnormalOrderLianmeng(Lianmeng lianmeng, DateTime lastDateTime, DateTime dateTime) + { + var req = new MTRequest(lianmeng); + req.GetCPSAbnormalOrderList(lastDateTime, dateTime, items => + { + var db = Db; + db.UseTran(() => + { + foreach (var item in items) + { + var uniqueItemId = item["uniqueItemId"].Value(); + var eventType = item["eventType"].Value(); + var info = db.Queryable().Where(w => w.uniqueItemId == uniqueItemId).SplitTable(t => t.Take(2)).First(); + if (info != null) + { + if ((int)info.SystemOrderStatus > 3000) + { + continue; + } + switch (eventType) + { + case 1: + //退款 + info.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.全额退款; + break; + case 2: + //风控 + info.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单失效; + break; + case 4: + //负项调整 + info.SystemOrderStatus = Common.Models.Enums.SystemOrderStatus.订单失效; + break; + } + //修改数据 + db.Updateable(info).SplitTable(t => t.Take(2)).ExecuteCommand(); + } + else + { + //订单不存在 + } + } + }, ex => db.OnLog("美团异常订单处理", ex)); + return false; + }); + } + /// + /// 获取上次时间 + /// + /// + /// + private DateTime GetLastDateTime(string id) + { + return Client.Config.RuntimeCache.GetPublicValue("订单同步" + id, () => DateTime.MinValue); + } + /// + /// 记录上次时间 + /// + /// + /// + private void SetLastDateTime(string id, DateTime now) + { + Client.Config.RuntimeCache.SetPublicValue("订单同步" + id, now); + } + + /// + /// 收到需要订单更新事件 + /// + /// + /// + /// + private void MTRequest_OrderNoticeEvent(Lianmeng lianmeng, DateTime start, DateTime end) + { + var req = new MTRequest(lianmeng); + HandleOrder(lianmeng, req, start, end); + } + } +} diff --git a/Server/Timers/OldUserActivationTimer.cs b/Server/Timers/OldUserActivationTimer.cs new file mode 100644 index 0000000..f9fff64 --- /dev/null +++ b/Server/Timers/OldUserActivationTimer.cs @@ -0,0 +1,81 @@ +using Common.DbExtends.Extends; +using Common.DbExtends.Others; +using Common.Models.JsonModels; +using Common.Models.SubCountTables; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Utils; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Timers +{ + public class OldUserActivationTimer : MyTimer + { + private Client client = Client.SingleClient; + SqlSugar.SqlSugarClient Db { get { return client.Db; } } + private DateTime UpdateTime = DateTime.MinValue; + + protected override void Run(object state, bool timedOut) + { + var now = DateTime.Now; + if (now.Hour == 4 || now.Hour == 5) + { + if (UpdateTime == DateTime.MinValue || UpdateTime.Day != now.Day) + { + try + { + UpdateTime = DateTime.Now; + var robots = Db.Queryable().ToList(); + + var dbTables = Db.DbMaintenance.GetTableInfoList().Where(f => f.Name.StartsWith("userdata_")).ToList(); + if (dbTables.Count == 0) return; + + foreach (var robot in robots) + { + var rebateConfig = Db.GetRebateConfigById(robot.ConfigRebateId); + if (rebateConfig != null && rebateConfig.IsOldChange) + { + //排除掉设置的groupid和不自动归类的分组 + var groupIds = Db.Queryable() + .Where(f => f.Id != rebateConfig.GroupId && f.AotuSort == false) + .Select(f => f.Id) + .ToList(); + + var day = rebateConfig.UnuseDays; + var lastTime = DateTime.Now.AddDays(-day); + foreach (var item in dbTables) + { + var tabName = item.Name; + var db = Db; + db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new MySplitService(MySplitService.MySplitType.数量); + db.Updateable() + .SetColumns(f => f.GroupId == rebateConfig.GroupId) + //.Where(f => f.LastBuyTime.AddDays(day) < DateTime.Now && f.CreateTime.AddDays(day) < DateTime.Now && !groupIds.Contains(f.GroupId)) + .Where(f => f.LastBuyTime < lastTime && f.CreateTime < lastTime && !groupIds.Contains(f.GroupId)) + .SplitTable(tab => tab.InTableNames(tabName)) + .ExecuteCommand(); + } + + } + } + } + catch (Exception ex) + { + Db.OnLog("更改用户组", ex); + throw; + } + + } + } + + + + } + } + +} diff --git a/Server/Timers/PDDOrderTimer.cs b/Server/Timers/PDDOrderTimer.cs new file mode 100644 index 0000000..c31cdde --- /dev/null +++ b/Server/Timers/PDDOrderTimer.cs @@ -0,0 +1,308 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.MyClass.Caches; +using SqlSugar; + +namespace Server.Timers +{ + /// + /// 拼多多 + /// + public class PDDOrderTimer : MyTimer + { + public PDDOrderTimer() + { + PinduoRequest.OrderNoticeEvent += PinduoRequest_OrderNoticeEvent; + } + /// + /// 主动刷新订单 + /// + /// + /// + /// + private void PinduoRequest_OrderNoticeEvent(Lianmeng lianmeng, DateTime start, DateTime end) + { + this.HandleOrder(lianmeng, new PinduoRequest(lianmeng), start, end); + } + + readonly Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db => Client.Db; + + private readonly ConcurrentDictionary IsUpdateing = new ConcurrentDictionary(); + + protected override void Run(object state, bool timedOut) + { + var lianmengs = this.Db.Queryable().Where(w => w.LianmengType == Common.Models.Enums.LianmengType.拼多多联盟 && w.ExpirationTime > DateTime.Now).ToList(); foreach (var lianmeng in lianmengs) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + continue; + } + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if ((DateTime.Now - lastDateTime).TotalSeconds <= 60)//60秒间隔读取 + { + continue; + } + //启动线程读取 + ThreadPool.QueueUserWorkItem((o) => + { + HandleOrderLianmeng(o as Lianmeng); + }, lianmeng); + } + } + /// + /// 读取订单 + /// + /// + private void HandleOrderLianmeng(Lianmeng lianmeng) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + return; + } + //标记防止重复读取 + IsUpdateing[lianmeng.Id] = true; + try + { + var req = new PinduoRequest(lianmeng); + //上次读取时间 + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if (lastDateTime == DateTime.MinValue) + { + //如果没有时间,读取最近1个月的数据 + lastDateTime = DateTime.Now.AddDays(-30); + } + //req.CreatePosition("测试推广位"); + //本次读取时间 + var datetime = DateTime.Now; + //处理订单 + HandleOrder(lianmeng, req, lastDateTime, datetime); + //记录本次读取时间 + SetLastDateTime(lianmeng.Id + "", datetime); + } + catch (Exception ex) + { + Db.OnLog("拼多多订单同步2", ex); + } + finally + { + //删除防止重复读取标记 + + IsUpdateing.TryRemove(lianmeng.Id, out _); + if (lianmeng.ExpirationTime < DateTime.Now) + { + Db.Updateable(lianmeng).UpdateColumns(s => new { s.ExpirationTime }).ExecuteCommand(); + } + } + + } + /// + /// 处理订单 + /// + /// + /// + /// + /// + private void HandleOrder(Lianmeng lianmeng, PinduoRequest req, DateTime lastDateTime, DateTime datetime) + { + lastDateTime = lastDateTime.AddMinutes(-1); + req.OrderQuery(lastDateTime, datetime, (items) => + { + var db = Db; + db.UseTran(() => + { + foreach (var item in items) + { + var orderId = item["order_id"].Value(); + var createtime = Util.TimespanToDatatime(item["order_create_time"].Value()); + var modifyTime = item["order_modify_at"].Value(); + var orderStatus = (PDDOrderStatusEnum)item["order_status"].Value(); + var tablenames = db.GetTableName(createtime); + var info = db.Queryable().Where(w => w.order_id == orderId).SplitTable(t => t.InTableNames(tablenames)).First(); + if (info != null) + { + if (info.order_modify_at == modifyTime) + { + continue; + } + else if ((int)info.SystemOrderStatus > 3000) + { + continue; + } + //复制对象 + Util.CopyToObj(item, info); + //设置订单状态 + SetOrderState(db, lianmeng, orderStatus, info); + //修改数据 + db.Updateable(info).SplitTable(t => t.InTableNames(tablenames)).ExecuteCommand(); + } + else + { + info = new PddOrder(); + info.Id = Util.CreateID(createtime); + info.LianmengId = lianmeng.Id; + Util.CopyToObj(item, info); + SetOrderState(db, lianmeng, orderStatus, info); + db.Insertable(info).SplitTable().ExecuteCommand(); + } + } + }, ex => db.OnLog("拼多多订单同步", ex)); + return false; + }); + } + /// + /// 设置订单状态 + /// + /// + /// + /// + private void SetOrderState(SqlSugarClient db, Lianmeng lianmeng, PDDOrderStatusEnum orderStatus, PddOrder info) + { + switch (orderStatus) + { + case PDDOrderStatusEnum.已支付: + info.SystemOrderStatus = SystemOrderStatus.订单付款; + DocumentaryUser(db, info); + break; + case PDDOrderStatusEnum.已成团: + info.SystemOrderStatus = SystemOrderStatus.订单付款; + DocumentaryUser(db, info); + break; + case PDDOrderStatusEnum.确认收货: + info.SystemOrderStatus = SystemOrderStatus.订单收货; + CreateComplete(db, info); + break; + case PDDOrderStatusEnum.审核成功: + info.SystemOrderStatus = SystemOrderStatus.订单收货; + CreateComplete(db, info); + break; + case PDDOrderStatusEnum.审核失败: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case PDDOrderStatusEnum.已经结算: + info.SystemOrderStatus = SystemOrderStatus.订单结算; + CreateComplete(db, info); + break; + case PDDOrderStatusEnum.已处罚: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case PDDOrderStatusEnum.没有佣金: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + } + } + /// + /// 跟单用户 + /// + /// + private void DocumentaryUser(SqlSugarClient db, PddOrder info) + { + if (info.UserId > 0) + { + return; + } + //通过扩展ID,查到了用户 + if (long.TryParse(info.custom_parameters, out var queryId)) + { + var queryTabName = db.GetTableName(queryId); + QueryHist cache = db.Queryable().SplitTable(tab => tab.InTableNames(queryTabName)) + .Single(f => f.Id == queryId); + if (cache != null) + { + info.UserId = cache.UserId; + info.QueryCache = cache; + var user = db.GetUserData(info.UserId); + user.PayOrderCount++; + db.Save(user); + } + } + } + + /// + /// 生成订单完成信息 + /// + /// + private void CreateComplete(SqlSugarClient db, PddOrder info) + { + if (info.UserId <= 0) + { + return; + } + if (info.order_receive_time <= 0) + { + return; + } + if (info.order_pay_time <= DateTime.MinValue) + { + return; + } + if (info.PayStatus == OrderPayStatus.未支付) + { + info.PayStatus = OrderPayStatus.支付中; + var startTime = Util.TimespanToDatatime(info.order_receive_time + ""); + var endTime = Util.TimespanToDatatime(info.order_pay_time + ""); + //时间截取 + var timeConsuming = startTime - endTime; + DateTime thawingTime = DateTime.Now; + if (timeConsuming.TotalDays < 1) + { + var pubConfig = Db.GetPubConfig(); + if (pubConfig != null && pubConfig.ExtendDay > 0) + { + thawingTime = startTime.AddDays(pubConfig.ExtendDay); + } + } + var frozen = new FinishOrder() + { + CreateTime = DateTime.Now, + LianmengType = LianmengType.拼多多联盟, + OrderId = info.Id, + ThawingTime = thawingTime, + UserId = info.UserId + }; + db.Insertable(frozen).ExecuteCommand(); + //发送通知 + var tablenames = db.GetTableName(info.order_create_time); + if (info.UserId > 0 && info.QueryCache != null) + { + bool IsFreeze = (frozen.ThawingTime > DateTime.Now); + Client.SendClientMsg(info.QueryCache.RobotId, DeviceMessageType.拼多多订单更新, new { OrderId = info.Id, TableName = tablenames, IsFreeze = IsFreeze }); + } + } + } + /// + /// 获取上次时间 + /// + /// + /// + private DateTime GetLastDateTime(string id) + { + return Client.Config.RuntimeCache.GetPublicValue("订单同步" + id, () => DateTime.MinValue); + } + /// + /// 记录上次时间 + /// + /// + /// + private void SetLastDateTime(string id, DateTime now) + { + Client.Config.RuntimeCache.SetPublicValue("订单同步" + id, now); + } + + } +} diff --git a/Server/Timers/SessionTimer.cs b/Server/Timers/SessionTimer.cs new file mode 100644 index 0000000..d6df8dd --- /dev/null +++ b/Server/Timers/SessionTimer.cs @@ -0,0 +1,58 @@ +using Common.DbExtends.Extends; +using Common.Models.UnqTables; +using Common.Utils; +using Server.MyClass.Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Timers +{ + internal class SessionTimer : MyTimer + { + //public SessionTimer(Client Client) + //{ + // this.Client = Client; + //} + Client Client = Client.SingleClient; + + protected override void Run(object state, bool timedOut) + { + try + { + //更新客户端及超时消息 + var List1 = Client.OnlineDevices.Where(f => f.Value.ReadTime < DateTime.Now.AddMinutes(-10)).ToList(); + if (List1.Count > 0) + { + foreach (var item in List1) + { + Client.OnlineDevices.TryRemove(item.Key,out _); + } + } + var time = DateTime.Now.AddMinutes(-10); + var timeOutReplyMessage = Client.ReplyMessages.Where(f=>f.Value.CreateTime f.Value.RequestTime < DateTime.Now.AddHours(-3)).ToList(); + if (list2.Count > 0) + { + foreach (var item in list2) + { + Client.OnlineUsers.TryRemove(item.Key, out _); + } + } + + } + catch (Exception ex) + { + Client.Db.OnLog("Session更新",ex); + } + } + } +} diff --git a/Server/Timers/StoreBlackTimer.cs b/Server/Timers/StoreBlackTimer.cs new file mode 100644 index 0000000..e45a14f --- /dev/null +++ b/Server/Timers/StoreBlackTimer.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.Controllers.Help; +using Server.Utils; + +namespace Server.Timers +{ + /// + /// 商店黑名单同步 + /// + public class StoreBlackTimer : MyTimer + { + readonly Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db => Client.Db; + /// + /// 运行 + /// + /// + /// + protected override void Run(object state, bool timedOut) + { + //YZCloudApiHelper.GetBlacklist() + ReadBlacklist(Client.Config.RuntimeCache.GetPublicValue("玩家商店黑名单同步时间", () => DateTime.MinValue), false, (items, index, total) => + { + //Console.WriteLine("输出:" + index + "|" + total + "|" + items.Count); + var db = Db; + var syncTime = Client.Config.RuntimeCache.GetPublicValue("玩家商店黑名单同步时间", () => DateTime.MinValue); + if (syncTime != DateTime.MinValue) + { + syncTime = syncTime.AddMinutes(-1); + } + bool issyncAdd = false; + db.UseTran(() => + { + foreach (var item in items) + { + if (item.UpdateDateTime >= syncTime) + { + issyncAdd = true; + var platform = GetPlatform(item); + if (platform == LianmengType.无) + { + continue; + } + var info = db.Queryable().Where(w => w.Platform == platform && w.StoreId == item.StoreId).First(); + if (info == null) + { + info = new StoreBlacklist(); + info.Platform = platform; + info.StoreName = item.StoreName; + info.Remark = item.Remark; + info.UpdateTime = DateTime.Now; + info.IsDel = item.IsRemove; + info.IsCloud = true; + info.StoreId = item.StoreId; + db.Insertable(info).ExecuteCommand(); + } + else + { + if (info.IsDel) + { + //如果本地已经删除,则忽略。 + continue; + } + info.Remark = item.Remark; + info.UpdateTime = DateTime.Now; + info.IsDel = item.IsRemove; + info.IsCloud = true; + db.Updateable(info).ExecuteCommand(); + } + } + } + }, ex => db.OnLog("同步商店黑名单", ex)); + if (issyncAdd) + { + Client.Config.RuntimeCache.SetPublicValue("玩家商店黑名单同步时间", items.LastOrDefault().UpdateDateTime); + } + return false; + }); + } + + private LianmengType GetPlatform(CloudStoreBlacklistResult item) + { + return LianmengTypeHelper.GetPlatformType(item.Platform); + } + /// + /// 读取 + /// + /// + /// + public static void ReadBlacklist(DateTime updateDateTime, bool isAsc, Func, int, int, bool> callback) + { + var size = 1000; + var index = 1; + while (true) + { + var res = YZCloudApiHelper.GetStoreBlacklist(new StoreBlacklistSearchPagingInput() + { + PageIndex = index, + PageSize = size, + UserToken = "", + IsAsc = isAsc, + UpdateDateTime = updateDateTime, + AuditState = AuditStateEmun.Succee + }); + if (res == null || res.Datas.Count <= 0) + { + break; + } + if (callback?.Invoke(res.Datas, index, res.PageNumber) == true) + { + break; + } + if (index <= 0) + { + break; + } + index++; + } + } + } +} diff --git a/Server/Timers/SuningHuiTimer.cs b/Server/Timers/SuningHuiTimer.cs new file mode 100644 index 0000000..3b83cb2 --- /dev/null +++ b/Server/Timers/SuningHuiTimer.cs @@ -0,0 +1,315 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.MyClass.Caches; +using SqlSugar; + +namespace Server.Timers +{ + /// + /// 苏宁订单同步 + /// + public class SuningHuiTimer : MyTimer + { + public SuningHuiTimer() + { + SuningRequest.OrderNoticeEvent += WeipinhuiRequest_OrderNoticeEvent; + } + + private void WeipinhuiRequest_OrderNoticeEvent(Lianmeng lianmeng, DateTime start, DateTime end) + { + HandleOrder(lianmeng, new SuningRequest(lianmeng), start, end); + } + + readonly Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db => Client.Db; + + private readonly ConcurrentDictionary IsUpdateing = new ConcurrentDictionary(); + + protected override void Run(object state, bool timedOut) + { + var lianmengs = this.Db.Queryable().Where(w => w.LianmengType == Common.Models.Enums.LianmengType.苏宁联盟 && w.ExpirationTime > DateTime.Now).ToList(); + foreach (var lianmeng in lianmengs) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + continue; + } + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if ((DateTime.Now - lastDateTime).TotalSeconds <= 60)//60秒间隔读取 + { + continue; + } + //启动线程读取 + ThreadPool.QueueUserWorkItem((o) => + { + HandleOrderLianmeng(o as Lianmeng); + }, lianmeng); + //HandleOrderLianmeng(lianmeng); + } + } + /// + /// 读取订单 + /// + /// + private void HandleOrderLianmeng(Lianmeng lianmeng) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + return; + } + //标记防止重复读取 + IsUpdateing[lianmeng.Id] = true; + try + { + var req = new SuningRequest(lianmeng); + //上次读取时间 + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if (lastDateTime == DateTime.MinValue) + { + //如果没有时间,读取最近1个月的数据 + lastDateTime = DateTime.Now.AddDays(-30); + } + //本次读取时间 + var datetime = DateTime.Now; + //处理订单 + HandleOrder(lianmeng, req, lastDateTime, datetime); + //记录本次读取时间 + SetLastDateTime(lianmeng.Id + "", datetime); + } + catch (Exception ex) + { + Db.OnLog("苏宁订单同步2", ex); + } + finally + { + //删除防止重复读取标记 + + IsUpdateing.TryRemove(lianmeng.Id, out _); + if (lianmeng.ExpirationTime < DateTime.Now) + { + Db.Updateable(lianmeng).UpdateColumns(s => new { s.ExpirationTime }).ExecuteCommand(); + } + } + } + /// + /// 处理订单 + /// + /// + /// + /// + /// + private void HandleOrder(Lianmeng lianmeng, SuningRequest req, DateTime lastDateTime, DateTime datetime) + { + lastDateTime = lastDateTime.AddMinutes(-1); + req.OrderQuery(lastDateTime, datetime, (items) => + { + var db = Db; + db.UseTran(() => + { + foreach (var item in items) + { + var orderCode = item["orderCode"].Value(); + var orderDetailToken = item["orderDetail"].Children().FirstOrDefault(); + //goodsId 商品ID + var orderId = orderCode; + var orderTime = item["orderSubmitTime"].Value(); + var lastUpdateTime = item["orderLineStatusChangeTime"].Value(); + var tablenames = db.GetTableName(orderTime); + var info = db.Queryable() + .Where(w => w.orderCode == orderId) + .SplitTable(t => t.InTableNames(tablenames)) + .First(); + if (info != null) + { + if (lastUpdateTime == info.orderLineStatusChangeTime) + { + continue; + } + else if ((int)info.SystemOrderStatus > 3000) + { + continue; + } + //Util.CopyToObj(item, info); + Util.CopyToObj(orderDetailToken, info); + SetOrderState(db, lianmeng, info.orderLineStatus, info); + //修改数据 + db.Updateable(info).SplitTable(t => t.InTableNames(tablenames)).ExecuteCommand(); + } + else + { + info = new SnOrder(); + info.Id = Util.CreateID(orderTime); + info.orderCode = orderId; + info.LianmengId = lianmeng.Id; + Util.CopyToObj(orderDetailToken, info); + SetOrderState(db, lianmeng, info.orderLineStatus, info); + db.Insertable(info).SplitTable().ExecuteCommand(); + } + } + }, ex => Db.OnLog("苏宁订单同步", ex)); + return false; + }); + } + /// + /// 设置订单状态 + /// + /// + /// + /// + private void SetOrderState(SqlSugarClient db, Lianmeng lianmeng, string orderLineStatus, SnOrder info) + { + //转成小写 + var arr = orderLineStatus.ToLower().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries); + foreach (var state in arr) + { + switch (state) + { + case "c"://支付完成 + DocumentaryUser(db, info); + break; + case "r"://退款 + SalesReturn(db, lianmeng, info); + break; + case "d"://确认收货 + CreateComplete(db, info); + break; + case "wb"://待付尾款 + break; + case "rd"://已退定金 + break; + } + } + } + /// + /// 跟单用户 + /// + /// + private void DocumentaryUser(SqlSugarClient db, SnOrder info) + { + if (info.UserId > 0) + { + return; + } + //通过扩展ID,查到了用户 + if (long.TryParse(info.childAccountId, out var queryId)) + { + var queryTabName = db.GetTableName(queryId); + var cache = db.Queryable().SplitTable(tab => tab.InTableNames(queryTabName)) + .Single(f => f.Id == queryId); + if (cache != null) + { + info.UserId = cache.UserId; + info.QueryCache = cache; + var user = Db.GetUserData(info.UserId); + user.PayOrderCount++; + db.Save(user); + } + } + } + /// + /// 退货判断处理 + /// + /// + /// + private void SalesReturn(SqlSugarClient db, Lianmeng lianmeng, SnOrder info) + { + if (info.UserId <= 0) + { + return; + } + if (info.PayStatus != OrderPayStatus.已支付) + { + return; + } + db.PayPoint(info, info.QueryCache, info.Id, info.productName, true); + } + /// + /// 生成订单完成信息 + /// + /// + private void CreateComplete(SqlSugarClient db, SnOrder info) + { + if (info.UserId <= 0) + { + return; + } + if (string.IsNullOrWhiteSpace(info.confirmTime)) + { + return; + } + if (!DateTime.TryParse(info.confirmTime, out var cDateTime)) + { + return; + } + if (info.payTime <= DateTime.MinValue) + { + return; + } + if (info.PayStatus == OrderPayStatus.未支付) + { + info.PayStatus = OrderPayStatus.支付中; + var startTime = DateTime.Parse(info.confirmTime); + var endTime = info.payTime; + //时间截取 + var timeConsuming = startTime - endTime; + DateTime thawingTime = DateTime.Now; + if (timeConsuming.TotalDays < 1) + { + var pubConfig = Db.GetPubConfig(); + if (pubConfig != null && pubConfig.ExtendDay > 0) + { + thawingTime = startTime.AddDays(pubConfig.ExtendDay); + } + } + var frozen = new FinishOrder() + { + CreateTime = DateTime.Now, + LianmengType = LianmengType.苏宁联盟, + OrderId = info.Id, + ThawingTime = thawingTime, + UserId = info.UserId + }; + db.Insertable(frozen).ExecuteCommand(); + //发送通知 + var tablenames = db.GetTableName(info.orderSubmitTime); + if (info.UserId > 0 && info.QueryCache != null) + { + bool IsFreeze = (frozen.ThawingTime > DateTime.Now); + Client.SendClientMsg(info.QueryCache.RobotId, DeviceMessageType.苏宁订单更新, new { OrderId = info.Id, TableName = tablenames, IsFreeze = IsFreeze }); + } + } + } + /// + /// 获取上次时间 + /// + /// + /// + private DateTime GetLastDateTime(string id) + { + return Client.Config.RuntimeCache.GetPublicValue("订单同步" + id, () => DateTime.MinValue); + } + /// + /// 记录上次时间 + /// + /// + /// + private void SetLastDateTime(string id, DateTime now) + { + Client.Config.RuntimeCache.SetPublicValue("订单同步" + id, now); + } + } +} diff --git a/Server/Timers/SystemTimer.cs b/Server/Timers/SystemTimer.cs new file mode 100644 index 0000000..8d7f6a9 --- /dev/null +++ b/Server/Timers/SystemTimer.cs @@ -0,0 +1,32 @@ +using Common.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +namespace Server.Timers +{ + + public class SystemTimer : MyTimer + { + public SystemTimer() + { + Client.SingleClient.Events.ExitWinform += Events_ExitWinform; + } + + private void Events_ExitWinform(object sender, EventArgs e) + { + SaveConfig(); + } + + protected override void Run(object state, bool timedOut) + { + SaveConfig(); + } + private void SaveConfig() + { + Client.SingleClient.Db.SetMapValue("系统缓存", Client.SingleClient.Config.RuntimeCache); + } + } +} diff --git a/Server/Timers/TbSpecialTimer.cs b/Server/Timers/TbSpecialTimer.cs new file mode 100644 index 0000000..3654778 --- /dev/null +++ b/Server/Timers/TbSpecialTimer.cs @@ -0,0 +1,106 @@ +using Common.Models.UnqTables; +using Common.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Requests.Lianmengs; +using Common.Models.SubValueTables; +using SqlSugar; +using System.Threading; +using Common.Models.SubTables; +using Common.Utils.Extends; + +namespace Server.Timers +{ + public class TbSpecialTimer : MyTimer + { + private DateTime DeleteTime = DateTime.MinValue; + private Client client = Client.SingleClient; + private int UpdaetCount = 0; + private SqlSugar.SqlSugarClient Db { get { return client.Db; } } + + protected override void Run(object state, bool timedOut) + { + try + { + UpdaetCount++; + var time = DateTime.Now.AddMinutes(-60); + + //第一步:每天删除一次三天以前的查询记录 + if (DeleteTime.Day != DateTime.Now.Day) + { + DeleteTime = DateTime.Now; + Db.Deleteable().Where(f => f.CreateTime < DateTime.Now.AddDays(-3)); + } + + //第二步:筛选时间,优先把最近30分钟筛选出来,其他的一天查一次 + var exp = Expressionable.Create(); + if (UpdaetCount == 600) //10小时了,同步下当天的 + { + exp.And(f => f.CreateTime >= DateTime.Now.AddDays(-1)); + } + else if (UpdaetCount != 1440) //没到24小时,仅同步最近30分钟的 + { + exp.And(f => f.CreateTime >= DateTime.Now.AddMinutes(-30)); + } + + var list = Db.Queryable().Where(exp.ToExpression()).OrderBy(f => f.Id, SqlSugar.OrderByType.Asc).ToList(); + if (list.Count > 0) + { + foreach (var item in list) + { + var lm = Db.GetLianmeng(item.LianmengId); + if (lm != null && lm.ExpirationTime > DateTime.Now) + { + + var req = new TaobaoRequest(lm); + + var type = item.UserType.ToExternalType(); + + var data = req.QuerySpecial($"{item.Username}", type); + if (data != null && data["inviter_list"] != null && data["inviter_list"].Count() > 0) + { + foreach (var v in data["inviter_list"]) + { + var special_id = (long)data["special_id"]; + var tableName = Db.GetTableName(req.Lianmeng.Id); + var rst = Db.GetTbSpecial(item.UserId, item.LianmengId); + if (rst == null) + { + rst = new TbSpecial() + { + SpecialId = special_id, + LianmengId = item.LianmengId, + UpdateTime = DateTime.Now, + UserId = item.UserId + }; + Db.Save(rst); + } + //删掉 + Db.Deleteable(item).ExecuteCommand(); + break; + } + } + else + { + item.SyncTime = DateTime.Now; + Db.Updateable(item).ExecuteCommand(); + } + } + + Thread.Sleep(1000); + } + } + } + catch (Exception ex) + { + Db.OnLog("淘宝会员关系同步", ex); + } + } + + + } +} diff --git a/Server/Timers/TbUpdateRefundOrderTimer.cs b/Server/Timers/TbUpdateRefundOrderTimer.cs new file mode 100644 index 0000000..f37412c --- /dev/null +++ b/Server/Timers/TbUpdateRefundOrderTimer.cs @@ -0,0 +1,258 @@ +using Common.DbExtends.Extends; +using Common.Models.UnqTables; +using Common.Requests.Entitys.Taobao; +using Common.Requests.Lianmengs; +using Common.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.Models.Enums; +using Common.Models.SubTables; +using Newtonsoft.Json.Linq; +using SqlSugar; +namespace Server.Timers +{ + /// + /// 通过Cookies更新淘宝维权退款订单 + /// + internal class TbUpdateRefundOrderTimer : MyTimer + { + + public TbUpdateRefundOrderTimer() + { + TaobaoRequest.OrderRefundNoticeEvent += TaobaoRequest_OrderRefundNoticeEvent; + } + + private void TaobaoRequest_OrderRefundNoticeEvent(TaobaoRequest req, Newtonsoft.Json.Linq.JToken Orders, + bool NextPage, DateTime EndTime) + { + var db = Client.SingleClient.Db; + db.UseTran(() => + { + foreach (var item in Orders) + { + var tbTradeId = item["tbTradeId"].ToString(); + var tbTradeParentId = item["tbTradeParentId"].ToString(); + var itemId = item["itemId"].ToString(); + var oldRefundStatus = int.Parse(item["refundStatus"].ToString()); + //查询3个月内的订单信息 + var tbOrder = db.Queryable().SplitTable(DateTime.Now.AddMonths(-3), DateTime.Now) + .Where(w => w.trade_id == tbTradeId).First(); + if (tbOrder == null) + { + //这里表示订单还未同步,就不处理 + continue; + } + var tabName = db.GetTableName(DateTime.Parse(item["refundCreateTime"].ToString())); + var tbrOrder = db.Queryable() + .Where(f => f.tbTradeId == tbTradeId) + .SplitTable(tab => tab.InTableNames(tabName)) + .First(); + if (tbrOrder == null) + { + tbrOrder = new TbROrder() + { + tbTradeId = tbTradeId, + tbTradeParentId = tbTradeParentId + }; + } + else if (oldRefundStatus == tbrOrder.refundStatus) + { + ///状态一样,直接跳过 + continue; + } + + Util.CopyToObj(item, tbrOrder); + SetState(db, item, tbrOrder, tbOrder); + if (tbOrder.Id == 0) + { + tbOrder.Id = Util.CreateID(tbrOrder.refundCreateTime); + db.Insertable(tbOrder).SplitTable().ExecuteCommand(); + } + else + { + db.Updateable(tbOrder).SplitTable(t => t.InTableNames(tabName)).ExecuteCommand(); + } + //更新订单信息 + var tbtabNames = db.GetTableName(tbOrder.tk_create_time); + db.Updateable(tbOrder).SplitTable(s => s.InTableNames(tbtabNames)).ExecuteCommand(); + } + }, ex => Client.SingleClient.Db.OnLog("更新淘宝退款订单", ex)); + } + + /// + /// 处理退单状态 + /// + /// + /// + private void SetState(SqlSugarClient db, JToken item, TbROrder tbrOrder, TbOrder tbOrder) + { + if (tbOrder == null) + { + return; + } + switch (tbrOrder.showRefundStatus) + { + case "维权创建": + tbOrder.SystemOrderStatus = SystemOrderStatus.订单退款中; + //退款 + SalesReturn(db, tbOrder); + break; + case "维权成功": + WeiQuanSucceed(tbrOrder, tbOrder); + break; + case "维权失败": + HandlePayPoint(db, tbOrder); + break; + case "等待处理": + tbOrder.SystemOrderStatus = SystemOrderStatus.订单退款中; + break; + case "维权成功,等待补扣佣金": + break; + case "维权成功,佣金补扣成功": + WeiQuanSucceed(tbrOrder, tbOrder); + break; + case "维权失败,等待商家返还佣金": + break; + case "维权失败,商家佣金返还成功": + HandlePayPoint(db, tbOrder); + break; + } + } + /// + /// 处理支付积分给用户 + /// + private void HandlePayPoint(SqlSugarClient db, TbOrder tbOrder) + { + if (tbOrder.PayStatus != OrderPayStatus.已支付) + { + return; + } + db.PayPoint(tbOrder, tbOrder.QueryCache, tbOrder.Id, tbOrder.item_title, false); + } + /// + /// 维权成功 + /// + /// + /// + private void WeiQuanSucceed(TbROrder tbrOrder, TbOrder tbOrder) + { + if (Math.Abs(tbrOrder.alipayTotalPrice - tbrOrder.refundFee) > 0) + { + tbOrder.SystemOrderStatus = SystemOrderStatus.部分退款; + } + else + { + tbOrder.SystemOrderStatus = SystemOrderStatus.全额退款; + } + } + /// + /// 退货判断处理 + /// + /// + private void SalesReturn(SqlSugarClient db, TbOrder tbOrder) + { + if (tbOrder.UserId <= 0) + { + return; + } + if (tbOrder.PayStatus != OrderPayStatus.已支付) + { + return; + } + db.PayPoint(tbOrder, tbOrder.QueryCache, tbOrder.Id, tbOrder.item_title, true); + } + protected override void Run(object state, bool timedOut) + { + var datas = Client.SingleClient.Db.Queryable().Where(f => f.LianmengType == Common.Models.Enums.LianmengType.淘宝联盟 && f.IsCookiValid).ToList(); + foreach (var item in datas) + { + try + { + var req = new TaobaoRequest(item); + var starTime = DateTime.Now.AddMonths(-1); + var endTime = DateTime.Now; + //由于阿里妈妈爬虫,无法根据更新时间,所以每次更新下最近30天即可 + req.UpdateRefundOrder(starTime, endTime); + //处理官方API的处罚订单查询 + HandleApiRefundOrder(req, starTime); + } + catch (Exception ex) + { + if (ex.Message.Contains("cookie已失效")) + { + Client.SingleClient.Db.Updateable(item).ExecuteCommand(); + } + Client.SingleClient.Db.OnLog("更新淘宝退款订单", ex); + } + } + } + /// + /// 处理官方API的处罚订单查询 + /// + /// + /// + private void HandleApiRefundOrder(TaobaoRequest req, DateTime startDateTime) + { + req.ReadOrderRefundList(startDateTime, items => + { + var db = Client.SingleClient.Db; + db.UseTran(() => + { + foreach (var token in items) + { + var punish_status = token["punish_status"].Value(); + var tbTradeId = token["tb_trade_id"].Value(); + var tabName = db.GetTableName(DateTime.Parse(token["tk_trade_create_time"].ToString())); + var tbPunishOrder = db.Queryable().Where(f => f.tb_trade_id == tbTradeId) + .SplitTable(t => t.InTableNames(tabName)) + .First(); + if (tbPunishOrder == null) + { + tbPunishOrder = new TbPunishOrder(); + + } + Util.CopyToObj(token, tbPunishOrder); + if (tbPunishOrder.Id <= 0) + { + tbPunishOrder.Id = Util.CreateID(tbPunishOrder.tk_trade_create_time); + db.Insertable(tbPunishOrder).SplitTable().ExecuteCommand(); + } + else + { + db.Updateable(tbPunishOrder).SplitTable(t => t.InTableNames(tabName)).ExecuteCommand(); + } + var tbOrder = db.Queryable() + .Where(f => f.trade_id == tbTradeId) + .SplitTable(DateTime.Now.AddMonths(-3), DateTime.Now) + .First(); + if (tbOrder == null) + { + //订单不存在 + continue; + } + switch (punish_status) + { + case 0://冻结 + tbOrder.SystemOrderStatus = SystemOrderStatus.违规订单; + SalesReturn(db, tbOrder);//收回已经支付给用户的积分 + break; + case 1://解冻 + if (tbOrder.PayStatus == OrderPayStatus.已扣除) + { + HandlePayPoint(db, tbOrder);//在把积分给客户 + } + break; + } + //更新订单信息 + var tbtabNames = db.GetTableName(tbOrder.tk_create_time); + db.Updateable(tbOrder).SplitTable(s => s.InTableNames(tbtabNames)).ExecuteCommand(); + } + }, ex => db.OnLog("同步处罚订单查询", ex)); + return false; + }); + } + } +} diff --git a/Server/Timers/TbUpdateorderTimer.cs b/Server/Timers/TbUpdateorderTimer.cs new file mode 100644 index 0000000..8787f6a --- /dev/null +++ b/Server/Timers/TbUpdateorderTimer.cs @@ -0,0 +1,346 @@ +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using Newtonsoft.Json; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.IO; +using System.Xml.Linq; +using System.Xml; +using Common.DbExtends.Extends; +using Common.Models.SubValueTables; +using Server.Utils; +using Server.Configs; +using Server.MyClass.Caches; + +namespace Server.Timers +{ + + public class TbUpdateorderTimer : MyTimer + { + + private Dictionary IsUpdateing = new Dictionary(); + private Client client = Client.SingleClient; + SqlSugar.SqlSugarClient Db { get { return client.Db; } } + public TbUpdateorderTimer() + { + TaobaoRequest.OrderNoticeEvent += TaobaoRequest_OrderNoticeEvent; + } + + + private void TaobaoRequest_OrderNoticeEvent(TaobaoRequest req, Newtonsoft.Json.Linq.JToken Orders, TBOrderScene OrderScene, bool IsNext, DateTime EndTime) + { + if (Orders != null && Orders.Count() > 0) + { + var Db = Client.SingleClient.Db; + try + { + Db.BeginTran(); + foreach (var item in Orders) + { + var tk_create_time = DateTime.Parse(item["tk_create_time"].ToString()); + var table_name = Db.GetTableName(tk_create_time); + var order = Db.Queryable() + .Where(f => f.trade_id == item["trade_id"].ToString() && f.trade_parent_id == item["trade_parent_id"].ToString()) + .SplitTable(t => t.InTableNames(table_name)) + .First(); + + //新订单 + if (order == null) + { + order = new TbOrder() + { + trade_id = item["trade_id"].ToString(), + trade_parent_id = item["trade_parent_id"].ToString(), + SystemOrderStatus = SystemOrderStatus.订单创建 + }; + } + //跳过已更新的订单 + else if (order.modified_time == item["modified_time"].ToString()) continue; + //跳过已完成订单(防止重复结算) + else if ((int)order.SystemOrderStatus > 2000) continue; + + order.LianmengId = req.Lianmeng.Id; + Util.CopyToObj(item, order); + + //查找用户对应关系,并查找用户的查询记录 + if (order.tk_status == TkStatus.订单付款) + { + if (order.UserId == 0) + { + if (order.special_id != 0) + { + var tb_special_table_name = Db.GetTableName(req.Lianmeng.Id); + var tbSpecial = Db.Queryable().Where(f => f.SpecialId == order.special_id).SplitTable(t => t.InTableNames(tb_special_table_name)).First(); + if (tbSpecial != null) + { + order.UserId = tbSpecial.UserId; + var pid = $"{order.site_id}_{order.adzone_id}"; + var cache = Db.GetQueryHist(order.UserId, order.item_id, order.LianmengId, pid); + if (cache != null)//找到查询记录直接复制 + { + order.QueryCache = cache; + } + } + } + else + { + var lastId = order.trade_parent_id.Substring(order.trade_parent_id.Length - 6); + //通过聊天记录查一次 + var pid = $"{order.site_id}_{order.adzone_id}"; + var cache = Db.GetQueryHist(f => f.ItemId == order.item_id && f.TaobaoLastid == lastId && f.Pid == pid && f.LianmegnId == req.Lianmeng.Id && f.ItemType == LianmengType.淘宝联盟); + if (cache != null) + { + order.QueryCache = cache; + order.UserId = cache.UserId; + } + else + { + //如果查询出来,只有一条记录 + var cacheTmp = Db.GetQueryHist(f => f.ItemId == order.item_id && f.TaobaoLastid == "" && f.Pid == pid && f.LianmegnId == req.Lianmeng.Id && f.ItemType == LianmengType.淘宝联盟); + if (cacheTmp != null) + { + order.QueryCache = cacheTmp; + order.UserId = cacheTmp.UserId; + } + } + } + //首次找到后用户,对他的付款订单数增量 + if (order.UserId != 0) + { + var user = Db.GetUserData(order.UserId); + user.PayOrderCount++; + Db.Save(user); + + //可是查询记录没找到,自动创建一条查询记录(不入库),直接保存到ORDER里面,便于记录最后佣金 + if (order.QueryCache == null) + { + var userData = Db.GetUserData(order.UserId); + var robotData = Db.GetRobot(userData.RobotId); + if (robotData != null) + { + var rConfig = Db.GetRebateConfigById(robotData.ConfigRebateId); + var query = new QueryHist(userData, order.item_id, LianmengType.淘宝联盟, order.LianmengId, $"{order.site_id}_{order.adzone_id}", order.pub_share_pre_fee); + if (Db.CalculationData(query, rConfig)) + { + order.QueryCache = query; + var bConfig = Db.GetBaseConfigById(robotData.ConfigBaseId); + if (bConfig != null) + { + Db.CalculationData(query, bConfig); + } + } + } + } + } + } + } + else if (order.tk_status == TkStatus.订单失效) + { + order.SystemOrderStatus = SystemOrderStatus.订单失效; + if (order.UserId > 0) + { + var UserData = Db.GetUserData(order.UserId); + UserData.PayOrderCount++; + Db.Save(UserData); + } + } + + //对数据库更新 + var orderId = order.Id > 0 ? order.Id : Util.CreateID(order.tk_create_time); + if (order.Id == 0) + { + order.Id = orderId; + Db.Insertable(order).SplitTable().ExecuteCommand(); + + } + else Db.Updateable(order).SplitTable(it => it.InTableNames(table_name)).ExecuteCommand(); + + + + FinishOrder frozen = null; + //改变状态 + switch (order.tk_status) + { + case TkStatus.订单成功: + case TkStatus.订单结算: + order.SystemOrderStatus = SystemOrderStatus.订单结算; + if (order.UserId > 0) + { + if (order.PayStatus == OrderPayStatus.未支付) + { + order.PayStatus = OrderPayStatus.支付中; + //时间截取 + var TimeConsuming = DateTime.Parse(order.tk_earning_time) - DateTime.Parse(order.tk_paid_time); + DateTime ThawingTime = DateTime.Now; + if (TimeConsuming.TotalDays < 1) + { + var pubConfig = Db.GetPubConfig(); + if (pubConfig != null && pubConfig.ExtendDay > 0) + { + ThawingTime = DateTime.Parse(order.tk_earning_time).AddDays(pubConfig.ExtendDay); + } + } + frozen = new FinishOrder() { CreateTime = DateTime.Now, LianmengType = LianmengType.淘宝联盟, OrderId = order.Id, ThawingTime = ThawingTime, UserId = order.UserId }; + } + } + + break; + case TkStatus.订单付款: + order.SystemOrderStatus = SystemOrderStatus.订单付款; + + break; + case TkStatus.订单失效: + order.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case TkStatus.未知: + break; + default: + break; + } + Db.Updateable(order).SplitTable(it => it.InTableNames(table_name)).ExecuteCommand(); + + if (frozen != null) Db.Insertable(frozen).ExecuteCommand(); + + if (order.UserId > 0 && order.QueryCache != null) + { + bool IsFreeze = (frozen != null && frozen.ThawingTime > DateTime.Now); + client.SendClientMsg(order.QueryCache.RobotId, DeviceMessageType.淘宝订单更新, new { OrderId = order.Id, TableName = table_name, IsFreeze = IsFreeze }); + } + + } + + + Db.CommitTran(); + } + catch (Exception ex) + { + Db.RollbackTran(); + Db.OnLog("淘宝订单同步", ex); + return; + } + } + + if (!IsNext) + { + var tbConfig = Client.SingleClient.Config.RuntimeCache.TbDatas.FirstOrDefault(f => f.LianmengId == req.Lianmeng.Id); + switch (OrderScene) + { + case TBOrderScene.常规订单: + tbConfig.UpdateTime1 = EndTime; + break; + case TBOrderScene.渠道订单: + break; + case TBOrderScene.会员运营订单: + tbConfig.UpdateTime3 = EndTime; + break; + default: + break; + } + + } + + } + public RuntimeCache updateOrderCache { get { return Client.SingleClient.Config.RuntimeCache; } } + protected override void Run(object state, bool timedOut) + { + try + { + //第一步:获取可以更新的联盟集合 + var List = Db.Queryable().WithCache().Where(f => f.LianmengType == Common.Models.Enums.LianmengType.淘宝联盟 && f.ExpirationTime > DateTime.Now).ToList(); + foreach (var item in List) + { + //更新中跳过 + if (IsUpdateing.ContainsKey(item.Id) && IsUpdateing[item.Id]) continue; + + + //读取配置 + TaobaoUpdateCacheInfo tbConfig; + tbConfig = Client.SingleClient.Config.RuntimeCache.TbDatas.FirstOrDefault(f => f.LianmengId == item.Id); + if (tbConfig == null) + { + tbConfig = new Configs.TaobaoUpdateCacheInfo() { LianmengId = item.Id }; + updateOrderCache.TbDatas.Add(tbConfig); + } + + if (IsUpdateing.ContainsKey(item.Id)) + { + ////60内秒内更新过,跳过 + if (tbConfig.UpdateTimer7.AddSeconds(60) > DateTime.Now) continue; + } + + IsUpdateing[item.Id] = true; + + Task.Factory.StartNew(() => + { + try + { + tbConfig.UpdateTimer7 = DateTime.Now; ; + + + //第三步:开始更新,并从最后一次更新时间中更新 - 普通订单和会员运营订单 + TaobaoRequest req = new TaobaoRequest(item); + + foreach (TBOrderScene em in Enum.GetValues(typeof(TBOrderScene))) + { + if (em == TBOrderScene.常规订单) + { + if (tbConfig.UpdateTime1 > tbConfig.UpdateTimer7) + { + //throw new Exception("开始时间不能大于结束时间"); + tbConfig.UpdateTime1= tbConfig.UpdateTimer7; + } + var ErrorMsg = req.UpdateOrder(tbConfig.UpdateTime1, tbConfig.UpdateTimer7, em); + if (!string.IsNullOrEmpty(ErrorMsg)) + { + Db.OnLog("淘宝订单更新", ErrorMsg, LogType.错误); + } + } + else if (em == TBOrderScene.会员运营订单) + { + if (tbConfig.UpdateTime3 > tbConfig.UpdateTimer7) + { + //throw new Exception("开始时间不能大于结束时间"); + tbConfig.UpdateTime3 = tbConfig.UpdateTimer7; + } + var ErrorMsg = req.UpdateOrder(tbConfig.UpdateTime3, tbConfig.UpdateTimer7, em); + if (!string.IsNullOrEmpty(ErrorMsg)) + { + Db.OnLog("淘宝订单更新", ErrorMsg, LogType.错误); + } + } + } + } + catch (Exception) + { + //client.Event.OnLog($"更新淘宝订单({item.Nickname}({item.Username}))发生错误:{ex.Message}", "淘宝", ex); + } + finally + { + IsUpdateing[item.Id] = false; + } + }); + Thread.Sleep(1000); + } + + } + catch (Exception) + { + + } + } + + + + + } + + +} diff --git a/Server/Timers/UpdateCookiesTimer.cs b/Server/Timers/UpdateCookiesTimer.cs new file mode 100644 index 0000000..f029f0a --- /dev/null +++ b/Server/Timers/UpdateCookiesTimer.cs @@ -0,0 +1,158 @@ +using Common.DbExtends.Extends; +using Common.Models.UnqTables; +using Common.Utils; +using CsharpHttpHelper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Server.Timers +{ + public class UpdateCookiesTimer : MyTimer + { + + private static string[] Urls = new string[] + { + "http://www.alimama.com/index.htm", + "https://ssp.tanx.com/api/userinfo?callback=userInfoCallback", + "http://ssp.tanx.com/api/userinfo?callback=userInfoCallback", + "https://media.alimama.com/user/base_info.htm", + "https://media.alimama.com/verify/risk.htm", + "https://media.alimama.com/", + "https://media.alimama.com/product.htm", + "https://pub.alimama.com/myunion.htm", + "https://tbk.bbs.taobao.com/list.html", + "https://pub.alimama.com/manage/overview/index.htm", + "https://pub.alimama.com/common/getUnionPubContextInfo.json", + "https://media.alimama.com/violationu2/violation2_page.json?r=mx_794&toPage={pageIndex}&pageSize={pageSize}", + "https://pub.alimama.com/third/manage/record/adzone.htmhttps://pub.alimama.com/third/manage/record/site.htm?tab=self_web_site",//媒体备案管理 - 自有平台(网站) + "https://pub.ama.com/third/manage/record/site.htm?tab=self_web_site&sencecode=self_app&pageNo={pageIndex}&pageSize={pageSize}",//媒体备案管理 - 自有平台(App客户端) + "https://pub.alimama.com/third/manage/record/site.htm?tab=self_web_site&sencecode=self_pc_client&pageNo={pageIndex}&pageSize={pageSize}",//媒体备案管理 - 自有平台(PC客户端) + "https://pub.alimama.com/third/manage/record/site.htm?tab=self_web_site&sencecode=self_offline&pageNo={pageIndex}&pageSize={pageSize}",//媒体备案管理 - 自有平台(线下阵地) + "https://pub.alimama.com/third/manage/record/adzone.htm",//推广位 + "https://pub.alimama.com/third/manage/record/site.htm?tab=all",//媒体备案管理 - 全部 + "https://pub.alimama.com/third/manage/record/site.htm?tab=self_web_site&sencecode=self_miniprogram&pageNo={pageIndex}&pageSize={pageSize}",//媒体备案管理 - 自有平台(小程序/快应用) + "https://pub.alimama.com/third/manage/record/site.htm?tab=self_web_site&sencecode=self_operating_system&pageNo=1&pageSize={pageSize}",//媒体备案管理 - 自有平台(操作系统) + "https://pub.alimama.com/third/manage/record/site.htm?tab=self_web_site&sencecode=self_hardware_device&pageNo=1&pageSize={pageSize}",//媒体备案管理 - 自有平台(硬件设备) + "https://pub.alimimama.com/third/manage/record/site.htm?tab=other_social",//媒体备案管理 - 他方平台(社交平台) + "https://pub.alimama.com/third/manage/record/site.htm?tab=other_social&sencecode=other_content&pageNo=1&pageSize={pageSize}",//媒体备案管理 - 他方平台(内容平台) + "https://pub.alimama.com/third/manage/record/site.htm?tab=traffic_purchasing",//媒体备案管理 - 无自有阵地 + "http://c.tanx.com/", + //"https://pub.alimama.com/openapi/json2/1/gateway.unionpub/xt.entry.json",////内容库查询 + "https://pub.alimama.com/manage/user/new_privilege.htm", + "https://media.alimama.com/violationu2/violation2_page.json?toPage={pageIndex}&pageSize={pageSize}&punishStatus={punishStatus}", + "https://pub.alimama.com/manage/overview/index.htm", + "https://pub.alimama.com/openapi/param2/1/gateway.unionpub/report.getTbkOrderDetails.json?t={timespan}000&_tb_token_={tb_token}&jumpType=0&positionIndex=&pageNo={pageIndex}&startTime={开始时间}&endTime={结束时间}&queryType{queryType}&tkStatus=&memberType=&pageSize={pageSize}", + "https://pub.alimama.com/common/getUnionPubContextInfo.json", + "https://media.alimama.com/violationu2/warning_instance_page.json?r=mx_544&toPage={pageIndex}&pageSize={pageSize}", + "https://everyservice.cdn.taobao.com/widget/queryServiceStrategy", + "https://everyhelp.taobao.com/version/getWidgetVersion", + "https://media.alimama.com/violation/violation_list.htm", + "https://c.tanx.com/" + }; + + private Client client = Client.SingleClient; + + protected override void Run(object state, bool timedOut) + { + //通过cookise更新不需要多线程,防止速度过快,被限制IP + try + { + var lianmengs = client.Db.Queryable().Where(f => f.LianmengType == Common.Models.Enums.LianmengType.淘宝联盟 && f.IsCookiValid == true).ToList(); + foreach (var item in lianmengs) + { + UpdateAlimamaCookie(item); + Thread.Sleep(1000); + } + + } + catch (Exception ex) + { + client.Db.OnLog("更新Cookies异常",ex); + } + } + + /// + /// 更新Cookies + /// + /// 需要更新的联盟账号 + private void UpdateAlimamaCookie(Lianmeng lm) + { + var url = Urls[new Random(Guid.NewGuid().GetHashCode()).Next(0,Urls.Length)]; + if (UpdateCookies(lm, url, string.Empty)) + { + client.Db.Save(lm); + } + } + + /// + /// 更新Cookies + /// + /// 更新哪个联盟 + /// 需要更新的URL + /// POST数据 + /// 如果有更新,会返回true + private bool UpdateCookies(Lianmeng lm,string url,string postData) + { + var flag = false; + try + { + //当前页码 + var pageIndex = new Random(Guid.NewGuid().GetHashCode()).Next(1, 5).ToString(); + //每页显示条数 + var pageSize = "40"; + //提取tb_token + var tb_token = HttpExtend.GetCookiesValue("_tb_token", lm.Cookies); + //获取punishStatus + var punishStatus = new Random(Guid.NewGuid().GetHashCode()).Next(1, 9).ToString(); + + + url = url.Replace("{pageSize}", pageSize) + .Replace("{pageIndex}", pageIndex) + .Replace("{tb_token}", tb_token) + .Replace("{punishStatus}", punishStatus) + .Replace("{开始时间}", DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd")) + .Replace("{开始时间}", DateTime.Now.ToString("yyyy-MM-dd")) + .Replace("{timespan}", HttpExtend.GetTimeStamp()) + .Replace("{12位随机}", Util.GetTimespan(DateTime.Now).ToString()); + + HttpHelper http = new HttpHelper(); + HttpItem item = new HttpItem() + { + URL = url, + Method = string.IsNullOrEmpty(postData) ? "get" : "post", + IsToLower = false, + Cookie = lm.Cookies, + Referer = "http://pub.alimama.com/myunion.htm", + Postdata = postData, + Timeout = 3000, + ReadWriteTimeout = 3000, + UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER", + ContentType = "application/x-www-form-urlencoded", + Allowautoredirect = true, + ProtocolVersion = System.Net.HttpVersion.Version11 + }; + var result = http.GetHtml(item); + + if (result != null && result.Html.Contains("noLogin\":true")) + { + lm.IsCookiValid = false; + flag = true; + } + var cookies = result.Cookie; + if (!string.IsNullOrEmpty(cookies)) + { + lm.Cookies = result.UpdateCookies(result.Cookie); + flag = true; + } + } + catch (Exception) + { + } + return flag; + } + } +} diff --git a/Server/Timers/WeiPinHuiTimer.cs b/Server/Timers/WeiPinHuiTimer.cs new file mode 100644 index 0000000..62fe6a2 --- /dev/null +++ b/Server/Timers/WeiPinHuiTimer.cs @@ -0,0 +1,366 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.SubTables; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using Newtonsoft.Json.Linq; +using Server.MyClass.Caches; +using SqlSugar; + +namespace Server.Timers +{ + /// + /// 唯品会订单同步 + /// + public class WeiPinHuiTimer : MyTimer + { + public WeiPinHuiTimer() + { + WeipinhuiRequest.OrderNoticeEvent += WeipinhuiRequest_OrderNoticeEvent; + } + + private void WeipinhuiRequest_OrderNoticeEvent(Lianmeng lianmeng, DateTime start, DateTime end) + { + HandleOrder(lianmeng, new WeipinhuiRequest(lianmeng), start, end); + } + + readonly Client Client = Client.SingleClient; + private SqlSugar.SqlSugarClient Db => Client.Db; + + private readonly ConcurrentDictionary IsUpdateing = new ConcurrentDictionary(); + + protected override void Run(object state, bool timedOut) + { + var lianmengs = this.Db.Queryable().Where(w => w.LianmengType == Common.Models.Enums.LianmengType.唯品会联盟 && w.ExpirationTime > DateTime.Now).ToList(); + foreach (var lianmeng in lianmengs) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + continue; + } + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if ((DateTime.Now - lastDateTime).TotalSeconds <= 60)//60秒间隔读取 + { + continue; + } + //启动线程读取 + ThreadPool.QueueUserWorkItem((o) => + { + HandleOrderLianmeng(o as Lianmeng); + }, lianmeng); + //HandleOrderLianmeng(lianmeng); + } + } + /// + /// 读取订单 + /// + /// + private void HandleOrderLianmeng(Lianmeng lianmeng) + { + //防止重复读取 + if (IsUpdateing.ContainsKey(lianmeng.Id)) + { + return; + } + //标记防止重复读取 + IsUpdateing.TryAdd(lianmeng.Id, true); + try + { + var req = new WeipinhuiRequest(lianmeng); + //上次读取时间 + var lastDateTime = GetLastDateTime(lianmeng.Id + ""); + if (lastDateTime == DateTime.MinValue) + { + //如果没有时间,读取最近1个月的数据 + lastDateTime = DateTime.Now.AddDays(-30); + } + //req.CreatePosition("测试推广位"); + //本次读取时间 + var datetime = DateTime.Now; + //处理订单 + HandleOrder(lianmeng, req, lastDateTime, datetime); + //记录本次读取时间 + SetLastDateTime(lianmeng.Id + "", datetime); + } + catch (Exception ex) + { + Db.OnLog("唯品会订单同步2", ex); + } + finally + { + //删除防止重复读取标记 + IsUpdateing.TryRemove(lianmeng.Id, out _); + if (lianmeng.ExpirationTime < DateTime.Now) + { + Db.Updateable(lianmeng).UpdateColumns(s => new { s.ExpirationTime }).ExecuteCommand(); + } + } + } + /// + /// 处理订单 + /// + /// + /// + /// + /// + private void HandleOrder(Lianmeng lianmeng, WeipinhuiRequest req, DateTime lastDateTime, DateTime datetime) + { + lastDateTime = lastDateTime.AddMinutes(-1); + req.OrderQuery(lastDateTime, datetime, (items) => + { + var db = Db; + db.UseTran(() => + { + foreach (var item in items) + { + var detailListTokens = item["detailList"].Children(); + foreach (var detailListToken in detailListTokens) + { + //goodsId 商品ID + var orderSn = item["orderSn"].Value(); + var goodsId = detailListToken["goodsId"].Value(); + var orderId = orderSn; + var orderTime = Util.TimespanToDatatime(item["orderTime"].Value()); + //afterSaleInfo + JToken afterSaleInfoToken = null; + if (detailListToken["afterSaleInfo"] != null)//退货 + { + afterSaleInfoToken = detailListToken["afterSaleInfo"].Children().First(); + } + var lastUpdateTime = item["lastUpdateTime"].Value(); + var tablenames = db.GetTableName(orderTime); + var info = db.Queryable() + .Where(w => w.OrderId == orderId) + .SplitTable(t => t.InTableNames(tablenames)) + .First(); + if (info != null) + { + if (lastUpdateTime == info.lastUpdateTime) + { + continue; + } + else if ((int)info.SystemOrderStatus > 3000) + { + continue; + } + Util.CopyToObj(item, info); + Util.CopyToObj(detailListToken, info); + Util.CopyToObj(afterSaleInfoToken, info); + SetOrderState(db, lianmeng, info.orderSubStatusName, info); + //修改数据 + db.Updateable(info).SplitTable(t => t.InTableNames(tablenames)).ExecuteCommand(); + } + else + { + info = new WphOrder(); + info.Id = Util.CreateID(orderTime); + info.OrderId = orderId; + info.LianmengId = lianmeng.Id; + Util.CopyToObj(item, info); + Util.CopyToObj(detailListToken, info); + Util.CopyToObj(afterSaleInfoToken, info); + SetOrderState(db,lianmeng, info.orderSubStatusName, info); + db.Insertable(info).SplitTable().ExecuteCommand(); + } + } + } + }, ex => Db.OnLog("唯品会订单同步", ex)); + return false; + }); + } + /// + /// 设置订单状态 + /// + /// + /// + /// + private void SetOrderState(SqlSugarClient db, Lianmeng lianmeng, Wph_OrderSubStatusNameType infoOrderSubStatusName, WphOrder info) + { + switch (infoOrderSubStatusName) + { + case Wph_OrderSubStatusNameType.已下单: + info.SystemOrderStatus = SystemOrderStatus.订单创建; + + break; + case Wph_OrderSubStatusNameType.已付款: + info.SystemOrderStatus = SystemOrderStatus.订单付款; + DocumentaryUser(db,info); + break; + case Wph_OrderSubStatusNameType.已签收: + info.SystemOrderStatus = SystemOrderStatus.订单收货; + DocumentaryUser(db, info); + break; + case Wph_OrderSubStatusNameType.待结算: + info.SystemOrderStatus = SystemOrderStatus.订单付款; + DocumentaryUser(db, info); + break; + case Wph_OrderSubStatusNameType.已结算: + info.SystemOrderStatus = SystemOrderStatus.订单结算; + CreateComplete(db, info); + break; + case Wph_OrderSubStatusNameType.已失效: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + //退货处理 + SalesReturn(db, lianmeng, info); + break; + case Wph_OrderSubStatusNameType.维权中: + info.SystemOrderStatus = SystemOrderStatus.订单退款中; + break; + case Wph_OrderSubStatusNameType.维权完成: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case Wph_OrderSubStatusNameType.手动失效: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + } + switch (info.afterSaleType) + { + case Wph_SfterSaleType.无: + break; + case Wph_SfterSaleType.退货: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case Wph_SfterSaleType.换货: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + } + switch (info.afterSaleStatus) + { + case Wph_AfterSaleStatusType.无: + break; + case Wph_AfterSaleStatusType.售后中: + info.SystemOrderStatus = SystemOrderStatus.订单退款中; + break; + case Wph_AfterSaleStatusType.售后完成: + info.SystemOrderStatus = SystemOrderStatus.订单失效; + break; + case Wph_AfterSaleStatusType.售后取消: + break; + } + + } + /// + /// 跟单用户 + /// + /// + private void DocumentaryUser(SqlSugarClient db, WphOrder info) + { + if (info.UserId > 0) + { + return; + } + //通过扩展ID,查到了用户 + if (long.TryParse(info.statParam, out var queryId)) + { + var queryTabName = db.GetTableName(queryId); + QueryHist cache = db.Queryable().SplitTable(tab => tab.InTableNames(queryTabName)) + .Single(f => f.Id == queryId); + if (cache != null) + { + info.UserId = cache.UserId; + info.QueryCache = cache; + var user = db.GetUserData(info.UserId); + user.PayOrderCount++; + db.Save(user); + } + } + } + /// + /// 退货判断处理 + /// + /// + /// + private void SalesReturn(SqlSugarClient db, Lianmeng lianmeng, WphOrder info) + { + if (info.UserId <= 0) + { + return; + } + if (info.PayStatus != OrderPayStatus.已支付) + { + return; + } + db.PayPoint(info, info.QueryCache, info.Id, info.goodsName, true); + } + /// + /// 生成订单完成信息 + /// + /// + private void CreateComplete(SqlSugarClient db, WphOrder info) + { + if (info.UserId <= 0) + { + return; + } + if (info.settledTime <= 0) + { + return; + } + if (info.orderTime <= DateTime.MinValue) + { + return; + } + if (info.PayStatus == OrderPayStatus.未支付) + { + info.PayStatus = OrderPayStatus.支付中; + var startTime = Util.TimespanToDatatime(info.settledTime + ""); + var endTime = Util.TimespanToDatatime(info.orderTime + ""); + //时间截取 + var timeConsuming = startTime - endTime; + DateTime thawingTime = DateTime.Now; + if (timeConsuming.TotalDays < 1) + { + var pubConfig = Db.GetPubConfig(); + if (pubConfig != null && pubConfig.ExtendDay > 0) + { + thawingTime = startTime.AddDays(pubConfig.ExtendDay); + } + } + var frozen = new FinishOrder() + { + CreateTime = DateTime.Now, + LianmengType = LianmengType.唯品会联盟, + OrderId = info.Id, + ThawingTime = thawingTime, + UserId = info.UserId + }; + db.Insertable(frozen).ExecuteCommand(); + //发送通知 + var tablenames = Db.GetTableName(info.orderTime); + if (info.UserId > 0 && info.QueryCache != null) + { + bool IsFreeze = (frozen.ThawingTime > DateTime.Now); + Client.SendClientMsg(info.QueryCache.RobotId, DeviceMessageType.唯品会订单更新, new { OrderId = info.Id, TableName = tablenames, IsFreeze = IsFreeze }); + } + } + } + /// + /// 获取上次时间 + /// + /// + /// + private DateTime GetLastDateTime(string id) + { + return Client.Config.RuntimeCache.GetPublicValue("订单同步" + id, () => DateTime.MinValue); + } + /// + /// 记录上次时间 + /// + /// + /// + private void SetLastDateTime(string id, DateTime now) + { + Client.Config.RuntimeCache.SetPublicValue("订单同步" + id, now); + } + + } +} diff --git a/Server/Utils/AutoMapperEx.cs b/Server/Utils/AutoMapperEx.cs new file mode 100644 index 0000000..5ece70c --- /dev/null +++ b/Server/Utils/AutoMapperEx.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; +using AutoMapper; +using Server.Utils; + +namespace Server +{ + /// + /// 扩展 + /// + public static class AutoMapperEx + { + /// + /// 绑定指定名字 + /// + /// + /// + /// + /// + /// + public static void MapFromDynamic( + this IMemberConfigurationExpression c, string memberName, Func resolverValue = null) + { + var resolver = new DynamicCustomResolver(memberName.Trim(' '), resolverValue); + c.MapFrom(resolver); + } + + public static IMappingExpression Ignore( + this IMappingExpression map, + Expression> selector) + { + map.ForMember(selector, config => config.Ignore()); + return map; + } + } +} diff --git a/Server/Utils/CacheHelper.cs b/Server/Utils/CacheHelper.cs new file mode 100644 index 0000000..196d0ae --- /dev/null +++ b/Server/Utils/CacheHelper.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web; +using System.Web.Caching; + +namespace Server.Utils +{ + /// + /// 缓存操作,默认缓存1分钟 + /// + public class CacheHelper + { + #region 单例 + private static CacheHelper ini; + + public static CacheHelper GetIntance() + { + if (ini == null) + { + ini = new CacheHelper(); + } + return ini; + } + + private CacheHelper() { } + #endregion + + /// + /// 缓存容器 + /// + static System.Web.Caching.Cache objCache = new System.Web.Caching.Cache(); + + + /// + /// 设置数据缓存 + /// + public void SetCache(string CacheKey, object objObject, int timeout = 7200) + { + + if (objCache.Get(CacheKey) != null) + { + objCache.Remove(CacheKey); + } + objCache.Insert(CacheKey, objObject, null, DateTime.Now.AddSeconds(timeout), TimeSpan.Zero); + } + + /// + /// 获取当前应用程序指定CacheKey的Cache值 + /// + /// + /// y + public object GetCache(string CacheKey) + { + return objCache[CacheKey]; + } + + + /// + /// 清除单一键缓存 + /// + /// + public void RemoveKeyCache(string CacheKey) + { + try + { + objCache.Remove(CacheKey); + } + catch { } + } + + + /// + /// 清除所有缓存 + /// + public void RemoveAllCache() + { + IDictionaryEnumerator CacheEnum = objCache.GetEnumerator(); + if (objCache.Count > 0) + { + ArrayList al = new ArrayList(); + while (CacheEnum.MoveNext()) + { + al.Add(CacheEnum.Key); + } + foreach (string key in al) + { + objCache.Remove(key); + } + } + + } + + + /// + /// 以列表形式返回已存在的所有缓存 + /// + /// + public ArrayList ShowAllCache() + { + ArrayList al = new ArrayList(); + + if (objCache.Count > 0) + { + IDictionaryEnumerator CacheEnum = objCache.GetEnumerator(); + while (CacheEnum.MoveNext()) + { + al.Add(CacheEnum.Key); + } + } + return al; + } + + + + } +} diff --git a/Server/Utils/DynamicCustomResolver.cs b/Server/Utils/DynamicCustomResolver.cs new file mode 100644 index 0000000..7109a4b --- /dev/null +++ b/Server/Utils/DynamicCustomResolver.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AutoMapper; + +namespace Server.Utils +{ + /// + /// 动态属性 + /// + /// + /// + public class DynamicCustomResolver : IValueResolver + { + public DynamicCustomResolver(string name, Func resolverValueFunc) + { + Name = name; + this.MemberType = typeof(TDestination).GetProperty(name).PropertyType; + this.ResolverValueFunc = resolverValueFunc; + } + /// + /// 属性的名称 + /// + public string Name { get; set; } + /// + /// 成员类型 + /// + public Type MemberType { get; set; } + /// + /// 自定义转换值 + /// + public Func ResolverValueFunc { get; set; } + /// + /// 转换 + /// + /// + /// + /// + /// + /// + public TMember Resolve(TSource source, TDestination destination, TMember destMember, ResolutionContext context) + { + try + { + var dny = source as ExpandoObject; + var item = dny.FirstOrDefault(w => w.Key == Name); + var val = item.Value; + //如果自定义了转换器,就调用 + if (ResolverValueFunc != null) + { + return ResolverValueFunc(val); + } + if (item.Value == DBNull.Value) + { + val = null; + } + if (this.MemberType.IsEnum)//枚举 + { + if (val == null) + { + return (TMember)Enum.ToObject(this.MemberType, 0); + } + return (TMember)Enum.ToObject(this.MemberType, val); + } + if (this.MemberType == typeof(string)) + { + if (val == null) + { + return default(TMember); + } + return (TMember)Convert.ChangeType(val, this.MemberType); + } + if (this.MemberType.IsValueType) + { + if (val == null) + { + return default(TMember); + } + } + return (TMember)Convert.ChangeType(val, this.MemberType); + } + catch (Exception e) + { + throw new Exception(this.Name + "转换错误 " + source, e); + } + } + } +} diff --git a/Server/Utils/LianmengTypeHelper.cs b/Server/Utils/LianmengTypeHelper.cs new file mode 100644 index 0000000..adc2187 --- /dev/null +++ b/Server/Utils/LianmengTypeHelper.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Common.Models.Enums; +using Server.Utils; + +namespace Server.Utils +{ + /// + /// 联盟转换帮助类 + /// + public class LianmengTypeHelper + { + /// + /// 转换成联盟类型 + /// + /// + /// + public static LianmengType GetPlatformType(string platform) + { + switch (platform) + { + case "微信": + return LianmengType.淘宝联盟; + case "京东": + return LianmengType.京东联盟; + case "唯品会": + return LianmengType.唯品会联盟; + case "抖音": + return LianmengType.抖音联盟; + case "拼多多": + return LianmengType.拼多多联盟; + case "美团": + return LianmengType.美团联盟; + case "苏宁": + return LianmengType.苏宁联盟; + } + return LianmengType.无; + } + /// + /// 联盟转换成平台文本 + /// + /// + /// + public static string GetPlatform(LianmengType type) + { + switch (type) + { + case LianmengType.淘宝联盟: + return "淘宝"; + case LianmengType.京东联盟: + return "京东"; + case LianmengType.拼多多联盟: + return "拼多多"; + case LianmengType.唯品会联盟: + return "唯品会"; + case LianmengType.苏宁联盟: + return "苏宁"; + case LianmengType.抖音联盟: + return "抖音"; + case LianmengType.美团联盟: + return "美团"; + } + return ""; + } + } +} diff --git a/Server/Utils/ServiceInstaller.cs b/Server/Utils/ServiceInstaller.cs new file mode 100644 index 0000000..6b45efc --- /dev/null +++ b/Server/Utils/ServiceInstaller.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Runtime.InteropServices; +using System.ServiceProcess; +using System.Diagnostics; + +namespace Server.Utils +{ + /// + /// 安装Windows服务业务层 + /// + public class ServiceInstaller + { + + public static ServiceController GetServiceController(string serviceName) + { + ServiceController[] controllers = ServiceController.GetServices(); + int nNum = controllers.Length; + try + { + for (int i = 0; i <= (nNum - 1); i++) + { + if ((controllers[i].ServiceName.ToUpper() == serviceName.ToUpper())) + { + var v = controllers[i]; + return v; + } + } + } + catch (Exception) + { + + } + return null; + } + + /// + /// 执行DOS命令,返回DOS命令的输出 + /// + /// dos命令 + /// 等待命令执行的时间(单位:毫秒), + /// 如果设定为0,则无限等待 + /// 返回DOS命令的输出 + public static string Execute(string command, int seconds) + { + string output = ""; //输出字符串 + if (command != null && !command.Equals("")) + { + var pro = new Process(); + pro.StartInfo.FileName = "cmd.exe"; + pro.StartInfo.UseShellExecute = false; + pro.StartInfo.CreateNoWindow = true; + pro.StartInfo.RedirectStandardInput = true; + pro.StartInfo.RedirectStandardOutput = true; + pro.StartInfo.RedirectStandardError = true; + pro.OutputDataReceived += (sender, e) => Console.WriteLine(e.Data); + pro.ErrorDataReceived += (sender, e) => Console.WriteLine(e.Data); + + try + { + if (pro.Start())//开始进程 + { + var sIn = pro.StandardInput; + sIn.AutoFlush = true; + var Codes = command.Split(new string[] {"\r\n"}, StringSplitOptions.None); + + pro.BeginOutputReadLine(); + + foreach (var code in Codes) + { + sIn.WriteLine(code); + } + + + if (seconds == 0) + { + pro.WaitForExit();//这里无限等待进程结束 + } + else + { + pro.WaitForExit(seconds); //等待进程结束,等待时间为指定的毫秒 + } + output = pro.StandardOutput.ReadToEnd();//读取进程的输出 + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message);//捕获异常,输出异常信息 + } + finally + { + if (pro != null) + pro.Close(); + } + } + return output; + } + + + + public static string InitServer(string Path,string Name) + { + var code = $@"@echo off +net stop {Name} +{Path} --remove {Name} +{Path} --install {Name} +net start {Name}"; + return Execute(code,20); + + } + } + + + +} + + + diff --git a/Server/Utils/YZCloudApiHelper.cs b/Server/Utils/YZCloudApiHelper.cs new file mode 100644 index 0000000..29e3936 --- /dev/null +++ b/Server/Utils/YZCloudApiHelper.cs @@ -0,0 +1,846 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using Common.Utils; +using CsharpHttpHelper; + +namespace Server.Utils +{ + /// + /// 后端API + /// + public class YZCloudApiHelper + { + /// + /// host + /// + private static readonly string host = "http://yzinterface.api.52cmg.cn/api/"; + private static readonly int appkey = 334391396; + private static readonly string appsecret = "b924f8b944694cb8891bcfc7834dedb533436a3776de472cbde99577337902b2"; + + + private static T HttpT(string api, string method, object postdata = null) where T : class + { + try + { + var result = HttpResult(api,method,postdata); + if (result.StatusCode == HttpStatusCode.OK) + { + return Newtonsoft.Json.JsonConvert.DeserializeObject(result.Html); + } + return null; + } + catch (Exception e) + { + Client.SingleClient.Db.OnLog("请求出错", e); + return null; + } + + } + /// + /// http + /// + /// + /// + /// + /// + private static HttpResult HttpResult(string api, string method, object postdata = null) + { + var data = Newtonsoft.Json.JsonConvert.SerializeObject(postdata); + var http = new HttpHelper(); + HttpItem item = new HttpItem() + { + URL = host + api, + Method = method, + Timeout = 100000, + ReadWriteTimeout = 30000, + IsToLower = false, + Cookie = "", + UserAgent = "YZBlacklistCollect", + Accept = "text/html, application/xhtml+xml, */*", + ContentType = "application/json", + Referer = "", + Allowautoredirect = false, + AutoRedirectCookie = false, + Postdata = data, + PostEncoding = Encoding.UTF8 + }; + var timespan = Util.GetTimespan(DateTime.Now); + var sign = Util.GetMd5(AesHelper.Encrypt(data + appkey + timespan, appsecret)); + item.Header.Add("sign", sign); + item.Header.Add("timestamp", timespan + ""); + item.Header.Add("appkey", appkey + ""); + var result = http.GetHtml(item); + return result; + } + + + + + + private static ServiceResult Http(string api, string method, object postdata = null) + { + try + { + var result = HttpResult(api, method, postdata); + if (result.StatusCode == HttpStatusCode.OK) + { + return Newtonsoft.Json.JsonConvert.DeserializeObject>(result.Html); + } + return new ServiceResult(default(T)) + { + Ok = false, + Message = result.Html, + }; + } + catch (Exception e) + { + Client.SingleClient.Db.OnLog("请求出错", e); + return new ServiceResult(default(T)) + { + Ok = false, + Message = e.ToString(), + }; + } + + } + + private static ServiceResult Http(string api, string method, object postdata = null) + { + try + { + var result = HttpResult(api, method, postdata); + if (result.StatusCode == HttpStatusCode.OK) + { + return Newtonsoft.Json.JsonConvert.DeserializeObject(result.Html); + } + return new ServiceResult() + { + Ok = false, + Data = result.Html, + }; + } + catch (Exception e) + { + Client.SingleClient.Db.OnLog("请求出错", e); + return new ServiceResult() + { + Ok = false, + Data = e.ToString(), + }; + } + } + /// + /// 删除黑名单数据 + /// + /// + /// + public static ServiceResult RemoveBlacklist(List inputs) + { + inputs.ForEach(item => + { + if (string.IsNullOrWhiteSpace(item.UserToken)) + { + item.UserToken = DbExtend.ComputerFeature; + } + }); + return Http("UserBlacklist/Remove", "post", inputs); + } + + /// + /// 获取黑名单列表 + /// + /// + /// + public static PageResult GetBlacklist(BlacklistSearchPagingInput input) + { + if (string.IsNullOrWhiteSpace(input.UserToken)) + { + input.UserToken = DbExtend.ComputerFeature; + } + return HttpT>("UserBlacklist/GetList", "post", input); + } + /// + /// 获取商品黑名单列表 + /// + /// + /// + public static PageResult GetGoodsBlacklist(GoodsBlacklistSearchPagingInput input) + { + if (string.IsNullOrWhiteSpace(input.UserToken)) + { + input.UserToken = DbExtend.ComputerFeature; + } + return HttpT>("GoodsBlacklist/GetList", "post", input); + } + + + /// + /// 获取商店黑名单列表 + /// + /// + /// + public static PageResult GetStoreBlacklist(StoreBlacklistSearchPagingInput input) + { + if (string.IsNullOrWhiteSpace(input.UserToken)) + { + input.UserToken = DbExtend.ComputerFeature; + } + return HttpT>("StoreBlacklist/GetList", "post", input); + } + + /// + /// 删除商品黑名单数据 + /// + /// + /// + public static ServiceResult RemoveGoodsBlacklist(List inputs) + { + inputs.ForEach(item => + { + if (string.IsNullOrWhiteSpace(item.UserToken)) + { + item.UserToken = DbExtend.ComputerFeature; + } + }); + return Http("GoodsBlacklist/Remove", "post", inputs); + } + /// + /// 删除商品黑名单数据 + /// + /// + /// + public static ServiceResult RemoveStoreBlacklist(List inputs) + { + inputs.ForEach(item => + { + if (string.IsNullOrWhiteSpace(item.UserToken)) + { + item.UserToken = DbExtend.ComputerFeature; + } + }); + return Http("StoreBlacklist/Remove", "post", inputs); + } + /// + /// 新增用户黑名单 + /// + /// + /// + public static ServiceResult AddUserBlacklist(List inputs) + { + inputs.ForEach(item => + { + if (string.IsNullOrWhiteSpace(item.UserToken)) + { + item.UserToken = DbExtend.ComputerFeature; + } + }); + return Http("UserBlacklist/Add", "post", inputs); + } + + /// + /// 新增商品黑名单 + /// + /// + /// + public static ServiceResult AddGoodsBlacklist(List inputs) + { + inputs.ForEach(item => + { + if (string.IsNullOrWhiteSpace(item.UserToken)) + { + item.UserToken = DbExtend.ComputerFeature; + } + }); + return Http("GoodsBlacklist/Add", "post", inputs); + } + + /// + /// 新增商店黑名单 + /// + /// + /// + public static ServiceResult AddStoreBlacklist(List inputs) + { + inputs.ForEach(item => + { + if (string.IsNullOrWhiteSpace(item.UserToken)) + { + item.UserToken = DbExtend.ComputerFeature; + } + }); + return Http("StoreBlacklist/Add", "post", inputs); + } + } + /// + /// 设置商店 + /// + public class SetStoerBlacklistInput + { + /// + /// 平台 + /// + [Required] + [DisplayName("平台")] + public string Platform { get; set; } + /// + /// 商店名称 + /// + [DisplayName("商店名称")] + public string StoreName { get; set; } + /// + /// 商店ID + /// + public string StoreId { get; set; } + /// + /// 备注 + /// + [DisplayName("备注")] + public string Remark { get; set; } = string.Empty; + /// + /// 新增时间 + /// + [Required] + [DisplayName("新增时间")] + public DateTime AddDateTime { get; set; } + /// + /// 用户Token标示 + /// + [DisplayName("用户关联特征码")] + public string UserToken { get; set; } + } + /// + /// 设置商品 + /// + public class SetGoodsBlacklistInput + { + /// + /// 平台 + /// + [Required] + [DisplayName("平台")] + public string Platform { get; set; } + /// + /// 商品ID + /// + [Required] + [DisplayName("商品ID")] + public string GoodsId { get; set; } + /// + /// 商店名称 + /// + [DisplayName("商店名称")] + public string StoreName { get; set; } + /// + /// 备注 + /// + [DisplayName("备注")] + public string Remark { get; set; } = string.Empty; + /// + /// 新增时间 + /// + [Required] + [DisplayName("新增时间")] + public DateTime AddDateTime { get; set; } + /// + /// 用户Token标示 + /// + [DisplayName("用户关联特征码")] + public string UserToken { get; set; } + } + /// + /// 新增黑名单 + /// + public class SetBlacklistInput + { + /// + /// 0=微信 1=QQ + /// + public int Type { get; set; } + /// + /// 用户ID + /// + public string UserName { get; set; } + /// + /// 用户昵称 + /// + public string UserNick { get; set; } + /// + /// 分组类型 + /// + public BlacklistGroupType GroupType { get; set; } + /// + /// 头像 + /// + public string Avatar { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } = string.Empty; + /// + /// 新增时间 + /// + public DateTime AddDateTime { get; set; } + /// + /// 用户Token标示 + /// + public string UserToken { get; set; } + } + /// + /// 删除商店黑名单 + /// + public class RemoveStoreBlacklistInput + { + /// + /// 商店ID + /// + public string StoreId { get; set; } + /// + /// 平台 + /// + [Required] + [DisplayName("平台")] + public string Platform { get; set; } + /// + /// 用户标示 + /// + [Required] + [DisplayName("用户标示")] + public string UserToken { get; set; } + } + /// + /// 删除商品黑名单 + /// + public class RemoveGoodsBlacklistInput + { + /// + /// 商品ID + /// + [Required] + [DisplayName("商品ID")] + public string GoodsId { get; set; } + /// + /// 平台 + /// + [Required] + [DisplayName("平台")] + public string Platform { get; set; } + /// + /// 用户标示 + /// + [Required] + [DisplayName("用户标示")] + public string UserToken { get; set; } + } + /// + /// 审核状态 + /// + public enum AuditStateEmun : int + { + /// + /// 等待审核 + /// + Waiting = 0, + /// + /// 审核成功 + /// + Succee = 1, + /// + /// 审核失败 + /// + Failure = 2, + } + /// + /// 云商品黑名单返回结果 + /// + public class CloudStoreBlacklistResult + { + /// + /// ID + /// + public long Id { get; set; } + /// + /// 平台 + /// + public string Platform { get; set; } + /// + /// 商店ID + /// + public string StoreId { get; set; } + /// + /// 商店名称 + /// + public string StoreName { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } = string.Empty; + /// + /// 添加时间 + /// + public DateTime AddDateTime { get; set; } + /// + /// 用户Token标示 + /// + public string UserToken { get; set; } + /// + /// 更新时间 + /// + public DateTime UpdateDateTime { get; set; } + /// + /// 是否删除 + /// + public bool IsRemove { get; set; } + } + /// + /// 商店黑名单搜索 + /// + public class StoreBlacklistSearchPagingInput : SearchPagingInput + { + /// + /// 用户Token标示 + /// + public string UserToken { get; set; } + /// + /// 升序还是降序 + /// + public bool IsAsc { get; set; } + /// + /// 更新时间 + /// + public DateTime? UpdateDateTime { get; set; } + /// + /// 审核状态 + /// + public AuditStateEmun? AuditState { get; set; } + } + /// + /// 云商品黑名单返回结果 + /// + public class CloudGoodsBlacklistResult + { + /// + /// ID + /// + public long Id { get; set; } + + /// + /// 商品ID + /// + public string GoodsId { get; set; } + /// + /// 平台 + /// + public string Platform { get; set; } + /// + /// 商店名称 + /// + public string StoreName { get; set; } + /// + /// 备注 + /// + public string Remark { get; set; } = string.Empty; + /// + /// 添加时间 + /// + public DateTime AddDateTime { get; set; } + /// + /// 用户Token标示 + /// + public string UserToken { get; set; } + /// + /// 更新时间 + /// + public DateTime UpdateDateTime { get; set; } + /// + /// 是否删除 + /// + public bool IsRemove { get; set; } + } + /// + /// 商品黑名单搜索 + /// + public class GoodsBlacklistSearchPagingInput : SearchPagingInput + { + /// + /// 用户Token标示 + /// + public string UserToken { get; set; } + /// + /// 升序还是降序 + /// + public bool IsAsc { get; set; } + /// + /// 更新时间 + /// + public DateTime? UpdateDateTime { get; set; } + /// + /// 审核状态 + /// + public AuditStateEmun? AuditState { get; set; } + } + /// + /// 黑名单搜索 + /// + public class BlacklistSearchPagingInput : SearchPagingInput + { + /// + /// 用户Token标示 + /// + [DisplayName("用户关联特征码")] + public string UserToken { get; set; } + /// + /// 升序还是降序 + /// + public bool IsAsc { get; set; } + /// + /// 同步时间 + /// + public DateTime? UpdateDateTime { get; set; } + /// + /// 审核状态 + /// + public AuditStateEmun? AuditState { get; set; } + } + /// + /// 云黑名单返回结果 + /// + public class CloudBlacklistResult + { + /// + /// ID + /// + public long Id { get; set; } + + /// + /// 0=微信 1=QQ + /// + public int Type { get; set; } + /// + /// 用户ID + /// + public string UserName { get; set; } + /// + /// 用户昵称 + /// + public string UserNick { get; set; } + /// + /// 分组类型 + /// + public BlacklistGroupType GroupType { get; set; } + /// + /// 头像 + /// + public string Avatar { get; set; } + + /// + /// 备注 + /// + public string Remark { get; set; } = string.Empty; + /// + /// 添加时间 + /// + public DateTime AddDateTime { get; set; } + /// + /// 更新时间 + /// + public DateTime UpdateDateTime { get; set; } + + /// + /// 用户Token标示 + /// + public string UserToken { get; set; } + /// + /// 是否删除 + /// + public bool IsRemove { get; set; } + } + /// + /// 黑名单分组 + /// + public enum BlacklistGroupType : int + { + /// + /// 未分组 + /// + 未分组 = 0, + /// + /// 薅羊毛党 + /// + 薅羊毛党 = 1, + /// + /// 恶意举报 + /// + 恶意举报 = 2 + } + + /// + /// 删除黑名单 + /// + public class RemoveBlacklistInput + { + /// + /// 用户id + /// + [Required] + [DisplayName("用户id")] + public string Username { get; set; } + /// + /// 用户类型0微信 1QQ + /// + [Required] + [DisplayName("类型")] + public int Type { get; set; } + /// + /// 用户标示 + /// + [Required] + [DisplayName("用户标示")] + public string UserToken { get; set; } + } + /// + /// 统一服务返回结果 + /// + public class ServiceResult + { + /// + /// 请求是否成功 + /// + public bool Ok { get; set; } + /// + /// 数据 + /// + public object Data { get; set; } + /// + /// 错误信息 + /// + public string Message { get; set; } + } + /// + /// 统一返回结果 + /// + /// + public class ServiceResult : ServiceResult + { + /// + /// 初始化 + /// + /// + public ServiceResult(T data) + { + this.Data = data; + } + /// + /// 返回数据 + /// + public new T Data { get; set; } + + } + /// + /// 分页数据 + /// + /// + public class PageResult + { + /// + /// 下一页 + /// + public bool IsNext { get; set; } + + /// + /// 上一页 + /// + public bool IsBack { get; set; } + + /// + /// 数据 + /// + public List Datas { get; set; } + + /// + /// 总数量 + /// + public int TotalNumber { get; set; } + + /// + /// 每页显示条数 + /// + public int PageSize { get; set; } + + /// + /// 总页码 + /// + public int PageNumber { get; set; } + + /// + /// 当前页码 + /// + public int PageIndex { get; set; } + + /// + /// + /// + /// + /// + /// + /// + /// + public PageResult(List Datas, int TotalNumber, int PageSize, int PageIndex) + { + if (PageIndex <= 0 || PageSize <= 0) throw new Exception("Index或PageSize 有问题,请检查"); + if (PageSize > 10000) throw new Exception("每页查询数量,不能超过100"); + + PageNumber = 1; + if (TotalNumber != 0 && PageSize > 0) + { + PageNumber = TotalNumber / PageSize; + if (TotalNumber % PageSize != 0) PageNumber++; + } + this.Datas = Datas; + this.TotalNumber = TotalNumber; + this.PageNumber = PageNumber; + this.PageSize = PageSize; + this.PageIndex = PageIndex; + this.IsBack = PageIndex > 1; + this.IsNext = PageIndex < PageNumber; + } + } + + + + /// + /// 分页输入参数 + /// + public class PagingInput + { + /// + /// 页码 + /// + + public int PageIndex { get; set; } = 1; + + /// + /// 限制条数 + /// + + public int PageSize { get; set; } = 10; + } + + + /// + /// 搜索输入 + /// + public class SearchPagingInput : PagingInput + { + /// + /// 关键字 + /// + public string Keyword { get; set; } + } +} diff --git a/Server/Utils/ZipHelper.cs b/Server/Utils/ZipHelper.cs new file mode 100644 index 0000000..13db72d --- /dev/null +++ b/Server/Utils/ZipHelper.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ICSharpCode.SharpZipLib.Zip; + +namespace Server.Utils +{ + public class ZipHelper + { + #region 加压方法 + /// + /// 功能:压缩文件(暂时只压缩文件夹下一级目录中的文件,文件夹及其子级被忽略) + /// + /// 被压缩的文件夹夹路径 + /// 生成压缩文件的路径,为空则默认与被压缩文件夹同一级目录,名称为:文件夹名+.zip + /// 出错信息 + /// 是否压缩成功 + public static bool ZipFile(string dirPath, string zipFilePath, out string err) + { + err = ""; + if (dirPath == string.Empty) + { + err = "要压缩的文件夹不能为空!"; + return false; + } + if (!Directory.Exists(dirPath)) + { + err = "要压缩的文件夹不存在!"; + return false; + } + //压缩文件名为空时使用文件夹名+.zip + if (zipFilePath == string.Empty) + { + if (dirPath.EndsWith("//")) + { + dirPath = dirPath.Substring(0, dirPath.Length - 1); + } + zipFilePath = dirPath + ".zip"; + } + try + { + string[] filenames = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories); + using (ZipOutputStream s = new ZipOutputStream(File.Create(zipFilePath))) + { + s.SetLevel(9); + byte[] buffer = new byte[4096]; + foreach (string file in filenames) + { + ZipEntry entry = new ZipEntry(Path.GetFileName(file)); + entry.DateTime = DateTime.Now; + s.PutNextEntry(entry); + using (FileStream fs = File.OpenRead(file)) + { + int sourceBytes; + do + { + sourceBytes = fs.Read(buffer, 0, buffer.Length); + s.Write(buffer, 0, sourceBytes); + } while (sourceBytes > 0); + } + } + s.Finish(); + s.Close(); + } + } + catch (Exception ex) + { + err = ex.Message; + return false; + } + return true; + } + #endregion + + #region 解压 + /// + /// 功能:解压zip格式的文件。 + /// + /// 压缩文件路径 + /// 解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 + /// 出错信息 + /// 解压是否成功 + public static bool UnZipFile(string zipFilePath, string unZipDir, out string err) + { + err = ""; + if (zipFilePath == string.Empty) + { + err = "压缩文件不能为空!"; + return false; + } + if (!File.Exists(zipFilePath)) + { + err = "压缩文件不存在!"; + return false; + } + //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 + if (unZipDir == string.Empty) + unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath)); + if (!unZipDir.EndsWith("//")) + unZipDir += "//"; + if (!Directory.Exists(unZipDir)) + Directory.CreateDirectory(unZipDir); + + try + { + using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath))) + { + + ZipEntry theEntry; + while ((theEntry = s.GetNextEntry()) != null) + { + string directoryName = Path.GetDirectoryName(theEntry.Name); + string fileName = Path.GetFileName(theEntry.Name); + if (directoryName.Length > 0) + { + Directory.CreateDirectory(unZipDir + directoryName); + } + if (!directoryName.EndsWith("//")) + directoryName += "//"; + if (fileName != String.Empty) + { + using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name)) + { + + int size = 2048; + byte[] data = new byte[2048]; + while (true) + { + size = s.Read(data, 0, data.Length); + if (size > 0) + { + streamWriter.Write(data, 0, size); + } + else + { + break; + } + } + } + } + }//while + } + } + catch (Exception ex) + { + err = ex.Message; + return false; + } + return true; + }//解压结束 + #endregion + + + + }//Class_end +} diff --git a/Server/Winforms/DefaultForm.Designer.cs b/Server/Winforms/DefaultForm.Designer.cs new file mode 100644 index 0000000..eaf907b --- /dev/null +++ b/Server/Winforms/DefaultForm.Designer.cs @@ -0,0 +1,50 @@ +namespace Server.Winforms +{ + partial class DefaultForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DefaultForm)); + this.SuspendLayout(); + // + // DefaultForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(595, 445); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); + this.Name = "DefaultForm"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "DefaultForm"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/Server/Winforms/DefaultForm.cs b/Server/Winforms/DefaultForm.cs new file mode 100644 index 0000000..13842f5 --- /dev/null +++ b/Server/Winforms/DefaultForm.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server.Winforms +{ + public partial class DefaultForm : Form + { + public DefaultForm() + { + InitializeComponent(); + } + } +} diff --git a/Server/Winforms/DefaultForm.resx b/Server/Winforms/DefaultForm.resx new file mode 100644 index 0000000..32f36e2 --- /dev/null +++ b/Server/Winforms/DefaultForm.resx @@ -0,0 +1,408 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + + AAABAAEAQEAAAAEAIAAoQgAAFgAAACgAAABAAAAAgAAAAAEAIAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAANWVFQzbkg8j3JUSOgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAANuTEEDbkxBA25MQQNuTEEDbkxBA25MQQNuTEEDbkxBA25MQQNuTEEDbkxBA25MQQNuT + EEDbkxBA25MQQNuTEEDbkxBA2pUQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADemxYX2pUSdNqWEtHblhL/25YS/9uWEv/blhLy25cSfwAA + AAAAAAAAAAAAAAAAAAAAAAAA3pYRLtqWEu3blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhLv3JYRr9uWE3nblRJGAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOCZFBnblxJ/25YS5duWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEtQAAAAAAAAAAAAAAAAAAAAAAAAAANuWEczblhL/25YS/9uWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEaMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANyVE17blhLl25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhLUAAAAAAAAAAAAAAAAAAAAAAAAAADblhG/25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YR+NuWElUAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANuX + EZPblhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhOy25cSfwAAAAAAAAAAAAAAAAAA + AAAAAAAA25MQQNuWEb/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/2ZQTQwAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAANuWEqzblhL/25YS/9uWEv/blhL/25YS/9qWEu3blROk25cReN2WE0TbkhIOAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADYiRQN25MQQNmVEnPalRL025YS/9uW + Ev/blhL/25YS/9uWEv/Vjg4SAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAANuWEnDblhL/25YS/9uWEv/blhL/25YS/9uVE6TdmBUlAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA3pYUJ9qVEt7blhL/25YS/9uWEv/blhL/3JcSnwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOCbDyHblhLp25YS/9uWEv/blhL/25YS/9uX + EVsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA25YS1NuWEv/blhL/25YS/9uWEv/blhJVAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclxKQ25YS/9uW + Ev/blhL/25YS/9yXEp8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANuYEirclhL225YS/9uW + Ev/blhL/25USjgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AADWlBAf25YS/9uWEv/blhL/25YS/9uWEuUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA2pYTpduWEv/blhL/25YS/9uXEsYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA25YRXNuWEv/blhL/25YS/9uWEv/blxJiAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAANuXEXjblhL/25YS/9uWEv/blhL/25IABwAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANuWEqrblhL/25YS/9uWEv/blhHbAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADbkxBA25YS/9uWEv/blhL/25YS/9uT + EEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADblhLP25YS/9uW + Ev/blhL/25cSqwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA25YRhtuW + Ev/blhL/25YS/9uWEv/flRUYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA25YS5NuWEv/blhL/25YS/9qWE3wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAANuWErnblhL/25YS/9uWEv/blhLkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAANqWEvrblhL/25YS/9uWEv/alxFMAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAN2XEUzblhL/25YS/9uWEv/blhL/25cTswAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADalRLX25YS/9uWEv/blhL/3JYRZgAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMyZGgrblhOy25YS/9uWEv/blhL/25YS/9uW + ElUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA25YRoduW + Ev/blhL/25YS/9qWEpkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANyWFDPblRLG25YS/9uW + Ev/blhL/25YS/9uXEsYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAANqVEm/blhL/25YS/9uWEv/blhHMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2pUQMNqW + EpnblhL/25YS/9uWEv/blhL/25YS/9uWEv/dlhFaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclxNC25YS/9uWEv/blhL/25YS/9uVEkYAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA25cSf9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/clxN7AAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3JcXFtuWEv/blhL/25YS/9uW + Ev/alhLRAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAANuWEczblhL/25YS/9uWEv/blhL/25YS/9uWEv/clxKmAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AADblhGG25YS/9uWEv/blhL/25YS/9uWEZQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADblhLx25YS/9uWEv/blhL/25YS/9uW + EsndlxFMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA1ZUVDNuWE87blhL/25YS/9uWEv/blhL/3JYRSQAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA25YS1NuW + Ev/blhL/25YS/9uWEb8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADblhJV25YS/9uWEv/blhL/25YS/9uW + Ev/clxNuAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAANuVEsbblhL/25YS/9uWEv/blxK6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANuW + Ep7blhL/25YS/9uWEv/blhL/25YS/9yWEaHblxNd3pYRLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclhLf25YS/9uWEv/blhL/2pYSpwAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA25URh9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blRLo25YSuNqU + EzcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2pYR+duWEv/blhL/25YS/9uX + EZMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclxNg25YR+NuWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blhHMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3JUSSNuW + Ev/blhL/25YS/9uWEv/blxJ/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANqY + ED7blhLI25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWE2sAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAANqWE5bblhL/25YS/9uWEv/blhL/2pQTNwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAANuXEDHblhF33JcSvNuWEv/blhL/25YS/9uWEv/alRLX650UDQAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAOCbDyHblhLp25YS/9uWEv/blhL/25YR2wAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADXlBQm3JYS09uW + Ev/blhL/25YS/9uWEXkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclxKQ25YS/9uWEv/blhL/25YS/9qW + EZIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAANqWEUvblhL/25YS/9uWEv/blhLk25gSKgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADZlhE925YS/9uW + Ev/blhL/25YS/9uVEu/alRMpAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3JUSrtuWEv/blhL/25YS/9uWEtTbmBIqAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA25YS3duWEv/blhL/25YS/9uWEv/clxN7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANyXETvblhL/25YS/9uW + Ev/blhL/25YS1NuYEioAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAA2pYSytuWEv/blhL/25YS/9uWEv/blhPO358gCAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA25cSmtuWEv/blhL/25YS/9uWEv/blhLU3ZYSYQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADblA8y25YS1NuWEv/blhL/25YS/9uWEv/blhL/2ZUTNQAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclxKf25YS/9uWEv/blhL/25YS/9uWEv/blhG/25USVAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANuSEhzalRKL25cS+duWEv/blhL/25YS/9uW + Ev/blhL/25USRgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAANuVEZPblhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blRK62pUSkdyWEWbclhQzAAAAAOCZFBnclhQz3ZcSYtuWEqjblhLu25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YReQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA2pYTiNuWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhLs3JUTXgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclhFm25YRzNuWEv/blhL/25YS/9uWEv/blhL/25YS/9uW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/alhKZ3pgQLwAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADclhFm25YRzNuW + Ev/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS/9uWEv/blhL/25YS7tqWEpnclhQzAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAADclhFm25YSm9uVEsHclhLm25YS/9uWEv/blhL/25YS/9uWEdvblhKo2ZQTUdiJ + FA0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOOcDhLalBM33JUVJAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA + AAAAAAAA//////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////+P+AAB/////APgAAAf///w + A+AAAA///+AD4AAAA///wAPgAAAB//+AD////AD//wD/////gP/+A//////gf/4H/////+B//A////// + 8H/8D//////wP/wf//////A//B//////8D/8H//////wf/wf/////+B//B//////wH/8H/////+A//wf + /////gD//A/////8Af/8D/////wD//4H/////Af//gP////8H///Af////wf//+AP////B///8AH///8 + H///4Af///gf///wA///+B////wB///wP////4H///A/////wP//4D/////gf//gf////+A//8B///// + 8B//AP/////4B/wB//////wAQAP//////gAAB///////AAAP///////AAD////////AA/////////x// + //////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////8= + + + \ No newline at end of file diff --git a/Server/Winforms/InitMysqlForm.Designer.cs b/Server/Winforms/InitMysqlForm.Designer.cs new file mode 100644 index 0000000..7618f2c --- /dev/null +++ b/Server/Winforms/InitMysqlForm.Designer.cs @@ -0,0 +1,340 @@ +namespace Server.Winforms +{ + partial class InitMysqlForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.tool_status = new System.Windows.Forms.ToolStripStatusLabel(); + this.statusStrip1 = new System.Windows.Forms.StatusStrip(); + this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); + this.button2 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label5 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.radioButton1 = new System.Windows.Forms.RadioButton(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.label7 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.radioButton2 = new System.Windows.Forms.RadioButton(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.textBox4 = new System.Windows.Forms.TextBox(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.groupBox3 = new System.Windows.Forms.GroupBox(); + this.statusStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.groupBox2.SuspendLayout(); + this.groupBox3.SuspendLayout(); + this.SuspendLayout(); + // + // tool_status + // + this.tool_status.Name = "tool_status"; + this.tool_status.Size = new System.Drawing.Size(39, 20); + this.tool_status.Text = "就绪"; + // + // statusStrip1 + // + this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripStatusLabel1, + this.tool_status}); + this.statusStrip1.Location = new System.Drawing.Point(0, 496); + this.statusStrip1.Name = "statusStrip1"; + this.statusStrip1.Padding = new System.Windows.Forms.Padding(1, 0, 19, 0); + this.statusStrip1.Size = new System.Drawing.Size(692, 26); + this.statusStrip1.TabIndex = 12; + this.statusStrip1.Text = "statusStrip1"; + // + // toolStripStatusLabel1 + // + this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; + this.toolStripStatusLabel1.Size = new System.Drawing.Size(54, 20); + this.toolStripStatusLabel1.Text = "状态:"; + // + // button2 + // + this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.button2.Location = new System.Drawing.Point(383, 442); + this.button2.Margin = new System.Windows.Forms.Padding(4); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(119, 34); + this.button2.TabIndex = 11; + this.button2.Text = "退出"; + this.button2.UseVisualStyleBackColor = true; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(225, 442); + this.button1.Margin = new System.Windows.Forms.Padding(4); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(119, 34); + this.button1.TabIndex = 10; + this.button1.Text = "下一步"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(505, 46); + this.numericUpDown1.Margin = new System.Windows.Forms.Padding(4); + this.numericUpDown1.Maximum = new decimal(new int[] { + 100000, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(95, 25); + this.numericUpDown1.TabIndex = 9; + this.numericUpDown1.Value = new decimal(new int[] { + 3306, + 0, + 0, + 0}); + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(395, 52); + this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(97, 15); + this.label5.TabIndex = 8; + this.label5.Text = "数据库端口:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(95, 202); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(97, 15); + this.label4.TabIndex = 6; + this.label4.Text = "数据库地址:"; + // + // radioButton1 + // + this.radioButton1.AutoSize = true; + this.radioButton1.Checked = true; + this.radioButton1.Location = new System.Drawing.Point(96, 36); + this.radioButton1.Margin = new System.Windows.Forms.Padding(4); + this.radioButton1.Name = "radioButton1"; + this.radioButton1.Size = new System.Drawing.Size(227, 19); + this.radioButton1.TabIndex = 0; + this.radioButton1.TabStop = true; + this.radioButton1.Text = "一、自动安装Mysql数据库8.0"; + this.radioButton1.UseVisualStyleBackColor = true; + this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(95, 155); + this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(97, 15); + this.label3.TabIndex = 4; + this.label3.Text = "数据库密码:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(97, 104); + this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(97, 15); + this.label2.TabIndex = 2; + this.label2.Text = "数据库账号:"; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(97, 52); + this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(97, 15); + this.label1.TabIndex = 0; + this.label1.Text = "数据库名称:"; + // + // label7 + // + this.label7.AutoSize = true; + this.label7.ForeColor = System.Drawing.Color.Green; + this.label7.Location = new System.Drawing.Point(328, 39); + this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label7.Name = "label7"; + this.label7.Size = new System.Drawing.Size(277, 15); + this.label7.TabIndex = 11; + this.label7.Text = "(新手力推,后期也可以导入云数据库)"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.ForeColor = System.Drawing.SystemColors.ControlDarkDark; + this.label6.Location = new System.Drawing.Point(328, 90); + this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(277, 15); + this.label6.TabIndex = 10; + this.label6.Text = "(适用于资金充裕,可搭配云数据库用)"; + // + // radioButton2 + // + this.radioButton2.AutoSize = true; + this.radioButton2.Location = new System.Drawing.Point(96, 88); + this.radioButton2.Margin = new System.Windows.Forms.Padding(4); + this.radioButton2.Name = "radioButton2"; + this.radioButton2.Size = new System.Drawing.Size(218, 19); + this.radioButton2.TabIndex = 1; + this.radioButton2.Text = "二、手动录入Mysql连接信息"; + this.radioButton2.UseVisualStyleBackColor = true; + this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged); + // + // groupBox2 + // + this.groupBox2.Controls.Add(this.textBox4); + this.groupBox2.Controls.Add(this.textBox3); + this.groupBox2.Controls.Add(this.textBox2); + this.groupBox2.Controls.Add(this.textBox1); + this.groupBox2.Controls.Add(this.numericUpDown1); + this.groupBox2.Controls.Add(this.label5); + this.groupBox2.Controls.Add(this.label4); + this.groupBox2.Controls.Add(this.label3); + this.groupBox2.Controls.Add(this.label2); + this.groupBox2.Controls.Add(this.label1); + this.groupBox2.Enabled = false; + this.groupBox2.Location = new System.Drawing.Point(16, 171); + this.groupBox2.Margin = new System.Windows.Forms.Padding(4); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Padding = new System.Windows.Forms.Padding(4); + this.groupBox2.Size = new System.Drawing.Size(656, 254); + this.groupBox2.TabIndex = 9; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "方案二"; + // + // textBox4 + // + this.textBox4.Location = new System.Drawing.Point(193, 199); + this.textBox4.Margin = new System.Windows.Forms.Padding(4); + this.textBox4.Name = "textBox4"; + this.textBox4.Size = new System.Drawing.Size(405, 25); + this.textBox4.TabIndex = 13; + // + // textBox3 + // + this.textBox3.Location = new System.Drawing.Point(193, 151); + this.textBox3.Margin = new System.Windows.Forms.Padding(4); + this.textBox3.Name = "textBox3"; + this.textBox3.Size = new System.Drawing.Size(405, 25); + this.textBox3.TabIndex = 12; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(193, 104); + this.textBox2.Margin = new System.Windows.Forms.Padding(4); + this.textBox2.Name = "textBox2"; + this.textBox2.Size = new System.Drawing.Size(405, 25); + this.textBox2.TabIndex = 11; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(193, 49); + this.textBox1.Margin = new System.Windows.Forms.Padding(4); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(176, 25); + this.textBox1.TabIndex = 10; + // + // groupBox3 + // + this.groupBox3.Controls.Add(this.label7); + this.groupBox3.Controls.Add(this.label6); + this.groupBox3.Controls.Add(this.radioButton2); + this.groupBox3.Controls.Add(this.radioButton1); + this.groupBox3.Location = new System.Drawing.Point(16, 16); + this.groupBox3.Margin = new System.Windows.Forms.Padding(4); + this.groupBox3.Name = "groupBox3"; + this.groupBox3.Padding = new System.Windows.Forms.Padding(4); + this.groupBox3.Size = new System.Drawing.Size(656, 144); + this.groupBox3.TabIndex = 8; + this.groupBox3.TabStop = false; + this.groupBox3.Text = "请选择存储方案"; + // + // InitMysqlForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(692, 522); + this.Controls.Add(this.statusStrip1); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.groupBox2); + this.Controls.Add(this.groupBox3); + this.Margin = new System.Windows.Forms.Padding(5); + this.Name = "InitMysqlForm"; + this.Text = "初始化数据库"; + this.Load += new System.EventHandler(this.InitMysqlForm_Load); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); + this.groupBox3.ResumeLayout(false); + this.groupBox3.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ToolStripStatusLabel tool_status; + private System.Windows.Forms.StatusStrip statusStrip1; + private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.RadioButton radioButton1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label7; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.RadioButton radioButton2; + private System.Windows.Forms.GroupBox groupBox2; + private System.Windows.Forms.GroupBox groupBox3; + private System.Windows.Forms.TextBox textBox4; + private System.Windows.Forms.TextBox textBox3; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.TextBox textBox1; + } +} \ No newline at end of file diff --git a/Server/Winforms/InitMysqlForm.cs b/Server/Winforms/InitMysqlForm.cs new file mode 100644 index 0000000..b818baf --- /dev/null +++ b/Server/Winforms/InitMysqlForm.cs @@ -0,0 +1,360 @@ +using ICSharpCode.SharpZipLib.Zip; +using Server.Utils; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server.Winforms +{ + internal partial class InitMysqlForm : DefaultForm + { + Client Client; + public InitMysqlForm(Client Client) + { + InitializeComponent(); + this.Client = Client; + } + + private void InitMysqlForm_Load(object sender, EventArgs e) + { + + } + private void SetStatusText(string text) + { + if (!this.IsDisposed) + { + this.Invoke(new Action(delegate () + { + this.tool_status.Text = text; + })); + } + } + public void DownloadFile(string URL, string filename, ProgressBar prog = null) + { + float percent = 0; + if (File.Exists(filename)) File.Delete(filename); + + Stream st = null; + Stream so = null; + System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL); + System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse(); + long totalBytes = myrp.ContentLength; + prog?.Invoke(new Action(delegate + { + prog.Value = 0; + prog.Maximum = (int)totalBytes; + + })); + + st = myrp.GetResponseStream(); + so = new System.IO.FileStream(filename, System.IO.FileMode.Create); + try + { + long totalDownloadedByte = 0; + byte[] by = new byte[1024]; + int osize = st.Read(by, 0, (int)by.Length); + while (osize > 0) + { + + totalDownloadedByte = osize + totalDownloadedByte; + Application.DoEvents(); + so.Write(by, 0, osize); + + prog?.Invoke(new Action(delegate { prog.Value = (int)totalDownloadedByte; })); + osize = st.Read(by, 0, (int)by.Length); + percent = (float)totalDownloadedByte / (float)totalBytes * 100; + if (prog != null) Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息 + } + } + catch (Exception ex) + { + if (File.Exists(filename)) File.Delete(filename); + if (so != null) + { + so.Close(); + so.Dispose(); + so = null; + } + if (st != null) + { + st.Close(); + st.Dispose(); + st = null; + } + + + throw ex; + } + finally + { + if (so != null) + { + so.Close(); + so.Dispose(); + so = null; + } + if (st != null) + { + st.Close(); + st.Dispose(); + st = null; + } + } + } + + + /// + /// 功能:解压zip格式的文件。 + /// + /// 压缩文件路径 + /// 解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 + /// 出错信息 + /// 解压是否成功 + public void UnZip(string zipFilePath, string unZipDir) + { + try + { + if (zipFilePath == string.Empty) + { + throw new Exception("压缩文件不能为空!"); + } + if (!File.Exists(zipFilePath)) + { + throw new System.IO.FileNotFoundException("压缩文件不存在!"); + } + //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹 + if (unZipDir == string.Empty) + unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), + Path.GetFileNameWithoutExtension(zipFilePath)); + if (!unZipDir.EndsWith("/")) + unZipDir += "/"; + if (!Directory.Exists(unZipDir)) + Directory.CreateDirectory(unZipDir); + + using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath))) + { + + ZipEntry theEntry; + while ((theEntry = s.GetNextEntry()) != null) + { + string directoryName = Path.GetDirectoryName(theEntry.Name); + string fileName = Path.GetFileName(theEntry.Name); + if (directoryName.Length > 0) + { + Directory.CreateDirectory(unZipDir + directoryName); + } + if (!directoryName.EndsWith("/")) + directoryName += "/"; + if (fileName != String.Empty) + { + using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name)) + { + int size = 1024 * 10; + byte[] data = new byte[size]; + while (true) + { + size = s.Read(data, 0, data.Length); + if (size > 0) + { + streamWriter.Write(data, 0, size); + } + else + { + break; + } + } + } + } + } + } + } + catch (Exception ex) + { + //如果解压失败,删除掉. 刚刚解压的内容 + DeletePath(unZipDir); + throw ex; + } + } + //创建方法,删除文件夹中的所有文件包括文件夹本身 + public void DeletePath(string file) + { + try + { + //去除文件夹和子文件的只读属性 + //去除文件夹的只读属性 + System.IO.DirectoryInfo fileInfo = new DirectoryInfo(file); + fileInfo.Attributes = FileAttributes.Normal & FileAttributes.Directory; + //去除文件的只读属性 + System.IO.File.SetAttributes(file, System.IO.FileAttributes.Normal); + //判断文件夹是否还存在 + if (Directory.Exists(file)) + { + foreach (string f in Directory.GetFileSystemEntries(file)) + { + if (File.Exists(f)) + { + //如果有子文件删除文件 + File.Delete(f); + } + else + { + //循环递归删除子文件夹 + DeletePath(f); + } + } + //删除空文件夹 + Directory.Delete(file); + } + } + catch (Exception) + { + + + } + } + + private void button1_Click(object sender, EventArgs e) + { + this.button1.Enabled = false; + Task.Factory.StartNew(delegate () + { + try + { + var mysql_name = textBox1.Text.Trim().ToLower(); + var mysql_port = (int)numericUpDown1.Value; + var mysql_user = textBox2.Text.Trim(); + var mysql_pass = textBox3.Text.Trim(); + var mysql_host = textBox4.Text.Trim(); + + SetStatusText("正在检测..."); + if (this.radioButton1.Checked) + { + var ServerName = "mysql8.0"; + var Server = ServiceInstaller.GetServiceController(ServerName); + if (Server == null) + { + var mysqlPath = @"C:\mysql8.0"; + //确认没有解压文件 + if (!System.IO.Directory.Exists(mysqlPath)) + { + //找到压缩包 + var mysqlFile = CsharpHttpHelper.HttpExtend.MapFile("mysql8.0.zip", "File"); + if (!File.Exists(mysqlFile)) + { + SetStatusText("正在下载mysql8.0安装包..."); + DownloadFile("http://qiniu.down.api.52cmg.cn/mysql8.0.zip", mysqlFile); + } + if (!File.Exists(mysqlFile)) throw new Exception("找不到mysql8.0的安装包"); + + SetStatusText("正在安装mysql8.0..."); + UnZip(mysqlFile, mysqlPath); + } + Thread.Sleep(1000); + ServiceInstaller.InitServer(@"C:\mysql8.0\bin\mysqld", ServerName); + Server = ServiceInstaller.GetServiceController(ServerName); + int index = 0; + while (index < 30 && Server == null) + { + index++; + System.Threading.Thread.Sleep(1000); + Server = ServiceInstaller.GetServiceController(ServerName); + } + } + if (Server == null) + { + throw new Exception("安装失败,请联系客服人员处理"); + } + else if (Server.Status == System.ServiceProcess.ServiceControllerStatus.Running) + { + SetStatusText("MySQL 8.0 环境监测通过!"); + } + else + { + Server.Start(); + SetStatusText("MySQL 8.0 环境监测通过!"); + } + + mysql_name = "fanli_v2"; + mysql_user = "root"; + mysql_pass = "123456"; + mysql_port = 3306; + mysql_host = "127.0.0.1"; + } + else + { + if (string.IsNullOrEmpty(mysql_name)) mysql_name = "fanli_v2"; + } + + SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() + { + ConnectionString = $"Data Source={mysql_host};Persist Security Info=True;User ID={mysql_user};Password={mysql_pass};Port={mysql_port};Min Pool Size = 1; Max Pool Size = 1;Charset=utf8mb4;",//连接符字串 + DbType = SqlSugar.DbType.MySql, //数据库类型 + IsAutoCloseConnection = true //不设成true要手动close + }); + + var DbList = db.DbMaintenance.GetDataBaseList(db); + if (!DbList.Contains(mysql_name)) + { + // COLLATE utf8mb4_general_ci + if (db.Ado.ExecuteCommand($"CREATE DATABASE {mysql_name} DEFAULT CHARACTER SET utf8mb4 ;") == 0) + { + throw new Exception("自动创建数据库失败!"); + } + } + + + Client.Config.Ini.SetValue("Mysql", "名称", mysql_name); + Client.Config.Ini.SetValue("Mysql", "账号", mysql_user); + Client.Config.Ini.SetValue("Mysql", "密码", mysql_pass); + Client.Config.Ini.SetValue("Mysql", "IP", mysql_host); + Client.Config.Ini.SetValue("Mysql", "端口", mysql_port.ToString()); + + Client.Config.MysqlPort = mysql_port; + Client.Config.MysqlPass = mysql_pass; + Client.Config.MysqlName = mysql_name; + Client.Config.MysqlHost = mysql_host; + Client.Config.MysqlUser = mysql_user; + + this.Invoke(new Action(delegate + { + this.DialogResult = DialogResult.Yes; + this.Close(); + })); + } + catch (Exception ex) + { + this.Invoke(new Action(delegate () + { + this.tool_status.Text = ex.Message; + MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + })); + + } + finally + { + //if (this.IsAccessible) + { + this.Invoke(new Action(delegate + { + this.button1.Enabled = true; + })); + } + } + }); + } + + private void radioButton_CheckedChanged(object sender, EventArgs e) + { + groupBox2.Enabled = radioButton2.Checked; + } + } +} diff --git a/Server/Winforms/InitMysqlForm.resx b/Server/Winforms/InitMysqlForm.resx new file mode 100644 index 0000000..174ebc7 --- /dev/null +++ b/Server/Winforms/InitMysqlForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LianMengWebViewLoginHelper.cs b/Server/Winforms/LoginForms/LianMengWebViewLoginHelper.cs new file mode 100644 index 0000000..b3f057f --- /dev/null +++ b/Server/Winforms/LoginForms/LianMengWebViewLoginHelper.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Common.DbExtends.Extends; +using EO.Base; +using EO.WebBrowser; +using EO.WebEngine; + +namespace Server.Winforms.LoginForms +{ + /// + /// 无头浏览登陆操作 + /// + public class LianMengWebViewLoginHelper + { + public void InitDefaultWebview(int Number) + { + ThreadPool.QueueUserWorkItem(o => + { + for (int i = 0; i < Number; i++) + { + var login = CreateLogin(); + if (login != null) + { + _queues.Enqueue(login); + } + Thread.Sleep(1000); + } + }); + } + private static LianMengWebViewLoginHelper _helper; + private static object lockobj = new object(); + /// + /// 获取对象 + /// + public static LianMengWebViewLoginHelper Instance + { + get + { + if (_helper != null) + { + return _helper; + } + lock (lockobj) + { + if (_helper != null) + { + return _helper; + } + _helper = new LianMengWebViewLoginHelper(); + return _helper; + } + } + } + /// + /// 浏览器控制对象 + /// (需要创建一个隔离区域) + /// + public ThreadRunner GetNewThreadRunner() + { + var name = Guid.NewGuid().ToString("N"); + EO.Base.Runtime.EnableEOWP = true; + EO.WebEngine.Engine engine = EO.WebEngine.Engine.Create(name); + engine.Options.Proxy = ProxyInfo.Direct;//绕过代理 + //设置浏览器语言 + engine.Options.UILanguage = "zh-CN,zh;q=0.9,en;q=0.8"; + //设置缓存目录 + engine.Options.CachePath = Common.Utils.Util.MapPath($"Cache\\WebBrowser\\{name}"); + EO.WebEngine.BrowserOptions options = new EO.WebEngine.BrowserOptions(); + //options.AllowJavaScript = false;//禁用JS + //options.LoadImages = false;//禁用图像加载 + //options.EnableWebSecurity = false;//设置为false,启用本地文件访问 + engine.Options.SetDefaultBrowserOptions(options);//引擎级别 + return new ThreadRunner(name, engine); + } + + /// + /// 线程安全的队列集合 + /// + public ConcurrentQueue _queues { get; private set; } = new ConcurrentQueue(); + + /// + /// 生成一个新的浏览器View + /// + /// + private LianmengWebViewLogin CreateLogin() + { + for (int i = 0; i < 5; i++) + { + try + { + var newThreadRunner = GetNewThreadRunner(); + var webView = newThreadRunner.CreateWebView(); + return new LianmengWebViewLogin(newThreadRunner, webView); + } + catch (Exception ex) + { + Client.SingleClient.Db.OnLog("生成一个新得浏览器",ex); + Thread.Sleep(1000); + } + } + return null; + } + /// + /// 获取一个浏览器登陆服务 + /// + /// + public LianmengWebViewLogin GetViewLogin() + { + if (_queues.IsEmpty) + { + return CreateLogin(); + } + if (_queues.TryDequeue(out var res)) + { + //新增一个 + ThreadPool.QueueUserWorkItem(o => + { + var client = CreateLogin(); + if (client != null) + { + _queues.Enqueue(client); + } + }); + return res; + } + return CreateLogin(); + } + } +} diff --git a/Server/Winforms/LoginForms/LianmengWebViewLogin.cs b/Server/Winforms/LoginForms/LianmengWebViewLogin.cs new file mode 100644 index 0000000..1a8e9e4 --- /dev/null +++ b/Server/Winforms/LoginForms/LianmengWebViewLogin.cs @@ -0,0 +1,744 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Windows.Forms; +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using CsharpHttpHelper; +using EO.WebBrowser; +using Newtonsoft.Json.Linq; +using Server.MyClass.Views; +using Timer = System.Threading.Timer; + +namespace Server.Winforms.LoginForms +{ + /// + /// 用浏览器登陆服务 + /// + public class LianmengWebViewLogin : IDisposable + { + public ThreadRunner ThreadRunner { get; set; } + public WebView WebView { get; set; } + + public LianmengWebViewLogin(ThreadRunner threadRunner, WebView webView) + { + ThreadRunner = threadRunner; + WebView = webView; + WebView.CertificateError += WebView_CertificateError; + WebView.LoadCompleted += WebView_LoadCompleted; + WebView.NewWindow += WebView_NewWindow; + var sHandler = new SampleHandler(); + sHandler.AfterReceiveData += SHandler_AfterReceiveData; + WebView.RegisterResourceHandler(sHandler);//注册自定义资源处理程序 + LoadUrl("about:blank"); + _timer = new Timer(o => + { + this.Dispose(); + }, null, TimeSpan.FromMinutes(5), TimeSpan.FromMilliseconds(-1)); + } + + private Timer _timer; + private void SHandler_AfterReceiveData(string url, JToken token) + { + try + { + if (url.StartsWith("https://login.taobao.com/newlogin/qrcode/generate.do")) + { + if (token["content"] != null && token["content"]["data"] != null && token["content"]["data"]["codeContent"] != null) + { + QRCodeStatus = LoginQRCodeStatus.等待扫码; + QRCodeUrl = token["content"]["data"]["codeContent"].ToString(); + } + else + { + QRCodeStatus = LoginQRCodeStatus.获取二维码失败; + this.Dispose(); + } + } + else if (url.StartsWith("https://login.taobao.com/newlogin/qrcode/query.do")) + { + if (token["content"] != null && token["content"]["data"] != null && token["content"]["data"]["qrCodeStatus"] != null) + { + var qrStatus = token["content"]["data"]["qrCodeStatus"].ToString(); + if (qrStatus == "NEW") + QRCodeStatus = LoginQRCodeStatus.等待扫码; + else if (qrStatus == "SCANED") + QRCodeStatus = LoginQRCodeStatus.等待确认登录; + else if (qrStatus == "EXPIRED") + { + QRCodeStatus = LoginQRCodeStatus.二维码已过期; + this.Dispose(); + + } + else if (qrStatus == "CONFIRMED") + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + + } + else + { + Console.WriteLine(qrStatus); + } + + } + + } + else if (url.StartsWith("https://verify.meituan.com/v2/ext_api/login/verify")) + { + if (token != null && token["error"] != null && token["error"]["message"] != null) + { + var error = token["error"]["message"].ToString(); + if (!string.IsNullOrEmpty(error)) + { + this.ErrorMsg = error; + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + this.Dispose(); + } + } + } + } + catch (Exception) + { + + } + } + + public string Msgid = Guid.NewGuid().ToString("N"); + + public string QRCodeUrl = string.Empty; + public LoginQRCodeStatus QRCodeStatus = LoginQRCodeStatus.正在获取二维码; + public string ErrorMsg = string.Empty; + public string Cookies; + public string LoginTelphone { get; set; } + + /// + /// 创建了新的窗口 + /// + /// + /// + private void WebView_NewWindow(object sender, NewWindowEventArgs e) + { + var webView = sender as WebView; + if (webView == null) + { + return; + } + ThreadRunner.Post(() => + { + webView.LoadUrl(e.TargetUrl); + }); + } + private JToken UserToken; + + + /// + /// 页面加载完成 + /// + /// + /// + private void WebView_LoadCompleted(object sender, LoadCompletedEventArgs e) + { + try + { + var url = this.WebView.Url; + //if (!string.IsNullOrWhiteSpace(url)) + //{ + // ThreadPool.QueueUserWorkItem(o => + // { + // this.ThreadRunner.Send(() => + // { + // var img = this.WebView.Capture(false); + // img.Save(DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg"); + // }); + // }); + //} + //Console.WriteLine($"目标地址:" + url); + if (url == "about:blank") + { + return; + } + + + + #region 登录淘宝联盟 + else if (url == alimama) + { + var js = @" +var codeBtn = document.getElementsByClassName('iconfont icon-qrcode'); +if(codeBtn && codeBtn.length==1) +{ + codeBtn[0].click(); +} +"; + this.ThreadRunner.Send(() => + { + this.WebView.EvalScript(js); + }); + } + else if (url.StartsWith("https://www.alimama.com/index.htm")) + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + this.ThreadRunner.Post(() => + { + var ck = this.WebView.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + var target = $"{Client.SingleClient.Url}/lianmeng/logintaobaocallback"; + var sqUrl = $"http://cps.api.52cmg.cn/api/login.aspx?m=login_taobao&url={HttpUtility.UrlEncode(target)}"; + this.LoadUrl(sqUrl); + }); + + } + else if (url.StartsWith("https://oauth.taobao.com/authorize")) + { + this.ThreadRunner.Send(() => + { + this.WebView.EvalScript($"document.getElementById('sub').click();"); + }); + } + else if (url.StartsWith(Client.SingleClient.Url)) + { + System.Threading.Thread.Sleep(300); + var Params = HttpUtility.ParseQueryString(url); + var UserId = Params.Get("taobao_user_id"); + var lm = Client.SingleClient.Db.Queryable().WithCache().First(f => f.Username == UserId && f.LianmengType == LianmengType.淘宝联盟); + if (lm != null) + { + lm.Cookies = this.Cookies; + lm.IsCookiValid = true; + Client.SingleClient.Db.Save(lm); + } + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + + //启动一个线程,去同步PID + Task.Factory.StartNew(() => + { + try + { + var req = new TaobaoRequest(lm, null); + var pids = req.QueryAdzones(); + if (pids.Count > 0) + { + var db = Client.SingleClient.Db; + db.UseTran(() => + { + foreach (var item in pids) + { + var media = db.Queryable().Where(f => f.LianmengId == lm.Id && f.SiteId == item.siteId && f.AdzoneId == item.adzoneId).First(); + if (media == null) + media = new TbMedia() { LianmengId = lm.Id, SiteId = item.siteId, AdzoneId = item.adzoneId }; + + + if (media.Id == 0 || media.AdzoneName != item.adzoneName || media.SiteName != item.siteName) + { + if (item.isSpecial) + media.IsSpecial = item.isSpecial; + + media.AdzoneName = item.adzoneName; + media.SiteName = item.siteName; + media.Pid = item.pid; + db.Storageable(media).ExecuteCommand(); + } + } + }); + } + } + catch (Exception) + { + } + }); + this.Dispose(); + } + #endregion + + #region 登录抖音联盟 + else if (url.StartsWith("https://buyin.jinritemai.com/mpa/account/login")) + { + this.ThreadRunner.Post(() => + { + var res = this.WebView.EvalScript("document.getElementsByClassName('platform-logo')[0].click();"); + }); + } + else if (url.StartsWith("https://open.douyin.com/platform/oauth/connect")) + { + this.ThreadRunner.Post(() => + { + ; + WebView.EvalScript(@"function getqr() + { + var imgs = document.getElementsByClassName('qr'); + if(imgs.length>0 && imgs[0].src && imgs[0].src.length>10) + { + return imgs[0].src; + } +return ''; + } +", false); + var timeout = DateTime.Now.AddSeconds(10); + while (timeout > DateTime.Now) + { + Util.Sleep(100); + this.QRCodeUrl = WebView.InvokeFunction("getqr")?.ToString(); + if (string.IsNullOrEmpty(this.QRCodeUrl)) + { + continue; + } + else + { + break; + } + } + if (!string.IsNullOrEmpty(this.QRCodeUrl)) + { + QRCodeStatus = LoginQRCodeStatus.等待扫码; + } + }); + } + else if (url.StartsWith("https://buyin.jinritemai.com/dashboard/institution/through-power")) + { + //auxo-btn auxo-btn-primary auxo-btn-lg + this.ThreadRunner.Post(() => + { + var timeout = DateTime.Now.AddSeconds(10); + while (timeout > DateTime.Now) + { + Util.Sleep(1000); + if (!WebView.Url.StartsWith("https://buyin.jinritemai.com/dashboard/institution/through-power")) break; + else + { + this.ThreadRunner.Send(() => + { + WebView.EvalScript(@"function excute_js() + { + var btn = document.getElementsByClassName('auxo-btn auxo-btn-primary auxo-btn-lg'); + if(btn.length>0 ) + { + btn[0].click(); + return true; + } +return false; + } +", false); + }); + } + } + }); + } + else if (url.StartsWith("https://buyin.jinritemai.com/dashboard")) + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + this.ThreadRunner.Post(() => + { + var ck = WebView.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + var json = DouyinRequest.GetLoginUserInfo(this.Cookies, Ua); + var jObj = JObject.Parse(json); + if (jObj["code"] != null) + { + var code = jObj["code"].ToString(); + if (code == "0") + { + var shop_id = jObj["data"]["shop_id"].ToString(); + if (shop_id == "0") + { + ErrorMsg = $@"该账号未开通商品分享功能,请开通后重试 + +注:开通电商权限,需要同时满足以下4个条件 +①、账号实名认证 +②、个人主页视频数(公开且审核通过)≥ 10 条 +③、账号粉丝量(绑定第三方粉丝量不计数)≥ 1000 +④、商品分享保证金 ¥500立即充值"; + QRCodeStatus = LoginQRCodeStatus.登录失败; + + return; + } + else + { + UserToken = jObj["data"]; + var sqUrl = $"http://cps.api.52cmg.cn/api/douyin.asmx/login"; + this.LoadUrl(sqUrl); + return; + } + + } + } + this.ErrorMsg = "无法识别:" + json; + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + }); + } + else if (url.StartsWith("http://cps.api.52cmg.cn/api/douyin.asmx/login_result")) + { + this.ThreadRunner.Post(() => + { + var json = WebView.GetText(); + if (!string.IsNullOrWhiteSpace(json)) + { + var jObj = JObject.Parse(json); + if (jObj != null && (bool)jObj["ok"]) + { + var u = jObj["message"]; + var username = u["authority_id"].ToString(); + var douyin = Client.SingleClient.Db.Queryable().Where(f => f.Username == username && f.LianmengType == Common.Models.Enums.LianmengType.抖音联盟).First(); + if (douyin == null) + { + douyin = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.抖音联盟, + Username = u["authority_id"].ToString() + }; + }; + + douyin.ReToken = u["refresh_token"].ToString(); + douyin.ExpirationTime = DateTime.Parse(u["expires_time"].ToString()); + douyin.Cookies = this.Cookies; + douyin.Token = u["access_token"].ToString(); + douyin.Nickname = UserToken["shop_name"].ToString(); + douyin.IsCookiValid = true; + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + Client.SingleClient.Db.Save(douyin); + + Task.Factory.StartNew(() => + { + try + { + DouyinRequest req = new DouyinRequest(douyin); + //查询抖音推广位 + var list = req.GetDouyinPidAdzone(); + if (list.Count > 0) + { + var db = Client.SingleClient.Db; + try + { + db.BeginTran(); + foreach (var item in list) + { + var media = db.Queryable().Where(f => f.LianmengId == douyin.Id && f.Pid == item.pid).First(); + if (media == null) + { + media = new DyMedia() { Pid = item.pid, LianmengId = douyin.Id }; + } + + if (media.Id == 0 || media.UpdateTime != item.update_time) + { + media.MediaType = (DouyinMediaType)item.media_type; + media.AdzoneName = item.site_name; + media.MediaName = item.media_name; + media.UpdateTime = item.update_time; + db.Save(media); + } + } + db.CommitTran(); + } + catch (Exception ex) + { + db.RollbackTran(); + Client.SingleClient.Db.OnLog("更新抖音推广位", ex); + } + } + } + catch (Exception ex) + { + Client.SingleClient.Db.OnLog("更新抖音推广位", ex); + } + }); + this.Dispose(); + } + } + }); + } + #endregion + + #region 登录美团联盟 + else if (url == "https://pub.meituan.com/#/api-doc") + { + + Util.Sleep(500); + this.ThreadRunner.Post(() => + { + this.WebView.EvalScript($"" + + $"document.getElementById('phoneNumInput').focus();" + ); + Util.Sleep(100); + var chars = this.LoginTelphone.ToCharArray(); + foreach (int item in chars) + { + switch (item) + { + case 49: + this.WebView.SendKeyEvent(true, KeyCode.D0); + break; + case 50: + this.WebView.SendKeyEvent(true, KeyCode.D1); + break; + case 51: + this.WebView.SendKeyEvent(true, KeyCode.D2); + break; + case 52: + this.WebView.SendKeyEvent(true, KeyCode.D3); + break; + case 53: + this.WebView.SendKeyEvent(true, KeyCode.D4); + break; + case 54: + this.WebView.SendKeyEvent(true, KeyCode.D5); + break; + case 55: + this.WebView.SendKeyEvent(true, KeyCode.D6); + break; + case 56: + this.WebView.SendKeyEvent(true, KeyCode.D7); + break; + case 57: + this.WebView.SendKeyEvent(true, KeyCode.D8); + break; + case 58: + this.WebView.SendKeyEvent(true, KeyCode.D9); + break; + } + Util.Sleep(1000); + } + //Util.Sleep(500); + WebView.EvalScript("document.getElementById('sendCodeBtnText').click();"); + this.QRCodeStatus = LoginQRCodeStatus.等待确认登录; + }); + } + else if (url == "https://pub.meituan.com/#/sign-manage") + { + this.ThreadRunner.Post(() => + { + var ck = WebView.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + var http = new HttpHelper(); + var html = http.GetHtml("https://pub.meituan.com/benchmark/login/appkey", this.Cookies).Html; + var json = JObject.Parse(html); + if (json["msg"].ToString() == "成功") + { + html = http.GetHtml("https://pub.meituan.com/benchmark/login/userinfo", this.Cookies).Html; + var u = JObject.Parse(html)["data"]; + var username = u["mainMtUserId"].ToString(); + + var douyin = Client.SingleClient.Db.Queryable().Where(f => f.Username == username && f.LianmengType == Common.Models.Enums.LianmengType.美团联盟).First(); + if (douyin == null) + { + douyin = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.美团联盟, + Username = username, + Remark = LoginTelphone + }; + }; + + douyin.ReToken = json["utmSource"].ToString(); + douyin.ExpirationTime = DateTime.Now.AddYears(100); + douyin.Cookies = this.Cookies; + douyin.Token = json["data"].ToString(); + douyin.Nickname = u["nickName"].ToString(); + douyin.IsCookiValid = true; + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + Client.SingleClient.Db.Save(douyin); + + } + else + { + this.ErrorMsg = json["msg"].ToString(); + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + } + }); + } + #endregion + } + catch (Exception ex) + { + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + this.ErrorMsg = ex.Message; + } + } + /// + /// 证书错误 + /// + /// + /// + private void WebView_CertificateError(object sender, CertificateErrorEventArgs e) + { + } + /// + /// 加载地址 + /// + /// + public void LoadUrl(string url) + { + Thread.Sleep(1000); + ThreadRunner.Post(() => + { + WebView.LoadUrl(url); + }); + } + /// + /// 释放浏览器 + /// + public void Dispose() + { + //停止计时器 + if (_timer != null) + { + _timer.Dispose(); + } + if (WebView != null) + { + WebView?.Dispose(); + } + if (this.ThreadRunner != null) + { + this.ThreadRunner?.Dispose(); + } + WebView = null; + this.ThreadRunner = null; + _timer = null; + } + + + + + private const string Ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"; + private const string alimama = "https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&css_style=alimama&from=alimama&redirectURL=http%3A%2F%2Fwww.alimama.com&full_redirect=true&disableQuickLogin=true&qq-pf-to=pcqq.c2c"; + + public LianmengType LoginType { get; set; } + public void Start(LianmengType Type) + { + this.LoginType = Type; + switch (Type) + { + case LianmengType.淘宝联盟: + this.LoadUrl(alimama); + break; + case LianmengType.京东联盟: + break; + case LianmengType.拼多多联盟: + break; + case LianmengType.唯品会联盟: + break; + case LianmengType.苏宁联盟: + break; + case LianmengType.抖音联盟: + this.LoadUrl("https://buyin.jinritemai.com/mpa/account/login?log_out=1&type=24&target_url="); + break; + case LianmengType.美团联盟: + this.LoadUrl("https://pub.meituan.com/#/api-doc"); + break; + default: + break; + } + } + + + #region 自定义响应Response 20210321 + + private class SampleHandler : ResourceHandler + { + string[] Urls = new string[] { "https://login.taobao.com/newlogin/qrcode/generate.do" }; + public event System.Action AfterReceiveData; + //此方法判断是否自定义处理响应 + public override bool Match(Request request) + { + for (int i = 0; i < Urls.Length; i++) + { + if (request.Url.StartsWith(Urls[i])) + { + return true; + } + } + + return false; + } + + //如果自定义响应,则在这里处理请求,并返回要显示的信息 + public override void ProcessRequest(Request request, EO.WebBrowser.Response response) + { + try + { + var cookies = Regex.Replace(request.Cookies.ToString(), "path=/", "").Replace("\r\n", ""); + var useragent = request.Headers["User-Agent"]; + var http = new HttpHelper(); + var item = new HttpItem() + { + URL = request.Url, + ContentType = "application/x-www-form-urlencoded", + Method = request.Method, + Timeout = 5000, + Cookie = cookies, + UserAgent = useragent + }; + + + if (request.PostData != null && request.PostData.Count == 1) + { + var data = Encoding.UTF8.GetString(request.PostData[0].Data); + item.Postdata = data; + } + + + + + var result = http.GetHtml(item); + //头部信息更新 + if (result.Header != null && result.Header.Count > 0) + { + foreach (var key in result.Header.AllKeys) + { + response.Headers[key] = result.Header[key]; + } + } + + + + //Cookies更新 + if (!string.IsNullOrEmpty(result.Cookie)) + { + var temp_cookiesStr = Regex.Replace(HttpHelper.GetSmallCookie(result.Cookie), "path=/", "").Replace("\r\n", ""); + + var temp_cookies = temp_cookiesStr.Split(';'); + + foreach (var ck in temp_cookies) + { + var temp_ck = ck.Split('='); + if (temp_ck.Length == 2) + { + response.Cookies.Add(new EO.WebEngine.Cookie(temp_ck[0].Trim(), temp_ck[1].Trim())); + } + } + } + + response.ContentType = "application/json";//必须设置,否则会弹出对话框并无法显示在EO.Web控件上 + response.ContentEncoding = "UTF-8";//必须设置,否则中文显示乱码 + byte[] be = Encoding.UTF8.GetBytes(result.Html); + response.OutputStream.Write(be, 0, be.Length); + response.OutputStream.Close(); + AfterReceiveData.Invoke(request.Url, JToken.Parse(result.Html)); + } + catch + { + // ignored + } + + base.ProcessRequest(request, response); + } + } + #endregion + } +} diff --git a/Server/Winforms/LoginForms/LoginAlimamaFrom.Designer.cs b/Server/Winforms/LoginForms/LoginAlimamaFrom.Designer.cs new file mode 100644 index 0000000..293ad99 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginAlimamaFrom.Designer.cs @@ -0,0 +1,80 @@ +namespace Server.Winforms.LoginForms +{ + partial class LoginAlimamaFrom + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.webControl1 = new EO.WinForm.WebControl(); + this.webView1 = new EO.WebBrowser.WebView(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // webControl1 + // + this.webControl1.BackColor = System.Drawing.Color.White; + this.webControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.webControl1.Location = new System.Drawing.Point(0, 0); + this.webControl1.Name = "webControl1"; + this.webControl1.Size = new System.Drawing.Size(347, 303); + this.webControl1.TabIndex = 0; + this.webControl1.WebView = this.webView1; + // + // webView1 + // + this.webView1.InputMsgFilter = null; + this.webView1.ObjectForScripting = null; + this.webView1.Title = null; + // + // timer1 + // + this.timer1.Enabled = true; + this.timer1.Interval = 300000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // LoginAlimamaFrom + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(347, 303); + this.Controls.Add(this.webControl1); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "LoginAlimamaFrom"; + this.Text = "登录阿里妈妈"; + this.Load += new System.EventHandler(this.LoginAlimama_Load); + this.ResumeLayout(false); + + } + + #endregion + + private EO.WinForm.WebControl webControl1; + private EO.WebBrowser.WebView webView1; + private System.Windows.Forms.Timer timer1; + } +} \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginAlimamaFrom.cs b/Server/Winforms/LoginForms/LoginAlimamaFrom.cs new file mode 100644 index 0000000..8a73448 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginAlimamaFrom.cs @@ -0,0 +1,311 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using CsharpHttpHelper; +using CsharpHttpHelper.Enum; +using EO.Base; +using EO.WebBrowser; +using Newtonsoft.Json.Linq; +using Server.MyClass.Views; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Web; +using System.Windows.Forms; + +namespace Server.Winforms.LoginForms +{ + public partial class LoginAlimamaFrom : LoginBaseForm + { + + public LoginAlimamaFrom() + { + InitializeComponent(); + } + + private const string alimama = "https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&css_style=alimama&from=alimama&redirectURL=http%3A%2F%2Fwww.alimama.com&full_redirect=true&disableQuickLogin=true&qq-pf-to=pcqq.c2c"; + + private void InitEobrowser(string DefaultUrl) + { + var MyWeb = this.webView1; + var Name = Guid.NewGuid().ToString("N"); + + EO.Base.Runtime.EnableEOWP = true; + EO.WebEngine.Engine engine = EO.WebEngine.Engine.Create(Name); + engine.Options.Proxy = ProxyInfo.Direct;//绕过代理 + //设置浏览器语言 + engine.Options.UILanguage = "zh-CN,zh;q=0.9,en;q=0.8"; + //设置缓存目录 + engine.Options.CachePath = Common.Utils.Util.MapPath($"Cache\\WebBrowser\\{Name}"); + EO.WebEngine.BrowserOptions options = new EO.WebEngine.BrowserOptions(); + //options.AllowJavaScript = false;//禁用JS + //options.LoadImages = false;//禁用图像加载 + //options.EnableWebSecurity = false;//设置为false,启用本地文件访问 + engine.Options.SetDefaultBrowserOptions(options);//引擎级别 + MyWeb.Engine = engine; + MyWeb.AcceptLanguage = engine.Options.UILanguage; + + //MyWeb.LoadFailed += MyWeb_LoadFailed;//加载失败 + //MyWeb.TitleChanged += MyWeb_TitleChanged;//Title改变 + //MyWeb.BeforeRequestLoad += MyWeb_BeforeRequestLoad;//在请求加载之前 + //MyWeb.BeforeSendHeaders += MyWeb_BeforeSendHeaders;//发送请求头之前 + //MyWeb.AfterReceiveHeaders += MyWeb_AfterReceiveHeaders;//接收请求头之后 + //MyWeb.UrlChanged += MyWeb_UrlChanged;//地址改变事件 + MyWeb.LoadCompleted += MyWeb_LoadCompleted;//加载完成事件 + //MyWeb.NewWindow += MyWeb_NewWindow;//打开新窗口事件 + //MyWeb.GotFocus += MyWeb_GotFocus;//得到焦点 + //MyWeb.JSExtInvoke += MyWeb_JSExtInvoke;//JS外部调用 + //MyWeb.JSDialog += MyWeb_JSDialog;//JS对话框 + //MyWeb.ConsoleMessage += MyWeb_ConsoleMessage;//控制台消息 + //MyWeb.ShouldForceDownload += MyWeb_ShouldForceDownload;//应强制下载 + //MyWeb.NeedCredentials += MyWeb_NeedCredentials;//当网页需要身份验证时,EO.WebBrowser引发NeedCredentials 事件。如果您不处理此事件,则默认实现将显示一个对话框,询问用户用户名和密码。 + //MyWeb.CertificateError += MyWeb_CertificateError;//证书错误事件 + MyWeb.NewWindow += WebView_NewWindow; + var sHandler = new SampleHandler(); + sHandler.AfterReceiveData += SHandler_AfterReceiveData; + webControl1.WebView.RegisterResourceHandler(sHandler);//注册自定义资源处理程序 + + MyWeb.LoadUrl(DefaultUrl); + + } + + private void WebView_NewWindow(object sender, NewWindowEventArgs e) + { + webControl1.WebView.LoadUrl(e.TargetUrl); + } + + + + #region 自定义响应Response 20210321 + + private class SampleHandler : ResourceHandler + { + string[] Urls = new string[] { "https://login.taobao.com/newlogin/qrcode/generate.do"}; + public event System.Action AfterReceiveData; + //此方法判断是否自定义处理响应 + public override bool Match(Request request) + { + for (int i = 0; i < Urls.Length; i++) + { + if (request.Url.StartsWith(Urls[i])) + { + return true; + } + } + + return false; + } + + //如果自定义响应,则在这里处理请求,并返回要显示的信息 + public override void ProcessRequest(Request request, EO.WebBrowser.Response response) + { + try + { + var cookies = Regex.Replace(request.Cookies.ToString(), "path=/", "").Replace("\r\n", ""); + var useragent = request.Headers["User-Agent"]; + var http = new HttpHelper(); + var item = new HttpItem() + { + URL = request.Url, + ContentType = "application/x-www-form-urlencoded", + Method = request.Method, + Timeout = 5000, + Cookie = cookies, + UserAgent = useragent + }; + + + if (request.PostData != null && request.PostData.Count == 1) + { + var data = Encoding.UTF8.GetString(request.PostData[0].Data); + item.Postdata = data; + } + + + + + var result = http.GetHtml(item); + //头部信息更新 + if (result.Header != null && result.Header.Count > 0) + { + foreach (var key in result.Header.AllKeys) + { + response.Headers[key] = result.Header[key]; + } + } + + + + //Cookies更新 + if (!string.IsNullOrEmpty(result.Cookie)) + { + var temp_cookiesStr = Regex.Replace(HttpHelper.GetSmallCookie(result.Cookie), "path=/", "").Replace("\r\n", ""); + + var temp_cookies = temp_cookiesStr.Split(';'); + + foreach (var ck in temp_cookies) + { + var temp_ck = ck.Split('='); + if (temp_ck.Length == 2) + { + response.Cookies.Add(new EO.WebEngine.Cookie(temp_ck[0].Trim(), temp_ck[1].Trim())); + } + } + } + + response.ContentType = "application/json";//必须设置,否则会弹出对话框并无法显示在EO.Web控件上 + response.ContentEncoding = "UTF-8";//必须设置,否则中文显示乱码 + byte[] be = Encoding.UTF8.GetBytes(result.Html); + response.OutputStream.Write(be, 0, be.Length); + response.OutputStream.Close(); + AfterReceiveData.Invoke(request.Url,JToken.Parse(result.Html)); + } + catch (Exception ex) + { + + } + base.ProcessRequest(request, response); + } + } + #endregion + + private void SHandler_AfterReceiveData(string url,JToken token) + { + //获取二维码 + if (url.StartsWith("https://login.taobao.com/newlogin/qrcode/generate.do")) + { + if (token["content"] != null && token["content"]["data"] != null && token["content"]["data"]["codeContent"] != null) + { + QRCodeStatus = LoginQRCodeStatus.等待扫码; + QRCodeUrl = token["content"]["data"]["codeContent"].ToString(); + } + else + { + QRCodeStatus = LoginQRCodeStatus.获取二维码失败; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + } + else if(url.StartsWith("https://login.taobao.com/newlogin/qrcode/query.do")) + { + if (token["content"] != null && token["content"]["data"] != null && token["content"]["data"]["qrCodeStatus"] != null) + { + var qrStatus = token["content"]["data"]["qrCodeStatus"].ToString(); + if (qrStatus == "NEW") + QRCodeStatus = LoginQRCodeStatus.等待扫码; + else if (qrStatus == "SCANED") + QRCodeStatus = LoginQRCodeStatus.等待确认登录; + else if (qrStatus == "EXPIRED") + { + QRCodeStatus = LoginQRCodeStatus.二维码已过期; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + else if (qrStatus == "CONFIRMED") + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + + } + else + { + Console.WriteLine(qrStatus); + } + + } + + } + } + + + private void MyWeb_LoadCompleted(object sender, EO.WebBrowser.LoadCompletedEventArgs e) + { + try + { + var url = this.webView1.Url; + if (url == alimama) + { + var js = @" +var codeBtn = document.getElementsByClassName('iconfont icon-qrcode'); +if(codeBtn && codeBtn.length==1) +{ + codeBtn[0].click(); +} +"; + this.webView1.EvalScript(js); + } + else if (url.StartsWith("https://www.alimama.com/index.htm")) + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + var ck = this.webView1.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + + this.Invoke(new System.Action(delegate () + { + var target = $"{Client.SingleClient.Url}/lianmeng/logintaobaocallback"; + var sqUrl = $"http://cps.api.52cmg.cn/api/login.aspx?m=login_taobao&url={HttpUtility.UrlEncode(target)}"; + this.webView1.LoadUrl(sqUrl); + })); + } + else if (url.StartsWith("https://oauth.taobao.com/authorize")) + { + this.webView1.EvalScript($"document.getElementById('sub').click();"); + } + else if (url.StartsWith(Client.SingleClient.Url)) + { + System.Threading.Thread.Sleep(300); + var Params = HttpUtility.ParseQueryString(url); + var UserId = Params.Get("taobao_user_id"); + var Lianmeng = Client.SingleClient.Db.Queryable().WithCache().First(f => f.Username == UserId && f.LianmengType == LianmengType.淘宝联盟); + if (Lianmeng != null) + { + Lianmeng.Cookies = this.Cookies; + Client.SingleClient.Db.Save(Lianmeng); + } + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + } + catch (Exception) + { + + } + } + + + private void LoginAlimama_Load(object sender, EventArgs e) + { + try + { + InitEobrowser(alimama); + + } + catch (Exception) + { + } + } + + private void timer1_Tick(object sender, EventArgs e) + { + QRCodeStatus = LoginQRCodeStatus.操作超时 ; + this.timer1.Enabled = false; + this.Close(); + } + } +} diff --git a/Server/Winforms/LoginForms/LoginAlimamaFrom.resx b/Server/Winforms/LoginForms/LoginAlimamaFrom.resx new file mode 100644 index 0000000..09a2f6b --- /dev/null +++ b/Server/Winforms/LoginForms/LoginAlimamaFrom.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 129, 17 + + \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginBaseForm.Designer.cs b/Server/Winforms/LoginForms/LoginBaseForm.Designer.cs new file mode 100644 index 0000000..823ec22 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginBaseForm.Designer.cs @@ -0,0 +1,49 @@ +namespace Server.Winforms.LoginForms +{ + partial class LoginBaseForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + this.Visible = false; + // + // LoginBaseForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(475, 412); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "LoginBaseForm"; + this.Text = "登录"; + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginBaseForm.cs b/Server/Winforms/LoginForms/LoginBaseForm.cs new file mode 100644 index 0000000..1f7c056 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginBaseForm.cs @@ -0,0 +1,50 @@ +using Server.MyClass.Views; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server.Winforms.LoginForms +{ + public partial class LoginBaseForm : DefaultForm + { + public string Msgid = Guid.NewGuid().ToString("N"); + public string QRCodeUrl = string.Empty; + public LoginQRCodeStatus QRCodeStatus = LoginQRCodeStatus.正在获取二维码; + public string ErrorMsg = string.Empty; + public string Cookies; + + public void CloseUI() + { + try + { + if (!this.IsDisposed) + { + this.Invoke(new System.Action(delegate () + { + try + { + this.Close(); + } + catch (Exception) + { + } + + })); + } + } + catch (Exception) + { + } + } + public LoginBaseForm() + { + InitializeComponent(); + } + } +} diff --git a/Server/Winforms/LoginForms/LoginBaseForm.resx b/Server/Winforms/LoginForms/LoginBaseForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginBaseForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginDouyinForm.Designer.cs b/Server/Winforms/LoginForms/LoginDouyinForm.Designer.cs new file mode 100644 index 0000000..0d9a429 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginDouyinForm.Designer.cs @@ -0,0 +1,70 @@ +namespace Server.Winforms.LoginForms +{ + partial class LoginDouyinForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.webControl1 = new EO.WinForm.WebControl(); + this.webView1 = new EO.WebBrowser.WebView(); + this.SuspendLayout(); + // + // webControl1 + // + this.webControl1.BackColor = System.Drawing.Color.White; + this.webControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.webControl1.Location = new System.Drawing.Point(0, 0); + this.webControl1.Name = "webControl1"; + this.webControl1.Size = new System.Drawing.Size(420, 378); + this.webControl1.TabIndex = 0; + this.webControl1.Text = "webControl1"; + this.webControl1.WebView = this.webView1; + // + // webView1 + // + this.webView1.InputMsgFilter = null; + this.webView1.ObjectForScripting = null; + this.webView1.Title = null; + // + // LoginDouyinForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(420, 378); + this.Controls.Add(this.webControl1); + this.Name = "LoginDouyinForm"; + this.Text = "登录抖音"; + this.Load += new System.EventHandler(this.LoginDouyinForm_Load); + this.ResumeLayout(false); + + } + + #endregion + + private EO.WinForm.WebControl webControl1; + private EO.WebBrowser.WebView webView1; + } +} \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginDouyinForm.cs b/Server/Winforms/LoginForms/LoginDouyinForm.cs new file mode 100644 index 0000000..859a5d6 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginDouyinForm.cs @@ -0,0 +1,220 @@ +using Common.DbExtends.Extends; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using EO.Base; +using Newtonsoft.Json.Linq; +using Server.MyClass.Views; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Windows.Forms; + +namespace Server.Winforms.LoginForms +{ + public partial class LoginDouyinForm : LoginBaseForm + { + + private const string Ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"; + public LoginDouyinForm() + { + InitializeComponent(); + } + + private void InitEobrowser(string DefaultUrl) + { + var MyWeb = this.webView1; + var Name = Guid.NewGuid().ToString("N"); + + EO.Base.Runtime.EnableEOWP = true; + EO.WebEngine.Engine engine = EO.WebEngine.Engine.Create("test"); + engine.Options.Proxy = ProxyInfo.Direct;//绕过代理 + //设置浏览器语言 + engine.Options.UILanguage = "zh-CN,zh;q=0.9,en;q=0.8"; + engine.Options.CustomUserAgent = Ua; + //设置缓存目录 + engine.Options.CachePath = Common.Utils.Util.MapPath($"Cache\\WebBrowser\\{Name}"); + EO.WebEngine.BrowserOptions options = new EO.WebEngine.BrowserOptions(); + //options.AllowJavaScript = false;//禁用JS + //options.LoadImages = false;//禁用图像加载 + //options.EnableWebSecurity = false;//设置为false,启用本地文件访问 + engine.Options.SetDefaultBrowserOptions(options);//引擎级别 + MyWeb.Engine = engine; + MyWeb.AcceptLanguage = engine.Options.UILanguage; + + //MyWeb.LoadFailed += MyWeb_LoadFailed;//加载失败 + //MyWeb.TitleChanged += MyWeb_TitleChanged;//Title改变 + //MyWeb.BeforeRequestLoad += MyWeb_BeforeRequestLoad;//在请求加载之前 + //MyWeb.BeforeSendHeaders += MyWeb_BeforeSendHeaders;//发送请求头之前 + //MyWeb.AfterReceiveHeaders += MyWeb_AfterReceiveHeaders;//接收请求头之后 + //MyWeb.UrlChanged += MyWeb_UrlChanged;//地址改变事件 + MyWeb.LoadCompleted += MyWeb_LoadCompleted;//加载完成事件 + //MyWeb.NewWindow += MyWeb_NewWindow;//打开新窗口事件 + //MyWeb.GotFocus += MyWeb_GotFocus;//得到焦点 + //MyWeb.JSExtInvoke += MyWeb_JSExtInvoke;//JS外部调用 + //MyWeb.JSDialog += MyWeb_JSDialog;//JS对话框 + //MyWeb.ConsoleMessage += MyWeb_ConsoleMessage;//控制台消息 + //MyWeb.ShouldForceDownload += MyWeb_ShouldForceDownload;//应强制下载 + //MyWeb.NeedCredentials += MyWeb_NeedCredentials;//当网页需要身份验证时,EO.WebBrowser引发NeedCredentials 事件。如果您不处理此事件,则默认实现将显示一个对话框,询问用户用户名和密码。 + //MyWeb.CertificateError += MyWeb_CertificateError;//证书错误事件 + MyWeb.NewWindow += WebView_NewWindow; + //var sHandler = new SampleHandler(); + //sHandler.AfterReceiveData += SHandler_AfterReceiveData; + //webControl1.WebView.RegisterResourceHandler(sHandler);//注册自定义资源处理程序 + + MyWeb.LoadUrl(DefaultUrl); + + } + private JToken UserToken; + private void MyWeb_LoadCompleted(object sender, EO.WebBrowser.LoadCompletedEventArgs e) + { + try + { + var url = e.Url; + Console.WriteLine("加载完成:"+url); + if (url.StartsWith("https://buyin.jinritemai.com/mpa/account/login")) + { + this.webView1.EvalScript("document.getElementsByClassName('platform-logo')[0].click();"); + } + else if (url.StartsWith("https://open.douyin.com/platform/oauth/connect")) + { + webControl1.WebView.EvalScript(@"function getqr() + { + var imgs = document.getElementsByClassName('qr'); + if(imgs.length>0 && imgs[0].src && imgs[0].src.length>10) + { + return imgs[0].src; + } +return ''; + } +", false); + var timeout = DateTime.Now.AddSeconds(10); + while (timeout > DateTime.Now) + { + Util.Sleep(500); + this.QRCodeUrl = webControl1.WebView.InvokeFunction("getqr")?.ToString(); + if (string.IsNullOrEmpty(this.QRCodeUrl)) continue; + else break; + } + + if (!string.IsNullOrEmpty(this.QRCodeUrl)) + { + QRCodeStatus = LoginQRCodeStatus.等待扫码; + } + } + else if (url.StartsWith("https://buyin.jinritemai.com/dashboard/institution/through-power")) + { + + } + else if (url.StartsWith("https://buyin.jinritemai.com/dashboard")) + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + + var ck = this.webView1.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + + var json = DouyinRequest.GetLoginUserInfo(this.Cookies, Ua); + var jObj = JObject.Parse(json); + if (jObj != null && jObj["code"] != null) + { + var code = jObj["code"].ToString(); + if (code == "0") + { + var shop_id = jObj["data"]["shop_id"].ToString(); + if (shop_id == "0") + { + ErrorMsg = $@"该账号未开通商品分享功能,请开通后重试 + +注:开通电商权限,需要同时满足以下4个条件 +①、账号实名认证 +②、个人主页视频数(公开且审核通过)≥ 10 条 +③、账号粉丝量(绑定第三方粉丝量不计数)≥ 1000 +④、商品分享保证金 ¥500立即充值"; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + return; + } + else + { + UserToken = jObj["data"]; + var sqUrl = $"http://cps.api.52cmg.cn/api/douyin.asmx/login"; + this.webView1.LoadUrl(sqUrl); + return; + } + + } + } + + this.ErrorMsg = "无法识别:" + json; + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + + + } + else if (url.StartsWith("http://cps.api.52cmg.cn/api/douyin.asmx/login_result")) + { + var json = webControl1.WebView.GetText(); + if (!string.IsNullOrWhiteSpace(json)) + { + var jObj = JObject.Parse(json); + if (jObj != null && (bool)jObj["ok"]) + { + var u = jObj["message"]; + var douyin = Client.SingleClient.Db.Queryable().Where(f => f.Username == jObj["authority_id"].ToString() && f.LianmengType == Common.Models.Enums.LianmengType.抖音联盟).First(); + if (douyin == null) + { + douyin = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.抖音联盟, + Username = u["authority_id"].ToString() + }; + }; + + douyin.ReToken = u["refresh_token"].ToString(); + douyin.ExpirationTime = DateTime.Parse(u["expires_time"].ToString()); + douyin.Cookies = this.Cookies; + douyin.Token = u["access_token"].ToString(); + douyin.Nickname = UserToken["shop_name"].ToString(); + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + Client.SingleClient.Db.Save(douyin); + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + Console.WriteLine(); + + } + } + + + this.DialogResult = DialogResult.OK; + } + } + catch (Exception) + { + + } + } + + private void WebView_NewWindow(object sender, EO.WebBrowser.NewWindowEventArgs e) + { + webControl1.WebView.LoadUrl(e.TargetUrl); + } + + private void LoginDouyinForm_Load(object sender, EventArgs e) + { + InitEobrowser("https://buyin.jinritemai.com/mpa/account/login?log_out=1&type=24&target_url="); + } + } +} diff --git a/Server/Winforms/LoginForms/LoginDouyinForm.resx b/Server/Winforms/LoginForms/LoginDouyinForm.resx new file mode 100644 index 0000000..cb4cc33 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginDouyinForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginLianmengForm.Designer.cs b/Server/Winforms/LoginForms/LoginLianmengForm.Designer.cs new file mode 100644 index 0000000..501b75d --- /dev/null +++ b/Server/Winforms/LoginForms/LoginLianmengForm.Designer.cs @@ -0,0 +1,70 @@ +namespace Server.Winforms.LoginForms +{ + partial class LoginLianmengForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.webControl1 = new EO.WinForm.WebControl(); + this.webView1 = new EO.WebBrowser.WebView(); + this.SuspendLayout(); + // + // webControl1 + // + this.webControl1.BackColor = System.Drawing.Color.White; + this.webControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.webControl1.Location = new System.Drawing.Point(0, 0); + this.webControl1.Name = "webControl1"; + this.webControl1.Size = new System.Drawing.Size(910, 432); + this.webControl1.TabIndex = 0; + this.webControl1.Text = "webControl1"; + this.webControl1.WebView = this.webView1; + // + // webView1 + // + this.webView1.InputMsgFilter = null; + this.webView1.ObjectForScripting = null; + this.webView1.Title = null; + // + // LoginLianmengForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(910, 432); + this.Controls.Add(this.webControl1); + this.Name = "LoginLianmengForm"; + this.Text = "登录联盟"; + this.Load += new System.EventHandler(this.LoginLianmengForm_Load); + this.ResumeLayout(false); + + } + + #endregion + + private EO.WinForm.WebControl webControl1; + private EO.WebBrowser.WebView webView1; + } +} \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginLianmengForm.cs b/Server/Winforms/LoginForms/LoginLianmengForm.cs new file mode 100644 index 0000000..224b03d --- /dev/null +++ b/Server/Winforms/LoginForms/LoginLianmengForm.cs @@ -0,0 +1,695 @@ +using Common.DbExtends.Extends; +using Common.Models.Enums; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using CsharpHttpHelper; +using EO.Base; +using EO.WebBrowser; +using Newtonsoft.Json.Linq; +using Server.MyClass.Views; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; +using System.Web; +using System.Windows.Forms; + +namespace Server.Winforms.LoginForms +{ + public partial class LoginLianmengForm : LoginBaseForm + { + public LoginLianmengForm() + { + InitializeComponent(); + } + private void InitEobrowser(string DefaultUrl) + { + var MyWeb = this.webView1; + var Name = Guid.NewGuid().ToString("N"); + + EO.Base.Runtime.EnableEOWP = true; + EO.WebEngine.Engine engine = EO.WebEngine.Engine.Create(Name); + engine.Options.Proxy = ProxyInfo.Direct;//绕过代理 + //设置浏览器语言 + engine.Options.UILanguage = "zh-CN,zh;q=0.9,en;q=0.8"; + //设置缓存目录 + engine.Options.CachePath = Common.Utils.Util.MapPath($"Cache\\WebBrowser\\{Name}"); + EO.WebEngine.BrowserOptions options = new EO.WebEngine.BrowserOptions(); + //options.AllowJavaScript = false;//禁用JS + //options.LoadImages = false;//禁用图像加载 + //options.EnableWebSecurity = false;//设置为false,启用本地文件访问 + engine.Options.SetDefaultBrowserOptions(options);//引擎级别 + MyWeb.Engine = engine; + MyWeb.AcceptLanguage = engine.Options.UILanguage; + + //MyWeb.LoadFailed += MyWeb_LoadFailed;//加载失败 + //MyWeb.TitleChanged += MyWeb_TitleChanged;//Title改变 + //MyWeb.BeforeRequestLoad += MyWeb_BeforeRequestLoad;//在请求加载之前 + //MyWeb.BeforeSendHeaders += MyWeb_BeforeSendHeaders;//发送请求头之前 + //MyWeb.AfterReceiveHeaders += MyWeb_AfterReceiveHeaders;//接收请求头之后 + //MyWeb.UrlChanged += MyWeb_UrlChanged;//地址改变事件 + MyWeb.LoadCompleted += MyWeb_LoadCompleted;//加载完成事件 + //MyWeb.NewWindow += MyWeb_NewWindow;//打开新窗口事件 + //MyWeb.GotFocus += MyWeb_GotFocus;//得到焦点 + //MyWeb.JSExtInvoke += MyWeb_JSExtInvoke;//JS外部调用 + //MyWeb.JSDialog += MyWeb_JSDialog;//JS对话框 + //MyWeb.ConsoleMessage += MyWeb_ConsoleMessage;//控制台消息 + //MyWeb.ShouldForceDownload += MyWeb_ShouldForceDownload;//应强制下载 + //MyWeb.NeedCredentials += MyWeb_NeedCredentials;//当网页需要身份验证时,EO.WebBrowser引发NeedCredentials 事件。如果您不处理此事件,则默认实现将显示一个对话框,询问用户用户名和密码。 + MyWeb.CertificateError += MyWeb_CertificateError;//证书错误事件 + + MyWeb.NewWindow += WebView_NewWindow; + var sHandler = new SampleHandler(); + sHandler.AfterReceiveData += SHandler_AfterReceiveData; + webControl1.WebView.RegisterResourceHandler(sHandler);//注册自定义资源处理程序 + + MyWeb.LoadUrl(DefaultUrl); + + } + + private void MyWeb_CertificateError(object sender, CertificateErrorEventArgs e) + { + + } + + #region 自定义响应Response 20210321 + + private class SampleHandler : ResourceHandler + { + string[] Urls = new string[] { "https://login.taobao.com/newlogin/qrcode/generate.do" }; + public event System.Action AfterReceiveData; + //此方法判断是否自定义处理响应 + public override bool Match(Request request) + { + for (int i = 0; i < Urls.Length; i++) + { + if (request.Url.StartsWith(Urls[i])) + { + return true; + } + } + + return false; + } + + //如果自定义响应,则在这里处理请求,并返回要显示的信息 + public override void ProcessRequest(Request request, EO.WebBrowser.Response response) + { + try + { + var cookies = Regex.Replace(request.Cookies.ToString(), "path=/", "").Replace("\r\n", ""); + var useragent = request.Headers["User-Agent"]; + var http = new HttpHelper(); + var item = new HttpItem() + { + URL = request.Url, + ContentType = "application/x-www-form-urlencoded", + Method = request.Method, + Timeout = 5000, + Cookie = cookies, + UserAgent = useragent + }; + + + if (request.PostData != null && request.PostData.Count == 1) + { + var data = Encoding.UTF8.GetString(request.PostData[0].Data); + item.Postdata = data; + } + + + + + var result = http.GetHtml(item); + //头部信息更新 + if (result.Header != null && result.Header.Count > 0) + { + foreach (var key in result.Header.AllKeys) + { + response.Headers[key] = result.Header[key]; + } + } + + + + //Cookies更新 + if (!string.IsNullOrEmpty(result.Cookie)) + { + var temp_cookiesStr = Regex.Replace(HttpHelper.GetSmallCookie(result.Cookie), "path=/", "").Replace("\r\n", ""); + + var temp_cookies = temp_cookiesStr.Split(';'); + + foreach (var ck in temp_cookies) + { + var temp_ck = ck.Split('='); + if (temp_ck.Length == 2) + { + response.Cookies.Add(new EO.WebEngine.Cookie(temp_ck[0].Trim(), temp_ck[1].Trim())); + } + } + } + + response.ContentType = "application/json";//必须设置,否则会弹出对话框并无法显示在EO.Web控件上 + response.ContentEncoding = "UTF-8";//必须设置,否则中文显示乱码 + byte[] be = Encoding.UTF8.GetBytes(result.Html); + response.OutputStream.Write(be, 0, be.Length); + response.OutputStream.Close(); + AfterReceiveData.Invoke(request.Url, JToken.Parse(result.Html)); + } + catch + { + // ignored + } + + base.ProcessRequest(request, response); + } + } + #endregion + public LianmengType LoginType { get; set; } + public void Start(LianmengType Type) + { + this.LoginType = Type; + switch (Type) + { + case LianmengType.淘宝联盟: + this.webView1.LoadUrl(alimama); + break; + case LianmengType.京东联盟: + break; + case LianmengType.拼多多联盟: + break; + case LianmengType.唯品会联盟: + break; + case LianmengType.苏宁联盟: + break; + case LianmengType.抖音联盟: + this.webView1.LoadUrl("https://buyin.jinritemai.com/mpa/account/login?log_out=1&type=24&target_url="); + break; + case LianmengType.美团联盟: + this.webView1.LoadUrl("https://pub.meituan.com/#/api-doc"); + break; + default: + break; + } + } + private void SHandler_AfterReceiveData(string url, JToken token) + { + try + { + //获取二维码 + if (url.StartsWith("https://login.taobao.com/newlogin/qrcode/generate.do")) + { + if (token["content"] != null && token["content"]["data"] != null && token["content"]["data"]["codeContent"] != null) + { + QRCodeStatus = LoginQRCodeStatus.等待扫码; + QRCodeUrl = token["content"]["data"]["codeContent"].ToString(); + } + else + { + QRCodeStatus = LoginQRCodeStatus.获取二维码失败; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + } + else if (url.StartsWith("https://login.taobao.com/newlogin/qrcode/query.do")) + { + if (token["content"] != null && token["content"]["data"] != null && token["content"]["data"]["qrCodeStatus"] != null) + { + var qrStatus = token["content"]["data"]["qrCodeStatus"].ToString(); + if (qrStatus == "NEW") + QRCodeStatus = LoginQRCodeStatus.等待扫码; + else if (qrStatus == "SCANED") + QRCodeStatus = LoginQRCodeStatus.等待确认登录; + else if (qrStatus == "EXPIRED") + { + QRCodeStatus = LoginQRCodeStatus.二维码已过期; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + else if (qrStatus == "CONFIRMED") + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + + } + else + { + Console.WriteLine(qrStatus); + } + + } + + } + else if (url.StartsWith("https://verify.meituan.com/v2/ext_api/login/verify")) + { + if (token != null && token["error"] != null && token["error"]["message"] != null) + { + var error = token["error"]["message"].ToString(); + if (!string.IsNullOrEmpty(error)) + { + this.ErrorMsg = error; + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + this.CloseUI(); + } + } + } + } + catch (Exception) + { + + } + } + + private void WebView_NewWindow(object sender, EO.WebBrowser.NewWindowEventArgs e) + { + webControl1.WebView.LoadUrl(e.TargetUrl); + } + private const string Ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"; + private const string alimama = "https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&css_style=alimama&from=alimama&redirectURL=http%3A%2F%2Fwww.alimama.com&full_redirect=true&disableQuickLogin=true&qq-pf-to=pcqq.c2c"; + private JToken UserToken; + private void MyWeb_LoadCompleted(object sender, EO.WebBrowser.LoadCompletedEventArgs e) + { + try + { + var url = this.webView1.Url; + Console.WriteLine($"目标地址:"+url); + + #region 登录淘宝联盟 + if (url == alimama) + { + var js = @" +var codeBtn = document.getElementsByClassName('iconfont icon-qrcode'); +if(codeBtn && codeBtn.length==1) +{ + codeBtn[0].click(); +} +"; + this.webView1.EvalScript(js); + } + else if (url.StartsWith("https://www.alimama.com/index.htm")) + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + var ck = this.webView1.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + + this.Invoke(new System.Action(delegate () + { + var target = $"{Client.SingleClient.Url}/lianmeng/logintaobaocallback"; + var sqUrl = $"http://cps.api.52cmg.cn/api/login.aspx?m=login_taobao&url={HttpUtility.UrlEncode(target)}"; + this.webView1.LoadUrl(sqUrl); + })); + } + else if (url.StartsWith("https://oauth.taobao.com/authorize")) + { + this.webView1.EvalScript($"document.getElementById('sub').click();"); + } + else if (url.StartsWith(Client.SingleClient.Url)) + { + System.Threading.Thread.Sleep(300); + var Params = HttpUtility.ParseQueryString(url); + var UserId = Params.Get("taobao_user_id"); + var lm = Client.SingleClient.Db.Queryable().WithCache().First(f => f.Username == UserId && f.LianmengType == LianmengType.淘宝联盟); + if (lm != null) + { + lm.Cookies = this.Cookies; + lm.IsCookiValid = true; + Client.SingleClient.Db.Save(lm); + } + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + + //启动一个线程,去同步PID + Task.Factory.StartNew(() => + { + try + { + var req = new TaobaoRequest(lm, null); + var pids = req.QueryAdzones(); + if (pids.Count > 0) + { + var db = Client.SingleClient.Db; + db.UseTran(() => + { + foreach (var item in pids) + { + var media = db.Queryable().Where(f => f.LianmengId == lm.Id && f.SiteId == item.siteId && f.AdzoneId == item.adzoneId).First(); + if (media == null) + media = new TbMedia() { LianmengId = lm.Id, SiteId = item.siteId, AdzoneId = item.adzoneId }; + + + if (media.Id == 0 || media.AdzoneName != item.adzoneName || media.SiteName != item.siteName) + { + if (item.isSpecial) + media.IsSpecial = item.isSpecial; + + media.AdzoneName = item.adzoneName; + media.SiteName = item.siteName; + media.Pid = item.pid; + db.Storageable(media).ExecuteCommand(); + } + } + }); + } + } + catch (Exception) + { + } + }); + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + #endregion + + #region 登录抖音联盟 + else if (url.StartsWith("https://buyin.jinritemai.com/mpa/account/login")) + { + this.webView1.EvalScript("document.getElementsByClassName('platform-logo')[0].click();"); + } + else if (url.StartsWith("https://open.douyin.com/platform/oauth/connect")) + { + webControl1.WebView.EvalScript(@"function getqr() + { + var imgs = document.getElementsByClassName('qr'); + if(imgs.length>0 && imgs[0].src && imgs[0].src.length>10) + { + return imgs[0].src; + } +return ''; + } +", false); + var timeout = DateTime.Now.AddSeconds(10); + while (timeout > DateTime.Now) + { + Util.Sleep(100); + this.QRCodeUrl = webControl1.WebView.InvokeFunction("getqr")?.ToString(); + if (string.IsNullOrEmpty(this.QRCodeUrl)) continue; + else break; + } + + if (!string.IsNullOrEmpty(this.QRCodeUrl)) + { + QRCodeStatus = LoginQRCodeStatus.等待扫码; + } + } + else if (url.StartsWith("https://buyin.jinritemai.com/dashboard/institution/through-power")) + { + //auxo-btn auxo-btn-primary auxo-btn-lg +; + var timeout = DateTime.Now.AddSeconds(10); + while (timeout > DateTime.Now) + { + Util.Sleep(1000); + if (!this.webView1.Url.StartsWith("https://buyin.jinritemai.com/dashboard/institution/through-power")) break; + else + { + webControl1.WebView.EvalScript(@"function excute_js() + { + var btn = document.getElementsByClassName('auxo-btn auxo-btn-primary auxo-btn-lg'); + if(btn.length>0 ) + { + btn[0].click(); + return true; + } +return false; + } +", false); + } + + } + + } + else if (url.StartsWith("https://buyin.jinritemai.com/dashboard")) + { + QRCodeStatus = LoginQRCodeStatus.正在授权; + + var ck = this.webView1.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + + var json = DouyinRequest.GetLoginUserInfo(this.Cookies, Ua); + var jObj = JObject.Parse(json); + if (jObj != null && jObj["code"] != null) + { + var code = jObj["code"].ToString(); + if (code == "0") + { + var shop_id = jObj["data"]["shop_id"].ToString(); + if (shop_id == "0") + { + ErrorMsg = $@"该账号未开通商品分享功能,请开通后重试 + +注:开通电商权限,需要同时满足以下4个条件 +①、账号实名认证 +②、个人主页视频数(公开且审核通过)≥ 10 条 +③、账号粉丝量(绑定第三方粉丝量不计数)≥ 1000 +④、商品分享保证金 ¥500立即充值"; + QRCodeStatus = LoginQRCodeStatus.登录失败; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + return; + } + else + { + UserToken = jObj["data"]; + var sqUrl = $"http://cps.api.52cmg.cn/api/douyin.asmx/login"; + this.webView1.LoadUrl(sqUrl); + return; + } + + } + } + + this.ErrorMsg = "无法识别:" + json; + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + + + } + else if (url.StartsWith("http://cps.api.52cmg.cn/api/douyin.asmx/login_result")) + { + var json = webControl1.WebView.GetText(); + if (!string.IsNullOrWhiteSpace(json)) + { + var jObj = JObject.Parse(json); + if (jObj != null && (bool)jObj["ok"]) + { + var u = jObj["message"]; + var username = u["authority_id"].ToString(); + var douyin = Client.SingleClient.Db.Queryable().Where(f => f.Username == username && f.LianmengType == Common.Models.Enums.LianmengType.抖音联盟).First(); + if (douyin == null) + { + douyin = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.抖音联盟, + Username = u["authority_id"].ToString() + }; + }; + + douyin.ReToken = u["refresh_token"].ToString(); + douyin.ExpirationTime = DateTime.Parse(u["expires_time"].ToString()); + douyin.Cookies = this.Cookies; + douyin.Token = u["access_token"].ToString(); + douyin.Nickname = UserToken["shop_name"].ToString(); + douyin.IsCookiValid = true; + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + Client.SingleClient.Db.Save(douyin); + + Task.Factory.StartNew(() => + { + try + { + DouyinRequest req = new DouyinRequest(douyin); + //查询抖音推广位 + var list = req.GetDouyinPidAdzone(); + if (list.Count > 0) + { + var db = Client.SingleClient.Db; + try + { + db.BeginTran(); + foreach (var item in list) + { + var media = db.Queryable().Where(f => f.LianmengId == douyin.Id && f.Pid == item.pid).First(); + if (media == null) + { + media = new DyMedia() { Pid = item.pid, LianmengId = douyin.Id }; + } + + if (media.Id == 0 || media.UpdateTime != item.update_time) + { + media.MediaType = (DouyinMediaType)item.media_type; + media.AdzoneName = item.site_name; + media.MediaName = item.media_name; + media.UpdateTime = item.update_time; + db.Save(media); + } + } + db.CommitTran(); + } + catch (Exception ex) + { + db.RollbackTran(); + Client.SingleClient.Db.OnLog("更新抖音推广位", ex); + } + } + } + catch (Exception ex) + { + Client.SingleClient.Db.OnLog("更新抖音推广位", ex); + } + }); + + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + Console.WriteLine(); + + } + } + + + this.DialogResult = DialogResult.OK; + } + #endregion + + #region 登录美团联盟 + else if (url == "https://pub.meituan.com/#/api-doc") + { + + Util.Sleep(500); + this.webView1.EvalScript($"" + + $"document.getElementById('phoneNumInput').focus();" + ); + Util.Sleep(100); + var chars = this.LoginTelphone.ToCharArray(); + foreach (int item in chars) + { + switch (item) + { + case 49: + this.webView1.SendKeyEvent(true, KeyCode.D0); + break; + case 50: + this.webView1.SendKeyEvent(true, KeyCode.D1); + break; + case 51: + this.webView1.SendKeyEvent(true, KeyCode.D2); + break; + case 52: + this.webView1.SendKeyEvent(true, KeyCode.D3); + break; + case 53: + this.webView1.SendKeyEvent(true, KeyCode.D4); + break; + case 54: + this.webView1.SendKeyEvent(true, KeyCode.D5); + break; + case 55: + this.webView1.SendKeyEvent(true, KeyCode.D6); + break; + case 56: + this.webView1.SendKeyEvent(true, KeyCode.D7); + break; + case 57: + this.webView1.SendKeyEvent(true, KeyCode.D8); + break; + case 58: + this.webView1.SendKeyEvent(true, KeyCode.D9); + break; + } + Util.Sleep(1000); + } + + //Util.Sleep(500); + this.webView1.EvalScript("document.getElementById('sendCodeBtnText').click();"); + this.QRCodeStatus = LoginQRCodeStatus.等待确认登录; + + } + else if (url == "https://pub.meituan.com/#/sign-manage") + { + var ck = this.webView1.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + + var http = new HttpHelper(); + var html = http.GetHtml("https://pub.meituan.com/benchmark/login/appkey",this.Cookies).Html; + var json = JObject.Parse(html); + if (json["msg"].ToString() == "成功") + { + html = http.GetHtml("https://pub.meituan.com/benchmark/login/userinfo",this.Cookies).Html; + var u = JObject.Parse(html)["data"]; + var username = u["mainMtUserId"].ToString(); + + var douyin = Client.SingleClient.Db.Queryable().Where(f => f.Username == username && f.LianmengType == Common.Models.Enums.LianmengType.美团联盟).First(); + if (douyin == null) + { + douyin = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.美团联盟, + Username = username, + Remark = LoginTelphone + }; + }; + + douyin.ReToken = json["utmSource"].ToString(); + douyin.ExpirationTime = DateTime.Now.AddYears(100); + douyin.Cookies = this.Cookies; + douyin.Token = json["data"].ToString(); + douyin.Nickname = u["nickName"].ToString(); + douyin.IsCookiValid = true; + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + Client.SingleClient.Db.Save(douyin); + + } + else + { + this.ErrorMsg = json["msg"].ToString(); + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + } + } + #endregion + } + catch (Exception ex) + { + this.QRCodeStatus = LoginQRCodeStatus.登录失败; + this.ErrorMsg = ex.Message; + } + } + public string LoginTelphone { get; set; } + public void LoginMeituan(string Code) + { + + } + + public void Init() + { + this.InitEobrowser("about:blank"); + + } + + private void LoginLianmengForm_Load(object sender, EventArgs e) + { + Init(); + } + } +} diff --git a/Server/Winforms/LoginForms/LoginLianmengForm.resx b/Server/Winforms/LoginForms/LoginLianmengForm.resx new file mode 100644 index 0000000..cb4cc33 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginLianmengForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginMeituanClass.cs b/Server/Winforms/LoginForms/LoginMeituanClass.cs new file mode 100644 index 0000000..0ca3140 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginMeituanClass.cs @@ -0,0 +1,157 @@ +using CsharpHttpHelper; +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Server.Winforms.LoginForms +{ + internal class LoginMeituanClass + { + private string uuid = Guid.NewGuid().ToString("N").ToUpper(); + private string requestCode = string.Empty; + public string mobile = string.Empty; + public string Cookies { get; private set; } + public string appkey { get; private set; } + public string utmSource { get; private set; } + public string nickName { get; private set; } + + /// + /// 获取验证码 + /// + /// 手机号 + /// 错误信息 + public string SendLoginCode(string mobile) + { + this.mobile = mobile; + HttpHelper http = new HttpHelper(); + //尝试创建登录请求 + var result = http.GetHtml($"https://passport.meituan.com/api/v3/account/mobileloginapply?uuid={uuid}&risk_app=-1&risk_platform=1&risk_partner=423&risk_smsTemplateId=0&join_key=&risk_smsPrefixId=0&loginSource=0&campaignPlatform=&allCampaignId=&sdkType=h5&sdkVersion=1.2.15&same_site=false", "", $"mobile={mobile}&verifyLevel=2&countryCode=86"); + var json = JObject.Parse(result.Html.ToString()); + if (json["error"]["code"].ToString() == "101190") + { + //验证号码信息 + requestCode = json["error"]["data"]["requestCode"].ToString(); + result = http.GetHtml("https://verify.meituan.com/v2/ext_api/page_data", "", $"requestCode={requestCode}", "https://pub.meituan.com/"); + json = JObject.Parse(result.Html.ToString()); + if (json != null) + { + if (!string.IsNullOrEmpty(json["error"]?.ToString())) return json["error"].ToString(); + + //真实发送 + result = http.GetHtml("https://verify.meituan.com/v2/ext_api/login/info", "", $"id=4&request_code={requestCode}&fingerprint=&mobile={mobile}"); + json = JObject.Parse(result.Html.ToString()); + if (!string.IsNullOrEmpty(json["error"]?.ToString())) + return json["error"].ToString(); + else + return string.Empty; + } + else return result.Html; + } + else if (!string.IsNullOrEmpty(json["error"]?.ToString())) return json["error"].ToString(); + else return result.Html; + } + + + /// + /// 验证验证码有效性 + /// + /// 验证码 + /// 错误原因 + public string VerifyLoginCode(string code) + { + if (code.Length != 6) throw new Exception("登录失败,验证码不正确!"); + var http = new HttpHelper(); + var result = http.GetHtml("https://verify.meituan.com/v2/ext_api/login/verify", "", $"id=4&request_code={requestCode}&fingerprint=&mobile={mobile}&smscode={code}"); + var json = JObject.Parse(result.Html); + if (json["status"].ToString()!="1") + return json["error"]["message"].ToString(); + + var respose_code = json["data"]["response_code"].ToString(); + var item = http.GetItem($"https://passport.meituan.com/api/v3/account/mobilelogin?risk_platform=1&risk_partner=423&risk_app=-1&join_key=&uuid={uuid}&loginSource=0&token_id=DNCmLoBpSbBD6leXFdqIxA&sdkType=pc&same_site=false&sdkVersion=1.2.15", this.Cookies, $"tokenVersion=1&requestCode={requestCode}&mobile={mobile}&responseCode={respose_code}&device_os=Window&setCookie=true", "https://pub.meituan.com/"); + result = http.GetHtml(item); + json = JObject.Parse(result.Html); + if (json["user"] != null) + { + this.Cookies = "lt=" + json["user"]["token"]; + appkey = JObject.Parse(http.GetHtml("https://pub.meituan.com/benchmark/login/appkey", this.Cookies).Html)["data"].ToString(); + var userinfo = JObject.Parse(http.GetHtml("https://pub.meituan.com/benchmark/login/userinfo", this.Cookies).Html)["data"]; + utmSource = userinfo["utmSource"].ToString(); + nickName = userinfo["nickName"].ToString(); + + return string.Empty; + } + else return result.Html; + } + + + /// + /// 获得推广位 + /// + public List GetMedias() + { + List medias = new List(); + try + { + var http = new HttpHelper(); + var html = http.GetHtml("https://pub.meituan.com/benchmark/promote/promotion/list", this.Cookies).Html; + var json = JObject.Parse(html); + if (json["data"] != null) + { + var data = json["data"]; + foreach (var item in data) + { + var obj = new MeituanMedia(); + Common.Utils.Util.CopyToObj(item, obj); + medias.Add(obj); + } + + } + else return null; + } + catch (Exception) + { + } + return medias; + } + + + public class MeituanMedia + { + /// + /// 推广位ID + /// + public string promotionId { get; set; } + /// + /// 酒店 + /// + public string promotionName { get; set; } + /// + /// 媒体ID + /// + public string mediaId { get; set; } + /// + /// 媒体名称 + /// + public string mediaName { get; set; } + /// + /// 媒体类型 + /// + public int mediaType { get; set; } + /// + /// 状态 + /// + public int status { get; set; } + /// + /// 添加时间 + /// + public DateTime addTime { get; set; } + /// + /// 修改时间 + /// + public DateTime updateTime { get; set; } + } + } +} diff --git a/Server/Winforms/LoginForms/LoginSuningClass.cs b/Server/Winforms/LoginForms/LoginSuningClass.cs new file mode 100644 index 0000000..0025f05 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginSuningClass.cs @@ -0,0 +1,146 @@ +using Common.DbExtends.Extends; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using CsharpHttpHelper; +using Newtonsoft.Json.Linq; +using Server.MyClass.Views; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading; +using System.Threading.Tasks; + +namespace Server.Winforms.LoginForms +{ + internal class LoginSuningClass + { + public string QRCodeUrl; + public string ErrorMsg; + public LoginQRCodeStatus QRCodeStatus; + + private string uuid; + private string Cookies; + + public string GetQRCodeUrl() + { + try + { + var login_url = $"https://passport.suning.com/ids/qrLoginUuidGenerate.htm?image=false&yys={Common.Utils.Util.GetTimespan(DateTime.Now)}000"; + var http = new HttpHelper(); + var result = http.GetHtml(login_url); + var json = JObject.Parse(result.Html); + + if (json != null && json["res_code"]?.ToString() == "0") + { + this.QRCodeUrl = json["url"].ToString(); + this.uuid = json["qrToken"].ToString(); + this.Cookies = HttpHelper.GetSmallCookie(result.Cookie); + QRCodeStatus = LoginQRCodeStatus.等待扫码; + StarCheck(); + return this.QRCodeUrl; + } + else throw new Exception(result.Html); + } + catch (Exception ex) + { + ErrorMsg = ex.Message; + QRCodeStatus = LoginQRCodeStatus.获取二维码失败; + } + return string.Empty; + } + + private void StarCheck() + { + ThreadPool.QueueUserWorkItem(x => + { + var timeout = DateTime.Now.AddMinutes(5); + while (DateTime.Now用户名:(?<会员名>.+?)[\w\W]+会员编码:(?<会员编码>\d+)", RegexOptions.IgnoreCase | RegexOptions.Multiline); + if (reg.Success) + { + var memberId = reg.Groups["会员编码"].Value; + + + var suning = Client.SingleClient.Db.Queryable().Where(f => f.Username == memberId && f.LianmengType == Common.Models.Enums.LianmengType.抖音联盟).First(); + if (suning == null) + { + suning = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.苏宁联盟, + Username = memberId + }; + }; + SuningRequest req = new SuningRequest(suning); + var token = req.CreateToolsRelation(memberId); + + suning.ReToken = String.Empty; + suning.ExpirationTime = DateTime.Now.AddYears(100); + suning.Cookies = this.Cookies; + suning.Token = token; + suning.Nickname = reg.Groups["会员名"].Value; + Client.SingleClient.Db.Save(suning); + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + break; + } + else + { + + QRCodeStatus = LoginQRCodeStatus.登录失败; + ErrorMsg = "已确认登录,但获取关键信息失败!"; + break; + } + } + else + { + QRCodeStatus = LoginQRCodeStatus.二维码已过期; + break; + } + } + catch (Exception) + { + } + + } + }); + } + } +} diff --git a/Server/Winforms/LoginForms/LoginSuningFrom.Designer.cs b/Server/Winforms/LoginForms/LoginSuningFrom.Designer.cs new file mode 100644 index 0000000..54fd3bd --- /dev/null +++ b/Server/Winforms/LoginForms/LoginSuningFrom.Designer.cs @@ -0,0 +1,78 @@ +namespace Server.Winforms.LoginForms +{ + partial class LoginSuningFrom + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.webControl1 = new EO.WinForm.WebControl(); + this.webView1 = new EO.WebBrowser.WebView(); + this.timer1 = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // webControl1 + // + this.webControl1.BackColor = System.Drawing.Color.White; + this.webControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.webControl1.Location = new System.Drawing.Point(0, 0); + this.webControl1.Name = "webControl1"; + this.webControl1.Size = new System.Drawing.Size(295, 266); + this.webControl1.TabIndex = 0; + this.webControl1.Text = "webControl1"; + this.webControl1.WebView = this.webView1; + // + // webView1 + // + this.webView1.InputMsgFilter = null; + this.webView1.ObjectForScripting = null; + this.webView1.Title = null; + // + // timer1 + // + this.timer1.Interval = 1000; + this.timer1.Tick += new System.EventHandler(this.timer1_Tick); + // + // LoginSuningFrom + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(295, 266); + this.Controls.Add(this.webControl1); + this.Name = "LoginSuningFrom"; + this.Text = "登录苏宁"; + this.Load += new System.EventHandler(this.LoginSuningFrom_Load); + this.ResumeLayout(false); + + } + + #endregion + + private EO.WinForm.WebControl webControl1; + private EO.WebBrowser.WebView webView1; + private System.Windows.Forms.Timer timer1; + } +} \ No newline at end of file diff --git a/Server/Winforms/LoginForms/LoginSuningFrom.cs b/Server/Winforms/LoginForms/LoginSuningFrom.cs new file mode 100644 index 0000000..8cad8d8 --- /dev/null +++ b/Server/Winforms/LoginForms/LoginSuningFrom.cs @@ -0,0 +1,392 @@ +using Common.DbExtends.Extends; +using Common.Models.UnqTables; +using Common.Requests.Lianmengs; +using Common.Utils; +using CsharpHttpHelper; +using CsharpHttpHelper.Enum; +using EO.Base; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Server.MyClass.Views; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server.Winforms.LoginForms +{ + public partial class LoginSuningFrom : LoginBaseForm + { + public LoginSuningFrom() + { + InitializeComponent(); + } + + + private void InitEobrowser(string DefaultUrl) + { + var MyWeb = this.webView1; + var Name = Guid.NewGuid().ToString("N"); + + EO.Base.Runtime.EnableEOWP = true; + EO.WebEngine.Engine engine = EO.WebEngine.Engine.Create(Name); + engine.Options.Proxy = ProxyInfo.Direct;//绕过代理 + //设置浏览器语言 + engine.Options.UILanguage = "zh-CN,zh;q=0.9,en;q=0.8"; + //设置缓存目录 + engine.Options.CachePath = Common.Utils.Util.MapPath($"Cache\\WebBrowser\\{Name}"); + EO.WebEngine.BrowserOptions options = new EO.WebEngine.BrowserOptions(); + //options.AllowJavaScript = false;//禁用JS + //options.LoadImages = false;//禁用图像加载 + //options.EnableWebSecurity = false;//设置为false,启用本地文件访问 + engine.Options.SetDefaultBrowserOptions(options);//引擎级别 + MyWeb.Engine = engine; + MyWeb.AcceptLanguage = engine.Options.UILanguage; + + //MyWeb.LoadFailed += MyWeb_LoadFailed;//加载失败 + //MyWeb.TitleChanged += MyWeb_TitleChanged;//Title改变 + //MyWeb.BeforeRequestLoad += MyWeb_BeforeRequestLoad;//在请求加载之前 + //MyWeb.BeforeSendHeaders += MyWeb_BeforeSendHeaders;//发送请求头之前 + //MyWeb.AfterReceiveHeaders += MyWeb_AfterReceiveHeaders;//接收请求头之后 + //MyWeb.UrlChanged += MyWeb_UrlChanged;//地址改变事件 + MyWeb.LoadCompleted += MyWeb_LoadCompleted;//加载完成事件 + //MyWeb.NewWindow += MyWeb_NewWindow;//打开新窗口事件 + //MyWeb.GotFocus += MyWeb_GotFocus;//得到焦点 + //MyWeb.JSExtInvoke += MyWeb_JSExtInvoke;//JS外部调用 + //MyWeb.JSDialog += MyWeb_JSDialog;//JS对话框 + //MyWeb.ConsoleMessage += MyWeb_ConsoleMessage;//控制台消息 + //MyWeb.ShouldForceDownload += MyWeb_ShouldForceDownload;//应强制下载 + //MyWeb.NeedCredentials += MyWeb_NeedCredentials;//当网页需要身份验证时,EO.WebBrowser引发NeedCredentials 事件。如果您不处理此事件,则默认实现将显示一个对话框,询问用户用户名和密码。 + //MyWeb.CertificateError += MyWeb_CertificateError;//证书错误事件 + //MyWeb.NewWindow += WebView_NewWindow; + //var sHandler = new SampleHandler(); + //sHandler.AfterReceiveData += SHandler_AfterReceiveData; + //webControl1.WebView.RegisterResourceHandler(sHandler);//注册自定义资源处理程序 + + MyWeb.LoadUrl(DefaultUrl); + + } + + + + private void MyWeb_LoadCompleted(object sender, EO.WebBrowser.LoadCompletedEventArgs e) + { + try + { + var url = e.Url; + Console.WriteLine("加载完成:"+url); + if (url.StartsWith("https://passport.suning.com/ids/login")) + { + webControl1.WebView.EvalScript(@"function getqr() + { + var imgs = document.getElementsByClassName('qrCodesId'); + if(imgs.length>0 && imgs[0].src && imgs[0].src.length>10) + { + return imgs[0].src; + } +return ''; + } +", false); + var timeout = DateTime.Now.AddSeconds(10); + while (timeout > DateTime.Now) + { + Util.Sleep(500); + this.QRCodeUrl = webControl1.WebView.InvokeFunction("getqr")?.ToString(); + if (string.IsNullOrEmpty(this.QRCodeUrl)) continue; + else break; + } + + if (!string.IsNullOrEmpty(this.QRCodeUrl)) + { + this.QRCodeStatus = MyClass.Views.LoginQRCodeStatus.等待扫码; + } + } + else if (url.StartsWith("http://sums.suning.com/union/myUnion/account/info.htm")) + { + var ck = this.webView1.Engine.CookieManager.GetCookies(url); + StringBuilder sb = new StringBuilder(); + foreach (var key in ck.AllKeys) + sb.Append(key + "=" + ck[key].Value + ";"); + this.Cookies = sb.ToString(); + + var html = this.webView1.GetHtml(); + html = Regex.Replace(html, @"\s", "", RegexOptions.IgnoreCase); + var reg = Regex.Match(html, @"用户名:(?<会员名>.+?)[\w\W]+会员编码:(?<会员编码>\d+)", RegexOptions.IgnoreCase | RegexOptions.Multiline); + if (reg.Success) + { + var memberId = reg.Groups["会员编码"].Value; + + + var suning = Client.SingleClient.Db.Queryable().Where(f => f.Username == memberId && f.LianmengType == Common.Models.Enums.LianmengType.抖音联盟).First(); + if (suning == null) + { + suning = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.苏宁联盟, + Username = memberId + }; + }; + SuningRequest req = new SuningRequest(suning, null); + var token = req.CreateToolsRelation(memberId); + + suning.ReToken = String.Empty; + suning.ExpirationTime = DateTime.MaxValue; + suning.Cookies = this.Cookies; + suning.Token = token; + suning.Nickname = reg.Groups["会员名"].Value; + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + else + { + QRCodeStatus = LoginQRCodeStatus.登录失败; + ErrorMsg = "已确认登录,但获取关键信息失败!"; + } + + + } + } + catch (Exception ex) + { + QRCodeStatus = LoginQRCodeStatus.登录失败; + ErrorMsg =ex.Message; + } + } + private string uuid = string.Empty; + private void LoginSuningFrom_Load(object sender, EventArgs e) + { + //InitEobrowser("https://passport.suning.com/ids/login?service=https://aq.suning.com/asc/auth?targetUrl=http%3A%2F%2Fsums.suning.com%2Funion%2FmyUnion%2Faccount%2Finfo.htm&loginTheme=b2c&multipleActive=false"); + + try + { + var login_url = $"https://passport.suning.com/ids/qrLoginUuidGenerate.htm?image=false&yys={Common.Utils.Util.GetTimespan(DateTime.Now)}000"; + var http = new HttpHelper(); + var result = http.GetHtml(login_url); + /*{ + "res_code": "0", + "qrToken": "qrW0hko8F1pE00ymjrX5hi3CCmRkiodVl1", + "url": "http://code.suning.cn/iUHns4?qrToken=qrW0hko8F1pE00ymjrX5hi3CCmRkiodVl1&actionTag=1" +}*/ + var json = JObject.Parse(result.Html); + + if (json != null && json["res_code"]?.ToString() == "0") + { + this.QRCodeUrl = json["url"].ToString(); + this.uuid = json["qrToken"].ToString(); + this.Cookies = HttpHelper.GetSmallCookie(result.Cookie); + this.timer1.Enabled = true; + QRCodeStatus = LoginQRCodeStatus.等待扫码; + }else throw new Exception(result.Html); + } + catch (Exception ex) + { + ErrorMsg = ex.Message; + QRCodeStatus = LoginQRCodeStatus.获取二维码失败; + } + } + public static string UpdateCookies(string oldCookie, string newCookie) + { + #region 老妖xxx + if (!string.IsNullOrEmpty(oldCookie) && !string.IsNullOrEmpty(newCookie)) + { + oldCookie = HttpHelper.GetSmallCookie(oldCookie).Replace(";;",";"); + List Old = oldCookie.Split(';').Select(f => f.Trim()).ToList(); + + newCookie = HttpHelper.GetSmallCookie(newCookie); + List New = newCookie.Split(';').Select(f => f.Trim()).ToList(); + foreach (string n in New) + { + foreach (string o in Old) + { + if (o == n || o.Split('=')[0] == n.Split('=')[0]) + { + Old.Remove(o); + break; + } + } + } + List list = new List(Old); + + foreach (var item in New) + { + if (!string.IsNullOrWhiteSpace(item)) + { + var tmp = item.Split('='); + if (tmp.Length >= 2) + { + var oldTmp = list.Where(f => f.Trim().StartsWith(tmp[0] + "=")).ToList(); + foreach (var oldItem in oldTmp) + { + if (!string.IsNullOrWhiteSpace(oldItem)) + { + list.Remove(oldItem); + } + } + list.Add(item); + } + } + } + list = list.Where(f => !string.IsNullOrWhiteSpace(f)).ToList(); + return string.Join(";", list.ToArray()); + } + else if (!string.IsNullOrEmpty(oldCookie)) return oldCookie; + else if (!string.IsNullOrEmpty(newCookie)) return newCookie; + else return ""; + #endregion + + //#region 老道 + //if (!string.IsNullOrEmpty(oldCookie) && !string.IsNullOrEmpty(newCookie)) + //{ + // oldCookie = HttpHelper.GetSmallCookie(oldCookie); + // List Old = oldCookie.Split(';').Select(f => f.Trim()).Distinct().ToList(); + + // newCookie = HttpHelper.GetSmallCookie(newCookie); + // List New = newCookie.Split(';').Select(f => f.Trim()).Distinct().ToList(); + // foreach (string n in New) + // { + // foreach (string o in Old) + // { + // if (o == n || o.Split('=')[0] == n.Split('=')[0]) + // { + // Old.Remove(o); + // break; + // } + // } + // } + // List list = new List(Old); + // //list.AddRange(New); + // foreach (var item in New) + // { + // if (!string.IsNullOrWhiteSpace(item)) + // { + // var tmp = item.Split('='); + // if (tmp.Length >= 2) + // { + // var oldTmp = list.Where(f => f.Trim().StartsWith(tmp[0] + "=")).ToList(); + // foreach (var oldItem in oldTmp) + // { + // if (!string.IsNullOrWhiteSpace(oldItem)) + // { + // list.Remove(oldItem); + // } + // } + // list.Add(item); + // } + // } + // } + // list = list.Where(f => !string.IsNullOrWhiteSpace(f)).ToList(); + // return string.Join(";", list.ToArray()); + //} + //else if (!string.IsNullOrEmpty(oldCookie)) return oldCookie; + //else if (!string.IsNullOrEmpty(newCookie)) return newCookie; + //else return ""; + //#endregion + } + private void timer1_Tick(object sender, EventArgs e) + { + try + { + var http = new HttpHelper(); + var result = http.GetHtml("https://passport.suning.com/ids/qrLoginStateProbe?r="+Guid.NewGuid().ToString(), this.Cookies, $"uuid={uuid}&service=&terminal=PC", "https://passport.suning.com/ids/login"); + var json = JObject.Parse(result.Html); + var code = json["state"].ToString(); + + if (!string.IsNullOrEmpty(result.Cookie)) this.Cookies = result.UpdateCookies(this.Cookies); + if (code == "0") + { + QRCodeStatus = LoginQRCodeStatus.等待扫码; + } + else if (code == "1") + { + QRCodeStatus = LoginQRCodeStatus.等待确认登录; + } + else if (code == "2") + { + this.timer1.Enabled = false; + + var vid = Util.GetTimespan(DateTime.Now).ToString() + (long)(new Random().NextDouble() * 100000000); + this.Cookies += $";_snma=" + HttpHelper.URLEncode("1|{vid}|{vid.Substring(0,13)}|{HttpExtend.GetTimeStamp(DateTime.Now,true)}|{HttpExtend.GetTimeStamp(DateTime.Now, true)}|27|2"); + //var item = http.GetItem($"https://dfp.suning.com/dfprs-collect/fp/ad-log.png?token=THhV9h17f9c4c133blF0N6f62&snrs=%7B%22vid%22%3A%22{vid}%22%2C%22snsr%22%3A%7B%22source%22%3A%22direct%22%2C%22medium%22%3A%22direct%22%2C%22content%22%3A%22%22%2C%22campaign%22%3A%22%22%2C%22term%22%3A%22%22%7D%7D",this.Cookies,"", "https://passport.suning.com/"); + //item.Accept = "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"; + //item.Header["cache-control"] = "no-cache"; + + var item = http.GetItem($"https://passport.suning.com/ids/login?service=https%3A%2F%2Floginst.suning.com%2Fauth%3FtargetUrl%3Dhttps%253A%252F%252Floginst.suning.com%252FauthStatus%253Fcallback%253DjQuery172004949899331832408_1647605568465%2526_%253D{HttpExtend.GetTimeStamp(DateTime.Now,true)}&gateway=true&loginTheme=b2c&multipleActive=false",this.Cookies); + item.Allowautoredirect = false; + result = http.GetHtml(item); + + this.Cookies = result.UpdateCookies(this.Cookies); + + //this.Cookies = result.UpdateCookies(this.Cookies); + item = http.GetItem("http://sums.suning.com/union/myUnion/account/info.htm",this.Cookies); + item.Timeout = 10000; + item.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0"; + item.Accept = "text/html, application/xhtml+xml, */*"; + item.ContentType = "text/html"; + item.Referer = "http://sums.suning.com/union/myUnion/account/info.htm"; + + var html = http.GetHtml(item).Html; + html = Regex.Replace(html, @"\s", "", RegexOptions.IgnoreCase); + var reg = Regex.Match(html, @"用户名:(?<会员名>.+?)[\w\W]+会员编码:(?<会员编码>\d+)", RegexOptions.IgnoreCase | RegexOptions.Multiline); + if (reg.Success) + { + var memberId = reg.Groups["会员编码"].Value; + + + var suning = Client.SingleClient.Db.Queryable().Where(f => f.Username == memberId && f.LianmengType == Common.Models.Enums.LianmengType.抖音联盟).First(); + if (suning == null) + { + suning = new Lianmeng() + { + LianmengType = Common.Models.Enums.LianmengType.苏宁联盟, + Username = memberId + }; + }; + SuningRequest req = new SuningRequest(suning, null); + var token = req.CreateToolsRelation(memberId); + + suning.ReToken = String.Empty; + suning.ExpirationTime = DateTime.Now.AddYears(100); + suning.Cookies = this.Cookies; + suning.Token = token; + suning.Nickname = reg.Groups["会员名"].Value; + Client.SingleClient.Db.Save(suning); + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + else + { + + QRCodeStatus = LoginQRCodeStatus.登录失败; + ErrorMsg = "已确认登录,但获取关键信息失败!"; + } + + QRCodeStatus = LoginQRCodeStatus.登录并授权成功; + } + else + { + this.timer1.Enabled = false; + QRCodeStatus = LoginQRCodeStatus.二维码已过期; + this.Invoke(new System.Action(delegate () + { + this.Close(); + })); + } + } + catch (Exception) + { + } + } + } +} diff --git a/Server/Winforms/LoginForms/LoginSuningFrom.resx b/Server/Winforms/LoginForms/LoginSuningFrom.resx new file mode 100644 index 0000000..09a2f6b --- /dev/null +++ b/Server/Winforms/LoginForms/LoginSuningFrom.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 129, 17 + + \ No newline at end of file diff --git a/Server/Winforms/MainForm.Designer.cs b/Server/Winforms/MainForm.Designer.cs new file mode 100644 index 0000000..f93a6d6 --- /dev/null +++ b/Server/Winforms/MainForm.Designer.cs @@ -0,0 +1,302 @@ +namespace Server.Winforms +{ + partial class MainForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); + this.tabControl1 = new System.Windows.Forms.TabControl(); + this.tabPage1 = new System.Windows.Forms.TabPage(); + this.button8 = new System.Windows.Forms.Button(); + this.button6 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button7 = new System.Windows.Forms.Button(); + this.button5 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.button1 = new System.Windows.Forms.Button(); + this.Webappsecret = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); + this.Mysqluser = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.Adminusername = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.Wangzhi = new System.Windows.Forms.TextBox(); + this.label1 = new System.Windows.Forms.Label(); + this.tabPage3 = new System.Windows.Forms.TabPage(); + this.tabControl1.SuspendLayout(); + this.tabPage1.SuspendLayout(); + this.SuspendLayout(); + // + // notifyIcon1 + // + this.notifyIcon1.Text = "云控系统(返利机器人)"; + this.notifyIcon1.BalloonTipShown += new System.EventHandler(this.notifyIcon1_BalloonTipShown); + this.notifyIcon1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.notifyIcon1_MouseDoubleClick); + // + // tabControl1 + // + this.tabControl1.Controls.Add(this.tabPage1); + this.tabControl1.Controls.Add(this.tabPage3); + this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tabControl1.Location = new System.Drawing.Point(0, 0); + this.tabControl1.Name = "tabControl1"; + this.tabControl1.SelectedIndex = 0; + this.tabControl1.Size = new System.Drawing.Size(704, 294); + this.tabControl1.SizeMode = System.Windows.Forms.TabSizeMode.Fixed; + this.tabControl1.TabIndex = 0; + // + // tabPage1 + // + this.tabPage1.Controls.Add(this.button8); + this.tabPage1.Controls.Add(this.button6); + this.tabPage1.Controls.Add(this.button3); + this.tabPage1.Controls.Add(this.button4); + this.tabPage1.Controls.Add(this.button7); + this.tabPage1.Controls.Add(this.button5); + this.tabPage1.Controls.Add(this.button2); + this.tabPage1.Controls.Add(this.button1); + this.tabPage1.Controls.Add(this.Webappsecret); + this.tabPage1.Controls.Add(this.label4); + this.tabPage1.Controls.Add(this.Mysqluser); + this.tabPage1.Controls.Add(this.label3); + this.tabPage1.Controls.Add(this.Adminusername); + this.tabPage1.Controls.Add(this.label2); + this.tabPage1.Controls.Add(this.Wangzhi); + this.tabPage1.Controls.Add(this.label1); + this.tabPage1.Location = new System.Drawing.Point(4, 22); + this.tabPage1.Name = "tabPage1"; + this.tabPage1.Padding = new System.Windows.Forms.Padding(3); + this.tabPage1.Size = new System.Drawing.Size(696, 268); + this.tabPage1.TabIndex = 2; + this.tabPage1.Text = "控制台"; + this.tabPage1.UseVisualStyleBackColor = true; + // + // button8 + // + this.button8.Location = new System.Drawing.Point(570, 90); + this.button8.Name = "button8"; + this.button8.Size = new System.Drawing.Size(75, 23); + this.button8.TabIndex = 21; + this.button8.Text = "修改密码"; + this.button8.UseVisualStyleBackColor = true; + this.button8.Click += new System.EventHandler(this.button8_Click); + // + // button6 + // + this.button6.Enabled = false; + this.button6.Location = new System.Drawing.Point(570, 138); + this.button6.Name = "button6"; + this.button6.Size = new System.Drawing.Size(75, 23); + this.button6.TabIndex = 20; + this.button6.Text = "修改密码"; + this.button6.UseVisualStyleBackColor = true; + // + // button3 + // + this.button3.Location = new System.Drawing.Point(570, 42); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.TabIndex = 19; + this.button3.Text = "打开网站"; + this.button3.UseVisualStyleBackColor = true; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // button4 + // + this.button4.Location = new System.Drawing.Point(478, 90); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(75, 23); + this.button4.TabIndex = 18; + this.button4.Text = "复制"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // button7 + // + this.button7.Location = new System.Drawing.Point(570, 190); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(75, 23); + this.button7.TabIndex = 17; + this.button7.Text = "重置密钥"; + this.button7.UseVisualStyleBackColor = true; + this.button7.Click += new System.EventHandler(this.button7_Click); + // + // button5 + // + this.button5.Location = new System.Drawing.Point(478, 42); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(75, 23); + this.button5.TabIndex = 15; + this.button5.Text = "复制"; + this.button5.UseVisualStyleBackColor = true; + this.button5.Click += new System.EventHandler(this.button5_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(478, 138); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 12; + this.button2.Text = "复制"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.button2_Click_1); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(478, 190); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 11; + this.button1.Text = "复制"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click_1); + // + // Webappsecret + // + this.Webappsecret.Location = new System.Drawing.Point(180, 190); + this.Webappsecret.Name = "Webappsecret"; + this.Webappsecret.PasswordChar = '*'; + this.Webappsecret.ReadOnly = true; + this.Webappsecret.Size = new System.Drawing.Size(281, 21); + this.Webappsecret.TabIndex = 10; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label4.Location = new System.Drawing.Point(73, 193); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(98, 14); + this.label4.TabIndex = 9; + this.label4.Text = "免密API密钥:"; + // + // Mysqluser + // + this.Mysqluser.Location = new System.Drawing.Point(180, 140); + this.Mysqluser.Name = "Mysqluser"; + this.Mysqluser.Size = new System.Drawing.Size(281, 21); + this.Mysqluser.TabIndex = 7; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label3.Location = new System.Drawing.Point(80, 141); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(91, 14); + this.label3.TabIndex = 6; + this.label3.Text = "数据库名称:"; + // + // Adminusername + // + this.Adminusername.Location = new System.Drawing.Point(180, 92); + this.Adminusername.Name = "Adminusername"; + this.Adminusername.Size = new System.Drawing.Size(281, 21); + this.Adminusername.TabIndex = 4; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label2.Location = new System.Drawing.Point(80, 95); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(91, 14); + this.label2.TabIndex = 3; + this.label2.Text = "管理员账号:"; + // + // Wangzhi + // + this.Wangzhi.Location = new System.Drawing.Point(180, 42); + this.Wangzhi.Name = "Wangzhi"; + this.Wangzhi.ReadOnly = true; + this.Wangzhi.Size = new System.Drawing.Size(281, 21); + this.Wangzhi.TabIndex = 1; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label1.Location = new System.Drawing.Point(94, 45); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(77, 14); + this.label1.TabIndex = 0; + this.label1.Text = "网站地址:"; + // + // tabPage3 + // + this.tabPage3.Location = new System.Drawing.Point(4, 22); + this.tabPage3.Name = "tabPage3"; + this.tabPage3.Padding = new System.Windows.Forms.Padding(3); + this.tabPage3.Size = new System.Drawing.Size(696, 280); + this.tabPage3.TabIndex = 3; + this.tabPage3.Text = "日志"; + this.tabPage3.UseVisualStyleBackColor = true; + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(704, 294); + this.Controls.Add(this.tabControl1); + this.MaximizeBox = false; + this.Name = "MainForm"; + this.Text = "机器人服务端"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing); + this.Load += new System.EventHandler(this.MainForm_Load); + this.SizeChanged += new System.EventHandler(this.MainForm_SizeChanged); + this.tabControl1.ResumeLayout(false); + this.tabPage1.ResumeLayout(false); + this.tabPage1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.NotifyIcon notifyIcon1; + private System.Windows.Forms.TabControl tabControl1; + private System.Windows.Forms.TabPage tabPage1; + private System.Windows.Forms.TabPage tabPage3; + private System.Windows.Forms.TextBox Wangzhi; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button button7; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.TextBox Webappsecret; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.TextBox Mysqluser; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox Adminusername; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button8; + private System.Windows.Forms.Button button6; + } +} \ No newline at end of file diff --git a/Server/Winforms/MainForm.cs b/Server/Winforms/MainForm.cs new file mode 100644 index 0000000..c40e321 --- /dev/null +++ b/Server/Winforms/MainForm.cs @@ -0,0 +1,302 @@ +using Common.DbExtends.Extends; +using Common.Models.JsonModels; +using Common.Models.UnqTables; +using Common.Utils; +using EO.Base; +using EO.WebEngine; +using Microsoft.Win32; +using Server.Winforms.LoginForms; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows.Forms; +using Action = System.Action; + +namespace Server.Winforms +{ + public partial class MainForm : DefaultForm + { + + + public MainForm() + { + InitializeComponent(); + + } + + + + + private void linkLabel1_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e) + { + //if (this.linkLabel1.Text == "显示") + //{ + // this.linkLabel1.Text = "隐藏"; + // this.textBox1.Text = Client.Config.Appsecret; + //} + //else + //{ + // this.textBox1.Text = "***************"; + // this.linkLabel1.Text = "显示"; + //} + + } + + private bool IsCloseForm; + Client Client; + private void OpenUrl(string url) + { + + try + { + RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\"); + string s = key.GetValue("").ToString(); + System.Diagnostics.Process.Start(s.Substring(0, s.Length - 8), url); + return; + } + catch (Exception) + { + } + + try + { + //调用系统默认的浏览器 + System.Diagnostics.Process.Start("explorer.exe", url); + return; + } + catch (Exception) + { + } + + try + { + + //调用系统默认的浏览器 + System.Diagnostics.Process.Start(url); + return; + } + catch (Exception) + { + } + + + } + + /// + /// 初始化完成 + /// + public Action InitCompleteAction { get; set; } + + private void MainForm_Load(object sender, EventArgs e) + { + try + { + + Client = Client.SingleClient; + Client.Form = this; + this.notifyIcon1.Icon = this.Icon; + + + //this.numericUpDown1.Value = Client.Config.Port; + Client.InitSystem(); + + var Admin = Client.Db.Queryable().Single(f => f.Id == 1); + if (Admin == null) + { + InitCompleteAction?.Invoke(); + + var f = new SetDefaultuserForm(); + if (f.ShowDialog() != DialogResult.Yes) + { + + IsCloseForm = true; + this.Close(); + return; + } + + Admin = f.AdminEntity; + } + + this.Adminusername.Text = Admin.Username; + this.Wangzhi.Text = Client.Url; + + this.Mysqluser.Text = Client.Config.MysqlName; + this.Webappsecret.Text = Client.Config.Appsecret; + Client.Db.OnLog("服务端", "启动成功!"); + + + //初始化一个窗口,放着 + LianMengWebViewLoginHelper.Instance.InitDefaultWebview(3); + InitCompleteAction?.Invoke(); + } + catch (Exception ex) + { + DialogResult = DialogResult.No; + IsCloseForm = true; + MessageBox.Show(ex.Message, "初始化失败", MessageBoxButtons.OK, MessageBoxIcon.Error); + this.Close(); + } + finally + { + InitCompleteAction?.Invoke(); + } + } + + //退出时候,保存缓存 + private void Events_ExitWinform(object sender, EventArgs e) + { + + } + + private void linkLabel2_LinkClicked_1(object sender, LinkLabelLinkClickedEventArgs e) + { + //var Rst = MessageBox.Show("重置后机器人客户端需要重新设置通行证", "您确定要重置吗?", MessageBoxButtons.YesNo,MessageBoxIcon.Question); + //if (Rst == DialogResult.Yes) + //{ + // Client.Config.Appsecret = Guid.NewGuid().ToString(); + // if (this.linkLabel1.Text == "隐藏") + // { + // this.textBox1.Text = Client.Config.Appsecret; + // } + // Client.Config.Ini.SetValue("终端","密钥", Client.Config.Appsecret); + //} + } + + private void MainForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (!IsCloseForm) + { + var Rst = MessageBox.Show("退出后云端网页及API功能将无法正常加载", "您确定要退出吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (Rst == DialogResult.No) + { + this.WindowState = FormWindowState.Minimized; + e.Cancel = true; + return; + } + else + this.notifyIcon1.Visible = false; + + Client.SingleClient.Events.OnExitWinform(this); + } + } + + private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) + { + this.WindowState = FormWindowState.Normal; + } + + private int MinformCount; + private void MainForm_SizeChanged(object sender, EventArgs e) + { + if (this.WindowState == FormWindowState.Minimized) + { + MinformCount++; + this.notifyIcon1.Visible = true; + this.ShowInTaskbar = false; + if (MinformCount == 1) + { + this.notifyIcon1.ShowBalloonTip(3000, "云控-最小化通知", "双击右下角云控图标,会再次显示出来", ToolTipIcon.None); + } + + } + else if (this.WindowState == FormWindowState.Normal) + { + + this.notifyIcon1.Visible = false; + this.ShowInTaskbar = true; + } + } + + private void notifyIcon1_BalloonTipShown(object sender, EventArgs e) + { + + } + + private void button2_Click(object sender, EventArgs e) + { + + } + + private void button1_Click(object sender, EventArgs e) + { + var CerData = new + { + Ip = Client.InternetIP, + Port = Client.Config.Port, + Appsecret = Client.Config.Appsecret + }; + + } + + private void button4_Click(object sender, EventArgs e) + { + Clipboard.SetDataObject(this.Adminusername.Text); + + } + + private void button5_Click(object sender, EventArgs e) + { + Clipboard.SetDataObject(this.Wangzhi.Text); + } + + private void button3_Click(object sender, EventArgs e) + { + OpenUrl(Client.SingleClient.Url); + } + + private void button2_Click_1(object sender, EventArgs e) + { + Clipboard.SetDataObject(this.Mysqluser.Text); + } + + private void button1_Click_1(object sender, EventArgs e) + { + Clipboard.SetDataObject(this.Client.Config.Appsecret); + } + + private void button7_Click(object sender, EventArgs e) + { + var Rst = MessageBox.Show("重置后机器人客户端需要重新设置密钥", "您确定要重置吗?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + if (Rst == DialogResult.Yes) + { + Client.Config.Appsecret = Guid.NewGuid().ToString(); + this.Webappsecret.Text = Client.Config.Appsecret; + Client.Config.Ini.SetValue("终端", "密钥", Client.Config.Appsecret); + } + } + + private void button6_Click(object sender, EventArgs e) + { + } + + private void timer1_Tick(object sender, EventArgs e) + { + + } + + private Queue LoginForms = new Queue(); + public LoginForms.LoginLianmengForm GetLoginForm() + { + if (LoginForms.Count > 0) + return LoginForms.Dequeue(); + else + return new LoginLianmengForm(); + } + + private void button8_Click(object sender, EventArgs e) + { + + var f = new SetDefaultuserForm(); + if (f.ShowDialog() == DialogResult.Yes) + { + this.Adminusername.Text = f.AdminEntity.Username; + } + } + } +} diff --git a/Server/Winforms/MainForm.resx b/Server/Winforms/MainForm.resx new file mode 100644 index 0000000..84ceda3 --- /dev/null +++ b/Server/Winforms/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Server/Winforms/SetDefaultuserForm.Designer.cs b/Server/Winforms/SetDefaultuserForm.Designer.cs new file mode 100644 index 0000000..d1b3f53 --- /dev/null +++ b/Server/Winforms/SetDefaultuserForm.Designer.cs @@ -0,0 +1,131 @@ +namespace Server.Winforms +{ + partial class SetDefaultuserForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.textBox2 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); + this.label3 = new System.Windows.Forms.Label(); + this.textBox3 = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(83, 51); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(41, 12); + this.label1.TabIndex = 0; + this.label1.Text = "账号:"; + // + // textBox1 + // + this.textBox1.Location = new System.Drawing.Point(130, 48); + this.textBox1.Name = "textBox1"; + this.textBox1.Size = new System.Drawing.Size(206, 21); + this.textBox1.TabIndex = 1; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(83, 101); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(41, 12); + this.label2.TabIndex = 2; + this.label2.Text = "密码:"; + // + // textBox2 + // + this.textBox2.Location = new System.Drawing.Point(130, 97); + this.textBox2.Name = "textBox2"; + this.textBox2.PasswordChar = '*'; + this.textBox2.Size = new System.Drawing.Size(206, 21); + this.textBox2.TabIndex = 3; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(181, 192); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(96, 34); + this.button1.TabIndex = 4; + this.button1.Text = "保存配置"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(59, 144); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(65, 12); + this.label3.TabIndex = 5; + this.label3.Text = "确认密码:"; + // + // textBox3 + // + this.textBox3.Location = new System.Drawing.Point(130, 141); + this.textBox3.Name = "textBox3"; + this.textBox3.PasswordChar = '*'; + this.textBox3.Size = new System.Drawing.Size(206, 21); + this.textBox3.TabIndex = 6; + // + // SetDefaultuserForm + // + this.AcceptButton = this.button1; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(398, 253); + this.Controls.Add(this.textBox3); + this.Controls.Add(this.label3); + this.Controls.Add(this.button1); + this.Controls.Add(this.textBox2); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBox1); + this.Controls.Add(this.label1); + this.Name = "SetDefaultuserForm"; + this.Text = "设置超级管理员"; + this.Load += new System.EventHandler(this.SetDefaultUser_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox textBox2; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.TextBox textBox3; + } +} \ No newline at end of file diff --git a/Server/Winforms/SetDefaultuserForm.cs b/Server/Winforms/SetDefaultuserForm.cs new file mode 100644 index 0000000..56adb60 --- /dev/null +++ b/Server/Winforms/SetDefaultuserForm.cs @@ -0,0 +1,88 @@ +using Common.Models.UnqTables; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server.Winforms +{ + public partial class SetDefaultuserForm : DefaultForm + { + public SetDefaultuserForm() + { + InitializeComponent(); + } + public Staff AdminEntity; + public Role RoleEntity; + private void SetDefaultUser_Load(object sender, EventArgs e) + { + RoleEntity = Client.SingleClient.Db.Queryable().Where(f => f.Name == "超级管理员").First(); + + + AdminEntity = Client.SingleClient.Db.Queryable().Where(f =>f.IsCreator == true).First(); + if (AdminEntity != null) + { + this.textBox1.Text = AdminEntity.Username; + } + } + + //List roles = new List() { "Anlyze", "Data", "Tools", "Artificial", "Qunfa", "Social", "Account", "Lianmeng", "Robot", "Staff", "Member", "Grouping", "WechatUser", "Fans", "Blacklist", "Reminder", "Func", "Pub", "Base", "Rebate", "Feed", "Keywords", "Order", "TbOrder", "JdOrder", "DyOrder", "MtOrder", "SnOrder", "WphOrder", "PddOrder", "Financial", "CashList", "PayRecord", "IntegralRecord", "Help", "RunLog", "QA", "Guide", "About"}; + + private void button1_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(this.textBox1.Text) || string.IsNullOrEmpty(this.textBox2.Text) || string.IsNullOrEmpty(this.textBox3.Text)) + { + MessageBox.Show("操作失败,用户名或密码为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else if (this.textBox2.Text != this.textBox3.Text) + { + MessageBox.Show("操作失败,两次密码输入的不一致", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + else + { + + + + //修改了用户名,就检查下用户名是否存在 + if (AdminEntity != null && AdminEntity.Username != this.textBox1.Text) + { + var v = Client.SingleClient.Db.Queryable().Where(f => f.Username == this.textBox1.Text).First(); + if (v != null) + { + MessageBox.Show("操作失败,该用户名已存在请修改后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + //MD5加密 + var password = Common.Utils.Util.GetMd5(this.textBox2.Text); + if (AdminEntity == null) + { + AdminEntity = new Staff(); + AdminEntity.IsCreator = true; + AdminEntity.Username = this.textBox1.Text; + AdminEntity.Password = password; + AdminEntity.RoleId = RoleEntity.Id; + AdminEntity.IsCreator = true; + Client.SingleClient.Db.Insertable(AdminEntity).ExecuteCommand(); + } + else + { + AdminEntity.IsCreator = true; + AdminEntity.Username = this.textBox1.Text; + AdminEntity.Password = password; + Client.SingleClient.Db.Updateable(AdminEntity).ExecuteCommand(); + } + + + this.DialogResult = DialogResult.Yes; + this.Close(); + } + + } + } +} diff --git a/Server/Winforms/SetDefaultuserForm.resx b/Server/Winforms/SetDefaultuserForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Server/Winforms/SetDefaultuserForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Server/Winforms/StartForm.Designer.cs b/Server/Winforms/StartForm.Designer.cs new file mode 100644 index 0000000..655447d --- /dev/null +++ b/Server/Winforms/StartForm.Designer.cs @@ -0,0 +1,79 @@ +namespace Server.Winforms +{ + partial class StartForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label1.Location = new System.Drawing.Point(94, 71); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(207, 16); + this.label1.TabIndex = 0; + this.label1.Text = "服务端正在启动,请稍后..."; + // + // pictureBox1 + // + this.pictureBox1.Image = global::Server.Properties.Resources.progress; + this.pictureBox1.Location = new System.Drawing.Point(134, 31); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(100, 20); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; + this.pictureBox1.TabIndex = 1; + this.pictureBox1.TabStop = false; + // + // StartForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(367, 124); + this.Controls.Add(this.pictureBox1); + this.Controls.Add(this.label1); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "StartForm"; + this.Text = "云控系统服务端"; + this.Load += new System.EventHandler(this.StartForm_Load); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.PictureBox pictureBox1; + } +} \ No newline at end of file diff --git a/Server/Winforms/StartForm.cs b/Server/Winforms/StartForm.cs new file mode 100644 index 0000000..9742487 --- /dev/null +++ b/Server/Winforms/StartForm.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Server.Winforms +{ + public partial class StartForm : DefaultForm + { + public StartForm() + { + InitializeComponent(); + } + + private void StartForm_Load(object sender, EventArgs e) + { + + } + } +} diff --git a/Server/Winforms/StartForm.resx b/Server/Winforms/StartForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/Server/Winforms/StartForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Server/packages.config b/Server/packages.config new file mode 100644 index 0000000..34ef013 --- /dev/null +++ b/Server/packages.config @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file