public ActionResult Add(long id, long userId) { WeiActivityModel activityModel = WeiActivityApplication.GetActivityModel(id); this.activityWinModel = new WeiActivityWinModel(); int num = new Random().Next(1, 100); this.activityWinModel.activityId = id; this.activityWinModel.addDate = DateTime.Now; this.activityWinModel.userId = userId; this.activityWinModel.integrals = activityModel.consumePoint; this.activityWinModel.isWin = false; this.activityWinModel.awardId = 0L; this.activityWinModel.awardName = "未中奖"; foreach (WeiActivityAwardModel model2 in activityModel.awards) { if (num <= this.GetCount(activityModel.Id, model2.Id)) { this.activityWinModel.isWin = true; if (model2.awardType == WeiActivityAwardType.Integral) { this.activityWinModel.awardName = model2.integral.ToString(); this.activityWinModel.awardId = model2.Id; this.activityWinModel.awardType = model2.awardType; break; } if (model2.awardType == WeiActivityAwardType.Bonus) { BonusInfo info = this._iBonusService.Get(model2.bonusId); if (info == null) { this.activityWinModel.isWin = false; } else { string bonusSurplus = this._iBonusService.GetBonusSurplus(model2.bonusId); if (info.IsInvalid) { this.activityWinModel.isWin = false; } else if (Convert.ToInt32(bonusSurplus) <= 0) { this.activityWinModel.isWin = false; } else { this.activityWinModel.awardName = info.Name; this.activityWinModel.awardId = model2.Id; this.activityWinModel.awardType = model2.awardType; this.activityWinModel.bonusId = model2.bonusId; } } break; } if (model2.awardType == WeiActivityAwardType.Coupon) { CouponModel model3 = CouponApplication.Get(model2.couponId); if (model3 == null) { this.activityWinModel.isWin = false; } else { int num2 = WeiActivityWinApplication.GetCouPonMax(this.activityWinModel.userId, this.activityWinModel.activityId, model2.Id); if (model3.Num <= 0) { this.activityWinModel.isWin = false; } else if ((model3.perMax != 0) && (num2 >= model3.perMax)) { this.activityWinModel.isWin = false; } else if (model3.EndTime < DateTime.Now) { this.activityWinModel.isWin = false; } else { string couponName = model3.CouponName; if (model3.ShopName != "") { couponName = couponName + "(" + model3.ShopName + ")"; } if (model3.OrderAmount != "") { couponName = couponName + "(" + model3.OrderAmount + ")"; } this.activityWinModel.awardName = couponName; this.activityWinModel.awardId = model2.Id; this.activityWinModel.awardType = model2.awardType; this.activityWinModel.couponId = model2.couponId; } } break; } } } WeiActivityWinApplication.WinnerSubmit(this.activityWinModel); decimal receivePriceByUserId = 0M; if (this.activityWinModel.bonusId > 0L) { receivePriceByUserId = this._iBonusService.GetReceivePriceByUserId(this.activityWinModel.bonusId, userId); } BaseController.Result data = new BaseController.Result { success = true, msg = this.activityWinModel.awardId.ToString() + "," + receivePriceByUserId.ToString() }; return(base.Json(data)); }
public WeiActivityWinModel AddWinInfo(WeiActivityModel activityModel) { activityWinModel = new WeiActivityWinModel(); Random r = new Random(); int num = r.Next(1, 101);//获取随机数做为中奖信息 activityWinModel.activityId = activityModel.Id; activityWinModel.addDate = DateTime.Now; activityWinModel.userId = curUserId; activityWinModel.isWin = false; activityWinModel.awardId = 0; activityWinModel.awardName = "未中奖"; activityWinModel.awardType = WeiActivityAwardType.Integral; // var activityModel=WeiActivityWinApplication.GetWinModel() foreach (var item in activityModel.awards) { //获取的随机数在该奖等区域类 if (num <= GetCount(activityModel.Id, item.Id)) { if (item.awardType == WeiActivityAwardType.Integral) { activityWinModel.awardName = item.integral.ToString(); activityWinModel.awardId = item.Id; activityWinModel.awardType = item.awardType; activityWinModel.isWin = true; return(activityWinModel); } else if (item.awardType == WeiActivityAwardType.Bonus) { Model.BonusInfo bonusInfo = _iBonusService.Get(item.bonusId); string Surplus = _iBonusService.GetBonusSurplus(item.bonusId); if (bonusInfo.IsInvalid)//红包已经失效 返回 未中奖 { break; } if (Convert.ToInt32(Surplus) <= 0)//当前红包已经领取完 设置未中奖 { break; } //获取红包名称 activityWinModel.awardName = bonusInfo.Himall_BonusReceive.Where(p => p.IsShare == false && p.UserId == null).FirstOrDefault().Price.ToString() + "元红包"; activityWinModel.awardId = item.Id; activityWinModel.awardType = item.awardType; activityWinModel.bonusId = bonusInfo.Id; activityWinModel.isWin = true; return(activityWinModel); } else if (item.awardType == WeiActivityAwardType.Coupon) { CouponModel couponModel = CouponApplication.Get(item.couponId); int perMax = WeiActivityWinApplication.GetCouPonMax(activityWinModel.userId, activityWinModel.activityId, item.Id); if (couponModel == null) { break; } if (couponModel.Num <= 0)//无库存 返回 未中奖 { break; } if (couponModel.EndTime < DateTime.Now)//优惠券失效 { break; } if (couponModel.perMax != 0 && perMax >= couponModel.perMax) { break; } //获取优惠券名称 string awardName = couponModel.CouponName; if (couponModel.ShopName != "") { awardName = awardName + "(" + couponModel.ShopName + ")"; } if (couponModel.OrderAmount != "") { activityWinModel.amount = "(" + couponModel.OrderAmount + ")"; } activityWinModel.awardName = awardName; activityWinModel.awardId = item.Id; activityWinModel.awardType = item.awardType; activityWinModel.couponId = couponModel.Id; activityWinModel.isWin = true; return(activityWinModel); } } } return(activityWinModel); }
public string GetCouponName(long id) { return(CouponApplication.Get(id).CouponName); }
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 = "" })); }