Răsfoiți Sursa

模型删除验证

gbsong 3 ani în urmă
părinte
comite
98210acf74

+ 12 - 20
app/api/business/ChengDanBus.php

@@ -34,7 +34,6 @@ class ChengDanBus
     }
 
 
-
     public function createUnderTakerInfo($data)
     {
         $uid = $this->uid;
@@ -65,26 +64,19 @@ class ChengDanBus
     //查询任务列表数据
     public function selectUndertakerTaskList($task_class,$pageNum,$pageSize,$data)
     {
-        $where=[
-            ['bear_id|check_id|report_id', '=', $this->uid],
+        $where_undertake = [['bear_id|check_id|report_id', '=', $this->uid],];
+        $where = [
+            ['task_class','=',$task_class],
         ];
-        if ($data['year']!='') array_push($where, ['year', '=', $data['year']]);
-        //任务状态:0:未发布,1:执行中,2:已结束未完成,3:已结束已完成
-        if ($data['ispublic'] != '') array_push($where, ['ispublic', '=', $data['ispublic']]);
-        //任务开始时间
-        if ($data['starttime'] != '') array_push($where, ['starttime', '>=', $data['starttime']]);
-        //任务结束时间
-        if ($data['endtime'] != '') array_push($where, ['endtime', '<=', $data['endtime']]);
-        //任务名称:模糊查询
-        if ($data['task_name'] != '' ) array_push($where, ['task_name', 'LIKE', '%'.$data['task_name'].'%']);
-
-
-
-
-        $data = (new Ccjc())->selectUndertakeData($task_class,$where,$pageNum,$pageSize);
-        $count = (new Ccjc())->countUndertakeData($task_class,$where);
-        // $count =(new Undertake())->countCcjcData($where);
-        return ['rows'=>$data,'total'=>$count];
+        if ($data['year']!='') $where[] = ['year', '=', $data['year']];
+        if ($data['ispublic'] != '') $where[] = ['ispublic', '=', $data['ispublic']];       //任务状态:0:未发布,1:执行中,2:已结束未完成,3:已结束已完成
+        if ($data['starttime'] != '') $where[]=['starttime', '>=', $data['starttime']];        //任务开始时间
+        if ($data['endtime'] != '') $where[] = ['endtime', '<=', $data['endtime']];        //任务结束时间
+        if ($data['task_name'] != '' ) $where[] = ['task_name', 'LIKE', '%' . $data['task_name'] . '%'];        //任务名称:模糊查询
+
+        $data = (new Ccjc())->selectUndertakeData($where_undertake,$where,$pageNum,$pageSize);
+        $total = (new Ccjc())->countUndertakeData($where_undertake,$where);
+        return ['rows'=>$data,'total'=>$total];
     }
 
 }

+ 3 - 4
app/api/business/CydBus.php

@@ -81,10 +81,9 @@ class CydBus
 
 
         //根据信息获取抽样单位和检测单位的信息
-        $sample_info = (new Jcdw())->getInfoById($undertaek_info['bear_id']);
-        $check_info = (new Jcdw())->getInfoById($undertaek_info['check_id']);
-        return ['list'=>$result,'sample_info'=>$sample_info,'check_info'=>$check_info];
-//        return $result;
+        $sample_info = (new Jcdw())->getLiteInfoById($undertaek_info['bear_id']);
+
+        return ['list'=>$result,'sample_info'=>$sample_info,];
 
     }
 

+ 5 - 8
app/api/business/SuperviserTaskBus.php → app/api/business/JianGuanBus.php

@@ -1,20 +1,13 @@
 <?php
-/**
- *
- *User:Administrator
- *Date:2021/10/9
- */
 
 namespace app\api\business;
 
 use app\api\exception\ApiException;
 use app\api\model\Ccjc;
-use app\api\model\Jcdw;
 use app\api\model\Orgs;
-use app\common\lib\Arr;
 use app\common\lib\auth\JwtAuth;
 
-class SuperviserTaskBus
+class JianGuanBus
 {
     private $rymc;
     public function __construct()
@@ -46,6 +39,7 @@ class SuperviserTaskBus
         return ['rows'=>$result, 'total'=>$count,];
     }
 
+
     //创建任务
     public function createTask($data,$orgs_data)
     {
@@ -63,6 +57,8 @@ class SuperviserTaskBus
         return $result;
     }
 
