Kirin 2 anos atrás
pai
commit
0002eb7502
1 arquivos alterados com 91 adições e 9 exclusões
  1. 91 9
      application/admin/controller/Category.php

+ 91 - 9
application/admin/controller/Category.php

@@ -52,7 +52,7 @@ class Category extends Backend
     /**
      * 查看
      */
-     
+
     public function index()
     {
         //设置过滤方法
@@ -60,7 +60,7 @@ class Category extends Backend
         if ($this->request->isAjax()) {
             $search = $this->request->request("search");
             $type = $this->request->request("type");
-           
+
             //构造父类select列表选项数据
             $list = [];
             foreach ($this->categorylist as $k => $v) {
@@ -76,17 +76,14 @@ class Category extends Backend
                     if ($type == "all" || $type == null) {
                         $list = $this->categorylist;
                     } elseif ($v['type'] == $type) {
-                        if((input('keyField') && input('keyValue')))
-                        {
-                            if($v[input('keyField')] == input('keyValue'))
-                            {
+                        if ((input('keyField') && input('keyValue'))) {
+                            if ($v[input('keyField')] == input('keyValue')) {
                                 $list[] = $v;
                             }
-                        }
-                        else{
+                        } else {
                             $list[] = $v;
                         }
-                       
+
                     }
                 }
             }
@@ -207,6 +204,91 @@ class Category extends Backend
         return $this->view->fetch();
     }
 
+    /**
+     * 删除
+     */
+    public function del($ids = "")
+    {
+        if (!$this->request->isPost()) {
+            $this->error(__("Invalid parameters"));
+        }
+        $ids = $ids ? $ids : $this->request->post("ids");
+        if ($ids) {
+            $pk = $this->model->getPk();
+            $adminIds = $this->getDataLimitAdminIds();
+            if (is_array($adminIds)) {
+                $this->model->where($this->dataLimitField, 'in', $adminIds);
+            }
+            if ($this->auth->getUserInfo()['cid'] == 0)
+                $list = $this->model->where($pk, 'in', $ids)->select();
+            else
+                $list = $this->model->where($pk, 'in', $ids)->where('cid', $this->auth->getUserInfo()['cid'])->select();
+
+            $count = 0;
+            Db::startTrans();
+            try {
+                foreach ($list as $k => $v) {
+                    $count += $v->delete();
+                }
+                Db::commit();
+            } catch (PDOException $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            } catch (Exception $e) {
+                Db::rollback();
+                $this->error($e->getMessage());
+            }
+            if ($count) {
+                $this->success();
+            } else {
+                $this->error(__('No rows were deleted'));
+            }
+        }
+        $this->error(__('Parameter %s can not be empty', 'ids'));
+    }
+
+    /**
+     * 真实删除
+     */
+    public function destroy($ids = "")
+    {
+        if (!$this->request->isPost()) {
+            $this->error(__("Invalid parameters"));
+        }
+        $ids = $ids ? $ids : $this->request->post("ids");
+        $pk = $this->model->getPk();
+        $adminIds = $this->getDataLimitAdminIds();
+        if (is_array($adminIds)) {
+            $this->model->where($this->dataLimitField, 'in', $adminIds);
+        }
+        if ($ids) {
+            $this->model->where($pk, 'in', $ids);
+        }
+        if (!$this->auth->getUserInfo()['cid'] == 0)
+            $this->model->where('cid', $this->auth->getUserInfo()['cid']);
+        $count = 0;
+        Db::startTrans();
+        try {
+            $list = $this->model->onlyTrashed()->select();
+            foreach ($list as $k => $v) {
+                $count += $v->delete(true);
+            }
+            Db::commit();
+        } catch (PDOException $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if ($count) {
+            $this->success();
+        } else {
+            $this->error(__('No rows were deleted'));
+        }
+        $this->error(__('Parameter %s can not be empty', 'ids'));
+    }
+
 
     /**
      * Selectpage搜索