예제 #1
0
        /// <summary>
        /// 获取用户收藏帖子列表
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="userId"></param>
        /// <param name="totalCount"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public List <CityMsg> getListMyFavoriteMsg(int aid, int userId, out int totalCount, int pageSize = 10, int pageIndex = 1)
        {
            string strWhere = $"f.aid={aid} and f.userId={userId} and f.state=0 and f.actionType=0 and msg.state=1";

            string sql = $"select msg.*,f.Id as FavoriteId  from CityUserFavoriteMsg f left join CityMsg msg on f.msgId=msg.Id where {strWhere} order by addTime desc LIMIT {(pageIndex - 1) * pageSize},{pageSize}";

            totalCount = GetMyFavoriteMsgCount(strWhere);
            List <CityMsg> listCity_Msg = new List <CityMsg>();

            using (var dr = SqlMySql.ExecuteDataReader(Utility.dbEnum.MINIAPP.ToString(), CommandType.Text, sql))
            {
                while (dr.Read())
                {
                    CityMsg x = CityMsgBLL.SingleModel.GetModel(dr);
                    if (x != null && x.Id > 0)
                    {
                        //获取用户头像
                        C_UserInfo c_UserInfo = C_UserInfoBLL.SingleModel.GetModel(x.userId);
                        if (c_UserInfo != null)
                        {
                            x.userName      = c_UserInfo.NickName;
                            x.userHeaderImg = c_UserInfo.HeadImgUrl;
                        }

                        //获取帖子类别
                        CityStoreMsgType city_StoreMsgType = CityStoreMsgTypeBLL.SingleModel.GetModel(x.msgTypeId);
                        if (city_StoreMsgType != null)
                        {
                            x.msgTypeName = city_StoreMsgType.name;
                        }

                        //根据帖子ID获取其浏览量-收藏量-分享量数据
                        CityMsgViewFavoriteShare city_MsgViewFavoriteShare = CityMsgViewFavoriteShareBLL.SingleModel.getModelByMsgId(x.Id);
                        if (city_MsgViewFavoriteShare != null)
                        {
                            x.ViewCount     = city_MsgViewFavoriteShare.ViewCount;
                            x.FavoriteCount = city_MsgViewFavoriteShare.FavoriteCount;
                            x.ShareCount    = city_MsgViewFavoriteShare.ShareCount;
                            x.DzCount       = city_MsgViewFavoriteShare.DzCount;
                        }
                        x.msgDetail   = HttpUtility.HtmlDecode(x.msgDetail);
                        x.showTimeStr = CommondHelper.GetTimeSpan(DateTime.Now - x.addTime);
                        x.FavoriteId  = (dr["FavoriteId"] != DBNull.Value?Convert.ToInt32(dr["FavoriteId"]):0);//收藏记录ID
                        listCity_Msg.Add(x);
                    }
                }
            }


            return(listCity_Msg);
        }
예제 #2
0
        public List <CityMsgReport> getListByaid(int aid, out int totalCount, int pageSize = 10, int pageIndex = 1, string orderWhere = "addTime desc")
        {
            string strWhere = $"aid={aid} and state=0";

            totalCount = base.GetCount(strWhere);

            List <CityMsgReport> listCity_MsgReport = base.GetList(strWhere, pageSize, pageIndex, "*", orderWhere);

            if (listCity_MsgReport != null && listCity_MsgReport.Count > 0)
            {
                string            userIds      = string.Join(",", listCity_MsgReport.Select(s => s.reportUserId).Distinct());
                List <C_UserInfo> userInfoList = C_UserInfoBLL.SingleModel.GetListByIds(userIds);

                string         cityMsgIds  = string.Join(",", listCity_MsgReport.Select(s => s.msgId));
                List <CityMsg> cityMsgList = CityMsgBLL.SingleModel.GetListByIds(cityMsgIds);

                listCity_MsgReport.ForEach(x => {
                    //获取举者用户昵称
                    C_UserInfo c_UserInfo = userInfoList?.FirstOrDefault(f => f.Id == x.reportUserId);
                    if (c_UserInfo != null)
                    {
                        x.reportUserName = c_UserInfo.NickName;
                    }

                    //获取被举报帖子的信息
                    CityMsg city_Msg = cityMsgList?.FirstOrDefault(f => f.Id == x.msgId);
                    if (city_Msg != null)
                    {
                        x.beReportMsgState = city_Msg.state;
                        x.beReportMsgPhone = city_Msg.phone;
                        c_UserInfo         = C_UserInfoBLL.SingleModel.GetModel(city_Msg.userId);
                        if (c_UserInfo != null)
                        {
                            x.beReportUserName = c_UserInfo.NickName;
                        }
                    }
                });
            }

            return(listCity_MsgReport);
        }