+
+
     //删除任务
     public function deleteTaskItem($data,$data_count)
     {
@@ -133,4 +129,5 @@ class SuperviserTaskBus
         $result = (new Ccjc())->updateTaskByArrCondition($data);
         return $result;
     }
+
 }

+ 7 - 0
app/api/business/ModelBus.php

@@ -156,6 +156,13 @@ class ModelBus
         for ($i = 0; $i < $data_count; $i++) {
             //从数据库获取当前模型的user_id        //验证模型创建者是否一致
             $user_id = (new TestModel())->getUserIdByModelID($data[$i]['id'])['user_id'];
+            //查询模型绑定任务,如果绑定则禁止删除
+            $ccjc_info = (new Ccjc())->getTaskInfoByModelId($data[$i]['id']);
+
+            if ( !($ccjc_info==[])) {
+                throw new ApiException(config('status.err_disable_delete'));
+            }
+
             if ($user_id != $this->uid) {
                 throw new ApiException(config('status.none_authority'));
             }

+ 5 - 4
app/api/controller/v1/JianGuan.php

@@ -7,6 +7,7 @@
 
 namespace app\api\controller\v1;
 
+use app\api\business\JianGuanBus;
 use app\api\business\SuperviserTaskBus;
 use app\api\validate\TaskValidate;
 use think\exception\ValidateException;
@@ -35,7 +36,7 @@ class JianGuan
             return showError($exception->getError());
         }
 
-        $res= (new SuperviserTaskBus())->selectTask($data);
+        $res= (new JianGuanBus())->selectTask($data);
         return showSuccess($res);
     }
 
@@ -66,7 +67,7 @@ class JianGuan
             return showError($exception->getError());
         }
 
-        $res= (new SuperviserTaskBus())->createTask($data,$orgs);
+        $res= (new JianGuanBus())->createTask($data,$orgs);
         return showSuccess($res);
     }
 
@@ -81,7 +82,7 @@ class JianGuan
             $data[$k] = ['id' => $v];
             $data_count+=1;
         }
-        $result = (new SuperviserTaskBus())->deleteTaskItem($data,$data_count);
+        $result = (new JianGuanBus())->deleteTaskItem($data,$data_count);
         return showSuccess($result);
     }
 
@@ -102,7 +103,7 @@ class JianGuan
             $data_count+=1;
         }
 
-        $result = (new SuperviserTaskBus())->updateTaskUpdateInfo($data,$data_count);
+        $result = (new JianGuanBus())->updateTaskUpdateInfo($data,$data_count);
         return showSuccess($result);
     }
 

+ 4 - 13
app/api/controller/v1/QianTou.php

@@ -44,14 +44,9 @@ class QianTou
         $data = [
             'pageNum' => request()->param('pageNum', 1, 'int'),
             'pageSize' => request()->param('pageSize',null, 'int'),
-            'task_id' => request()->param('task_id'),
-        ];
-        try {
-            validate(TaskValidate::class)->scene('getTaskInfo')->check($data);
-        } catch (ValidateException $exception) {
-            return showError($exception->getError());
-        }
-
+            'task_id' => request()->param('task_id','','int'),
+            ];
+        //todo validate
         $result = (new QianTouBus())->getTaskInfo($data);
         return showSuccess($result);
     }
@@ -59,11 +54,7 @@ class QianTou
     public function qtRelease()
     {
         $task_id = request()->param('task_id', '', 'int');
-        try {
-            validate(TaskValidate::class)->scene('qtRelease')->check($task_id);
-        } catch (ValidateException $exception) {
-            return showError($exception->getError());
-        }
+
         $result = (new QianTouBus())->releaseTask($task_id);
         return showSuccess($result);
     }

+ 16 - 0
app/api/controller/v1/SGB.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace app\api\controller\v1;
+
+use app\api\model\TestModel;
+
+class SGB
+{
+
+    public function index()
+    {
+        $model_id = request()->param('model_id');
+        $result = (new TestModel())->getProductInfo($model_id,$where='');
+        return showSuccess($result);
+    }
+}

+ 15 - 48
app/api/model/Ccjc.php

@@ -26,29 +26,19 @@ class Ccjc extends model{
         return $this->hasOne('orgs', 'task_id', 'id');
     }
 
