| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\validate\agricultural_machinery;
- use app\common\validate\BaseValidate;
- use app\common\model\supply_demand\SupplyDemandInfo;
- use app\common\model\supply_demand\SupplyDemandCate;
- use app\common\model\user\User;
- /**
- * 供需分类验证
- * Class ArticleCateValidate
- * @package app\adminapi\validate\article
- */
- class SupplyDemandCateValidate extends BaseValidate
- {
- protected $rule = [
- 'id' => 'require|checkCateInfo',
- 'name' => 'require|checkName',
- 'status' => 'requireIf:status,0|in:0,1',
- 'pid'=>'require|checkPid',
- ];
- protected $message = [
- 'id.require' => '供需分类id不能为空',
- 'name.require' => '请输入分类名称',
- 'status.require' => '状态必传',
- 'status.in' => '状态参数规则错误',
- 'pid.require' => '请父级分类必传',
- ];
- /**
- * @notes 列表
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/10 15:11
- */
- public function scenesupplyDemandCate()
- {
- return $this->only(['type']);
- }
- /**
- * @notes 添加场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/10 15:11
- */
- public function sceneAdd()
- {
- return $this->remove(['id'])
- ->remove('id', 'require|checkCateInfo');
- }
- /**
- * @notes 详情场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/21 17:55
- */
- public function sceneDetail()
- {
- return $this->only(['id']);
- }
- /**
- * @notes 更改状态场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/21 18:02
- */
- public function sceneEdit()
- {
- return $this
- ->remove('type', 'require');
- }
- /**
- * @notes 获取所有农耕分类场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/15 10:05
- */
- public function sceneStatus()
- {
- return $this->only(['id','status']);
- }
- /**
- * @notes 删除场景
- * @return ArticleCateValidate
- * @author heshihu
- * @date 2022/2/21 17:52
- */
- public function sceneDelete()
- {
- return $this->only(['id'])
- ->append('id', 'checkCateInfo');
- }
- /**
- * @notes 检查指定服务信息是否存在
- * @param $value
- * @return bool|string
- * @author heshihu
- * @date 2022/2/10 15:10
- */
- public function checkName($value){
- $category = SupplyDemandCate::where(['name'=>$value])->findOrEmpty();
- if (!$category->isEmpty()) {
- return '已存在改分类名称';
- }
- return true;
- }
- public function checkPid($value)
- {
- if($value == 0) return true;
- $category = SupplyDemandCate::findOrEmpty($value);
- if ($category->isEmpty()) {
- return '父级分类不存在';
- }
- return true;
- }
- public function checkUserInfo($value,$data)
- {
- $category = User::findOrEmpty($value);
- if ($category->isEmpty()) {
- return '用户信息不存在';
- }
- return true;
- }
- public function checkCateInfo($value)
- {
- $category = SupplyDemandCate::findOrEmpty($value);
- if ($category->isEmpty()) {
- return '分类不存在';
- }
- return true;
- }
- }
|