diff --git a/app/index/controller/Index.php b/app/index/controller/Index.php index 11c6234..2473066 100644 --- a/app/index/controller/Index.php +++ b/app/index/controller/Index.php @@ -29,9 +29,9 @@ class Index extends Common { // - $list_active_shares = Share::where('user_id',$this->modelUser->id)->where('status',0)->select(); + $list_active_shares = Share::where('user_id', $this->modelUser->id)->order('id desc')->where('status', 0)->select(); - View::assign('list_active_shares',$list_active_shares); + View::assign('list_active_shares', $list_active_shares); return View::fetch(); } @@ -60,7 +60,8 @@ class Index extends Common $post_data = $request->post(); $post_data['user_id'] = $this->modelUser->id; - + $post_data['uid'] = uniqid(); + $post_data['times_last'] = $post_data['times']; $root_dir = App::getRootPath(); $safe_dir = '/safe/'; @@ -173,17 +174,16 @@ class Index extends Common return $file_key; } - $file_name = $file_key; - $file_name_others = []; + $file_ext = ''; if (strpos($file_key, '.') !== false) { $file_key_array = explode('.', $file_key); - $file_name = array_shift($file_key_array); + $file_ext = array_pop($file_key_array); - $file_name_others = $file_key_array; + $file_name = implode('.', $file_key_array); } - $new_file_name = $file_name . '(1).' . implode('.', $file_name_others); + $new_file_name = $file_name . '(1).' . $file_ext; return $this->build_files_list_key($file_list, $new_file_name); } @@ -201,9 +201,63 @@ class Index extends Common * @param int $id * @return \think\Response */ - public function read($id) + public function read($uid) { // + $msg = ''; + + $model_share = Share::where('uid', $uid)->find(); + View::assign('share', $model_share); + + $list_share_files = ShareFiles::where('share_id', $model_share->id)->select(); + + View::assign('share_files', $list_share_files); + + + $is_download = $this->request->param('do_download'); + $password = trim($this->request->param('password')); + + + if (empty($model_share)) { + $msg = '访问的分享链接不存在'; + } else if ($model_share->expire_time < time()) { + $msg = '分享链接已过期'; + } else if (!empty($model_share->password)) { + if ($is_download == 1) { + if (empty($password)) { + $msg = '请输入密码'; + } + + if ($model_share->password != $password) { + $msg = '输入的密码错误'; + } + } + } else if ($model_share->times > 0 && $model_share->times_last == 0) { + $msg = '分享的文件已没有下载次数'; + } else if ($model_share->status != 0) { + $msg = '文件已下架'; + } + + if ($is_download == 1) { + + if (!empty($msg)) { + return $this->error($msg); + } + + if ($model_share->times > 0) { + $model_share->times_last--; + $model_share->times_download++; + $model_share->save(); + } + + return download(ShareFiles::build_safe_path($model_share->build_download_save_name), basename($model_share->build_download_save_name)); + } + + $model_share->visit++; + $model_share->save(); + + View::assign('msg', $msg); + return View::fetch(); } /** diff --git a/app/index/route/app.php b/app/index/route/app.php new file mode 100644 index 0000000..d08e44c --- /dev/null +++ b/app/index/route/app.php @@ -0,0 +1,5 @@ +hasMany(ShareFiles::class,'share_id'); + } + + public function getExpireDateAttr() + { + + $date = date('Y-m-d H:i:s', $this->getAttr('expire_time')); + + return $date; + } + + public function getTotalSizeFormatAttr() + { + return format_size($this->getData('total_size')); + } + + public function getExpireTimeAttr() + { + $exipre = $this->getData('expire'); + return $this->getOrigin('create_time') + $exipre; + } + + public function getReadUrlAttr() + { + return url('Index/read', ['uid' => $this->getData('uid')], false, true); + } } diff --git a/app/model/ShareFiles.php b/app/model/ShareFiles.php index 3a50672..4ce1c98 100644 --- a/app/model/ShareFiles.php +++ b/app/model/ShareFiles.php @@ -21,5 +21,11 @@ class ShareFiles extends Model return $root_dir . $safe_dir . $save_name; } + + public function getFileSizeFormatAttr() + { + $value = $this->getData('file_size'); + return format_size($value); + } // } diff --git a/public/static/css/index.css b/public/static/css/index.css index 39ecf22..6660078 100644 --- a/public/static/css/index.css +++ b/public/static/css/index.css @@ -26,4 +26,12 @@ body { .file-size{ margin-left: 15px; color: #999; +} + +.footer{ + margin-bottom: 15px; +} + +.footer > *{ + margin-right: 15px; } \ No newline at end of file diff --git a/view/index/common/_header.html b/view/index/common/_header.html new file mode 100644 index 0000000..49f59d7 --- /dev/null +++ b/view/index/common/_header.html @@ -0,0 +1,45 @@ +
+
+ +
+
+ +
+
+
+ {if $user.type == 'temp' } + +
+
+ +
+ +
+ {else /} +
+
+
+ +
+ + {/if} +
+
+ +
\ No newline at end of file diff --git a/view/index/index/index.html b/view/index/index/index.html index 2ff4158..9028b2c 100644 --- a/view/index/index/index.html +++ b/view/index/index/index.html @@ -22,56 +22,17 @@ .file-progress { margin-right: 15px; } + + .files { + border: 1px dashed #bbb; + padding: 15px; + } -
-
- -
-
- -
-
-
- {if $user.type == 'temp' } - -
-
- -
- -
- {else /} -
-
-
- -
- - {/if} -
-
- -
+ {include file='common/_header'/}
@@ -128,7 +89,88 @@
+
+
+
分享记录
+
+ {empty name='list_active_shares'} +
+
+ 当前没有数据 +
+
+ {else /} + + + + + + + + + + + + + {volist name='list_active_shares' id='vo'} + + + + + + + + + {/volist} + +
分享信息访问统计密码剩余次数过期时间操作
+

分享链接: + {$vo.uid} +

+

分享时间:{$vo.create_time}

+

文件大小:{$vo.total_size_format}

+
+ 文件列表: + 显示 + +
+
+

下载次数:{$vo.times_download}

+

访问次数:{$vo.visit}

+
+ {empty name='vo.password'} + 无密码 + {else /} + {$vo.password} + {/empty} + + {empty name='vo.times'} + 无限制 + {else /} + {$vo.times_last}/{$vo.times} + {/empty} + {$vo.expire_date} +
+
立即下架
+
+
+ {/empty} + +
+
+
+
+ +