Пример #1
0
 public override int Calculate(BetOrder order)
 {
     base.CheckNumLength(order.Num, 3);
     // var companyType = DaCompanyType.GetCompanyTypeByCompany(order.CompanyId);
     var gamePlayWay = LotterySystem.Current.FindGamePlayWay(order.GamePlayWayId);//DaGamePlayWay.GetGamePlayWay(order.GamePlayWayId);
     return TransToMethod(gamePlayWay)(order.Num, order.CompanyId);
 }
Пример #2
0
 public bool Inject(BetOrder order)
 {
     IsDrop = false;
     bool returnValue;
     if (returnValue = !Extended.IsStopAcceptBet(order.CompanyId, order.GamePlayWayId))
     {
         lock (_lockHelper)
         {
             var upperLimit = GetUpperLimit(order);
             if (returnValue = (!upperLimit.StopBet && Check(order, upperLimit)))
             {
                 TransformOrder(order, upperLimit);
                 upperLimit.TotalBetAmount += order.Amount;
                 UpperLimitManager.GetManager().UpdateLimit(upperLimit);
             }
         }
     }
     return returnValue;
 }
Пример #3
0
        public bool Inject(BetOrder order)
        {
            IsDrop = false;
            var betedAmount = GetUserBetedAmountByOrder(order);

            var totalAmount = betedAmount + order.Amount;

            //计算要跌水的值

            var drops = GetDropWater(order);
            double dropValue = 0; //drops.Where(it => it.Amount < totalAmount).Sum(it => it.DropValue);
            foreach (var d in drops)
                if (d.Amount < totalAmount) dropValue += d.DropValue;

            if (dropValue > 0)
            {
                IsDrop = true;
                order.DropWater += dropValue;
                order.Net += dropValue;
                double memberComm = (100 - order.Net).PercentageToDecimal(4);
                order.Commission = order.Turnover * (decimal)memberComm;
                order.NetAmount = order.Turnover - order.Commission;
                order.AncestorCommission.ForEach(it =>
                {
                    if (it.Role == Role.Company)
                    {
                        it.Commission += order.DropWater;
                    }
                    else
                    {
                        it.Commission -= order.DropWater;
                    }
                    it.CommAmount = (decimal)(it.Commission.PercentageToDecimal(4)) * order.Turnover;
                });
            }
            return true;
        }
Пример #4
0
 public abstract int Calculate(BetOrder order);
Пример #5
0
        /// <summary>
        /// 获取会员结单
        /// </summary>
        /// <param name="member">The member.</param>
        /// <returns></returns>
        public IEnumerable<BetOrder> GetStatement(User member, out BetOrder lastWeekTotal)
        {
            if (member.Role != Role.Guest) throw new NoPermissionException("获取会员结单", member.ToString());

            int dayCount = 14;
            int diffDay = 0;
            if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday) diffDay = 7;
            else diffDay = (int)DateTime.Today.DayOfWeek;

            int count = diffDay + 7 > LotterySystem.Current.StatementOrderCount ? LotterySystem.Current.StatementOrderCount : diffDay + 7;
            var endDate = DateTime.Today.AddDays(-1 * count);
            var statememt = DaOrder.GetStatementOrder(member, dayCount);

            #region 获取上周总结

            var lastMonday = DateTime.Today.AddDays(-1 * (diffDay + 6));
            var lastSunday = lastMonday.AddDays(6);

            var lastWeekTotals = statememt.Where(it => it.CreateTime >= lastMonday && it.CreateTime <= lastSunday);
            lastWeekTotal = new BetOrder { CreateTime = lastSunday };
            foreach (var order in lastWeekTotals)
            {
                if (lastWeekTotal == null)
                {
                    lastWeekTotal = order;
                    lastWeekTotal.CreateTime = lastSunday;
                }
                else
                {
                    lastWeekTotal.Turnover += order.Turnover;
                    lastWeekTotal.Commission += order.Commission;
                    lastWeekTotal.NetWin += order.NetWin;
                    lastWeekTotal.DrawResult += order.DrawResult;
                    lastWeekTotal.CancelAmount += order.CancelAmount;
                }
            }
            #endregion

            var result = statememt.Where(it => it.CreateTime >= lastMonday);
            if (result.Count() < dayCount)
            {
                List<BetOrder> orders = new List<BetOrder>(result);
                List<DateTime> dates = new List<DateTime>();
                for (int i = 0; i < dayCount; i++)
                    dates.Add(DateTime.Today.AddDays(-1 * i));
                var notExistDate = dates.Except(result.Select(it => it.CreateTime));
                orders.AddRange(notExistDate.Select(it => new BetOrder { CreateTime = it }));
                result = orders;
            }
            int takeCount = (int)DateTime.Today.DayOfWeek + 7;
            if (takeCount > 10 || takeCount <= 7)
                takeCount = 10;
            return result.OrderBy(it => it.CreateTime).Skip(dayCount - takeCount).Take(count);
        }
