Ejemplo n.º 1
0
        public string PrizeBJDCTicket(int num)
        {
            var successCount = 0;
            var failCount    = 0;
            var log          = new List <string>();

            try
            {
                var manager        = new Sports_Manager();
                var ticketListInfo = manager.QueryPrizeTicketList("BJDC", num);
                var prizeList      = new List <TicketBatchPrizeInfo>();
                //var ticketStrSql = string.Empty;
                foreach (var ticket in ticketListInfo.TicketList)
                {
                    try
                    {
                        if (ticket.TicketStatus != TicketStatus.Ticketed)
                        {
                            continue;
                        }

                        var preTaxBonusMoney   = 0M;
                        var afterTaxBonusMoney = 0M;
                        var bonusCount         = 0;
                        var codeList           = new List <Ticket_AnteCode_Running>();
                        var collection         = new GatewayAnteCodeCollection_Sport();
                        //100_3/101_1
                        foreach (var item in ticket.BetContent.Split('/'))
                        {
                            var oneMatch = item.Split('_');
                            codeList.Add(new Ticket_AnteCode_Running
                            {
                                MatchId      = oneMatch[0],
                                IssuseNumber = ticket.IssuseNumber,
                                AnteNumber   = oneMatch[1],
                                IsDan        = false,
                                GameType     = ticket.GameType,
                            });
                            collection.Add(new GatewayAnteCode_Sport
                            {
                                AnteCode = oneMatch[1],
                                MatchId  = oneMatch[0],
                                GameType = ticket.GameType,
                                IsDan    = false
                            });
                        }
                        var n = int.Parse(ticket.PlayType.Replace("P", "").Split('_')[1]);
                        if (n > 1)
                        {
                            #region M串N
                            var orderEntity = new Sports_Business().AnalyzeOrder_Sport_Prize <Ticket_Order_Running, Ticket_Ticket_Running, Ticket_AnteCode_Running>(new GatewayTicketOrder_Sport
                            {
                                Amount         = ticket.Amount,
                                AnteCodeList   = collection,
                                Attach         = string.Empty,
                                GameCode       = ticket.GameCode,
                                GameType       = ticket.GameType,
                                IssuseNumber   = ticket.IssuseNumber,
                                IsVirtualOrder = false,
                                OrderId        = ticket.SchemeId,
                                PlayType       = ticket.PlayType.Replace("P", ""),
                                Price          = 2,
                                UserId         = string.Empty,
                                TotalMoney     = ticket.BetMoney
                            }, "LOCAL", "agentId");

                            foreach (var ticket_cp in orderEntity.GetTicketList())
                            {
                                var matchIdL = (from c in ticket_cp.GetAnteCodeList() select c.MatchId).ToArray();
                                var codeL    = codeList.Where(p => matchIdL.Contains(p.MatchId)).ToArray();

                                var analyzer    = AnalyzerFactory.GetSportAnalyzer(ticket_cp.GameCode, ticket_cp.GameType, int.Parse(ticket_cp.PlayType.Replace("P", "").Split('_')[0]));
                                var bonusResult = analyzer.CaculateBonus(codeL.ToArray(), ticketListInfo.MatchList.ToArray());
                                if (bonusResult.IsWin)
                                {
                                    bonusCount += bonusResult.BonusCount;
                                    for (var i = 0; i < bonusResult.BonusCount; i++)
                                    {
                                        var matchIdList         = bonusResult.BonusHitMatchIdListCollection[i];
                                        var sps                 = GetSPs(ticket_cp.GameCode, ticket_cp.GameType, ticket_cp.IssuseNumber, matchIdList);
                                        var oneBeforeBonusMoney = 2M;
                                        var isTrue              = false;
                                        var num_q               = 0;
                                        foreach (var item in sps)
                                        {
                                            if (item.Value == 1M)
                                            {
                                                num_q++;
                                                var entity        = codeL.Where(p => p.MatchIndex == int.Parse(item.Key)).FirstOrDefault();
                                                var anteCodeCount = entity.AnteCode.Split(',').Count();
                                                oneBeforeBonusMoney *= anteCodeCount;
                                                if (sps.Count == 1)
                                                {
                                                    isTrue = true;
                                                }
                                            }
                                            else
                                            {
                                                oneBeforeBonusMoney *= item.Value;
                                            }
                                        }
                                        if (!isTrue && num_q != sps.Count)
                                        {
                                            oneBeforeBonusMoney *= 0.65M;    // 官方扣点 - 65%
                                        }
                                        oneBeforeBonusMoney = Math.Truncate(oneBeforeBonusMoney * 100) / 100;
                                        var oneAfterBonusMoney = oneBeforeBonusMoney;

                                        //北单奖金小于2元的 按2元计算
                                        if (oneBeforeBonusMoney < 2M)
                                        {
                                            oneBeforeBonusMoney = 2M;
                                            oneAfterBonusMoney  = 2M;
                                        }

                                        if (oneBeforeBonusMoney >= 10000)
                                        {
                                            oneAfterBonusMoney = oneBeforeBonusMoney * (1M - 0.2M);
                                        }
                                        oneBeforeBonusMoney *= ticket_cp.Amount;
                                        oneAfterBonusMoney  *= ticket_cp.Amount;

                                        preTaxBonusMoney   += oneBeforeBonusMoney;
                                        afterTaxBonusMoney += oneAfterBonusMoney;
                                    }
                                }
                            }

                            //单票金额上限
                            if (afterTaxBonusMoney >= 5000000M)
                            {
                                afterTaxBonusMoney = 5000000M;
                            }

                            #endregion
                        }
                        else
                        {
                            #region M串1
                            var analyzer    = AnalyzerFactory.GetSportAnalyzer(ticket.GameCode, ticket.GameType, int.Parse(ticket.PlayType.Replace("P", "").Split('_')[0]));
                            var bonusResult = analyzer.CaculateBonus(codeList.ToArray(), ticketListInfo.MatchList.ToArray());
                            if (bonusResult.IsWin)
                            {
                                bonusCount += bonusResult.BonusCount;
                                for (var i = 0; i < bonusResult.BonusCount; i++)
                                {
                                    var matchIdList         = bonusResult.BonusHitMatchIdListCollection[i];
                                    var sps                 = GetSPs(ticket.GameCode, ticket.GameType, ticket.IssuseNumber, matchIdList);
                                    var oneBeforeBonusMoney = 2M;
                                    var isTrue              = false;
                                    var num_q               = 0;
                                    foreach (var item in sps)
                                    {
                                        if (item.Value == 1M)
                                        {
                                            num_q++;
                                            var entity        = codeList.Where(p => p.MatchIndex == int.Parse(item.Key)).FirstOrDefault();
                                            var anteCodeCount = entity.AnteCode.Split(',').Count();
                                            oneBeforeBonusMoney *= anteCodeCount;
                                            if (sps.Count == 1)
                                            {
                                                isTrue = true;
                                            }
                                        }
                                        else
                                        {
                                            oneBeforeBonusMoney *= item.Value;
                                        }
                                    }
                                    if (!isTrue && num_q != sps.Count)
                                    {
                                        oneBeforeBonusMoney *= 0.65M;    // 官方扣点 - 65%
                                    }
                                    oneBeforeBonusMoney = Math.Truncate(oneBeforeBonusMoney * 100) / 100;
                                    var oneAfterBonusMoney = oneBeforeBonusMoney;

                                    //北单奖金小于2元的 按2元计算
                                    if (oneBeforeBonusMoney < 2M)
                                    {
                                        oneBeforeBonusMoney = 2M;
                                        oneAfterBonusMoney  = 2M;
                                    }

                                    if (oneBeforeBonusMoney >= 10000)
                                    {
                                        oneAfterBonusMoney = oneBeforeBonusMoney * (1M - 0.2M);
                                    }
                                    oneBeforeBonusMoney *= ticket.Amount;
                                    oneAfterBonusMoney  *= ticket.Amount;

                                    //单票金额上限
                                    if (oneAfterBonusMoney >= 5000000M)
                                    {
                                        oneAfterBonusMoney = 5000000M;
                                    }

                                    preTaxBonusMoney   += oneBeforeBonusMoney;
                                    afterTaxBonusMoney += oneAfterBonusMoney;
                                }
                            }

                            #endregion
                        }

                        //更新票数据sql
                        prizeList.Add(new TicketBatchPrizeInfo
                        {
                            //Id = item.Id,
                            TicketId    = ticket.TicketId,
                            BonusStatus = afterTaxBonusMoney > 0M ? BonusStatus.Win : BonusStatus.Lose,
                            PreMoney    = preTaxBonusMoney,
                            AfterMoney  = afterTaxBonusMoney,
                        });

                        //var ticketStrSql = string.Format("update C_Sports_Ticket set PreTaxBonusMoney={0},AfterTaxBonusMoney={1},BonusStatus={2} where TicketId='{3}' {4}"
                        //          , preTaxBonusMoney, afterTaxBonusMoney, afterTaxBonusMoney > 0M ? Convert.ToInt32(BonusStatus.Win) : Convert.ToInt32(BonusStatus.Lose), ticket.TicketId, Environment.NewLine);
                        //manager.ExecSql(ticketStrSql);
                        successCount++;
                    }
                    catch (Exception ex)
                    {
                        failCount++;
                        log.Add(ticket.TicketId + "派奖出错 - " + ex.Message);
                    }
                }

                //批量更新数据库
                BusinessHelper.UpdateTicketBonus(prizeList);

                log.Insert(0, string.Format("总查询到{0}张票,成功派奖票:{1}条,失败派奖票:{2}条", ticketListInfo.TicketList.Count, successCount, failCount));
            }
            catch (Exception ex)
            {
                return("派奖票数据出错 - " + ex.Message);
            }

            return(string.Join(Environment.NewLine, log.ToArray()));
        }