-    public function selectCcjcAndOrgsData($task_uid,$task_class='例行监测',$pageNum=1,$pageSize=10)
+    public function selectUndertakeData($where_undertake,$where,$pageNum,$pageSize)
     {
-        $ccjc = new Ccjc();
-        return $ccjc->where([['task_class', '=', $task_class],])->with([
-            'orgs'=>function ($query) use ($task_uid){
-                $query->where('unit_id',$task_uid);
-            }
-        ])->page((int)$pageNum,(int)$pageSize)->select();
-    }
-
-
-    public function selectUndertakeData($task_class,$where, $pageNum, $pageSize)
-    {
-        $result = Ccjc::hasWhere('undertake', function ($query) use ($where){
-            $query->where($where);
-        })->where('task_class','=',$task_class)->page($pageNum,$pageSize)->select();
+        $result = Ccjc::hasWhere('undertake', function ($query) use ($where_undertake) {
+            $query->where($where_undertake);
+        })->where($where)->page((int)$pageNum,(int)$pageSize)->select();
         return $result;
     }
-    public function countUndertakeData($task_class,$where)
+
+    public function countUndertakeData($where_undertake,$where)
     {
-        $result = Ccjc::hasWhere('undertake', function ($query) use ($where){
-            $query->where($where);
-        })->where('task_class','=',$task_class)->count();
+        $result = Ccjc::hasWhere('undertake', function ($query) use ($where_undertake) {
+            $query->where($where_undertake);
+        })->where($where)->count();
         return $result;
     }
 
@@ -63,21 +53,16 @@ class Ccjc extends model{
         return $this->where($where)->select()->count();
     }
 
+    public function updateInfoByTaskID($task_id,$data)
+    {
+        return $this->where('id','=',$task_id)->save($data);
+    }
 
     //删除任务
     public function deleteItemById($task_id)
     {
         return $this->where('id', '=', $task_id)->delete();
     }
-    public function deleteTaskByID($id)
-    {
-        if (empty($id)) {
-            return false;
-        }
-        return $this->select($id)->delete();
-    }
-
-
 
     //添加任务 返回添加数据的主键id
     public function createTask($data)
@@ -89,29 +74,11 @@ class Ccjc extends model{
         return $this->where('id','=',$task_id)->find();
     }
 
-    public function selectInfoByTaskId($task_id_arr)
-    {
-        return $this->select($task_id_arr);
-    }
-
-    //根据id查询任务发布者releaser
-    public function getCreaterById($id)
-    {
-        return $this->select($id)->column('releaser');
-    }
-
-
-    public function updateInfoByTaskID($task_id, $data)
+    public function getTaskInfoByModelId($model_id)
     {
-        return $this->where('id', '=', $task_id)->save($data);
+        return $this->where('test_model_id', '=', $model_id)->find();
     }
 
