예제 #1
0
        /// <summary>
        /// top10 奖金排行榜
        /// </summary>
        /// <returns>top10 奖金排行榜</returns>
        public GambleRankListResponse GetTop10Rank(Guid managerId)
        {
            GambleRankListResponse response = new GambleRankListResponse();

            try
            {
                List <GambleRankEntity> list = GambleRankMgr.GetRank(10);

                response.Code = (int)MessageCode.Success;
                if (list != null && list.Count != 0)
                {
                    response.Data = list;
                }
                GambleRankEntity rank = GambleRankMgr.GetById(managerId);

                if (rank != null)
                {
                    response.MyRank      = rank.RankIndex;
                    response.MyWinPoints = rank.WinTotalMoney;
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.GetTop10Rank", ex);
                response.Code = (int)MessageCode.Exception;
            }
            return(response);
        }
예제 #2
0
 /// <summary>
 /// 发奖
 /// </summary>
 private void GiveReward(string zoneId)
 {
     try
     {
         List <GambleRankEntity> list = GambleRankMgr.GetRank(10, zoneId);
         for (int i = 0, count = list.Count; i < count; i++)
         {
             if (list[i].Status == 1)
             {
                 continue;//已经发过奖了
             }
             //TODO=======邮件发送奖励
             int cardLib = 0;
             int rank    = list[i].RankIndex;
             if (rank == 1)
             {
                 cardLib = 9;
             }
             else if (rank == 2)
             {
                 cardLib = 8;
             }
             else if (rank >= 3 && rank <= 10)
             {
                 cardLib = 10;
             }
             if (cardLib > 0)
             {
                 var itemCode = CacheFactory.LotteryCache.LotteryByLib(cardLib);
                 if (itemCode > 0)
                 {
                     MailInfoEntity mailInfo = new MailInfoEntity();
                     mailInfo.MailType       = (int)EnumMailType.AdminSend;
                     mailInfo.ManagerId      = list[i].ManagerId;
                     mailInfo.IsRead         = false;
                     mailInfo.Status         = 0;
                     mailInfo.RowTime        = DateTime.Now;
                     mailInfo.ExpiredTime    = MailCore.Instance.GetExpiredTime(true, DateTime.Now);
                     mailInfo.ContentString  = "竞猜排名奖励|恭喜你竞猜盈利排名第" + rank + ",获得奖励,请查收附件.";
                     mailInfo.MailAttachment = new MailAttachmentEntity();
                     mailInfo.MailAttachment.AddAttachment(1, itemCode, false, 0);
                     mailInfo.Attachment = SerializationHelper.ToByte(mailInfo.MailAttachment);
                     mailInfo.HasAttach  = true;
                     MailInfoMgr.Insert(mailInfo, null, zoneId);
                 }
             }
             //======已经发奖,改变status标记==============
             list[i].Status = 1;
             GambleRankMgr.Update(list[i], null, zoneId);
         }
     }
     catch (Exception ex)
     {
         SystemlogMgr.Error("GambleCore.GiveReward", ex);
     }
 }
예제 #3
0
        /// <summary>
        /// 发排行榜奖励
        /// </summary>
        public bool GiveRankReward(string zoneId)
        {
            try
            {
                //获取最新的发奖操作日志
                GambleRankrewardlogEntity rewardEntity = GambleRankrewardlogMgr.GetLastestOne(zoneId);
                if (rewardEntity == null)
                {
                    GambleRankrewardlogMgr.AddNewOne(null, zoneId);
                    rewardEntity = GambleRankrewardlogMgr.GetLastestOne(zoneId);
                    //return false;
                }
                GiveReward(zoneId);
                if (CheckRewardIsFinished(zoneId))
                {
                    rewardEntity.Status = 2;
                    GambleRankMgr.MoveToHistory(rewardEntity.Idx, zoneId);
                    //GambleRankrewardlogMgr.AddNewOne(null, zoneId);
                }
                rewardEntity.UpdateTime = DateTime.Now;
                GambleRankrewardlogMgr.Update(rewardEntity, null, zoneId);
                //switch ((EnumGambleRankRewardStatus)rewardEntity.Status)
                //{
                //    //判断是否到了发奖时间,到了就改变状态为发奖中,没有就改变updateTime
                //    //发奖时间为过期后的1小时之内
                //    case EnumGambleRankRewardStatus.Init:
                //        if (IsInRewardTime())
                //        {
                //            rewardEntity.Status = 1;
                //        }
                //        break;
                //    //如果是到了发奖中,就执行发奖操作,全部操作完毕了状态改为发奖完成
                //    case EnumGambleRankRewardStatus.Rewarding:
                //        GiveReward();
                //        if(CheckRewardIsFinished())
                //            rewardEntity.Status = 2;
                //        break;
                //    //如果是发奖完成了,需要清数据,然后新增一条操作日志
                //    case EnumGambleRankRewardStatus.Rewarded:
                //        GambleRankrewardlogMgr.AddNewOne();
                //        break;
                //    default: break;
                //}

                rewardEntity.UpdateTime = DateTime.Now;
                GambleRankrewardlogMgr.Update(rewardEntity, null, zoneId);
                return(true);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("GambleCore.GiveRankReward", ex);
            }
            return(false);
        }
예제 #4
0
 /// <summary>
 /// 排名前10的是否都发奖了?
 /// </summary>
 /// <returns>是否都发奖了</returns>
 private bool CheckRewardIsFinished(string zoneId)
 {
     try
     {
         List <GambleRankEntity> list = GambleRankMgr.GetRank(10, zoneId);
         for (int i = 0, count = list.Count; i < count; i++)
         {
             if (list[i].Status == 0)
             {
                 return(false);
             }
         }
         return(true);
     }
     catch (Exception ex)
     {
         SystemlogMgr.Error("GambleCore.GiveReward", ex);
     }
     return(false);
 }
예제 #5
0
        /// <summary>
        /// 获取我的排行
        /// </summary>
        /// <param name="managerId">经理ID</param>
        /// <returns>我的排行</returns>
        public GambleRankResponse GetMyRank(Guid managerId)
        {
            GambleRankResponse response = new GambleRankResponse();

            try
            {
                GambleRankEntity rank = GambleRankMgr.GetById(managerId);

                if (rank != null)
                {
                    response.Data = rank;
                }
                response.Code = (int)MessageCode.Success;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("Gamble.GetMyRank", ex);
                response.Code = (int)MessageCode.Exception;
            }
            return(response);
        }
예제 #6
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);
            }
        }