rabin 2 months ago
parent
commit
e716342cc4
4 changed files with 103 additions and 15 deletions
  1. 69 5
      api/Manage.php
  2. 16 0
      lib/Manage.php
  3. 17 0
      lib/View.php
  4. 1 10
      table/file.php

+ 69 - 5
api/Manage.php

@@ -25,12 +25,26 @@ class Manage extends Auth
     }
 
     # 删除文件
-    public function delFile($id, $file)
+    public function upFileStatus()
     {
-        $info = pathinfo($file);
-        $file = explode('.', $info['filename']);
-        $file = $file[0];
-        return Dever::db('file', 'upload')->update(array('rule_id' => $id, 'name' => $file), array('status' => 2));
+        $rule_id = Dever::input('id');
+        $id = Dever::input('file_id');
+        $status = Dever::input('status', 'is_numeric', '状态', 2);
+        $user_id = Dever::load('util', 'upload')->getUser();
+        return Dever::db('file', 'upload')->update(array('id' => $id, 'user_id' => $user_id), array('status' => $status));
+    }
+
+    # 彻底删除文件
+    public function delFile()
+    {
+        $rule_id = Dever::input('id');
+        $id = Dever::input('file_id');
+        $user_id = Dever::load('util', 'upload')->getUser();
+        $state = Dever::db('file', 'upload')->delete(array('id' => $id, 'status' => 2, 'user_id' => $user_id));
+        if ($state) {
+            # 同时删除文件
+        }
+        return 'ok';
     }
 
     # 添加文件
@@ -39,4 +53,54 @@ class Manage extends Auth
         $data = Dever::load('save', 'upload')->init($id)->addFile($url, $source, $name, $file, $size);
         return $data;
     }
+
+    # 获取文件库文件列表
+    public function getFileList()
+    {
+        $type = Dever::input('type', 'is_numeric', '类型', 0);
+        $id = Dever::input('id', 'is_numeric', '上传规则错误', 1);
+        $cate_id = Dever::input('cate_id', 'is_numeric', '上传分类', 1);
+        $group_id = Dever::load('util', 'upload')->getGroup();
+        $user_id = Dever::load('util', 'upload')->getUser();
+        $file = Dever::input('file');
+
+        $data = Dever::input();
+
+        $set = array();
+        $set['num'] = 10;
+        $where['rule_id'] = $id;
+        $where['status'] = 1;
+        #$where['cate_id'] = $cate_id;
+        if ($type == 1) {
+            $where['group_id'] = $group_id;
+        } elseif ($type == 2) {
+            $where['user_id'] = $user_id;
+        } elseif ($type == 4) {
+            $where['status'] = 2;
+        }
+        
+        $result['file'] = Dever::db('file', 'upload')->select($where, $set);
+        if ($result['file']) {
+            foreach ($result['file'] as &$v) {
+                if ($v['source_name']) {
+                    $v['name'] = $v['source_name'];
+                }
+                $v['url'] = Dever::load('view', 'upload')->getUrl($v);
+                $v['class'] = '';
+                $v['del'] = 2;
+                if ($user_id == $v['user_id']) {
+                    $v['del'] = 1;
+                }
+                if ($file) {
+                    foreach ($file as $v1) {
+                        if ($v1 && $v1['url'] == $v['url']) {
+                            $v['class'] = 'show-image-active';
+                        }
+                    }
+                }
+            }
+        }
+        $result['total'] = Dever::page('total');
+        return $result;
+    }
 }

+ 16 - 0
lib/Manage.php

@@ -0,0 +1,16 @@
+<?php namespace Upload\Lib;
+use Dever;
+class Manage
+{
+    # 文件表按照月份分区
+    public function getFileField()
+    {
+        return array
+        (
+            'type' => 'range',
+            'field' => 'cdate', 
+            'value' => 'date("Y-m", strtotime("+1 month"))'
+        );
+        return $type;
+    }
+}

+ 17 - 0
lib/View.php

@@ -9,6 +9,23 @@ class View
         3 => 'Oss',
     );
 
+    public function getUrl($info)
+    {
+        if (strstr($info['file'], 'http')) {
+            return $info['file'];
+        }
+        $save = Dever::db('save', 'upload')->find($info['save_id']);
+        if ($save['host']) {
+            $host = $save['host'];
+            if (strstr($host, '{host}')) {
+                $host = str_replace('{host}', Dever::host(), $host);
+            }
+        } else {
+            $host = Dever::host() . 'data/' . DEVER_PROJECT . '/upload/';
+        }
+        return $host . $info['file'];
+    }
+
     public function local($file)
     {
         $host = Dever::host() . 'data/';

+ 1 - 10
table/file.php

@@ -2,16 +2,7 @@
 return array
 (
     'name' => '文件列表',
-    'partition' => array
-    (
-        # 按照月份分区
-        'field' => array
-        (
-            'type' => 'range',
-            'field' => 'cdate', 
-            'value' => 'date("Y-m", strtotime("+1 month"))'
-        ),
-    ),
+    'partition' => 'Dever::call("manage/common.system", array(false, true, "upload/manage.getFileField"))',
     # 数据结构
     'struct' => array
     (