using System; using System.Collections.Generic; using System.Linq; using MySystem.PxcModels; namespace MySystem { public class Utils { public readonly static Utils Instance = new Utils(); private Utils() { } /// /// 操作收支明细 /// /// /// /// public void OpAccount(int UserId, decimal Money, int ChangeType, bool IsTotal = true) { WebCMSEntities db = new WebCMSEntities(); UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId); if (account == null) { account = db.UserAccount.Add(new UserAccount() { Id = UserId, UserId = UserId, }).Entity; db.SaveChanges(); } decimal BeforeTotalAmount = account.TotalAmount; //变更前总金额 decimal BeforeFreezeAmount = account.FreezeAmount; //变更前冻结金额 decimal BeforeBalanceAmount = account.BalanceAmount; //变更前余额 account.BalanceAmount += Money; if(IsTotal) { account.TotalAmount += Money; } decimal AfterTotalAmount = account.TotalAmount; //变更后总金额 decimal AfterFreezeAmount = account.FreezeAmount; //变更后冻结金额 decimal AfterBalanceAmount = account.BalanceAmount; //变更后余额 UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord() { CreateDate = DateTime.Now, UpdateDate = DateTime.Now, UserId = UserId, //创客 ChangeType = ChangeType, //变动类型 ChangeAmount = Money, //变更金额 BeforeTotalAmount = BeforeTotalAmount, //变更前总金额 AfterTotalAmount = AfterTotalAmount, //变更后总金额 BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额 AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额 BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额 AfterBalanceAmount = AfterBalanceAmount, //变更后余额 }).Entity; db.SaveChanges(); db.Dispose(); } public void ToChargeAmount(int UserId, decimal Money) { WebCMSEntities db = new WebCMSEntities(); UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId); if (account == null) { account = db.UserAccount.Add(new UserAccount() { Id = UserId, UserId = UserId, }).Entity; db.SaveChanges(); } account.ToChargeAmount += Money; db.SaveChanges(); db.Dispose(); } } }