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\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. 'type' =>'require|in:1,2,3',
  32. ];
  33. protected $message = [
  34. 'id.require' => ' 分类id不能为空',
  35. 'name.require' => '分类名称不能为空',
  36. 'name.length' => '分类长度须在1-60位字符',
  37. 'sort.egt' => '排序值不正确',
  38. 'type.require' => '类型不能为空',
  39. 'type.in' => '类型值type参数规则错误',
  40. ];
  41. /**
  42. * @notes 列表
  43. * @return ArticleCateValidate
  44. * @author heshihu
  45. * @date 2022/2/10 15:11
  46. */
  47. public function sceneList()
  48. {
  49. return $this->only(['type']);
  50. }
  51. /**
  52. * @notes 添加场景
  53. * @return ArticleCateValidate
  54. * @author heshihu
  55. * @date 2022/2/10 15:11
  56. */
  57. public function sceneAdd()
  58. {
  59. return $this->remove(['id'])
  60. ->remove('id', 'require|checkMachineryCate');
  61. }
  62. /**
  63. * @notes 详情场景
  64. * @return ArticleCateValidate
  65. * @author heshihu
  66. * @date 2022/2/21 17:55
  67. */
  68. public function sceneDetail()
  69. {
  70. return $this->only(['id']);
  71. }
  72. /**
  73. * @notes 更改状态场景
  74. * @return ArticleCateValidate
  75. * @author heshihu
  76. * @date 2022/2/21 18:02
  77. */
  78. public function sceneStatus()
  79. {
  80. return $this->only(['id', 'status']);
  81. }
  82. public function sceneEdit()
  83. {
  84. return $this
  85. ->remove('type', '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. }