SupplyDemandValidate.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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\user\User;
  18. /**
  19. * 供需管理验证
  20. * Class ArticleCateValidate
  21. * @package app\adminapi\validate\article
  22. */
  23. class SupplyDemandValidate extends BaseValidate
  24. {
  25. protected $rule = [
  26. 'id' => 'require|checkUserServiceInfo',
  27. 'user_id' => 'require|checkUserInfo',
  28. 'status' => 'requireIf:status,0|in:0,1,2,3',
  29. 'type' =>'require|in:1,2',
  30. 'mobile' => 'require|mobile',
  31. 'images'=>'require',
  32. ];
  33. protected $message = [
  34. 'id.require' => ' 供需id不能为空',
  35. 'user_id.require' => '请选择用户',
  36. 'type.require' => '类型不能为空',
  37. 'type.in' => '类型值type参数规则错误',
  38. 'mobile.require' => '联系方式参数缺失',
  39. 'mobile.mobile' => '请填写正确的手机号',
  40. 'images.require' => '请输入上传服务图片',
  41. ];
  42. /**
  43. * @notes 列表
  44. * @return ArticleCateValidate
  45. * @author heshihu
  46. * @date 2022/2/10 15:11
  47. */
  48. public function sceneSupplyDemand()
  49. {
  50. return $this->only(['status']);
  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|checkUserServiceInfo');
  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 sceneStatus()
  80. {
  81. return $this->only(['id', 'status'])->append('status', 'checkStatus');;
  82. }
  83. public function sceneEdit()
  84. {
  85. return $this
  86. ->remove('type', 'require');
  87. }
  88. /**
  89. * @notes 获取所有农耕分类场景
  90. * @return ArticleCateValidate
  91. * @author heshihu
  92. * @date 2022/2/15 10:05
  93. */
  94. public function sceneSelect()
  95. {
  96. // return $this->only(['type']);
  97. }
  98. /**
  99. * @notes 删除场景
  100. * @return ArticleCateValidate
  101. * @author heshihu
  102. * @date 2022/2/21 17:52
  103. */
  104. public function sceneDelete()
  105. {
  106. return $this->only(['id'])
  107. ->append('id', 'checkUserServiceInfo');
  108. }
  109. /**
  110. * @notes 检查指定服务信息是否存在
  111. * @param $value
  112. * @return bool|string
  113. * @author heshihu
  114. * @date 2022/2/10 15:10
  115. */
  116. public function checkUserServiceInfo($value)
  117. {
  118. $category = SupplyDemandInfo::findOrEmpty($value);
  119. if ($category->isEmpty()) {
  120. return '供需信息不存在';
  121. }
  122. return true;
  123. }
  124. public function checkUserInfo($value,$data)
  125. {
  126. $category = User::findOrEmpty($value);
  127. if ($category->isEmpty()) {
  128. return '用户信息不存在';
  129. }
  130. return true;
  131. }
  132. public function checkStatus($value){
  133. return true;
  134. }
  135. /**
  136. * @notes 删除时验证农耕分类是否已使用
  137. * @param $value
  138. * @return bool|string
  139. * @author heshihu
  140. * @date 2022/2/22 14:45
  141. */
  142. public function checkDeleteArticleCate($value)
  143. {
  144. // $article = Article::where('cid', $value)->findOrEmpty();
  145. // if (!$article->isEmpty()) {
  146. // return '农耕分类已使用,请先删除绑定该农耕分类的农耕服务';
  147. // }
  148. return true;
  149. }
  150. }