Пример #6
0
 internal string GetBetAmountDicKey(BetOrder order)
 {
     string key = string.Format("{0}_{1}_{2}", order.CompanyId, order.GamePlayWayId, order.Num);
     return key;
 }
Пример #7
0
 private IEnumerable<BetAutoDropWater> GetDropWater(BetOrder order)
 {
     var company = TodayCompany.Find(it => it.CompanyId == order.CompanyId);
     if (company == null)
         throw new ArgumentException("找不到开奖公司,CompanyId:" + order.CompanyId);
     string key = string.Format("{0}_{1}", (int)company.CompanyType, order.GamePlayWayId);
     IEnumerable<BetAutoDropWater> drops;
     if (!AutoDropDic.TryGetValue(key, out drops))
     {
         drops = DwManager.GetAutoDrops(company.CompanyType, order.GamePlayWayId);
         AutoDropDic.Add(key, drops);
     }
     return drops;
 }
 public MultipleCalculator BuildCalculator(BetOrder order)
 {
     if (!CalcDic.ContainsKey(order.GamePlayWayId))
         CalcDic.Add(order.GamePlayWayId, CreateMultipleCalculator(order.GamePlayWayId));
     return CalcDic[order.GamePlayWayId];
 }
Пример #9
0
 private void TransformOrder(BetOrder order, BetUpperLimit upperLimit)
 {
     if (upperLimit.DropValue > 0)
     {
         IsDrop = true;
         order.DropWater += upperLimit.DropValue;
         order.Net += upperLimit.DropValue;
         double memberComm = (100 - order.Net).PercentageToDecimal(4);
         order.Commission = order.Turnover * (decimal)memberComm;
         order.NetAmount = order.Turnover - order.Commission;
         order.AncestorCommission.ForEach(it =>
         {
             if (it.Role == Role.Company)
             {
                 it.Commission += upperLimit.DropValue;
             }
             else
             {
                 it.Commission -= upperLimit.DropValue;
             }
             it.CommAmount = (decimal)it.Commission.PercentageToDecimal(4) * order.Turnover;
         });
     }
 }
Пример #10
0
 public void RollOrderLimit(BetOrder order)
 {
     throw new NotImplementedException();
 }
Пример #11
0
        /// <summary>
        /// 检查该注单是否可下.
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="upperLimit">The upper limit.</param>
        /// <returns></returns>
        protected bool Check(BetOrder order, BetUpperLimit upperLimit)
        {
            decimal totalBetAmount = order.Amount + upperLimit.TotalBetAmount;
            if (totalBetAmount > upperLimit.UpperLlimit)        //最终投注金额大于投注上限金额
            {
                //TODO:错误信息呈现设计,存在多个插入失败
                //ErrorMessage = "Can't Bet!";
                return false;
            }
            while (totalBetAmount > upperLimit.NextLimit)          //总投注金额小于投注上限,大于本次跌水金额限制(增加跌水)
            {
                UpdateUpperLimit(upperLimit);

                //本次跌水限制金额==总下注金额时则说明没有跌水限制了
                if (upperLimit.NextLimit == upperLimit.TotalBetAmount) break;
            }

            return true;
        }
Пример #12
0
 /// <summary>
 /// 获取注单相对应的上限限制记录.
 /// </summary>
 /// <param name="order">The order.</param>
 /// <returns></returns>
 protected BetUpperLimit GetUpperLimit(BetOrder order)
 {
     //获取指定公司,玩法,号码的上限限制
     var upperLimit = UpperLimitManager.GetManager().GetLimit(order);
     if (upperLimit == null)
         throw new ApplicationException("找不到上限!");
     return upperLimit;
 }
