Explorar o código

add getCydList validate

ggsong %!s(int64=3) %!d(string=hai) anos
pai
achega
3d59dab0aa
Modificáronse 2 ficheiros con 34 adicións e 1 borrados
  1. 6 1
      app/api/controller/v1/Cyd.php
  2. 28 0
      app/api/validate/Sample.php

+ 6 - 1
app/api/controller/v1/Cyd.php

@@ -8,13 +8,18 @@
 namespace app\api\controller\v1;
 
 use app\api\business\CydBus;
+use think\exception\ValidateException;
 
 class Cyd
 {
     public function getCydList()
     {
         $task_id = request()->param('task_id', '', 'int');
-        //todo validate
+        try {
+            validate(\app\api\validate\Sample::class)->scene('get_cyd_list')->check($task_id);
+        } catch (ValidateException $exception) {
+            return show(config('status.err_validate'),$exception->getError());
+        }
 
         $result = (new CydBus())->getCydList($task_id);
         if ($result['total'] == 0) {

+ 28 - 0
app/api/validate/Sample.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ *
+ *User:Administrator
+ *Date:2021/10/29
+ */
+
+namespace app\api\validate;
+
+use think\Validate;
+
+class Sample extends Validate
+{
+
+    protected $rule = [
+        'task_id' => 'require|integer',
+
+    ];
+    protected $message = [
+        'task_id.require' => '任务id为空',
+        'task_id.integer' => '任务id错误',
+
+    ];
+
+    protected $scene = [
+        'get_cyd_list' => ['task_id',],
+    ];
+}