Browse Source

增加统计交易额到RDS数据库

lcl 2 years ago
parent
commit
0eba7f313d

+ 224 - 0
AppStart/Helper/StatNewService.cs

@@ -0,0 +1,224 @@
+using System;
+using System.Collections.Generic;
+using Library;
+using LitJson;
+using System.Linq;
+using System.Data;
+using System.Threading;
+using MySystem.PxcModels;
+
+namespace MySystem
+{
+    public class StatNewService
+    {
+        public readonly static StatNewService Instance = new StatNewService();
+        private StatNewService()
+        { }
+
+
+
+
+
+
+        // 统计交易额V2
+        public void StartStat()
+        {
+            Thread th = new Thread(StartStatDo);
+            th.IsBackground = true;
+            th.Start();
+        }
+        public void StartStatDo()
+        {
+            while (true)
+            {
+                string content = RedisDbconn.Instance.RPop<string>("StatTradeAmountQueue");
+                if(!string.IsNullOrEmpty(content))
+                {
+                    StatTradeAmount(content, 1);
+                    StatTradeAmount(content, 2);
+                }
+                Thread.Sleep(10000);
+            }
+        }
+        public void StatTradeAmount(string content, int Kind)
+        {
+            WebCMSEntities db = new WebCMSEntities();
+            try
+            {
+                JsonData selfDr = JsonMapper.ToObject(content);
+                int UserId = int.Parse(selfDr["UserId"].ToString());
+                Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
+                string ParentNav = user.ParentNav;
+                int BrandId = int.Parse(selfDr["BrandId"].ToString());
+                int BankCardType = int.Parse(selfDr["BankCardType"].ToString());
+                int QrPayFlag = int.Parse(selfDr["QrPayFlag"].ToString());
+                int MerHelpFlag = int.Parse(selfDr["MerHelpFlag"].ToString());
+                int Version = int.Parse(selfDr["Version"].ToString());
+                int CapFlag = int.Parse(selfDr["CapFlag"].ToString());
+                int VipFlag = int.Parse(selfDr["VipFlag"].ToString());
+                int PayType = int.Parse(selfDr["PayType"].ToString());
+                string TradeDate = selfDr["TradeDate"].ToString();
+                decimal TradeAmount = decimal.Parse(selfDr["TradeAmount"].ToString());
+                int TradeCount = int.Parse(selfDr["TradeCount"].ToString());
+                if(Kind == 2)
+                {
+                    TradeDate = TradeDate.Substring(0, 6);
+                }
+                if(string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>("TradeDaySummary" + TradeDate)))
+                {
+                    CustomerSqlConn.op(AppConfig.Base.CreateTradeDaySummary.Replace("#DateTime#", TradeDate), AppConfig.Base.StatSqlConn);
+                    RedisDbconn.Instance.Set("TradeDaySummary" + TradeDate, "1");
+                    int sec = 3600 * 13;
+                    if(Kind == 2)
+                    {
+                        sec = 3600 * 12 * 35;
+                    }
+                    RedisDbconn.Instance.SetExpire("TradeDaySummary" + TradeDate, sec);
+                    Thread.Sleep(2000);
+                }
+
+                string Id = "0";
+                DataTable check = CustomerSqlConn.dtable("select Id from TradeDaySummary" + TradeDate + " where UserId=" + UserId + " and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'", AppConfig.Base.StatSqlConn);
+                if(check.Rows.Count < 1)
+                {
+                    check = CustomerSqlConn.dtable("insert into TradeDaySummary" + TradeDate + " (UserId,BrandId,QueryCount,VipFlag,PayType,SeoTitle) values (" + UserId + "," + BrandId + "," + QrPayFlag + "," + VipFlag + "," + PayType + ",'self');select @@IDENTITY", AppConfig.Base.StatSqlConn);
+                    if(check.Rows.Count > 0)
+                    {
+                        Id = check.Rows[0][0].ToString();
+                    }
+                }
+                else
+                {
+                    Id = check.Rows[0][0].ToString();
+                }
+                string selfStat = "";
+                if (BankCardType == 0)
+                {
+                    if (Version == 1)
+                    {
+                        selfStat += "ProfitDirectDebitTradeAmt = ProfitDirectDebitTradeAmt+" + TradeAmount + ",";
+                        if (CapFlag == 1)
+                        {
+                            selfStat += "ProfitDirectDebitCapTradeAmt = ProfitDirectDebitCapTradeAmt+" + TradeAmount + ",";
+                            selfStat += "ProfitDirectDebitCapNum = ProfitDirectDebitCapNum+" + TradeCount + ",";
+                        }
+                    }
+                    else if (MerHelpFlag == 1)
+                    {
+                        selfStat += "HelpDirectDebitTradeAmt = HelpDirectDebitTradeAmt+" + TradeAmount + ",";
+                        if (CapFlag == 1)
+                        {
+                            selfStat += "HelpDirectDebitCapTradeAmt = HelpDirectDebitCapTradeAmt+" + TradeAmount + ",";
+                            selfStat += "HelpDirectDebitCapNum = HelpDirectDebitCapNum+" + TradeCount + ",";
+                        }
+                    }
+                    else
+                    {
+                        selfStat += "NotHelpDirectDebitTradeAmt = NotHelpDirectDebitTradeAmt+" + TradeAmount + ",";
+                        if (CapFlag == 1)
+                        {
+                            selfStat += "NotHelpDirectDebitCapTradeAmt = NotHelpDirectDebitCapTradeAmt+" + TradeAmount + ",";
+                            selfStat += "NotHelpDirectDebitCapNum = NotHelpDirectDebitCapNum+" + TradeCount + ",";
+                        }
+                    }
+                }
+                else if (BankCardType != 0)
+                {
+                    if (Version == 1)
+                    {
+                        selfStat += "ProfitDirectTradeAmt = ProfitDirectTradeAmt+" + TradeAmount + ",";
+                    }
+                    else if (MerHelpFlag == 1)
+                    {
+                        selfStat += "HelpDirectTradeAmt = HelpDirectTradeAmt+" + TradeAmount + ",";
+                    }
+                    else
+                    {
+                        selfStat += "NotHelpDirectTradeAmt = NotHelpDirectTradeAmt+" + TradeAmount + ",";
+                    }
+                }
+                CustomerSqlConn.op("update TradeDaySummary" + TradeDate + " set " + selfStat.TrimEnd(',') + " where Id=" + Id, AppConfig.Base.StatSqlConn);
+                ParentNav += "," + UserId + ",";
+                if (!string.IsNullOrEmpty(ParentNav))
+                {
+                    string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
+                    foreach (string NavUserIdString in ParentNavList)
+                    {
+                        int NavUserId = int.Parse(NavUserIdString);
+
+                        string PId = "0";
+                        DataTable pcheck = CustomerSqlConn.dtable("select Id from TradeDaySummary" + TradeDate + " where UserId=" + NavUserId + " and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'", AppConfig.Base.StatSqlConn);
+                        if(pcheck.Rows.Count < 1)
+                        {
+                            pcheck = CustomerSqlConn.dtable("insert into TradeDaySummary" + TradeDate + " (UserId,BrandId,QueryCount,VipFlag,PayType,SeoTitle) values (" + NavUserId + "," + BrandId + "," + QrPayFlag + "," + VipFlag + "," + PayType + ",'team');select @@IDENTITY", AppConfig.Base.StatSqlConn);
+                            if(pcheck.Rows.Count > 0)
+                            {
+                                PId = pcheck.Rows[0][0].ToString();
+                            }
+                        }
+                        else
+                        {
+                            PId = pcheck.Rows[0][0].ToString();
+                        }
+
+                        string teamStat = "";
+                        if (BankCardType == 0)
+                        {
+                            if (Version == 1)
+                            {
+                                teamStat += "ProfitNonDirectDebitTradeAmt = ProfitNonDirectDebitTradeAmt+" + TradeAmount + ",";
+                                if (CapFlag == 1)
+                                {
+                                    teamStat += "ProfitDirectDebitCapTradeAmt = ProfitDirectDebitCapTradeAmt+" + TradeAmount + ",";
+                                    teamStat += "ProfitDirectDebitCapNum = ProfitDirectDebitCapNum+" + TradeCount + ",";
+                                }
+                            }
+                            else if (MerHelpFlag == 1)
+                            {
+                                teamStat += "HelpNonDirectDebitTradeAmt = HelpNonDirectDebitTradeAmt+" + TradeAmount + ",";
+                                if (CapFlag == 1)
+                                {
+                                    teamStat += "HelpDirectDebitCapTradeAmt = HelpDirectDebitCapTradeAmt+" + TradeAmount + ",";
+                                    teamStat += "HelpDirectDebitCapNum = HelpDirectDebitCapNum+" + TradeCount + ",";
+                                }
+                            }
+                            else
+                            {
+                                teamStat += "NotHelpNonDirectDebitTradeAmt = NotHelpNonDirectDebitTradeAmt+" + TradeAmount + ",";
+                                if (CapFlag == 1)
+                                {
+                                    teamStat += "NotHelpDirectDebitCapTradeAmt = NotHelpDirectDebitCapTradeAmt+" + TradeAmount + ",";
+                                    teamStat += "NotHelpDirectDebitCapNum = NotHelpDirectDebitCapNum+" + TradeCount + ",";
+                                }
+                            }
+                        }
+                        else if (BankCardType != 0)
+                        {
+                            if (Version == 1)
+                            {
+                                teamStat += "ProfitNonDirectTradeAmt = ProfitNonDirectTradeAmt+" + TradeAmount + ",";
+                            }
+                            else if (MerHelpFlag == 1)
+                            {
+                                teamStat += "HelpNonDirectTradeAmt = HelpNonDirectTradeAmt+" + TradeAmount + ",";
+                            }
+                            else
+                            {
+                                teamStat += "NotHelpNonDirectTradeAmt = NotHelpNonDirectTradeAmt+" + TradeAmount + ",";
+                            }
+                        }
+                        CustomerSqlConn.op("update TradeDaySummary" + TradeDate + " set " + teamStat.TrimEnd(',') + " where Id=" + PId, AppConfig.Base.StatSqlConn);
+                    }
+                }
+                db.SaveChanges();
+            }
+            catch (Exception ex)
+            {
+                function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "实时统计交易额日志RDS异常");
+            }
+            db.Dispose();
+            function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "实时统计交易额日志RDS");
+        }
+
+    }
+}