예제 #3
0
        /// <summary>
        /// 获取帖子评论列表
        /// </summary>
        /// <param name="aid"></param>
        /// <param name="totalCount"></param>
        /// <param name="keyMsg"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="Id"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List <CityMsgComment> GetCityMsgComment(int aid, out int totalCount, string keyMsg = "", int pageSize = 10, int pageIndex = 1, int Id = 0, int userId = 0)
        {
            string strWhere = $"aid={aid} and State=0 ";
            List <MySqlParameter> parameters = new List <MySqlParameter>();

            if (userId > 0)
            {
                strWhere += $"  and FromUserId={userId} ";
            }

            if (Id > 0)
            {
                strWhere += $"  and MsgId={Id}";
            }

            if (!string.IsNullOrEmpty(keyMsg))
            {
                strWhere += $" and CommentDetail like @keyMsg ";
                parameters.Add(new MySqlParameter("keyMsg", $"%{keyMsg}%"));
            }

            totalCount = base.GetCount(strWhere, parameters.ToArray());

            List <CityMsgComment> listCityMsgComment = base.GetListByParam(strWhere, parameters.ToArray(), pageSize, pageIndex, "*", " AddTime Desc");

            if (listCityMsgComment != null && listCityMsgComment.Count > 0)
            {
                string fuserIds = string.Join(",", listCityMsgComment.Select(s => s.FromUserId));
                string tuserIds = string.Join(",", listCityMsgComment.Select(s => s.ToUserId));
                if (!string.IsNullOrEmpty(tuserIds))
                {
                    if (!string.IsNullOrEmpty(fuserIds))
                    {
                        fuserIds += "," + tuserIds;
                    }
                    else
                    {
                        fuserIds = tuserIds;
                    }
                }
                List <C_UserInfo> userInfoList = C_UserInfoBLL.SingleModel.GetListByIds(fuserIds);

                string         cityMsgIds  = string.Join(",", listCityMsgComment.Select(s => s.MsgId));
                List <CityMsg> cityMsgList = CityMsgBLL.SingleModel.GetListByIds(cityMsgIds);

                listCityMsgComment.ForEach(x =>
                {
                    C_UserInfo c_userInfo = userInfoList?.FirstOrDefault(f => f.Id == x.FromUserId);
                    if (c_userInfo != null)
                    {
                        x.NickName  = c_userInfo.NickName;
                        x.HeaderImg = c_userInfo.HeadImgUrl;
                    }
                    else
                    {
                        x.NickName = "匿名";
                    }

                    C_UserInfo to_userInfo = userInfoList?.FirstOrDefault(f => f.Id == x.ToUserId);
                    if (to_userInfo != null)
                    {
                        x.ToNickName  = to_userInfo.NickName;
                        x.ToHeaderImg = to_userInfo.HeadImgUrl;
                    }

                    CityMsg cityMsg = cityMsgList?.FirstOrDefault(f => f.Id == x.MsgId);
                    if (cityMsg != null)
                    {
                        x.MsgTxt      = cityMsg.msgDetail.Length > 20 ? cityMsg.msgDetail.Substring(0, 20) + "..." : cityMsg.msgDetail;
                        x.MsgFirstImg = cityMsg.imgList.FirstOrDefault();
                    }

                    x.ShowTimeStr = CommondHelper.GetTimeSpan(DateTime.Now - x.AddTime);
                });
            }

            return(listCityMsgComment);
        }
