public bool AddStoneFactorySystemDailyProfit(StoneFactorySystemDailyProfit profit) { bool isOK = MyDBHelper.Instance.ConnectionCommandExecuteNonQuery(mycmd => { string sqlText = "insert into stonefactorysystemdailyprofit " + "(`profitRate`,`Day`) " + " values (@profitRate,@Day) "; mycmd.CommandText = sqlText; mycmd.Parameters.AddWithValue("@profitRate", profit.profitRate); mycmd.Parameters.AddWithValue("@Day", profit.Day.ToDateTime()); mycmd.ExecuteNonQuery(); }); return(isOK); }
private StoneFactorySystemDailyProfit LoadYesterdayFactoryProfitRate() { StoneFactorySystemDailyProfit profit = null; try { if (File.Exists(GlobalData.StoneFactoryYesterdayProfitRateConfigFile)) { using (FileStream stream = File.Open(GlobalData.StoneFactoryYesterdayProfitRateConfigFile, FileMode.Open)) { XmlDocument doc = new XmlDocument(); doc.Load(stream); XmlNode root = doc.SelectSingleNode("root"); if (root == null) { return(null); } XmlNode node = root.SelectSingleNode("Profit"); if (node == null) { return(null); } XmlNode nodeRate = node.SelectSingleNode("Rate"); if (nodeRate == null) { return(null); } XmlNode nodeDate = node.SelectSingleNode("Date"); if (nodeDate == null) { return(null); } profit = new StoneFactorySystemDailyProfit(); profit.profitRate = Convert.ToDecimal(nodeRate.InnerText); DateTime date = Convert.ToDateTime(nodeDate.InnerText); profit.Day = new MyDateTime(date); return(profit); } } return(null); } catch (Exception) { return(null); } }
public StoneFactorySystemDailyProfitUIModel(StoneFactorySystemDailyProfit parent) { this.ParentObject = parent; }
public void DailySetProfit() { try { lock (_lockDailySetProfit) { if ((DateTime.Now - _lastExeSetProfit).TotalHours < 20) { return; } _lastExeSetProfit = DateTime.Now; } decimal profitRate = StoneFactoryConfig.DailyMinProfit; StoneFactorySystemDailyProfit yesterdayProfit = LoadYesterdayFactoryProfitRate(); if (yesterdayProfit != null && yesterdayProfit.profitRate != 0 && (DateTime.Now.Date - yesterdayProfit.Day.ToDateTime().Date).Days == 0) { //如当天保存了收益率,则使用当天收益率,否则使用默认收益率。 profitRate = yesterdayProfit.profitRate; } DBProvider.PlayerStoneFactoryDBProvider.AddStoneFactorySystemDailyProfit(new StoneFactorySystemDailyProfit() { Day = new MyDateTime(DateTime.Now), profitRate = profitRate }); PlayerStoneFactoryAccountInfo[] listAllFactories = DBProvider.PlayerStoneFactoryDBProvider.GetAllPlayerStoneFactoryAccountInfos(); foreach (var factory in listAllFactories) { if (!factory.FactoryIsOpening || factory.FactoryLiveDays <= 0 || factory.LastDayValidStoneStack == 0) { continue; } PlayerInfo currentPlayer = DBProvider.UserDBProvider.GetPlayerByUserID(factory.UserID); PlayerInfo Level1ReferPlayerInfo = null; PlayerInfo Level2ReferPlayerInfo = null; PlayerInfo Level3ReferPlayerInfo = null; if (!string.IsNullOrEmpty(currentPlayer.SimpleInfo.ReferrerUserName)) { Level1ReferPlayerInfo = DBProvider.UserDBProvider.GetPlayerByUserName(currentPlayer.SimpleInfo.ReferrerUserName); if (Level1ReferPlayerInfo != null && !string.IsNullOrEmpty(Level1ReferPlayerInfo.SimpleInfo.ReferrerUserName)) { Level2ReferPlayerInfo = DBProvider.UserDBProvider.GetPlayerByUserName(Level1ReferPlayerInfo.SimpleInfo.ReferrerUserName); if (Level2ReferPlayerInfo != null && !string.IsNullOrEmpty(Level2ReferPlayerInfo.SimpleInfo.ReferrerUserName)) { Level3ReferPlayerInfo = DBProvider.UserDBProvider.GetPlayerByUserName(Level2ReferPlayerInfo.SimpleInfo.ReferrerUserName); } } } decimal profitRMB = factory.LastDayValidStoneStack * profitRate; MyDBHelper.Instance.TransactionDataBaseOper(myTrans => { bool isOK = DBProvider.PlayerStoneFactoryDBProvider.AddProfitRMBChangedRecord(new StoneFactoryProfitRMBChangedRecord() { UserID = factory.UserID, ProfitType = FactoryProfitOperType.FactoryOutput, OperRMB = profitRMB, ValidStoneCount = factory.LastDayValidStoneStack, OperTime = new MyDateTime(DateTime.Now) }, myTrans); if (!isOK) { return(OperResult.RESULTCODE_FALSE); } if (Level1ReferPlayerInfo != null) { var level1FactoryAccount = listAllFactories.FirstOrDefault(f => f.UserID == Level1ReferPlayerInfo.SimpleInfo.UserID); if (level1FactoryAccount != null && level1FactoryAccount.FactoryIsOpening && level1FactoryAccount.FactoryLiveDays > 0) { int minStoneStack = level1FactoryAccount.TotalStackCount < factory.TotalStackCount ? level1FactoryAccount.TotalStackCount : factory.TotalStackCount; if (minStoneStack != 0) { isOK = DBProvider.PlayerStoneFactoryDBProvider.AddProfitRMBChangedRecord(new StoneFactoryProfitRMBChangedRecord() { UserID = Level1ReferPlayerInfo.SimpleInfo.UserID, ProfitType = FactoryProfitOperType.Level1ReferenceAward, OperRMB = minStoneStack * profitRate * StoneFactoryConfig.FactoryOutputProfitAwardRMBConfig[0], OperTime = new MyDateTime(DateTime.Now) }, myTrans); if (!isOK) { return(OperResult.RESULTCODE_FALSE); } } } } if (Level2ReferPlayerInfo != null) { var level2FactoryAccount = listAllFactories.FirstOrDefault(f => f.UserID == Level2ReferPlayerInfo.SimpleInfo.UserID); if (level2FactoryAccount != null && level2FactoryAccount.FactoryIsOpening && level2FactoryAccount.FactoryLiveDays > 0) { int minStoneStack = level2FactoryAccount.TotalStackCount < factory.TotalStackCount ? level2FactoryAccount.TotalStackCount : factory.TotalStackCount; if (minStoneStack != 0) { isOK = DBProvider.PlayerStoneFactoryDBProvider.AddProfitRMBChangedRecord(new StoneFactoryProfitRMBChangedRecord() { UserID = Level2ReferPlayerInfo.SimpleInfo.UserID, ProfitType = FactoryProfitOperType.Level2ReferenceAward, OperRMB = minStoneStack * profitRate * StoneFactoryConfig.FactoryOutputProfitAwardRMBConfig[1], OperTime = new MyDateTime(DateTime.Now) }, myTrans); if (!isOK) { return(OperResult.RESULTCODE_FALSE); } } } } if (Level3ReferPlayerInfo != null) { var level3FactoryAccount = listAllFactories.FirstOrDefault(f => f.UserID == Level3ReferPlayerInfo.SimpleInfo.UserID); if (level3FactoryAccount != null && level3FactoryAccount.FactoryIsOpening && level3FactoryAccount.FactoryLiveDays > 0) { int minStoneStack = level3FactoryAccount.TotalStackCount < factory.TotalStackCount ? level3FactoryAccount.TotalStackCount : factory.TotalStackCount; if (minStoneStack != 0) { isOK = DBProvider.PlayerStoneFactoryDBProvider.AddProfitRMBChangedRecord(new StoneFactoryProfitRMBChangedRecord() { UserID = Level3ReferPlayerInfo.SimpleInfo.UserID, ProfitType = FactoryProfitOperType.Level3ReferenceAward, OperRMB = minStoneStack * profitRate * StoneFactoryConfig.FactoryOutputProfitAwardRMBConfig[2], OperTime = new MyDateTime(DateTime.Now) }, myTrans); if (!isOK) { return(OperResult.RESULTCODE_FALSE); } } } } return(OperResult.RESULTCODE_TRUE); }, exc => { if (exc != null) { LogHelper.Instance.AddErrorLog("管理员设置工厂收益异常,玩家ID:" + factory.UserID, exc); } }); } } catch (Exception exc) { LogHelper.Instance.AddErrorLog("矿石加工厂DailySetProfit异常", exc); } }