Example #1
0
        public void LotteryProcess(UserLottery ul, Prize winprize)
        {
            _context.LotteryRecords.Add(new LotteryRecord
            {
                LotteryID = ul.LotteryID,
                UserID    = ul.UserID,
                Prize     = winprize
            });

            if (winprize.Type == 0 && winprize.Points > 0)
            {
                dynamic extdata = new ExpandoObject();

                extdata.Points    = winprize.Points;
                extdata.ShortMark = winprize.Lottery.Name + "奖励";//"抽奖";

                var res = IntegralProcess(ul.User.UserIntegral, null, extdata);
            }
            else
            {
                if (winprize.Type == 1 && winprize.Coupon != null)
                {
                    var uc = new UserCoupon();

                    uc.Coupon      = winprize.Coupon;
                    uc.User        = ul.User;
                    uc.ExpiredTime = winprize.Coupon.ExpiredTime ?? DateTime.Now.AddDays(winprize.Coupon.ValidDays ?? 30);

                    uc = _context.UserCoupons.Add(uc);
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            FileStream      fs;
            BinaryFormatter bf       = new BinaryFormatter();
            List <User>     userlist = new List <User>();

            number = "190504";
            Regex rans = new Regex(@"\[(?<name>.+?),\s+(?<answer>.+?)\]");

            int answerLength = 0;

            if (File.Exists("users.dat") && File.Exists("lotteries.txt"))
            {
                fs       = new FileStream("users.dat", FileMode.Open, FileAccess.Read);
                userlist = (List <User>)bf.Deserialize(fs);
                fs.Close();
            }
            Lottery lottery = GetLottery();

            if (lottery == null)
            {
                Console.ReadLine();
                return;
            }
            Directory.SetCurrentDirectory(number);
            // UserLottery uly;
            Dictionary <User, string> rawAnswers = new Dictionary <User, string>();

            answerLength = 0;
            foreach (var ans in File.ReadLines("answer.txt"))
            {
                Match  match   = rans.Match(ans);
                string name    = match.Groups["name"].Value;
                User   current = userlist.Find(u => u.Name == name);
                if (current == null)
                {
                    userlist.Add(current = new User(name));
                }
                rawAnswers.Add(current, match.Groups["answer"].Value);
                // uly = new UserLottery(match.Groups["answer"].Value, current, lottery);
                //if (answerLength < match.Groups["answer"].Value.Length)
                //{
                //    answerLength = match.Groups["answer"].Value.Length;
                //}
            }
            lottery.IsSeasonalLottery = true;
            answerLength = 0;
            string[]    lotterylist = new string[] { "190401", "190402", "190403" };
            UserLottery seasonal;

            foreach (User u in userlist)
            {
                var anses = lotterylist.Select(l =>
                {
                    var tmp = u.History.SingleOrDefault(ul => ul.Lottery.Number == l);
                    if (tmp == null)
                    {
                        return("-");
                    }
                    else
                    {
                        return(tmp.RawAnswer.Split("/".ToCharArray()).Last());
                    }
                });
                var seasonalAnswer = anses.Aggregate((a, b) => a + "/" + b);
                if (rawAnswers.ContainsKey(u))
                {
                    seasonalAnswer = rawAnswers[u] + "/" + seasonalAnswer;
                }
                else
                {
                    seasonalAnswer = "-/-/-/-/-/-/" + seasonalAnswer;
                }
                if (seasonalAnswer != "-/-/-/-/-/-/-/-/-")
                {
                    seasonal     = new UserLottery(seasonalAnswer, u, lottery);
                    answerLength = Math.Max(answerLength, seasonalAnswer.Length);
                }
            }
            lottery.UpdateData();
            int m = lottery.Problems.Count(), n = lottery.Count;

            foreach (var p in lottery.Problems)
            {
                Console.WriteLine(p.ScorePercent);
            }
            foreach (var u in lottery.OrderByDescending(u => u.AdjustedScore))
            {
                Console.Write("{0}{1}{2,-8}", padRightEx(u.User.Name, 16), u.RawAnswer.ToString().PadRight(answerLength + 8), u.AdjustedScore.ToString("0.##"));
                foreach (var a in u.Answers)
                {
                    Console.Write("{0,-8}", a.Score.ToString("0.#####"));
                }
                Console.WriteLine("{0,-8}", u.Rank);
            }
            fs = new FileStream("..\\users.dat", FileMode.Create, FileAccess.Write);
            bf.Serialize(fs, userlist);
            fs.Close();
            Console.ReadLine();
        }
Example #3
0
        public BusinessResultDto GetWinPrize(UserLottery ul)
        {
            Prize winprize = null;

            ul.Chance--;

            if (ul.Lottery.CostPoints > 0)
            {
                dynamic extdata = new ExpandoObject();

                extdata.Points    = -ul.Lottery.CostPoints;
                extdata.ShortMark = ul.Lottery.Name;//"抽奖";

                var res = IntegralProcess(ul.User.UserIntegral, null, extdata);
            }

            //var listprize = ul.Lottery.Prizes.Where(t => t.IsValid == true).Select(t => new { t.ID, t.Name, t.WinRate, t.Points, t.CouponID }).ToList();

            var listprize = ul.Lottery.Prizes.Where(t => t.IsValid == true);

            var ratearr = listprize.Select(t => t.WinRate).ToArray();

            var win = RollWinning(ratearr);

            if (win >= 0)
            {
                winprize = listprize.ElementAt(win);
            }

            if (winprize != null)
            {
                LotteryProcess(ul, winprize);
            }


            //_context.LotteryRecords.Add(new LotteryRecord
            //{
            //    LotteryID = ul.LotteryID,
            //    UserID = ul.UserID,
            //    Prize = winprize
            //});

            //if (winprize.Type == 0 && winprize.Points>0)
            //{
            //    dynamic extdata = new ExpandoObject();

            //    extdata.Points = winprize.Points;
            //    extdata.ShortMark = winprize.Lottery.Name;//"抽奖";

            //    var res = IntegralProcess(ul.User.UserIntegral, null, extdata);
            //}


            //return winprize;

            _resultdto.issave  = _isSave;
            _resultdto.message = _message;
            _resultdto.detail  = winprize;

            return(_resultdto);
        }