ArticleCateLogic.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\logic\article;
  15. use app\common\enum\YesNoEnum;
  16. use app\common\logic\BaseLogic;
  17. use app\common\model\article\ArticleCate;
  18. /**
  19. * 资讯分类管理逻辑
  20. * Class ArticleCateLogic
  21. * @package app\adminapi\logic\article
  22. */
  23. class ArticleCateLogic extends BaseLogic
  24. {
  25. /**
  26. * @notes 添加资讯分类
  27. * @param array $params
  28. * @author heshihu
  29. * @date 2022/2/18 10:17
  30. */
  31. public static function add(array $params)
  32. {
  33. ArticleCate::create([
  34. 'name' => $params['name'],
  35. 'is_show' => $params['is_show'],
  36. 'sort' => $params['sort'] ?? 0
  37. ]);
  38. }
  39. /**
  40. * @notes 编辑资讯分类
  41. * @param array $params
  42. * @return bool
  43. * @author heshihu
  44. * @date 2022/2/21 17:50
  45. */
  46. public static function edit(array $params) : bool
  47. {
  48. try {
  49. ArticleCate::update([
  50. 'id' => $params['id'],
  51. 'name' => $params['name'],
  52. 'is_show' => $params['is_show'],
  53. 'sort' => $params['sort'] ?? 0
  54. ]);
  55. return true;
  56. } catch (\Exception $e) {
  57. self::setError($e->getMessage());
  58. return false;
  59. }
  60. }
  61. /**
  62. * @notes 删除资讯分类
  63. * @param array $params
  64. * @author heshihu
  65. * @date 2022/2/21 17:52
  66. */
  67. public static function delete(array $params)
  68. {
  69. ArticleCate::destroy($params['id']);
  70. }
  71. /**
  72. * @notes 查看资讯分类详情
  73. * @param $params
  74. * @return array
  75. * @author heshihu
  76. * @date 2022/2/21 17:54
  77. */
  78. public static function detail($params) : array
  79. {
  80. return ArticleCate::findOrEmpty($params['id'])->toArray();
  81. }
  82. /**
  83. * @notes 更改资讯分类状态
  84. * @param array $params
  85. * @return bool
  86. * @author heshihu
  87. * @date 2022/2/21 18:04
  88. */
  89. public static function updateStatus(array $params)
  90. {
  91. ArticleCate::update([
  92. 'id' => $params['id'],
  93. 'is_show' => $params['is_show']
  94. ]);
  95. return true;
  96. }
  97. /**
  98. * @notes 文章分类数据
  99. * @return array
  100. * @throws \think\db\exception\DataNotFoundException
  101. * @throws \think\db\exception\DbException
  102. * @throws \think\db\exception\ModelNotFoundException
  103. * @author 段誉
  104. * @date 2022/10/13 10:53
  105. */
  106. public static function getAllData()
  107. {
  108. return ArticleCate::where(['is_show' => YesNoEnum::YES])
  109. ->order(['sort' => 'desc', 'id' => 'desc'])
  110. ->select()
  111. ->toArray();
  112. }
  113. }