Exemple #1
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);
            }
        }
        /// <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);
            }
        }
Exemple #3
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);
            }
        }