123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- using System;
- using System.Collections.Generic;
- using Library;
- using System.Linq;
- using MySystem.MainModels;
- namespace MySystem
- {
- public class BusinessTradeSummaryDbconn
- {
- public readonly static BusinessTradeSummaryDbconn Instance = new BusinessTradeSummaryDbconn();
- public BusinessTradeSummaryDbconn()
- { }
- // TODO:读取很慢,感觉redis没生效
- #region 获取单个字段
- //个人业绩
- public decimal GetTrade(int UserId, int IsLeader)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- public decimal GetDateTrade(int UserId, int IsLeader, string TradeDate)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeDate);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.TradeDate == TradeDate);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- public decimal GetMonthTrade(int UserId, int IsLeader, string TradeMonth)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- public decimal GetDateTradeForBrand(int UserId, int IsLeader, string TradeDate, int BrandId)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- public decimal GetMonthTradeForBrand(int UserId, int IsLeader, string TradeMonth, int BrandId)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- //贷记卡/借记卡
- public decimal GetDateTradeForCloud(int UserId, int IsLeader, string TradeDate, int QrPayFlag, int BankCardType)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate);
- if (check)
- {
- if (BankCardType == 0)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate).Sum(m => m.HelpDirectDebitTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- else
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.NotHelpDirectTradeAmt);
- }
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate);
- if (check)
- {
- if (BankCardType == 0)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate).Sum(m => m.HelpDirectDebitTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- else
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.NotHelpDirectTradeAmt);
- }
- }
- }
- db.Dispose();
- return amt;
- }
- //云闪付
- public decimal GetDateTradeForCloud(int UserId, int IsLeader, string TradeDate, int QrPayFlag)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeDate == TradeDate).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- //云闪付
- public decimal GetMonthTradeForCloud(int UserId, int IsLeader, string TradeMonth, int QrPayFlag)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- //贷记卡/借记卡
- public decimal GetMonthTradeForCloud(int UserId, int IsLeader, string TradeMonth, int QrPayFlag, int BankCardType)
- {
- decimal amt = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.UserId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- bool check = db.BusinessTradeSummary.Any(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth);
- if (check)
- {
- amt = db.BusinessTradeSummary.Where(m => m.PartnerId == UserId && m.QueryCount == QrPayFlag && m.TradeMonth == TradeMonth).Sum(m => m.HelpDirectTradeAmt + m.HelpDirectDebitTradeAmt + m.NotHelpDirectTradeAmt + m.NotHelpDirectDebitTradeAmt);
- }
- }
- db.Dispose();
- return amt;
- }
- public int GetActCount(int UserId, int IsLeader, string TradeMonthOrDate = "")
- {
- int MakerCount = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- if (string.IsNullOrEmpty(TradeMonthOrDate))
- {
- bool check = db.BusinessActSummary.Any(m => m.UserId == UserId);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.UserId == UserId).Sum(m => m.ActCount);
- }
- }
- else
- {
- if (TradeMonthOrDate.Length == 8)
- {
- bool check = db.BusinessActSummary.Any(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.UserId == UserId && m.TradeDate == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- else
- {
- bool check = db.BusinessActSummary.Any(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- if (string.IsNullOrEmpty(TradeMonthOrDate))
- {
- bool check = db.BusinessActSummary.Any(m => m.PartnerId == UserId);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.PartnerId == UserId).Sum(m => m.ActCount);
- }
- }
- else
- {
- if (TradeMonthOrDate.Length == 8)
- {
- bool check = db.BusinessActSummary.Any(m => m.PartnerId == UserId && m.TradeDate == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.PartnerId == UserId && m.TradeDate == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- else
- {
- bool check = db.BusinessActSummary.Any(m => m.PartnerId == UserId && m.TradeMonth == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.PartnerId == UserId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- }
- }
- db.Dispose();
- return MakerCount;
- }
- public int GetBrandActCount(int UserId, int IsLeader, int BrandId, string TradeMonthOrDate = "")
- {
- int MakerCount = 0;
- WebCMSEntities db = new WebCMSEntities();
- //主账号
- if (IsLeader == 1)
- {
- if (TradeMonthOrDate.Length == 8)
- {
- bool check = db.BusinessActSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeDate == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- else
- {
- bool check = db.BusinessActSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- }
- //子账号
- if (IsLeader == 0)
- {
- if (TradeMonthOrDate.Length == 8)
- {
- bool check = db.BusinessActSummary.Any(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeDate == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeDate == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- else
- {
- bool check = db.BusinessActSummary.Any(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate);
- if (check)
- {
- MakerCount = db.BusinessActSummary.Where(m => m.PartnerId == UserId && m.BrandId == BrandId && m.TradeMonth == TradeMonthOrDate).Sum(m => m.ActCount);
- }
- }
- }
- db.Dispose();
- return MakerCount;
- }
- //激活机具数
- public int GetCount(int UserId, int BrandId)
- {
- int ActCount = 0;
- WebCMSEntities db = new WebCMSEntities();
- bool check = db.UserTradeMonthSummary.Any(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoTitle == "self");
- if (check)
- {
- ActCount = db.UserTradeMonthSummary.Where(m => m.UserId == UserId && m.BrandId == BrandId && m.SeoTitle == "self").Sum(m => m.ActiveBuddyMerStatus);
- }
- db.Dispose();
- return ActCount;
- }
- #endregion
- }
- }
|