123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240 |
- using System;
- using System.Collections.Generic;
- using Library;
- using System.Linq;
- using System.Data;
- using MySystem.MainModels;
- namespace MySystem
- {
- public class UserDataDbconn
- {
- public readonly static UserDataDbconn Instance = new UserDataDbconn();
- #region 获取单个字段
- public UserData Get(int Id)
- {
- // string key = "UserData:" + Id;
- // if (RedisDbconn.Instance.Exists(key))
- // {
- // UserData obj = RedisDbconn.Instance.Get<UserData>(key);
- // if (obj != null)
- // {
- // return obj;
- // }
- // }
- WebCMSEntities db = new WebCMSEntities();
- UserData userData = db.UserData.FirstOrDefault(m => m.UserId == Id);
- if (userData != null)
- {
- // RedisDbconn.Instance.Set(key, userData);
- // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
- }
- return userData;
- }
- public int GetSelfMakerCount(int Id)
- {
- string key = "MakerCount:" + Id;
- if (RedisDbconn.Instance.Exists(key))
- {
- int obj = RedisDbconn.Instance.Get<int>(key);
- return obj;
- }
- WebCMSEntities db = new WebCMSEntities();
- UserData userData = db.UserData.FirstOrDefault(m => m.UserId == Id);
- if (userData != null)
- {
- RedisDbconn.Instance.Set(key, userData.FansCount);
- RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
- }
- return 0;
- }
- public int GetTeamMakerCount(int Id)
- {
- string key = "TeamMakerCount:" + Id;
- if (RedisDbconn.Instance.Exists(key))
- {
- int obj = RedisDbconn.Instance.Get<int>(key);
- return obj;
- }
- WebCMSEntities db = new WebCMSEntities();
- string IdString = "," + Id + ",";
- int MakerCount = db.Users.Count(m => m.ParentNav.Contains(IdString) && m.AuthFlag == 1);
- RedisDbconn.Instance.Set(key, MakerCount);
- RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
- return MakerCount;
- }
- public int GetSelfMakerCountForMonth(int Id, string TradeMonth)
- {
- string key = "AddMakerCount:" + Id + ":" + TradeMonth;
- if (RedisDbconn.Instance.Exists(key))
- {
- int obj = RedisDbconn.Instance.Get<int>(key);
- return obj;
- }
- DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
- DateTime end = start.AddMonths(1);
- WebCMSEntities db = new WebCMSEntities();
- int MakerCount = db.Users.Count(m => m.ParentUserId == Id && m.AuthDate >= start && m.AuthDate < end);
- RedisDbconn.Instance.Set(key, MakerCount);
- RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
- return MakerCount;
- }
- public int GetTeamMakerCountForMonth(int Id, string TradeMonth)
- {
- string key = "TeamAddMakerCount:" + Id + ":" + TradeMonth;
- if (RedisDbconn.Instance.Exists(key))
- {
- int obj = RedisDbconn.Instance.Get<int>(key);
- return obj;
- }
- DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
- DateTime end = start.AddMonths(1);
- WebCMSEntities db = new WebCMSEntities();
- string IdString = "," + Id + ",";
- int MakerCount = db.Users.Count(m => m.ParentNav.Contains(IdString) && m.AuthDate >= start && m.AuthDate < end);
- RedisDbconn.Instance.Set(key, MakerCount);
- RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
- return MakerCount;
- }
- public int GetPosActCount(int UserId, string TradeMonthOrDate = "")
- {
- int MakerCount = 0;
- // string key = "TotalPosMerchant:" + Id;
- // if (RedisDbconn.Instance.Exists(key))
- // {
- // int obj = RedisDbconn.Instance.Get<int>(key);
- // return obj;
- // }
- // WebCMSEntities db = new WebCMSEntities();
- // string condi = "";
- // if (!string.IsNullOrEmpty(TradeMonth))
- // {
- // string start = TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00";
- // string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
- // condi += " and ActivationTime>='" + start + "' and ActivationTime<'" + end + "'";
- // }
- // OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- // DataTable dt = OtherMySqlConn.dtable("select count(Id) from PosMachinesTwo where BuyUserId=" + Id + " and ActivationState=1 and UserId>0" + condi);
- // if (dt.Rows.Count > 0)
- // {
- // MakerCount = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
- // }
- // RedisDbconn.Instance.Set(key, MakerCount);
- // OtherMySqlConn.connstr = "";
- WebCMSEntities db = new WebCMSEntities();
- if(string.IsNullOrEmpty(TradeMonthOrDate))
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoTitle == "self");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- else
- {
- if(TradeMonthOrDate.Length == 8)
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- else
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- }
- return MakerCount;
- }
- public int GetTeamPosActCount(int UserId, string TradeMonthOrDate = "")
- {
- int MakerCount = 0;
- // string key = "TeamTotalPosMerchant:" + Id;
- // if (RedisDbconn.Instance.Exists(key))
- // {
- // int obj = RedisDbconn.Instance.Get<int>(key);
- // return obj;
- // }
- // WebCMSEntities db = new WebCMSEntities();
- // string condi = "";
- // if (!string.IsNullOrEmpty(TradeMonth))
- // {
- // string start = TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00";
- // string end = DateTime.Parse(start).AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
- // condi += " and ActivationTime>='" + start + "' and ActivationTime<'" + end + "'";
- // }
- // OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString();
- // DataTable dt = OtherMySqlConn.dtable("select count(Id) from PosMachinesTwo where BuyUserId in (select Id from Users where ParentNav like '%," + Id + ",%' or Id=" + Id + ") and ActivationState=1 and UserId>0" + condi);
- // if (dt.Rows.Count > 0)
- // {
- // MakerCount = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
- // }
- // RedisDbconn.Instance.Set(key, MakerCount);
- // OtherMySqlConn.connstr = "";
- WebCMSEntities db = new WebCMSEntities();
- if(string.IsNullOrEmpty(TradeMonthOrDate))
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoTitle == "team");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- else
- {
- if(TradeMonthOrDate.Length == 8)
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- else
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- }
- db.Dispose();
- return MakerCount;
- }
- public int GetTeamBrandPosActCount(int UserId, int BrandId, string TradeMonthOrDate = "")
- {
- int MakerCount = 0;
- WebCMSEntities db = new WebCMSEntities();
- if(TradeMonthOrDate.Length == 8)
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- else
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "team").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- db.Dispose();
- return MakerCount;
- }
- #endregion
- }
- }
|