예제 #4
0
        public ActionResult getMsgDetail()
        {
            returnObj = new Return_Msg_APP();
            string appId  = Context.GetRequest("appId", string.Empty);
            int    msgId  = Context.GetRequestInt("msgId", 0);  //帖子信息Id
            int    userId = Context.GetRequestInt("userId", 0); //用户Id
            string latStr = Context.GetRequest("lat", string.Empty);
            string lngStr = Context.GetRequest("lng", string.Empty);

            if (string.IsNullOrEmpty(appId) || msgId <= 0)
            {
                returnObj.code = "200";
                returnObj.Msg  = "参数错误";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            XcxAppAccountRelation r = _xcxAppAccountRelationBLL.GetModelByAppid(appId);

            if (r == null)
            {
                returnObj.code = "200";
                returnObj.Msg  = "小程序未授权";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }


            CityMsg model = CityMsgBLL.SingleModel.getMsg(r.Id, msgId);

            if (model == null)
            {
                returnObj.code = "200";
                returnObj.Msg  = "找不到数据";
                return(Json(returnObj, JsonRequestBehavior.AllowGet));
            }

            double lat = 0.00;
            double lng = 0.00;

            //表示按照距离最近的
            //表示没有传坐标 通过客户端IP获取经纬度
            // log4net.LogHelper.WriteInfo(this.GetType(), $"!!!!orderType={orderType};{lat},{lng}");
            if (!double.TryParse(latStr, out lat) || !double.TryParse(lngStr, out lng) || lat <= 0 || lng <= 0)
            {
                string IP = WebHelper.GetIP();

                IPToPoint iPToPoint = CommondHelper.GetLoctionByIP(IP);
                if (iPToPoint != null)
                {
                    lat = iPToPoint.result.location.lat;
                    lng = iPToPoint.result.location.lng;
                    // log4net.LogHelper.WriteInfo(this.GetType(), $"IP={IP};{lat},{lng}");
                }
            }
            model.distance = CityMsgBLL.SingleModel.GetDistance(Convert.ToDouble(model.lat), Convert.ToDouble(model.lng), lat, lng);

            CityUserFavoriteMsg _userFavoriteMsg = CityUserFavoriteMsgBLL.SingleModel.getCity_UserFavoriteMsg(r.Id, msgId, userId);

            model.isFavorited = (_userFavoriteMsg != null);
            _userFavoriteMsg  = CityUserFavoriteMsgBLL.SingleModel.getCity_UserFavoriteMsg(r.Id, msgId, userId, 1);
            model.isDzed      = (_userFavoriteMsg != null);
            CityMsgReport city_MsgReport = CityMsgReportBLL.SingleModel.GetCityMsgReport(userId, msgId);

            model.isReported = (city_MsgReport != null);
            int commentTotalCount = 0;

            model.Comments    = CityMsgCommentBLL.SingleModel.GetCityMsgComment(r.Id, out commentTotalCount, string.Empty, 1000, 1, model.Id);
            returnObj.isok    = true;
            returnObj.Msg     = "获取成功";
            returnObj.dataObj = new { msg = model };
            return(Json(returnObj, JsonRequestBehavior.AllowGet));
        }
예제 #5
0
        public ActionResult AddMsgViewFavoriteShare()
        {
            returnObj = new Return_Msg_APP();
            string appId      = Context.GetRequest("appId", string.Empty);
            int    msgId      = Context.GetRequestInt("msgId", 0);
            int    userId     = Context.GetRequestInt("userId", 0);
            int    actionType = Context.GetRequestInt("actionType", 0);//默认为0 表示浏览量 1表示收藏 2 表示分享成功 3表示点赞

            if (string.IsNullOrEmpty(appId) || msgId <= 0)
            {
                returnObj.code = "200";
                returnObj.Msg  = "参数错误";
                return(Json(returnObj));
            }
            XcxAppAccountRelation r = _xcxAppAccountRelationBLL.GetModelByAppid(appId);

            if (r == null)
            {
                returnObj.code = "200";
                returnObj.Msg  = "小程序未授权";
                return(Json(returnObj));
            }
            C_UserInfo userInfo = new C_UserInfo();

            if (actionType == 3 || actionType == 1)
            {
                if (userId <= 0)
                {
                    returnObj.code = "200";
                    returnObj.Msg  = "请先授权";
                    return(Json(returnObj));
                }
                userInfo = C_UserInfoBLL.SingleModel.GetModel(userId);
                if (userInfo == null)
                {
                    returnObj.code = "200";
                    returnObj.Msg  = "登录信息过期";
                    return(Json(returnObj));
                }
            }

            CityMsg cityMsg = CityMsgBLL.SingleModel.GetModel(msgId);

            if (cityMsg == null)
            {
                returnObj.code = "200";
                returnObj.Msg  = "帖子不存在";
                return(Json(returnObj));
            }
            string           msgTypeName      = string.Empty;
            CityStoreMsgType cityStoreMsgType = CityStoreMsgTypeBLL.SingleModel.GetModel(cityMsg.msgTypeId);

            if (cityStoreMsgType != null)
            {
                msgTypeName = cityStoreMsgType.name;
            }

            CityMsgViewFavoriteShare mode = CityMsgViewFavoriteShareBLL.SingleModel.getModelByMsgId(msgId);

            TransactionModel tranModel = new TransactionModel();

            if (mode == null)
            {
                //新增一条数据
                mode = new CityMsgViewFavoriteShare();
                switch (actionType)
                {
                case 1:    //表示收藏

                    mode.FavoriteCount = 1;
                    if (CityUserFavoriteMsgBLL.SingleModel.getCity_UserFavoriteMsg(r.Id, msgId, userId) == null)
                    {
                        tranModel.Add(CityUserFavoriteMsgBLL.SingleModel.BuildAddSql(new CityUserFavoriteMsg()
                        {    //用户-帖子收藏记录
                            aid     = r.Id,
                            userId  = userId,
                            msgId   = msgId,
                            addTime = DateTime.Now
                        }));
                    }
                    break;

                case 2:    //表示分享成功
                    mode.ShareCount = 1;
                    break;

                case 3:    //表示点赞成功
                    if (CityUserFavoriteMsgBLL.SingleModel.getCity_UserFavoriteMsg(r.Id, msgId, userId, 1) == null)
                    {
                        mode.DzCount = 1;
                        CityUserMsg city_UserMsg = new CityUserMsg();
                        city_UserMsg.addTime    = DateTime.Now;
                        city_UserMsg.aid        = r.Id;
                        city_UserMsg.fromUserId = userId;
                        city_UserMsg.toUserId   = cityMsg.userId;
                        city_UserMsg.updateTime = DateTime.Now;
                        city_UserMsg.msgBody    = string.Format(WebSiteConfig.City_UserDzMsgTemplate, userInfo.NickName, $"'#{msgTypeName}#{(cityMsg.msgDetail.Length > 10 ? cityMsg.msgDetail.Substring(0, 10) : cityMsg.msgDetail)}'");
                        city_UserMsg.msgType    = 1;
                        tranModel.Add(CityUserMsgBLL.SingleModel.BuildAddSql(city_UserMsg));

                        tranModel.Add(CityUserFavoriteMsgBLL.SingleModel.BuildAddSql(new CityUserFavoriteMsg()
                        {    //用户-帖子点赞记录
                            aid        = r.Id,
                            userId     = userId,
                            msgId      = msgId,
                            addTime    = DateTime.Now,
                            actionType = 1
                        }));
                    }
                    break;

                default:    //默认为0 表示浏览量
                    mode.ViewCount = 1;
                    break;
                }

                mode.msgId   = msgId;
                mode.addTime = DateTime.Now;
                mode.aid     = r.Id;
                tranModel.Add(CityMsgViewFavoriteShareBLL.SingleModel.BuildAddSql(mode));

                if (tranModel.sqlArray == null || tranModel.sqlArray.Length <= 0 || !CityMsgViewFavoriteShareBLL.SingleModel.ExecuteTransactionDataCorect(tranModel.sqlArray))
                {
                    returnObj.code = "200";
                    returnObj.Msg  = "新增失败";
                    return(Json(returnObj));
                }

                returnObj.isok = true;
                returnObj.code = "200";
                returnObj.Msg  = "新增成功";
                return(Json(returnObj));
            }
            else
            {
                string updateFiled = "ViewCount";
                //更新
                switch (actionType)
                {
                case 1:    //表示收藏

                    if (CityUserFavoriteMsgBLL.SingleModel.getCity_UserFavoriteMsg(r.Id, msgId, userId) == null)
                    {
                        mode.FavoriteCount += 1;
                        updateFiled         = "FavoriteCount";
                        tranModel.Add(CityUserFavoriteMsgBLL.SingleModel.BuildAddSql(new CityUserFavoriteMsg()
                        {    //用户-帖子收藏记录
                            aid     = r.Id,
                            userId  = userId,
                            msgId   = msgId,
                            addTime = DateTime.Now
                        }));
                    }
                    break;

                case 2:    //表示分享成功
                    mode.ShareCount += 1;
                    updateFiled      = "ShareCount";
                    break;

                case 3:    //表示点赞成功

                    if (CityUserFavoriteMsgBLL.SingleModel.getCity_UserFavoriteMsg(r.Id, msgId, userId, 1) == null)
                    {
                        mode.DzCount += 1;
                        updateFiled   = "DzCount";
                        //发消息
                        CityUserMsg city_UserMsg = new CityUserMsg();
                        city_UserMsg.addTime    = DateTime.Now;
                        city_UserMsg.aid        = r.Id;
                        city_UserMsg.fromUserId = userId;
                        city_UserMsg.toUserId   = cityMsg.userId;
                        city_UserMsg.updateTime = DateTime.Now;
                        city_UserMsg.msgBody    = string.Format(WebSiteConfig.City_UserDzMsgTemplate, userInfo.NickName, $"'#{msgTypeName}#{(cityMsg.msgDetail.Length > 10 ? cityMsg.msgDetail.Substring(0, 10) : cityMsg.msgDetail)}'");
                        city_UserMsg.msgType    = 1;
                        tranModel.Add(CityUserMsgBLL.SingleModel.BuildAddSql(city_UserMsg));

                        tranModel.Add(CityUserFavoriteMsgBLL.SingleModel.BuildAddSql(new CityUserFavoriteMsg()
                        {    //用户-帖子点赞记录
                            aid        = r.Id,
                            userId     = userId,
                            msgId      = msgId,
                            addTime    = DateTime.Now,
                            actionType = 1
                        }));
                    }

                    break;

                default:    //默认为0 表示浏览量
                    mode.ViewCount += 1;
                    break;
                }

                tranModel.Add(CityMsgViewFavoriteShareBLL.SingleModel.BuildUpdateSql(mode, updateFiled));

                if (tranModel.sqlArray == null || tranModel.sqlArray.Length <= 0 || !CityMsgViewFavoriteShareBLL.SingleModel.ExecuteTransactionDataCorect(tranModel.sqlArray))
                {
                    returnObj.code = "200";
                    returnObj.Msg  = "更新失败";
                    return(Json(returnObj));
                }

                returnObj.isok = true;
                returnObj.code = "200";
                returnObj.Msg  = "更新成功";
                return(Json(returnObj));
            }
        }
예제 #6
0
        /// <summary>
        /// 新增评论
        /// </summary>
        /// <returns></returns>
        public ActionResult AddComment()
        {
            base.returnObj      = new Return_Msg_APP();
            base.returnObj.code = "200";
            string appId         = Context.GetRequest("appId", string.Empty);
            int    userId        = Context.GetRequestInt("userId", 0);
            int    Id            = Context.GetRequestInt("Id", 0);
            string commentDetail = Context.GetRequest("commentDetail", string.Empty);

            if (string.IsNullOrEmpty(appId) || userId <= 0 || Id <= 0)
            {
                base.returnObj.Msg = "参数错误";
                return(Json(base.returnObj));
            }

            if (string.IsNullOrEmpty(commentDetail))
            {
                base.returnObj.Msg = "评论详情不能为空";
                return(Json(base.returnObj));
            }
            if (commentDetail.Length > 1000)
            {
                base.returnObj.Msg = "评论详情最大1000字符";
                return(Json(base.returnObj));
            }

            XcxAppAccountRelation r = _xcxAppAccountRelationBLL.GetModelByAppid(appId);

            if (r == null)
            {
                base.returnObj.Msg = "小程序未授权";
                return(Json(base.returnObj));
            }

            //表示帖子的评论
            CityMsg cityMsg = CityMsgBLL.SingleModel.GetModel(Id);

            if (cityMsg == null || cityMsg.state == -1)
            {
                base.returnObj.Msg = "帖子不存在!";
                return(Json(base.returnObj));
            }


            CityMsgComment cityMsgComment = new CityMsgComment();

            cityMsgComment.AId           = r.Id;
            cityMsgComment.FromUserId    = userId;
            cityMsgComment.CommentDetail = commentDetail;
            cityMsgComment.AddTime       = DateTime.Now;
            cityMsgComment.ToUserId      = cityMsg.userId;
            cityMsgComment.MsgId         = cityMsg.Id;
            int commentTotalCount = 0;
            int commentId         = Convert.ToInt32(CityMsgCommentBLL.SingleModel.Add(cityMsgComment));

            if (commentId > 0)
            {
                base.returnObj.dataObj = new { comments = CityMsgCommentBLL.SingleModel.GetCityMsgComment(r.Id, out commentTotalCount, string.Empty, 1000, 1, cityMsg.Id) };
                base.returnObj.isok    = true;
                base.returnObj.Msg     = "评论成功";
                return(Json(base.returnObj));
            }
            else
            {
                base.returnObj.Msg = "评论失败";
                return(Json(base.returnObj));
            }
        }