/// <summary>
        /// 将IDataReader的当前记录读取到DailycupMatchEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public DailycupMatchEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new DailycupMatchEntity();

            obj.Idx            = (System.Guid)reader["Idx"];
            obj.DailyCupId     = (System.Int32)reader["DailyCupId"];
            obj.HomeManager    = (System.Guid)reader["HomeManager"];
            obj.AwayManager    = (System.Guid)reader["AwayManager"];
            obj.HomeName       = (System.String)reader["HomeName"];
            obj.AwayName       = (System.String)reader["AwayName"];
            obj.HomeLogo       = (System.String)reader["HomeLogo"];
            obj.AwayLogo       = (System.String)reader["AwayLogo"];
            obj.HomeLevel      = (System.Int32)reader["HomeLevel"];
            obj.AwayLevel      = (System.Int32)reader["AwayLevel"];
            obj.HomePower      = (System.Int32)reader["HomePower"];
            obj.AwayPower      = (System.Int32)reader["AwayPower"];
            obj.HomeWorldScore = (System.Int32)reader["HomeWorldScore"];
            obj.AwayWorldScore = (System.Int32)reader["AwayWorldScore"];
            obj.HomeScore      = (System.Int32)reader["HomeScore"];
            obj.AwayScore      = (System.Int32)reader["AwayScore"];
            obj.Round          = (System.Int32)reader["Round"];
            obj.ChipInCount    = (System.Int32)reader["ChipInCount"];
            obj.Status         = (System.Int32)reader["Status"];
            obj.RowTime        = (System.DateTime)reader["RowTime"];

            return(obj);
        }
