Ejemplo n.º 1
0
        /// <summary>
        /// 获取一个随机日志实体
        /// </summary>
        /// <param name="WheelID"></param>
        /// <returns></returns>
        public WheelLog GetWheelCode(Guid WheelID, string UserWexinID)
        {
            var Wheel = WheelRepository.GetByKey(WheelID);
            var users = WheelUserRepository.FindAll(Specification<WheelUser>.Eval(o => o.WheelID == Wheel.WheelID)).ToList();
            var userWheelCodes = users.Select(o => o.WheelCode).ToList();
            //获取奖品的概率容量
            int container = Wheel.WheelScale;
            var WheelItems = Wheel.WheelItems.ToList();

            for (int i = 0; i < WheelItems.Count; i++)
            {
                container = container - WheelItems[i].WheelItemScale;
            }

            //设定一个string动态数组 添加中奖代号
            List<WheelLog> WheelCodes = new List<WheelLog>();
            for (int i = 0; i < WheelItems.Count; i++)
            {
                //剩余奖品数量
                var k = i + 1;
                var itemlogs = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.IsAward == k)).ToList();
                var sum = WheelItems[i].WheelItemScale - itemlogs.Count;
                for (int j = 0; j < sum; j++)
                {
                    WheelLog log = new WheelLog();
                    log.WheelCode = Function.GuidTo16String(Guid.NewGuid());
                    log.IsAward = k;
                    log.AddDate = DateTime.Now;
                    log.WheelID = Wheel.WheelID;
                    log.WheelUserWexinID = UserWexinID;
                    WheelCodes.Add(log);
                }
            }

            int AwardingNum = WheelCodes.Count();
            Random rd = new Random();
            int rdnum = rd.Next(1, container + AwardingNum);
            if (rdnum <= AwardingNum)
            {
                return WheelCodes[rdnum - 1];
            }
            else
            {
                return new WheelLog()
                {
                    WheelUserWexinID = UserWexinID,
                    IsAward = 0,
                    AddDate = DateTime.Now,
                    WheelID = Wheel.WheelID,
                    WheelCode = "0"
                };
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public JsonResult GetWheelitem(Guid WheelID, string UserWexinID = "")
        {
            var Wheel = WheelRepository.GetByKey(WheelID);
            if (Request.UserAgent.ToLower().IndexOf("micromessenger") == -1)
            {
                return Json(new { message = "每日只能提交" + Wheel.EveryDayTimes.ToString() + "次." }, JsonRequestBehavior.AllowGet);
            }

            var ip = Request.UserHostAddress;
            var dt = DateTime.Now.Date;
            //清理过期未领取的奖品
            ClearExpiredAward(WheelID);
            //GetWheelCode(WheelID, UserWexinID);
            //添加日志
            WheelLog WheelCode;
            var logs = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.IsAward > 0)).ToList();
            // var users = WheelUserRepository.FindAll(Specification<WheelUser>.Eval(o => o.WheelID == Wheel.WheelID)).ToList();
            int num = 0;
            foreach (var item in Wheel.WheelItems)
            {
                num += item.WheelItemScale;
            }

            // if (logs.Count >= num)
            if (logs.Count >= num)
            {
                WheelCode = new WheelLog();
                WheelCode.WheelCode = "0";
                WheelCode.IsAward = 0;
                WheelCode.AddDate = DateTime.Now;
                WheelCode.WheelID = Wheel.WheelID;
                WheelCode.WheelUserWexinID = UserWexinID;
            }
            else
            {
                WheelCode = GetWheelCode(WheelID, UserWexinID);
            }

            //var WheelCode = GetWheelCode(WheelID);
            WheelCode.IP = ip;
            Session["WheelCode"] = WheelCode;
            int IsAward = WheelCode.IsAward;
            WheelItemViewModel Wheelitem = new WheelItemViewModel();
            if (IsAward > 0)
            {
                var Si = Wheel.WheelItems.ToList()[IsAward - 1];
                Wheelitem = Mapper.Map<WheelItem, WheelItemViewModel>(Si);
                Wheelitem.WheelCode = WheelCode.WheelCode;
            }
            else
            {
                //由于大转盘有十二个位置点,按照索引从0开始到11,其中,0,4,8为中将点,所以设置一个没有0,4,8的不中间数组,而后进行随机处理
                int[] arr = { 1, 2, 3, 5, 6, 7, 9, 10, 11 };
                Random randow = new Random();
                int ran = randow.Next(0, arr.Length - 1);
                string Angle = GetAngle(arr[ran], 12, 5);
                Wheelitem.WheelCode = WheelCode.WheelCode;
                Wheelitem.WheelItemID = IsAward;
                Wheelitem.MaxAngle = Angle.Split('|')[1];
                Wheelitem.MinAngle = Angle.Split('|')[0];
                Wheelitem.WheelItemName = "谢谢惠顾";
            }

            var log = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelUserWexinID == UserWexinID && o.AddDate > dt && o.WheelID == Wheel.WheelID)).ToList();
            if (log.Count < Wheel.EveryDayTimes && Wheel.StartDate < DateTime.Now && Wheel.EndDate.AddDays(1) > DateTime.Now)
            {
                ///日志记录
                WheelLogRepository.Add(WheelCode);
                WheelLogRepository.Context.Commit();
                return Json(Wheelitem);
            }
            else if (DateTime.Now < Wheel.StartDate)
            {
                return Json(new { message = "活动暂未开始,敬请期待!" }, JsonRequestBehavior.AllowGet);
            }
            else if (DateTime.Now > Wheel.EndDate.AddDays(1))
            {
                return Json(new { message = "活动已经结束了!" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { message = "每日只能提交" + Wheel.EveryDayTimes.ToString() + "次" }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 3
0
        public JsonResult GetGift(Guid WheelID, string UserWexinID = "")
        {
            var ip = Request.UserHostAddress;
            var dt = DateTime.Now.Date;
            var Wheel = WheelRepository.GetByKey(WheelID);
            GetGiftCode(WheelID);//调用此方法是为了去检查是否有抢到红包没有提交用户信息,然而删除,空出名额
            //添加日志
            WheelLog WheelCode;
            string sdate = DateTime.Now.ToString("yyyy-MM-dd");
            DateTime ddate = Convert.ToDateTime(sdate);

            //获取当天中奖人数
            var logs = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.IsAward > 0 && o.AddDate >= ddate && o.AddDate < ddate.AddDays(1))).ToList();

            //循环相加获取出后台设置好的奖品数量
            int num = 0;
            foreach (var item in Wheel.WheelItems)
            {
                num += item.WheelItemScale;
            }

            var IsChou = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.WheelUserWexinID == UserWexinID && o.AddDate >= ddate && o.AddDate < ddate.AddDays(1))).ToList();
            var IsShare = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.WheelUserWexinID == UserWexinID && o.IsShare == 1 && o.AddDate >= ddate && o.AddDate < ddate.AddDays(1))).ToList();
            var IsAwards = WheelUserRepository.FindAll(Specification<WheelUser>.Eval(o => o.WheelID == Wheel.WheelID && o.WheelUserWexinID == UserWexinID)).ToList();
            var weiUser = RecordWUserRepository.FindAll(Specification<RecordWUser>.Eval(o => o.FromUserName == UserWexinID)).ToList();
            //判断是否关注从来没有抽过,或者是抽过一次,但是分享了
            if ((weiUser.Count > 0 && IsChou.Count < 0) || (IsChou.Count == 1 && IsShare.Count > 0))
            {
                //判断中过多少次奖
                if (IsAwards.Count < 2)
                {
                    //判断奖品数量是否超过指定
                    if (logs.Count < num)
                    {
                        //防止并发
                        Random rm = new Random();
                        Thread.Sleep(rm.Next(500, 1000));
                        WheelCode = GetGiftCode(WheelID);
                    }
                    else
                    {
                        WheelCode = new WheelLog();
                        WheelCode.WheelCode = "0";
                        WheelCode.IsAward = 0;
                        WheelCode.AddDate = DateTime.Now;
                        WheelCode.WheelID = Wheel.WheelID;
                    }
                }
                else
                {
                    WheelCode = new WheelLog();
                    WheelCode.WheelCode = "0";
                    WheelCode.IsAward = 0;
                    WheelCode.AddDate = DateTime.Now;
                    WheelCode.WheelID = Wheel.WheelID;
                }
            }
            else
            {
                WheelCode = new WheelLog();
                WheelCode.WheelCode = "0";
                WheelCode.IsAward = 0;
                WheelCode.AddDate = DateTime.Now;
                WheelCode.WheelID = Wheel.WheelID;
            }

            WheelCode.IP = ip;
            Session["WheelCode"] = WheelCode;

            //判断随机产生的日志实体是否中奖
            int IsAward = WheelCode.IsAward;
            WheelItemViewModel Wheelitem = new WheelItemViewModel();
            if (IsAward > 0)
            {
                var Si = Wheel.WheelItems.ToList()[IsAward - 1];
                Wheelitem = Mapper.Map<WheelItem, WheelItemViewModel>(Si);
                Wheelitem.WheelCode = WheelCode.WheelCode;
            }
            else
            {
                Wheelitem.WheelCode = WheelCode.WheelCode;
                Wheelitem.WheelItemID = IsAward;
                Wheelitem.MaxAngle = "";
                Wheelitem.MinAngle = "";
                Wheelitem.WheelItemName = "没有抽中";
            }

            if (IsChou.Count < Wheel.EveryDayTimes && Wheel.StartDate < DateTime.Now && Wheel.EndDate.AddDays(1) > DateTime.Now)
            {
                ///日志记录
                WheelLogRepository.Add(WheelCode);
                WheelLogRepository.Context.Commit();
                return Json(Wheelitem);
            }
            else if (logs.Count > 20)
            {
                return Json(new { message = "今日红包已经抢完!" }, JsonRequestBehavior.AllowGet);
            }
            else if (DateTime.Now < Wheel.StartDate)
            {
                return Json(new { message = "活动暂未开始,敬请期待!" }, JsonRequestBehavior.AllowGet);
            }
            else if (DateTime.Now > Wheel.EndDate.AddDays(1))
            {
                return Json(new { message = "活动已经结束了!" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { message = "每日最多抢" + Wheel.EveryDayTimes.ToString() + "次" }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public JsonResult GetGiftitem(Guid WheelID, string UserWexinID = "")
        {
            var ip = Request.UserHostAddress;
            var dt = DateTime.Now.Date;
            var Wheel = WheelRepository.GetByKey(WheelID);
            GetGiftCode(WheelID);
            //添加日志
            WheelLog WheelCode;
            string sdate = DateTime.Now.ToString("yyyy-MM-dd");
            DateTime ddate = Convert.ToDateTime(sdate);
            var logs = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.IsAward > 0 && o.AddDate >= ddate && o.AddDate < ddate.AddDays(1))).ToList();

            var IsChou = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.WheelUserWexinID == UserWexinID)).ToList();
            int num = 0;
            int mm = 0;
            foreach (var item in IsChou)
            {
                if (item.IsShare > 0)
                {
                    mm += item.IsShare;
                }
            }

            foreach (var item in Wheel.WheelItems)
            {
                num += item.WheelItemScale;
            }

            if (logs.Count >= num)
            {
                WheelCode = new WheelLog();
                WheelCode.WheelCode = "0";
                WheelCode.IsAward = 0;
                WheelCode.AddDate = DateTime.Now;
                WheelCode.WheelID = Wheel.WheelID;
            }
            else
            {
                WheelCode = GetGiftCode(WheelID);
            }

            WheelCode.IP = ip;
            Session["WheelCode"] = WheelCode;

            int IsAward = WheelCode.IsAward;
            WheelItemViewModel Wheelitem = new WheelItemViewModel();
            if (IsAward > 0)
            {
                var Si = Wheel.WheelItems.ToList()[IsAward - 1];
                Wheelitem = Mapper.Map<WheelItem, WheelItemViewModel>(Si);
                Wheelitem.WheelCode = WheelCode.WheelCode;
            }
            else
            {
                Wheelitem.WheelCode = WheelCode.WheelCode;
                Wheelitem.WheelItemID = IsAward;
                Wheelitem.MaxAngle = "";
                Wheelitem.MinAngle = "";
                Wheelitem.WheelItemName = "没有抽中";
            }

            var log = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelUserWexinID == UserWexinID && o.AddDate > dt && o.WheelID == Wheel.WheelID)).ToList();
            if (log.Count < Wheel.EveryDayTimes && Wheel.StartDate < DateTime.Now && Wheel.EndDate.AddDays(1) > DateTime.Now)
            {
                ///日志记录
                WheelLogRepository.Add(WheelCode);
                WheelLogRepository.Context.Commit();
                return Json(Wheelitem);
            }
            else if (logs.Count > 20)
            {
                return Json(new { message = "今日红包已经抢完!" }, JsonRequestBehavior.AllowGet);
            }
            else if (DateTime.Now < Wheel.StartDate)
            {
                return Json(new { message = "活动暂未开始,敬请期待!" }, JsonRequestBehavior.AllowGet);
            }
            else if (DateTime.Now > Wheel.EndDate.AddDays(1))
            {
                return Json(new { message = "活动已经结束了!" }, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { message = "每日最多抢两次" + Wheel.EveryDayTimes.ToString() + "次" }, JsonRequestBehavior.AllowGet);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取一个随机日志实体
        /// </summary>
        /// <param name="WheelID"></param>
        /// <returns></returns>
        public WheelLog GetGiftCode(Guid WheelID)
        {
            //DateTime dt = DateTime.Now.AddHours(-1);
            DateTime dt = DateTime.Now.AddMinutes(-10);
            var Wheel = WheelRepository.GetByKey(WheelID);
            var users = WheelUserRepository.FindAll(Specification<WheelUser>.Eval(o => o.WheelID == Wheel.WheelID)).ToList();
            //清理日志  如果用户中奖 两个小时里没有提交信息 就将日志其删除
            var logs = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.IsAward > 0 && o.AddDate < dt)).ToList();
            foreach (var item in logs)
            {
                if (!users.Exists(o => o.WheelLogID == item.WheelLogID))
                {
                    WheelLogRepository.Remove(item);
                    WheelLogRepository.Context.Commit();
                }
            }
            var userWheelCodes = users.Select(o => o.WheelCode).ToList();
            //获取奖品的概率容量
            int container = Wheel.WheelScale;
            var WheelItems = Wheel.WheelItems.ToList();

            for (int i = 0; i < WheelItems.Count; i++)
            {
                container = container - WheelItems[i].WheelItemScale;
            }
            //设定一个string动态数组 添加中奖代号
            List<WheelLog> WheelCodes = new List<WheelLog>();
            for (int i = 0; i < WheelItems.Count; i++)
            {
                //剩余奖品数量
                var k = i + 1;
                var itemlogs = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.IsAward == k)).ToList();
                var sum = WheelItems[i].WheelItemScale - itemlogs.Count;
                for (int j = 0; j < sum; j++)
                {
                    WheelLog log = new WheelLog();
                    log.WheelCode = Function.GuidTo16String(Guid.NewGuid());
                    log.IsAward = k;
                    log.AddDate = DateTime.Now;
                    log.WheelID = Wheel.WheelID;
                    WheelCodes.Add(log);
                }
            }
            if (container > 0)
            {
                for (int i = 0; i < container; i++)
                {
                    WheelLog log = new WheelLog();
                    log.WheelCode = "0";
                    log.IsAward = 0;
                    log.AddDate = DateTime.Now;
                    log.WheelID = Wheel.WheelID;
                    WheelCodes.Add(log);
                }
            }
            //获取一个随机数 随机抽奖
            Random randow = new Random();
            int ran = randow.Next(0, WheelCodes.Count - 1);
            return WheelCodes[ran];
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public JsonResult GetEggitem(Guid WheelID, string UserWexinID = "")
        {
            var ip = Request.UserHostAddress;
            var dt = DateTime.Now.Date;
            var Wheel = WheelRepository.GetByKey(WheelID);
            GetEggCode(WheelID);//调用此方法是为了去检查是否有砸中了有奖金蛋没有提交用户信息,然而删除,空出名额
            //添加日志
            WheelLog WheelCode;
            string sdate = DateTime.Now.ToString("yyyy-MM-dd");
            DateTime ddate = Convert.ToDateTime(sdate);

            //获取中奖人数
            var logs = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.IsAward > 0)).ToList();

            //循环相加获取出后台设置好的奖品数量
            int num = 0;
            foreach (var item in Wheel.WheelItems)
            {
                num += item.WheelItemScale;
            }

            //var IsChou = WheelLogRepository.FindAll(Specification<WheelLog>.Eval(o => o.WheelID == Wheel.WheelID && o.WheelUserWexinID == UserWexinID)).ToList();
            var weiUser = PayCustomerRepository.FindAll(Specification<PayCustomer>.Eval(o => o.OpendId == UserWexinID)).ToList();
            var IsAwad = PayCustomerRepository.FindAll(Specification<PayCustomer>.Eval(o => o.OpendId == UserWexinID && o.IsAward == 0)).SingleOrDefault();

            //判断是否支付成功从来没有抽过
            if ((weiUser.Count > 0 && IsAwad != null))
            {
                //判断奖品数量是否超过指定
                if (logs.Count < num)
                {
                    //防止并发
                    Random rm = new Random();
                    Thread.Sleep(rm.Next(500, 1000));
                    WheelCode = GetEggCode(WheelID);
                }
                else
                {
                    WheelCode = new WheelLog();
                    WheelCode.WheelCode = "0";
                    WheelCode.IsAward = 0;
                    WheelCode.AddDate = DateTime.Now;
                    WheelCode.WheelID = Wheel.WheelID;
                }
            }
            else
            {
                WheelCode = new WheelLog();
                WheelCode.WheelCode = "0";
                WheelCode.IsAward = 0;
                WheelCode.AddDate = DateTime.Now;
                WheelCode.WheelID = Wheel.WheelID;
            }

            WheelCode.IP = ip;
            Session["WheelCode"] = WheelCode;

            //判断随机产生的日志实体是否中奖
            int IsAward = WheelCode.IsAward;
            EggItemViewModel Eggitem = new EggItemViewModel();

            if (IsAward > 0)
            {
                var Si = Wheel.WheelItems.ToList()[IsAward - 1];
                //Eggitem = Mapper.Map<WheelItem, WheelItemViewModel>(Si);
                Eggitem.nickname = IsAwad.nickname;
                Eggitem.WheelItemName = Si.WheelItemName;
                Eggitem.WheelItemAward = Si.WheelItemAward;
                Eggitem.WheelCode = WheelCode.WheelCode;
                Eggitem.WheelItemID = IsAward;
            }
            else
            {
                Eggitem.WheelCode = WheelCode.WheelCode;
                Eggitem.WheelItemID = IsAward;
                Eggitem.WheelItemName = "没有砸中!";
                Eggitem.nickname = IsAwad.nickname;
            }

            if (IsAwad != null && Wheel.StartDate < DateTime.Now && Wheel.EndDate.AddDays(1) > DateTime.Now)
            {
                //支付记录修改
                IsAwad.IsAward = 1;
                PayCustomerRepository.Update(IsAwad);
                PayCustomerRepository.Context.Commit();
                ///日志记录
                WheelLogRepository.Add(WheelCode);
                WheelLogRepository.Context.Commit();
                return Json(Eggitem);
            }
            else if (logs.Count > 1)
            {
                return Json(new { message = "只有一次砸金蛋的机会!" }, JsonRequestBehavior.AllowGet);
            }
            //else if (DateTime.Now < Wheel.StartDate)
            //{
            //    return Json(new { message = "活动暂未开始,敬请期待!" }, JsonRequestBehavior.AllowGet);

            //}
            //else if (DateTime.Now > Wheel.EndDate.AddDays(1))
            //{
            //    return Json(new { message = "活动已经结束了!" }, JsonRequestBehavior.AllowGet);
            //}
            else
            {
                return null;
            }
        }