| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using Library;
- using System.Linq;
- using MySystem.MainModels;
- namespace MySystem
- {
- public class UserAccountDbconn
- {
- public readonly static UserAccountDbconn Instance = new UserAccountDbconn();
- #region 获取单个字段
- public UserAccount Get(int Id)
- {
- // string key = "UserAccount:" + Id;
- // if (RedisDbconn.Instance.Exists(key))
- // {
- // UserAccount obj = RedisDbconn.Instance.Get<UserAccount>(key);
- // if (obj != null)
- // {
- // return obj;
- // }
- // }
- WebCMSEntities db = new WebCMSEntities();
- UserAccount order = db.UserAccount.FirstOrDefault(m => m.Id == Id);
- if (order != null)
- {
- // RedisDbconn.Instance.Set(key, order);
- // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
- }
- db.Dispose();
- return order;
- }
- public decimal GetIncome(int Id, string TradeMonth)
- {
- string key = "UserAccount:Income:" + Id + ":" + TradeMonth;
- if (RedisDbconn.Instance.Exists(key))
- {
- decimal obj = RedisDbconn.Instance.Get<decimal>(key);
- return obj;
- }
- WebCMSEntities db = new WebCMSEntities();
- decimal result = 0;
- DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
- DateTime end = start.AddMonths(1);
- bool check = db.UserAccountRecord.Any(m => m.UserId == Id && m.CreateDate >= start && m.CreateDate < end && (m.ChangeType == 0 || m.ChangeType == 1 || m.ChangeType == 12 || m.ChangeType == 31 || m.ChangeType == 50 || m.ChangeType == 60 || m.ChangeType == 64 || m.ChangeType == 111 || m.ChangeType == 112 || m.ChangeType == 113 || m.ChangeType == 114 || m.ChangeType == 115 || m.ChangeType == 116 || m.ChangeType == 117 || m.ChangeType == 118 || m.ChangeType == 119));
- if (check)
- {
- result = db.UserAccountRecord.Where(m => m.UserId == Id && m.CreateDate >= start && m.CreateDate < end && (m.ChangeType == 0 || m.ChangeType == 1 || m.ChangeType == 12 || m.ChangeType == 31 || m.ChangeType == 50 || m.ChangeType == 60 || m.ChangeType == 64 || m.ChangeType == 111 || m.ChangeType == 112 || m.ChangeType == 113 || m.ChangeType == 114 || m.ChangeType == 115 || m.ChangeType == 116 || m.ChangeType == 117 || m.ChangeType == 118 || m.ChangeType == 119)).Sum(m => m.ChangeAmount);
- RedisDbconn.Instance.Set(key, result);
- RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(180, 300));
- }
- return result;
- }
- public decimal GetExpend(int Id, string TradeMonth)
- {
- string key = "UserAccount:Expend:" + Id + ":" + TradeMonth;
- if (RedisDbconn.Instance.Exists(key))
- {
- decimal obj = RedisDbconn.Instance.Get<decimal>(key);
- return obj;
- }
- decimal result = 0;
- WebCMSEntities db = new WebCMSEntities();
- DateTime start = DateTime.Parse(TradeMonth.Substring(0, 4) + "-" + TradeMonth.Substring(4, 2) + "-01 00:00:00");
- DateTime end = start.AddMonths(1);
- bool check = db.UserAccountRecord.Any(m => m.UserId == Id && m.CreateDate >= start && m.CreateDate < end && (m.ChangeType == 3 || m.ChangeType == 4 || m.ChangeType == 5 || m.ChangeType == 20 || m.ChangeType == 63));
- if (check)
- {
- result += db.UserAccountRecord.Where(m => m.UserId == Id && m.CreateDate >= start && m.CreateDate < end && (m.ChangeType == 3 || m.ChangeType == 4 || m.ChangeType == 5 || m.ChangeType == 20 || m.ChangeType == 63)).Sum(m => m.ChangeAmount);
- }
- DateTime checkTime = DateTime.Parse("2022-04-11 19:31:39");
- check = db.UserCashRecord.Any(m => m.UserId == Id && m.CreateDate < checkTime && m.CreateDate >= start && m.CreateDate < end && m.Status == 1);
- if (check)
- {
- result += db.UserCashRecord.Where(m => m.UserId == Id && m.CreateDate < checkTime && m.CreateDate >= start && m.CreateDate < end && m.Status == 1).Sum(m => m.TradeAmount);
- }
- RedisDbconn.Instance.Set(key, result);
- RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(180, 600));
- return result;
- }
- #endregion
- }
- }
|