using System; using System.Collections.Generic; using Library; using System.Linq; using MySystem.MainModels; namespace MySystem { public class UserTradeDaySummaryDbconn { public readonly static UserTradeDaySummaryDbconn Instance = new UserTradeDaySummaryDbconn(); public UserTradeDaySummaryDbconn() { } // TODO:读取很慢,感觉redis没生效 #region 获取单个字段 //个人业绩 public decimal GetTrade(int UserId, string kind = "self") { // string key = "TotalAmount:" + UserId; //总交易 // if (kind == "team") // { // key = "Team" + key; // } // string obj = RedisDbconn.Instance.Get(key); // if (!string.IsNullOrEmpty(obj)) // { // return decimal.Parse(function.CheckNum(obj)); // } decimal amt = 0; WebCMSEntities db = new WebCMSEntities(); bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.SeoTitle == kind); if (check) { if (kind == "self") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt); } else if (kind == "team") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt); } } // RedisDbconn.Instance.Set(key, amt); db.Dispose(); return amt; } public decimal GetDateTrade(int UserId, string TradeDate, string kind = "self") { // if (UserId == 598) // { // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).TotalAmt; // } // string key = "TotalAmount:" + UserId + ":" + TradeDate; //总交易 // if (kind == "team") // { // key = "Team" + key; // } // string obj = RedisDbconn.Instance.Get(key); // if (!string.IsNullOrEmpty(obj)) // { // return decimal.Parse(function.CheckNum(obj)); // } decimal amt = 0; WebCMSEntities db = new WebCMSEntities(); bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind); if (check) { if (kind == "self") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt); } else if (kind == "team") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt); } } // RedisDbconn.Instance.Set(key, amt); db.Dispose(); return amt; } public decimal GetMonthTrade(int UserId, string TradeMonth, string kind = "self") { // if (UserId == 598) // { // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).TotalAmt; // } // string key = "TotalAmount:" + UserId + ":" + TradeMonth; //总交易 // if (kind == "team") // { // key = "Team" + key; // } // string obj = RedisDbconn.Instance.Get(key); // if (!string.IsNullOrEmpty(obj)) // { // return decimal.Parse(function.CheckNum(obj)); // } decimal amt = 0; WebCMSEntities db = new WebCMSEntities(); bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind); if (check) { if (kind == "self") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt); } else if (kind == "team") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt); } } // RedisDbconn.Instance.Set(key, amt); db.Dispose(); return amt; } public decimal GetDateTradeForBrand(int UserId, string TradeDate, int BrandId, string kind = "self") { // if (UserId == 598) // { // var item = UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).Brands.FirstOrDefault(m => m.Id == BrandId); // if (item != null) // { // return item.Amt; // } // return 0; // } // string key = "TotalAmount:" + UserId + ":" + BrandId + ":" + TradeDate; //总交易 // if (kind == "team") // { // key = "Team" + key; // } // string obj = RedisDbconn.Instance.Get(key); // if (!string.IsNullOrEmpty(obj)) // { // return decimal.Parse(function.CheckNum(obj)); // } decimal amt = 0; WebCMSEntities db = new WebCMSEntities(); bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m. SeoTitle == kind); if (check) { if (kind == "self") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt); } else if (kind == "team") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt); } } // RedisDbconn.Instance.Set(key, amt); db.Dispose(); return amt; } public decimal GetMonthTradeForBrand(int UserId, string TradeMonth, int BrandId, string kind = "self") { // if (UserId == 598) // { // var item = UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).Brands.FirstOrDefault(m => m.Id == BrandId); // if (item != null) // { // return item.Amt; // } // return 0; // } // string key = "TotalAmount:" + UserId + ":" + BrandId + ":" + TradeMonth; //总交易 // if (kind == "team") // { // key = "Team" + key; // } // string obj = RedisDbconn.Instance.Get(key); // if (!string.IsNullOrEmpty(obj)) // { // return decimal.Parse(function.CheckNum(obj)); // } decimal amt = 0; WebCMSEntities db = new WebCMSEntities(); bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind); if (check) { if (kind == "self") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt); } else if (kind == "team") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt); } } // RedisDbconn.Instance.Set(key, amt); db.Dispose(); return amt; } public decimal GetDateTradeForCloud(int UserId, string TradeDate, int QrPayFlag, string kind = "self") { // if (UserId == 598) // { // if (QrPayFlag == 1) // { // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).QrAmt; // } // else // { // return UserTradeStatDbconn.Instance.GetTradeByDate(UserId, TradeDate, kind).PosAmt; // } // } // string key = "TotalPosAmount:" + UserId + ":" + TradeDate; //总交易 // if (QrPayFlag == 1) // { // key = "TotalCloudPayAmount:" + UserId + ":" + TradeDate; //总交易 // } // if (kind == "team") // { // key = "Team" + key; // } // string obj = RedisDbconn.Instance.Get(key); // if (!string.IsNullOrEmpty(obj)) // { // return decimal.Parse(function.CheckNum(obj)); // } decimal amt = 0; WebCMSEntities db = new WebCMSEntities(); bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind); if (check) { if (kind == "self") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt); } else if (kind == "team") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt); } } // RedisDbconn.Instance.Set(key, amt); db.Dispose(); return amt; } public decimal GetMonthTradeForCloud(int UserId, string TradeMonth, int QrPayFlag, string kind = "self") { // if (UserId == 598) // { // if (QrPayFlag == 1) // { // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).QrAmt; // } // else // { // return UserTradeStatDbconn.Instance.GetTradeByMonth(UserId, TradeMonth, kind).PosAmt; // } // } // string key = "TotalPosAmount:" + UserId + ":" + TradeMonth; //总交易 // if (QrPayFlag == 1) // { // key = "TotalCloudPayAmount:" + UserId + ":" + TradeMonth; //总交易 // } // if (kind == "team") // { // key = "Team" + key; // } // string obj = RedisDbconn.Instance.Get(key); // if (!string.IsNullOrEmpty(obj)) // { // return decimal.Parse(function.CheckNum(obj)); // } decimal amt = 0; WebCMSEntities db = new WebCMSEntities(); bool check = db.TradeDaySummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m. SeoTitle == kind); if (check) { if (kind == "self") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt); } else if (kind == "team") { amt = db.TradeDaySummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth && m.SeoTitle == kind).Sum(m => m.HelpNonDirectTradeAmt + m.HelpNonDirectDebitTradeAmt + m.NotHelpNonDirectTradeAmt + m.NotHelpNonDirectDebitTradeAmt); } } // RedisDbconn.Instance.Set(key, amt); db.Dispose(); return amt; } #endregion } }