Пример #13
0
 /// <summary>
 /// 创建下注订单.
 /// </summary>
 /// <param name="num">The num.</param>
 /// <param name="numQuantity">The num quantity.</param>
 /// <param name="commModel">The comm model.</param>
 /// <param name="gamePlayWay">The game play way.</param>
 /// <param name="company">The company.</param>
 /// <param name="wager">The wager.</param>
 /// <returns></returns>
 private BetOrder BuildBetOrder(string num, int numQuantity, Pair<CommissionGroup, IEnumerable<ConcreteCommission>> memberComm, GamePlayWay gamePlayWay,
     LotteryCompany company, decimal wager, User user, bool isCon = false)
 {
     var commValue = memberComm.Value.Find(it => it.CompanyType == company.CompanyType && it.GameType == gamePlayWay.GameType);
     double percentComm = isCon ? commValue.Commission - LotterySystem.Current.AutoElectionCodeCommission : commValue.Commission;
     decimal comm = (decimal)MathHelper.PercentageToDecimal(percentComm, 4);
     decimal turnOver = wager * numQuantity;
     decimal commission = comm * turnOver;
     BetOrder order = new BetOrder
     {
         Num = num,
         GamePlayWayId = gamePlayWay.Id,
         CompanyId = company.CompanyId,
         Amount = wager,
         Odds = commValue.Odds,
         Commission = commission,
         Turnover = turnOver,
         Net = 100 - percentComm,
         NetAmount = turnOver - commission,
         Status = BetStatus.Valid,
         UserId = user.UserId,
         AncestorCommission = BuildAncestorCommission(turnOver, user, gamePlayWay.GameType, company.CompanyType, memberComm.Key.Specie, isCon)
     };
     if (isCon)
     {
         order.DropWater += LotterySystem.Current.AutoElectionCodeCommission;
     }
     return order;
 }
Пример #14
0
 public BetUpperLimit GetLimit(BetOrder order)
 {
     return GetLimit(order.Num, order.CompanyId, order.GamePlayWayId);
 }
Пример #15
0
 /// <summary>
 /// 根据注单计算.
 /// </summary>
 /// <param name="order">The order.</param>
 /// <returns></returns>
 public int Calculate(BetOrder order)
 {
     var calculator = MultipleCalculatorFactory.GetFactory().BuildCalculator(order);
     return calculator.Calculate(order);
 }
 public abstract override int Calculate(BetOrder order);
Пример #17
0
        protected bool CheckGameLimit(BetOrder order)
        {
            //注单中的公司肯定在今日开奖公司中
            var company = TodayCompany.Find(it => it.CompanyId == order.CompanyId);
            if (company == null) return false;
            var companyType = company.CompanyType;
            //获取注单公司所在公司类型所有公司
            var companyTypeCompanys = TodayCompany.Where(it => it.CompanyType == company.CompanyType);
            Spec<BetOrder> orSpec = null;
            bool isFirst = true;
            foreach (var com in companyTypeCompanys)
            {
                if (isFirst)
                {
                    isFirst = false;
                    orSpec = it => it.CompanyId == com.CompanyId;
                }
                else
                    orSpec = orSpec.Or(it => it.CompanyId == com.CompanyId);
            }
            if (order.Num.IsNum())
            {
                orSpec = orSpec.And(it => it.Num == order.Num);
            }
            else if (order.Num.IsPL2())
            {
                var splNums = order.Num.Split('#');
                Spec<BetOrder> plSpec = it => it.Num == order.Num;
                plSpec = plSpec.Or(it => it.Num == splNums[1] + "#" + splNums[0]);
                orSpec = orSpec.And(plSpec);
            }
            else if (order.Num.IsPL3())
            {
                var plNums = order.Num.Split('#');
                string[] nums = new string[5];
                string numFormat = "{0}#{1}#{2}";
                nums[0] = string.Format(numFormat, nums[0], nums[2], nums[1]);
                nums[1] = string.Format(numFormat, nums[1], nums[0], nums[2]);
                nums[2] = string.Format(numFormat, nums[1], nums[2], nums[0]);
                nums[3] = string.Format(numFormat, nums[2], nums[0], nums[1]);
                nums[4] = string.Format(numFormat, nums[2], nums[1], nums[0]);
                Spec<BetOrder> plSpec = it => it.Num == order.Num;
                foreach (var plNum in nums)
                    plSpec = plSpec.Or(it => order.Num == plNum);
                orSpec = orSpec.And(plSpec);
            }
            //获取数据库中的总金额
            Func<BetOrder, bool> spec = it => it.GamePlayWayId == order.GamePlayWayId && orSpec(it);
            decimal dbAmount = 0, beAddAmount = 0;

            string key = BaseChecker.GetBetAmountDicKey(order);
            BetOrder target;
            if (BaseChecker.UserValidOrderDic.TryGetValue(key, out target))
                dbAmount = target.Amount;

            //foreach (var item in BaseChecker.UserValidOrderList)
            //    if (spec(item))
            //        dbAmount += item.Amount;
            foreach (var item in BaseChecker.BeInsertOrderList)
                if (spec(item))
                    beAddAmount += item.Amount;

            var totalAmount = dbAmount + beAddAmount;    //取得总金额
            totalAmount += order.Amount;
            var gameLimitList = GetGameLimitByUser(order.UserId);
            //找出游戏限制
            var gameLimit = gameLimitList.Find(it => it.CompanyType == companyType && it.GamePlayWayId == order.GamePlayWayId);
            if (gameLimit == null)
                throw new ApplicationException(string.Format("不存在GamePlayWayId为{0}的游戏限制!", order.GamePlayWayId));

            if (totalAmount > gameLimit.LimitValue)
                return false;

            return true;
        }
