Пример #1
0
        /// <summary>
        /// 计算投注结果
        /// </summary>
        /// <param name="issueCode">当前期号</param>
        /// <param name="openResult">开奖结果</param>
        private void CalculateBetting(string lotteryCode, string issueCode, string openResult)
        {
            //获取本期所有投注数据,进行计算
            var source = this.mBetDetailService.GetIssuesBetDetail(lotteryCode, issueCode);

            if (null == source)
            {
                return;
            }

            //循环进行计算
            foreach (var item in source)
            {
                int code = item.PalyRadioCode;
                try
                {
                    ICalculate calculate = RadioContentFactory.CreateInstance(code);
                    LogManager.Info(string.Format("创建ICalculate code={0}; 对象为{1}", code, calculate.GetType().ToString()));
                    calculate.Calculate(issueCode, ManagerOpenResult(openResult), item);
                    item.OpenResult = openResult;
                    if (item.IsMatch)
                    {
                        item.Stauts = BasicModel.BetResultType.Winning;
                        //记录,更新用户余额
                        this.mRebateHelper.UpdateUserBanance(item.UserId, item.WinMoney, TradeType.奖金派送, item.BetCode, 0);

                        //插入中奖消息
                        mMessageService.Create(CreateMsg(item.BetCode, item.WinMoney, item.UserId, 0));
                        this.mMessageService.Save();
                    }
                    else
                    {
                        item.Stauts = BasicModel.BetResultType.NotWinning;
                    }
                    //计算返点
                    //if (item.PrizeType == 1)
                    //{
                    this.mRebateHelper.BettingCalculate(item.PrizeType, item.UserId, item.TotalAmt, item.BetCode, mRebateHelper.GetRadioMaxRemo(item.PalyRadioCode, item.BonusLevel));
                    //}
                }
                catch (Exception ex)
                {
                    LogManager.Error(string.Format("第{0}期,投注明细项id为{1} 计算过程中发生异常;Exception={2}", issueCode, item.Id, ex.Message));
                }
            }
            this.mBetDetailService.Save();
        }
Пример #2
0
        private void CalculatePage(object obj)
        {
            PoolParam param = obj as PoolParam;
            string    key   = param.lotteryCode + "_" + param.Issue;

            if (param == null)
            {
                LogManager.Info("PoolParam 为null,直接返回!");
                return;
            }
            if (param.WhileIndex > 3)
            {
                string betCodes = "";
                param.Details.ForEach(x => betCodes += x.BetCode);
                LogManager.Error("投注超过三次计算,结束计算:" + betCodes);
                return;
            }
            string issueCode  = param.Issue;
            string openResult = param.openResult;

            LogManager.Info("开始计算结果:" + param.ToString());
            //IDbContextFactory factory = new DbContextFactory();
            //var betDetailService = new BetDetailService(new Repo<BetDetail>(factory));
            //var messageService = new MessageService(new Repo<Message>(factory));

            List <BetDetail> source      = param.Details;
            List <BetDetail> errorSource = new List <BetDetail>();

            //循环进行计算
            foreach (var item in source)
            {
                int code = item.PalyRadioCode;
                try
                {
                    ICalculate calculate = RadioContentFactory.CreateInstance(code);
                    LogManager.Info(string.Format("创建ICalculate code={0}; 对象为{1}", code, calculate.GetType().ToString()));
                    calculate.Calculate(issueCode, openResult, item);
                    item.OpenResult = openResult;
                    if (item.IsMatch)
                    {
                        item.Stauts = BasicModel.BetResultType.Winning;
                        //插入中奖消息
                        // messageService.Create(CreateMsg(item.BetCode, item.WinMoney, item.UserId, 0));
                        //messageService.Save();
                        LotteryIssuesData.CreateMessage(CreateMsg(item.BetCode, item.WinMoney, item.UserId, 0));
                    }
                    else
                    {
                        item.Stauts = BasicModel.BetResultType.NotWinning;
                        if (item.IsBuyTogether == 1)
                        {
                            //修改子项为未中奖
                            LotteryIssuesData.UpdateBuyTogerher(item.Id, 2, 0m);
                        }
                    }

                    OpenOfficialQueue.CreateInstance().Put(item);//添加至更新队列 计算返点以及余额
                    //保存状态
                    // betDetailService.UpdateOpenState(item);
                    if (!LotteryIssuesData.UpdateOpenState(item))
                    {
                        errorSource.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    LogManager.Error(string.Format("第{0}期,投注明细项id为{1} 计算过程中发生异常", issueCode, item.Id), ex);
                    errorSource.Add(item);//失败项目,添加至列表中,稍后更新
                }
            }
            int errorCount = errorSource.Count;

            if (errorCount > 0)
            {
                param.Details     = errorSource;
                param.WhileIndex += 1;
                //继续计算
                CalculatePage(param);
                LogManager.Info("计算失败项总数为" + errorCount + " 系统将继续计算!");
            }

            //betDetailService.Save();
            LogManager.Info("计算结果结束:" + param.ToString());


            //完成计算
            IssueBettingNumsing.CreateInstance().CompledRunning(key, param.pageIndex);
        }