+ 16 - 0
AppStart/Helper/StatService.cs

@@ -84,6 +84,7 @@ namespace MySystem
                                 decimal TradeAmount = decimal.Parse(selfDr[11].ToString());
                                 int TradeCount = int.Parse(selfDr[12].ToString());
                                 string TradeMonth = TradeDate.Substring(0, 6);
+
                                 TradeDaySummary selfStat = db.TradeDaySummary.FirstOrDefault(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.TradeDate == TradeDate && m.BrandId == BrandId && m.QueryCount == QrPayFlag && m.VipFlag == VipFlag && m.PayType == PayType && m.SeoTitle == "self");
                                 if (selfStat == null)
                                 {
@@ -215,6 +216,21 @@ namespace MySystem
                                         }
                                     }
                                 }
+
+                                Dictionary<string, object> statData = new Dictionary<string, object>();
+                                statData.Add("UserId", UserId);
+                                statData.Add("BrandId", BrandId);
+                                statData.Add("BankCardType", BankCardType);
+                                statData.Add("QrPayFlag", QrPayFlag);
+                                statData.Add("MerHelpFlag", MerHelpFlag);
+                                statData.Add("Version", Version);
+                                statData.Add("CapFlag", CapFlag);
+                                statData.Add("VipFlag", VipFlag);
+                                statData.Add("PayType", PayType);
+                                statData.Add("TradeDate", TradeDate);
+                                statData.Add("TradeAmount", TradeAmount);
+                                statData.Add("TradeCount", TradeCount);
+                                RedisDbconn.Instance.AddList("StatTradeAmountQueue", Newtonsoft.Json.JsonConvert.SerializeObject(statData));
                             }
                             OtherMySqlConn.op("update TradeRecord set QueryCount=1 where Id in (" + ids.TrimEnd(',') + ")");
                             function.WritePage("/TradeRecord/", "Id.txt", startId);

