AgriculturalMachineryServiceCategoryValidate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. }
  60. /**
  61. * @notes 详情场景
  62. * @return ArticleCateValidate
  63. * @author heshihu
  64. * @date 2022/2/21 17:55
  65. */
  66. public function sceneDetail()
  67. {
  68. return $this->only(['id']);
  69. }
  70. /**
  71. * @notes 更改状态场景
  72. * @return ArticleCateValidate
  73. * @author heshihu
  74. * @date 2022/2/21 18:02
  75. */
  76. public function sceneStatus()
  77. {
  78. return $this->only(['id', 'status']);
  79. }
  80. public function sceneEdit()
  81. {
  82. return $this
  83. ->remove('type', 'require');
  84. }
  85. /**
  86. * @notes 获取所有农耕分类场景
  87. * @return ArticleCateValidate
  88. * @author heshihu
  89. * @date 2022/2/15 10:05
  90. */
  91. public function sceneSelect()
  92. {
  93. // return $this->only(['type']);
  94. }
  95. /**
  96. * @notes 删除场景
  97. * @return ArticleCateValidate
  98. * @author heshihu
  99. * @date 2022/2/21 17:52
  100. */
  101. public function sceneDelete()
  102. {
  103. return $this->only(['id'])
  104. ->append('id', 'checkDeleteArticleCate');
  105. }
  106. /**
  107. * @notes 检查指定农耕分类是否存在
  108. * @param $value
  109. * @return bool|string
  110. * @author heshihu
  111. * @date 2022/2/10 15:10
  112. */
  113. public function checkMachineryCate($value)
  114. {
  115. $category = AgriculturalMachineryServiceCategory::findOrEmpty($value);
  116. if ($category->isEmpty()) {
  117. return '农耕分类不存在';
  118. }
  119. return true;
  120. }
  121. /**
  122. * @notes 删除时验证农耕分类是否已使用
  123. * @param $value
  124. * @return bool|string
  125. * @author heshihu
  126. * @date 2022/2/22 14:45
  127. */
  128. public function checkDeleteArticleCate($value)
  129. {
  130. // $article = Article::where('cid', $value)->findOrEmpty();
  131. // if (!$article->isEmpty()) {
  132. // return '农耕分类已使用,请先删除绑定该农耕分类的农耕服务';
  133. // }
  134. return true;
  135. }
  136. }