Beispiel #1
0
        public ActionResult Add(long id, long userId)
        {
            WeiActivityModel activityModel = WeiActivityApplication.GetActivityModel(id);

            activityWinModel = new WeiActivityWinModel();
            Random r   = new Random();
            int    num = r.Next(1, 100);//获取随机数做为中奖信息

            activityWinModel.activityId = id;
            activityWinModel.addDate    = DateTime.Now;
            activityWinModel.userId     = userId;
            activityWinModel.integrals  = activityModel.consumePoint;
            //int activityNum = 0;

            activityWinModel.isWin     = false;
            activityWinModel.awardId   = 0;
            activityWinModel.awardName = "未中奖";
            foreach (var item in activityModel.awards)
            {
                //累加计算奖等区域
                //activityNum = activityNum + GetCount(activityModel.Id, item.Id);
                //获取的随机数在该奖等区域类
                if (num <= GetCount(activityModel.Id, item.Id))
                {
                    activityWinModel.isWin = true;

                    if (item.awardType == WeiActivityAwardType.Integral)
                    {
                        activityWinModel.awardName = item.integral.ToString();
                        activityWinModel.awardId   = item.Id;
                        activityWinModel.awardType = item.awardType;
                        break;
                    }
                    else if (item.awardType == WeiActivityAwardType.Bonus)
                    {
                        Entities.BonusInfo bonusInfo = _iBonusService.Get(item.bonusId);
                        if (bonusInfo == null)
                        {
                            //activityNum = 0;
                            activityWinModel.isWin = false;
                            break;
                        }
                        string Surplus = _iBonusService.GetBonusSurplus(item.bonusId);
                        if (bonusInfo.IsInvalid)//红包已经失效 返回 未中奖
                        {
                            //activityNum = 0;
                            activityWinModel.isWin = false;
                            break;
                        }
                        if (Convert.ToInt32(Surplus) <= 0)//当前红包已经领取完 设置未中奖
                        {
                            //activityNum = 0;
                            activityWinModel.isWin = false;
                            break;
                        }

                        //获取红包名称
                        activityWinModel.awardName = bonusInfo.Name;
                        activityWinModel.awardId   = item.Id;
                        activityWinModel.awardType = item.awardType;
                        activityWinModel.bonusId   = item.bonusId;
                        break;
                    }
                    else if (item.awardType == WeiActivityAwardType.Coupon)
                    {
                        CouponModel couponModel = CouponApplication.Get(item.couponId);
                        if (couponModel == null)
                        {
                            //activityNum = 0;
                            activityWinModel.isWin = false;
                            break;
                        }
                        int perMax = WeiActivityApplication.GetCouPonMax(activityWinModel.userId, activityWinModel.activityId, item.Id);
                        if (couponModel.Num <= 0)//优惠券无库存 返回 未中奖
                        {
                            //activityNum = 0;
                            activityWinModel.isWin = false;
                            break;
                        }
                        if (couponModel.perMax != 0 && perMax >= couponModel.perMax)
                        {
                            //activityNum = 0;
                            activityWinModel.isWin = false;
                            break;
                        }
                        if (couponModel.EndTime < DateTime.Now)//优惠券已经失效
                        {
                            //activityNum = 0;
                            activityWinModel.isWin = false;
                            break;
                        }

                        string awardName = couponModel.CouponName;
                        if (couponModel.ShopName != "")
                        {
                            awardName = awardName + "(" + couponModel.ShopName + ")";
                        }
                        if (couponModel.OrderAmount != "")
                        {
                            awardName = awardName + "(" + couponModel.OrderAmount + ")";
                        }
                        //获取红包名称
                        activityWinModel.awardName = awardName;
                        activityWinModel.awardId   = item.Id;
                        activityWinModel.awardType = item.awardType;
                        activityWinModel.couponId  = item.couponId;
                        break;
                    }
                }
            }

            WeiActivityApplication.WinnerSubmit(activityWinModel);
            decimal bonusPrice = 0;

            if (activityWinModel.bonusId > 0)
            {
                bonusPrice = _iBonusService.GetReceivePriceByUserId(activityWinModel.bonusId, userId);
            }

            return(Json(new Result()
            {
                success = true, data = activityWinModel.awardId.ToString() + "," + bonusPrice.ToString(), msg = ""
            }));
        }
 public static decimal GetReceivePriceByUserId(long id, long userId)
 {
     return(_iBonusService.GetReceivePriceByUserId(id, userId));
 }