-    /**
-     * 更新任务状态
-     * @param $arr_condition:['id'=>1,'task_name'=>'更改的名称','isPublish'=>'2']
-     * @return false|\think\Collection
-     * @throws \Exception
-     */
     public function updateTaskByArrCondition($arr_condition)
     {
         if (empty($arr_condition)) {

+ 8 - 0
app/api/model/Jcdw.php

@@ -33,6 +33,14 @@ class Jcdw extends model{
         return $this->where('id', '=', $id)->find();
     }
 
+    public function getLiteInfoById($id)
+    {
+        if (empty($id)) {
+            return false;
+        }
+        return $this->where('id', '=', $id)->field('name,address,user_fzr,phone_fzr,email')->find();
+    }
+
     public function getInfoList($where='',$pageNum=1,$pageSize=10)
     {
         return $this->where($where)->page($pageNum,$pageSize)->select();

+ 0 - 17
app/api/model/SamplePesticides.php

@@ -37,21 +37,4 @@ class SamplePesticides extends Model
             ->save($data);
     }
 
-
-
-    public function updateItemByTestIdAndSampleId($test_id, $sample_id, $data)
-    {
-        $result= $this->where([
-            ['test_id', '=', $test_id],
-            ['sample_id', '=', $sample_id]
-        ])
-            ->update($data);
-        return $result;
-    }
-
-    public function saveItemById($id, $data)
-    {
-        return $this->where($id)->save($data);
-    }
-
 }

+ 6 - 9
app/api/model/TestModel.php

@@ -14,26 +14,23 @@ class TestModel extends Model
     protected $table = 't_test_model';
     protected $pk = 'id';
 
-    //关联模型一对多定义
-    public function testProduct()
+    function testPesticides()
     {
-        return $this->hasMany(TestProduct::class, 'test_model_id', 'id');
+        return $this->hasMany('TestPesticides', 'test_model_id', 'id');
     }
-    //关联模型一对多定义
-    public function testPesticides()
+
+    function testProduct()
     {
-        return $this->hasMany(TestPesticides::class, 'test_model_id', 'id');
+        return $this->hasMany('TestProduct', 'test_model_id', 'id');
     }
 
-    //关联模型一对多使用
-    public function getProductInfo($model_id,$where='')
+    public function getProductInfo($model_id,$where=[])
     {
         $models = TestModel::find($model_id);
         $productInfo = $models->testProduct()->where($where)->select();
         return $productInfo;
     }
 
-    //关联模型一对多使用
     public function getPesticidesInfo($model_id,$where='')
     {
         $models = TestModel::find($model_id, $where = '');

+ 4 - 1
app/api/route/app.php

@@ -12,6 +12,9 @@ Route::group(function () {
 })->allowCrossDomain();
 
 Route::group(function () {
+    //测试
+    Route::post(":version.test",":version.SGB/index");                      //测试
+
     //监管端
     Route::post(":version.getTaskList",":version.JianGuan/getTaskList");                      //获取任务列表              #监管
     Route::post(":version.AddTask",":version.JianGuan/addTaskItem");                          //添加任务                 #监管
@@ -34,7 +37,7 @@ Route::group(function () {
 
 
     //牵头单位
-    Route::post(":version.qtRelease",":version.QianTou/qtRelease");                           //牵头单位发布任务
+    Route::post(":version.qtRelease",":version.QianTou/qtRelease");                           //牵头单位发布任务            #修改的是整个任务的状态
     Route::post(":version.getTaskTest",":version.QianTou/selectQtTaskList");                  //获取牵头单位所属任务        #牵头
     Route::post(":version.getTaskDetail",":version.QianTou/getTaskInfo");                     //获取任务信息                 #牵头     #任务     #detail
     Route::post(":version.getTestList",":version.QianTou/getTestUnitList");                    //获取检测单位,获取抽样单位       #牵头单位   #机构与地域  #选择机构

+ 7 - 1
app/api/validate/TaskValidate.php

@@ -8,6 +8,7 @@ class TaskValidate extends Validate
 {
     protected $rule = [
         'id' => ['require', 'integer', 'get:0'],//id
+        'task_id' => ['require', 'integer', 'get:0'],//任务id
         'pageNum' => ['require', 'integer', 'gt:0'],//页码,gt在内置规则:https://www.kancloud.cn/manual/thinkphp6_0/1037629#_232
         'pageSize' => ['require', 'integer', 'gt:0'],//每页显示数量
         'task_class' => ['require', 'in' => '例行监测,专项监测'],//任务列表:例行监测
@@ -36,6 +37,11 @@ class TaskValidate extends Validate
             'integer' => [200001, '传参错误'],
             'gt' => [200002, '传参错误'],
         ],
+        'task_id' => [
+            'require' => [200000, '传参错误'],
+            'integer' => [200001, '传参错误'],
+            'gt' => [200002, '传参错误'],
+        ],
         'pageNum' => [
             'require' => [200100, '页码不能为空'],
             'integer' => [200101, '页码必须为整数'],
@@ -134,7 +140,7 @@ class TaskValidate extends Validate
     //牵头单位 发布任务 验证场景定义
     public function sceneQtRelease()
     {
-        return $this->only['task_id'];
+        return $this->only(['task_id']);
     }
 
     //牵头单位 机构与地域 选择抽样机构,检测机构,报告上传机构

+ 1 - 0
config/status.php

@@ -25,6 +25,7 @@ return [
     'data_abnormal' => ['402', '操作数据异常,请检查操作结果'],
     'err_enPublic_status'=>['403','当前任务不可发布'],
     'err_disPublic_status'=>['403','当前任务不可废止'],
+    'err_disable_delete'=>['403','当前数据不可删除'],
     'err_data_upload' => ['4004', '数据上传失败,请重试'],
     'err_reUpload_data'=>['4005','禁止重复上传数据'],
     'err_none_auth_upload_data'=>['4006','无权上传数据,请联系管理员'],