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