コード例 #1
0
        /// <summary>
        /// 获取我参与的竞猜
        /// </summary>
        /// <param name="managerId">经理ID</param>
        /// <returns>获取我参与的竞猜</returns>
        public GambleDetailListResponse GetMyGambleList(Guid managerId)
        {
            List <GambleDetailEntity> list     = GambleDetailMgr.GetByManagerIdTop10(managerId);
            GambleDetailListResponse  response = new GambleDetailListResponse();

            response.Code = (int)MessageCode.Success;
            if (list != null && list.Count != 0)
            {
                response.Data = list;
            }
            return(response);
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
        }