public JsonResult RepliesSubmit(int tid, string content, int fid) { ResultModel <string> model = new ResultModel <string>(); _service.Command <MainOutsourcing>((db, o) => { model.IsSuccess = false; if (base.IsLogin.IsFalse()) { model.ResultInfo = "-1"; } else { db.BeginTran(); try { var prePost = db.Queryable <BBS_Posts>().OrderBy(it => it.Postdatetime, OrderByType.Desc).FirstOrDefault(it => it.Posterid == _userInfo.Id); if (prePost != null && (DateTime.Now - prePost.Postdatetime.TryToDate()).Seconds <= 6) { model.ResultInfo = "你回复的太快了,请在等" + (5 - (DateTime.Now - prePost.Postdatetime.TryToDate()).Seconds) + "秒!"; } else { BBS_Posts p = new BBS_Posts(); p.Title = ""; p.Parentid = tid; p.Message = content; p.Fid = fid; p.Tid = tid; p.Posterid = base._userInfo.Id; p.Poster = base._userInfo.NickName; p.Lastedit = base._userInfo.NickName; p.Postdatetime = DateTime.Now; p.Ip = RequestInfo.UserAddress; db.Insert(p); db.Update <BBS_Topics>(" Replies=isnull([Replies],0)+1,Lastpost=@lp,Lastposter=@Lastposter,Lastposterid=@Lastposterid", it => it.Tid == tid, new { lp = DateTime.Now, Lastposter = _userInfo.NickName, Lastposterid = _userInfo.Id });//回复数加1 model.IsSuccess = true; base.RemoveForumsStatisticsCache(); db.CommitTran(); //发送邮箱提醒 o.SendMail(base._userInfo, tid, p, db); //发送站内信 o.SendPMS(base._userInfo, tid, p, db); } } catch (Exception ex) { model.ResultInfo = "回复失败!"; PubMethod.WirteExp(ex); db.RollbackTran(); } } }); return(Json(model)); }
/// <summary> /// 发送邮件通知 /// </summary> /// <param name="isLogin"></param> /// <param name="_userInfo"></param> /// <param name="tid"></param> /// <param name="p"></param> /// <param name="db"></param> internal void SendMail(UserInfo currentUser, int tid, BBS_Posts p, SqlSugarClient db) { //未配置邮箱不发送 if (PubGet.GetEmailUserName.IsNullOrEmpty()) { return; } var topic = db.Queryable <BBS_Topics>().Single(it => it.Tid == tid); var isOneUser = currentUser.Id == topic.Posterid; var html = FileSugar.FileToString(FileSugar.GetMapPath("~/Template/mail/Replies.html")).Replace('\r', ' ').Replace('\n', ' '); var oldHtml = html; //发贴和回贴不是同一个人 if (isOneUser.IsFalse()) { var toUser = db.Queryable <UserInfo>().Single(it => it.Id == topic.Posterid); if (toUser.Email.IsEamil()) { string toUserName = toUser.NickName; string fromUserName = currentUser.NickName; string toMail = toUser.Email; MailSmtp ms = new MailSmtp(PubGet.GetEmailSmtp, PubGet.GetEmailUserName, PubGet.GetEmailPassword); string url = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid); html = html.ToFormat(toUserName, fromUserName, topic.Title, DateTime.Now, url); var title = PubMethod.RemoveAllSpace(fromUserName + "回复了:" + StringSugar.ToCutString(topic.Title, 10, "...")); ms.Send(PubGet.GetEmailUserName, PubConst.SiteMailUserName, toMail, title, html); System.Threading.Thread.Sleep(100); } } html = oldHtml; //处理@ if (p.Message.IsValuable() && p.Message.Contains("@")) { var adUserIds = db.Queryable <BBS_Posts>().Where(it => it.Tid == tid && it.Parentid > 0).Select(it => it.Posterid).ToList(); var adUsers = db.Queryable <UserInfo>().In(adUserIds).ToList(); var matchUsers = Regex.Matches(p.Message, @"\<span style\=""color:#4f99cf""\>@(.+?)\<\/span\>"); if (matchUsers != null && matchUsers.Count > 0) { var userNames = matchUsers.Cast <Match>().Select(it => it.Groups[1].Value).ToList(); adUsers = adUsers.Where(it => userNames.Contains(it.NickName)).ToList(); foreach (var item in adUsers) { if (item.Email.IsValuable() && item.Id != currentUser.Id) { string toUserName = item.NickName; string fromUserName = currentUser.NickName; string toMail = item.Email; MailSmtp ms = new MailSmtp(PubGet.GetEmailSmtp, PubGet.GetEmailUserName, PubGet.GetEmailPassword); string url = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid); html = html.ToFormat(toUserName, fromUserName, p.Message, DateTime.Now, url); var title = PubMethod.RemoveAllSpace(fromUserName + "在【" + topic.Title.TryToString().Trim() + "】@了你"); ms.Send(PubGet.GetEmailUserName, PubConst.SiteMailUserName, toMail, title, html); System.Threading.Thread.Sleep(100); } } } } }
public JsonResult AskSubmit(short fid, string title, string content, string vercode, int rate = 0, int id = 0) { ResultModel <string> model = new ResultModel <string>(); _service.Command <MainOutsourcing>((db, o) => { Check.Exception(fid == 0 || title.IsNullOrEmpty() || content.IsNullOrEmpty() || vercode.IsNullOrEmpty(), "参数不合法!"); Check.Exception(title.Length < 5 && content.Length < 20 || content.Length > 1000000, "参数不合法!"); Check.Exception(base.GetForumsList != null && base.GetForumsList.Any(it => it.Fid == fid).IsFalse(), "参数不合法!"); var sm = SessionManager <string> .GetInstance(); var severCode = sm[PubConst.SessionVerifyCode]; model.IsSuccess = false; if (vercode != severCode) { model.ResultInfo = "验证码错误!"; } else if (IsLogin.IsFalse()) { model.ResultInfo = "对不起您还没有登录!"; } else { try { db.BeginTran(); var isAdd = id == 0; if (isAdd) { //插贴子标题 BBS_Topics t = o.GetTopics(fid, title, rate, _userInfo); var tid = db.Insert(t).ObjToInt(); t.Tid = tid; //插贴子主体 BBS_Posts p = o.GetPosts(fid, content, _userInfo, t); db.Insert(p); } else { var topics = db.Queryable <BBS_Topics>().InSingle(id); Check.Exception(topics.Posterid != _userInfo.Id && _userInfo.RoleId == PubEnum.RoleType.User.TryToInt(), "您没有权限修改!"); db.Update <BBS_Topics>(new { Title = title, Rate = rate, Fid = fid }, it => it.Tid == id); db.Update <BBS_Posts>(new { Title = title, Rate = rate, Fid = fid, Message = content }, it => it.Tid == id && it.Parentid == 0); } db.CommitTran(); model.IsSuccess = true; base.RemoveForumsStatisticsCache();//清除统计缓存 } catch (Exception ex) { model.ResultInfo = "发布失败!"; db.RollbackTran(); PubMethod.WirteExp(ex); } } }); return(Json(model)); }
/// <summary> /// 站内信 /// </summary> /// <param name="currentUser"></param> /// <param name="tid"></param> /// <param name="p"></param> /// <param name="db"></param> internal void SendPMS(UserInfo currentUser, int tid, BBS_Posts p, SqlSugarClient db) { var topic = db.Queryable <BBS_Topics>().Single(it => it.Tid == tid); var isOneUser = currentUser.Id == topic.Posterid; var html = FileSugar.FileToString(FileSugar.GetMapPath("~/Template/mail/PMS.html")).Replace('\r', ' ').Replace('\n', ' '); var oldHtml = html; //发贴和回贴不是同一个人 if (isOneUser.IsFalse()) { var toUser = db.Queryable <UserInfo>().Single(it => it.Id == topic.Posterid); string toUserName = toUser.NickName; string fromUserName = currentUser.NickName; string url = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid); html = html.ToFormat(toUserName, fromUserName, topic.Title, url); var title = PubMethod.RemoveAllSpace(fromUserName + "回复了:" + StringSugar.ToCutString(topic.Title, 10, "...")); db.Insert <BBS_PMS>(new BBS_PMS() { Message = html, Subject = title, Msgfrom = fromUserName, Msgfromid = currentUser.Id, Msgto = toUserName, Msgtoid = toUser.Id, New = 1, Postdatetime = DateTime.Now }); } html = oldHtml; //处理@ if (p.Message.IsValuable() && p.Message.Contains("@")) { var adUserIds = db.Queryable <BBS_Posts>().Where(it => it.Tid == tid && it.Parentid > 0).Select(it => it.Posterid).ToList(); var adUsers = db.Queryable <UserInfo>().In(adUserIds).ToList(); var matchUsers = Regex.Matches(p.Message, @"\<span style\=""color:#4f99cf""\>@(.+?)\<\/span\>"); if (matchUsers != null && matchUsers.Count > 0) { var userNames = matchUsers.Cast <Match>().Select(it => it.Groups[1].Value).ToList(); adUsers = adUsers.Where(it => userNames.Contains(it.NickName)).ToList(); foreach (var item in adUsers) { if (item.Email.IsValuable() && item.Id != currentUser.Id) { string toUserName = item.NickName; string fromUserName = currentUser.NickName; string url = RequestInfo.HttpDomain + "/Ask/{0}/{1}#btnSubmit".ToFormat(topic.Fid, topic.Tid); html = html.ToFormat(toUserName, fromUserName, p.Message, url); var title = PubMethod.RemoveAllSpace(fromUserName + "在【" + topic.Title.TryToString().Trim() + "】@了你"); db.Insert <BBS_PMS>(new BBS_PMS() { Message = html, Subject = title, Msgfrom = fromUserName, Msgfromid = currentUser.Id, Msgto = toUserName, Msgtoid = item.Id, New = 1, Postdatetime = DateTime.Now }); } } } } }