+ 313 - 0
AppStart/RedisDbconn.cs

@@ -0,0 +1,313 @@
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using CSRedis;
+using Library;
+using System.Linq;
+
+namespace MySystem
+{
+    public class RedisDbconn
+    {
+        public readonly static RedisDbconn Instance = new RedisDbconn();
+        public static CSRedis.CSRedisClient csredis;
+        private RedisDbconn()
+        {
+            if (csredis == null)
+            {
+                csredis = new CSRedis.CSRedisClient(ConfigurationManager.AppSettings["RedisConnStr"].ToString());
+            }
+        }
+
+        #region 设置单个字段
+        public bool Set(string key, object value, int sec = -1)
+        {
+            return csredis.Set(key, value, sec);
+            // return false;
+        }
+        #endregion
+
+        #region 整数累加
+        public long AddInt(string key, long value = 1)
+        {
+            return csredis.IncrBy(key, value);
+            // return 0;
+        }
+        #endregion
+
+        #region 数字累加
+        public decimal AddNumber(string key, decimal value = 1)
+        {
+            return csredis.IncrByFloat(key, value);
+            // return 0;
+        }
+        #endregion
+
+        #region 获取单个字段
+        public T Get<T>(string key)
+        {
+            return csredis.Get<T>(key);
+        }
+        #endregion
+
+        #region 设置散列字段
+        public bool HSet(string key, string field, object value)
+        {
+            return csredis.HSet(key, field, value);
+            // return false;
+        }
+        #endregion
+
+        #region 散列整数累加
+        public long HAddInt(string key, string field, long value = 1)
+        {
+            return csredis.HIncrBy(key, field, value);
+            // return 0;
+        }
+        #endregion
+
+        #region 散列数字累加
+        public decimal HAddNumber(string key, string field, decimal value = 1)
+        {
+            return csredis.HIncrByFloat(key, field, value);
+            // return 0;
+        }
+        #endregion
+
+        #region 获取散列元素
+        public T HGet<T>(string key, string field)
+        {
+            return csredis.HGet<T>(key, field);
+        }
+        #endregion
+
+        #region 获取散列所有元素
+        public Dictionary<string, T> HGetAll<T>(string key)
+        {
+            return csredis.HGetAll<T>(key);
+        }
+        #endregion
+
+        #region 添加列表对象
+        public long AddList(string key, object value)
+        {
+            return csredis.LPush(key, value);
+            // return 0;
+        }
+        public long AddList(string key, object[] value)
+        {
+            return csredis.LPush(key, value);
+            // return 0;
+        }
+        public long AddRightList(string key, object value)
+        {
+            return csredis.RPush(key, value);
+            // return 0;
+        }
+        public T RPop<T>(string key)
+        {
+            return csredis.RPop<T>(key);
+        }
+        #endregion
+
+        #region 添加集合对象
+        public long SAdd(string key, object value)
+        {
+            return csredis.SAdd(key, value);
+            // return 0;
+        }
+        public long SAdd(string key, object[] value)
+        {
+            return csredis.SAdd(key, value);
+            // return 0;
+        }
+        #endregion
+
+        #region 获取集合对象
+        public T[] SGetList<T>(string key)
+        {
+            return csredis.SMembers<T>(key);
+        }
+        #endregion
+
+        #region 判断元素是否存在
+        public bool SIsMember(string key, object value)
+        {
+            return csredis.SIsMember(key, value);
+        }
+        #endregion
+
+        #region 修改列表对象
+        public bool SetList(string key, int index, object value)
+        {
+            long itemindex = csredis.LLen(key) - index - 1;
+            return csredis.LSet(key, itemindex, value);
+            // return false;
+        }
+        #endregion
+
+        #region 获取列表
+        public List<T> GetList<T>(string key, int pageNum = 1, int pageSize = 10)
+        {
+            int start = (pageNum - 1) * pageSize;
+            int end = start + pageSize - 1;
+            T[] list = csredis.LRange<T>(key, start, end);
+            return list.ToList();
+        }
+        #endregion
+
+        #region 添加排序列表对象
+        public long AddSort(string key, object value, decimal score)
+        {
+            return csredis.ZAdd(key, (score, value));
+            // return 0;
+        }
+        #endregion
+
+        #region 获取排序列表
+        public List<T> GetSort<T>(string key, int pageNum = 1, int pageSize = 10)
+        {
+            int start = (pageNum - 1) * pageSize;
+            int end = start + pageSize;
+            string[] list = csredis.ZRangeByScore(key, start, end);
+            List<T> lists = new List<T>();
+            foreach (string record in list)
+            {
+                lists.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<T>(record));
+            }
+            return lists;
+        }
+        public List<T> GetSortDesc<T>(string key, int pageNum = 1, int pageSize = 10)
+        {
+            int start = (pageNum - 1) * pageSize;
+            int end = start + pageSize;
+            string[] list = csredis.ZRevRangeByScore(key, start, end);
+            List<T> lists = new List<T>();
+            foreach (string record in list)
+            {
+                lists.Add(Newtonsoft.Json.JsonConvert.DeserializeObject<T>(record));
+            }
+            return lists;
+        }
+        #endregion
+
+        public bool Remove(string key, long start, long end)
+        {
+            return csredis.LTrim(key, start, end);
+        }
+
+        public bool RemoveTop(string key, long count)
+        {
+            return RedisDbconn.Instance.Remove(key, count, RedisDbconn.Instance.Count(key) - 1); ;
+        }
+
+        public long Count(string key)
+        {
+            return csredis.LLen(key);
+        }
+
+        public void Clear(string pattern)
+        {
+            string[] keys = csredis.Keys(pattern);
+            csredis.Del(keys);
+        }
+
+        public string[] GetKeys(string pattern)
+        {
+            string[] keys = csredis.Keys(pattern);
+            return keys;
+        }
+
+        public bool Exists(string key)
+        {
+            return csredis.Exists(key);
+        }
+
+        public bool HExists(string key, string field)
+        {
+            return csredis.HExists(key, field);
+        }        
+
+        public void SetExpire(string key, int expire)
+        {
+            csredis.Expire(key, expire); //秒为单位
+        }
+
+
+
+
+        /// <summary>
+        /// 锁key
+        /// </summary>
+        private readonly string lockKey = "RedisLock";
+        /// <summary>
+        /// 锁的过期秒数
+        /// </summary>
+        private readonly int lockTime = 20;
+        /// <summary>
+        /// 续命线程取消令牌
+        /// </summary>
+        private CancellationTokenSource tokenSource = new CancellationTokenSource();
+
+        /// <summary>
+        /// 获取锁
+        /// </summary>
+        /// <param name="requestId">请求id保证释放锁时的客户端和加锁的客户端一致</param>
+        /// <returns></returns>
+        public bool GetLock(string requestId)
+        {
+            //设置key 设置过期时间20s
+            while (true)
+            {
+                //设置key Redis2.6.12以上版本,可以用set获取锁。set可以实现setnx和expire,这个是原子操作
+                if (csredis.Set(lockKey, requestId, lockTime, RedisExistence.Nx))
+                {
+                    //设置成功后开启子线程为key续命
+                    CreateThredXm();
+                    return true;
+                }
+            }
+        }
+        /// <summary>
+        /// 为锁续命(防止业务操作时间大于锁自动释放时间,锁被自动释放掉)
+        /// </summary>
+        void CreateThredXm()
+        {
+            Task.Run(() =>
+            {
+                while (true)
+                {
+                    Thread.Sleep(10);
+                    //外部取消 退出子线程
+                    if (tokenSource.IsCancellationRequested)
+                    {
+                        return;
+                    }
+                    //查询key还有多少秒释放
+                    var Seconds = csredis.PTtl(lockKey) / 1000;
+                    //key还剩1/3秒时重设过期时间
+                    if (Seconds < (lockTime / 3))
+                    {
+                        //小于5秒则自动 重设过期时间
+                        csredis.Expire(lockKey, lockTime);
+                    }
+                }
+            }, tokenSource.Token);
+        }
+        /// <summary>
+        /// 释放锁操作
+        /// </summary>
+        /// <param name="requestId">请求id保证释放锁时的客户端和加锁的客户端一致</param>
+        public void ReleaseLock(string requestId)
+        {
+            //这里使用Lua脚本保证原子性操作
+            string script = "if  redis.call('get', KEYS[1]) == ARGV[1] then " +
+                    "return redis.call('del', KEYS[1]) " +
+                    "else return 0 end";
+            csredis.Eval(script, lockKey, requestId);
+            //取消续命线程
+            tokenSource.Cancel();
+        }
+    }
+}

