rabin 7 maanden geleden
bovenliggende
commit
72765b781a
10 gewijzigde bestanden met toevoegingen van 180 en 28 verwijderingen
  1. 16 18
      api/Save.php
  2. 14 6
      lib/Save.php
  3. 33 0
      lib/Util.php
  4. 16 1
      manage/file.php
  5. 8 0
      manage/save.php
  6. 5 3
      table/cate.php
  7. 23 0
      table/file.php
  8. 20 0
      table/group.php
  9. 12 0
      table/save.php
  10. 33 0
      table/user.php

+ 16 - 18
api/Save.php

@@ -2,35 +2,33 @@
 use Dever;
 class Save
 {
-    public function act($id = 1, $file = '')
+    public function __construct()
     {
-        if (!$file) {
-            Dever::error('file不存在');
-        }
-        return Dever::load('save', 'upload')->act($id, $file);
+        $this->id = Dever::input('id', 'is_numeric', '上传规则错误', 1);
+        $this->file = Dever::input('file', '!empty', '上传文件错误');
+        $this->cate_id = Dever::input('cate_id', 'is_numeric', '上传分类', 1);
+        $this->group_id = Dever::load('util', 'upload')->getGroup();
+        $this->user_id = Dever::load('util', 'upload')->getUser();
     }
 
-    public function wangEditor($id = 1, $file = '')
+    public function act()
+    {
+        return Dever::load('save', 'upload')->init($this->id, $this->cate_id, $this->group_id, $this->user_id)->act($this->file);
+    }
+
+    public function wangEditor()
     {
-        if (!$file) {
-            Dever::error('file不存在');
-        }
         Dever::config('setting', array('output' => array
         (
             'status' => array('errno', array('1' => 0, '2' => 1)),
             'msg' => 'message',
         )));
-        return $this->act($id, $file);
+        return $this->act();
     }
 
-    public function avatar($id = 1, $file = '', $uid = false)
+    public function avatar()
     {
-        if (!$file) {
-            Dever::error('file不存在');
-        }
-        if (!$uid) {
-            Dever::error('uid不存在');
-        }
-        return Dever::load('save', 'upload')->act($id, $file, 'jpg', $uid);
+        $uid = Dever::input('uid', 'is_numeric', '用户ID');
+        return Dever::load('save', 'upload')->init($this->id, $this->cate_id, $this->group_id, $this->user_id)->act($this->file, 'jpg', $uid);
     }
 }

+ 14 - 6
lib/Save.php

@@ -15,7 +15,7 @@ class Save
         8 => 'exe,msi',
     );
     private $type = 1;
-    public function init($id)
+    public function init($id, $cate_id = 1, $group_id = false, $user_id = false)
     {
         $this->config = Dever::db('rule', 'upload')->find($id);
         if (!$this->config) {
@@ -25,6 +25,9 @@ class Save
         if (!$this->config['save']) {
             Dever::error('存储位置错误');
         }
+        $this->cate_id = $cate_id ? $cate_id : 1;
+        $this->group_id = $group_id;
+        $this->user_id = $user_id;
         return $this;
     }
 
@@ -52,15 +55,18 @@ class Save
             }
         }
         $result['type'] = $this->config['save']['type'];
+        $result['method'] = $this->config['save']['method'];
         if ($result['type'] > 1) {
             $result += Dever::load('tool', 'upload')->get($this->config['save'])->getInfo();
         }
         return $result;
     }
 
