예제 #1
0
        /// <summary>
        /// 奖品发放节流
        /// </summary>
        public bool Throttling()
        {
            //节流比例
            var throttling = Common.TypeHelper.StringToInt(WebFramework.GeneralMethodBase.GetKeyConfig(50).Val);

            if (throttling > 0)
            {
                Common.Prize prize = new Common.Prize(throttling, 0, 0, 0, 0, 0, 100 - throttling);

                if (prize.GetPrize()[0] == "一等奖")
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// 添加虚拟订单
        /// </summary>
        /// <param name="model">订单</param>
        public void AddFictitiousOrder(Model.OrderInfoModel model)
        {
            //虚拟比例
            var Fictitious = Common.TypeHelper.StringToInt(WebFramework.GeneralMethodBase.GetKeyConfig(51).Val);

            if (Fictitious > 0)
            {
                var task = Task.Factory.StartNew(() =>
                {
                    Common.Prize prize = new Common.Prize(Fictitious, 0, 0, 0, 0, 0, 100 - Fictitious);

                    //奖项为一等奖时添加虚拟订单
                    if (prize.GetPrize()[0] == "参与奖")
                    {
                        return;
                    }

                    Model.FictitiousOrderModel FictitiousModel = new Model.FictitiousOrderModel();
                    FictitiousModel.OrderCode    = model.OrderCode;
                    FictitiousModel.Jx           = model.Jx;
                    FictitiousModel.Jp           = model.Jp;
                    FictitiousModel.DateStamp    = model.DateStamp;
                    FictitiousModel.Ip           = model.Ip;
                    FictitiousModel.IpAddress    = model.IpAddress;
                    FictitiousModel.CreateTime   = model.CreateTime;
                    FictitiousModel.OpenId       = model.OpenId;
                    FictitiousModel.Mob          = model.Mob;
                    FictitiousModel.Code         = model.Code;
                    FictitiousModel.States       = model.States;
                    FictitiousModel.HbOrderCode  = model.HbOrderCode;
                    FictitiousModel.RedPackMoney = model.RedPackMoney;

                    new Db.FictitiousOrderDal().Add(FictitiousModel);
                });
            }
        }
예제 #3
0
        /// <summary>
        /// 获取奖项(最多7个)
        /// </summary>
        /// <param name="PrizeCont">奖项总个数(最多7个)</param>
        /// <param name="AwardsType">抽奖类型 1:常规奖 2:红包奖</param>
        /// <returns>奖项</returns>
        public static Model.AwardsStatisticsModel GetPrize(int PrizeCont, int AwardsType)
        {
            if (PrizeCont > 7)
            {
                return(null);
            }

            Db.AwardsStatisticsDal AwardsDal = new Db.AwardsStatisticsDal();
            Db.ZpConfigDal         dal       = new Db.ZpConfigDal();
            Model.ZpConfigModel    m         = dal.GetModel(AwardsType);

            #region 获取所有奖项设置值

            #region 奖项每天总数
            int[] PrizeDayCont = new int[] { m.Zjl7, m.Zjl9, m.Zjl11, m.Zjl13, m.Zjl15, m.Zjl17 };
            #endregion

            #region 奖项总数
            int[] PrizeAllCont = new int[] { m.Zjl8, m.Zjl10, m.Zjl12, m.Zjl14, m.Zjl16, m.Zjl18 };
            #endregion

            #region 奖项预设中奖率

            int[] PresetProbability = new int[] { m.Zjl1, m.Zjl2, m.Zjl3, m.Zjl4, m.Zjl5, m.Zjl6 };
            #endregion

            #region 奖项实际中奖率
            int[] ActualProbability = new int[] { 0, 0, 0, 0, 0, 0 };
            #endregion

            #endregion

            #region 获取奖项统计参与详细
            List <Model.AwardsStatisticsModel> AwardsList = AwardsDal.GetModelList(string.Format(" and AwardsType={0} order by id", AwardsType));
            #endregion

            #region 获取奖项实际参与量与预设奖项总量比较后的中奖率
            for (int i = 0; i < PrizeCont - 1; i++)
            {
                ActualProbability[i] = PresetProbability[i];

                Model.AwardsStatisticsModel model = AwardsList.Where(w => w.AwardsId == i + 1).FirstOrDefault();//获取奖项参与详情
                if (model == null)
                {
                    throw new ArgumentNullException("获取奖项失败");
                }

                #region 如果当前奖项日期不等于当天,则每日总数为0
                if (model.DateStamp != DateTime.Now.ToShortDateString())
                {
                    model.TodayTotal = 0;
                }
                #endregion

                if (model.TodayTotal >= PrizeDayCont[i] || model.AllTotal - model.BackTotal >= PrizeAllCont[i])
                {
                    ActualProbability[i] = 0;
                }
            }
            #endregion

            #region 抽奖
            int          seven = 100 - ActualProbability[0] - ActualProbability[1] - ActualProbability[2] - ActualProbability[3] - ActualProbability[4] - ActualProbability[5];
            Common.Prize prize = new Common.Prize(ActualProbability[0], ActualProbability[1], ActualProbability[2], ActualProbability[3], ActualProbability[4], ActualProbability[5], seven);
            #endregion

            #region 赋值中奖详情-奖项-角度-奖品名称-奖项Id
            string[] PrizeModel = prize.GetPrize();

            Model.AwardsStatisticsModel AwardsPrizeModel = AwardsList.Where(s => s.AwardsName == PrizeModel[0]).FirstOrDefault();
            if (AwardsPrizeModel == null)
            {
                throw new ArgumentNullException("获取奖项失败");
            }

            AwardsPrizeModel.Angle = PrizeModel[1];//角度
            #endregion

            return(AwardsPrizeModel);
        }