SupplyDemandCateValidate.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. 'pid'=>'require|checkPid',
  31. ];
  32. protected $message = [
  33. 'id.require' => '供需分类id不能为空',
  34. 'name.require' => '请输入分类名称',
  35. 'status.require' => '状态必传',
  36. 'status.in' => '状态参数规则错误',
  37. 'pid.require' => '请父级分类必传',
  38. ];
  39. /**
  40. * @notes 列表
  41. * @return ArticleCateValidate
  42. * @author heshihu
  43. * @date 2022/2/10 15:11
  44. */
  45. public function scenesupplyDemandCate()
  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|checkCateInfo');
  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 sceneEdit()
  77. {
  78. return $this
  79. ->remove('type', 'require');
  80. }
  81. /**
  82. * @notes 获取所有农耕分类场景
  83. * @return ArticleCateValidate
  84. * @author heshihu
  85. * @date 2022/2/15 10:05
  86. */
  87. public function sceneStatus()
  88. {
  89. return $this->only(['id','status']);
  90. }
  91. /**
  92. * @notes 删除场景
  93. * @return ArticleCateValidate
  94. * @author heshihu
  95. * @date 2022/2/21 17:52
  96. */
  97. public function sceneDelete()
  98. {
  99. return $this->only(['id'])
  100. ->append('id', 'checkCateInfo');
  101. }
  102. /**
  103. * @notes 检查指定服务信息是否存在
  104. * @param $value
  105. * @return bool|string
  106. * @author heshihu
  107. * @date 2022/2/10 15:10
  108. */
  109. public function checkName($value){
  110. $category = SupplyDemandCate::where(['name'=>$value])->findOrEmpty();
  111. if (!$category->isEmpty()) {
  112. return '已存在改分类名称';
  113. }
  114. return true;
  115. }
  116. public function checkPid($value)
  117. {
  118. if($value == 0) return true;
  119. $category = SupplyDemandCate::findOrEmpty($value);
  120. if ($category->isEmpty()) {
  121. return '父级分类不存在';
  122. }
  123. return true;
  124. }
  125. public function checkUserInfo($value,$data)
  126. {
  127. $category = User::findOrEmpty($value);
  128. if ($category->isEmpty()) {
  129. return '用户信息不存在';
  130. }
  131. return true;
  132. }
  133. public function checkCateInfo($value)
  134. {
  135. $category = SupplyDemandCate::findOrEmpty($value);
  136. if ($category->isEmpty()) {
  137. return '分类不存在';
  138. }
  139. return true;
  140. }
  141. }