CategoryController.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using Infrastructure.Model;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Mvc;
  4. using ZR.Common;
  5. using ZR.Mall.Model;
  6. using ZR.Mall.Model.Dto;
  7. using ZR.Mall.Service.IService;
  8. namespace ZR.Mall.Controllers
  9. {
  10. /// <summary>
  11. /// 商品分类Controller
  12. /// </summary>
  13. [Route("shopping/category")]
  14. [ApiExplorerSettings(GroupName = "shopping")]
  15. public class CategoryController : BaseController
  16. {
  17. /// <summary>
  18. /// 商品分类接口
  19. /// </summary>
  20. private readonly ICategoryService _categoryService;
  21. public CategoryController(ICategoryService categoryService)
  22. {
  23. _categoryService = categoryService;
  24. }
  25. /// <summary>
  26. /// 查询商品分类列表
  27. /// </summary>
  28. /// <param name="parm"></param>
  29. /// <returns></returns>
  30. [HttpGet("list")]
  31. [ActionPermissionFilter(Permission = "shop:category:list")]
  32. public IActionResult QueryCategory([FromQuery] ShoppingCategoryQueryDto parm)
  33. {
  34. var response = _categoryService.GetList(parm);
  35. return SUCCESS(response);
  36. }
  37. /// <summary>
  38. /// 查询商品分类列表树
  39. /// </summary>
  40. /// <param name="parm"></param>
  41. /// <returns></returns>
  42. [HttpGet("treeList")]
  43. //[AllowAnonymous]
  44. public IActionResult QueryTreeCategory([FromQuery] ShoppingCategoryQueryDto parm)
  45. {
  46. var response = _categoryService.GetTreeList(parm);
  47. return SUCCESS(response);
  48. }
  49. /// <summary>
  50. /// 查询详情
  51. /// </summary>
  52. /// <param name="CategoryId"></param>
  53. /// <returns></returns>
  54. [HttpGet("{CategoryId}")]
  55. [AllowAnonymous]
  56. public IActionResult GetCategory(int CategoryId)
  57. {
  58. var response = _categoryService.GetFirst(x => x.CategoryId == CategoryId);
  59. return SUCCESS(response);
  60. }
  61. /// <summary>
  62. /// 添加商城目录
  63. /// </summary>
  64. /// <returns></returns>
  65. [HttpPost]
  66. [ActionPermissionFilter(Permission = "shop:category:add")]
  67. [Log(Title = "商城分类", BusinessType = BusinessType.INSERT)]
  68. public IActionResult AddCategory([FromBody] CategoryDto parm)
  69. {
  70. var modal = parm.Adapt<Category>().ToCreate(HttpContext);
  71. var response = _categoryService.AddCategory(modal);
  72. return ToResponse(response);
  73. }
  74. /// <summary>
  75. /// 更新商城分类
  76. /// </summary>
  77. /// <returns></returns>
  78. [HttpPut]
  79. [ActionPermissionFilter(Permission = "shop:category:edit")]
  80. [Log(Title = "商城分类", BusinessType = BusinessType.UPDATE)]
  81. public IActionResult UpdateShoppingCategory([FromBody] CategoryDto parm)
  82. {
  83. var modal = parm.Adapt<Category>().ToUpdate(HttpContext);
  84. var response = _categoryService.Update(modal);
  85. return ToResponse(response);
  86. }
  87. /// <summary>
  88. /// 删除商城分类
  89. /// </summary>
  90. /// <returns></returns>
  91. [HttpDelete("{ids}")]
  92. [ActionPermissionFilter(Permission = "shop:category:delete")]
  93. [Log(Title = "商城分类", BusinessType = BusinessType.DELETE)]
  94. public IActionResult DeleteCategory(string ids)
  95. {
  96. int[] idsArr = Tools.SpitIntArrary(ids);
  97. if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
  98. var response = _categoryService.Delete(idsArr);
  99. return ToResponse(response);
  100. }
  101. /// <summary>
  102. /// 导出目录
  103. /// </summary>
  104. /// <returns></returns>
  105. [Log(Title = "商城分类", BusinessType = BusinessType.EXPORT, IsSaveResponseData = false)]
  106. [HttpGet("export")]
  107. [ActionPermissionFilter(Permission = "shop:category:export")]
  108. public IActionResult Export([FromQuery] ShoppingCategoryQueryDto parm)
  109. {
  110. parm.PageNum = 1;
  111. parm.PageSize = 100000;
  112. var list = _categoryService.ExportList(parm).Result;
  113. if (list == null || list.Count <= 0)
  114. {
  115. return ToResponse(ResultCode.FAIL, "没有要导出的数据");
  116. }
  117. var result = ExportExcelMini(list, "商品分类", "商品分类");
  118. return ExportExcel(result.Item2, result.Item1);
  119. }
  120. /// <summary>
  121. /// 获取目录
  122. /// </summary>
  123. /// <returns></returns>
  124. [HttpGet("CategoryList")]
  125. public IActionResult CategoryList()
  126. {
  127. var response = _categoryService.GetAll();
  128. return SUCCESS(response);
  129. }
  130. /// <summary>
  131. /// 保存排序
  132. /// </summary>
  133. /// <param name="id"></param>
  134. /// <param name="value"></param>
  135. /// <returns></returns>
  136. [ActionPermissionFilter(Permission = "shop:category:edit")]
  137. [HttpGet("ChangeSort")]
  138. [Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)]
  139. public IActionResult ChangeSort(int id = 0, int value = 0)
  140. {
  141. if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); }
  142. var response = _categoryService.Update(w => w.CategoryId == id, it => new Category()
  143. {
  144. CategoryId = id,
  145. OrderNum = value
  146. });
  147. return ToResponse(response);
  148. }
  149. }
  150. }