Пример #18
0
 public bool Inject(BetOrder order)
 {
     return CheckBetLimit(order) && CheckGameLimit(order);
 }
Пример #19
0
 public void Update(BetOrder order)
 {
     string sql = string.Format(@"UPDATE {0} SET {1}=@{1},{2}=@{2},{3}=@{3} WHERE {4}=@{4}", BetOrder.TABLENAME, BetOrder.STATUS, BetOrder.DROPWATER, BetOrder.DRAWRESULT, BetOrder.ORDERID);
     base.ExecuteNonQuery(sql, new SqlParameter(BetOrder.STATUS, (int)order.Status),
         new SqlParameter(BetOrder.DROPWATER, order.DropWater),
         new SqlParameter(BetOrder.DRAWRESULT, order.DrawResult),
         new SqlParameter(BetOrder.ORDERID, order.OrderId));
 }
Пример #20
0
 /// <summary>
 /// Checks the bet limit.
 /// </summary>
 /// <param name="order">The order.</param>
 /// <param name="orderList">The order list.</param>
 /// <returns></returns>
 protected bool CheckBetLimit(BetOrder order)
 {
     var gameplayway = LotterySystem.Current.GamePlayWays.Find(it => it.Id == order.GamePlayWayId);
     var betLimitList = GetLimitByUser(order.UserId);
     var betlimit = betLimitList.Find(it => it.GameType == gameplayway.GameType);   //找出单注限制
     if (order.Amount < betlimit.LeastLimit || order.Amount > betlimit.LargestLimit)
         return false;
     else
         return true;
 }
Пример #21
0
        private decimal GetUserBetedAmountByOrder(BetOrder order)
        {
            string key = BaseChecker.GetBetAmountDicKey(order);
            decimal totalAmount = 0;
            BetOrder target;
            if (BaseChecker.UserValidOrderDic.TryGetValue(key, out target))
                totalAmount += target.Amount;
            Func<BetOrder, bool> spec = it => it.Num == order.Num && it.CompanyId == order.CompanyId && it.GamePlayWayId == order.GamePlayWayId;
            foreach (var item in BaseChecker.BeInsertOrderList)
                if (spec(item))
                    totalAmount += item.Amount;
            return totalAmount;

            //decimal dbAmount = 0, beAddAmount = 0;
            //Func<BetOrder, bool> spec = it => it.Num == order.Num && it.CompanyId == order.CompanyId && it.GamePlayWayId == order.GamePlayWayId;
            //foreach (var item in BaseChecker.UserValidOrderList)
            //    if (spec(item))
            //        dbAmount += item.Amount;
            //foreach (var item in BaseChecker.BeInsertOrderList)
            //    if (spec(item))
            //        beAddAmount += item.Amount;
            //return dbAmount + beAddAmount;
        }
