diff --git a/Infrastructure/CustomException/ResultCode.cs b/Infrastructure/CustomException/ResultCode.cs index 58739e4c80369701fd295ad73f8cc8215780664e..6f1c9c897f90099b758a913828ac9703b3132db8 100644 --- a/Infrastructure/CustomException/ResultCode.cs +++ b/Infrastructure/CustomException/ResultCode.cs @@ -34,6 +34,9 @@ namespace Infrastructure [Description("授权失败")] OAUTH_FAIL = 201, + [Description("请先绑定手机号")] + PHONE_BIND = 202, + [Description("未授权")] DENY = 401, diff --git a/ZR.ServiceCore/ProteryConstant.cs b/Infrastructure/ProteryConstant.cs similarity index 100% rename from ZR.ServiceCore/ProteryConstant.cs rename to Infrastructure/ProteryConstant.cs diff --git a/ZR.Admin.WebApi/Controllers/Article/ArticleCategoryController.cs b/ZR.Admin.WebApi/Controllers/Article/ArticleCategoryController.cs index ffa2ac7eb8e11a0221531107d3faf1c0c79dbba4..bb9a8186db7b4ac18600eb72a91a4b56f9585841 100644 --- a/ZR.Admin.WebApi/Controllers/Article/ArticleCategoryController.cs +++ b/ZR.Admin.WebApi/Controllers/Article/ArticleCategoryController.cs @@ -1,7 +1,8 @@ using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Filters; +using ZR.Model.Content; using ZR.Model.Dto; -using ZR.Model.System; +using ZR.Service.Content.IService; namespace ZR.Admin.WebApi.Controllers { @@ -28,7 +29,7 @@ namespace ZR.Admin.WebApi.Controllers /// /// [HttpGet("list")] - //[ActionPermissionFilter(Permission = "articlecategory:list")] + [AllowAnonymous] public IActionResult QueryArticleCategory([FromQuery] ArticleCategoryQueryDto parm) { var response = _ArticleCategoryService.GetList(parm); @@ -41,7 +42,7 @@ namespace ZR.Admin.WebApi.Controllers /// /// [HttpGet("treeList")] - //[ActionPermissionFilter(Permission = "articlecategory:list")] + [AllowAnonymous] public IActionResult QueryTreeArticleCategory([FromQuery] ArticleCategoryQueryDto parm) { var response = _ArticleCategoryService.GetTreeList(parm); @@ -54,6 +55,7 @@ namespace ZR.Admin.WebApi.Controllers /// /// [HttpGet("{CategoryId}")] + [AllowAnonymous] //[ActionPermissionFilter(Permission = "articlecategory:query")] public IActionResult GetArticleCategory(int CategoryId) { @@ -62,6 +64,20 @@ namespace ZR.Admin.WebApi.Controllers return SUCCESS(response); } + /// + /// 查询目录分类 + /// + /// + /// + [HttpGet("type{categoryType}")] + //[ActionPermissionFilter(Permission = "articlecategory:query")] + public IActionResult GetArticleCategoryByType(int categoryType) + { + var response = _ArticleCategoryService.GetFirst(x => x.CategoryType == categoryType); + + return SUCCESS(response); + } + /// /// 添加文章目录 /// diff --git a/ZR.Admin.WebApi/Controllers/Article/ArticleController.cs b/ZR.Admin.WebApi/Controllers/Article/ArticleController.cs index 4056968f89a4a8c949eb3ef5af76a963f37432d2..c8475fc4ec3f94ef50b2cee4df52b54494d9e5a5 100644 --- a/ZR.Admin.WebApi/Controllers/Article/ArticleController.cs +++ b/ZR.Admin.WebApi/Controllers/Article/ArticleController.cs @@ -1,9 +1,8 @@ using Microsoft.AspNetCore.Mvc; -using SqlSugar; using ZR.Admin.WebApi.Filters; -using ZR.Model.System; -using ZR.Model.System.Dto; -using ZR.ServiceCore.Model.Enums; +using ZR.Model.Content; +using ZR.Model.Dto; +using ZR.Service.Content.IService; namespace ZR.Admin.WebApi.Controllers { @@ -21,10 +20,13 @@ namespace ZR.Admin.WebApi.Controllers private readonly IArticleService _ArticleService; private readonly IArticleCategoryService _ArticleCategoryService; - public ArticleController(IArticleService ArticleService, IArticleCategoryService articleCategoryService) + public ArticleController( + IArticleService ArticleService, + IArticleCategoryService articleCategoryService) { _ArticleService = ArticleService; _ArticleCategoryService = articleCategoryService; + _ArticleService = ArticleService; } /// @@ -53,83 +55,36 @@ namespace ZR.Admin.WebApi.Controllers return SUCCESS(response); } - /// - /// 前台查询文章列表 - /// - /// - [HttpGet("hotList")] - [AllowAnonymous] - public IActionResult QueryHot([FromQuery] ArticleQueryDto parm) - { - var response = _ArticleService.GetHotList(parm); - - return SUCCESS(response); - } - - /// - /// 查询最新文章列表 - /// - /// - [HttpGet("newList")] - [AllowAnonymous] - public IActionResult QueryNew() - { - var predicate = Expressionable.Create
(); - predicate = predicate.And(m => m.Status == "1"); - predicate = predicate.And(m => m.IsPublic == 1); - - var response = _ArticleService.Queryable() - .Where(predicate.ToExpression()) - .Includes(x => x.ArticleCategoryNav) //填充子对象 - .Take(10) - .OrderBy(f => f.UpdateTime, OrderByType.Desc).ToList(); - - return SUCCESS(response); - } - /// /// 查询文章详情 /// /// /// [HttpGet("{id}")] - [AllowAnonymous] public IActionResult Get(int id) { long userId = HttpContext.GetUId(); - var response = _ArticleService.GetId(id); - var model = response.Adapt(); - if (model == null) return ToResponse(ResultCode.FAIL, "文章不存在"); - if (model.IsPublic == 0 && userId != model.UserId) - { - return ToResponse(ResultCode.CUSTOM_ERROR, "访问失败"); - } - if (model != null) - { - model.ArticleCategoryNav = _ArticleCategoryService.GetById(model.CategoryId); - model.TagList = model.Tags?.Split(',', StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty(); - } - var CK = "ARTICLE_DETAILS_" + userId + HttpContextExtension.GetClientUserIp(HttpContext); - if (!CacheHelper.Exists(CK)) - { - _ArticleService.UpdateArticleHit(id); - } - CacheHelper.SetCache(CK, 1, 10); - return SUCCESS(model); + var model = _ArticleService.GetArticle(id, userId); + + ApiResult apiResult = ApiResult.Success(model); + + return ToResponse(apiResult); } /// - /// 添加文章 + /// 发布文章 /// /// [HttpPost("add")] [ActionPermissionFilter(Permission = "system:article:add")] - [Log(Title = "发布文章", BusinessType = BusinessType.INSERT)] + //[Log(Title = "发布文章", BusinessType = BusinessType.INSERT)] public IActionResult Create([FromBody] ArticleDto parm) { var addModel = parm.Adapt
().ToCreate(context: HttpContext); addModel.AuthorName = HttpContext.GetName(); addModel.UserId = HttpContext.GetUId(); + addModel.UserIP = HttpContext.GetClientUserIp(); + addModel.Location = HttpContextExtension.GetIpInfo(addModel.UserIP); return SUCCESS(_ArticleService.InsertReturnIdentity(addModel)); } @@ -140,7 +95,7 @@ namespace ZR.Admin.WebApi.Controllers /// [HttpPut("edit")] [ActionPermissionFilter(Permission = "system:article:update")] - [Log(Title = "文章修改", BusinessType = BusinessType.UPDATE)] + //[Log(Title = "文章修改", BusinessType = BusinessType.UPDATE)] public IActionResult Update([FromBody] ArticleDto parm) { parm.AuthorName = HttpContext.GetName(); @@ -190,6 +145,5 @@ namespace ZR.Admin.WebApi.Controllers var response = _ArticleService.Delete(id); return SUCCESS(response); } - } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/Controllers/Article/ArticleTopicController.cs b/ZR.Admin.WebApi/Controllers/Article/ArticleTopicController.cs new file mode 100644 index 0000000000000000000000000000000000000000..300c10266d5bec959cdba6c685ef0fcc46157cdd --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/Article/ArticleTopicController.cs @@ -0,0 +1,122 @@ +using Microsoft.AspNetCore.Mvc; +using ZR.Admin.WebApi.Filters; +using ZR.Model.Content; +using ZR.Model.Dto; +using ZR.Service.Content.IService; + +//创建时间:2024-04-29 +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 文章话题 + /// + [Verify] + [ApiExplorerSettings(GroupName = "article")] + [Route("article/ArticleTopic")] + public class ArticleTopicController : BaseController + { + /// + /// 文章话题接口 + /// + private readonly IArticleTopicService _ArticleTopicService; + + public ArticleTopicController(IArticleTopicService ArticleTopicService) + { + _ArticleTopicService = ArticleTopicService; + } + + /// + /// 查询文章话题列表 + /// + /// + /// + [HttpGet("list")] + [ActionPermissionFilter(Permission = "articletopic:list")] + public IActionResult QueryArticleTopic([FromQuery] ArticleTopicQueryDto parm) + { + var response = _ArticleTopicService.GetList(parm); + return SUCCESS(response); + } + + /// + /// 查询文章话题详情 + /// + /// + /// + [HttpGet("{TopicId}")] + [ActionPermissionFilter(Permission = "articletopic:query")] + public IActionResult GetArticleTopic(long TopicId) + { + var response = _ArticleTopicService.GetInfo(TopicId); + + var info = response.Adapt(); + return SUCCESS(info); + } + + /// + /// 添加文章话题 + /// + /// + [HttpPost] + [ActionPermissionFilter(Permission = "articletopic:add")] + [Log(Title = "文章话题", BusinessType = BusinessType.INSERT)] + public IActionResult AddArticleTopic([FromBody] ArticleTopicDto parm) + { + var modal = parm.Adapt().ToCreate(HttpContext); + + var response = _ArticleTopicService.AddArticleTopic(modal); + + return SUCCESS(response); + } + + /// + /// 更新文章话题 + /// + /// + [HttpPut] + [ActionPermissionFilter(Permission = "articletopic:edit")] + [Log(Title = "文章话题", BusinessType = BusinessType.UPDATE)] + public IActionResult UpdateArticleTopic([FromBody] ArticleTopicDto parm) + { + var modal = parm.Adapt().ToUpdate(HttpContext); + var response = _ArticleTopicService.UpdateArticleTopic(modal); + + return ToResponse(response); + } + + /// + /// 删除文章话题 + /// + /// + [HttpDelete("delete/{ids}")] + [ActionPermissionFilter(Permission = "articletopic:delete")] + [Log(Title = "文章话题", BusinessType = BusinessType.DELETE)] + public IActionResult DeleteArticleTopic([FromRoute] string ids) + { + var idArr = Tools.SplitAndConvert(ids); + + return ToResponse(_ArticleTopicService.Delete(idArr)); + } + + /// + /// 导出文章话题 + /// + /// + [Log(Title = "文章话题", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)] + [HttpGet("export")] + [ActionPermissionFilter(Permission = "articletopic:export")] + public IActionResult Export([FromQuery] ArticleTopicQueryDto parm) + { + parm.PageNum = 1; + parm.PageSize = 100000; + var list = _ArticleTopicService.ExportList(parm).Result; + if (list == null || list.Count <= 0) + { + return ToResponse(ResultCode.FAIL, "没有要导出的数据"); + } + var result = ExportExcelMini(list, "文章话题", "文章话题"); + return ExportExcel(result.Item2, result.Item1); + } + + } +} \ No newline at end of file diff --git a/ZR.Admin.WebApi/Controllers/Article/FrontArticleController.cs b/ZR.Admin.WebApi/Controllers/Article/FrontArticleController.cs new file mode 100644 index 0000000000000000000000000000000000000000..34a3276ad1d251541656cfc1c6580453eba05e92 --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/Article/FrontArticleController.cs @@ -0,0 +1,205 @@ +using Microsoft.AspNetCore.Mvc; +using SqlSugar; +using ZR.Admin.WebApi.Filters; +using ZR.Model.Content; +using ZR.Model.Dto; +using ZR.Model.System.Dto; +using ZR.Service.Content.IService; + +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 内容管理前端接口 + /// + [Route("front/article")] + [ApiExplorerSettings(GroupName = "article")] + [Verify] + public class FrontArticleController : BaseController + { + /// + /// 文章接口 + /// + private readonly IArticleService _ArticleService; + private readonly IArticleCategoryService _ArticleCategoryService; + private readonly IArticlePraiseService _ArticlePraiseService; + private readonly ISysUserService _SysUserService; + private readonly IArticleTopicService _ArticleTopicService; + + public FrontArticleController( + IArticleService ArticleService, + IArticleCategoryService articleCategoryService, + IArticlePraiseService articlePraiseService, + ISysUserService sysUserService, + IArticleTopicService articleTopicService) + { + _ArticleService = ArticleService; + _ArticleCategoryService = articleCategoryService; + _ArticleService = ArticleService; + _ArticlePraiseService = articlePraiseService; + _SysUserService = sysUserService; + _ArticleTopicService = articleTopicService; + } + + /// + /// 前台查询文章列表 + /// + /// + [HttpGet("homeList")] + [AllowAnonymous] + public IActionResult QueryHomeList([FromQuery] ArticleQueryDto parm) + { + parm.UserId = HttpContext.GetUId(); + var response = _ArticleService.GetArticleList(parm); + + return SUCCESS(response); + } + + /// + /// 查询最新文章列表 + /// + /// + [HttpGet("newList")] + [AllowAnonymous] + public IActionResult QueryNew() + { + var predicate = Expressionable.Create
(); + predicate = predicate.And(m => m.Status == "1"); + predicate = predicate.And(m => m.IsPublic == 1); + predicate = predicate.And(m => m.ArticleType == 0); + + var response = _ArticleService.Queryable() + .Where(predicate.ToExpression()) + .Includes(x => x.ArticleCategoryNav) //填充子对象 + .Take(10) + .OrderBy(f => f.UpdateTime, OrderByType.Desc).ToList(); + + return SUCCESS(response); + } + + /// + /// 点赞 + /// + /// + /// + /// + [HttpPost("praise/{id}")] + [ActionPermissionFilter(Permission = "common")] + public IActionResult Praise(int id = 0, long authorId = 0) + { + ArticlePraise addModel = new() + { + UserId = HttpContext.GetUId(), + UserIP = HttpContext.GetClientUserIp(), + ArticleId = id, + ToUserId = authorId + }; + addModel.Location = HttpContextExtension.GetIpInfo(addModel.UserIP); + + return SUCCESS(_ArticlePraiseService.Praise(addModel)); + } + + /// + /// 置顶 + /// + /// + [HttpPut("top")] + [ActionPermissionFilter(Permission = "common")] + public IActionResult Top([FromBody] Article parm) + { + var response = _ArticleService.TopArticle(parm); + + return SUCCESS(response); + } + + /// + /// 修改可见范围 + /// + /// + [HttpPut("changePublic")] + [ActionPermissionFilter(Permission = "common")] + public IActionResult ChangePublic([FromBody] Article parm) + { + if (parm == null) { return ToResponse(ResultCode.CUSTOM_ERROR); } + var userId = HttpContext.GetUId(); + if (userId != parm.UserId) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "操作失败"); + } + var response = _ArticleService.ChangeArticlePublic(parm); + + return SUCCESS(response); + } + + /// + /// 删除 + /// + /// + [HttpDelete("del/{id}")] + [ActionPermissionFilter(Permission = "common")] + public IActionResult Delete(int id = 0) + { + var userId = HttpContext.GetUId(); + var info = _ArticleService.GetId(id); + if (info == null || info.UserId != userId) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "删除失败(-1)"); + } + var response = _ArticleService.Delete(id); + return SUCCESS(response); + } + + /// + /// 查询文章详情 + /// + /// + /// + [HttpGet("{id}")] + [AllowAnonymous] + public IActionResult Get(int id) + { + long userId = HttpContext.GetUId(); + var model = _ArticleService.GetArticle(id, userId); + var user = _SysUserService.GetById(model.UserId); + ApiResult apiResult = ApiResult.Success(model); + model.User = new ArticleUser() + { + Avatar = user.Avatar, + NickName = user.NickName, + Sex = user.Sex, + }; + //apiResult.Put("user", user.Adapt()); + return ToResponse(apiResult); + } + + /// + /// 前台查询话题 + /// + /// + /// + [HttpGet("topicList")] + [AllowAnonymous] + public IActionResult QueryTopicList([FromQuery] ArticleTopicQueryDto parm) + { + var response = _ArticleTopicService.GetTopicList(parm); + + return SUCCESS(response); + } + + /// + /// 查询文章话题详情 + /// + /// + /// + [HttpGet("topic/{TopicId}")] + [AllowAnonymous] + public IActionResult GetArticleTopic(long TopicId) + { + var response = _ArticleTopicService.GetInfo(TopicId); + + _ArticleTopicService.Update(w => w.TopicId == TopicId, it => new ArticleTopic() { ViewNum = it.ViewNum + 1 }); + + var info = response.Adapt(); + return SUCCESS(info); + } + } +} diff --git a/ZR.Admin.WebApi/Controllers/Article/FrontCommentController.cs b/ZR.Admin.WebApi/Controllers/Article/FrontCommentController.cs new file mode 100644 index 0000000000000000000000000000000000000000..d1a028f342e47c09e9231f35c378e3f63a2742ba --- /dev/null +++ b/ZR.Admin.WebApi/Controllers/Article/FrontCommentController.cs @@ -0,0 +1,115 @@ +using Microsoft.AspNetCore.Mvc; +using ZR.Admin.WebApi.Filters; +using ZR.Model; +using ZR.Model.Content; +using ZR.Model.Dto; +using ZR.Service.Content.IService; + +namespace ZR.Admin.WebApi.Controllers +{ + /// + /// 评论 + /// + [Route("front/comment")] + [ApiExplorerSettings(GroupName = "article")] + [ApiController] + public class FrontCommentController : BaseController + { + private readonly IArticleCommentService messageService; + + /// + /// + /// + /// + public FrontCommentController(IArticleCommentService messageService) + { + this.messageService = messageService; + } + + /// + /// 查询评论列表 + /// + /// + /// + [HttpGet("list")] + public IActionResult QueryList([FromQuery] MessageQueryDto parm) + { + parm.PageSize = 10; + PagedInfo? response; + //查询二级评论 + if (parm.CommentId > 0) + { + response = messageService.GetReplyComments(parm.CommentId, parm); + } + else + { + response = messageService.GetMessageList(parm); + } + + return SUCCESS(response); + } + + /// + /// 评论 + /// + /// + [HttpPost("add")] + [Verify] + [ActionPermissionFilter(Permission = "common")] + public IActionResult Create([FromBody] ArticleCommentDto parm) + { + var uid = HttpContextExtension.GetUId(HttpContext); + if (uid <= 0) { return ToResponse(ResultCode.DENY); } + + var addModel = parm.Adapt().ToCreate(context: HttpContext); + addModel.UserIP = HttpContextExtension.GetClientUserIp(HttpContext); + addModel.UserId = uid; + return SUCCESS(messageService.AddMessage(addModel).Adapt()); + } + + /// + /// 评论点赞 + /// + /// + /// + [HttpPost("praise")] + [ActionPermissionFilter(Permission = "common")] + [Verify] + public IActionResult Praise([FromBody] ArticleCommentDto dto) + { + if (dto == null || dto.CommentId <= 0) return ToResponse(ResultCode.PARAM_ERROR); + //var uid = HttpContextExtension.GetUId(HttpContext); + + return SUCCESS(messageService.PraiseMessage(dto.CommentId)); + } + + /// + /// 评论删除 + /// + /// + /// + [HttpDelete("delete/{mid}")] + [ActionPermissionFilter(Permission = "common")] + [Verify] + public IActionResult Delete(long mid) + { + var uid = HttpContextExtension.GetUId(HttpContext); + if (uid <= 0) { return ToResponse(ResultCode.DENY); } + return SUCCESS(messageService.DeleteMessage(mid.ParseToLong(), uid)); + } + + /// + /// 查询我的评论列表 + /// + /// + /// + [HttpGet("mylist")] + [Verify] + public IActionResult QueryMyCommentList([FromQuery] MessageQueryDto parm) + { + PagedInfo response = messageService.GetMyMessageList(parm); + + return SUCCESS(response); + } + } +} diff --git a/ZR.Admin.WebApi/Controllers/Article/MonentController.cs b/ZR.Admin.WebApi/Controllers/Article/MomentsController.cs similarity index 38% rename from ZR.Admin.WebApi/Controllers/Article/MonentController.cs rename to ZR.Admin.WebApi/Controllers/Article/MomentsController.cs index 7ea92ccf8c5b48f235457c8418fc6473c2c6bb00..d1647c47625d733c78da923a46ea2b13881b5ec4 100644 --- a/ZR.Admin.WebApi/Controllers/Article/MonentController.cs +++ b/ZR.Admin.WebApi/Controllers/Article/MomentsController.cs @@ -1,25 +1,30 @@ using Microsoft.AspNetCore.Mvc; using ZR.Admin.WebApi.Filters; -using ZR.Model.System; -using ZR.Model.System.Dto; -using ZR.ServiceCore.Model.Enums; +using ZR.Model.Content; +using ZR.Model.Dto; +using ZR.Model.Enum; +using ZR.Service.Content.IService; namespace ZR.Admin.WebApi.Controllers { [Verify] - [Route("monent")] - public class MonentController : BaseController + [Route("moment")] + [ApiExplorerSettings(GroupName = "article")] + public class MomentsController : BaseController { /// /// 动态接口 /// private readonly IArticleService _ArticleService; - private readonly IArticleCategoryService _ArticleCategoryService; - public MonentController(IArticleService ArticleService, IArticleCategoryService articleCategoryService) + /// + /// + /// + /// + public MomentsController( + IArticleService ArticleService) { _ArticleService = ArticleService; - _ArticleCategoryService = articleCategoryService; } /// @@ -40,96 +45,39 @@ namespace ZR.Admin.WebApi.Controllers /// 查询动态列表 /// /// - [HttpGet("monentList")] + [HttpGet("momentList")] [AllowAnonymous] public IActionResult QueryMonentList([FromQuery] ArticleQueryDto parm) { parm.UserId = HttpContext.GetUId(); parm.ArticleType = 2; - var response = _ArticleService.GetArticleList(parm); - - return SUCCESS(response); - } - - /// - /// 置顶 - /// - /// - [HttpPut("top")] - [Log(Title = "置顶动态", BusinessType = BusinessType.UPDATE)] - public IActionResult Top([FromBody] Article parm) - { - var response = _ArticleService.TopArticle(parm); - - return SUCCESS(response); - } - - /// - /// 修改可见范围 - /// - /// - [HttpPut("changePublic")] - [Log(Title = "是否公开", BusinessType = BusinessType.UPDATE)] - public IActionResult ChangePublic([FromBody] Article parm) - { - var response = _ArticleService.ChangeArticlePublic(parm); - - return SUCCESS(response); + if (parm.TabId == 100) + { + return SUCCESS(_ArticleService.GetFollowMonentList(parm)); + } + return SUCCESS(_ArticleService.GetMonentList(parm)); } /// /// 动态发布 /// /// - [HttpPost("publishMonent")] - [Log(Title = "动态发布", BusinessType = BusinessType.INSERT)] - public IActionResult PublishMonent([FromBody] ArticleDto parm) + [HttpPost("publishMoment")] + [ActionPermissionFilter(Permission = "common")] + public IActionResult PublishMoment([FromBody] ArticleDto parm) { + if (parm == null) { return ToResponse(ResultCode.PARAM_ERROR); } var addModel = parm.Adapt
().ToCreate(context: HttpContext); - addModel.AuthorName = HttpContext.GetName(); - addModel.UserId = HttpContext.GetUId(); - addModel.ArticleType = ArticleTypeEnum.Monent; - addModel.UserIP = HttpContext.GetClientUserIp(); + addModel.Tags = parm.TopicName; - string location = HttpContextExtension.GetIpInfo(addModel.UserIP); - addModel.Location = location; - return SUCCESS(_ArticleService.InsertReturnIdentity(addModel)); - } - - /// - /// 删除动态 - /// - /// - [HttpDelete("del/{id}")] - [Log(Title = "动态删除", BusinessType = BusinessType.DELETE)] - public IActionResult DeleteMonents(int id = 0) - { - var userId = HttpContext.GetUId(); - var info = _ArticleService.GetId(id); - if (info == null || info.UserId != userId) - { - return ToResponse(ResultCode.CUSTOM_ERROR, "删除失败(-1)"); - } - var response = _ArticleService.Delete(id); - return SUCCESS(response); - } - - /// - /// 点赞动态 - /// - /// - [HttpPost("praise/{id}")] - public IActionResult PraiseMonents(int id = 0) - { - var response = _ArticleService.PraiseArticle(id); - return SUCCESS(response); + return SUCCESS(_ArticleService.PublishMonent(addModel)); } /// /// 动态信息 /// /// - [HttpDelete("getInfo")] + [HttpGet("getInfo")] public IActionResult GetInfo() { var userId = HttpContext.GetUId(); diff --git a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs index 3fdd901f7b83f0adea5a60f1bea284e6b3e54ffe..5ea32ff89e6ec47179d889f24267a52d4a1f3fe2 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysLoginController.cs @@ -43,7 +43,6 @@ namespace ZR.Admin.WebApi.Controllers.System roleService = sysRoleService; } - /// /// 登录 /// @@ -261,37 +260,49 @@ namespace ZR.Admin.WebApi.Controllers.System ///
/// /// - [HttpPost("checkMobile")] + [HttpPost("/checkMobile")] [Log(Title = "发送短息", BusinessType = BusinessType.INSERT)] public IActionResult CheckMobile([FromBody] PhoneLoginDto dto) { dto.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext); - - SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff"); - if (sysConfig?.ConfigValue != "off" && !SecurityCodeHelper.Validate(dto.Uuid, dto.Code, false)) + var uid = HttpContext.GetUId(); + //SysConfig sysConfig = sysConfigService.GetSysConfigByKey("sys.account.captchaOnOff"); + //if (!SecurityCodeHelper.Validate(dto.Uuid, dto.Code, false)) + //{ + // return ToResponse(ResultCode.CUSTOM_ERROR, "验证码错误"); + //} + if (dto.SendType == 0) + { + var info = sysUserService.GetFirst(f => f.Phonenumber == dto.PhoneNum) ?? throw new CustomException(ResultCode.CUSTOM_ERROR, "该手机号不存在", false); + uid = info.UserId; + } + if (dto.SendType == 1) { - return ToResponse(ResultCode.CUSTOM_ERROR, "验证码错误"); + if (sysUserService.CheckPhoneBind(dto.PhoneNum).Count > 0) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "手机号已绑定其他账号"); + } } + string location = HttpContextExtension.GetIpInfo(dto.LoginIP); - var info = sysUserService.GetFirst(f => f.Phonenumber == dto.PhoneNum) ?? throw new CustomException(ResultCode.CUSTOM_ERROR, "该手机号不存在", false); var smsCode = RandomHelper.GenerateNum(6); - var smsContent = $"验证码{smsCode}(随机验证码),有效期10分钟。"; + var smsContent = $"验证码{smsCode},有效期10分钟。"; //TODO 发送短息验证码,1分钟内允许一次 smsCodeLogService.AddSmscodeLog(new ServiceCore.Model.SmsCodeLog() { - Userid = info.UserId, + Userid = uid, PhoneNum = dto.PhoneNum.ParseToLong(), - AddTime = DateTime.Now, - SendType = 1, + SendType = dto.SendType, SmsCode = smsCode, SmsContent = smsContent, UserIP = dto.LoginIP, Location = location, }); + CacheService.SetPhoneCode(dto.PhoneNum, smsCode); - return SUCCESS(new { smsCode }); + return SUCCESS(1); } /// @@ -324,5 +335,27 @@ namespace ZR.Admin.WebApi.Controllers.System CacheService.SetUserPerms(GlobalConstant.UserPermKEY + user.UserId, permissions); return SUCCESS(JwtUtil.GenerateJwtToken(JwtUtil.AddClaims(loginUser))); } + + /// + /// 手机号绑定 + /// + /// + /// + [Route("/PhoneBind")] + [HttpPost] + [Log(Title = "手机号绑定")] + public IActionResult PhoneBind([FromBody] PhoneLoginDto loginBody) + { + if (loginBody == null) { throw new CustomException("请求参数错误"); } + loginBody.LoginIP = HttpContextExtension.GetClientUserIp(HttpContext); + var uid = HttpContext.GetUId(); + if (!CacheService.CheckPhoneCode(loginBody.PhoneNum, loginBody.PhoneCode)) + { + return ToResponse(ResultCode.CUSTOM_ERROR, "短信验证码错误"); + } + var result = sysUserService.ChangePhoneNum(uid, loginBody.PhoneNum); + + return SUCCESS(result); + } } } diff --git a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs index 22349dec2a22e22802e69307266ba97b8e65443a..097124addf87cfe1aa1a7b5e34336766bcecf5b0 100644 --- a/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs +++ b/ZR.Admin.WebApi/Controllers/System/SysMenuController.cs @@ -185,6 +185,20 @@ namespace ZR.Admin.WebApi.Controllers.System return ToResponse(result); } + /// + /// 菜单删除 + /// + /// + /// + [HttpDelete("deleteAll/{menuId}")] + [Log(Title = "菜单管理", BusinessType = BusinessType.DELETE)] + [ActionPermissionFilter(Permission = "system:menu:remove")] + public IActionResult RemoveAll(int menuId = 0) + { + int result = sysMenuService.DeleteAllMenuById(menuId); + + return ToResponse(result); + } /// /// 保存排序 diff --git a/ZR.Admin.WebApi/Controllers/System/monitor/UserOnlineLogController.cs b/ZR.Admin.WebApi/Controllers/System/monitor/UserOnlineLogController.cs index 1a0bce424df6e9d7fed0240d7e4e496c3d7cead9..49962e6786d88b4b70616a0eed549c2f0fd50038 100644 --- a/ZR.Admin.WebApi/Controllers/System/monitor/UserOnlineLogController.cs +++ b/ZR.Admin.WebApi/Controllers/System/monitor/UserOnlineLogController.cs @@ -10,6 +10,7 @@ namespace ZR.Admin.WebApi.Controllers /// 用户在线时长 /// [Verify] + [ApiExplorerSettings(GroupName = "sys")] [Route("monitor/UserOnlineLog")] public class UserOnlineLogController : BaseController { diff --git a/ZR.Admin.WebApi/iprate.json b/ZR.Admin.WebApi/iprate.json index 7269065d863c76655469205dbacaacb70608b7c3..ce41fb9e8faff4bbad52e26dfd9620bc205166fb 100644 --- a/ZR.Admin.WebApi/iprate.json +++ b/ZR.Admin.WebApi/iprate.json @@ -20,6 +20,12 @@ "Period": "3s", "Limit": 5 }, + { + "Endpoint": "*:/checkMobile", + //时间段,格式:{数字}{单位};可使用单位:s, m, h, d + "Period": "60s", + "Limit": 1 + }, { "Endpoint": "((post)|(put)):*", "Period": "3s", diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/api.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/api.txt index 30f869c275bdae229a12c85c8fe71a7690ded2a0..93217fcd9adb0d33badf760f98d2f83ab5b7047e 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/api.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/api.txt @@ -60,19 +60,4 @@ export function del${genTable.BusinessName}(pid) { method: 'delete' }) } -$end -$if(replaceDto.ShowBtnTruncate) -// 清空${genTable.functionName} -export function clear${genTable.BusinessName}() { - return request({ - url: '/${genTable.ModuleName}/${genTable.BusinessName}/clean', - method: 'delete' - }) -} -$end -$if(replaceDto.ShowBtnExport) -// 导出${genTable.functionName} -export async function export${genTable.BusinessName}(query) { - await downFile('/${genTable.ModuleName}/${genTable.BusinessName}/export', { ...query }) -} $end \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/form.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/form.txt index 429ae1525fd50fe8d65c56f2648d484b49089f30..da88a3c96a7d885bc89948a8ee83d3c03957071f 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/form.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/app/form.txt @@ -1,5 +1,6 @@