void BindOptions() { if (ddltNeedOpenGambleTitle.Items.Count == 0) { return; } GambleTitleEntity title = GambleTitleMgr.GetById(new Guid(ddltNeedOpenGambleTitle.SelectedValue), ZoneId); List <GambleOptionEntity> list = GambleOptionMgr.GetByTitleId(new Guid(ddltNeedOpenGambleTitle.SelectedValue), ZoneId); rblOptions.DataSource = list; rblOptions.DataTextField = "OptionContent"; rblOptions.DataValueField = "Idx"; rblOptions.DataBind(); if (title.ResultFlagId != Guid.Empty) { for (int i = 0, count = rblOptions.Items.Count; i < count; i++) { if (new Guid(rblOptions.Items[i].Value) == title.ResultFlagId) { rblOptions.Items[i].Selected = true; return; } } } }
/// <summary> /// 查看当前可以坐庄的主题 /// </summary> /// <returns>查看当前可以发起的主题</returns> public GambleTitleListResponse GetCanHostTitleList() { GambleTitleListResponse response = new GambleTitleListResponse(); try { List <GambleTitleEntity> list = GambleTitleMgr.GetCanHostStartList(); response.Code = (int)MessageCode.Success; DateTime BaseTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); if (list != null && list.Count != 0) { for (int i = 0, count = list.Count; i < count; i++) { list[i].StartedTime = Convert.ToInt64(list[i].StartTime.Subtract(BaseTime).TotalMilliseconds); list[i].StopedTime = Convert.ToInt64(list[i].StopTime.Subtract(BaseTime).TotalMilliseconds); List <GambleOptionEntity> optionList = GambleOptionMgr.GetByTitleId(list[i].Idx); list[i].OptionList = optionList; } response.Data = list; } } catch (Exception ex) { SystemlogMgr.Error("Gamble.GetCanHostTitleList", ex); response.Code = (int)MessageCode.Exception; } return(response); }
//void BindOptions() //{ // cblOptions.DataSource = null; // if(SZTitles.Items.Count == 0) // return; // List<GambleOptionEntity> optionList = GambleOptionMgr.GetByTitleId(new Guid(SZTitles.SelectedValue),ZoneId); // cblOptions.DataSource = optionList; // cblOptions.DataTextField = "OptionContent"; // cblOptions.DataValueField = "Idx"; // cblOptions.DataBind(); //} void BindOptions() { blOptions.DataSource = null; if (SZTitles.Items.Count == 0) { return; } List <GambleOptionEntity> optionList = GambleOptionMgr.GetByTitleId(new Guid(SZTitles.SelectedValue), ZoneId); blOptions.DataSource = optionList; blOptions.DataTextField = "OptionContent"; blOptions.DataValueField = "Idx"; blOptions.DataBind(); }
/// <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); }
/// <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); } }