123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System;
- using System.Collections.Generic;
- using Library;
- using System.Linq;
- using MySystem.MainModels;
- namespace MySystem
- {
- public class UserTradeStatDbconn
- {
- public readonly static UserTradeStatDbconn Instance = new UserTradeStatDbconn();
- public UserTradeStatDbconn()
- { }
- #region 获取单个字段
- //个人业绩
- public UserTradeData GetTradeByDate(int UserId, string TradeDate, string kind = "self")
- {
- string key = "UserTradeAmt:" + UserId + ":" + TradeDate + ":" + kind; //总交易
- if (kind == "team")
- {
- key = "Team" + key;
- }
- UserTradeData obj = RedisDbconn.Instance.Get<UserTradeData>(key);
- if (obj != null)
- {
- return obj;
- }
- obj = new UserTradeData();
- WebCMSEntities db = new WebCMSEntities();
- bool check = db.UserTradeDaySummary.Any(m => m.UserId == UserId && m.SeoTitle == kind);
- if (check)
- {
- List<UserTradeDaySummary> data = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeDate == TradeDate && m.SeoTitle == kind).ToList();
- if (kind == "self")
- {
- obj.TotalAmt = data.Sum(m => m.DirectTradeAmt + m.DirectDebitTradeAmt);
- if (data.Where(m => m.QueryCount == 0).Count() > 0)
- {
- obj.PosAmt = data.Where(m => m.QueryCount == 0).Sum(m => m.DirectTradeAmt + m.DirectDebitTradeAmt);
- }
- else if (data.Where(m => m.QueryCount == 1).Count() > 0)
- {
- obj.QrAmt = data.Where(m => m.QueryCount == 1).Sum(m => m.DirectTradeAmt + m.DirectDebitTradeAmt);
- }
- obj.Brands = new List<Brand>();
- foreach (UserTradeDaySummary sub in data.OrderBy(m => m.BrandId).ToList())
- {
- if (obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId) == null)
- {
- obj.Brands.Add(new Brand()
- {
- Id = sub.BrandId,
- Amt = sub.DirectTradeAmt + sub.DirectDebitTradeAmt,
- });
- }
- else
- {
- obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId).Amt += sub.DirectTradeAmt + sub.DirectDebitTradeAmt;
- }
- }
- }
- else if (kind == "team")
- {
- obj.TotalAmt = data.Sum(m => m.NonDirectTradeAmt + m.NonDirectDebitTradeAmt);
- if (data.Where(m => m.QueryCount == 0).Count() > 0)
- {
- obj.PosAmt = data.Where(m => m.QueryCount == 0).Sum(m => m.NonDirectTradeAmt + m.NonDirectDebitTradeAmt);
- }
- else if (data.Where(m => m.QueryCount == 1).Count() > 0)
- {
- obj.QrAmt = data.Where(m => m.QueryCount == 1).Sum(m => m.NonDirectTradeAmt + m.NonDirectDebitTradeAmt);
- }
- obj.Brands = new List<Brand>();
- foreach (UserTradeDaySummary sub in data.OrderBy(m => m.BrandId).ToList())
- {
- if (obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId) == null)
- {
- obj.Brands.Add(new Brand()
- {
- Id = sub.BrandId,
- Amt = sub.NonDirectTradeAmt + sub.NonDirectDebitTradeAmt,
- });
- }
- else
- {
- obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId).Amt += sub.NonDirectTradeAmt + sub.NonDirectDebitTradeAmt;
- }
- }
- }
- }
- RedisDbconn.Instance.Set(key, obj);
- db.Dispose();
- return obj;
- }
- public UserTradeData GetTradeByMonth(int UserId, string TradeMonth, string kind = "self")
- {
- string key = "UserTradeAmt:" + UserId + ":" + TradeMonth + ":" + kind; //总交易
- if (kind == "team")
- {
- key = "Team" + key;
- }
- UserTradeData obj = RedisDbconn.Instance.Get<UserTradeData>(key);
- if (obj != null)
- {
- return obj;
- }
- obj = new UserTradeData();
- WebCMSEntities db = new WebCMSEntities();
- bool check = db.UserTradeDaySummary.Any(m => m.UserId == UserId && m.SeoTitle == kind);
- if (check)
- {
- List<UserTradeDaySummary> data = db.UserTradeDaySummary.Where(m => m.UserId == UserId && m.TradeMonth == TradeMonth && m.SeoTitle == kind).ToList();
- if (kind == "self")
- {
- obj.TotalAmt = data.Sum(m => m.DirectTradeAmt + m.DirectDebitTradeAmt);
- if (data.Where(m => m.QueryCount == 0).Count() > 0)
- {
- obj.PosAmt = data.Where(m => m.QueryCount == 0).Sum(m => m.DirectTradeAmt + m.DirectDebitTradeAmt);
- }
- else if (data.Where(m => m.QueryCount == 1).Count() > 0)
- {
- obj.QrAmt = data.Where(m => m.QueryCount == 1).Sum(m => m.DirectTradeAmt + m.DirectDebitTradeAmt);
- }
- obj.Brands = new List<Brand>();
- foreach (UserTradeDaySummary sub in data.OrderBy(m => m.BrandId).ToList())
- {
- if (obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId) == null)
- {
- obj.Brands.Add(new Brand()
- {
- Id = sub.BrandId,
- Amt = sub.DirectTradeAmt + sub.DirectDebitTradeAmt,
- });
- }
- else
- {
- obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId).Amt += sub.DirectTradeAmt + sub.DirectDebitTradeAmt;
- }
- }
- }
- else if (kind == "team")
- {
- obj.TotalAmt = data.Sum(m => m.NonDirectTradeAmt + m.NonDirectDebitTradeAmt);
- if (data.Where(m => m.QueryCount == 0).Count() > 0)
- {
- obj.PosAmt = data.Where(m => m.QueryCount == 0).Sum(m => m.NonDirectTradeAmt + m.NonDirectDebitTradeAmt);
- }
- else if (data.Where(m => m.QueryCount == 1).Count() > 0)
- {
- obj.QrAmt = data.Where(m => m.QueryCount == 1).Sum(m => m.NonDirectTradeAmt + m.NonDirectDebitTradeAmt);
- }
- obj.Brands = new List<Brand>();
- foreach (UserTradeDaySummary sub in data.OrderBy(m => m.BrandId).ToList())
- {
- if (obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId) == null)
- {
- obj.Brands.Add(new Brand()
- {
- Id = sub.BrandId,
- Amt = sub.NonDirectTradeAmt + sub.NonDirectDebitTradeAmt,
- });
- }
- else
- {
- obj.Brands.FirstOrDefault(m => m.Id == sub.BrandId).Amt += sub.NonDirectTradeAmt + sub.NonDirectDebitTradeAmt;
- }
- }
- }
- }
- RedisDbconn.Instance.Set(key, obj);
- db.Dispose();
- return obj;
- }
-
- #endregion
- }
- }
|