+ 93 - 0
Config/Base.cs

@@ -0,0 +1,93 @@
+using System.Collections.Generic;
+using Library;
+
+namespace AppConfig
+{
+    public class Base
+    {
+        public static string StatSqlConn = Library.ConfigurationManager.AppSettings["StatSqlConnStr"].ToString();
+
+        public static string CreateTradeDaySummary = "SET NAMES utf8mb4;" +
+                                                    "SET FOREIGN_KEY_CHECKS = 0;" +
+                                                    "CREATE TABLE `TradeDaySummary#DateTime#` (" +
+                                                    "`Id` int(11) NOT NULL AUTO_INCREMENT," +
+                                                    "`Sort` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`QueryCount` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`Status` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`Version` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`CreateDate` datetime DEFAULT NULL," +
+                                                    "`UpdateDate` datetime DEFAULT NULL," +
+                                                    "`CreateMan` varchar(50) DEFAULT NULL," +
+                                                    "`UpdateMan` varchar(50) DEFAULT NULL," +
+                                                    "`SeoTitle` varchar(100) DEFAULT NULL," +
+                                                    "`SeoKeyword` varchar(200) DEFAULT NULL," +
+                                                    "`SeoDescription` varchar(500) DEFAULT NULL," +
+                                                    "`TopUserId` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`HelpNonDirectNonQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectNonQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectDebitCapNum` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectDebitCapTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectDebitCapNum` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectDebitCapTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectNonQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectNonQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpNonDirectTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`HelpDirectTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectNonQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectNonQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectDebitCapNum` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`NotHelpNonDirectDebitCapTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectDebitCapNum` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`NotHelpDirectDebitCapTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectNonQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectNonQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpNonDirectTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`NotHelpDirectTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`MgrName` varchar(32) DEFAULT NULL," +
+                                                    "`MgrNo` varchar(16) DEFAULT NULL," +
+                                                    "`BrandId` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`TradeMonth` varchar(6) DEFAULT NULL," +
+                                                    "`TradeDate` varchar(8) DEFAULT NULL," +
+                                                    "`UserId` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`PayType` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`VipFlag` int(11) NOT NULL DEFAULT '0'," +
+                                                    "`ProfitNonDirectNonQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectNonQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectQrDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectDebitCapNum` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectDebitCapTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectDebitCapNum` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectDebitCapTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectDebitTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectNonQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectNonQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectQrCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectCreditTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitNonDirectTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "`ProfitDirectTradeAmt` decimal(18,2) NOT NULL DEFAULT '0.00'," +
+                                                    "PRIMARY KEY (`Id`) USING BTREE," +
+                                                    "KEY `TradeDaySummaryIndex` (`UserId`,`TradeMonth`,`TradeDate`,`BrandId`,`QueryCount`,`VipFlag`,`PayType`,`SeoTitle`)" +
+                                                    ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;" +
+                                                    "SET FOREIGN_KEY_CHECKS = 1;";
+    }
+}

