/// <summary> /// 获取下一个题目 /// </summary> /// <param name="clientId">int 客户端编号</param> /// <returns>Hash 题目集合</returns> public static Hash Next(int clientId) { string sql = "SELECT td.*,IFNULL(tcd.result, -1) AS result " + "FROM tq_question td LEFT JOIN tc_client_question tcd ON td.questionId=tcd.questionId AND clientId=@0 " + "WHERE IFNULL(tcd.result, -1) IN(-1, 0, 2) " + "ORDER BY IFNULL(tcd.result, -1) DESC, td.degree ASC "; using (MySqlADO ado = new MySqlADO()) { HashCollection items = ado.GetHashCollection(sql, clientId).ToHashCollection("data"); if (items.Count > 0) { int degree = items[0].ToInt("degree"); int maxDegree = 1; for (int i = 0; i < items.Count; i++) { if (items[i].ToInt("degree") > degree) { maxDegree = i; break; } } if (items[0].ToInt("result") == 0 || items[0].ToInt("result") == 2) { return(items[0]); } Random random = new Random(); return(items[random.Next(0, maxDegree)]); } return(new Hash()); } }
/// <summary> /// 获取所有题目选项 /// </summary> /// <param name="exceptDinosaurId">int 排除题目编号</param> /// <returns>Hash 题目集合</returns> public static Hash AllName(int exceptDinosaurId) { string sql = "SELECT name FROM td_dinosaur WHERE dinosaurId<>@0"; using (MySqlADO ado = new MySqlADO()) { return(ado.GetHashCollection(sql, exceptDinosaurId)); } }
/// <summary> /// 根据复活卡激活列表 /// </summary> /// <param name="clientId">int 客户端编号</param> /// <returns>Hash 激活列表</returns> public static Hash List(int clientId) { string sql = "SELECT tcs.*,tc.avatarUrl,tc.nick,tc.gender FROM tc_client_live tcs LEFT JOIN tc_client tc ON tcs.clientId=tc.clientId WHERE tcs.toClientId=@0 ORDER BY tcs.createTime DESC "; using (MySqlADO ado = new MySqlADO()) { return(ado.GetHashCollection(sql, clientId)); } }
/// <summary> /// 根据客户端获取排行榜 /// </summary> /// <param name="clientId">int 客户端编号</param> /// <returns>Hash 排行榜</returns> public static Hash GetRank(int clientId) { string sql = "SELECT *,tcr.relateType,tcr.openGId " + "FROM tc_client tc LEFT JOIN tc_client_relate tcr ON tc.clientId=tcr.toClientId AND tcr.fromClientId=@0 " + "WHERE tc.actived=1 ORDER BY tc.score DESC, tc.updateTime DESC"; using (MySqlADO ado = new MySqlADO()) { return(ado.GetHashCollection(sql, clientId)); } }
/// <summary> /// 获取配置信息 /// </summary> /// <returns>Hash 配置信息</returns> public static Hash Detail() { string sql = "SELECT * FROM tz_setting"; using (MySqlADO ado = new MySqlADO()) { Hash result = new Hash(); HashCollection items = ado.GetHashCollection(sql).ToHashCollection("data"); foreach (Hash item in items) { result[item.ToString("key")] = item.ToString("value"); } return(result); } }
/// <summary> /// 获取剩余题目 /// </summary> /// <param name="clientId">int 客户端编号</param> /// <returns>Hash 题目集合</returns> public static Hash Assign(int clientId) { string sql = "SELECT td.*,tcd.result " + "FROM td_dinosaur td LEFT JOIN tc_client_dinosaur tcd ON td.dinosaurId=tcd.dinosaurId AND clientId=@0 " + "WHERE IFNULL(tcd.result, 0) in (0,2) " + "ORDER BY IFNULL(tcd.result, 0) DESC, td.index ASC "; using (MySqlADO ado = new MySqlADO()) { HashCollection items = ado.GetHashCollection(sql, clientId).ToHashCollection("data"); if (items.Count > 0) { if (items[0].ToInt("result") == 2) { return(items[0]); } Random random = new Random(); return(items[random.Next(0, items.Count)]); } return(new Hash()); } }