Пример #1
0
        /// <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);
            }
        }
Пример #2
0
        /// <summary>
        /// 杯赛竞猜结果
        /// </summary>
        /// <param name="gambleEntity"></param>
        public MailBuilder(DailycupGambleEntity gambleEntity)
            : this()
        {
            //P(第几届)|AD(轮次)|N(选手名)|P(押注钻石数)|C(奖励钻石数)
            string content = string.Format("P,{0}|AD,{1}|N,{2}|GP,{3}|C,{4}", gambleEntity.DailyCupId,
                                           gambleEntity.RoundLevel, gambleEntity.GambleManagerName, gambleEntity.GamblePoint,
                                           gambleEntity.ResultPoint);

            if (gambleEntity.Status == (int)EnumGambleStatus.Success)
            {
                Builder(gambleEntity.ManagerId, EnumMailType.DailycupGambleSuccess, content);
                AddAttachment(EnumCurrencyType.Point, gambleEntity.ResultPoint);
            }
            else
            {
                Builder(gambleEntity.ManagerId, EnumMailType.DailycupGambleFail, content);
            }
        }
Пример #3
0
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>DailycupGambleEntity</returns>
        /// <remarks>2016/5/9 19:15:26</remarks>
        public DailycupGambleEntity GetById(System.Int32 idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

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

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


            DailycupGambleEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
Пример #4
0
        /// <summary>
        /// 将IDataReader的当前记录读取到DailycupGambleEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public DailycupGambleEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new DailycupGambleEntity();

            obj.Idx               = (System.Int32)reader["Idx"];
            obj.ManagerId         = (System.Guid)reader["ManagerId"];
            obj.GamblePoint       = (System.Int32)reader["GamblePoint"];
            obj.MatchId           = (System.Guid)reader["MatchId"];
            obj.HomeName          = (System.String)reader["HomeName"];
            obj.AwayName          = (System.String)reader["AwayName"];
            obj.DailyCupId        = (System.Int32)reader["DailyCupId"];
            obj.RoundLevel        = (System.Int32)reader["RoundLevel"];
            obj.GambleResult      = (System.Int32)reader["GambleResult"];
            obj.GambleManagerId   = (System.Guid)reader["GambleManagerId"];
            obj.GambleManagerName = (System.String)reader["GambleManagerName"];
            obj.ResultPoint       = (System.Int32)reader["ResultPoint"];
            obj.Status            = (System.Int32)reader["Status"];
            obj.RowTime           = (System.DateTime)reader["RowTime"];

            return(obj);
        }
Пример #5
0
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/5/9 19:15:26</remarks>
        public bool Update(DailycupGambleEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_DailycupGamble_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, entity.Idx);
            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId);
            database.AddInParameter(commandWrapper, "@GamblePoint", DbType.Int32, entity.GamblePoint);
            database.AddInParameter(commandWrapper, "@MatchId", DbType.Guid, entity.MatchId);
            database.AddInParameter(commandWrapper, "@HomeName", DbType.String, entity.HomeName);
            database.AddInParameter(commandWrapper, "@AwayName", DbType.String, entity.AwayName);
            database.AddInParameter(commandWrapper, "@DailyCupId", DbType.Int32, entity.DailyCupId);
            database.AddInParameter(commandWrapper, "@RoundLevel", DbType.Int32, entity.RoundLevel);
            database.AddInParameter(commandWrapper, "@GambleResult", DbType.Int32, entity.GambleResult);
            database.AddInParameter(commandWrapper, "@GambleManagerId", DbType.Guid, entity.GambleManagerId);
            database.AddInParameter(commandWrapper, "@GambleManagerName", DbType.String, entity.GambleManagerName);
            database.AddInParameter(commandWrapper, "@ResultPoint", DbType.Int32, entity.ResultPoint);
            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.Int32)database.GetParameterValue(commandWrapper, "@Idx");

            return(Convert.ToBoolean(results));
        }
Пример #6
0
        public static bool Update(DailycupGambleEntity dailycupGambleEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new DailycupGambleProvider(zoneId);

            return(provider.Update(dailycupGambleEntity, trans));
        }
Пример #7
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));
            }
        }