public static Dictionary <string, object> AddBaseInfo <T>(Dictionary <string, object> dic, string token, bool isAdd, ref OpertionUser opt)
        {
            var user = UtilConst.GetLoginOpt(token);

            var propertys = typeof(T).GetProperties();

            if (propertys.Count(x => x.Name == "CreateTime") > 0 && isAdd)
            {
                dic.Add("CreateTime", DateTime.Now);;
            }
            if (propertys.Count(x => x.Name == "CreateUserId") > 0 && isAdd)
            {
                dic.Add("CreateUserId", user.UserId);
            }
            if (propertys.Count(x => x.Name == "CreateUserName") > 0 && isAdd)
            {
                dic.Add("CreateUserName", user.UserName);
            }
            if (propertys.Count(x => x.Name == "UpdateUserId") > 0)
            {
                dic.Add("UpdateUserId", user.UserId);
            }
            if (propertys.Count(x => x.Name == "UpdateUserName") > 0)
            {
                dic.Add("UpdateUserName", user.UserName);
            }
            if (propertys.Count(x => x.Name == "UpdateTime") > 0)
            {
                dic.Add("UpdateTime", DateTime.Now);
            }
            opt.UserId       = user.UserId;
            opt.UserName     = user.UserName;
            opt.UserClientIp = GetIP();

            return(dic);
        }
Exemple #2
0
        public JsonResponse AddPraise([FromBody] JsonRequest model)
        {
            var res = new Result {
                IsSucceed = false
            };

            try
            {
                CommentView item = model?.Data.ToString()?.DeserialObject <CommentView>();
                if (item == null || string.IsNullOrEmpty(item.BlogNum))
                {
                    return(new JsonResponse {
                        Code = 1, Msg = "参数不合法"
                    });
                }
                var mem = UtilConst.GetLoginOpt(model.Token);

                var dic = new Dictionary <string, object>
                {
                    { nameof(ArticlePraise.MemberId), mem.UserId },
                    { nameof(ArticlePraise.BlogNum), item.BlogNum },
                    { nameof(ArticlePraise.IsDeleted), 0 }
                };
                var dodic = new Dictionary <string, object>
                {
                    { nameof(ArticlePraise.MemberId), mem.UserId },
                    { nameof(ArticlePraise.BlogNum), item.BlogNum },
                };
                var  ap    = BlogHelper.GetModelByWhere_ArticlePraise(dodic);
                var  opt   = new OpertionUser();
                bool isadd = true;//记录点赞还是取消点赞

                #region 点赞处理
                //取消点赞
                if (ap != null && ap.KID > 0)
                {
                    isadd = false;
                    dodic.Add(nameof(ArticlePraise.IsDeleted), 1);
                    dodic = UtilConst.AddBaseInfo <ArticlePraise>(dodic, model.Token, false, ref opt);
                    res   = BlogHelper.Update_ArticlePraise(dodic, ap.KID, opt);
                }
                //点赞
                else
                {
                    dodic.Add(nameof(ArticlePraise.IpAddress), GetIP());
                    dodic = UtilConst.AddBaseInfo <ArticlePraise>(dodic, model.Token, true, ref opt);
                    res   = BlogHelper.Add_ArticlePraise(dodic, opt);
                }
                #endregion

                #region 处理list 和 item 缓存
                Task.Run(() =>
                {
                    if (res.IsSucceed)
                    {
                        string key = $"{CJJ.Blog.Apiv2.Models.ConfigUtil.BlogItemCacheKeyPrefix}{item.BlogNum}";
                        BloginfoView bloginfoView = CacheHelper.GetCacheItem(key)?.ToString()?.DeserialObject <BloginfoView>();
                        bloginfoView.Start       += isadd ? 1 : -1;
                        CacheHelper.AddCacheItem(key, bloginfoView.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High);
                        string alllistkey         = ConfigUtil.BlogListCacheKey;
                        string allinfo            = CacheHelper.GetCacheItem(alllistkey)?.ToString();
                        List <Bloginfo> cachelist = allinfo?.DeserialObjectToList <Bloginfo>();
                        Bloginfo info             = cachelist.FirstOrDefault(x => x.BlogNum == item.BlogNum);
                        if (cachelist != null && cachelist.Count > 0 && info != null && info.KID > 0)
                        {
                            cachelist.FirstOrDefault(x => x.BlogNum == item.BlogNum).Start += isadd ? 1 : -1;
                            CacheHelper.AddCacheItem(alllistkey, cachelist.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High);
                        }
                    }
                });
                #endregion

                return(new JsonResponse {
                    Code = res.IsSucceed ? 0 : 1, Data = res
                });
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, "BlogController/AddPraise");
                return(new JsonResponse {
                    Code = 1, Msg = "程序好像开小差了" + ex.Message
                });
            }
        }
        public JsonResponse MemberLogin([FromBody] JsonRequest model)
        {
            try
            {
                RegistModel item = model.Data.ToString()?.DeserialObject <RegistModel>();

                if (string.IsNullOrEmpty(item.UserAccount) || string.IsNullOrEmpty(item.UserPassword))
                {
                    return(new JsonResponse {
                        Code = 1, Msg = "参数不合法"
                    });
                }

                var res = BlogHelper.MemberLogin(item.UserAccount, item.UserPassword, "0", UtilConst.GetIP(), "", "");
                if (res != null && res.IsSucceed)
                {
                    res.MemberInfo.UserPassword = "";
                }

                return(new JsonResponse {
                    Code = res.IsSucceed ? 0 : 1, Msg = res.Message, Data = res
                });
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, "MemberController/RegistItemMember");
                return(new JsonResponse {
                    Code = 1, Msg = "程序好像开小差了" + ex
                });
            }
        }
