rabin 1 dia atrás
pai
commit
fe6a500d2f

+ 35 - 0
app/Api/Save.php

@@ -0,0 +1,35 @@
+<?php namespace Upload\Api;
+use Dever;
+use Upload\Lib\Util;
+use Upload\Lib\Save as Service;
+class Save
+{
+    public function __construct()
+    {
+        $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::class)->getGroup();
+        $this->user_id = Dever::load(Util::class)->getUser();
+    }
+
+    public function act()
+    {
+        return Dever::load(Service::class)->init($this->id, $this->cate_id, $this->group_id, $this->user_id)->act($this->file);
+    }
+
+    public function wangEditor()
+    {
+        Dever::config('setting', ['output_app' => [], 'output' => [
+            'status' => ['errno', ['1' => 0, '2' => 1]],
+            'msg' => 'message',
+        ]]);
+        return $this->act();
+    }
+
+    public function avatar()
+    {
+        $uid = Dever::input('uid', 'is_numeric', '用户ID');
+        return Dever::load(Service::class)->init($this->id, $this->cate_id, $this->group_id, $this->user_id)->act($this->file, 'jpg', $uid);
+    }
+}

+ 0 - 0
lib/Manage.php → app/Lib/Manage.php


+ 8 - 8
lib/Save.php → app/Lib/Save.php

@@ -19,11 +19,11 @@ class Save
     private $type = 1;
     public function init($id, $cate_id = 1, $group_id = false, $user_id = false)
     {
-        $this->config = Dever::db('rule', 'upload')->find($id);
+        $this->config = Dever::db('upload/rule')->find($id);
         if (!$this->config) {
             Dever::error('上传规则错误');
         }
-        $this->config['save'] = Dever::db('save', 'upload')->find($this->config['save_id']);
+        $this->config['save'] = Dever::db('upload/save')->find($this->config['save_id']);
         if (!$this->config['save']) {
             Dever::error('存储位置错误');
         }
@@ -59,7 +59,7 @@ 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();
+            $result += Dever::load(Tool::class)->get($this->config['save'])->getInfo();
         }
         return $result;
     }
@@ -171,13 +171,13 @@ class Save
                 $name = $dest_name;
             }
             $dest = $this->config['id'] . '/' . $this->getDest($name, $ext, $uid);
-            $system = Dever::call("manage/util.system", [false, true, "upload/manage.getFileField"]);
+            $system = Dever::call("Manage/Lib/Util.system", [false, true, "Upload/Lib/Manage.getFileField"]);
             if ($system && isset($system['database'])) {
                 $dest = $system['database'] . '/' . $dest;
             }
         }
         # type 1是文件复制 2是base64 3是远程文件复制
-        $url = Dever::load('tool', 'upload')->get($this->config['save'])->upload($type, $source, $dest, $chunk, $this);
+        $url = Dever::load(Tool::class)->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);
         $data['url'] = $url . '?t=' . time();
         $data['type'] = $this->type;
