|
|
@@ -0,0 +1,160 @@
|
|
|
+<?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',
|
|
|
+ 'type' =>'requireIf:type,1|in:1,2',
|
|
|
+ 'pid'=>'require|checkPid',
|
|
|
+ ];
|
|
|
+
|
|
|
+ protected $message = [
|
|
|
+ 'id.require' => '供需分类id不能为空',
|
|
|
+ 'name.require' => '请输入分类名称',
|
|
|
+ 'type.require' => '类型不能为空',
|
|
|
+ 'type.in' => '类型值type参数规则错误',
|
|
|
+ '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::findOrEmpty($value);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|