Bläddra i källkod

委托单删除

huangsanjia 2 år sedan
förälder
incheckning
cb73dc8393
1 ändrade filer med 51 tillägg och 0 borttagningar
  1. 51 0
      application/admin/controller/Entrust.php

+ 51 - 0
application/admin/controller/Entrust.php

@@ -193,6 +193,57 @@ class Entrust extends Backend
         }
         $this->success();
     }
+
+    /**
+     * 删除
+     *
+     * @param $ids
+     * @return void
+     * @throws DbException
+     * @throws DataNotFoundException
+     * @throws ModelNotFoundException
+     */
+    public function del($ids = null)
+    {
+        if (false === $this->request->isPost()) {
+            $this->error(__("Invalid parameters"));
+        }
+        $ids = $ids ?: $this->request->post("ids");
+        if (empty($ids)) {
+            $this->error(__('Parameter %s can not be empty', 'ids'));
+        }
+        $row = $this->model->get($ids);
+        if (!empty($row['gather_id'])){
+            $tab = $row['gather_tab'] == 'gather_txt_check_gc'?'gather_txt_gc':'gather_txt_gcms';
+            $id = $row['gather_id'];
+            $res = Db::name($tab)->where('id',$id)->find();
+            if ($res['status'] == 1){
+                $this->error('检测数据已确认,无法删除!');
+            }
+        }
+        $pk = $this->model->getPk();
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds)) {
+            $this->model->where($this->dataLimitField, 'in', $adminIds);
+        }
+        $list = $this->model->where($pk, 'in', $ids)->select();
+
+        $count = 0;
+        Db::startTrans();
+        try {
+            foreach ($list as $item) {
+                $count += $item->delete();
+            }
+            Db::commit();
+        } catch (PDOException|Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($count) {
+            $this->success();
+        }
+        $this->error(__('No rows were deleted'));
+    }
     //提交到检测
     public function submit(){
         if (false === $this->request->isPost()) {