Exemple #2
0
 /// <summary>
 /// 根据比赛结果对象得出 出线者
 /// </summary>
 /// <param name="match">比赛对象</param>
 /// <returns>报名者对象</returns>
 private DailycupCompetitorsEntity GetWinner(DailycupMatchEntity match)
 {
     if (match.HomeScore >= match.AwayScore)
     {
         return(_CompetitorIndex[match.HomeManager]);
     }
     return(_CompetitorIndex[match.AwayManager]);
 }
        /// <summary>
        /// 针对某场比赛开奖
        /// </summary>
        /// <param name="match">The match.</param>
        static void OpenGamble(DailycupMatchEntity match)
        {
            List <DailycupGambleEntity> list = DailycupGambleMgr.GetGambleByMatchId(match.Idx);

            foreach (var gamble in list)
            {
                if (gamble.Status == (int)EnumGambleStatus.Init)
                {
                    OpenGamble(match, gamble);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Runs the dailycup round.
        /// </summary>
        /// <param name="matchs">The matchs.</param>
        /// <param name="round">The round.</param>
        /// <returns></returns>
        private List <DailycupMatchEntity> RunDailycupRound(List <DailycupMatchEntity> matchs, int round)
        {
            List <DailycupMatchEntity> list = new List <DailycupMatchEntity>();

            for (int i = 0; i < matchs.Count; i = i + 2) //roundcount必定是2的倍数!
            {
                //邻近用户比赛
                DailycupMatchEntity matchResult = Fight(GetWinner(matchs[i]), GetWinner(matchs[i + 1]), round);
                list.Add(matchResult);
            }
            return(list);
        }
        /// <summary>
        /// 针对某场比赛押注的某个经理开奖,如果博彩中了,就给奖励,否则给予惩罚
        /// </summary>
        /// <param name="match">The match.</param>
        /// <param name="gamble">The gamble.</param>
        private static void OpenGamble(DailycupMatchEntity match, DailycupGambleEntity gamble)
        {
            int matchResult;

            if (match.HomeScore > match.AwayScore)
            {
                matchResult = 1;
            }
            else if (match.HomeScore == match.AwayScore)
            {
                matchResult = 1;//平局算主队赢
            }
            else
            {
                matchResult = 2;
            }

            var resultPoint = 0;

            try
            {
                int newLevel = 0;
                if (matchResult == gamble.GambleResult) //押中
                {
                    gamble.Status = (int)EnumGambleStatus.Success;
                    resultPoint   = gamble.GamblePoint * 2;
                    //欧洲杯狂欢
                    ActivityExThread.Instance.EuropeCarnival(2, ref resultPoint);
                }
                else //押失败
                {
                    gamble.Status = (int)EnumGambleStatus.Fail;
                }
                gamble.ResultPoint = resultPoint;

                //猜中发奖励
                if (resultPoint > 0)
                {
                    var mail = new MailBuilder(gamble);
                    mail.Save();
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("OpenGamble", string.Format("每日杯赛开奖error{2},matchId:{0},gambleId:{1}", match.Idx, gamble.Idx, ex.Message), ex.StackTrace);
            }
        }
Exemple #6
0
        /// <summary>
        /// 判断投注是否关闭
        /// </summary>
        /// <param name="dailycup">The dailycup.</param>
        /// <param name="match">The match.</param>
        /// <returns>
        ///     <c>true</c> if [is gamble closed] [the specified dailycup id]; otherwise, <c>false</c>.
        /// </returns>
        public bool IsGambleClosed(DailycupInfoEntity dailycup, DailycupMatchEntity match)
        {
            DateTime now             = DateTime.Now;
            DateTime gambleLimitTime = DateTime.Today;

            //第一轮比赛投注截止时间
            gambleLimitTime = gambleLimitTime.AddSeconds(GetDailycupRoundTime(0).GambelCloseTime);
            if (match.Round == BeginRound(dailycup.Round))//当前押注的是第一轮比赛
            {
                if (DateTime.Now < gambleLimitTime)
                {
                    if (DateTime.Now > DateTime.Today.AddSeconds(CacheFactory.AppsettingCache.GetAppSettingToInt(EnumAppsetting.DailycupMyFirstRoundTime)))
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }

            int interValround = CacheFactory.AppsettingCache.GetAppSettingToInt(EnumAppsetting.DailycupSemiFinalRoundCount) - (dailycup.Round - match.Round + 1);

            if (interValround < 0 || interValround > 2)
            {
                return(true);
            }

            //投注截止时间
            gambleLimitTime = DateTime.Today.AddSeconds(GetDailycupRoundTime(interValround).GambelCloseTime);

            //投注开始时间
            DateTime preTime = DateTime.Today.AddSeconds(GetDailycupRoundTime(interValround - 1).MatchEndTime);

            if (now >= gambleLimitTime || now < preTime)
            {
                return(true);
            }

            return(false);
        }
Exemple #7
0
        /// <summary>
        /// Creates the first round.
        /// </summary>
        /// <param name="competitors">The competitors.</param>
        /// <returns></returns>
        private List <DailycupMatchEntity> CreateFirstRound(List <DailycupCompetitorsEntity> competitors)
        {
            //_MaxRound =
            int count      = competitors.Count;
            int matchCount = (int)Math.Pow(2, _dailycup.Round - 1);
            List <DailycupMatchEntity> firstRound = new List <DailycupMatchEntity>();

            for (int i = 0; i < matchCount; i++)
            {
                DailycupCompetitorsEntity away = null;
                if (matchCount * 2 - i <= count) //非轮空选手
                {
                    away = competitors[matchCount * 2 - i - 1];
                }
                DailycupMatchEntity match = Fight(competitors[i], away, 1);
                firstRound.Add(match);
            }
            return(firstRound);
        }
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/1/13 10:31:13</remarks>
        public bool Update(DailycupMatchEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_DailycupMatch_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Guid, entity.Idx);
            database.AddInParameter(commandWrapper, "@DailyCupId", DbType.Int32, entity.DailyCupId);
            database.AddInParameter(commandWrapper, "@HomeManager", DbType.Guid, entity.HomeManager);
            database.AddInParameter(commandWrapper, "@AwayManager", DbType.Guid, entity.AwayManager);
            database.AddInParameter(commandWrapper, "@HomeName", DbType.String, entity.HomeName);
            database.AddInParameter(commandWrapper, "@AwayName", DbType.String, entity.AwayName);
            database.AddInParameter(commandWrapper, "@HomeLogo", DbType.AnsiString, entity.HomeLogo);
            database.AddInParameter(commandWrapper, "@AwayLogo", DbType.AnsiString, entity.AwayLogo);
            database.AddInParameter(commandWrapper, "@HomeLevel", DbType.Int32, entity.HomeLevel);
            database.AddInParameter(commandWrapper, "@AwayLevel", DbType.Int32, entity.AwayLevel);
            database.AddInParameter(commandWrapper, "@HomePower", DbType.Int32, entity.HomePower);
            database.AddInParameter(commandWrapper, "@AwayPower", DbType.Int32, entity.AwayPower);
            database.AddInParameter(commandWrapper, "@HomeWorldScore", DbType.Int32, entity.HomeWorldScore);
            database.AddInParameter(commandWrapper, "@AwayWorldScore", DbType.Int32, entity.AwayWorldScore);
            database.AddInParameter(commandWrapper, "@HomeScore", DbType.Int32, entity.HomeScore);
            database.AddInParameter(commandWrapper, "@AwayScore", DbType.Int32, entity.AwayScore);
            database.AddInParameter(commandWrapper, "@Round", DbType.Int32, entity.Round);
            database.AddInParameter(commandWrapper, "@ChipInCount", DbType.Int32, entity.ChipInCount);
            database.AddInParameter(commandWrapper, "@Status", DbType.Int32, entity.Status);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);


            int results = 0;

            if (trans != null)
            {
                results = database.ExecuteNonQuery(commandWrapper, trans);
            }
            else
            {
                results = database.ExecuteNonQuery(commandWrapper);
            }

            entity.Idx = (System.Guid)database.GetParameterValue(commandWrapper, "@Idx");

            return(Convert.ToBoolean(results));
        }
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>DailycupMatchEntity</returns>
        /// <remarks>2016/1/13 10:31:12</remarks>
        public DailycupMatchEntity GetById(System.Guid idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("P_DailycupMatch_GetById");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Guid, idx);


            DailycupMatchEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
        public static bool Update(DailycupMatchEntity dailycupMatchEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new DailycupMatchProvider(zoneId);

            return(provider.Update(dailycupMatchEntity, trans));
        }
Exemple #11
0
        DailycupMatchEntity Fight(DailycupCompetitorsEntity home, DailycupCompetitorsEntity away, int round)
        {
            DailycupMatchEntity dailycupMatch = new DailycupMatchEntity();

            dailycupMatch.DailyCupId  = _dailycup.Idx;
            dailycupMatch.HomeManager = home.ManagerId;
            dailycupMatch.HomeName    = home.ManagerName;
            dailycupMatch.HomeLogo    = home.Logo;

            dailycupMatch.Idx            = ShareUtil.GenerateComb();
            dailycupMatch.Round          = round;
            dailycupMatch.ChipInCount    = 0;
            dailycupMatch.RowTime        = DateTime.Now;
            dailycupMatch.Status         = 0;
            dailycupMatch.HomeLevel      = home.Level;
            dailycupMatch.HomePower      = home.kpi;
            dailycupMatch.HomeWorldScore = home.WorldScore;
            if (away == null) //轮空
            {
                dailycupMatch.AwayManager = Guid.Empty;
                dailycupMatch.AwayName    = "";
                dailycupMatch.AwayScore   = 0;
                dailycupMatch.HomeScore   = 0;
                dailycupMatch.AwayLogo    = "";
            }
            else
            {
                try
                {
                    home.MaxRound = round;
                    away.MaxRound = round;
                    home.Rank     = _dailycup.Round - round + 1;
                    away.Rank     = _dailycup.Round - round + 1;
                    var matchHome = new MatchManagerInfo(home.ManagerId, false, false);
                    var matchAway = new MatchManagerInfo(away.ManagerId, false, false);
                    var matchData = new BaseMatchData((int)EnumMatchType.Dailycup, dailycupMatch.Idx, matchHome, matchAway);
                    matchData.ErrorCode = (int)MessageCode.MatchWait;
                    matchData.NoDraw    = true;
                    MemcachedFactory.MatchClient.Set(matchData.MatchId, matchData);

                    MatchCore.CreateMatch(matchData);
                    ////测试用 ------------
                    //matchData.ErrorCode = (int)MessageCode.Success;
                    //matchData.Home.Score = 5;
                    //matchData.Away.Score = 2;

                    if (matchData.ErrorCode == (int)MessageCode.Success)
                    {
                        dailycupMatch.AwayManager    = away.ManagerId;
                        dailycupMatch.AwayName       = away.ManagerName;
                        dailycupMatch.AwayLevel      = away.Level;
                        dailycupMatch.AwayLogo       = away.Logo;
                        dailycupMatch.AwayPower      = away.kpi;
                        dailycupMatch.AwayWorldScore = away.WorldScore;
                        dailycupMatch.HomeScore      = matchData.Home.Score;
                        dailycupMatch.AwayScore      = matchData.Away.Score;

                        if (matchData.Away.Score > matchData.Home.Score)
                        {
                            away.WinCount++;
                            if (round == _dailycup.Round)
                            {
                                away.Rank = -1;
                            }
                        }
                        else
                        {
                            home.WinCount++;
                            if (round == _dailycup.Round)
                            {
                                home.Rank = -1;
                            }
                        }
                        AddMatchStat(dailycupMatch);
                    }
                    else
                    {
                        dailycupMatch.AwayManager = Guid.Empty;
                        dailycupMatch.AwayName    = "";
                        dailycupMatch.AwayScore   = 0;
                        dailycupMatch.HomeScore   = 0;
                        dailycupMatch.AwayLogo    = "";
                        SystemlogMgr.Error("Create Dailycup", string.Format("round:{0},homeId:{1},awayId:{2},code:{3}", round, home.Idx, away.Idx, matchData.ErrorCode));
                        return(dailycupMatch);
                    }
                }
                catch (Exception ex)
                {
                    SystemlogMgr.Error("Create Dailycup", string.Format("round:{0},homeId:{1},awayId:{2}", round, home.Idx, away.Idx));
                    throw ex;
                }
            }
            return(dailycupMatch);
        }
Exemple #12
0
 void AddMatchStat(DailycupMatchEntity matchEntity)
 {
     AddMatchStat(matchEntity.HomeManager, matchEntity.HomeScore, matchEntity.AwayScore);
     AddMatchStat(matchEntity.AwayManager, matchEntity.AwayScore, matchEntity.HomeScore);
 }
Exemple #13
0
        /// <summary>
        /// 竞猜每日杯赛.
        /// </summary>
        /// <param name="managerId">The manager.</param>
        /// <param name="gamblePoint">押注金额</param>
        /// <param name="gambleResult">竞猜结果:1,主队胜;2,客队胜</param>
        /// <param name="matchId">比赛Id</param>
        /// <returns>如果为空,则押注成功,否则就是不成功的信息</returns>
        public DailycupAttendGambleResponse AttendGamble(Guid managerId, int gamblePoint, int gambleResult, Guid matchId, bool hasTask)
        {
            DailycupMatchEntity match = DailycupMatchMgr.GetById(matchId);

            #region Check

            if (match == null)
            {
                return(ResponseHelper.InvalidParameter <DailycupAttendGambleResponse>());
            }
            int dailycupId = match.DailyCupId;
            var dailycup   = DailycupInfoMgr.GetById(dailycupId);
            if (dailycup == null)
            {
                return(ResponseHelper.InvalidParameter <DailycupAttendGambleResponse>());
            }
            //押注已过期
            if (IsGambleClosed(dailycup, match))
            {
                return(ResponseHelper.Create <DailycupAttendGambleResponse>(MessageCode.DailycupGambleClosed));
            }
            int maxCount = 0;
            var manager  = ManagerCore.Instance.GetManager(managerId);


            //超过两个(包含2)球员被下注,就不能再下注了
            var gambleCount = DailycupGambleMgr.GambleCheck(dailycupId, manager.Idx, matchId);
            if (gambleCount == -1)
            {
                return(ResponseHelper.InvalidParameter <DailycupAttendGambleResponse>());
            }
            if (!CheckGambleCount(gambleCount, manager, out maxCount))
            {
                var response =
                    ResponseHelper.Create <DailycupAttendGambleResponse>(MessageCode.DailycupGamebleCountLimit);
                response.Data = new DailycupAttendGambleEntity();
                response.Data.MaxGambleCount = maxCount;
                return(response);
            }

            if (!CheckGamblePoint(gamblePoint, manager, out maxCount))
            {
                var response =
                    ResponseHelper.Create <DailycupAttendGambleResponse>(MessageCode.DailycupGamblePointLimit);
                response.Data = new DailycupAttendGambleEntity();
                response.Data.MaxGambleCount = maxCount;
                return(response);
            }
            //验证钻石数量
            var pointCount = PayCore.Instance.GetPoint(managerId);
            if (pointCount < gamblePoint)
            {
                return(ResponseHelper.Create <DailycupAttendGambleResponse>(MessageCode.LackofGold));
            }
            #endregion


            DailycupGambleEntity dailycupgamble = new DailycupGambleEntity();

            dailycupgamble.DailyCupId = dailycupId;
            if (gambleResult == 1)//押主队
            {
                dailycupgamble.GambleManagerId   = match.HomeManager;
                dailycupgamble.GambleManagerName = match.HomeName;
            }
            else//押客队
            {
                dailycupgamble.GambleManagerId   = match.AwayManager;
                dailycupgamble.GambleManagerName = match.AwayName;
            }
            dailycupgamble.GambleResult = gambleResult;
            dailycupgamble.GamblePoint  = gamblePoint;
            dailycupgamble.ResultPoint  = 0;
            dailycupgamble.ManagerId    = manager.Idx;
            dailycupgamble.MatchId      = matchId;
            dailycupgamble.Status       = 0;
            dailycupgamble.RowTime      = DateTime.Now;
            dailycupgamble.RoundLevel   = CalRoundType(dailycup.Round, match.Round);
            dailycupgamble.HomeName     = match.HomeName;
            dailycupgamble.AwayName     = match.AwayName;
            var isSuccess = DailycupGambleMgr.Insert(dailycupgamble);
            if (isSuccess)
            {
                DailycupMatchMgr.UpdateMatchChipInCount(matchId);
                //扣除钻石
                var code = PayCore.Instance.GambleTrueMatch(managerId, gamblePoint, Guid.NewGuid().ToString());
                if (code != MessageCode.Success)
                {
                    SystemlogMgr.Error("杯赛押注", "押注成功,扣除钻石失败");
                }

                var response = ResponseHelper.CreateSuccess <DailycupAttendGambleResponse>();
                response.Data            = new DailycupAttendGambleEntity();
                dailycupgamble.TimeTick  = ShareUtil.GetTimeTick(dailycupgamble.RowTime);
                response.Data.GambleData = dailycupgamble;

                response.Data.PopMsg = TaskHandler.Instance.DailycupGamble(managerId);
                if (hasTask)
                {
                    //response.Data.PopMsg = TaskHandler.Instance.DailycupGamble(managerId);
                }
                //ActiveCore.Instance.AddActive(managerId, EnumActiveType.CupLeagueGuessing, 1);
                return(response);
            }
            else
            {
                return(ResponseHelper.Create <DailycupAttendGambleResponse>(MessageCode.NbUpdateFail));
            }
        }