public ActionResult Index() { try { //页面上的Plugins IList <Plugin> plugins = _pluginService.GetALL(); //用isopen 来区分 是传统的抽奖还是 积分系统 Plugin curPlugin = plugins.Where(p => p.IsOpen == 1).FirstOrDefault(); ViewBag.CurPlugin = curPlugin; if (curPlugin == null) { throw new OceanException("对不起,不存在该插件或未开通,请检查!"); } ViewBag.Title = curPlugin.RPluginBase.Name; XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(curPlugin.Value); XmlNode pluginNode = xmlDoc.SelectSingleNode("plugin"); GetDataToViewData(pluginNode); ViewBag.MpUserArr = this.MpUserArr; ViewBag.MpUserID = this.MpUserID; ViewBag.CurrentScore = ViewBag.RecommendScore = ViewBag.DealScore = 0; if (MpUserID != Guid.Empty) { PagedList <ScoreConsumeInfo> scoreConsumeInfoList = _scoreConsumeInfoService.GetConsumeScoreList(MpUserID, 1, 30);//"from SceneResult where PluginId='" + Id.ToString() + "'"); ViewBag.ScoreConsumeInfoList = scoreConsumeInfoList; ScoreUser scoreUser = _scoreUserService.GetUnique("from ScoreUser where (MpUserId ='" + this.MpUserID + "')"); if (scoreUser != null) { ViewBag.CurrentScore = scoreUser.CurrentScore; ViewBag.RecommendScore = scoreUser.RecommendScore; ViewBag.DealScore = scoreUser.DealScore; } IList <ScorePluginResult> scorePluginResultList = _scorePluginResultService.GetList("from ScorePluginResult where MpUserId='" + MpUserID + "' order by createdate desc"); ViewBag.MyPlugin_SubmitList = scorePluginResultList; } bindScore = ViewData.GetInt("Score_Bind"); // ViewBag.Score_Bind; recommendScore = ViewData.GetInt("Score_Recommend"); // ViewBag.Score_Recommend; TempData["Id"] = curPlugin.Id; TempData["Score_Plugin_Title"] = ViewBag.Score_Plugin_Title; TempData["Score_Plugin_Summary"] = ViewBag.Score_Plugin_Summary; TempData["Score_Plugin_StartDate"] = ViewBag.Score_Plugin_StartDate; TempData["Score_Plugin_EndDate"] = ViewBag.Score_Plugin_EndDate; TempData["Score_Plugin_ZeroPrize"] = ViewBag.Score_Plugin_ZeroPrize; TempData["Score_Plugin_UsePoint"] = ViewData.GetInt("Score_Plugin_UsePoint"); TempData["Score_Plugin_FailsTimes"] = ViewBag.Score_Plugin_FailsTimes; TempData["Score_Plugin_FailsAddOdds"] = ViewBag.Score_Plugin_FailsAddOdds; return(View("Index")); } catch (Exception ex) { throw new OceanException(ex.Message, ex); } }
public ActionResult PluginsLottery(Guid Id, string t) { try { //Log4NetImpl.Write("抽奖开始:1"); if (Id == Guid.Empty) { return(Json(new { isOK = false, error_code = "ERR_ArgNotExist" })); //message = "参数有误,请检查!" }); } if (MpUserID == Guid.Empty) { string rawUrl = "http://wx.ssrcb.com/pluginsScene/PluginsLottery?id=" + WebHelper.GetGuid("Id", Guid.Empty); if (string.IsNullOrEmpty(RQuery["openid"])) { return(Json(new { isOK = false, isLogin = true, error_code = "ERR_NotLogin", message = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri=http://wx.ssrcb.com/mpuser/autologin?refUrl={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", MpCenterCache.AppID, rawUrl) })); } } Plugin plugin = _pluginService.GetById(Id); if (plugin == null) { return(Json(new { isOK = false, error_code = "ERR_PluginNotExits" }));//message = "对不起,不存在该插件或未开通,请检查!" }); } //设置布局页 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(plugin.Value); XmlNode pluginNode = xmlDoc.SelectSingleNode("plugin"); GetDataToViewData(pluginNode); if (ViewBag.Cst_Plugin_Title == null) { return(Json(new { isOK = false, error_code = "ERR_PluginNotExits" }));// message = "对不起,您还未配置或配置错误,请到插件中心进行配置下!" }); } if (!string.IsNullOrEmpty(ViewBag.Cst_Plugin_StartDate)) { DateTime startDate = TypeConverter.StrToDateTime(ViewBag.Cst_Plugin_StartDate.ToString()); if (startDate > DateTime.Now) { return(Json(new { isOK = false, error_code = "ERR_PluginNotStart" }));// message = "对不起,抽奖还未开始!" }); } else { if (!string.IsNullOrEmpty(ViewBag.Cst_Plugin_EndDate)) { DateTime endDate = TypeConverter.StrToDateTime(ViewBag.Cst_Plugin_EndDate.ToString()); if (endDate < DateTime.Now) { return(Json(new { isOK = false, error_code = "ERR_PluginIsEnd" }));// message = "对不起,抽奖已经结束!" }); } } } } //PluginSceneVerifyCodeDetail verifyCodeDetail = _pluginSceneVerifyCodeDetailService.GetUnique("from SceneVerifyCodeDetail where ClientMPID='" + this.MpUserID.ToString() + "' and convert(char(10),(CreateDate),120) = '" + DateTime.Now.ToString("yyyy-MM-dd") + "'"); PluginSceneVerifyCodeDetail verifyCodeDetail = _pluginSceneVerifyCodeDetailService.GetUnique("from SceneVerifyCodeDetail where ClientMPID='" + this.MpUserID.ToString() + "' and cast(DATEPART(YEAR, CreateDate) as varchar(4))+'-'+ cast(DATEPART(MONTH, CreateDate) as varchar(2)) = '" + DateTime.Now.ToString("yyyy-MM") + "'"); if (verifyCodeDetail == null) { return(Json(new { isOK = false, isVertfy = true, error_code = "ERR_UserNotVerify" })); } if (verifyCodeDetail.LeaveCount <= 0) { return(Json(new { isOK = false, error_code = "ERR_UserUseOutChance" })); } int prizeCount = TypeConverter.StrToInt(ViewBag.Cst_Plugin_PrizeCount, 12); int prizeItemCount = TypeConverter.StrToInt(ViewBag.Cst_Plugin_Items_Count, 1); if (prizeCount != prizeItemCount) { Log4NetImpl.Write("奖项设置不正确"); return(Json(new { isOK = false, error_code = "ERR_ArgNotExist" })); } IList <PrizeGift> prizeGift = new List <PrizeGift>(prizeItemCount); IList <Double> prizeItems = new List <Double>(prizeItemCount); IList <string> prizeItemsName = new List <string>(prizeCount); IList <int> prizeAngle = new List <int>(12); prizeItemsName.Add("一"); prizeItemsName.Add("二"); prizeItemsName.Add("三"); prizeItemsName.Add("四"); prizeItemsName.Add("五"); prizeItemsName.Add("六"); prizeItemsName.Add("七"); prizeItemsName.Add("八"); prizeItemsName.Add("九"); prizeItemsName.Add("十"); prizeItemsName.Add("十一"); prizeItemsName.Add("十二"); for (int i = 0; i < prizeItemCount; i++) { PrizeGift gift = new PrizeGift(); gift.ID = i; gift.Name = ViewData.GetString("Cst_Plugin_Items_PrizeName" + i.ToString()); gift.Alias_Name = ViewData.GetString("Cst_Plugin_Items_PrizeAliasName" + i.ToString()); gift.Odds = ViewData.GetDouble("Cst_Plugin_Items_PrizePercent" + i.ToString(), 0.00) / 100.00; gift.Pic = ViewData.GetString("Cst_Plugin_Items_PrizePic" + i.ToString()); gift.Quantity = ViewData.GetInt("Cst_Plugin_Items_PrizeNum" + i.ToString()); if (ViewData["Cst_Plugin_Items_PrizeUsedNum" + i.ToString()] != null) { gift.Leavings_Quantity = ViewData.GetInt("Cst_Plugin_Items_PrizeUsedNum" + i.ToString()); } else { gift.Leavings_Quantity = gift.Quantity; } gift.Angle = ViewData.GetInt("Cst_Plugin_Items_PrizeAngle" + i.ToString()); prizeAngle.Add(gift.Angle); gift.Prize_Name = prizeItemsName[i] + "等奖"; if (!string.IsNullOrEmpty(gift.Alias_Name)) { gift.Prize_Name = gift.Alias_Name; } gift.Has_Gift = ViewData.GetInt("Cst_Plugin_Items_Has_Gift" + i.ToString()); gift.Users = ViewData.GetString("Cst_Plugin_Items_SiteUsers" + i.ToString()); gift.UsersName = ViewData.GetString("Cst_Plugin_Items_SiteUsersName" + i.ToString()); prizeItems.Add(gift.Odds); prizeGift.Add(gift); } int averageAngle = 360 / prizeCount; prizeItems.OrderBy(d => d); int result = -1; string resultStr = ""; verifyCodeDetail.LeaveCount = verifyCodeDetail.LeaveCount - 1; verifyCodeDetail.UseDate = DateTime.Now; _pluginSceneVerifyCodeDetailService.Update(verifyCodeDetail); int count = _pluginSceneResultService.GetCount("from SceneResult where pluginId='" + Id.ToString() + "' and MpUserId='" + this.MpUserID.ToString() + "' and cast(DATEPART(YEAR, CreateDate) as varchar(4))+'-'+ cast(DATEPART(MONTH, CreateDate) as varchar(2)) = '" + DateTime.Now.ToString("yyyy-MM") + "'"); if (ViewData.GetInt("Cst_Plugin_ZeroPrize") == 1 && count > 0) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" })); } if (prizeGift.Where(g => g.Has_Gift == 1 && g.Leavings_Quantity > 0).Count() == 0) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));//new PrizeGift() { ID = -1, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 300, Prize_Name = "继续加油" }); } result = LotteryUtils.Lottery(prizeItems, prizeGift, prizeCount, this.MpUserID, Id); if (result == -1) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));//Json(new PrizeGift() { ID = -1, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 240, Prize_Name = "继续加油" }); } else if (result == -2) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));// Json(new PrizeGift() { ID = -2, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 180, Prize_Name = "继续加油" }); } else if (result == -3) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));// Json(new PrizeGift() { ID = -2, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 180, Prize_Name = "继续加油" }); } else { PrizeGift hasPrizeGift = prizeGift[result]; hasPrizeGift.Alias_Name = hasPrizeGift.Alias_Name ?? ""; if (hasPrizeGift.Has_Gift == 1 && hasPrizeGift.Leavings_Quantity > 0) { //中奖业务处理 PluginSceneResult pluginSceneResult = new PluginSceneResult(); pluginSceneResult.Address = ""; pluginSceneResult.CreateDate = DateTime.Now; pluginSceneResult.Email = ""; pluginSceneResult.IsUse = 0; pluginSceneResult.MobilePhone = ""; pluginSceneResult.Name = ""; pluginSceneResult.Phone = ""; pluginSceneResult.PluginId = Id; pluginSceneResult.MpUserId = this.MpUserID; pluginSceneResult.SN = ""; pluginSceneResult.UserName = (string.IsNullOrEmpty(this.Name) ? this.NickName : this.Name); if (this.MpUserArr != null) { pluginSceneResult.Summary = "恭喜用户[" + (string.IsNullOrEmpty(this.Name) ? this.NickName : this.Name) + "]获得" + hasPrizeGift.Prize_Name + "[" + hasPrizeGift.Name + "]"; } else { pluginSceneResult.Summary = "恭喜匿名用户获得" + hasPrizeGift.Prize_Name + "[" + hasPrizeGift.Name + "]"; } pluginSceneResult.Value = "<?xml version=\"1.0\" encoding=\"utf-8\"?><PluginSubmit><Cst_Plugin_ItemIndex>" + result.ToString() + "</Cst_Plugin_ItemIndex><Cst_Plugin_PrizeLevel>" + hasPrizeGift.Prize_Name + "</Cst_Plugin_PrizeLevel><Cst_Plugin_PrizeName>" + hasPrizeGift.Name + "</Cst_Plugin_PrizeName></PluginSubmit>"; #region 更新中奖数量 XmlNode itemsNode = pluginNode.SelectSingleNode("Cst_Plugin_Items"); XmlNode node = itemsNode.SelectSingleNode("Cst_Plugin_Items_PrizeUsedNum" + result.ToString()); if (node == null) { node = xmlDoc.CreateElement("Cst_Plugin_Items_PrizeUsedNum" + result.ToString()); node.InnerText = (hasPrizeGift.Quantity - 1).ToString(); itemsNode.AppendChild(node); } else { node.InnerText = (hasPrizeGift.Leavings_Quantity - 1).ToString(); } StringWriter sw = new StringWriter(); XmlTextWriter tx = new XmlTextWriter(sw); xmlDoc.WriteTo(tx); string strXmlText = sw.ToString(); plugin.Value = strXmlText; _pluginService.Update(plugin); #endregion _pluginSceneResultService.Insert(pluginSceneResult); hasPrizeGift.ResultID = pluginSceneResult.Id; } return(Content(JsonConvert.SerializeObject(hasPrizeGift), "text/javascript")); } } catch (Exception ex) { throw new OceanException(ex.Message, ex); } }
public ActionResult PluginsLottery(Guid Id, string t, string OpenID) { try { if (Id == Guid.Empty) { Log4NetImpl.Write("PluginsLottery:ajax-ERR_ArgNotExist"); return(Json(new { isOK = false, error_code = "ERR_ArgNotExist" })); } Plugin plugin = _pluginService.GetById(Id); if (plugin == null) { return(Json(new { isOK = false, error_code = "ERR_PluginNotExits" })); } //设置布局页 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(plugin.Value); XmlNode pluginNode = xmlDoc.SelectSingleNode("plugin"); GetDataToViewData(pluginNode); if (ViewBag.Cst_Plugin_Title == null) { return(Json(new { isOK = false, error_code = "ERR_PluginNotExits" }));// message = "对不起,您还未配置或配置错误,请到插件中心进行配置下!" }); } if (!string.IsNullOrEmpty(ViewBag.Cst_Plugin_StartDate)) { DateTime startDate = TypeConverter.StrToDateTime(ViewBag.Cst_Plugin_StartDate.ToString()); if (startDate > DateTime.Now) { return(Json(new { isOK = false, error_code = "ERR_PluginNotStart" }));// message = "对不起,抽奖还未开始!" }); } else { if (!string.IsNullOrEmpty(ViewBag.Cst_Plugin_EndDate)) { DateTime endDate = TypeConverter.StrToDateTime(ViewBag.Cst_Plugin_EndDate.ToString()); if (endDate < DateTime.Now) { return(Json(new { isOK = false, error_code = "ERR_PluginIsEnd" }));// message = "对不起,抽奖已经结束!" }); } } } } XYPluginUser xyPluginUser = _xyPluginUserService.GetUnique("from XYPluginUser where OpenId='" + OpenID + "'"); if (xyPluginUser == null) { Log4NetImpl.Write("PluginsLottery:ajax-ERR_UserNotVerify"); return(Json(new { isOK = false, isVertfy = true, error_code = "ERR_UserNotVerify" })); } if (xyPluginUser.LeftCount <= 0) { Log4NetImpl.Write("PluginsLottery:ajax-ERR_UserUseOutChance"); return(Json(new { isOK = false, error_code = "ERR_UserUseOutChance" })); } int prizeCount = TypeConverter.StrToInt(ViewBag.Cst_Plugin_PrizeCount, 12); int prizeItemCount = TypeConverter.StrToInt(ViewBag.Cst_Plugin_Items_Count, 1); if (prizeCount != prizeItemCount) { Log4NetImpl.Write("PluginsLottery:ajax-奖项设置不正确"); return(Json(new { isOK = false, error_code = "ERR_ArgNotExist" })); } IList <PrizeGift> prizeGift = new List <PrizeGift>(prizeItemCount); IList <Double> prizeItems = new List <Double>(prizeItemCount); IList <string> prizeItemsName = new List <string>(prizeCount); IList <int> prizeAngle = new List <int>(12); prizeItemsName.Add("一"); prizeItemsName.Add("二"); prizeItemsName.Add("三"); prizeItemsName.Add("四"); prizeItemsName.Add("五"); prizeItemsName.Add("六"); prizeItemsName.Add("七"); prizeItemsName.Add("八"); prizeItemsName.Add("九"); prizeItemsName.Add("十"); prizeItemsName.Add("十一"); prizeItemsName.Add("十二"); for (int i = 0; i < prizeItemCount; i++) { PrizeGift gift = new PrizeGift(); gift.ID = i; gift.Name = ViewData.GetString("Cst_Plugin_Items_PrizeName" + i.ToString()); gift.Alias_Name = ViewData.GetString("Cst_Plugin_Items_PrizeAliasName" + i.ToString()); gift.Odds = ViewData.GetDouble("Cst_Plugin_Items_PrizePercent" + i.ToString(), 0.00) / 100.00; gift.Pic = ViewData.GetString("Cst_Plugin_Items_PrizePic" + i.ToString()); gift.Quantity = ViewData.GetInt("Cst_Plugin_Items_PrizeNum" + i.ToString()); if (ViewData["Cst_Plugin_Items_PrizeUsedNum" + i.ToString()] != null) { gift.Leavings_Quantity = ViewData.GetInt("Cst_Plugin_Items_PrizeUsedNum" + i.ToString()); } else { gift.Leavings_Quantity = gift.Quantity; } gift.Angle = ViewData.GetInt("Cst_Plugin_Items_PrizeAngle" + i.ToString()); prizeAngle.Add(gift.Angle); gift.Prize_Name = prizeItemsName[i] + "等奖"; if (!string.IsNullOrEmpty(gift.Alias_Name)) { gift.Prize_Name = gift.Alias_Name; } gift.Has_Gift = ViewData.GetInt("Cst_Plugin_Items_Has_Gift" + i.ToString());//>1为奖品,2为刮刮卡 gift.Users = ViewData.GetString("Cst_Plugin_Items_SiteUsers" + i.ToString()); gift.UsersName = ViewData.GetString("Cst_Plugin_Items_SiteUsersName" + i.ToString()); prizeItems.Add(gift.Odds); prizeGift.Add(gift); } int averageAngle = 360 / prizeCount; prizeItems.OrderBy(d => d); int result = -1; xyPluginUser.LeftCount = xyPluginUser.LeftCount - 1; _xyPluginUserService.Update(xyPluginUser); int count = _pluginSceneResultService.GetCount("from SceneResult where pluginId='" + Id.ToString() + "' and MpUserId='" + xyPluginUser.Id + "'"); if (ViewData.GetInt("Cst_Plugin_ZeroPrize") == 1 && count > 0) { Log4NetImpl.Write("PluginsLottery:ajax-ERR_RunOutOfGift"); return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" })); } if (prizeGift.Where(g => g.Has_Gift > 1 && g.Leavings_Quantity > 0).Count() == 0) { Log4NetImpl.Write("PluginsLottery:ajax-ERR_RunOutOfGift"); return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" })); } result = LotteryUtils.Lottery(prizeItems, prizeGift, prizeCount, xyPluginUser.Id, Id); if (result == -1) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" })); } else if (result == -2) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));// Json(new PrizeGift() { ID = -2, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 180, Prize_Name = "继续加油" }); } else if (result == -3) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));// Json(new PrizeGift() { ID = -2, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 180, Prize_Name = "继续加油" }); } else { PrizeGift hasPrizeGift = prizeGift[result]; hasPrizeGift.Alias_Name = hasPrizeGift.Alias_Name ?? ""; if (hasPrizeGift.Has_Gift > 0 && hasPrizeGift.Leavings_Quantity > 0) { //中奖业务处理 PluginSceneResult pluginSceneResult = new PluginSceneResult(); pluginSceneResult.Address = ""; pluginSceneResult.CreateDate = DateTime.Now; pluginSceneResult.Email = ""; pluginSceneResult.IsUse = 0; pluginSceneResult.MobilePhone = ""; pluginSceneResult.Name = ""; pluginSceneResult.Phone = ""; pluginSceneResult.PluginId = Id; pluginSceneResult.MpUserId = xyPluginUser.Id; pluginSceneResult.SN = ""; pluginSceneResult.UserName = (string.IsNullOrEmpty(this.Name) ? this.NickName : this.Name); if (hasPrizeGift.Has_Gift == 2)//刮刮卡 { xyPluginUser.GuaGuaKa = 1; _xyPluginUserService.Update(xyPluginUser); } if (this.MpUserArr != null) { pluginSceneResult.Summary = "恭喜用户[" + (string.IsNullOrEmpty(this.Name) ? this.NickName : this.Name) + "]获得" + hasPrizeGift.Prize_Name + "[" + hasPrizeGift.Name + "]"; } else { pluginSceneResult.Summary = "恭喜匿名用户获得" + hasPrizeGift.Prize_Name + "[" + hasPrizeGift.Name + "]"; } pluginSceneResult.Value = "<?xml version=\"1.0\" encoding=\"utf-8\"?><PluginSubmit><Cst_Plugin_ItemIndex>" + result.ToString() + "</Cst_Plugin_ItemIndex><Cst_Plugin_PrizeLevel>" + hasPrizeGift.Prize_Name + "</Cst_Plugin_PrizeLevel><Cst_Plugin_PrizeName>" + hasPrizeGift.Name + "</Cst_Plugin_PrizeName></PluginSubmit>"; #region 更新中奖数量 XmlNode itemsNode = pluginNode.SelectSingleNode("Cst_Plugin_Items"); XmlNode node = itemsNode.SelectSingleNode("Cst_Plugin_Items_PrizeUsedNum" + result.ToString()); if (node == null) { node = xmlDoc.CreateElement("Cst_Plugin_Items_PrizeUsedNum" + result.ToString()); node.InnerText = (hasPrizeGift.Quantity - 1).ToString(); itemsNode.AppendChild(node); } else { node.InnerText = (hasPrizeGift.Leavings_Quantity - 1).ToString(); } StringWriter sw = new StringWriter(); XmlTextWriter tx = new XmlTextWriter(sw); xmlDoc.WriteTo(tx); string strXmlText = sw.ToString(); plugin.Value = strXmlText; _pluginService.Update(plugin); #endregion _pluginSceneResultService.Insert(pluginSceneResult); hasPrizeGift.ResultID = pluginSceneResult.Id; } return(Content(JsonConvert.SerializeObject(hasPrizeGift), "text/javascript")); } } catch (Exception ex) { throw new OceanException(ex.Message, ex); } }
public ActionResult PluginsLottery(Guid Id, string t) { try { if (Id == Guid.Empty) { Log4NetImpl.Write("ScoreSYS-PluginLottery:ID is NULL"); return(Json(new { isOK = false, error_code = "ERR_ArgNotExist" })); //message = "参数有误,请检查!" }); } if (MpUserID == Guid.Empty) { string rawUrl = "http://wx.ssrcb.com/ScoreSys/PluginLottery?id=" + WebHelper.GetGuid("Id", Guid.Empty); if (string.IsNullOrEmpty(RQuery["openid"])) { Log4NetImpl.Write("ScoreSYS-PluginLottery:Redirect"); return(Json(new { isOK = false, isLogin = true, error_code = "ERR_NotLogin", message = string.Format("https://open.weixin.qq.com/connect/oauth2/authorize?appid={0}&redirect_uri=http://wx.ssrcb.com/mpuser/autologin?refUrl={1}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", MpCenterCache.AppID, rawUrl) })); } } string Score_Plugin_Title = Request.Form["Score_Plugin_Title"]; string Score_Plugin_StartDate = Request.Form["Score_Plugin_StartDate"]; string Score_Plugin_EndDate = Request.Form["Score_Plugin_EndDate"]; string Score_Plugin_UsePoint = Request.Form["Score_Plugin_UsePoint"]; string Score_Plugin_FailsTimes = Request.Form["Score_Plugin_FailsTimes"]; string Score_Plugin_FailsAddOdds = Request.Form["Score_Plugin_FailsAddOdds"]; if (Score_Plugin_Title == "") { return(Json(new { isOK = false, error_code = "ERR_PluginNotExits" })); } if (!string.IsNullOrEmpty(Score_Plugin_StartDate)) { DateTime startDate = TypeConverter.StrToDateTime(Score_Plugin_StartDate); if (startDate > DateTime.Now) { return(Json(new { isOK = false, error_code = "ERR_PluginNotStart" })); } else { if (!string.IsNullOrEmpty(Score_Plugin_EndDate)) { DateTime endDate = TypeConverter.StrToDateTime(Score_Plugin_EndDate); if (endDate < DateTime.Now) { return(Json(new { isOK = false, error_code = "ERR_PluginIsEnd" }));// message = "对不起,抽奖已经结束!" }); } } } } IList <ScoreStoreItem> scoreStoreItems = _scoreStoreItemServiceService.GetList("from ScoreStoreItem where BaseId = '" + Id.ToString() + "'"); scoreStoreItems.OrderBy(storeItems => storeItems.PluginName); ScoreUser scoreUser = _scoreUserService.GetUnique("from ScoreUser where (MpUserId ='" + this.MpUserID.ToString() + "')"); if (scoreUser == null) { return(Json(new { isOK = false, isVertfy = true, error_code = "ERR_UserNotVerify" })); } if (scoreUser.CurrentScore < ViewData.GetInt("Score_Plugin_UsePoint")) { return(Json(new { isOK = false, error_code = "ERR_UserUseOutChance" })); } int prizeItemCount = scoreStoreItems.Count;// TypeConverter.StrToInt(ViewBag.Cst_Plugin_PrizeCount, 12); IList <PrizeGift> prizeGift = new List <PrizeGift>(prizeItemCount); IList <Double> prizeItems = new List <Double>(prizeItemCount); IList <string> prizeItemsName = new List <string>(prizeItemCount); IList <int> prizeAngle = new List <int>(prizeItemCount); prizeItemsName.Add("一"); prizeItemsName.Add("二"); prizeItemsName.Add("三"); prizeItemsName.Add("四"); prizeItemsName.Add("五"); prizeItemsName.Add("六"); prizeItemsName.Add("七"); prizeItemsName.Add("八"); prizeItemsName.Add("九"); prizeItemsName.Add("十"); prizeItemsName.Add("十一"); prizeItemsName.Add("十二"); for (int i = 0; i < prizeItemCount; i++) { ScoreStoreItem storeItem = scoreStoreItems[i]; PrizeGift gift = new PrizeGift(); gift.ID = i; gift.Name = storeItem.PluginName; gift.Alias_Name = storeItem.AliasName; gift.Odds = Convert.ToDouble(storeItem.PrizePercent) / 100; gift.Pic = storeItem.ItemPic; gift.Quantity = storeItem.TotalCount; gift.Leavings_Quantity = storeItem.LeftCount; gift.Angle = Convert.ToInt32(storeItem.PrizeAngle); prizeAngle.Add(gift.Angle); gift.Prize_Name = prizeItemsName[i] + "等奖"; if (!string.IsNullOrEmpty(gift.Alias_Name)) { gift.Prize_Name = gift.Alias_Name; } gift.Has_Gift = 1;// ViewData.GetInt("Cst_Plugin_Items_Has_Gift" + i.ToString()); //gift.Users = ViewData.GetString("Cst_Plugin_Items_SiteUsers" + i.ToString()); //gift.UsersName = ViewData.GetString("Cst_Plugin_Items_SiteUsersName" + i.ToString()); prizeItems.Add(gift.Odds); prizeGift.Add(gift); } prizeItems.OrderBy(d => d); //verifyCodeDetail.LeaveCount = verifyCodeDetail.LeaveCount - 1; //verifyCodeDetail.UseDate = DateTime.Now; //_pluginSceneVerifyCodeDetailService.Update(verifyCodeDetail); int count = _scorePluginResultService.GetCount("from ScorePluginResult where pluginId='" + Id.ToString() + "' and MpUserId='" + this.MpUserID.ToString() + "'"); int tryCount = _scoreConsumeInfoService.GetCount(" from ScoreConsumeInfo where ConsumeType = " + (int)ScoreConsume.Plugins + ""); if (count == 0 && tryCount > Convert.ToInt32(Score_Plugin_FailsTimes)) { PrizeGift _lastGift = prizeGift.Last(); double finalOdds = _lastGift.Odds * (1 + Convert.ToInt32(Score_Plugin_FailsAddOdds)); _lastGift.Odds = finalOdds; prizeItems.RemoveAt(prizeItems.Count - 1); prizeItems.Add(finalOdds); } int result = -1; scoreUser.CurrentScore = scoreUser.CurrentScore - Convert.ToInt32(Score_Plugin_UsePoint);// ViewData.GetInt("Score_Plugin_UsePoint"); scoreUser.LastUpdateDateTime = DateTime.Now; _scoreUserService.Update(scoreUser); #region 更新积分消耗纪录 ScoreConsumeInfo scoreConSumeInfo = new ScoreConsumeInfo(); scoreConSumeInfo.ConsumeDateTime = scoreConSumeInfo.CreateDate = DateTime.Now; scoreConSumeInfo.MpUserId = this.MpUserID; scoreConSumeInfo.ConsumeType = (int)(ScoreConsume.Plugins); scoreConSumeInfo.ConsumePoints = -Convert.ToInt32(Score_Plugin_UsePoint); scoreConSumeInfo.Summary = "抽奖消耗了" + Convert.ToInt32(Score_Plugin_UsePoint) + "积分"; _scoreConsumeInfoService.Insert(scoreConSumeInfo); #endregion result = LotteryUtils.Lottery(prizeItems, prizeGift, prizeItemCount, this.MpUserID, Id); if (result == -1) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));//Json(new PrizeGift() { ID = -1, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 240, Prize_Name = "继续加油" }); } else if (result == -2) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));// Json(new PrizeGift() { ID = -2, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 180, Prize_Name = "继续加油" }); } else if (result == -3) { return(Json(new { isOK = true, error_code = "ERR_RunOutOfGift" }));// Json(new PrizeGift() { ID = -2, Name = "未中奖", Odds = 0.00d, Pic = "", Quantity = 100000, Angle = 180, Prize_Name = "继续加油" }); } else { PrizeGift hasPrizeGift = prizeGift[result]; ScoreStoreItem scoreStoreItem = scoreStoreItems[result]; //ScoreStoreItem scoreStoreItem = _scoreStoreItemServiceService.GetUnique("from ScoreStoreItem where (Id ='" + this.MpUserID.ToString() + "')"); //score hasPrizeGift.Alias_Name = hasPrizeGift.Alias_Name ?? ""; if (scoreStoreItem.LeftCount > 0) { //中奖业务处理 ScorePluginResult pluginSceneResult = new ScorePluginResult(); pluginSceneResult.Address = ""; pluginSceneResult.CreateDate = DateTime.Now; pluginSceneResult.Type = 1; pluginSceneResult.IsUse = 0; pluginSceneResult.MobilePhone = ""; pluginSceneResult.Name = ""; pluginSceneResult.Phone = ""; pluginSceneResult.PluginId = Id; pluginSceneResult.MpUserId = this.MpUserID; pluginSceneResult.SN = ""; pluginSceneResult.UserName = (string.IsNullOrEmpty(this.Name) ? this.NickName : this.Name); if (this.MpUserArr != null) { pluginSceneResult.Summary = "恭喜用户[" + (string.IsNullOrEmpty(this.Name) ? this.NickName : this.Name) + "]获得" + hasPrizeGift.Prize_Name + "[" + hasPrizeGift.Name + "]"; } else { pluginSceneResult.Summary = "恭喜匿名用户获得" + hasPrizeGift.Prize_Name + "[" + hasPrizeGift.Name + "]"; } //pluginSceneResult.Value = "<?xml version=\"1.0\" encoding=\"utf-8\"?><PluginSubmit><Cst_Plugin_ItemIndex>" + result.ToString() + "</Cst_Plugin_ItemIndex><Cst_Plugin_PrizeLevel>" + hasPrizeGift.Prize_Name + "</Cst_Plugin_PrizeLevel><Cst_Plugin_PrizeName>" + hasPrizeGift.Name + "</Cst_Plugin_PrizeName></PluginSubmit>"; pluginSceneResult.Value = hasPrizeGift.Prize_Name + "++" + hasPrizeGift.Name; #region 更新商城数量 scoreStoreItem.LeftCount -= 1; _scoreStoreItemServiceService.Update(scoreStoreItem); #endregion #region 更新中奖纪录 _scorePluginResultService.Insert(pluginSceneResult); #endregion #region 更新虚拟积分纪录 if (scoreStoreItem.VirtualGift > 0) { scoreUser.CurrentScore += scoreStoreItem.VirtualGift; _scoreUserService.Update(scoreUser); ScoreConsumeInfo scoreConSumeInfo2 = new ScoreConsumeInfo(); scoreConSumeInfo2.ConsumeDateTime = scoreConSumeInfo.CreateDate = DateTime.Now; scoreConSumeInfo2.MpUserId = this.MpUserID; scoreConSumeInfo2.ConsumeType = (int)(ScoreConsume.Plugins); scoreConSumeInfo2.ConsumePoints = scoreStoreItem.VirtualGift; scoreConSumeInfo2.Summary = "抽奖中了" + scoreStoreItem.VirtualGift + "积分"; _scoreConsumeInfoService.Insert(scoreConSumeInfo2); } #endregion hasPrizeGift.ResultID = pluginSceneResult.Id; } return(Content(JsonConvert.SerializeObject(hasPrizeGift), "text/javascript")); } } catch (Exception ex) { throw new OceanException(ex.Message, ex); } }