コード例 #1
0
ファイル: OneyuanTaoHelp.cs プロジェクト: 123456-cq/xkq34_src
        public static string CalculateWinner([Optional, DefaultParameterValue("")] string ActivityId)
        {
            string str = "0";

            if (Monitor.TryEnter(Calculate))
            {
                try
                {
                    try
                    {
                        IList <OneyuanTaoInfo> oneyuanTaoInfoNotCalculate;
                        if (string.IsNullOrEmpty(ActivityId))
                        {
                            oneyuanTaoInfoNotCalculate = new OneyuanTaoDao().GetOneyuanTaoInfoNotCalculate();
                        }
                        else
                        {
                            oneyuanTaoInfoNotCalculate = new List <OneyuanTaoInfo> {
                                GetOneyuanTaoInfoById(ActivityId)
                            };
                        }
                        foreach (OneyuanTaoInfo info in oneyuanTaoInfoNotCalculate)
                        {
                            str = "1";
                            if (info.FinishedNum == 0)
                            {
                                SetOneyuanTaoHasCalculate(info.ActivityId);
                            }
                            else if (info.HasCalculate)
                            {
                                str = "success";
                            }
                            else if ((((info.ReachType == 1) && (info.FinishedNum >= info.ReachNum)) || (info.ReachType == 2)) || ((info.ReachType == 3) && (info.FinishedNum >= info.ReachNum)))
                            {
                                str = DoOneTaoDrawLottery(info);
                            }
                            else
                            {
                                str = "未满足开奖条件,开奖失败";
                                DoOneTaoRefund(info);
                            }
                        }
                        return(str);
                    }
                    catch (Exception)
                    {
                        str = "0";
                    }
                    return(str);
                }
                finally
                {
                    Monitor.Exit(Calculate);
                }
                return(str);
            }
            return("计算工作已启动,请等待计算开奖结果!");
        }
コード例 #2
0
ファイル: OneyuanTaoHelp.cs プロジェクト: llenroc/kangaroo
        public static string CalculateWinner(string ActivityId = "")
        {
            string result = "0";

            if (Monitor.TryEnter(OneyuanTaoHelp.Calculate))
            {
                try
                {
                    IList <OneyuanTaoInfo> list;
                    if (string.IsNullOrEmpty(ActivityId))
                    {
                        list = new OneyuanTaoDao().GetOneyuanTaoInfoNotCalculate();
                    }
                    else
                    {
                        list = new List <OneyuanTaoInfo>();
                        list.Add(OneyuanTaoHelp.GetOneyuanTaoInfoById(ActivityId));
                    }
                    foreach (OneyuanTaoInfo current in list)
                    {
                        result = "1";
                        if (current.FinishedNum == 0)
                        {
                            OneyuanTaoHelp.SetOneyuanTaoHasCalculate(current.ActivityId);
                        }
                        else if (current.HasCalculate)
                        {
                            result = "success";
                        }
                        else if ((current.ReachType == 1 && current.FinishedNum >= current.ReachNum) || current.ReachType == 2 || (current.ReachType == 3 && current.FinishedNum >= current.ReachNum))
                        {
                            result = OneyuanTaoHelp.DoOneTaoDrawLottery(current);
                        }
                        else
                        {
                            result = "未满足开奖条件,开奖失败";
                            OneyuanTaoHelp.DoOneTaoRefund(current);
                        }
                    }
                }
                catch (Exception var_3_134)
                {
                    result = "0";
                }
                finally
                {
                    Monitor.Exit(OneyuanTaoHelp.Calculate);
                }
            }
            else
            {
                result = "计算工作已启动,请等待计算开奖结果!";
            }
            return(result);
        }
コード例 #3
0
ファイル: OneyuanTaoHelp.cs プロジェクト: llenroc/kangaroo
        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);
        }
コード例 #4
0
ファイル: OneyuanTaoHelp.cs プロジェクト: 123456-cq/xkq34_src
        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);
        }