AgriculturalMachineryServiceCategoryValidate.php 4.1 KB

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