diff --git a/app/UploadFiles.php b/app/UploadFiles.php index 538ecf6..b9b1d34 100644 --- a/app/UploadFiles.php +++ b/app/UploadFiles.php @@ -115,7 +115,7 @@ class UploadFiles $model_file->file_sha1 = $file->sha1(); $model_file->create_time = time(); $model_file->type = $type; - + $model_file->disk = self::$disk; $model_file->save_name = Filesystem::disk(self::$disk)->putFile('upload/' . $dir_name, $file, 'uniqid'); $model_file->save(); return $model_file; diff --git a/app/index/controller/Common.php b/app/index/controller/Common.php index d67c22d..4bb73f6 100644 --- a/app/index/controller/Common.php +++ b/app/index/controller/Common.php @@ -5,16 +5,84 @@ namespace app\index\controller; use app\model\Category; use app\model\Nav; use app\model\Post; +use app\model\User; +use think\facade\Session; use think\facade\View; use think\helper\Str; +use UserHub\Client; class Common extends BaseController { + public $modelUser = null; + public function initialize() { parent::initialize(); + $user_id = Session::get('user_id'); + if (!empty($user_id)) { + $this->modelUser = User::find($user_id); + View::assign('user', $this->modelUser); + }else{ + $this->tempLogin(); + } + + $this->ulthonLogin(); + } + + public function tempLogin() + { + if (empty($this->modelUser)) { + $temp_user = []; + $temp_user['account'] = uniqid(); + + $temp_user['type'] = 'temp'; + + $model_user = User::create($temp_user); + + $this->modelUser = $model_user; + Session::set('user_id', $model_user->id); + View::assign('user', $this->modelUser); + + } + } + + public function ulthonLogin() + { + + if (empty($this->modelUser) || $this->modelUser->type != 'ulthon') { + $code = $this->request->param('code'); + + $user_hub_client = new Client([ + 'key' => get_system_config('user_hub_key'), + 'secret' => get_system_config('user_hub_secret'), + 'host' => get_system_config('user_hub_host'), + ]); + if (empty($code)) { + $url = $user_hub_client->getBowserRedirectUrl($this->request->url(true)); + View::assign('ulthon_login_url',$url); + + } else { + $user_info = $user_hub_client->getUserinfoByCode($code); + + $model_user = User::where('uid', $user_info['uid'])->find(); + + if (empty($model_user)) { + unset($user_info['id']); + // TODO:处理数据,或者中转数据 + // TODO:下载头像 + + $user_info['type'] = 'ulthon'; + + $model_user = User::create((array)$user_info); + } + + $this->modelUser = $model_user; + } + Session::set('user_id', $this->modelUser->id); + View::assign('user', $this->modelUser); + } } } diff --git a/app/index/controller/File.php b/app/index/controller/File.php index b2f2375..38caff3 100644 --- a/app/index/controller/File.php +++ b/app/index/controller/File.php @@ -46,6 +46,8 @@ class File extends Common { # code... + UploadFiles::setDisks('safe'); + return UploadFiles::save($request); } diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 3d0f232..11c6234 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -2,12 +2,21 @@ namespace app\index\controller; +use Alchemy\Zippy\Zippy; use app\model\Category; use app\model\Nav; use app\model\Post; use app\model\PostCategory; +use app\model\Share; +use app\model\ShareFiles; +use app\UploadFiles; +use think\facade\App; +use think\facade\Session; +use think\facade\Validate; use think\facade\View; +use think\File; use think\Request; +use think\validate\ValidateRule; class Index extends Common { @@ -20,6 +29,10 @@ class Index extends Common { // + $list_active_shares = Share::where('user_id',$this->modelUser->id)->where('status',0)->select(); + + View::assign('list_active_shares',$list_active_shares); + return View::fetch(); } @@ -43,6 +56,143 @@ class Index extends Common public function save(Request $request) { // + + $post_data = $request->post(); + + $post_data['user_id'] = $this->modelUser->id; + + $root_dir = App::getRootPath(); + + $safe_dir = '/safe/'; + + $file_preifx = $root_dir . $safe_dir; + + + $validate = Validate::rule('files_list', ValidateRule::isRequire()->isArray()->requireCallback(function ($value) use ($file_preifx) { + foreach ($value as $key_v => $value_v) { + $file_path = $file_preifx . $value_v['save_name']; + + if (!file_exists($file_path)) { + return false; + } + } + + return true; + }, '文件不存在')) + ->rule('password', ValidateRule::length('6,18')) + ->rule('times', ValidateRule::requireCallback(function ($value) { + if (empty($value)) { + return true; + } + + if (is_numeric($value)) { + if ($value > 0) { + return true; + } + } + + return false; + })) + ->rule('expire', ValidateRule::isRequire()->isNumber()->min(1)); + + if (!$validate->check($post_data)) { + return json_message($validate->getError()); + } + + + $model_share = Share::create($post_data); + + $total_size = 0; + + $files_list = []; + + foreach ($post_data['files_list'] as $key_file => $value_file) { + + $file_path = $file_preifx . $value_file['save_name']; + + UploadFiles::use($value_file['save_name']); + + $file = new File($file_path); + + $model_share_file = new ShareFiles(); + + $model_share_file->save_name = $value_file['save_name']; + $model_share_file->file_name = $value_file['file_name']; + + $model_share_file->mime_type = $file->getMime(); + + $model_share_file->file_size = $file->getSize(); + + $model_share_file->ext_name = $file->extension(); + + $model_share_file->file_md5 = $file->md5(); + $model_share_file->file_sha1 = $file->sha1(); + + $model_share_file->share_id = $model_share->id; + + $model_share_file->save(); + + $file_name = $value_file['file_name']; + + $file_name = $this->build_files_list_key($files_list, $file_name); + + $files_list[$file_name] = $file_path; + + + $total_size += $file->getSize(); + } + + // 合成大文件 + + $zippy = Zippy::load(); + + $download_zip_save_name = 'build_download_zip/' . uniqid() . '.zip'; + + $build_download_path = $file_preifx . $download_zip_save_name; + + $build_download_dir = dirname($build_download_path); + + if (!is_dir($build_download_dir)) { + mkdir($build_download_dir, 0777, true); + } + + $build_archive = $zippy->create($build_download_path, $files_list, true); + + $model_share->build_download_save_name = $download_zip_save_name; + + $model_share->total_size = $total_size; + + $model_share->save(); + + return json_message(); + } + + public function build_files_list_key($file_list, $file_key) + { + if (!isset($file_list[$file_key])) { + return $file_key; + } + + + $file_name = $file_key; + $file_name_others = []; + if (strpos($file_key, '.') !== false) { + $file_key_array = explode('.', $file_key); + $file_name = array_shift($file_key_array); + + $file_name_others = $file_key_array; + } + + $new_file_name = $file_name . '(1).' . implode('.', $file_name_others); + + return $this->build_files_list_key($file_list, $new_file_name); + } + + public function logout() + { + Session::clear(); + + return $this->success('已成功退出', url('index')); } /** diff --git a/app/model/Share.php b/app/model/Share.php new file mode 100644 index 0000000..b002d34 --- /dev/null +++ b/app/model/Share.php @@ -0,0 +1,15 @@ + - - - - 系统管理 - {include file="common/_require"} + + + + 系统管理 + {include file="common/_require"} - - + + -
- {include file="common/_header"} +
+ {include file="common/_header"} - {include file="common/left_system"} + {include file="common/left_system"} -
+
-
- -
-
- -
-
- 阿里OSS存储设置 -
-
-
-
AccessKey
-
- -
-
-
-
SecretKey
-
- -
-
-
-
空间名称
-
- -
-
-
-
空间域名
-
- -
-
- -
- -
-
-
-
- -
-
-
- -
-
- 阿里短信配置 -
-
-
-
AccessKey
-
- -
-
-
-
AccessSecret
-
- -
-
-
-
模板ID
-
- -
-
- -
- -
-
-
-
- -
-
-
- -
-
- 微信第三方平台配置 -
-
-
-
AppID
-
- -
-
-
-
AppSecret
-
- -
-
-
-
消息校验Token
-
- -
-
-
-
消息加解密Key
-
- -
-
-
- -
-
-
-
- -
-
-
-
-
- 微信公众号配置 -
-
-
-
公众号名称
-
- -
-
-
-
AppID
-
- -
-
-
-
AppSecret
-
- -
-
-
-
Token
-
- -
-
-
-
- -
保存
- -
-
-
-
-
-
-
-
-
-
- 微信支付配置 -
-
-
-
商户ID
-
- -
-
-
-
商户秘钥
-
- - -
-
-
-
商户key
-
- -
上传
-
-
-
-
商户cert
-
- -
上传
-
-
-
- -
-
-
-
-
-
-
-
+
+ +
+
+
+
+ UserHub +
+
+
+
key
+
+ +
+
+
+
secret
+
+ +
+
+
+
域名
+
+ +
+
+
+ +
+
+
+
- {include file="common/_footer"} +
+
+ +
+
- + + {include file="common/_footer"} +
+ \ No newline at end of file diff --git a/view/index/index/index.html b/view/index/index/index.html index 1a76abd..2ff4158 100644 --- a/view/index/index/index.html +++ b/view/index/index/index.html @@ -14,6 +14,14 @@ .webuploader-element-invisible { display: none; } + + .option-item { + margin-bottom: 0 !important; + } + + .file-progress { + margin-right: 15px; + } @@ -28,20 +36,38 @@
+ {if $user.type == 'temp' } +
+ {else /} +
+
+
+ +
+ + {/if}
@@ -68,7 +94,7 @@
- +
@@ -102,6 +128,7 @@
+ @@ -221,15 +248,27 @@ var fileList = [] - $('.file-list .file-item').each(function(index,elem){ + $('.file-list .file-item').each(function (index, elem) { var fileData = $(elem).data('success') - console.log(fileData); + fileList.push(fileData) }) - data.field.file_list = fileList + data.field.files_list = fileList + window.loading = layer.load() + $.post('{:url("save")}', data.field, function (result) { + if (result.code != 0) { + layer.close(window.loading) + layer.msg(result.msg) + return false; + } - console.log(data.field); + layer.msg('添加成功') + + setTimeout(() => { + location.reload(); + }, 1200); + }) return false; })