Beispiel #1
0
        // 投输赢
        // GET: /Casino/SingleChoice/id

        public ActionResult SingleChoice(Guid id)
        {
            var model = new SingleChoiceDto();

            var gambler = _repo.Query <Gambler>(x => x.UserID == AcnID).FirstOrDefault();

            model.MyCash = gambler?.Cash ?? 0f;

            // 判断玩家是否有单注限制
            var leagueGuid = _repo.Single <Match>(id)?.LeagueGuid;

            if (leagueGuid.HasValue)
            {
                model.BetLimit = GamblerDW.GetGamblerBetLimit(AcnID, leagueGuid.Value);
            }
            else
            {
                model.BetLimit = model.MyCash;
            }

            model.Match     = MatchDto.Single(id);
            model.MatchGuid = id;

            return(View(model));
        }
Beispiel #2
0
        public ActionResult SingleChoice(SingleChoiceDto model)
        {
            var id         = model.MatchGuid;
            var leagueGuid = _repo.Single <Match>(id)?.LeagueGuid;

            if (ModelState.IsValid)
            {
                try
                {
                    //Gambler in Lower could not bet above the SingleBetLimit of DefaultLeague (Contest)
                    if (leagueGuid != null && leagueGuid.Equals(ConfigGlobal_AcnCasino.DefaultLeagueID))
                    {
                        var g = GamblerDW.Single(AcnID, leagueGuid.Value);

                        // 如果没有投过注,或投注量小于标准,判断是否在下半赛区
                        if (g == null || g.TotalBet < ConfigGlobal_AcnCasino.TotalBetStandard)
                        {
                            var    singleBetLimit  = ConfigGlobal_AcnCasino.SingleBetLimit;
                            double?alreadyMatchBet = null;

                            // 获取单场比赛当前用户投注总额
                            var item = _repo.Query <CasinoItem>(x => x.MatchGuid == id &&
                                                                x.ItemType == CasinoType.SingleChoice).FirstOrDefault();
                            var myBets = _repo.Query <Bet>(x => x.CasinoItemGuid == item.ID && x.UserID == AcnID);

                            if (myBets.Count > 0)
                            {
                                alreadyMatchBet = myBets.Sum(x => x.BetAmount);
                            }

                            // 已投注量+本次投注量不可超过单场比赛限额
                            if (singleBetLimit > 0 && (alreadyMatchBet ?? 0) + model.BetAmount > singleBetLimit)
                            {
                                throw new Exception($"下半赛区每个玩家单场投注总量不能超过{singleBetLimit.ToString("N0")}博彩币");
                            }
                        }
                    }

                    //if (model.BetAmount > ConfigGlobal_AcnCasino.SingleBetLimit)
                    //{ throw new Exception($"移动版单场不能超过{ConfigGlobal_AcnCasino.SingleBetLimit.ToString("f0")}博彩币"); }

                    var bet = new Bet
                    {
                        UserID    = AcnID,
                        UserName  = User.Identity.Name,
                        BetAmount = model.BetAmount
                    };

                    bet.Place(id, model.SelectedOption);

                    //投注成功

                    TempData["DataUrl"] = $"data-url=/Casino/GameBet/{id}";
                    return(RedirectToAction("GameBet", new { id }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("Warn", ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("Warn", "请正确填写投注单");
            }

            var gambler = _repo.Query <Gambler>(x => x.UserID == AcnID).FirstOrDefault();

            model.MyCash = gambler?.Cash ?? 0f;

            if (leagueGuid.HasValue)
            {
                model.BetLimit = GamblerDW.GetGamblerBetLimit(AcnID, leagueGuid.Value);
            }
            else
            {
                model.BetLimit = model.MyCash;
            }

            model.Match = MatchDto.Single(model.MatchGuid);

            return(View(model));
        }