完成基本功能

This commit is contained in:
augushong
2021-06-20 01:02:11 +08:00
parent 36c059e5be
commit a869aadf95
8 changed files with 343 additions and 54 deletions

View File

@@ -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();
}
/**