ArticleCateValidate.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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\validate\article;
  15. use app\common\validate\BaseValidate;
  16. use app\common\model\article\ArticleCate;
  17. use app\common\model\article\Article;
  18. /**
  19. * 资讯分类管理验证
  20. * Class ArticleCateValidate
  21. * @package app\adminapi\validate\article
  22. */
  23. class ArticleCateValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'id' => 'require|checkArticleCate',
  27. 'name' => 'require|length:1,90',
  28. 'is_show' => 'require|in:0,1',
  29. 'sort' => 'egt:0',
  30. ];
  31. protected $message = [
  32. 'id.require' => '资讯分类id不能为空',
  33. 'name.require' => '资讯分类不能为空',
  34. 'name.length' => '资讯分类长度须在1-90位字符',
  35. 'sort.egt' => '排序值不正确',
  36. ];
  37. /**
  38. * @notes 添加场景
  39. * @return ArticleCateValidate
  40. * @author heshihu
  41. * @date 2022/2/10 15:11
  42. */
  43. public function sceneAdd()
  44. {
  45. return $this->remove(['id'])
  46. ->remove('id', 'require|checkArticleCate');
  47. }
  48. /**
  49. * @notes 详情场景
  50. * @return ArticleCateValidate
  51. * @author heshihu
  52. * @date 2022/2/21 17:55
  53. */
  54. public function sceneDetail()
  55. {
  56. return $this->only(['id']);
  57. }
  58. /**
  59. * @notes 更改状态场景
  60. * @return ArticleCateValidate
  61. * @author heshihu
  62. * @date 2022/2/21 18:02
  63. */
  64. public function sceneStatus()
  65. {
  66. return $this->only(['id', 'is_show']);
  67. }
  68. public function sceneEdit()
  69. {
  70. }
  71. /**
  72. * @notes 获取所有资讯分类场景
  73. * @return ArticleCateValidate
  74. * @author heshihu
  75. * @date 2022/2/15 10:05
  76. */
  77. public function sceneSelect()
  78. {
  79. return $this->only(['type']);
  80. }
  81. /**
  82. * @notes 删除场景
  83. * @return ArticleCateValidate
  84. * @author heshihu
  85. * @date 2022/2/21 17:52
  86. */
  87. public function sceneDelete()
  88. {
  89. return $this->only(['id'])
  90. ->append('id', 'checkDeleteArticleCate');
  91. }
  92. /**
  93. * @notes 检查指定资讯分类是否存在
  94. * @param $value
  95. * @return bool|string
  96. * @author heshihu
  97. * @date 2022/2/10 15:10
  98. */
  99. public function checkArticleCate($value)
  100. {
  101. $article_category = ArticleCate::findOrEmpty($value);
  102. if ($article_category->isEmpty()) {
  103. return '资讯分类不存在';
  104. }
  105. return true;
  106. }
  107. /**
  108. * @notes 删除时验证该资讯分类是否已使用
  109. * @param $value
  110. * @return bool|string
  111. * @author heshihu
  112. * @date 2022/2/22 14:45
  113. */
  114. public function checkDeleteArticleCate($value)
  115. {
  116. $article = Article::where('cid', $value)->findOrEmpty();
  117. if (!$article->isEmpty()) {
  118. return '资讯分类已使用,请先删除绑定该资讯分类的资讯';
  119. }
  120. return true;
  121. }
  122. }