Example #1
0
        /// <summary>
        /// 获取游戏列表
        /// author:刘嘉辉
        /// <param name="channelId">渠道号</param>
        /// <param name="channelIdType">渠道类型  0 来源设备信息  1 来源注册渠道  2 默认</param>
        /// </summary>
        /// <returns></returns>
        public async Task <List <AppGameDto> > GetGameListAsync(string channelId, int channelIdType)
        {
            List <AppGameDto> GameList     = new List <AppGameDto>();
            List <AppGameDto> GameListTemp = new List <AppGameDto>();
            int iLevel = StringExtension.IsChannelIdLevel(channelId) + 1;

            do
            {
                iLevel--;
                string strNewChannelId = StringExtension.UpdateChannelId(channelId, iLevel);
                /*查询渠道关联游戏*/
                var ibcGameInfo = await _context.IbcGameInfo.Where(c => c.channelid == strNewChannelId && c.Status == 1).FirstOrDefaultAsync();

                if (ibcGameInfo != null)
                {
                    /*游戏数组*/
                    string[] gameKeyArray;
                    //var GuessMatch = _biz.AcquireGuessMatch(); //从章鱼拿到竞猜数量数
                    var GuessMatch = _biz.NewAcquireGuessMatch();//从php获取竞猜数量
                    switch (channelIdType)
                    {
                    case 0:
                        gameKeyArray = ibcGameInfo.Ibc_gameid.Split(',');
                        break;

                    case 1:
                        gameKeyArray = ibcGameInfo.Register_gameid.Split(',');
                        break;

                    default:
                        gameKeyArray = ibcGameInfo.Default_gameid.Split(',');
                        break;
                    }

                    long[] arrId          = Array.ConvertAll <string, long>(gameKeyArray, m => long.Parse(m));
                    var    gameInfoEntity = await _context.GameInfo.Where(c => arrId.Contains(c.Id) && c.Stateus == 1).ToListAsync();

                    foreach (var item in gameInfoEntity)
                    {
                        //var guessMatchInfo = GuessMatch != null ? GuessMatch.data.Where(c => c.displayName == item.Game_Name).FirstOrDefault() : null; //获取游戏数量
                        //int guessMatchCount = guessMatchInfo == null ? 1 : guessMatchInfo.matchCount;
                        var guessMatchInfo = GuessMatch != null?GuessMatch.list.Where(c => c.displayName == item.Game_Name).FirstOrDefault() : null;

                        int guessMatchCount = guessMatchInfo == null ? 1 : guessMatchInfo.matchCount;
                        if (guessMatchCount != 0 || guessMatchInfo == null)
                        {
                            AppGameDto appGameDto = new AppGameDto
                            {
                                GameName    = item.Game_Name,                                         //游戏名称
                                GameType    = item.Game_type_id,                                      //游戏类型id
                                ImgUrl      = item.Icon_url,                                          //游戏图片链接
                                Url         = item.Target_url,                                        //游戏跳转链接
                                MatchCount  = guessMatchInfo == null ? 0 : guessMatchInfo.matchCount, //竞猜游戏数量
                                description = item.Description,                                       //游戏描述
                                UrlType     = item.Url_type,                                          //跳转方式
                                Id          = item.Id
                            };
                            //&& appGameDto.GameName != "狗狗冲冲冲"
                            //    && && appGameDto.GameName != "海南四星"
                            if (appGameDto.MatchCount == 0)
                            {
                                if (appGameDto.GameType == 4)
                                {
                                    GameListTemp.Add(appGameDto);
                                    continue;
                                }
                                continue;
                            }
                            GameListTemp.Add(appGameDto);
                        }
                    }
                    //排序游戏。
                    for (int i = 0; i < arrId.Length; i++)
                    {
                        for (int j = 0; j < GameListTemp.Count; j++)
                        {
                            if (arrId[i] == GameListTemp[j].Id)
                            {
                                GameList.Add(GameListTemp[j]);
                            }
                        }
                    }
                    return(GameList);
                }
            } while (iLevel > 1);

            return(null);
        }