| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- 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)
- {
- WebCMSEntities db = new WebCMSEntities();
- UserData userData = db.UserData.FirstOrDefault(m => m.UserId == Id);
- if (userData != null)
- {
- }
- 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;
- 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 GetSelfBrandPosActCount(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 == "self");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoKeyword == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- else
- {
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self");
- if (check)
- {
- MakerCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
- }
- }
- db.Dispose();
- return MakerCount;
- }
- public int GetTeamPosActCount(int UserId, string TradeMonthOrDate = "")
- {
- int MakerCount = 0;
- 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;
- }
- /// <summary>
- /// 获取来客吧区域代理交易额
- /// </summary>
- /// <param name="UserId">创客Id</param>
- /// <param name="TradeMonthOrDate">统计时间</param>
- /// <returns></returns>
- public decimal GetMpAgentTradeAmount(int UserId, string TradeMonthOrDate = "")
- {
- decimal TradeAmount = 0.00M;
- MpMainModels.WebCMSEntities mpdb = new MpMainModels.WebCMSEntities();
- MpMainModels2.WebCMSEntities mpdb2 = new MpMainModels2.WebCMSEntities();
- if (TradeMonthOrDate.Length == 8)
- {
- bool check = mpdb.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate);
- bool check2 = mpdb2.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate);
- if (check)
- {
- TradeAmount = mpdb.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate).Sum(m => m.TotalAmount);
- }
- if (check2)
- {
- TradeAmount += mpdb2.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.TotalAmount);
- }
- }
- else
- {
- bool check = mpdb.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate);
- bool check2 = mpdb2.AgentTradeStatSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate);
- if (check)
- {
- TradeAmount = mpdb.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.TotalAmount);
- }
- if (check2)
- {
- TradeAmount += mpdb2.AgentTradeStatSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.TotalAmount);
- }
- }
- mpdb.Dispose();
- mpdb2.Dispose();
- return TradeAmount;
- }
- #endregion
- }
- }
|