Beispiel #1
0
        private static string DoOneTaoDrawLottery(OneyuanTaoInfo WItem)
        {
            string   result           = "开奖失败";
            DateTime now              = DateTime.Now;
            int      participantCount = new OneyuanTaoDao().GetParticipantCount();

            if (participantCount < 50 + WItem.PrizeNumber)
            {
                OneyuanTaoHelp.AddInitParticipantInfo(50);
            }
            Dictionary <long, bool> dictionary = new Dictionary <long, bool>();

            dictionary.Clear();
            IList <Top50ParticipantInfo> top50ParticipantList = new OneyuanTaoDao().GetTop50ParticipantList(now, 50);

            while (true)
            {
                long num = 0L;
                foreach (Top50ParticipantInfo current in top50ParticipantList)
                {
                    num += long.Parse(current.BuyTime.ToString("Hmmssfff"));
                }
                long num2 = num % long.Parse(WItem.FinishedNum.ToString());
                long key  = 10000001L + num2;
                if (!dictionary.ContainsKey(key))
                {
                    dictionary.Add(key, true);
                    Top50ParticipantInfo top50ParticipantInfo = top50ParticipantList.Last <Top50ParticipantInfo>();
                    top50ParticipantInfo.PrizeLuckInfo = string.Format("{0},{1},{2},{3}", new object[]
                    {
                        key.ToString(),
                        num,
                        WItem.FinishedNum,
                        num2
                    });
                }
                else
                {
                    Top50ParticipantInfo top50ParticipantInfo = top50ParticipantList.Last <Top50ParticipantInfo>();
                    top50ParticipantInfo.PrizeLuckInfo = string.Format("{0}重复,{1},{2},{3},", new object[]
                    {
                        key.ToString(),
                        num,
                        WItem.FinishedNum,
                        num2
                    });
                }
                if (dictionary.Count >= WItem.PrizeNumber)
                {
                    break;
                }
                Top50ParticipantInfo nextParticipant = new OneyuanTaoDao().GetNextParticipant(now, top50ParticipantList.Last <Top50ParticipantInfo>().Pid);
                if (nextParticipant == null)
                {
                    break;
                }
                top50ParticipantList.Add(nextParticipant);
            }
            IsoDateTimeConverter isoDateTimeConverter = new IsoDateTimeConverter();

            isoDateTimeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
            if (dictionary.Count != WItem.PrizeNumber)
            {
                result = "订单数据不足,无法开出指定数量的中奖号!";
                new OneyuanTaoDao().SetErrPrizeCountInfo(WItem.ActivityId, JsonConvert.SerializeObject(top50ParticipantList, new JsonConverter[]
                {
                    isoDateTimeConverter
                }));
            }
            else
            {
                result = "success";
                if (OneyuanTaoHelp.SetOneyuanTaoPrizeTime(WItem.ActivityId, now, JsonConvert.SerializeObject(top50ParticipantList, new JsonConverter[]
                {
                    isoDateTimeConverter
                })))
                {
                    foreach (KeyValuePair <long, bool> current2 in dictionary)
                    {
                        OneyuanTaoHelp.setWin(current2.Key.ToString(), WItem.ActivityId);
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        private static string DoOneTaoDrawLottery(OneyuanTaoInfo WItem)
        {
            string   str = "开奖失败";
            DateTime now = DateTime.Now;

            if (new OneyuanTaoDao().GetParticipantCount() < (50 + WItem.PrizeNumber))
            {
                AddInitParticipantInfo(50);
            }
            Dictionary <long, bool> dictionary = new Dictionary <long, bool>();

            dictionary.Clear();
            IList <Top50ParticipantInfo> source = new OneyuanTaoDao().GetTop50ParticipantList(now, 50);

            while (true)
            {
                long num2 = 0L;
                foreach (Top50ParticipantInfo info in source)
                {
                    num2 += long.Parse(info.BuyTime.ToString("Hmmssfff"));
                }
                long num3 = num2 % long.Parse(WItem.FinishedNum.ToString());
                long key  = 0x989681L + num3;
                if (!dictionary.ContainsKey(key))
                {
                    dictionary.Add(key, true);
                    source.Last <Top50ParticipantInfo>().PrizeLuckInfo = string.Format("{0},{1},{2},{3}", new object[] { key.ToString(), num2, WItem.FinishedNum, num3 });
                }
                else
                {
                    source.Last <Top50ParticipantInfo>().PrizeLuckInfo = string.Format("{0}重复,{1},{2},{3},", new object[] { key.ToString(), num2, WItem.FinishedNum, num3 });
                }
                if (dictionary.Count >= WItem.PrizeNumber)
                {
                    break;
                }
                Top50ParticipantInfo nextParticipant = new OneyuanTaoDao().GetNextParticipant(now, source.Last <Top50ParticipantInfo>().Pid);
                if (nextParticipant == null)
                {
                    break;
                }
                source.Add(nextParticipant);
            }
            IsoDateTimeConverter converter = new IsoDateTimeConverter {
                DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff"
            };

            if (dictionary.Count != WItem.PrizeNumber)
            {
                str = "订单数据不足,无法开出推定数量的奖项,请查看开奖未计算过程";
                new OneyuanTaoDao().SetErrPrizeCountInfo(WItem.ActivityId, JsonConvert.SerializeObject(source, new JsonConverter[] { converter }));
                return(str);
            }
            str = "success";
            if (SetOneyuanTaoPrizeTime(WItem.ActivityId, now, JsonConvert.SerializeObject(source, new JsonConverter[] { converter })))
            {
                foreach (KeyValuePair <long, bool> pair in dictionary)
                {
                    setWin(pair.Key.ToString(), WItem.ActivityId);
                }
            }
            return(str);
        }