@@ -190,7 +190,7 @@ class Save
     public function addFile($url, $source_name, $name, $dest, $size)
     {
         if ($this->config['save']['type'] > 1) {
-            $url = Dever::load('tool', 'upload')->get($this->config['save'])->getUrl(3, $url, $this);
+            $url = Dever::load(Tool::class)->get($this->config['save'])->getUrl(3, $url, $this);
             if (isset($this->config['size']) && $this->config['size']) {
                 $size = $this->config['size'];
             }
@@ -225,13 +225,13 @@ class Save
         if ($this->user_id) {
             $data['user_id'] = $this->user_id;
         }
-        $data['id'] = Dever::db('file', 'upload')->up($file, $data);
+        $data['id'] = Dever::db('upload/file')->up($file, $data);
         return $data;
     }
 
     public function after()
     {
-        $data = Dever::db('rule_after', 'upload')->select(['rule_id' => $this->config['id']]);
+        $data = Dever::db('upload/rule_after')->select(['rule_id' => $this->config['id']]);
         if ($data) {
             foreach ($data as $k => $v) {
                 $table = '';

+ 2 - 1
lib/Tool.php → app/Lib/Tool.php

@@ -15,7 +15,8 @@ class Tool
             Dever::error('存储位置错误');
         }
         $tool = 'Upload\\Lib\\Tool\\' . $save;
-        $tool = new $tool($config);
+        $tool = new $tool();
+        $tool->init($config);
         return $tool;
     }
 }

+ 5 - 4
lib/Tool/Local.php → app/Lib/Tool/Local.php

@@ -1,9 +1,10 @@
 <?php namespace Upload\Lib\Tool;
 use Dever;
+use Image\Lib\Tool;
 class Local
 {
     private $config;
-    public function __construct($config)
+    public function init($config)
     {
         $this->config = $config;
     }
@@ -52,7 +53,7 @@ class Local
         }
         $after = $upload->after();
         if ($after) {
-            $tool = Dever::load('tool', 'image')->get()->cover(true);
+            $tool = Dever::load(Tool::class)->get()->cover(true);
             foreach ($after as $k => $v) {
                 if (isset($v['table'])) {
                     $method = 'handle_' . $v['table'];
@@ -74,8 +75,8 @@ class Local
 
     public function handle($id, $file, $type = 'thumb')
     {
-        $param = Dever::db($type, 'image')->find($id);
-        $tool = Dever::load('tool', 'image')->get()->cover(true);
+        $param = Dever::db('image/' . $type)->find($id);
+        $tool = Dever::load(Tool::class)->get()->cover(true);
         $file = $this->$method($tool, $file, $param);
         return $this->url($file);
     }

+ 4 - 3
lib/Tool/Oss.php → app/Lib/Tool/Oss.php

@@ -1,13 +1,14 @@
 <?php namespace Upload\Lib\Tool;
 use Dever;
-Dever::apply('sdk/oss', 'upload');
-# 后续开发吧
+Dever::apply('upload/sdk/oss');
+use Upload\Lib\Save;
+use Image\Lib\Tool;
 class Oss
 {
     private $token;
     private $auth;
     private $bucket;
-    public function __construct($config)
+    public function init($config)
     {
         $this->auth = new \Qiniu\Auth($config['appkey'], $config['appsecret']);
         $this->token = $this->auth->uploadToken($config['bucket'], null, 3600);

+ 7 - 5
lib/Tool/Qiniu.php → app/Lib/Tool/Qiniu.php

@@ -1,13 +1,15 @@
 <?php namespace Upload\Lib\Tool;
 use Dever;
-Dever::apply('qiniu', 'upload', 'sdk');
+Dever::apply('upload/sdk/qiniu');
+use Upload\Lib\Save;
+use Image\Lib\Tool;
 class Qiniu
 {
     private $token;
     private $auth;
     private $bucket;
     private $host;
-    public function __construct($config)
+    public function init($config)
     {
         $this->auth = new \Qiniu\Auth($config['appkey'], $config['appsecret']);
         $this->token = $this->auth->uploadToken($config['bucket'], null, 3600);
@@ -96,7 +98,7 @@ class Qiniu
 
     public function handle($id, $file, $type = 'thumb')
     {
-        $param = Dever::db($type, 'image')->find($id);
+        $param = Dever::db('image/' . $type)->find($id);
         return $this->$method($file, $param);
     }
 
@@ -146,7 +148,7 @@ class Qiniu
                     }
                 }
             }
-            list($x, $y) = Dever::load('tool', 'image')->get()->position($info['width'], $info['height'], $param['width'], $param['height'], $param['position']);
+            list($x, $y) = Dever::load(Tool::class)->get()->position($info['width'], $info['height'], $param['width'], $param['height'], $param['position']);
         }
         $prefix = '';
         if (!strstr($file, 'imageMogr2')) {
@@ -180,7 +182,7 @@ class Qiniu
     {
         $file .= '?vframe/jpg/offset/' . $num;
         if ($local == 1) {
-            $data = Dever::load('save', 'upload')->act(6, $file, 'jpg');
+            $data = Dever::load(Save::class)->act(6, $file, 'jpg');
             return $data['url'] . '?time=' . time();
         } else {
             return $file;

+ 6 - 6
lib/Util.php → app/Lib/Util.php

@@ -5,13 +5,13 @@ class Util
     public function getGroup($key = '', $name = '')
     {
         $data['key'] = Dever::input('group_key', 'is_string', '分组标识', $key);
-        $info = Dever::db('group', 'upload')->find($data);
+        $info = Dever::db('upload/group')->find($data);
         $data['name'] = Dever::input('group_name', 'is_string', '分组名称', $name);
         if ($info) {
-            Dever::db('group', 'upload')->update($info['id'], $data);
+            Dever::db('upload/group')->update($info['id'], $data);
             $id = $info['id'];
         } else {
-            $id = Dever::db('group', 'upload')->insert($data);
+            $id = Dever::db('upload/group')->insert($data);
         }
         return $id;
     }
@@ -21,12 +21,12 @@ class Util
         $data['token'] = Dever::input('user_token', 'is_string', '用户标识', $token);
         $data['table'] = Dever::input('user_table', 'is_string', '用户表', $table);
         $data['table_id'] = Dever::input('user_id', 'is_numeric', '用户ID', $uid);
-        $info = Dever::db('user', 'upload')->find($data);
+        $info = Dever::db('upload/user')->find($data);
         if ($info) {
-            Dever::db('user', 'upload')->update($info['id'], $data);
+            Dever::db('upload/user')->update($info['id'], $data);
             $id = $info['id'];
         } else {
-            $id = Dever::db('user', 'upload')->insert($data);
+            $id = Dever::db('upload/user')->insert($data);
         }
         return $id;
     }

+ 2 - 2
lib/View.php → app/Lib/View.php

@@ -13,7 +13,7 @@ class View
         if (strstr($info['file'], 'http')) {
             return $info['file'];
         }
-        $save = Dever::db('save', 'upload')->find($info['save_id']);
+        $save = Dever::db('upload/save')->find($info['save_id']);
         if ($save['host']) {
             $host = $save['host'];
             if (strstr($host, '{host}')) {
@@ -71,7 +71,7 @@ class View
                 $file = $domain . $file;
             }
             if ($local) {
-                $upload = Dever::load('save', 'upload')->act($local, $file);
+                $upload = Dever::load(Save::class)->act($local, $file);
                 if ($upload && isset($upload['url'])) {
                     $file = $upload['url'];
                 }

+ 1 - 1
index.php

@@ -1,6 +1,6 @@
 <?php
 #header("Access-Control-Allow-Origin: *");
-define('DEVER_APP_NAME', 'upload');
+define('DEVER_APP_NAME', 'Upload');
 define('DEVER_APP_LANG', '文件上传');
 define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
 include(DEVER_APP_PATH . '../../boot.php');

+ 108 - 0
manage/Api/Manage.php

@@ -0,0 +1,108 @@
+<?php namespace Upload\Manage\Api;
+use Dever;
+use Manage\Lib\Auth;
+use Upload\Lib\Util;
+use Upload\Lib\Save;
+class Manage extends Auth
+{
+    # 获取图片组件信息
+    public function getImage($value = false)
+    {
+        Dever::project('image');
+        $result = [];
+        $option = [];
+        if ($value == 1) {
+            $option = Dever::db('image/thumb')->select([]);
+        } elseif ($value == 2) {
+            $option = Dever::db('image/crop')->select([]);
+        } elseif ($value == 3) {
+            $option = Dever::db('image/water_pic')->select([]);
+        } elseif ($value == 4) {
+            $option = Dever::db('image/water_txt')->select([]);
+        }
+        $result['type_id']['type'] = 'select';
+        $result['type_id']['option'] = $option;
+        $result['type_id']['value'] = $option[0]['id'] ?? '';
+        return $result;
+    }
+
+    # 删除文件
+    public function upFileStatus()
+    {
+        $rule_id = Dever::input('id');
+        $id = Dever::input('file_id');
+        $status = Dever::input('status', 'is_numeric', '状态', 2);
+        $user_id = Dever::load(Util::class)->getUser();
+        return Dever::db('upload/file')->update(['id' => $id, 'user_id' => $user_id], ['status' => $status]);
+    }
+
+    # 彻底删除文件
+    public function delFile()
+    {
+        $rule_id = Dever::input('id');
+        $id = Dever::input('file_id');
+        $user_id = Dever::load(Util::class)->getUser();
+        $state = Dever::db('upload/file')->delete(['id' => $id, 'status' => 2, 'user_id' => $user_id]);
+        if ($state) {
+            # 同时删除文件
+        }
+        return 'ok';
+    }
+
+    # 添加文件
+    public function addFile($id, $url, $file, $source, $name, $size)
+    {
+        $data = Dever::load(Save::class)->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::class)->getGroup();
+        $user_id = Dever::load(Util::class)->getUser();
+        $file = Dever::input('file');
+
+        $data = Dever::input();
+
+        $set = [];
+        $set['num'] = 18;
+        $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('upload/file')->select($where, $set);
+        if ($result['file']) {
+            foreach ($result['file'] as &$v) {
+                if ($v['source_name']) {
+                    $v['name'] = $v['source_name'];
+                }
+                $v['url'] = Dever::load(\Upload\Lib\View::class)->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;
+    }
+}

+ 1 - 1
manage/rule_after.php

@@ -4,7 +4,7 @@ return [
         'field'    => [
             'type' => [
                 'type' => 'radio',
-                'remote' => 'upload/manage.getImage',
+                'remote' => 'Upload/Api/Manage.getImage',
             ],
             'type_id' => [
                 'name' => '操作配置',

+ 1 - 1
table/file.php

@@ -1,7 +1,7 @@
 <?php
 return [
     'name' => '文件列表',
-    'partition' => 'Dever::call("manage/util.system", [false, true, "upload/manage.getFileField"])',
+    'partition' => 'Dever::call("Manage/Lib/Util.system", [false, true, "Upload/Lib/Manage.getFileField"])',
     # 数据结构
     'struct' => [
         'file'      => [

+ 1 - 1
table/file_cite.php

@@ -1,7 +1,7 @@
 <?php
 return [
     'name' => '文件引用位置',
-    'partition' => 'Dever::call("manage/util.system", [false, true, "upload/manage.getFileField"])',
+    'partition' => 'Dever::call("Manage/Lib/Util.system", [false, true, "Upload/Lib/Manage.getFileField"])',
     # 数据结构
     'struct' => [
         'file_id'     => [

+ 1 - 1
table/user.php

@@ -4,7 +4,7 @@ return [
     根据token获取uid信息:
     $info = Dever::db('upload/user')->find(1);
     $token = explode('-', $info['token']);
-    Dever::load('common', 'manage')->setAuth(..$token);
+    Dever::load('util', 'manage')->setAuth(..$token);
     Dever::db($info['table'])->find($info['table_id']);
     */
     'name' => '上传用户表',