ArticleValidate.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\Article;
  17. /**
  18. * 资讯管理验证
  19. * Class ArticleValidate
  20. * @package app\adminapi\validate\article
  21. */
  22. class ArticleValidate extends BaseValidate
  23. {
  24. protected $rule = [
  25. 'id' => 'require|checkArticle',
  26. 'title' => 'require|length:1,255',
  27. // 'image' => 'require',
  28. 'cid' => 'require',
  29. 'is_show' => 'require|in:0,1',
  30. ];
  31. protected $message = [
  32. 'id.require' => '资讯id不能为空',
  33. 'title.require' => '标题不能为空',
  34. 'title.length' => '标题长度须在1-255位字符',
  35. // 'image.require' => '封面图必须存在',
  36. 'cid.require' => '所属栏目必须存在',
  37. ];
  38. /**
  39. * @notes 添加场景
  40. * @return ArticleValidate
  41. * @author heshihu
  42. * @date 2022/2/22 9:57
  43. */
  44. public function sceneAdd()
  45. {
  46. return $this->remove(['id'])
  47. ->remove('id','require|checkArticle');
  48. }
  49. /**
  50. * @notes 详情场景
  51. * @return ArticleValidate
  52. * @author heshihu
  53. * @date 2022/2/22 10:15
  54. */
  55. public function sceneDetail()
  56. {
  57. return $this->only(['id']);
  58. }
  59. /**
  60. * @notes 更改状态场景
  61. * @return ArticleValidate
  62. * @author heshihu
  63. * @date 2022/2/22 10:18
  64. */
  65. public function sceneStatus()
  66. {
  67. return $this->only(['id', 'is_show']);
  68. }
  69. public function sceneEdit()
  70. {
  71. }
  72. /**
  73. * @notes 删除场景
  74. * @return ArticleValidate
  75. * @author heshihu
  76. * @date 2022/2/22 10:17
  77. */
  78. public function sceneDelete()
  79. {
  80. return $this->only(['id']);
  81. }
  82. /**
  83. * @notes 检查指定资讯是否存在
  84. * @param $value
  85. * @return bool|string
  86. * @author heshihu
  87. * @date 2022/2/22 10:11
  88. */
  89. public function checkArticle($value)
  90. {
  91. $article = Article::findOrEmpty($value);
  92. if ($article->isEmpty()) {
  93. return '资讯不存在';
  94. }
  95. return true;
  96. }
  97. }