moonsflyer 5 месяцев назад
Родитель
Сommit
b70e2d404a
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      app/adminapi/validate/info/InfoCategoryValidate.php

+ 11 - 1
app/adminapi/validate/info/InfoCategoryValidate.php

@@ -25,7 +25,7 @@ use app\common\validate\BaseValidate;
 class InfoCategoryValidate extends BaseValidate
 {
     protected $rule = [
-        'id' => 'require',
+        'id' => 'require|checkId',
         'type' => 'require|in:1,2,3,4,5,6,7,8',
         'name' => 'require|checkName',
         'is_show' => 'in:0,1',
@@ -87,4 +87,14 @@ class InfoCategoryValidate extends BaseValidate
         }
         return true;
     }
+
+    public function checkId($value,$rule,$data){
+        $where[] = ['id', '=', $value];
+
+        $result = InfoCategory::where($where)->find();
+        if (!$result) {
+            return '该分类不存在!';
+        }
+        return true;
+    }
 }