protected void Page_Load(object sender, EventArgs e) { id = Convert.ToInt32(Request["id"]); webAction = Request["Action"]; actionStr = webAction == "add" ? "添加" : "编辑"; if (webAction == "edit") { model = this.bll.Get <WXLottery>(string.Format("AutoID='{0}'", id)); if (model == null) { Response.End(); } else { } } }
public int UserLogCount; //抽奖记录数 protected void Page_Load(object sender, EventArgs e) { try { if (!bll.IsLogin()) { Response.Write("您尚未登录,不能刮奖"); Response.End(); } UserInfo CurrentUserInfo = Comm.DataLoadTool.GetCurrUserModel(); model = bll.Get <WXLottery>(string.Format("AutoID={0}", Request["id"])); if (model == null) { Response.End(); } if (!string.IsNullOrEmpty(model.LotteryActivityID))//有关联的活动ID { if (bll.GetCount <WXSignInInfo>(string.Format("SignInUserID='{0}' And JuActivityID={1}", CurrentUserInfo.UserID, model.LotteryActivityID)) == 0) { sbLottery = "请签到后再抽奖"; return; } } //if (model.Status.Equals(0)) //{ // sbLottery = "刮奖未开启"; // if (!string.IsNullOrEmpty(model.StopMessage)) // { // sbLottery = model.StopMessage; // } // return; //} //#region 特殊处理 //if ((!string.IsNullOrEmpty(WinList.SingleOrDefault(p => p.Key == CurrentUserInfo.WXOpenId).Value) && model.AutoID.Equals(9))) //{ // //先查看中奖记录 // WXLotteryRecord roc = bll.Get<WXLotteryRecord>(string.Format("LotteryId=9 And UserId='{0}'", CurrentUserInfo.UserID)); // if (roc != null)//已经中过奖 // { // sbLottery = string.Format("恭喜!您获得了<br/>{0}</br>领取码:{1}", WinList.Single(p => p.Key == CurrentUserInfo.WXOpenId).Value, roc.Token); // IsWin = "true"; // UserLogCount = 1; // if (IsUserGetPrize(CurrentUserInfo.UserID, model.AutoID).Equals("true")) // { // IsGetPrize = "true"; // } // return; // } // // // // // if (model.Status.Equals(0)) // { // sbLottery = "刮奖未开启"; // if (!string.IsNullOrEmpty(model.StopMessage)) // { // sbLottery = model.StopMessage; // } // return; // } // // // //中奖 // Random r = new Random(); // WXLotteryRecord Record = new WXLotteryRecord(); // Record.InsertDate = DateTime.Now; // Record.LotteryId = model.AutoID; // Record.Token = r.Next(1, 9999).ToString(); // Record.WXAwardsId = 0; // Record.UserId = CurrentUserInfo.UserID; // Record.IsGetPrize = "0"; // if (bll.AddWXLotteryRecord(Record)) // { // sbLottery = string.Format("恭喜!您获得了<br/>{0}</br>领取码:{1}", WinList.Single(p => p.Key == CurrentUserInfo.WXOpenId).Value, Record.Token); // IsWin = "true"; // return; // } //} //#endregion if (!string.IsNullOrEmpty(model.NotWinMessage)) { sbLottery = model.NotWinMessage; } var LotteryRecord = bll.GetWXLotteryRecord(CurrentUserInfo.UserID, model.AutoID); if (LotteryRecord != null) { sbLottery = string.Format("您已经获得了:<br/>{0}<br/>领取码:{1}", LotteryRecord.WXAwardName, LotteryRecord.Token); UserLogCount = 1; IsWin = "true"; if (IsUserGetPrize(CurrentUserInfo.UserID, model.AutoID).Equals("true")) { IsGetPrize = "true"; } return; } //先插入刮奖日志 //检查用户刮奖次数 UserLogCount = bll.GetWXLotteryLogCount(model.AutoID, CurrentUserInfo.UserID); if (UserLogCount >= model.MaxCount) { //sbLottery = "您的刮奖次数已经用完了"; return; } if (IsUserGetPrize(CurrentUserInfo.UserID, model.AutoID).Equals("true")) { IsWin = "true"; sbLottery = string.Format("恭喜!您已经领过奖品!!!"); return; } if (model.Status.Equals(0)) { sbLottery = "刮奖未开启"; if (!string.IsNullOrEmpty(model.StopMessage)) { sbLottery = model.StopMessage; } return; } WXLotteryLog log = new WXLotteryLog(); log.LotteryId = model.AutoID; log.UserId = CurrentUserInfo.UserID; log.InsertDate = DateTime.Now; if (bll.AddWXLotteryLog(log))//下一步 { //获取刮奖日志数 int TotalLogCount = bll.GetWXLotteryLogCount(model.AutoID); List <WXLotteryWinningData> WinningDataList = bll.GetWXLotteryWinningDataList(model.AutoID); if (WinningDataList.SingleOrDefault(p => p.WinningIndex.Equals(TotalLogCount)) != null)//中奖了 { Random rand = new Random(); int token = rand.Next(1111, 9999); WXLotteryWinningData WinningData = WinningDataList.Single(p => p.WinningIndex.Equals(TotalLogCount)); //插入中奖记录 WXLotteryRecord Record = new WXLotteryRecord(); Record.InsertDate = DateTime.Now; Record.LotteryId = model.AutoID; Record.Token = token.ToString(); Record.WXAwardsId = WinningData.WXAwardsId; Record.UserId = CurrentUserInfo.UserID; Record.IsGetPrize = "0"; if (bll.AddWXLotteryRecord(Record)) { sbLottery = string.Format("恭喜!您获得了<br/>{0}</br>领取码:{1}", WinningData.WXAwardName, token); IsWin = "true"; } } } } catch (Exception ex) { sbLottery = ex.ToString(); } }