Exemple #4
0
        public JsonResponse Login([FromBody] LoginModel model)
        {
            SysLoginUser user = new SysLoginUser {
                IsSucceed = false
            };

            try
            {
                if (string.IsNullOrEmpty(model.Account) || string.IsNullOrEmpty(model.Password) || string.IsNullOrEmpty(model.Code) || string.IsNullOrEmpty(model.CodeKey))
                {
                    return(new JsonResponse {
                        Code = 1, Msg = "参数不完整"
                    });
                }

                var code = CacheHelper.GetCacheItemAndDel(model.CodeKey)?.ToString();
                if (string.IsNullOrEmpty(code) || code != model.Code)
                {
                    return(new JsonResponse {
                        Code = 1, Msg = "验证码错误"
                    });
                }

                user = BlogHelper.EmployeePasswordLogin(model.Account, model.Password, UtilConst.GetIP(), UtilConst.Agent, UtilConst.Dns);
                if (!CJJ.Blog.Apiv2.Models.ConfigUtil.Isdebug)
                {
                    user.DataIsEncrypt = true;
                }
                return(new JsonResponse {
                    Code = user.IsSucceed ? 0 : 1, Data = user
                });
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, "LoginController/Login错误");
                return(new JsonResponse {
                    Code = 1, Msg = "系统错误" + ex.Message
                });
            }
        }
        public JsonResponse AddItem(CommentView model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Token))
                {
                    return(new JsonResponse()
                    {
                        Code = 1, Msg = "请从新登录"
                    });
                }

                var opt     = new OpertionUser();
                var member  = UtilConst.Memberinfo(model.Token);
                var comment = new Dictionary <string, object>()
                {
                    { nameof(Comment.Memberid), member.MemberModel.KID },
                    { nameof(Comment.MemberName), member.MemberModel.UserName },
                    { nameof(Comment.ToMemberid), model.ToMemberid },
                    { nameof(Comment.Content), model.Content },
                    { nameof(Comment.BlogNum), model.BlogNum },
                    { nameof(Comment.Avatar), member.MemberModel.UserIcon },
                };
                var sessionid = model.Commentid;
                if (!string.IsNullOrEmpty(model.Commentid))
                {
                    comment.Add(nameof(Comment.Commentid), model.Commentid);
                }
                else
                {
                    sessionid = Guid.NewGuid().ToString("N");
                    comment.Add(nameof(Comment.Commentid), sessionid);
                }
                var    dic = UtilConst.AddBaseInfo <Comment>(comment, model.Token, true, ref opt);
                Result res = BlogHelper.Add_Comment(dic, opt);

                #region 处理list、item缓存问题

                Task.Run(() =>
                {
                    if (res.IsSucceed && model.ToMemberid.Toint() == 0)
                    {
                        List <Bloginfo> bloglist = CacheHelper.GetCacheItem(ConfigUtil.BlogListCacheKey)?.ToString()?.DeserialObjectToList <Bloginfo>();
                        Bloginfo info            = bloglist.FirstOrDefault(x => x.BlogNum == model.BlogNum);
                        if (bloglist != null && bloglist.Count > 0 && info != null && info.KID > 0)
                        {
                            bloglist.FirstOrDefault(x => x.BlogNum == model.BlogNum).Comments += 1;
                            CacheHelper.AddCacheItem(ConfigUtil.BlogListCacheKey, bloglist.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High);
                        }
                        var blogview = CacheHelper.GetCacheItem($"{ConfigUtil.BlogItemCacheKeyPrefix}{model.BlogNum}")?.DeserialObject <BloginfoView>();
                        if (blogview != null && blogview.KID > 0)
                        {
                            blogview.Comments += 1;
                            CacheHelper.AddCacheItem($"{ConfigUtil.BlogItemCacheKeyPrefix}{model.BlogNum}", blogview.SerializObject(), DateTime.Now.AddDays(2), Cache.NoSlidingExpiration, CacheItemPriority.High);
                        }
                    }
                });

                #endregion

                return(new JsonResponse()
                {
                    Code = res.IsSucceed ? 0 : 1, Data = sessionid
                });
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex, "CommentController/additem");
                return(new JsonResponse()
                {
                    Code = 1, Msg = "程序视乎开小差了" + ex.Message
                });
            }
        }