-    public function act($id, $source, $default_ext = '', $uid = false, $dest_name = '', $cate = 1)
+    public function act($source, $default_ext = '', $uid = false, $dest_name = '')
     {
-        $this->init($id);
+        if (!$this->config) {
+            Dever::error('上传规则错误');
+        }
         $name = '';
         $ext = '';
         $size = 0;
@@ -157,7 +163,7 @@ class Save
         $dest = $this->config['id'] . '/' . $this->getDest($name, $ext, $uid);
         # type 1是文件复制 2是base64 3是远程文件复制
         $url = Dever::load('tool', 'upload')->get($this->config['save'])->upload($type, $source, $dest, $chunk, $this);
-        $data = $this->up($source_name, $name, $dest, $this->config['size'], $this->config['width'] ?? 0, $this->config['height'] ?? 0, $cate);
+        $data = $this->up($source_name, $name, $dest, $this->config['size'], $this->config['width'] ?? 0, $this->config['height'] ?? 0);
         $data['url'] = $url;
         $data['type'] = $this->type;
         if (isset($content)) {
@@ -180,7 +186,7 @@ class Save
         return $data;
     }
 
-    private function up($source_name, $name, $dest, $size, $width = 0, $height = 0, $cate = 1)
+    private function up($source_name, $name, $dest, $size, $width = 0, $height = 0)
     {
         $file['rule_id'] = $this->config['id'];
         $file['name'] = $name;
@@ -195,7 +201,9 @@ class Save
         if ($height) {
             $data['height'] = $height;
         }
-        $data['cate_id'] = $cate;
+        $data['cate_id'] = $this->cate_id;
+        $data['group_id'] = $this->group_id;
+        $data['user_id'] = $this->user_id;
         $data['id'] = Dever::db('file', 'upload')->up($file, $data);
         return $data;
     }

+ 33 - 0
lib/Util.php

@@ -0,0 +1,33 @@
+<?php namespace Upload\Lib;
+use Dever;
+class Util
+{
+    public function getGroup()
+    {
+        $data['key'] = Dever::input('group_key', 'is_string', '分组标识');
+        $info = Dever::db('group', 'upload')->find($data);
+        $data['name'] = Dever::input('group_name', 'is_string', '分组名称');
+        if ($info) {
+            Dever::db('group', 'upload')->update($info['id'], $data);
+            $id = $info['id'];
+        } else {
+            $id = Dever::db('group', 'upload')->insert($data);
+        }
+        return $id;
+    }
+
+    public function getUser()
+    {
+        $data['token'] = Dever::input('user_token', 'is_string', '用户标识');
+        $data['table'] = Dever::input('user_table', 'is_string', '用户表');
+        $data['table_id'] = Dever::input('user_id', 'is_numeric', '用户ID');
+        $info = Dever::db('user', 'upload')->find($data);
+        if ($info) {
+            Dever::db('user', 'upload')->update($info['id'], $data);
+            $id = $info['id'];
+        } else {
+            $id = Dever::db('user', 'upload')->insert($data);
+        }
+        return $id;
+    }
+}

+ 16 - 1
manage/file.php

@@ -3,13 +3,28 @@ return array
 (
     'list' => array
     (
+        'field'      => array
+        (
+            'file',
+           //'name',
+            'source_name',
+            'cate_id',
+            'save_id',
+            'rule_id',
+            'size',
+            'width',
+            'height',
+            'status',
+            'cdate',
+        ),
         'button' => array(),
         'data_button' => array(),
         'search' => array
         (
-            'name',
             'cate_id',
+            //'name',
             'file',
+            'source_name',
             'status',
         ),
     ),

+ 8 - 0
manage/save.php

@@ -30,6 +30,10 @@ return array
                 'type' => 'radio',
                 'control' => true,
             ),
+            'method' => array
+            (
+                'type' => 'radio',
+            ),
             'appkey',
             'appsecret',
             'bucket',
@@ -44,6 +48,10 @@ return array
         ),
         'control' => array
         (
+            'method' => array
+            (
+                'type' => array(2,3),
+            ),
             'appkey' => array
             (
                 'type' => array(2,3),

+ 5 - 3
table/cate.php

@@ -13,11 +13,13 @@ return array
     ),
     'default' => array
     (
-        'field' => 'name,cdate',
+        'field' => 'id,name,cdate',
         'value' => array
         (
-            '"默认",' . DEVER_TIME,
-            '"裁剪",' . DEVER_TIME,
+            '1,"后台上传",' . DEVER_TIME,
+            '2,"用户上传",' . DEVER_TIME,
+            '3,"裁剪",' . DEVER_TIME,
+            '4,"采集",' . DEVER_TIME,
         ),
         'num' => 1,
     ),

+ 23 - 0
table/file.php

@@ -2,6 +2,16 @@
 return array
 (
     'name' => '文件列表',
+    'partition' => array
+    (
+        # 按照月份分区
+        'field' => array
+        (
+            'type' => 'range',
+            'field' => 'cdate', 
+            'value' => 'date("Y-m")'
+        ),
+    ),
     # 数据结构
     'struct' => array
     (
@@ -45,6 +55,19 @@ return array
             'value'     => 'upload/rule',
         ),
 
+        'group_id'     => array
+        (
+            'name'      => '文件分组',
+            'type'      => 'int(11)',
+            'value'     => 'upload/group',
+        ),
+
+        'user_id'     => array
+        (
+            'name'      => '上传用户id',
+            'type'      => 'int(11)',
+        ),
+
         'size'      => array
         (
             'name'      => '大小',

+ 20 - 0
table/group.php

@@ -0,0 +1,20 @@
+<?php
+return array
+(
+    'name' => '文件分组',
+    # 数据结构
+    'struct' => array
+    (
+        'name'      => array
+        (
+            'name'      => '分组名称',
+            'type'      => 'varchar(32)',
+        ),
+
+        'key'      => array
+        (
+            'name'      => '分组标识',
+            'type'      => 'varchar(32)',
+        ),
+    ),
+);

+ 12 - 0
table/save.php

@@ -24,6 +24,18 @@ return array
             'default'   => '1',
         ),
 
+        'method'     => array
+        (
+            'name'      => '上传方式',
+            'type'      => 'tinyint(1)',
+            'value' => array
+            (
+                1 => '后端上传至云端',
+                2 => '前端上传至云端',
+            ),
+            'default'   => '1',
+        ),
+
         'host'      => array
         (
             'name'      => '域名',

+ 33 - 0
table/user.php

@@ -0,0 +1,33 @@
+<?php
+return array
+(
+    /*
+    根据token获取uid信息:
+    $info = Dever::db('upload/user')->find(1);
+    $token = explode('-', $info['token']);
+    Dever::load('common', 'manage')->setAuth(..$token);
+    Dever::db($info['table'])->find($info['table_id']);
+    */
+    'name' => '上传用户表',
+    # 数据结构
+    'struct' => array
+    (
+        'token'      => array
+        (
+            'name'      => '用户token',
+            'type'      => 'varchar(500)',
+        ),
+
+        'table'      => array
+        (
+            'name'      => '用户表名',
+            'type'      => 'varchar(100)',
+        ),
+
+        'table_id'     => array
+        (
+            'name'      => '用户表id',
+            'type'      => 'int(11)',
+        ),
+    ),
+);