Beispiel #1
0
        /// <summary>
        /// 可以押注的主题
        /// </summary>
        /// <returns>可以押注的主题</returns>
        public GambleHostListResponse GetCanGambleTitleList()
        {
            GambleHostListResponse response = new GambleHostListResponse();

            try
            {
                response.RankRewardDate = RankRewardDate();
                List <GambleHostEntity> list = GambleHostMgr.GetStartList();
                if (list != null && list.Count != 0)
                {
                    for (int i = 0, count = list.Count; i < count; i++)
                    {
                        List <GambleHostoptionrateEntity> rateList = GambleHostoptionrateMgr.GetByHostId2(list[i].Idx);
                        AddTeamIcon(rateList);

                        list[i].RateList = rateList;
                    }
                }
                response.Code = (int)MessageCode.Success;
                response.Data = list;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.GetCanGambleTitleList", ex);
                response.Code = (int)MessageCode.Exception;
            }
            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// 获取我发起的竞猜
        /// </summary>
        /// <param name="managerId">经理ID</param>
        /// <returns>我发起的竞猜</returns>
        public GambleHostListResponse GetMyHostList(Guid managerId)
        {
            GambleHostListResponse response = new GambleHostListResponse();

            try
            {
                List <GambleHostEntity> list = GambleHostMgr.GetByManagerIdTop10(managerId);

                response.Code = (int)MessageCode.Success;
                if (list != null && list.Count != 0)
                {
                    for (int i = 0, count = list.Count; i < count; i++)
                    {
                        List <GambleHostoptionrateEntity> rateList = GambleHostoptionrateMgr.GetByHostId2(list[i].Idx);
                        list[i].RateList = rateList;
                    }
                    response.Data = list;
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.GetMyHostList", ex);
                response.Code = (int)MessageCode.Exception;
            }
            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// 开奖
        /// </summary>
        public void OpenGamble()
        {
            try
            {
                #region deal case
                //获取已经到了开奖时间,还没有开奖的主题
                List <GambleTitleEntity> titleList = GambleTitleMgr.GetNeedOpenGambleTitles();
                if (titleList == null)
                {
                    return;
                }
                if (titleList.Count == 0)
                {
                    return;
                }

                for (int titleIndex = 0, titleCount = titleList.Count; titleIndex < titleCount; titleIndex++)
                {
                    //如果还没有在后台设置最终哪个选项是获胜选项,就报错
                    if (titleList[titleIndex].ResultFlagId == Guid.Empty)
                    {
                        //SystemlogMgr.Error("Gamble.OpenGamble", "titleList[titleIndex].ResultFlagId == 0");
                        continue;
                    }

                    //List<GambleOptionEntity> optionList = GambleOptionMgr.GetByTitleId(titleList[titleIndex].Idx);
                    //if (optionList == null || optionList.Count == 0)
                    //{
                    //    SystemlogMgr.Error("Gamble.OpenGamble", "optionList == null || optionList.Count == 0");
                    //    continue;
                    //}
                    List <GambleHostEntity> hostList = GambleHostMgr.GetByTitleId(titleList[titleIndex].Idx);
                    if (hostList == null || hostList.Count == 0)
                    {
                        //更新状态为已开奖
                        titleList[titleIndex].Status = 2;
                        if (!GambleTitleMgr.Update(titleList[titleIndex]))
                        {
                            string msg = "GambleTitleId:" + titleList[titleIndex].Idx.ToString() + "Update status to 2 error!";
                            SystemlogMgr.Error("Gamble.OpenGamble", msg);
                        }
                        continue;
                    }

                    for (int hostIndex = 0, hostCount = hostList.Count; hostIndex < hostCount; hostIndex++)
                    {
                        List <GambleHostoptionrateEntity> rateList =
                            GambleHostoptionrateMgr.GetByHostId(hostList[hostIndex].Idx);
                        if (rateList == null)
                        {
                            continue;
                        }
                        if (rateList.Count == 0)
                        {
                            continue;
                        }
                        decimal winRate          = 0.00m;
                        int     gambleTotalMoney = 0;
                        for (int rateIndex = 0, rateCount = rateList.Count; rateIndex < rateCount; rateIndex++)
                        {
                            List <GambleDetailEntity> detailList = GambleDetailMgr.GetByOptionId(rateList[rateIndex].Idx);
                            if (detailList == null || detailList.Count == 0)
                            {
                                continue;
                            }
                            if (titleList[titleIndex].ResultFlagId == Guid.Empty)
                            {
                                SystemlogMgr.Error("Gamble.OpenGamble", "ResultFlagId is 0");
                                continue;
                            }
                            GambleOptionEntity optionRight = GambleOptionMgr.GetById(titleList[titleIndex].ResultFlagId);
                            #region 结算玩家的竞猜点券
                            //猜中的玩家
                            if (rateList[rateIndex].OptionId == titleList[titleIndex].ResultFlagId)
                            {
                                winRate          = rateList[rateIndex].WinRate;
                                gambleTotalMoney = rateList[rateIndex].GambleMoney;
                                //按照赔率进行结算,发送邮件
                                for (int detailIndex = 0, detailCount = detailList.Count; detailIndex < detailCount; detailIndex++)
                                {
                                    //该玩家的竞猜已经开过奖了
                                    if (detailList[detailIndex].Status != 0)
                                    {
                                        continue;
                                    }

                                    //给玩家结算奖金
                                    int returnMoney = Convert.ToInt32(
                                        (decimal)detailList[detailIndex].GambleMoney *
                                        rateList[rateIndex].WinRate * 0.95m);
                                    //更新状态为猜中
                                    detailList[detailIndex].Status      = 1;
                                    detailList[detailIndex].ResultMoney = returnMoney;
                                    if (!GambleDetailMgr.Update(detailList[detailIndex]))
                                    {
                                        continue;
                                    }
                                    //string mailContent = "恭喜你,在参与"+titleList[titleIndex].Title +
                                    //    "的竞猜中,成功猜中" + optionRight.OptionContent + ",获得奖励"
                                    //    + returnMoney +"点券";
                                    MailBuilder mailGambler = new MailBuilder(EnumMailType.GambleReturnToGambler,
                                                                              detailList[detailIndex].ManagerId, titleList[titleIndex].Title, optionRight.OptionContent, EnumCurrencyType.Point, returnMoney);
                                    mailGambler.Save();
                                    //更新竞猜排行榜数据
                                    int subMoney = returnMoney - detailList[detailIndex].GambleMoney;
                                    GambleRankMgr.UpdateData(detailList[detailIndex].ManagerId, detailList[detailIndex].ManagerName, subMoney);
                                }
                            }
                            //没猜中
                            else
                            {
                                for (int detailIndex = 0, detailCount = detailList.Count; detailIndex < detailCount; detailIndex++)
                                {
                                    //更新状态为未猜中
                                    detailList[detailIndex].Status = 2;
                                    GambleDetailMgr.Update(detailList[detailIndex]);
                                    //更新竞猜排行榜数据

                                    GambleRankMgr.UpdateData(detailList[detailIndex].ManagerId, detailList[detailIndex].ManagerName, 0 - detailList[detailIndex].GambleMoney);
                                }
                            }
                            #endregion
                        }

                        #region 结算庄家盈亏
                        if (hostList[hostIndex].ManagerId != LeagueConst.GambleNpcId)
                        {
                            int hostReturnMoney = Convert.ToInt32(winRate * (decimal)gambleTotalMoney);
                            int hostGambleMoney = hostList[hostIndex].TotalMoney - hostReturnMoney;
                            int tax             = 0;
                            int subMoney        = hostGambleMoney - hostList[hostIndex].HostMoney;
                            if (hostGambleMoney > hostList[hostIndex].HostMoney)
                            {
                                tax       = Convert.ToInt32((decimal)subMoney * 0.05m);
                                subMoney -= tax;
                            }
                            int hostMoney = hostGambleMoney - tax;
                            hostList[hostIndex].HostWinMoney = subMoney;
                            //string mailToHost = "你发起的竞猜"+ titleList[titleIndex].Title+"已完成奖励派发,奖池还剩余"+hostMoney
                            //    +"点券,本次竞猜你共盈利"+subMoney+"点券";
                            MailBuilder mailHost = new MailBuilder(EnumMailType.GambleReturnToHost,
                                                                   hostList[hostIndex].ManagerId, titleList[titleIndex].Title,
                                                                   EnumCurrencyType.Point, hostMoney, subMoney);
                            mailHost.Save();
                            //更新竞猜排行榜数据

                            string hostName = ManagerCore.Instance.GetManager(hostList[hostIndex].ManagerId).Name;
                            GambleRankMgr.UpdateData(hostList[hostIndex].ManagerId, hostName, subMoney);
                        }
                        #endregion
                        #region 更新Host状态为已开奖
                        hostList[hostIndex].Status = 2;
                        GambleHostMgr.Update(hostList[hostIndex]);
                        #endregion
                    }

                    //更新状态为已开奖
                    titleList[titleIndex].Status = 2;
                    if (!GambleTitleMgr.Update(titleList[titleIndex]))
                    {
                        string msg = "GambleTitleId:" + titleList[titleIndex].Idx.ToString() + "Update status to 2 error!";
                        SystemlogMgr.Error("Gamble.OpenGamble", msg);
                    }
                }
                #endregion

                #region 更新排行榜
                GambleRankMgr.UpdateRank();
                #endregion
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.OpenGamble", ex);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 坐庄
        /// </summary>
        /// <param name="managerId">庄家ID</param>
        /// <param name="rateStr">赔率字符串(以‘|’分割)</param>
        /// <param name="gambleTitleId">竞猜的主题ID</param>
        /// <param name="hostMoney">奖池的奖金</param>
        public AuctionBuyResponse ToBeHost(Guid managerId, string rateStr, Guid gambleTitleId, int hostMoney, string zoneId = "")
        {
            AuctionBuyResponse mc = new AuctionBuyResponse();

            //如果赔率是空  默认   2|2|2
            if (string.IsNullOrEmpty(rateStr))
            {
                rateStr = "2|2|2";
            }
            try
            {
                #region 各种验证
                //奖池不得低于5000点券
                if (hostMoney < CacheFactory.AppsettingCache.GetAppSettingToInt(EnumAppsetting.MinGamblePoolMoney))
                {
                    mc.Code = (int)MessageCode.GambleNotEnoughMoney;
                    return(mc);
                }
                //是否存在该题目
                GambleTitleEntity gte = GambleTitleMgr.GetById(gambleTitleId, zoneId);
                if (gte == null)
                {
                    mc.Code = (int)MessageCode.GambleTitleNoExist;
                    return(mc);
                }
                //该题目是否允许玩家坐庄
                if (managerId != LeagueConst.GambleNpcId)
                {
                    if (gte.IsOfficial == 1)
                    {
                        mc.Code = (int)MessageCode.ThisGambleTitleIsOfficial;
                        return(mc);
                    }
                }

                //最多三个庄家,检查有没有超过3家
                if (gte.CurrentCount >= 3)
                {
                    mc.Code = (int)MessageCode.GambleHostsIsFull;
                    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);
                }



                //验证赔率和玩家资金

                string[] rateArr = rateStr.Split('|');
                List <GambleOptionEntity> optionList = GambleOptionMgr.GetByTitleId(gambleTitleId, zoneId);
                if (optionList == null || optionList.Count == 0 || optionList.Count != rateArr.Length)
                {
                    mc.Code = (int)MessageCode.GambleParamError;
                    return(mc);
                }
                decimal[] rateArrM = new decimal[rateArr.Length];
                for (int i = 0, count = optionList.Count; i < count; i++)
                {
                    rateArrM[i] = decimal.Round(Convert.ToDecimal(rateArr[i]), 2);
                }

                #endregion

                //支付奖金

                string           billingId = "Gamble" + ShareUtil.GenerateComb();
                GambleHostEntity ghe       = new GambleHostEntity();
                ghe.ManagerId = managerId;
                if (managerId == LeagueConst.GambleNpcId)
                {
                    ghe.ManagerName = "Official_Manager";
                }
                else
                {
                    ghe.ManagerName = ManagerCore.Instance.GetManager(managerId).Name;
                }
                ghe.TitleId    = gambleTitleId;
                ghe.Status     = 0;
                ghe.RowTime    = DateTime.Now;
                ghe.TotalMoney = hostMoney;
                ghe.HostMoney  = hostMoney;
                string conn = ConnectionFactory.Instance.GetConnectionString(zoneId, EnumDbType.Main);
                using (var transactionManager = new TransactionManager(conn))
                {
                    transactionManager.BeginTransaction();
                    if (managerId != LeagueConst.GambleNpcId)
                    {
                        MessageCode code = PayCore.Instance.GambleTrueMatch(managerId, hostMoney, billingId, transactionManager.TransactionObject);
                        if (code != MessageCode.Success)
                        {
                            transactionManager.Rollback();
                            mc.Code = (int)code;
                            return(mc);
                        }
                    }
                    bool addResult = GambleTitleMgr.AddCount(gambleTitleId, transactionManager.TransactionObject, zoneId);
                    if (!addResult)
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleHostsIsFull;
                        return(mc);
                    }
                    int idxx = 0;
                    if (!GambleHostMgr.InsertOnce(managerId, ghe.ManagerName, ghe.TitleId, ghe.HostMoney, ghe.TotalMoney, ghe.RowTime, ref idxx, transactionManager.TransactionObject))
                    {
                        transactionManager.Rollback();
                        mc.Code = (int)MessageCode.GambleOnlyOnce;
                        return(mc);
                    }
                    ghe.Idx = idxx;
                    GambleHostoptionrateEntity ghoe = new GambleHostoptionrateEntity();
                    ghoe.HostId  = ghe.Idx;
                    ghoe.Status  = 0;
                    ghoe.RowTime = DateTime.Now;
                    for (int i = 0, count = optionList.Count; i < count; i++)
                    {
                        ghoe.OptionId = optionList[i].Idx;
                        ghoe.WinRate  = rateArrM[i];
                        if (!GambleHostoptionrateMgr.Insert(ghoe, transactionManager.TransactionObject, zoneId))
                        {
                            transactionManager.Rollback();
                            mc.Code = (int)MessageCode.GambleHostRateInsertError;
                            return(mc);
                        }
                    }
                    transactionManager.Commit();
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.ToBeHost", ex);
                mc.Code = (int)MessageCode.Exception;
                return(mc);
            }
            mc.Data = new AuctionBuyEntity();
            if (managerId != LeagueConst.GambleNpcId)
            {
                mc.Data.ManagerPoint = PayCore.Instance.GetPoint(managerId);
            }
            mc.Code = (int)MessageCode.Success;
            return(mc);
        }
Beispiel #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);
        }