Пример #22
0
 public void Insert(BetOrder order)
 {
     string sql = string.Format(@"INSERT INTO {0} ({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13}) VALUES
     (@{1},@{2},@{3},@{4},@{5},@{6},@{7},@{8},@{9},@{10},@{11},@{12},@{13}) SELECT Scope_Identity()", BetOrder.TABLENAME, BetOrder.SHEETID,
     BetOrder.NUM, BetOrder.GAMEPLAYWAYID, BetOrder.COMPANYID, BetOrder.AMOUNT, BetOrder.TURNOVER, BetOrder.ODDS,
     BetOrder.COMMISSION, BetOrder.NET, BetOrder.NETAMOUNT, BetOrder.STATUS, BetOrder.DROPWATER, BetOrder.EXT1);
     object id = base.ExecuteScalar(sql, new SqlParameter(BetOrder.SHEETID, order.SheetId),
         new SqlParameter(BetOrder.NUM, order.Num),
         new SqlParameter(BetOrder.GAMEPLAYWAYID, order.GamePlayWayId),
         new SqlParameter(BetOrder.COMPANYID, order.CompanyId),
         new SqlParameter(BetOrder.AMOUNT, order.Amount),
         new SqlParameter(BetOrder.TURNOVER, order.Turnover),
         new SqlParameter(BetOrder.ODDS, order.Odds),
         new SqlParameter(BetOrder.COMMISSION, order.Commission),
         new SqlParameter(BetOrder.NET, order.Net),
         new SqlParameter(BetOrder.NETAMOUNT, order.NetAmount),
         new SqlParameter(BetOrder.STATUS, order.Status),
         new SqlParameter(BetOrder.DROPWATER, order.DropWater),
         new SqlParameter(BetOrder.EXT1, order.Ext1));
     order.OrderId = Convert.ToInt32(id);
 }
Пример #23
0
        public void RollOrderLimit(BetOrder order)
        {
            var upperLimit = GetUpperLimit(order);
            if (upperLimit.TotalBetAmount < order.Amount)
                throw new InvalidDataException("Error Data!Total bet amount less than order's amount!");

            var dropWaters = GetDropWater(order.Num, order.CompanyId, order.GamePlayWayId);

            upperLimit.TotalBetAmount -= order.Amount;        //注单总金额减少

            var previous = dropWaters.Where(it => it.Amount > upperLimit.TotalBetAmount && it.Amount < upperLimit.NextLimit).        //找到上一个跌水规则
                GroupBy(it => it.Amount).
                OrderByDescending(it => it.Key);

            foreach (var previou in previous)
            {
                DropWater dropwater = null;
                int previousDropCount = 0;
                if (previous != null)
                {
                    foreach (var drop in previou)
                    {
                        previousDropCount++;
                        if (dropwater != null && dropwater.DropType == DropType.Manual) continue;
                        dropwater = drop;
                    }
                    if (previousDropCount > 2)
                        throw new InvalidDataException(string.Format("号码:{0}的跌水记录大于2!CompanyId:{1} , GamePlayWayId:{2}",
                            upperLimit.Num, upperLimit.CompanyId, upperLimit.GamePlayWayId));
                }
                if (dropwater != null && dropwater.Amount > upperLimit.TotalBetAmount)      //如果跌水规则的金额 > 下注总金额
                {
                    upperLimit.NextLimit = dropwater.Amount;
                    upperLimit.DropValue -= dropwater.DropValue;
                    //防止出现负数
                    if (upperLimit.DropValue < 0)
                        upperLimit.DropValue = 0;
                }
            }
            UpperLimitManager.GetManager().UpdateLimit(upperLimit);
        }
Пример #24
0
 /// <summary>
 /// 检查上限.
 /// </summary>
 /// <param name="order">The order.</param>
 /// <param name="user">The user.</param>
 /// <returns></returns>
 public bool Check(BetOrder order, User user)
 {
     PreLoadUserValidOrder(user);
     bool checkResult;
     checkResult = UserLimiter.Inject(order) && AutoDropLimiter.Inject(order) && UpperLimiter.Inject(order);
     IsDrop = checkResult && (AutoDropLimiter.IsDrop || UpperLimiter.IsDrop);
     return checkResult;
 }
Пример #25
0
 public void RollLimit(BetOrder order)
 {
     if (order.Status != BetStatus.Valid) return;
     UpperLimiter.RollOrderLimit(order);
 }
Пример #26
0
 public override int Calculate(BetOrder order)
 {
     if (!order.Num.IsPL2())
         throw new ApplicationException(string.Format("num:{0} not a pl2 number", order.Num));
     return GetMultiple(order.Num, order.CompanyId);
 }
Пример #27
0
 public void RollOrderLimit(BetOrder order)
 {
 }