Example #1
0
 public static bool AddParticipant(OneyuanTaoParticipantInfo info)
 {
     if (string.IsNullOrEmpty(info.Pid))
     {
         info.Pid = OneyuanTaoHelp.GetOrderNumber(false);
     }
     return(new OneyuanTaoDao().AddParticipant(info));
 }
Example #2
0
        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);
        }
Example #3
0
 private static void DoOneTaoRefund(OneyuanTaoInfo WItem)
 {
     OneyuanTaoHelp.SetOneyuanTaoHasCalculate(WItem.ActivityId);
 }
Example #4
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);
        }
Example #5
0
 public static string getStateStr(OneyuanTaoInfo info)
 {
     return(OneyuanTaoHelp.getOneTaoState(info).ToString());
 }
Example #6
0
 public static bool AddOneyuanTao(OneyuanTaoInfo info)
 {
     info.ActivityId = OneyuanTaoHelp.GetOrderNumber(true);
     return(new OneyuanTaoDao().AddOneyuanTao(info));
 }