/// <summary> /// 保存系统用户结余金额 /// </summary> public void SaveUserBalanceLog(string saveDate) { var manager = new UserBalanceManager(); var old = manager.QueryUserBalanceReport(saveDate); if (old != null) { throw new Exception(string.Format("日期 {0} 的网站结余数据已生成。", saveDate)); } var userBalanceList = manager.QueryAllUserBalance(saveDate); var table = GetNewUserBalanceHistoryTable(); for (int i = 0; i < userBalanceList.Count; i++) { var current = userBalanceList[i]; DataRow r = table.NewRow(); //r["Id"] = i; r["SaveDateTime"] = saveDate; r["UserId"] = current.UserId; r["FillMoneyBalance"] = current.FillMoneyBalance; r["BonusBalance"] = current.BonusBalance; r["CommissionBalance"] = current.CommissionBalance; r["ExpertsBalance"] = current.ExpertsBalance; r["FreezeBalance"] = current.FreezeBalance; r["RedBagBalance"] = current.RedBagBalance; r["UserGrowth"] = current.UserGrowth; r["CurrentDouDou"] = current.CurrentDouDou; r["CreateTime"] = DateTime.Now; table.Rows.Add(r); } //批量插入表 new Sports_Manager().SqlBulkAddTable(table, "SaveDateTime", "UserId", "FillMoneyBalance", "BonusBalance", "CommissionBalance", "ExpertsBalance", "FreezeBalance", "RedBagBalance", "UserGrowth", "CurrentDouDou", "CreateTime"); var report = new GameBiz.Domain.Entities.UserBalanceReport { CreateTime = DateTime.Now, SaveDateTime = saveDate, TotalBonusBalance = userBalanceList.Sum(p => p.BonusBalance), TotalCommissionBalance = userBalanceList.Sum(p => p.CommissionBalance), TotalDouDou = userBalanceList.Sum(p => p.CurrentDouDou), TotalExpertsBalance = userBalanceList.Sum(p => p.ExpertsBalance), TotalFillMoneyBalance = userBalanceList.Sum(p => p.FillMoneyBalance), TotalFreezeBalance = userBalanceList.Sum(p => p.FreezeBalance), TotalRedBagBalance = userBalanceList.Sum(p => p.RedBagBalance), TotalUserGrowth = userBalanceList.Sum(p => p.UserGrowth), }; manager.AddUserBalanceReport(report); //缓存json文件 var balanceContent = JsonSerializer.Serialize <List <UserBalanceHistoryInfo> >(userBalanceList); var reportContent = JsonSerializer.Serialize <UserBalanceReport>(report); var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WebReports", DateTime.Now.ToString("yyyyMM")); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var balanceFilePath = Path.Combine(path, string.Format("balanceList_{0}.json", saveDate)); var reportFilePath = Path.Combine(path, string.Format("balanceReport_{0}.json", saveDate)); File.WriteAllText(balanceFilePath, balanceContent, Encoding.UTF8); File.WriteAllText(reportFilePath, reportContent, Encoding.UTF8); }