public IList <LotteryDataModel> GetLotteryHistory(int ltId) { string cacheKey = string.Format(Const.CACHE_KEY_LOTTERY_HISTORY, ltId); IList <LotteryDataModel> history = (IList <LotteryDataModel>)RTCache.Get(cacheKey); if (history == null || history.Count < 0) { history = new List <LotteryDataModel>(); using (DbOperHandler dbOperHandler = new ComData().Doh()) { dbOperHandler.Reset(); dbOperHandler.SqlCmd = "select top 20 * from Sys_LotteryData where Type=" + ltId + " order by Title desc"; DataTable dataTable = dbOperHandler.GetDataTable(); if (dataTable != null && dataTable.Rows.Count > 0) { for (int i = 0; i < dataTable.Rows.Count; i++) { LotteryDataModel lot = new LotteryDataModel() { Id = Convert.ToInt32(dataTable.Rows[i]["id"]), Type = Convert.ToInt32(dataTable.Rows[i]["Type"]), Title = Convert.ToString(dataTable.Rows[i]["Title"]), Number = Convert.ToString(dataTable.Rows[i]["Number"]), NumberAll = Convert.ToString(dataTable.Rows[i]["NumberAll"]), Total = Convert.ToInt32(dataTable.Rows[i]["Total"]), Dx = Convert.ToInt32(dataTable.Rows[i]["Dx"]), Ds = Convert.ToInt32(dataTable.Rows[i]["Ds"]), OpenTime = Convert.ToDateTime(dataTable.Rows[i]["OpenTime"]), STime = Convert.ToDateTime(dataTable.Rows[i]["STime"]), Flag = Convert.ToInt32(dataTable.Rows[i]["Flag"]), Flag2 = Convert.ToInt32(dataTable.Rows[i]["Flag2"]), IsFill = Convert.ToBoolean(dataTable.Rows[i]["IsFill"]) }; history.Add(lot); } } //排序 if (history.Count > 0) { history = (from it in history orderby it.Title descending select it).ToList(); } dataTable.Clear(); dataTable.Dispose(); } RTCache.Insert(cacheKey, history); } return(history); }
/// <summary> /// 获取彩票玩法大类 /// </summary> /// <returns>大类</returns> public string GetPlayBigType() { string json = (string)RTCache.Get(Const.CACHE_KEY_SYS_BIG_PLAY_TABLE); if (string.IsNullOrEmpty(json)) { this.doh.Reset(); this.doh.SqlCmd = "SELECT Id,TypeId,Title FROM Sys_PlayBigType where IsOpen=0 ORDER BY Sort asc"; DataTable dataTable1 = this.doh.GetDataTable(); json = dtHelp.DT2JSON(dataTable1); dataTable1.Clear(); dataTable1.Dispose(); RTCache.Insert(Const.CACHE_KEY_SYS_BIG_PLAY_TABLE, json); } return(json); }
/// <summary> /// 获取彩票种类 /// </summary> /// <returns>彩票种类</returns> public string GetLottery() { string json = (string)RTCache.Get(Const.CACHE_KEY_SYS_LOTTERY_TABLE); if (string.IsNullOrEmpty(json)) { this.doh.Reset(); this.doh.SqlCmd = "SELECT * FROM [Sys_Lottery] where IsOpen=0 order by sort asc"; DataTable dataTable1 = this.doh.GetDataTable(); json = dtHelp.DT2JSON(dataTable1); dataTable1.Clear(); dataTable1.Dispose(); RTCache.Insert(Const.CACHE_KEY_SYS_LOTTERY_PLAY_TABLE, json); } return(json); }
/// <summary> /// 获取下注数据 /// </summary> /// <param name="lotteryId"></param> /// <param name="userId"></param> /// <returns></returns> public string GetBetDataListByLotteryIdAndUserId(string lotteryId, string userId) { string json = (string)RTCache.Get(Const.CACHE_KEY_USER_BET_TABLE); if (string.IsNullOrEmpty(json)) { this.doh.Reset(); this.doh.SqlCmd = "SELECT top 20 * FROM N_UserBet where LotteryId = " + lotteryId + " AND UserId = " + userId + " ORDER BY STime desc"; DataTable dataTable1 = this.doh.GetDataTable(); json = dtHelp.DT2JSON(dataTable1); dataTable1.Clear(); dataTable1.Dispose(); RTCache.Insert(Const.CACHE_KEY_USER_BET_TABLE, json); } return(json); }
/// <summary> /// 获取彩票种类玩法 /// </summary> /// <returns>彩票种类玩法</returns> public string GetLotteryPlayType() { string json = (string)RTCache.Get(Const.CACHE_KEY_SYS_LOTTERY_PLAY_TABLE); if (string.IsNullOrEmpty(json)) { this.doh.SqlCmd = "SELECT Id,Title,Ltype FROM Sys_Lottery where IsOpen=0 ORDER BY Sort asc"; DataTable dataTable2 = this.doh.GetDataTable(); this.doh.Reset(); this.doh.SqlCmd = "SELECT Id,LotteryId,Title FROM Sys_PlaySmallType where IsOpen=0 and flag=0 ORDER BY Sort asc"; DataTable dataTable3 = this.doh.GetDataTable(); json = dtHelp.DT2JSON2(dataTable2, dataTable3); dataTable2.Clear(); dataTable3.Clear(); dataTable2.Dispose(); dataTable3.Dispose(); RTCache.Insert(Const.CACHE_KEY_SYS_LOTTERY_PLAY_TABLE, json); } return(json); }
/// <summary> /// 获取彩票系统配置 /// </summary> /// <returns>彩票详细</returns> public IList <SysLotteryModel> GetSysLotteries() { IList <SysLotteryModel> lotteries = (IList <SysLotteryModel>)RTCache.Get(Const.CACHE_KEY_SYS_LOTTERY); if (lotteries == null || lotteries.Count <= 0) { lotteries = new List <SysLotteryModel>(); using (DbOperHandler db = new ComData().Doh()) { db.Reset(); db.SqlCmd = "select * from Sys_Lottery order by id"; DataTable dataTable = db.GetDataTable(); if (dataTable != null && dataTable.Rows.Count > 0) { for (int i = 0; i < dataTable.Rows.Count; i++) { SysLotteryModel lot = new SysLotteryModel() { Id = Convert.ToInt32(dataTable.Rows[i]["id"]), Title = Convert.ToString(dataTable.Rows[i]["Title"]), Code = Convert.ToString(dataTable.Rows[i]["Code"]), CloseTime = Convert.ToInt32(dataTable.Rows[i]["CloseTime"]), IsOpen = Convert.ToBoolean(dataTable.Rows[i]["CloseTime"]), ApiUrl = Convert.ToString(dataTable.Rows[i]["ApiUrl"]) }; lotteries.Add(lot); } } } RTCache.Insert(Const.CACHE_KEY_SYS_LOTTERY, lotteries); } return(lotteries); }
/// <summary> /// 已开奖 /// </summary> /// <param name="type"></param> /// <param name="title"></param> /// <param name="number"></param> /// <param name="opentime"></param> /// <param name="numberAll"></param> /// <returns></returns> public static bool ExistLottery(int type, string title, string number, string opentime, string numberAll) { string cacheKey = string.Format(Const.CACHE_KEY_LOTTERY_HISTORY, type); IList <LotteryDataModel> history = _dal.GetLotteryHistory(type); //数据已存在 if ((from it in history where it.Title == title select it).Count() > 0) { Log.ErrorFormat("彩票已开奖, 彩种: {0}, 期号: {1}", type, title); return(true); } //更新缓存 if (history.Count > 0) { history.RemoveAt(history.Count - 1); //移除最后一条 } history.Insert(0, new LotteryDataModel() { Type = type, Title = title, Number = number, NumberAll = numberAll, Total = LotterySum.SumNumber(number), Dx = 0, Ds = 0, Flag = 0, Flag2 = 0, IsFill = true, OpenTime = Convert.ToDateTime(opentime) }); RTCache.Insert(cacheKey, history); return(false); }
/// <summary> /// 更新彩票开奖信息 /// </summary> /// <param name="type"></param> /// <param name="title"></param> /// <param name="number"></param> /// <param name="opentime"></param> /// <param name="numberAll"></param> /// <returns></returns> public bool Update(int type, string title, string number, string opentime, string numberAll) { string cacheKey = string.Format(Const.CACHE_KEY_LOTTERY_HISTORY, type); IList <LotteryDataModel> history = GetLotteryHistory(type); //数据已存在 if ((from it in history where it.Title == title select it).Count() > 0) { return(false); } try { int num = LotterySum.SumNumber(number); using (SqlConnection conn = new SqlConnection(ComData.connectionString)) { using (SqlCommand com = new SqlCommand()) { conn.Open(); com.Connection = conn; com.CommandText = string.Format(@"INSERT INTO Sys_LotteryData(Type, Title, Number, NumberAll, Total, OpenTime, IsFill) SELECT {0}, '{1}', '{2}', '{3}', {4}, '{5}', 1 WHERE NOT EXISTS(SELECT 1 FROM Sys_LotteryData WHERE Type={0} and Title='{1}'); select @@identity as id; ", type, title, number, numberAll, num, opentime); object id = com.ExecuteScalar(); //插入数据 //插入成功 if (!Convert.IsDBNull(id)) { //更新缓存 if (history.Count > 0) { history.RemoveAt(history.Count - 1); //移除最后一条 } history.Insert(0, new LotteryDataModel() { Id = Convert.ToInt32(id), Type = type, Title = title, Number = number, NumberAll = numberAll, Total = num, Dx = 0, Ds = 0, Flag = 0, Flag2 = 0, IsFill = true, OpenTime = Convert.ToDateTime(opentime) }); RTCache.Insert(cacheKey, history); return(true); } else { Log.ErrorFormat("彩票已开奖, 彩种: {0}, 期号: {1}", type, title); } } } } catch (Exception ex) { Log.ErrorFormat("开奖入库异常 {0}", ex); } return(false); }