Exemplo n.º 1
0
        /// <summary>
        /// 通过管理员查询房间和用户列表
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public string GetRoomUserTreeData(string adminUserId)
        {
            string      sql      = "select r.* from grounp p JOIN room r on p.id = r.grounpId where p.userId =@userId";
            List <Room> roomList = MySqlExecuteTools.GetObjectResult <Room>(sql, new MySqlParameter[] { new MySqlParameter("@userId", adminUserId) });

            if (roomList.Count == 0)
            {
                Logger.Debug("GetRoomUserTreeData is null");
                return("");
            }

            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            roomList.ForEach((room) => {
                Dictionary <string, object> roomDic = new Dictionary <string, object>();
                roomDic.Add("id", room.id);
                roomDic.Add("name", room.name);

                List <Dictionary <string, object> > userListDic = new List <Dictionary <string, object> >();


                sql = "SELECT u.id,u.name from room_user ru JOIN `user` u  on ru.user_id = u.id where ru.room_id = @roomId";
                List <object> list = MySqlExecuteTools.GetMuchFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", room.id) });

                list.ForEach((item) => {
                    Dictionary <string, object> userDic = new Dictionary <string, object>();
                    List <object> userList = (List <object>)item;

                    string _userId  = userList[0].ToString();
                    string userName = userList[1].ToString();
                    userDic.Add("id", _userId);
                    userDic.Add("name", userName);
                    userListDic.Add(userDic);
                });
                roomDic.Add("child", userListDic);
                result.Add(roomDic);
            });

            string resultStr = Utils.CollectionsConvert.ToJSON(result);

            resultStr = resultStr.Replace("\\", "");
            Logger.Debug(resultStr);
            return(resultStr);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查询成绩
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="currentScore">0,为当前</param>
        ///  <param name="isPlayerOrder">是否查询结果为玩家排行</param>
        public string SearchScore(int userId, string userType, bool isPlayerOrder = true, int currentScore = 0)
        {
            //只考虑玩家
            int    roomId = GetRoomIdByUser(userId);
            string sql    = "";

            //玩家的排行
            if (isPlayerOrder)
            {
                int grounpID = GrounpIdByUser(userId, userType);
                if (grounpID == -1)
                {
                    return("");
                }
                return(SearchScoreGrounpId(grounpID));
            }
            //room的排行
            else
            {
                int grounpId = -1;
                //玩家
                if (userType.Equals("0"))
                {
                    sql = "select grounpId from room where id = @roomId";

                    List <object> list = (MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", roomId) }));
                    if (list == null || list.Count == 0)
                    {
                        return("");
                    }
                    grounpId = (int)(list[0]);
                }
                else
                {
                    sql      = "select id from grounp where userId = @userId";
                    grounpId = (int)(MySqlExecuteTools.GetSingleFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@userId", userId) })[0]);
                }


                sql = "select * from room where grounpId = @grounpId";
                //获取分组的
                List <Room>  rooms  = MySqlExecuteTools.GetObjectResult <Room>(sql, new MySqlParameter[] { new MySqlParameter("@grounpId", grounpId) });
                List <Score> scores = new List <Score>();
                rooms.ForEach((room) =>
                {
                    //求平均值
                    sql = " select avg(bulletCount),avg(lifeValue) as lv,avg(fightScore),createTime from score   where roomId = " + room.id + "  order by lv desc";
                    List <object> result = (List <object>)(MySqlExecuteTools.GetMuchFieldResult(sql, new MySqlParameter[] { new MySqlParameter("@roomId", room.id) })[0]);
                    int bulletCount      = 0;
                    if (result[0] != DBNull.Value)
                    {
                        bulletCount = Convert.ToInt16(result[0]);
                    }

                    int lifeValue = 0;
                    if (result[1] != DBNull.Value)
                    {
                        lifeValue = Convert.ToInt16(result[1]);
                    }

                    int fightScore = 0;

                    if (result[2] != DBNull.Value)
                    {
                        fightScore = Convert.ToInt16(result[2]);
                    }
                    int createTime = 0;
                    if (result[3] != DBNull.Value)
                    {
                        createTime = int.Parse(result[3].ToString());
                    }

                    Score score       = new Score();
                    score.bulletCount = bulletCount;
                    score.lifeValue   = lifeValue;
                    score.fightScore  = fightScore;
                    score.userName    = room.name;
                    score.createTime  = createTime;
                    scores.Add(score);
                });

                return(Utils.CollectionsConvert.ToJSON(scores));
            }
        }