public ActionResult SendMassage() { if (Common.SecureHelper.MD5(Request["BottleID"].ToString() + Common.SecureHelper.JeasuAutoKey) == Request["massageKey"].ToString()) { Bottle bottle = ServiceHelper.GetBottleService.GetEntity(Convert.ToInt32(Request["BottleID"]), false); //如果瓶子已经被回复过,并且不是本人创建的瓶子,也不是本人回复过的瓶子,则提示用户 if (bottle.FirstReplyUserID != null && (bottle.CreateUserID != CurrentInfo.CurrentUser.ID && bottle.FirstReplyUserID != CurrentInfo.CurrentUser.ID)) { ViewBag.HasReply = "1"; } //设置瓶子被查看的时间 if (bottle.CreateUserID == CurrentInfo.CurrentUser.ID) { //本人查看的时间 bottle.CreateViewTime = DateTime.Now; } else { //捡到瓶子的人查看的时间 bottle.ReplyViewTime = DateTime.Now; } bottle.Update(); } return(View()); }
public JsonResult ReplyBottle(Conversation conversation) { lock (lockReply) { //验证密匙 if (Common.SecureHelper.MD5(conversation.BottleID + Common.SecureHelper.JeasuAutoKey) == conversation.MassageKey) { //Bottle bottle = new Bottle(); if (string.IsNullOrWhiteSpace(conversation.Massage)) { return(Json(new Result(false, "多少说点东西!"), JsonRequestBehavior.AllowGet)); } //Bottle bottle = new Bottle(); if (conversation.Massage.Length <= 3) { return(Json(new Result(false, "内容太少咯,请多说点!"), JsonRequestBehavior.AllowGet)); } if (conversation.Massage.Length > 300) { return(Json(new Result(false, "内容太多了!"), JsonRequestBehavior.AllowGet)); } //如果FirstReplyUserID不为null 则说明有人回复过了 if (ServiceHelper.GetBottleService.Exists(t => t.ID == conversation.BottleID && t.FirstReplyUserID != null && t.CreateUserID != CurrentInfo.CurrentUser.ID && t.FirstReplyUserID != CurrentInfo.CurrentUser.ID)) { return(Json(new Result(false, "来迟了,瓶子已经被回复,请换个瓶子试试"), JsonRequestBehavior.AllowGet)); } Bottle bottle = ServiceHelper.GetBottleService.GetEntity((int)conversation.BottleID, false); //如果是第一个回复,则也需要把瓶子插入到回话中 if (!ServiceHelper.GetConversationService.Exists(t => t.BottleID == conversation.BottleID)) { //第一个回复的人不可以是自己 if (bottle.CreateUserID == CurrentInfo.CurrentUser.ID) { return(Json(new Result(false, "还是等有缘人回复把"), JsonRequestBehavior.AllowGet)); } Conversation cv = new Conversation(); cv.Massage = bottle.Massage; cv.BottleID = conversation.BottleID; cv.CreateUserName = bottle.CreateUserName; cv.CreateUserID = bottle.CreateUserID; cv.CreateTime = bottle.CreateTime; cv.Sexual = bottle.Sexual; cv.Add(); //更新瓶子的回复人 bottle.FishingCount = bottle.FishingCount + 1;//被打捞了一次 bottle.FirstReplyUserID = CurrentInfo.CurrentUser.ID; //如果是管理员,则随机名字 if (CurrentInfo.CurrentUser.ID == 6) { string netUser = "******"; Random rd = new Random(); if (bottle.Sexual == true) { netUser = NetUserNames.NetUserGirl[rd.Next(0, NetUserNames.NetUserGirl.Count)]; } else { netUser = NetUserNames.NetUserBoy[rd.Next(0, NetUserNames.NetUserBoy.Count)]; } bottle.FirstReplyUserName = netUser; } else { bottle.FirstReplyUserName = CurrentInfo.CurrentUser.RealName; } //扣除金币 CurrentInfo.CurrentUser.GoldCoin = CurrentInfo.CurrentUser.GoldCoin == null ? 0 : CurrentInfo.CurrentUser.GoldCoin; CurrentInfo.CurrentUser.Fishing = CurrentInfo.CurrentUser.Fishing - 1; } //bottle.Update(); conversation.CreateUserID = CurrentInfo.CurrentUser.ID; //如果是管理员,则随机名字,取上创建人的名字 if (CurrentInfo.CurrentUser.ID == 6) { //说明这个瓶子是管理员自己发的 if (bottle.CreateUserID == 6) { conversation.CreateUserName = bottle.CreateUserName; conversation.Sexual = bottle.Sexual; } else//如果这个瓶子是别人发的 { conversation.CreateUserName = bottle.FirstReplyUserName; conversation.Sexual = !((bool)bottle.Sexual); } } else { conversation.CreateUserName = CurrentInfo.CurrentUser.RealName; conversation.Sexual = CurrentInfo.CurrentUser.Sexual; } conversation.CreateTime = DateTime.Now; conversation.MassageKey = string.Empty; //设置瓶子的最后回复内容 bottle.LastReplyUserID = CurrentInfo.CurrentUser.ID; if (CurrentInfo.CurrentUser.ID == 6)//如果是管理员则设置最后回复名字是自动生成的 { bottle.LastReplyUserName = conversation.CreateUserName; } else { bottle.LastReplyUserName = CurrentInfo.CurrentUser.RealName; } bottle.LastReplyMassage = conversation.Massage; bottle.LastReplyTime = DateTime.Now; bottle.Update(); bool flage = conversation.Add() == null ? false : true; return(Json(new Result(flage, ResultType.Other), JsonRequestBehavior.AllowGet)); } else { return(Json(new Result(false, "发生错误,回复失败"), JsonRequestBehavior.AllowGet)); } } }