/// <summary> /// 保存数据库日志 /// </summary> /// <param name="model"></param> public void SaveLog(TRP_ClientLog model) { try { string insertsql = @"INSERT INTO [TRP_ClientLog] ( [CreateTime] ,[Description] ,[DeleteMark] ,[Enable] ,[IPAddress] ,[PageDesc] ,[PageUrl] ,[ActivityId] ,[ReceiveImage] ) VALUES ( @CreateTime ,@Description ,@DeleteMark ,@Enable ,@IPAddress ,@PageDesc ,@PageUrl ,@ActivityId ,@ReceiveImage ) "; idal.CreateEntity <TRP_ClientLog>(insertsql, model); } catch (Exception ex) { Logger.Error(string.Format("写数据库日志异常,异常信息:{0}", ex.ToString())); } }
public virtual JsonResult ReceivedAward(AwardReceivedModel model) { object data = null; try { var res = new JsonResult(); //已领取奖品 再次领取失败 if (isTakeAward(model.Openid, model.ActivityId)) { //返回json data = new { success = false, status = "2" }; } else { if (saveUserAwardReceiveInfo(model.Openid, model.AwardDetailId)) { //返回json data = new { success = true, status = "1" }; //记录日志 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/wxredpackets"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; var efid = DESEncrypt.Decrypt(model.AwardDetailId, _key); var awardName = model.AwardName; entity.Description = string.Format("{0}工作人员核销领奖,奖品为{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), awardName); entity.PageDesc = string.Format("工作人员核销领奖,奖品{0}", awardName); entity.ActivityId = Convert.ToInt32(model.ActivityId); //保存日志 logDi.getBll().SaveLog(entity); } else { //返回json data = new { success = false, status = "1" }; } } } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("微信用户-OpenId:{0}-领取奖品,保存到数据库中出现错误,,奖品ID为{1},错误详情:{2}", model.Openid, model.AwardDetailId, ex.ToString())); } return(Json(data, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 保存日志信息 /// </summary> /// <param name="model"></param> public void SaveLog(TRP_ClientLog model) { try { idal.Add(model); idal.Save(); } catch (Exception ex) { Logger.Error(string.Format("写数据库日志异常,异常信息:{0}", ex.ToString())); } }
//记录日志 public void RecordLog(string activityid, string des, string pagedesc, string ip = "127.0.0.1", string url = "test", string img = null) { TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = url; entity.IPAddress = ip; entity.ActivityId = Convert.ToInt32(activityid); entity.Description = des; entity.PageDesc = pagedesc; entity.ReceiveImage = img; TRP_ClientLog_BLL.getInstance().SaveLog(entity); }
/// <summary> /// 输手机号码 领取红包奖品 /// </summary> /// <param name="url"></param> /// <param name="activityId"></param> /// <param name="flag"></param> /// <param name="activityName"></param> /// <returns></returns> public ActionResult Index(string url, string activityId, string flag, string activityName, string computername) { ActionResult empty = new EmptyResult(); try { if (string.IsNullOrWhiteSpace(flag)) { //扫码计数-所有 scanCountDi.getBll().CountByNameAndId(activityId, activityName); } else { //http://www.chinazhihuiping.com/wxredpackets/SY_WDActivity/Activity?activityId={0}&flag={1} scanCountDi.getBll().CountByNameAndId(activityId, "" + activityName + "重定向"); } AwardsInfoModel awardsModel = new AwardsInfoModel(); TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/wxredpackets/PhoneGet/Index"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(activityId); //请求奖品 awardsModel = GetAwardsInfo(activityId, activityName); //奖品实体为null if (awardsModel == null) { Common.Helper.Logger.Info(string.Format("awardsModel == null")); return(View("Error")); } //奖品实体的类型为null if (awardsModel.Class != null) { //奖品实体的类型为"" if (awardsModel.Class == "") { Common.Helper.Logger.Info(string.Format("awardsModel.Class==''")); return(View("Error")); } } //获取奖品的类型实现奖品页面的跳转 if (string.IsNullOrWhiteSpace(computername)) { ResponseRedirect(string.Format("" + url + "?&type=&id={0}", awardsModel.id)); } else { ResponseRedirect(string.Format("" + url + "?&type=&id={0}&computername={1}", awardsModel.id, computername)); } return(empty); } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("" + activityName + "进入领奖页面异常,异常信息:{0}", ex.ToString())); Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/PhoneGet/Index?url={0}&activityId={1}&flag={2}&activityName={3}", url, activityId, flag, activityName)); return(empty); } }
/// <summary> /// 发现金 /// </summary> /// <returns></returns> public ActionResult GiveMoney(RequestModel request) { ActionResult empty = new EmptyResult(); try { //扫码计数-所有 scanCountDi.getBll().CountByNameAndId(request.activityId, request.activityName); #region 数据库日志记录 公共部分 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/GiveMoney"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(request.activityId); #endregion //获取微信用户信息 wxUserInfoModel wxUser = GetWxUserInfo(request.code); if (wxUser == null) { Response.Redirect(request.url + "&flag=1"); return(empty); } //微信用户openid string openid = wxUser.Openid; //保存微信信息 if (!isExistOpenId(wxUser.Openid)) { //保存用户微信信息 saveUserInfo(wxUser); } TRP_AwardReceive receivedModel = null; #region 今天已参加活动 if (isAttendToday(request.activityId, wxUser.Openid)) { //判断奖品是否已领 receivedModel = awardDi.getBll().hadTakeAward(wxUser.Openid, request.activityId); #region 奖品已核销 //奖品已领 if (receivedModel == null) { Response.Redirect(request.url + "&flag=1"); return(empty); } #endregion #region 奖品还未核销 //奖品还未领取 else { //获取奖品ID int string awardId = receivedModel.AwardDetailId.ToString(); //获取奖品详情 TRP_AwardDetail detailModel = detailDi.getBll().GetEntityById(awardId); //奖品名称 string awardsName = ""; //加密奖品id string ecodeAwardId = DESEncrypt.Encrypt(awardId, _key); if (detailModel != null) { //奖品名称 awardsName = detailModel.AwardName; } else { Response.Redirect(request.url + "&flag=1"); return(empty); } //奖品类型 if (!string.IsNullOrWhiteSpace(awardsName)) { GiveCash(awardsName, wxUser.Openid, request); } else { Response.Redirect(request.url + "&flag=1"); return(empty); } entity.Description = string.Format("用户在{0}点击红包,现金红包(为重复扫码,上次未核销奖品)", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); entity.PageDesc = "实物扫码,上次未核销奖品"; entity.ActivityId = Convert.ToInt32(request.activityId); logDi.getBll().SaveLog(entity); return(View("GiveMoney")); } #endregion } #endregion #region 今天还未参加活动 则请求奖品 AwardsInfoModel awardsModel = new AwardsInfoModel(); //请求奖品 awardsModel = GetAwardsInfo(request.activityId); //奖品实体为null if (awardsModel == null) { Response.Redirect(request.url + "&flag=1"); return(empty); } //奖品实体的类型为null if (awardsModel.Class != null) { //奖品实体的类型为"" if (awardsModel.Class == "") { Response.Redirect(request.url + "&flag=1"); return(empty); } } #endregion //发钱 if (GiveCash(awardsModel.Class, openid, request)) { //保存领奖信息-测试 saveScanInfo(wxUser.Openid, awardsModel.id); saveUserAwardReceiveInfo(wxUser.Openid, awardsModel.id); return(View("GiveMoney")); } else { Response.Redirect(request.url + "&flag=1"); return(empty); } } catch (Exception ex) { Response.Redirect(request.url); Common.Helper.Logger.Info(string.Format("获取用户微信Openid,发现金异常,异常信息:{0}", ex.ToString())); return(empty); } }
/// <summary> /// ViewData["Openid"] = ""; ////ViewData["wxName"] = "RandyField"; ////ViewData["AwardDetailId"] = ""; ////ViewData["AwardName"] = ""; ////ViewData["Activity"] = ""; ////ViewData["Type"] = "A"; ////return View(); ////ActionResult empty = new EmptyResult(); /// 热高乐园红包雨活动 /// </summary> /// <param name="activityId"></param> /// <param name="flag"></param> /// <returns></returns> public ActionResult Activity(string activityId, string flag, string guid) { /* * if (!string.IsNullOrWhiteSpace(guid)) * { * if (!IsInDate(activityId, guid, 10)) * { * return View("OutOfDate"); * } * } * //未传guid * else * { * return View("OutOfDate"); * } */ ActionResult empty = new EmptyResult(); try { if (string.IsNullOrWhiteSpace(flag)) { //扫码计数-所有 scanCountDi.getBll().CountByNameAndId(activityId, "【热高乐园红包雨】"); } else { if (flag.Trim() == "1") { scanCountDi.getBll().CountByNameAndId(activityId, "【热高乐园红包雨】发生重定向-现金红包跳转)"); } else { scanCountDi.getBll().CountByNameAndId(activityId, "【热高乐园红包雨】发生重定向-非现金红包跳转)"); } } //日志记录公共部分 AwardsInfoModel awardsModel = new AwardsInfoModel(); TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/wxredpackets/Test/Activity"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(activityId); //请求奖品 awardsModel = GetAwardsInfo(activityId); //奖品实体为空 if (awardsModel == null) { Dictionary <int, string> dic = new Dictionary <int, string>(); dic.Add(1, "https://shop13299622.wxrrd.com/coupon/get_code/68929"); dic.Add(2, "https://shop13299622.wxrrd.com/coupon/get_code/68928"); dic.Add(3, "https://shop13299622.wxrrd.com/coupon/get_code/68927"); dic.Add(4, "https://shop13299622.wxrrd.com/coupon/get_code/68926"); dic.Add(5, "https://shop13299622.wxrrd.com/coupon/get_code/68925"); dic.Add(6, "https://shop13299622.wxrrd.com/coupon/get_code/68924"); dic.Add(7, "https://shop13299622.wxrrd.com/coupon/get_code/68923"); dic.Add(8, "https://shop13299622.wxrrd.com/coupon/get_code/68922"); dic.Add(9, "https://shop13299622.wxrrd.com/coupon/get_code/68921"); //RedirectRandom(dic, 9); scanCountDi.getBll().CountByNameAndId(activityId, "【热高乐园红包雨】-取奖品awardsModel == null, 随机跳转"); return(empty); } //奖品的Class不为空 if (awardsModel.Class != null) { if (awardsModel.Class == "") { Dictionary <int, string> dic = new Dictionary <int, string>(); dic.Add(1, "https://shop13299622.wxrrd.com/coupon/get_code/68929"); dic.Add(2, "https://shop13299622.wxrrd.com/coupon/get_code/68928"); dic.Add(3, "https://shop13299622.wxrrd.com/coupon/get_code/68927"); dic.Add(4, "https://shop13299622.wxrrd.com/coupon/get_code/68926"); dic.Add(5, "https://shop13299622.wxrrd.com/coupon/get_code/68925"); dic.Add(6, "https://shop13299622.wxrrd.com/coupon/get_code/68924"); dic.Add(7, "https://shop13299622.wxrrd.com/coupon/get_code/68923"); dic.Add(8, "https://shop13299622.wxrrd.com/coupon/get_code/68922"); dic.Add(9, "https://shop13299622.wxrrd.com/coupon/get_code/68921"); //RedirectRandom(dic, 9); scanCountDi.getBll().CountByNameAndId(activityId, "【热高乐园红包雨】-取奖品awardsModel.Class=='', 随机跳转"); return(empty); } //如果是券 则直接写日志,跳转 string awardsCard = "卡"; #region 卡 if (awardsModel.Class.Contains(awardsCard)) { Dictionary <string, string> dicStr = new Dictionary <string, string>(); //50元 dicStr.Add("50元青色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68929"); dicStr.Add("50元橘色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68928"); dicStr.Add("50元橙色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68927"); dicStr.Add("50元黄色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68926"); dicStr.Add("50元土黄色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68925"); dicStr.Add("50元紫色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68924"); //100元 dicStr.Add("100元蓝色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68923"); dicStr.Add("100元绿色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68922"); dicStr.Add("100元青色卡", "https://shop13299622.wxrrd.com/coupon/get_code/68921"); //通票 //dicStr.Add("通票卡", "https://shop13299622.wxrrd.com/coupon/get_code/68930"); if (awardsModel.Class.Trim() == "通票卡") { scanCountDi.getBll().CountByNameAndId(activityId, string.Format("【热高乐园红包雨】-奖品:{0}", "100元蓝色卡")); RedirectRedPocket(dicStr, "100元蓝色卡"); } else { RedirectRedPocket(dicStr, awardsModel.Class); scanCountDi.getBll().CountByNameAndId(activityId, string.Format("【热高乐园红包雨】-奖品:{0}", awardsModel.Class)); } entity.Description = string.Format("用户在{0}点击红包,【热高乐园红包雨】二维码扫码,{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), awardsModel.Class); //数据库记录日志 logDi.getBll().SaveLog(entity); return(empty); } #endregion //非卡 else { //非卡重定向 至微信领奖页 string url = string.Format("http://www.chinazhihuiping.com/wxredpackets/Test/WXActivity?activityId={0}&giftType={1}&giftId={2}", activityId, awardsModel.Class, awardsModel.id); string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); ResponseWXRedirect(urlencode); return(empty); } } else { Dictionary <int, string> dic = new Dictionary <int, string>(); dic.Add(1, "https://shop13299622.wxrrd.com/coupon/get_code/68929"); dic.Add(2, "https://shop13299622.wxrrd.com/coupon/get_code/68928"); dic.Add(3, "https://shop13299622.wxrrd.com/coupon/get_code/68927"); dic.Add(4, "https://shop13299622.wxrrd.com/coupon/get_code/68926"); dic.Add(5, "https://shop13299622.wxrrd.com/coupon/get_code/68925"); dic.Add(6, "https://shop13299622.wxrrd.com/coupon/get_code/68924"); dic.Add(7, "https://shop13299622.wxrrd.com/coupon/get_code/68923"); dic.Add(8, "https://shop13299622.wxrrd.com/coupon/get_code/68922"); dic.Add(9, "https://shop13299622.wxrrd.com/coupon/get_code/68921"); //RedirectRandom(dic, 9); scanCountDi.getBll().CountByNameAndId(activityId, "【热高乐园红包雨】-取奖品awardsModel.Class == null, 随机跳转"); return(empty); } } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("【热高乐园红包雨】进入领奖页面异常,异常信息:{0}", ex.ToString())); Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/Activity?activityId={0}&flag={1}", activityId, 2)); return(empty); } }
/// <summary> /// 微信控制器 /// </summary> /// <param name="request"></param> /// <returns></returns> public ActionResult WXActivity(RequestModel request) { ActionResult empty = new EmptyResult(); try { #region 数据库日志记录 公共部分 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/ReGaoPark/WXActivity"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(request.activityId); #endregion #region 获取微信用户信息 昵称,头像等 wxUserInfoModel wxUser = GetWxUserInfo(request.code); if (wxUser == null) { //非卡重定向 至微信领奖页 string url = string.Format("http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/WXActivity?activityId={0}&giftType={1}&giftId={2}", request.activityId, request.giftType, request.giftId); string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); ResponseWXRedirect(urlencode); return(empty); } #endregion #region 今天已参加活动 if (isAttendToday(request.activityId, wxUser.Openid)) { //判断奖品是否已领 var receivedModel = awardDi.getBll().hadTakeAward(wxUser.Openid, request.activityId); #region 奖品已核销 //奖品已领 if (receivedModel == null) { Dictionary <int, string> dic = new Dictionary <int, string>(); dic.Add(1, "https://shop13299622.wxrrd.com/coupon/get_code/68929"); dic.Add(2, "https://shop13299622.wxrrd.com/coupon/get_code/68928"); dic.Add(3, "https://shop13299622.wxrrd.com/coupon/get_code/68927"); dic.Add(4, "https://shop13299622.wxrrd.com/coupon/get_code/68926"); dic.Add(5, "https://shop13299622.wxrrd.com/coupon/get_code/68925"); dic.Add(6, "https://shop13299622.wxrrd.com/coupon/get_code/68924"); //RedirectRandom(dic, 6); scanCountDi.getBll().CountByNameAndId(request.activityId, "【热高乐园红包雨】-实物已领取, 随机跳转"); return(empty); } #endregion #region 奖品还未核销 //奖品还未领取 else { //获取奖品ID int string awardId = receivedModel.AwardDetailId.ToString(); //获取奖品详情 TRP_AwardDetail detailModel = detailDi.getBll().GetEntityById(awardId); //奖品名称 string awardsName = ""; //加密奖品id string ecodeAwardId = DESEncrypt.Encrypt(awardId, _key); if (detailModel != null) { awardsName = detailModel.AwardName; } //奖品类型 if (!string.IsNullOrWhiteSpace(awardsName)) { string typeCode = ""; typeCode = "A"; ViewData["Type"] = typeCode; } ViewData["Openid"] = wxUser.Openid ?? ""; ViewData["wxName"] = wxUser.Nickname ?? ""; ViewData["AwardDetailId"] = ecodeAwardId; ViewData["AwardName"] = awardsName; ViewData["Activity"] = request.activityId ?? ""; entity.Description = string.Format("用户在{0}点击红包,二维码实物扫码(为重复扫码,上次未核销奖品)", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); entity.PageDesc = "实物扫码,上次未核销奖品"; entity.ActivityId = Convert.ToInt32(request.activityId); logDi.getBll().SaveLog(entity); return(View("Activity")); } #endregion } #endregion #region 首次参加活动 if (request.giftType != null) { string awardsType = request.giftType; string typeCode = ""; if (awardsType.Contains("笔记本")) { typeCode = "A"; } else { Common.Helper.Logger.Info(string.Format("【热高乐园红包雨】,用户获取奖品:微信用户-OpenId:{0}-领取奖品,未接收到奖品类型,发生了重定向")); Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/Activity?activityId={0}&flag={1}", request.activityId, 2)); return(empty); } ViewData["Type"] = typeCode; } //不存在微信用户 if (!isExistOpenId(wxUser.Openid)) { //保存用户微信信息 saveUserInfo(wxUser); } //保存扫码信息 saveScanInfo(wxUser.Openid, request.giftId); string awardName = request.giftType; entity.Description = string.Format("【热高乐园红包雨】,用户在{0}点击红包,二维码扫码进入实物领奖页面,奖品为{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), request.giftType); entity.PageDesc = string.Format("实物扫码,得到{0}", awardName); entity.ActivityId = Convert.ToInt32(DESEncrypt.Decrypt(request.giftId, _key)); logDi.getBll().SaveLog(entity); ViewData["Openid"] = wxUser.Openid ?? ""; ViewData["wxName"] = wxUser.Nickname ?? ""; ViewData["AwardDetailId"] = request.giftId ?? ""; ViewData["AwardName"] = request.giftType ?? ""; ViewData["Activity"] = request.activityId ?? ""; return(View("Activity")); #endregion #region 注释部分 无限制领取次数 //if (request.giftType != null) //{ // string awardsType = request.giftType; // string typeCode = ""; // if (awardsType.Contains("笔记本")) // { // typeCode = "A"; // } // else // { // Common.Helper.Logger.Info(string.Format("【热高乐园红包雨】,用户获取奖品:微信用户-OpenId:{0}-领取奖品,未接收到奖品类型,发生了重定向")); // Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/Activity?activityId={0}&flag={1}", request.activityId, 2)); // return empty; // } // ViewData["Type"] = typeCode; //} ////不存在微信用户 //if (!isExistOpenId(wxUser.Openid)) //{ // //保存用户微信信息 // saveUserInfo(wxUser); //} ////保存扫码信息 //saveScanInfo(wxUser.Openid, request.giftId); //#region 保存日志记录至数据库 //entity.Description = string.Format("【热高乐园红包雨】,用户在{0}点击红包,二维码扫码进入实物领奖页面,奖品为{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), request.giftType); //entity.PageDesc = string.Format("实物扫码,得到{0}", request.giftType); //entity.ActivityId = Convert.ToInt32(DESEncrypt.Decrypt(request.giftId, _key)); //logDi.getBll().SaveLog(entity); //#endregion //ViewData["Openid"] = wxUser.Openid ?? ""; //ViewData["wxName"] = wxUser.Nickname ?? ""; //ViewData["AwardDetailId"] = request.giftId ?? ""; //ViewData["AwardName"] = request.giftType ?? ""; //ViewData["Activity"] = request.activityId ?? ""; //return View("Activity"); #endregion } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("【热高乐园红包雨】领取实物异常,异常信息:{0}", ex.ToString())); Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/Activity?activityId={0}&flag={1}", request.activityId, 2)); return(empty); } }
/// <summary> /// ViewData["Openid"] = ""; ////ViewData["wxName"] = "RandyField"; ////ViewData["AwardDetailId"] = ""; ////ViewData["AwardName"] = ""; ////ViewData["Activity"] = ""; ////ViewData["Type"] = "A"; ////return View(); ////ActionResult empty = new EmptyResult(); /// 热高乐园红包雨活动 /// </summary> /// <param name="activityId"></param> /// <param name="flag"></param> /// <returns></returns> public ActionResult Activity(string activityId, string flag, string guid) { #region 测试 //ViewData["Openid"] = ""; //ViewData["wxName"] = "RandyField"; //ViewData["AwardDetailId"] = ""; //ViewData["AwardName"] = ""; //ViewData["Activity"] = ""; //ViewData["Type"] = "A"; //return View(); //string type = "0.88元现金红包"; //string opienid = "omJcruMSo_al_vHgI7dQHdixsPEM"; //RequestModel request=new RequestModel { // activityName = "【中兴30周年庆现金红包】", // TenPaySender = "中兴大厦", // TenPayWish = "恭喜发财", // TenPayGame = "30周年庆,红包雨", // TenPayRemark = "中兴大厦" //}; //GiveCash(type, opienid, request); if (!string.IsNullOrWhiteSpace(guid)) { if (!IsInDate(activityId, guid, 4)) { return(View("OutOfDate")); } } //未传guid else { return(View("OutOfDate")); } #endregion ActionResult empty = new EmptyResult(); try { #region 扫码计数 if (string.IsNullOrWhiteSpace(flag)) { //扫码计数-所有 scanCountDi.getBll().CountByNameAndId(activityId, str_a_activityname); } else { if (flag.Trim() == "1") { scanCountDi.getBll().CountByNameAndId(activityId, str_b_activityname); } else { scanCountDi.getBll().CountByNameAndId(activityId, str_c_activityname); } } #endregion #region 记录日志 //日志记录公共部分 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? enter_url; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(activityId); #endregion #region 重定向至微信授权URL //重定向至微信领奖页url,把奖品信息参数包裹 string url = string.Format("{0}?activityId={1}", wx_url, activityId); //url encode编码 string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); //重定向 微信授权url ResponseWXRedirect(urlencode); #endregion return(empty); } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("{0}进入领奖页面异常,异常信息:{1}", str_a_activityname, ex.ToString())); return(View("Nogift")); } }
/// <summary> /// 微信控制器 /// </summary> /// <param name="request"></param> /// <returns></returns> public ActionResult WXActivity(RequestModel request) { ActionResult empty = new EmptyResult(); try { #region 数据库日志记录 公共部分 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? wx_url; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(request.activityId); #endregion #region 获取微信用户信息 昵称,头像等 wxUserInfoModel wxUser = GetWxUserInfo(request.code); if (wxUser == null) { //微信用户信息未获取到 重定向至活动入口Action string url = string.Format("{0}?activityId={1}", enter_url, request.activityId); return(empty); } #endregion #region 今天已参加活动 if (isAttendToday(request.activityId, wxUser.Openid)) { //判断奖品是否已领 var receivedModel = awardDi.getBll().hadTakeAward(wxUser.Openid, request.activityId); #region 奖品已核销 //奖品已领 if (receivedModel == null) { scanCountDi.getBll().CountByNameAndId(request.activityId, str_d_activityname); return(View("HadAttend")); } #endregion #region 奖品还未核销 返回Activity视图 //奖品还未领取 else { //获取奖品ID int string awardId = receivedModel.AwardDetailId.ToString(); //获取奖品详情 TRP_AwardDetail detailModel = detailDi.getBll().GetEntityById(awardId); //奖品名称 string awardsName = ""; //加密奖品id string ecodeAwardId = DESEncrypt.Encrypt(awardId, _key); if (detailModel != null) { awardsName = detailModel.AwardName; } //奖品类型 if (!string.IsNullOrWhiteSpace(awardsName)) { string typeCode = ""; if (awards_code.ContainsKey(awardsName.Trim())) { typeCode = awards_code[awardsName.Trim()]; } else { return(View("Nogift")); } ViewData["Type"] = typeCode; } ViewData["Openid"] = wxUser.Openid ?? ""; ViewData["wxName"] = wxUser.Nickname ?? ""; ViewData["AwardDetailId"] = ecodeAwardId; ViewData["AwardName"] = awardsName; ViewData["Activity"] = request.activityId ?? ""; entity.Description = string.Format("用户在{0}点击红包,二维码实物扫码(为重复扫码,上次未核销奖品)", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); entity.PageDesc = "实物扫码,上次未核销奖品"; entity.ActivityId = Convert.ToInt32(request.activityId); logDi.getBll().SaveLog(entity); return(View("Activity")); } #endregion } #endregion #region 首次参加活动 else { //请求奖品 AwardsInfoModel awardsModel = GetAwardsInfo(request.activityId); //奖品的Class不为空 if (awardsModel.Class != null) { if (awardsModel.Class == "") { scanCountDi.getBll().CountByNameAndId(request.activityId, str_e_activityname); return(View("Nogift")); } else { string awardsType = awardsModel.Class; string typeCode = ""; //Common.Helper.Logger.Info("--test--"); //Common.Helper.Logger.Info(awardsModel.Class); //Common.Helper.Logger.Info(awards_code.ContainsKey(awardsModel.Class.Trim())); if (awards_code.ContainsKey(awardsModel.Class.Trim())) { //Common.Helper.Logger.Info(awards_code[awardsModel.Class.Trim()]); typeCode = awards_code[awardsModel.Class.Trim()]; } else { return(View("Nogift")); } ViewData["Type"] = typeCode; //不存在微信用户 if (!isExistOpenId(wxUser.Openid)) { //保存用户微信信息 saveUserInfo(wxUser); } //保存扫码信息 saveScanInfo(wxUser.Openid, awardsModel.id); string awardName = awardsType; entity.Description = string.Format("{0},用户在{1}点击红包,二维码扫码进入实物领奖页面,奖品为{1}", str_a_activityname, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), awardsType); entity.PageDesc = string.Format("实物扫码,得到{0}", awardName); entity.ActivityId = int.Parse(request.activityId); logDi.getBll().SaveLog(entity); ViewData["Openid"] = wxUser.Openid ?? ""; ViewData["wxName"] = wxUser.Nickname ?? ""; ViewData["AwardDetailId"] = awardsModel.id ?? ""; ViewData["AwardName"] = awardsModel.Class ?? ""; ViewData["Activity"] = request.activityId ?? ""; return(View("Activity")); } } else { scanCountDi.getBll().CountByNameAndId(request.activityId, str_f_activityname); return(View("Nogift")); } } #endregion #region 注释部分 无限制领取次数 //if (request.giftType != null) //{ // string awardsType = request.giftType; // string typeCode = ""; // if (awardsType.Contains("笔记本")) // { // typeCode = "A"; // } // else // { // Common.Helper.Logger.Info(string.Format("【热高乐园红包雨】,用户获取奖品:微信用户-OpenId:{0}-领取奖品,未接收到奖品类型,发生了重定向")); // Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/Activity?activityId={0}&flag={1}", request.activityId, 2)); // return empty; // } // ViewData["Type"] = typeCode; //} ////不存在微信用户 //if (!isExistOpenId(wxUser.Openid)) //{ // //保存用户微信信息 // saveUserInfo(wxUser); //} ////保存扫码信息 //saveScanInfo(wxUser.Openid, request.giftId); //#region 保存日志记录至数据库 //entity.Description = string.Format("【热高乐园红包雨】,用户在{0}点击红包,二维码扫码进入实物领奖页面,奖品为{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), request.giftType); //entity.PageDesc = string.Format("实物扫码,得到{0}", request.giftType); //entity.ActivityId = Convert.ToInt32(DESEncrypt.Decrypt(request.giftId, _key)); //logDi.getBll().SaveLog(entity); //#endregion //ViewData["Openid"] = wxUser.Openid ?? ""; //ViewData["wxName"] = wxUser.Nickname ?? ""; //ViewData["AwardDetailId"] = request.giftId ?? ""; //ViewData["AwardName"] = request.giftType ?? ""; //ViewData["Activity"] = request.activityId ?? ""; //return View("Activity"); #endregion } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("{0}领取实物异常,异常信息:{1}", str_a_activityname, ex.ToString())); Response.Redirect(string.Format("{0}?activityId={1}&flag={2}", enter_url, request.activityId, 2)); return(empty); } }
/// <summary> /// ViewData["Openid"] = ""; ////ViewData["wxName"] = "RandyField"; ////ViewData["AwardDetailId"] = ""; ////ViewData["AwardName"] = ""; ////ViewData["Activity"] = ""; ////ViewData["Type"] = "A"; ////return View(); ////ActionResult empty = new EmptyResult(); /// 热高乐园红包雨活动 /// </summary> /// <param name="activityId"></param> /// <param name="flag"></param> /// <returns></returns> /// string type = "1元"; //string opienid = "omJcruMSo_al_vHgI7dQHdixsPEM"; //RequestModel request = new RequestModel //{ // activityName = "【中兴30周年庆现金红包】", // TenPaySender = "中兴大厦", // TenPayWish = "恭喜发财", // TenPayGame = "30周年庆,红包雨", // TenPayRemark = "中兴大厦" //}; //GiveCash(type, opienid, request); public ActionResult Activity(string activityId, string flag, string guid) { /* * if (!string.IsNullOrWhiteSpace(guid)) * { * if (!IsInDate(activityId, guid, 4)) * { * return View("OutOfDate"); * } * } * //未传guid * else * { * return View("OutOfDate"); * } */ ActionResult empty = new EmptyResult(); try { if (string.IsNullOrWhiteSpace(flag)) { //扫码计数-所有 scanCountDi.getBll().CountByNameAndId(activityId, _activityName); } else { if (flag.Trim() == "1") { scanCountDi.getBll().CountByNameAndId(activityId, string.Format("{0}发生重定向-现金红包跳转", _activityName)); } else { scanCountDi.getBll().CountByNameAndId(activityId, string.Format("{0}发生重定向-非现金红包跳转", _activityName)); } } //日志记录公共部分 AwardsInfoModel awardsModel = new AwardsInfoModel(); TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/wxredpackets/NewCity/Activity"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(activityId); //请求奖品 awardsModel = GetAwardsInfo(activityId); //奖品的Class不为空 if (awardsModel.Class != null) { if (awardsModel.Class == "") { scanCountDi.getBll().CountByNameAndId(activityId, string.Format("{0}-取奖品awardsModel.Class == \"\"", _activityName)); return(View("Nogift")); } //重定向 至微信领奖页 string url = string.Format("http://www.chinazhihuiping.com/wxredpackets/NewCity/WXActivity?activityId={0}&giftType={1}&giftId={2}", activityId, awardsModel.Class, awardsModel.id); string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); ResponseWXRedirect(urlencode); return(empty); } else { scanCountDi.getBll().CountByNameAndId(activityId, string.Format("{0}-取奖品awardsModel.Class == null", _activityName)); return(View("Nogift")); } } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("{0}进入领奖页面异常,异常信息:{1}", _activityName, ex.ToString())); return(View("Nogift")); } }
/// <summary> /// 微信控制器 /// </summary> /// <param name="request"></param> /// <returns></returns> public ActionResult WXActivity(RequestModel request) { ActionResult empty = new EmptyResult(); try { #region 数据库日志记录 公共部分 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/NewCity/WXActivity"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(request.activityId); #endregion #region 获取微信用户信息 昵称,头像等 wxUserInfoModel wxUser = GetWxUserInfo(request.code); if (wxUser == null) { //非卡重定向 至微信领奖页 string url = string.Format("http://www.chinazhihuiping.com/wxredpackets/NewCity/WXActivity?activityId={0}&giftType={1}&giftId={2}", request.activityId, request.giftType, request.giftId); string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); ResponseWXRedirect(urlencode); return(empty); } #endregion #region 今天已参加活动 if (isAttendToday(request.activityId, wxUser.Openid)) { //判断奖品是否已领 var receivedModel = awardDi.getBll().hadTakeAward(wxUser.Openid, request.activityId); #region 奖品已核销 //奖品已领 if (receivedModel == null) { scanCountDi.getBll().CountByNameAndId(request.activityId, string.Format("{0}-实物已领取", _activityName)); return(View("HadAttend")); } #endregion #region 奖品还未核销 //奖品还未领取 else { //获取奖品ID int string awardId = receivedModel.AwardDetailId.ToString(); //获取奖品详情 TRP_AwardDetail detailModel = detailDi.getBll().GetEntityById(awardId); //奖品名称 string awardsName = ""; //加密奖品id string ecodeAwardId = DESEncrypt.Encrypt(awardId, _key); if (detailModel != null) { awardsName = detailModel.AwardName; } //奖品类型 if (!string.IsNullOrWhiteSpace(awardsName)) { string typeCode = ""; if (awardsName.Contains("周末礼金")) { typeCode = "A"; } else if (awardsName.Contains("健身月卡")) { typeCode = "B"; } else if (awardsName.Contains("圆春饼")) { typeCode = "C"; } else if (awardsName.Contains("咖啡券")) { typeCode = "D"; } else if (awardsName.Contains("公社五折")) { typeCode = "E"; } else if (awardsName.Contains("公社三折")) { typeCode = "F"; } else if (awardsName.Contains("美甲护理")) { typeCode = "G"; } else if (awardsName.Contains("美甲30元")) { typeCode = "H"; } else if (awardsName.Contains("一叶一生")) { typeCode = "I"; } else if (awardsName.Contains("含花")) { typeCode = "J"; } else if (awardsName.Contains("萌宠")) { typeCode = "K"; } else if (awardsName.Contains("南山")) { typeCode = "L"; } else if (awardsName.Contains("魅可发妆")) { typeCode = "M"; } else if (awardsName.Contains("在宥")) { typeCode = "N"; } else if (awardsName.Contains("月饼")) { typeCode = "O"; } else if (awardsName.Contains("大麦")) { typeCode = "P"; } else { return(View("Nogift")); } ViewData["Type"] = typeCode; } ViewData["Openid"] = wxUser.Openid ?? ""; ViewData["wxName"] = wxUser.Nickname ?? ""; ViewData["AwardDetailId"] = ecodeAwardId; ViewData["AwardName"] = awardsName; ViewData["Activity"] = request.activityId ?? ""; entity.Description = string.Format("用户在{0}点击红包,二维码实物扫码(为重复扫码,上次未核销奖品)", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); entity.PageDesc = "实物扫码,上次未核销奖品"; entity.ActivityId = Convert.ToInt32(request.activityId); logDi.getBll().SaveLog(entity); return(View("Activity")); } #endregion } #endregion #region 首次参加活动 if (request.giftType != null) { string awardsName = request.giftType; string typeCode = ""; if (awardsName.Contains("周末礼金")) { typeCode = "A"; } else if (awardsName.Contains("健身月卡")) { typeCode = "B"; } else if (awardsName.Contains("圆春饼")) { typeCode = "C"; } else if (awardsName.Contains("咖啡券")) { typeCode = "D"; } else if (awardsName.Contains("公社五折")) { typeCode = "E"; } else if (awardsName.Contains("公社三折")) { typeCode = "F"; } else if (awardsName.Contains("美甲护理")) { typeCode = "G"; } else if (awardsName.Contains("美甲30元")) { typeCode = "H"; } else if (awardsName.Contains("一叶一生")) { typeCode = "I"; } else if (awardsName.Contains("含花")) { typeCode = "J"; } else if (awardsName.Contains("萌宠")) { typeCode = "K"; } else if (awardsName.Contains("南山")) { typeCode = "L"; } else if (awardsName.Contains("魅可发妆")) { typeCode = "M"; } else if (awardsName.Contains("在宥")) { typeCode = "N"; } else if (awardsName.Contains("月饼")) { typeCode = "O"; } else if (awardsName.Contains("大麦")) { typeCode = "P"; } else { return(View("Nogift")); //Common.Helper.Logger.Info(string.Format("【中兴30周年红包雨】,用户获取奖品:微信用户-OpenId:{0}-领取奖品,未接收到奖品类型,发生了重定向")); //Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/ZTE/Activity?activityId={0}&flag={1}", request.activityId, 2)); //return empty; } ViewData["Type"] = typeCode; } //不存在微信用户 if (!isExistOpenId(wxUser.Openid)) { //保存用户微信信息 saveUserInfo(wxUser); } //保存扫码信息 saveScanInfo(wxUser.Openid, request.giftId); string awardName = request.giftType; entity.Description = string.Format("{0},用户在{1}点击红包,二维码扫码进入实物领奖页面,奖品为{2}", _activityName, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), request.giftType); entity.PageDesc = string.Format("实物扫码,得到{0}", awardName); entity.ActivityId = Convert.ToInt32(DESEncrypt.Decrypt(request.giftId, _key)); logDi.getBll().SaveLog(entity); ViewData["Openid"] = wxUser.Openid ?? ""; ViewData["wxName"] = wxUser.Nickname ?? ""; ViewData["AwardDetailId"] = request.giftId ?? ""; ViewData["AwardName"] = request.giftType ?? ""; ViewData["Activity"] = request.activityId ?? ""; return(View("Activity")); #endregion #region 注释部分 无限制领取次数 //if (request.giftType != null) //{ // string awardsType = request.giftType; // string typeCode = ""; // if (awardsType.Contains("笔记本")) // { // typeCode = "A"; // } // else // { // Common.Helper.Logger.Info(string.Format("【热高乐园红包雨】,用户获取奖品:微信用户-OpenId:{0}-领取奖品,未接收到奖品类型,发生了重定向")); // Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/ReGaoPark/Activity?activityId={0}&flag={1}", request.activityId, 2)); // return empty; // } // ViewData["Type"] = typeCode; //} ////不存在微信用户 //if (!isExistOpenId(wxUser.Openid)) //{ // //保存用户微信信息 // saveUserInfo(wxUser); //} ////保存扫码信息 //saveScanInfo(wxUser.Openid, request.giftId); //#region 保存日志记录至数据库 //entity.Description = string.Format("【热高乐园红包雨】,用户在{0}点击红包,二维码扫码进入实物领奖页面,奖品为{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), request.giftType); //entity.PageDesc = string.Format("实物扫码,得到{0}", request.giftType); //entity.ActivityId = Convert.ToInt32(DESEncrypt.Decrypt(request.giftId, _key)); //logDi.getBll().SaveLog(entity); //#endregion //ViewData["Openid"] = wxUser.Openid ?? ""; //ViewData["wxName"] = wxUser.Nickname ?? ""; //ViewData["AwardDetailId"] = request.giftId ?? ""; //ViewData["AwardName"] = request.giftType ?? ""; //ViewData["Activity"] = request.activityId ?? ""; //return View("Activity"); #endregion } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("{0}领取实物异常,异常信息:{1}", _activityName, ex.ToString())); Response.Redirect(string.Format("http://www.chinazhihuiping.com/wxredpackets/NewCity/Activity?activityId={0}&flag={1}", request.activityId, 2)); return(empty); } }
/// <summary> /// 活动入口 /// </summary> /// <param name="activityId"></param> /// <param name="awardid"></param> /// <param name="awardname"></param> /// <returns></returns> public ActionResult Activity(string activityId, string awardid, string awardname) { //isAttendToday("279", "omJcruKAnLncYOUTk2xrXKx3kWTc", 3); //awardDi.getBll().hadTakeAward("omJcruKAnLncYOUTk2xrXKx3kWTc", "279"); //ViewData["Openid"] = ""; //ViewData["wxName"] = "RandyField"; //ViewData["AwardDetailId"] = ""; //ViewData["AwardName"] = ""; //ViewData["Activity"] = ""; //ViewData["Type"] = "A"; //return View(); ActionResult empty = new EmptyResult(); //前端网不好 if (string.IsNullOrWhiteSpace(awardid)) { return(View("Nogift")); } //Common.Helper.Logger.Info(string.Format("{0}进入领奖页面,活动id-{1},奖品id-{2},奖品名称,{3}", str_a_activityname, activityId, awardid, awardname)); #region 测试 //ViewData["Openid"] = ""; //ViewData["wxName"] = "RandyField"; //ViewData["AwardDetailId"] = ""; //ViewData["AwardName"] = ""; //ViewData["Activity"] = ""; //ViewData["Type"] = "A"; //return View(); #endregion try { //awardname = System.Web.HttpUtility.UrlDecode(awardname, System.Text.Encoding.Unicode); #region 扫码计数 //scanCountDi.getBll().CountByNameAndId(activityId, str_a_activityname); #endregion #region 记录日志 //日志记录公共部分 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? enter_url; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(activityId); #endregion #region 重定向至微信授权URL //重定向至微信领奖页url,把奖品信息参数包裹 string url = string.Format("{0}?activityId={1}&giftId={2}&giftType={3}", wx_url, activityId, awardid, awardname); //url encode编码 string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); //重定向 微信授权url ResponseWXRedirect(urlencode); #endregion return(empty); } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("{0}进入领奖页面异常,异常信息:{1}", str_a_activityname, ex.ToString())); return(View("Nogift")); } }
/// <summary> /// ViewData["Openid"] = ""; ////ViewData["wxName"] = "RandyField"; ////ViewData["AwardDetailId"] = ""; ////ViewData["AwardName"] = ""; ////ViewData["Activity"] = ""; ////ViewData["Type"] = "A"; ////return View(); ////ActionResult empty = new EmptyResult(); /// 热高乐园红包雨活动 /// </summary> /// <param name="activityId"></param> /// <param name="flag"></param> /// <returns></returns> public ActionResult Activity(string activityId, string flag, string guid) { //string type = "0.88元现金红包"; //string opienid = "omJcruMSo_al_vHgI7dQHdixsPEM"; //RequestModel request=new RequestModel { // activityName = "【中兴30周年庆现金红包】", // TenPaySender = "中兴大厦", // TenPayWish = "恭喜发财", // TenPayGame = "30周年庆,红包雨", // TenPayRemark = "中兴大厦" //}; //GiveCash(type, opienid, request); /* * if (!string.IsNullOrWhiteSpace(guid)) * { * if (!IsInDate(activityId, guid, 4)) * { * return View("OutOfDate"); * } * } * //未传guid * else * { * return View("OutOfDate"); * } */ ActionResult empty = new EmptyResult(); try { if (string.IsNullOrWhiteSpace(flag)) { //扫码计数-所有 scanCountDi.getBll().CountByNameAndId(activityId, "【中兴30周年红包雨】"); } else { if (flag.Trim() == "1") { scanCountDi.getBll().CountByNameAndId(activityId, "【中兴30周年红包雨】发生重定向-现金红包跳转)"); } else { scanCountDi.getBll().CountByNameAndId(activityId, "【中兴30周年红包雨】发生重定向-非现金红包跳转)"); } } //日志记录公共部分 AwardsInfoModel awardsModel = new AwardsInfoModel(); TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/wxredpackets/ZTE/Activity"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(activityId); //请求奖品 awardsModel = GetAwardsInfo(activityId); //奖品的Class不为空 if (awardsModel.Class != null) { if (awardsModel.Class == "") { scanCountDi.getBll().CountByNameAndId(activityId, "【中兴30周年红包雨】-取奖品awardsModel.Class == \"\""); return(View("Nogift")); } //重定向 至微信领奖页 string url = string.Format("http://www.chinazhihuiping.com/wxredpackets/ZTE/WXActivity?activityId={0}&giftType={1}&giftId={2}", activityId, awardsModel.Class, awardsModel.id); string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); ResponseWXRedirect(urlencode); return(empty); } else { scanCountDi.getBll().CountByNameAndId(activityId, "【中兴30周年红包雨】-取奖品awardsModel.Class == null"); return(View("Nogift")); } } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("【中兴30周年红包雨】进入领奖页面异常,异常信息:{0}", ex.ToString())); return(View("Nogift")); } }
/// <summary> /// 活动入口 /// </summary> /// <param name="activityId"></param> /// <param name="awardid"></param> /// <param name="awardname"></param> /// <returns></returns> public ActionResult Activity(string activityId, string awardid, string awardname) { //ViewData["Openid"] = ""; //ViewData["wxName"] = "RandyField"; //ViewData["AwardDetailId"] = ""; //ViewData["AwardName"] = ""; //ViewData["Activity"] = ""; //ViewData["Type"] = "A"; //return View(); ActionResult empty = new EmptyResult(); //前端网不好 if (string.IsNullOrWhiteSpace(awardid)) { if (!string.IsNullOrWhiteSpace(awardname)) { RedirectRedPocket(dic_url, awardname); scanCountDi.getBll().CountByNameAndId(activityId, string.Format("【京东12月互动游戏】-flash端网络异常, 跳转券-【{0}】", awardname)); return(empty); } else { string url = ""; RedirectRandom(dic_rom_url, 3, out url); string key = dic_url.FirstOrDefault(q => q.Value.Contains(url)).Key; scanCountDi.getBll().CountByNameAndId(activityId, "【京东12月互动游戏】-取奖为空, 随机跳转券-【" + key + "】"); return(empty); } } //Common.Helper.Logger.Info(string.Format("{0}进入领奖页面,活动id-{1},奖品id-{2},奖品名称,{3}", str_a_activityname, activityId, awardid, awardname)); #region 测试 //ViewData["Openid"] = ""; //ViewData["wxName"] = "RandyField"; //ViewData["AwardDetailId"] = ""; //ViewData["AwardName"] = ""; //ViewData["Activity"] = ""; //ViewData["Type"] = "A"; //return View(); #endregion try { //awardname = System.Web.HttpUtility.UrlDecode(awardname, System.Text.Encoding.Unicode); #region 扫码计数 //scanCountDi.getBll().CountByNameAndId(activityId, str_a_activityname); #endregion #region 记录日志 //日志记录公共部分 TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? enter_url; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; entity.ActivityId = Convert.ToInt32(activityId); #endregion #region 重定向至微信授权URL //重定向至微信领奖页url,把奖品信息参数包裹 string url = string.Format("{0}?activityId={1}&giftId={2}&giftType={3}", wx_url, activityId, awardid, awardname); //url encode编码 string urlencode = System.Web.HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8); //重定向 微信授权url ResponseWXRedirect(urlencode); #endregion return(empty); } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("{0}进入领奖页面异常,异常信息:{1}", str_a_activityname, ex.ToString())); return(View("Nogift")); } }
/// <summary> /// 页面加载 /// </summary> /// <param name="request"></param> /// <returns></returns> public ActionResult Index(RequestModel request) { //return View(); //awardDi.getBll().hadTakeAward("omJcruMSo_al_vHgI7dQHdixsPEM", "44"); try { HttpHelper httpHelper = new HttpHelper(); #region 微信网页授权 string tokenJson = httpHelper.HttpGet(String.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", _appId, _appsecret, request.code), ""); JObject tokenJsonObj = null; if (!string.IsNullOrWhiteSpace(tokenJson)) { tokenJsonObj = JObject.Parse(tokenJson); } else { return(View("Error")); } string userInfoJson = ""; wxUserInfoModel model = null; if (tokenJsonObj != null) { userInfoJson = httpHelper.HttpGet(string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", tokenJsonObj["access_token"], tokenJsonObj["openid"]), ""); if (!string.IsNullOrWhiteSpace(userInfoJson)) { model = JsonConvert.DeserializeObject <wxUserInfoModel>(userInfoJson); if (model.Nickname == null || model.Sex == null) { return(View("Error")); } } else { return(View("Error")); } } else { return(View("Error")); } #endregion ActivityStatus status = new ActivityStatus(); status = ActivityStatus.Unknown; //活动id未取到 if (string.IsNullOrWhiteSpace(request.activityId)) { return(View("Error")); } TRP_ClientLog entity = new TRP_ClientLog(); entity.CreateTime = DateTime.Now; entity.DeleteMark = false; entity.Enable = true; entity.PageUrl = HttpContext.Request.Url.AbsoluteUri ?? "http://www.chinazhihuiping.com/wxredpackets"; entity.IPAddress = HttpContext.Request.UserHostAddress ?? "127.0.0.1"; //今天已参加活动 无领奖资格 直接返回视图 不请求奖品 if (isAttendToday(request.activityId, model.Openid)) { status = ActivityStatus.HasAttend; //判断奖品是否已领 如果没有领取 该奖品继续返回页面 var receivedModel = awardDi.getBll().hadTakeAward(model.Openid, request.activityId); if (receivedModel == null) { entity.Description = string.Format("用户在{0}点击红包,二维码实物扫码(已参加活动,为重复扫码)", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); entity.PageDesc = "实物扫码,已参加本次活动"; entity.ActivityId = Convert.ToInt32(request.activityId); logDi.getBll().SaveLog(entity); return(View("HasAttend")); } else { //获取奖品ID int string awardId = receivedModel.AwardDetailId.ToString(); TRP_AwardDetail detailModel = detailDi.getBll().GetEntityById(awardId); //奖品名称 string awardsName = ""; //加密奖品id string ecodeAwardId = DESEncrypt.Encrypt(awardId, _key); Common.Helper.Logger.Info("发生了重定向奖品Id加密:" + ecodeAwardId); if (detailModel != null) { //奖品名称 awardsName = detailModel.AwardName; Common.Helper.Logger.Info("发生了重定向奖品名称:" + awardsName); } if (!string.IsNullOrWhiteSpace(awardsName)) { string awardsType = awardsName; string typeCode = ""; if (awardsType.Contains("美食券")) { typeCode = "A"; } else if (awardsType.Contains("电影券")) { typeCode = "B"; } else if (awardsType.Contains("水趣多")) { typeCode = "C"; } else { typeCode = "D"; Common.Helper.Logger.Info(string.Format("重定向:微信用户-OpenId:{0}-领取奖品,未接收到奖品类型,默认发瓶水", model.Openid)); } ViewData["Type"] = typeCode; Common.Helper.Logger.Info("发生了重定向奖品type:" + typeCode); } else { ViewData["Type"] = ""; } ViewData["Openid"] = model.Openid ?? ""; ViewData["wxName"] = model.Nickname ?? ""; ViewData["AwardDetailId"] = ecodeAwardId; ViewData["AwardName"] = awardsName; ViewData["Activity"] = request.activityId ?? ""; entity.Description = string.Format("用户在{0}点击红包,二维码实物扫码(为重复扫码,上次未核销奖品)", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); entity.PageDesc = "实物扫码,上次未核销奖品"; entity.ActivityId = Convert.ToInt32(request.activityId); logDi.getBll().SaveLog(entity); return(View()); } //return View("HasAttend"); } string activityId = request.activityId; //http://localhost:89/RedPacketService/GetRedPacketServie?activityId=44 //获取奖品信息 string awards = httpHelper.HttpGet(String.Format("http://localhost:89/RedPacketService/GetRedPacketServie?activityId={0}", activityId), ""); if (string.IsNullOrWhiteSpace(awards)) { return(View("Error")); } //反序列化获取奖品信息 AwardsInfoModel awardsInfo = JsonConvert.DeserializeObject <AwardsInfoModel>(awards); if (awardsInfo != null) { if (awardsInfo.Class != null) { string awardsType = awardsInfo.Class; string typeCode = ""; if (awardsType.Contains("美食券")) { typeCode = "A"; } else if (awardsType.Contains("电影券")) { typeCode = "B"; } else if (awardsType.Contains("水趣多")) { typeCode = "C"; } else { typeCode = "D"; Common.Helper.Logger.Info(string.Format("获取奖品:微信用户-OpenId:{0}-领取奖品,未接收到奖品类型,默认发瓶水", model.Openid)); } ViewData["Type"] = typeCode; } } //首次参加本次活动 status = ActivityStatus.FirstTime; //不存在微信用户 if (!isExistOpenId(model.Openid)) { //保存用户微信信息 saveUserInfo(model); } //保存扫码信息 saveScanInfo(model.Openid, awardsInfo.id); string awardName = awardsInfo.Class; if (status == ActivityStatus.FirstTime) { entity.Description = string.Format("用户在{0}点击红包,二维码扫码进入实物领奖页面,奖品为{1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), awardName); entity.PageDesc = string.Format("实物扫码,得到{0}", awardName); entity.ActivityId = Convert.ToInt32(DESEncrypt.Decrypt(awardsInfo.id, _key)); logDi.getBll().SaveLog(entity); ViewData["Openid"] = model.Openid ?? ""; ViewData["wxName"] = model.Nickname ?? ""; ViewData["AwardDetailId"] = awardsInfo.id ?? ""; ViewData["AwardName"] = awardsInfo.Class ?? ""; ViewData["Activity"] = request.activityId ?? ""; return(View()); } } catch (Exception ex) { Common.Helper.Logger.Info(string.Format("进入领奖页面异常,异常信息:{0}", ex.ToString())); } return(View("Error")); }