/// <summary> /// 详情 /// </summary> public ActionResult Info() { try { var number = ZNRequest.GetString("key"); if (string.IsNullOrWhiteSpace(number)) { return(Json(new { result = false, message = "参数异常" }, JsonRequestBehavior.AllowGet)); } Article model = db.Single <Article>(x => x.Number == number); if (model == null) { return(Json(new { result = false, message = "信息异常" }, JsonRequestBehavior.AllowGet)); } //待审核 if (model.Status == Enum_Status.Audit) { var newmodel = new Article(); newmodel.ID = model.ID; newmodel.Title = model.Title; newmodel.ArticlePower = model.ArticlePower; newmodel.Status = model.Status; return(Json(new { result = true, message = newmodel }, JsonRequestBehavior.AllowGet)); } //已删除 if (model.Status == Enum_Status.Delete || model.Status == Enum_Status.DeleteCompletely) { var newmodel = new Article(); newmodel.ID = model.ID; newmodel.Title = model.Title; newmodel.ArticlePower = model.ArticlePower; newmodel.Status = model.Status; return(Json(new { result = true, message = newmodel }, JsonRequestBehavior.AllowGet)); } ////私密 //if (model.ArticlePower == Enum_ArticlePower.Myself) //{ // var newmodel = new Article(); // newmodel.ID = model.ID; // newmodel.Title = model.Title; // newmodel.ArticlePower = model.ArticlePower; // newmodel.Status = model.Status; // return Json(new { result = true, message = newmodel }, JsonRequestBehavior.AllowGet); //} ////加密 //var password = ZNRequest.GetString("ArticlePassword"); //if (model.ArticlePower == Enum_ArticlePower.Password && model.ArticlePowerPwd != password) //{ // var newmodel = new Article(); // newmodel.ID = model.ID; // newmodel.Title = model.Title; // newmodel.ArticlePower = model.ArticlePower; // newmodel.Status = model.Status; // return Json(new { result = true, message = newmodel }, JsonRequestBehavior.AllowGet); //} //当前用户编号 string xwp = ZNRequest.GetString("xwp"); var password = ZNRequest.GetString("ArticlePassword"); //微信分享设置 string url = ZNRequest.GetString("url"); url = System.Text.RegularExpressions.Regex.Replace(url, @":\d{2,5}/", "/");//去端口号 Share share = new Share(); share.AppID = WeixinHelper.AppID; share.NonceStr = WeixinHelper.NonceStr; share.TimeStr = UnixTimeHelper.FromDateTime(DateTime.Now).ToString(); share.Signature = WeixinHelper.GetSignature(url, share.TimeStr); model.Share = share; if (model.CreateUserNumber != xwp) { //私密 if (model.ArticlePower == Enum_ArticlePower.Myself) { var newmodel = new Article(); newmodel.ID = model.ID; newmodel.Title = model.Title; newmodel.ArticlePower = Enum_ArticlePower.Myself; newmodel.Share = share; return(Json(new { result = true, message = newmodel }, JsonRequestBehavior.AllowGet)); } //加密 if (model.ArticlePower == Enum_ArticlePower.Password && model.ArticlePowerPwd != password) { var newmodel = new Article(); newmodel.ID = model.ID; newmodel.Title = model.Title; newmodel.ArticlePower = Enum_ArticlePower.Password; newmodel.Share = share; return(Json(new { result = true, message = newmodel }, JsonRequestBehavior.AllowGet)); } } else { model.ArticlePower = Enum_ArticlePower.Public; } //浏览数 new SubSonic.Query.Update <Article>(provider).Set("Views").EqualTo(model.Views + 1).Where <Article>(x => x.ID == model.ID).Execute(); //创建人 User createUser = db.Single <User>(x => x.Number == model.CreateUserNumber); if (createUser != null) { model.NickName = createUser == null ? "" : createUser.NickName; model.Avatar = createUser == null ? "" : createUser.Avatar; model.AutoMusic = createUser.AutoMusic; model.ShareNick = createUser.ShareNick; } //文章部分 model.ArticlePart = new SubSonic.Query.Select(provider).From <ArticlePart>().Where <ArticlePart>(x => x.ArticleNumber == model.Number).OrderAsc("SortID").ExecuteTypedList <ArticlePart>(); model.CreateDateText = model.CreateDate.ToString("yyyy-MM-dd"); //模板配置 model.BackgroundJson = db.Single <Background>(x => x.ArticleNumber == model.Number && x.IsUsed == Enum_Used.Approved); if (model.Template >= 0) { model.TemplateJson = AppHelper.GetArticleTemplate().FirstOrDefault(x => x.ID == model.Template); } if (model.ColorTemplate > 0) { model.ColorTemplateJson = AppHelper.GetColorTemplate().FirstOrDefault(x => x.ID == model.ColorTemplate); } //漂浮装扮 var custom = db.Single <ArticleCustom>(x => x.ArticleNumber == model.Number); if (custom != null) { model.Showy = custom.ShowyUrl; model.MusicID = custom.MusicID; model.MusicName = custom.MusicName; model.MusicUrl = custom.MusicUrl; model.Transparency = custom.Transparency; model.MarginTop = custom.MarginTop; } return(Json(new { result = true, message = model }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { LogHelper.ErrorLoger.Error("HomeController_Info:" + ex.Message); } return(Json(new { result = false, message = "失败" }, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit_1_3() { ApiResult result = new ApiResult(); try { User user = GetUserInfo(); if (user == null) { result.message = EnumBase.GetDescription(typeof(Enum_ErrorCode), Enum_ErrorCode.UnLogin); result.code = Enum_ErrorCode.UnLogin; return(Json(result)); } var ArticleNumber = Tools.SafeString(ZNRequest.GetString("ArticleNumber")); if (string.IsNullOrWhiteSpace(ArticleNumber)) { result.message = "文章信息异常"; return(Json(result)); } var summary = SqlFilter(UrlDecode(ZNRequest.GetString("Summary")), false, false); if (string.IsNullOrWhiteSpace(summary)) { result.message = "请填写评论内容"; return(Json(result)); } summary = CutString(summary, 2000); var dirtyword = AppHelper.HasDirtyWord(summary); if (!string.IsNullOrWhiteSpace(dirtyword)) { result.message = "您的输入内容含有敏感内容[" + dirtyword + "],请检查后重试哦"; return(Json(result)); } Article article = new SubSonic.Query.Select(provider, "ID", "Number", "CreateUserNumber").From <Article>().Where <Article>(x => x.Number == ArticleNumber).ExecuteSingle <Article>(); if (article == null) { result.message = "文章信息异常"; return(Json(result)); } //判断是否拉黑 var black = db.Exists <Black>(x => x.CreateUserNumber == article.CreateUserNumber && x.ToUserNumber == user.Number); if (black) { result.code = Enum_ErrorCode.NoPower; result.message = "没有权限"; return(Json(result)); } Comment model = new Comment(); model.ArticleNumber = article.Number; model.ArticleUserNumber = article.CreateUserNumber; model.Summary = summary; model.Number = BuildNumber(); model.CreateDate = DateTime.Now; model.CreateUserNumber = user.Number; model.CreateIP = Tools.GetClientIP; model.ParentCommentNumber = ZNRequest.GetString("ParentCommentNumber"); model.ParentUserNumber = ZNRequest.GetString("ParentUserNumber"); model.Province = ZNRequest.GetString("Province"); model.City = ZNRequest.GetString("City"); model.District = ZNRequest.GetString("District"); model.Street = ZNRequest.GetString("Street"); model.DetailName = ZNRequest.GetString("DetailName"); model.CityCode = ZNRequest.GetString("CityCode"); model.Latitude = Tools.SafeDouble(ZNRequest.GetString("Latitude")); model.Longitude = Tools.SafeDouble(ZNRequest.GetString("Longitude")); model.ShowPosition = ZNRequest.GetInt("ShowPosition"); model.ID = Tools.SafeInt(db.Add <Comment>(model)); if (model.ID > 0) { result.result = true; result.message = model.ID; //推送 new AppHelper().Push(article.CreateUserNumber, article.ID, article.Number, user.NickName, Enum_PushType.Comment, false); } } catch (Exception ex) { LogHelper.ErrorLoger.Error("Comment_Edit_1_3:" + ex.Message); result.message = ex.Message; } return(Json(result)); }
public ActionResult Edit() { var parts = ""; try { User user = GetUserInfo(); if (user == null) { return(Json(new { result = false, message = "用户信息验证失败", code = Enum_ErrorCode.UnLogin }, JsonRequestBehavior.AllowGet)); } Article model = new Article(); model.ID = ZNRequest.GetInt("ArticleID"); if (model.ID > 0) { model = db.Single <Article>(x => x.ID == model.ID); if (model == null) { model = new Article(); } else { //判断权限 if (user.UserRole == Enum_UserRole.Common) { if (user.Number != model.CreateUserNumber) { return(Json(new { result = false, message = "没有权限", code = Enum_ErrorCode.NoPower }, JsonRequestBehavior.AllowGet)); } } } } model.Title = SqlFilter(ZNRequest.GetString("Title")); model.Title = CutString(model.Title, 100); var dirtyword = AppHelper.HasDirtyWord(model.Title); if (!string.IsNullOrWhiteSpace(dirtyword)) { return(Json(new { result = false, message = "您输入的标题含有敏感内容[" + dirtyword + "],请检查后重试哦" }, JsonRequestBehavior.AllowGet)); } if (string.IsNullOrWhiteSpace(model.Title)) { model.Title = "我的小微篇"; } model.Province = ZNRequest.GetString("Province"); model.City = ZNRequest.GetString("City"); model.District = ZNRequest.GetString("District"); model.Street = ZNRequest.GetString("Street"); model.DetailName = ZNRequest.GetString("DetailName"); model.CityCode = ZNRequest.GetString("CityCode"); model.Latitude = Tools.SafeDouble(ZNRequest.GetString("Latitude")); model.Longitude = Tools.SafeDouble(ZNRequest.GetString("Longitude")); model.Template = ZNRequest.GetInt("Template"); model.ColorTemplate = ZNRequest.GetInt("ColorTemplate"); model.UpdateUserNumber = user.Number; model.UpdateDate = DateTime.Now; model.UpdateIP = Tools.GetClientIP; model.Status = Enum_Status.Approved; model.Submission = Enum_Submission.TemporaryApproved;//默认临时投稿审核 var ArticlePower = ZNRequest.GetInt("ArticlePower", -1); if (ArticlePower > -1) { model.ArticlePower = ArticlePower; } var ArticlePowerPwd = ZNRequest.GetString("ArticlePowerPwd"); if (!string.IsNullOrWhiteSpace(ArticlePowerPwd)) { model.ArticlePowerPwd = ArticlePowerPwd; } var TypeID = ZNRequest.GetInt("ArticleType", 0); if (TypeID > 0) { var articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == TypeID); if (articleType != null) { model.TypeID = TypeID; model.TypeIDList = articleType.ParentIDList; } } var result = false; if (model.ID == 0) { var cover = ZNRequest.GetString("Cover"); if (string.IsNullOrWhiteSpace(cover)) { return(Json(new { result = false, message = "文章信息异常" }, JsonRequestBehavior.AllowGet)); } var covers = cover.Split(','); model.Cover = covers[0]; model.Recommend = Enum_ArticleRecommend.None; model.CreateUserNumber = user.Number; model.CreateDate = DateTime.Now; model.CreateIP = Tools.GetClientIP; model.Number = BuildNumber(); model.ID = Tools.SafeInt(db.Add <Article>(model)); result = model.ID > 0; //初始化文章段落 if (result) { for (var i = 0; i < covers.Length; i++) { ArticlePart part = new ArticlePart(); part.ArticleNumber = model.Number; part.Types = Enum_ArticlePart.Pic; part.Introduction = covers[i]; part.IntroExpand = string.Empty; part.SortID = Tools.SafeInt(i); part.Status = Enum_Status.Audit; part.CreateDate = DateTime.Now; part.CreateUserNumber = user.Number; part.CreateIP = Tools.GetClientIP; part.ID = Tools.SafeInt(db.Add <ArticlePart>(part)); result = part.ID > 0; } } if (result) { ArticleType articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == model.TypeID); model.TypeName = articleType == null ? string.Empty : articleType.Name; return(Json(new { result = true, message = new { ID = model.ID, Number = model.Number, ArticlePower = model.ArticlePower, ArticlePowerPwd = model.ArticlePowerPwd, ArticleType = model.TypeID, ArticleTypeName = model.TypeName } }, JsonRequestBehavior.AllowGet)); } } else { if (model.ArticlePower == Enum_ArticlePower.Public) { model.ArticlePower = Enum_ArticlePower.Myself; } if (string.IsNullOrWhiteSpace(model.Title)) { model.Title = "我的小微篇"; } result = db.Update <Article>(model) > 0; //取消自定义模板启用 if (model.Template != 1) { var list = db.Find <Background>(x => x.ArticleNumber == model.Number && x.IsUsed == Enum_Used.Approved).ToList(); if (list.Count > 0) { list.ForEach(x => { x.IsUsed = Enum_Used.Audit; }); db.UpdateMany <Background>(list); } } ArticleType articleType = AppHelper.GetArticleType().FirstOrDefault <ArticleType>(x => x.ID == model.TypeID); model.TypeName = articleType == null ? string.Empty : articleType.Name; parts = SqlFilter(ZNRequest.GetString("Part").Trim(), false, false); if (!string.IsNullOrWhiteSpace(parts)) { List <PartJson> list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PartJson> >(parts); list.ForEach(x => { if (x.Status == 0) { //排序 var partid = Tools.SafeInt(x.ID); var part = db.Single <ArticlePart>(y => y.ID == partid); if (part != null) { part.SortID = Tools.SafeInt(x.SortID); db.Update <ArticlePart>(part); } } else if (x.Status == 1) { //新增 ArticlePart part = new ArticlePart(); part.ArticleNumber = model.Number; part.Types = x.PartType; part.Introduction = x.Introduction; part.IntroExpand = x.IntroExpand; part.SortID = Tools.SafeInt(x.SortID); part.Status = Enum_Status.Audit; part.CreateDate = DateTime.Now; part.CreateUserNumber = user.Number; part.CreateIP = Tools.GetClientIP; part.ID = Tools.SafeInt(db.Add <ArticlePart>(part)); } else if (x.Status == 2) { //编辑 var partid = Tools.SafeInt(x.ID); var part = db.Single <ArticlePart>(y => y.ID == partid); if (part != null) { part.Introduction = x.Introduction; part.IntroExpand = x.IntroExpand; part.SortID = Tools.SafeInt(x.SortID); db.Update <ArticlePart>(part); } } else if (x.Status == 3) { //是否临时删除删除 if (x.Temporary == 0) { db.Delete <ArticlePart>(x.ID); } } }); } } if (result) { //更新自定义漂浮 var ShowyUrl = ZNRequest.GetString("ShowyUrl"); var MusicID = ZNRequest.GetInt("MusicID"); var MusicName = ZNRequest.GetString("MusicName"); var MusicUrl = ZNRequest.GetString("MusicUrl"); ArticleCustom custom = db.Single <ArticleCustom>(x => x.ArticleNumber == model.Number); if (custom == null) { custom = new ArticleCustom(); custom.ArticleNumber = model.Number; } custom.ShowyUrl = ShowyUrl; custom.MusicID = MusicID; custom.MusicName = MusicName; custom.MusicUrl = MusicUrl; if (custom.ID == 0) { db.Add <ArticleCustom>(custom); } else { db.Update <ArticleCustom>(custom); } return(Json(new { result = true, message = new { ID = model.ID, Number = model.Number, ArticlePower = model.ArticlePower, ArticlePowerPwd = model.ArticlePowerPwd, TypeID = model.TypeID, TypeName = model.TypeName } }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { LogHelper.ErrorLoger.Error("ArticleController_Edit:" + ex.Message + "," + parts); } return(Json(new { result = false, message = "失败" }, JsonRequestBehavior.AllowGet)); }