ArticleValidate.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\validate;
  20. use app\common\model\Article;
  21. use app\common\model\ArticleCategory;
  22. use app\common\validate\BaseValidate;
  23. class ArticleValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'id' => 'require',
  27. 'title' => 'require',
  28. 'cid' => 'require|checkCid',
  29. 'is_show' => 'in:0,1',
  30. ];
  31. protected $message = [
  32. 'title.require' => '标题不能为空',
  33. 'cid.require' => '请选择分类',
  34. 'is_show.in' => '是否显示类型错误',
  35. ];
  36. /**
  37. * @notes 添加文章/帮助场景
  38. * @return ArticleValidate
  39. * @author Tab
  40. * @date 2021/7/22 17:06
  41. */
  42. public function sceneAdd()
  43. {
  44. return $this->remove('id', 'require');
  45. }
  46. /**
  47. * @notes 获取文章/帮助详情场景
  48. * @return ArticleValidate
  49. * @author Tab
  50. * @date 2021/7/22 17:06
  51. */
  52. public function sceneDetail()
  53. {
  54. return $this->only(['id']);
  55. }
  56. /**
  57. * @notes 删除文章/帮助场景
  58. * @return ArticleValidate
  59. * @author Tab
  60. * @date 2021/7/22 17:06
  61. */
  62. public function sceneDelete()
  63. {
  64. return $this->only(['id']);
  65. }
  66. /**
  67. * @notes 文章显示或隐藏场景
  68. * @return ArticleValidate
  69. * @author Tab
  70. * @date 2021/7/22 17:07
  71. */
  72. public function sceneShow()
  73. {
  74. return $this->only(['id']);
  75. }
  76. /**
  77. * @notes 校验文章/帮助分类
  78. * @param $value
  79. * @return bool|string
  80. * @author Tab
  81. * @date 2021/7/22 17:08
  82. */
  83. public function checkCid($value)
  84. {
  85. $articleCategory = ArticleCategory::findOrEmpty($value);
  86. if($articleCategory->isEmpty()) {
  87. return '分类不存在';
  88. }
  89. return true;
  90. }
  91. }