SupplyDemandCateValidate.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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\supply_demand\SupplyDemandInfo;
  17. use app\common\model\supply_demand\SupplyDemandCate;
  18. use app\common\model\user\User;
  19. /**
  20. * 供需分类验证
  21. * Class ArticleCateValidate
  22. * @package app\adminapi\validate\article
  23. */
  24. class SupplyDemandCateValidate extends BaseValidate
  25. {
  26. protected $rule = [
  27. 'id' => 'require|checkCateInfo',
  28. 'name' => 'require|checkName',
  29. 'status' => 'requireIf:status,0|in:0,1',
  30. 'type' =>'requireIf:type,1|in:1,2',
  31. 'pid'=>'require|checkPid',
  32. ];
  33. protected $message = [
  34. 'id.require' => '供需分类id不能为空',
  35. 'name.require' => '请输入分类名称',
  36. 'type.require' => '类型不能为空',
  37. 'type.in' => '类型值type参数规则错误',
  38. 'status.require' => '状态必传',
  39. 'status.in' => '状态参数规则错误',
  40. 'pid.require' => '请父级分类必传',
  41. ];
  42. /**
  43. * @notes 列表
  44. * @return ArticleCateValidate
  45. * @author heshihu
  46. * @date 2022/2/10 15:11
  47. */
  48. public function scenesupplyDemandCate()
  49. {
  50. return $this->only(['type']);
  51. }
  52. /**
  53. * @notes 添加场景
  54. * @return ArticleCateValidate
  55. * @author heshihu
  56. * @date 2022/2/10 15:11
  57. */
  58. public function sceneAdd()
  59. {
  60. return $this->remove(['id'])
  61. ->remove('id', 'require|checkCateInfo');
  62. }
  63. /**
  64. * @notes 详情场景
  65. * @return ArticleCateValidate
  66. * @author heshihu
  67. * @date 2022/2/21 17:55
  68. */
  69. public function sceneDetail()
  70. {
  71. return $this->only(['id']);
  72. }
  73. /**
  74. * @notes 更改状态场景
  75. * @return ArticleCateValidate
  76. * @author heshihu
  77. * @date 2022/2/21 18:02
  78. */
  79. public function sceneEdit()
  80. {
  81. return $this
  82. ->remove('type', 'require');
  83. }
  84. /**
  85. * @notes 获取所有农耕分类场景
  86. * @return ArticleCateValidate
  87. * @author heshihu
  88. * @date 2022/2/15 10:05
  89. */
  90. public function sceneStatus()
  91. {
  92. return $this->only(['id','status']);
  93. }
  94. /**
  95. * @notes 删除场景
  96. * @return ArticleCateValidate
  97. * @author heshihu
  98. * @date 2022/2/21 17:52
  99. */
  100. public function sceneDelete()
  101. {
  102. return $this->only(['id'])
  103. ->append('id', 'checkCateInfo');
  104. }
  105. /**
  106. * @notes 检查指定服务信息是否存在
  107. * @param $value
  108. * @return bool|string
  109. * @author heshihu
  110. * @date 2022/2/10 15:10
  111. */
  112. public function checkName($value){
  113. $category = SupplyDemandCate::findOrEmpty($value);
  114. if (!$category->isEmpty()) {
  115. return '已存在改分类名称';
  116. }
  117. return true;
  118. }
  119. public function checkPid($value)
  120. {
  121. if($value == 0) return true;
  122. $category = SupplyDemandCate::findOrEmpty($value);
  123. if ($category->isEmpty()) {
  124. return '父级分类不存在';
  125. }
  126. return true;
  127. }
  128. public function checkUserInfo($value,$data)
  129. {
  130. $category = User::findOrEmpty($value);
  131. if ($category->isEmpty()) {
  132. return '用户信息不存在';
  133. }
  134. return true;
  135. }
  136. public function checkCateInfo($value)
  137. {
  138. $category = SupplyDemandCate::findOrEmpty($value);
  139. if ($category->isEmpty()) {
  140. return '分类不存在';
  141. }
  142. return true;
  143. }
  144. }