AgriculturalMachineryServiceCategoryValidate.php 3.7 KB

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