Exemple #1
0
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/6/7 15:33:43</remarks>
        public bool Update(GambleDetailEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_GambleDetail_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Int32, entity.Idx);
            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId);
            database.AddInParameter(commandWrapper, "@ManagerName", DbType.String, entity.ManagerName);
            database.AddInParameter(commandWrapper, "@HostOptionId", DbType.Int32, entity.HostOptionId);
            database.AddInParameter(commandWrapper, "@GambleMoney", DbType.Int32, entity.GambleMoney);
            database.AddInParameter(commandWrapper, "@ResultMoney", DbType.Int32, entity.ResultMoney);
            database.AddInParameter(commandWrapper, "@Status", DbType.Int32, entity.Status);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);
            database.AddInParameter(commandWrapper, "@RowVersion", DbType.Binary, entity.RowVersion);


            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));
        }
Exemple #2
0
        /// <summary>
        /// 将IDataReader的当前记录读取到GambleDetailEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public GambleDetailEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new GambleDetailEntity();

            obj.Idx          = (System.Int32)reader["Idx"];
            obj.ManagerId    = (System.Guid)reader["ManagerId"];
            obj.ManagerName  = (System.String)reader["ManagerName"];
            obj.HostOptionId = (System.Int32)reader["HostOptionId"];
            obj.GambleMoney  = (System.Int32)reader["GambleMoney"];
            obj.ResultMoney  = (System.Int32)reader["ResultMoney"];
            obj.Status       = (System.Int32)reader["Status"];
            obj.RowTime      = (System.DateTime)reader["RowTime"];
            obj.RowVersion   = (System.Byte[])reader["RowVersion"];

            return(obj);
        }
Exemple #3
0
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>GambleDetailEntity</returns>
        /// <remarks>2016/6/7 15:33:43</remarks>
        public GambleDetailEntity GetById(System.Int32 idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

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

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


            GambleDetailEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
Exemple #4
0
        public static bool Update(GambleDetailEntity gambleDetailEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new GambleDetailProvider(zoneId);

            return(provider.Update(gambleDetailEntity, trans));
        }
Exemple #5
0
        /// <summary>
        /// 玩家参与竞猜
        /// </summary>
        /// <param name="managerId">经理ID</param>
        /// <param name="gambleMoney">下注金额</param>
        /// <param name="optionRateId">庄家的哪个选项的竞猜</param>
        /// <returns>是否参与成功</returns>
        public AuctionBuyResponse AttendGamble(Guid managerId, int gambleMoney, int optionRateId)
        {
            #region 各种验证

            NbManagerEntity manager = ManagerCore.Instance.GetManager(managerId);

            AuctionBuyResponse mc = new AuctionBuyResponse();
            if (gambleMoney < 1)
            {
                mc.Code = (int)MessageCode.GambleTooPoor;
                return(mc);
            }
            if (manager == null)
            {
                mc.Code = (int)MessageCode.LoginNoUser;
                return(mc);
            }
            //是否存在该题目
            GambleTitleEntity gte = GambleTitleMgr.GetByOptionRateId(optionRateId);
            if (gte == null)
            {
                mc.Code = (int)MessageCode.GambleTitleNoExist;
                return(mc);
            }

            //竞猜还没有开始
            if (gte.StartTime > DateTime.Now)
            {
                mc.Code = (int)MessageCode.GambleNotStart;
                return(mc);
            }

            if (gte.StopTime < DateTime.Now)
            {
                mc.Code = (int)MessageCode.GambleNotStart;
                return(mc);
            }

            //检查奖金是否够支付
            GambleHostoptionrateEntity ore = GambleHostoptionrateMgr.GetById(optionRateId);
            if (ore == null || ore.Idx == 0)
            {
                mc.Code = (int)MessageCode.Exception;
                return(mc);
            }
            GambleHostEntity he = GambleHostMgr.GetById(ore.HostId);
            if (he == null || he.Idx == 0)
            {
                mc.Code = (int)MessageCode.Exception;
                return(mc);
            }
            decimal needMoney = (decimal)(ore.GambleMoney + gambleMoney) * ore.WinRate;
            if (needMoney > he.TotalMoney)
            {
                mc.Code = (int)MessageCode.GambleNeedMoreTotalMoney;
                return(mc);
            }

            //不能竞猜自己发起的主题
            if (managerId == he.ManagerId)
            {
                mc.Code = (int)MessageCode.GambleCannotGambleSelf;
                return(mc);
            }
            //压住金额20钻石:任意等级       100钻石:需VIP3        300钻石:需VIP5
            mc.Code = (int)MessageCode.NbFunctionNotOpen;
            switch (manager.Level)
            {
            case 0:
            case 1:
            case 2:
                if (gambleMoney != 20)
                {
                    return(mc);
                }
                break;

            case 3:
            case 4:
                if (gambleMoney != 20 || gambleMoney != 100)
                {
                    return(mc);
                }
                break;

            default:
                if (gambleMoney != 20 || gambleMoney != 100 || gambleMoney != 300)
                {
                    return(mc);
                }
                break;
            }
            //支付金额
            string billingId = "Gamble_" + ShareUtil.GenerateComb().ToString();

            GambleDetailEntity de = new GambleDetailEntity();
            de.ManagerId    = managerId;
            de.ManagerName  = manager.Name;
            de.GambleMoney  = gambleMoney;
            de.HostOptionId = ore.Idx;
            de.ResultMoney  = 0;
            de.Status       = 0;
            de.RowTime      = DateTime.Now;
            try
            {
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    ore.GambleMoney       += gambleMoney;
                    ore.AttendPeopleCount += 1;
                    he.TotalMoney         += gambleMoney;
                    he.AttendPeopleCount  += 1;
                    if (!GambleHostMgr.Update(he, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleTooManyPeopleIsGambling;
                        return(mc);
                    }
                    if (!GambleHostoptionrateMgr.Update(ore, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleTooManyPeopleIsGambling;
                        return(mc);
                    }
                    if (!GambleDetailMgr.Insert(de, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleTooManyPeopleIsGambling;
                        return(mc);
                    }
                    MessageCode code = PayCore.Instance.GambleTrueMatch(managerId, gambleMoney, billingId, transactionManager.TransactionObject);
                    if (code != MessageCode.Success)
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GamblePayError;
                        return(mc);
                    }
                    transactionManager.Commit();
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.AttendGamble", ex);
                mc.Code = (int)MessageCode.Exception;
            }
            #endregion
            mc.Data = new AuctionBuyEntity();
            mc.Data.ManagerPoint = PayCore.Instance.GetPoint(managerId);
            return(mc);
        }