+ 2 - 0
Startup.cs

@@ -125,6 +125,8 @@ namespace MySystem
             OperateService.Instance.Start(); //统计运营中心发货量
             OperateService.Instance.StartPosActNum(); //统计运营中心激活量
             OperateService.Instance.StartPosCouponSaleNum(); //统计运营中心机具券销售量
+            
+            StatNewService.Instance.StartStat(); //实时统计交易额RDS
             //必须打开的
 
         }

+ 1 - 0
appsettings.Development.json

@@ -19,6 +19,7 @@
     "Database": "KxsMainServer",
     "SqlConnStr": "server=47.109.31.237;port=3306;user=KxsMainServer2;password=FrW8ZfxlcaVdm1r0;database=KxsMainServer2;charset=utf8;",
     "OpSqlConnStr": "server=47.109.31.237;port=3306;user=KxsOpServer;password=r7jwZ8ydLoeswDR4;database=KxsOpServer;charset=utf8;",
+    "RedisConnStr": "47.109.31.237:6379,password=klm@redis,DefaultDatabase=2,poolsize=500,preheat=50,asyncPipeline=true",
     "IOSAppVersion": "1.0.0",
     "AndroidAppVersion": "1.0.0",
     "OSSKey": "iL9dWgBunZRwGbHQ",

+ 2 - 0
appsettings.json

@@ -19,6 +19,8 @@
     "Database": "KxsMainServer",
     "SqlConnStr": "server=47.108.231.170;port=3306;user=KxsMain;password=mzeqjriUWore0dwT;database=KxsMainServer;charset=utf8;",
     "OpSqlConnStr": "server=47.108.231.170;port=3306;user=KxsOpServer;password=r7jwZ8ydLoeswDR4;database=KxsOpServer;charset=utf8;",
+    "StatSqlConnStr": "server=rm-2vc27k81v217qs1t55o.mysql.cn-chengdu.rds.aliyuncs.com;port=3306;user=KxsStatServer;password=mzeqjriUWore0dwT;database=KxsStatServer;charset=utf8;",
+    "RedisConnStr": "47.108.207.184:6379,password=skb@redis2022,DefaultDatabase=2,poolsize=500,preheat=50,asyncPipeline=true",
     "IOSAppVersion": "1.0.0",
     "AndroidAppVersion": "1.0.0",
     "OSSKey": "iL9dWgBunZRwGbHQ",