mirror of
https://gitee.com/ulthon/ul-file-share.git
synced 2026-07-01 11:02:49 +08:00
完成基本功能
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
5
app/index/route/app.php
Normal file
5
app/index/route/app.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
use think\facade\Route;
|
||||
|
||||
Route::rule('share/:uid','Index/read');
|
||||
@@ -12,4 +12,33 @@ use think\Model;
|
||||
class Share extends Model
|
||||
{
|
||||
//
|
||||
|
||||
public function files()
|
||||
{
|
||||
return $this->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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
//
|
||||
}
|
||||
|
||||
@@ -26,4 +26,12 @@ body {
|
||||
.file-size{
|
||||
margin-left: 15px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.footer{
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.footer > *{
|
||||
margin-right: 15px;
|
||||
}
|
||||
45
view/index/common/_header.html
Normal file
45
view/index/common/_header.html
Normal file
@@ -0,0 +1,45 @@
|
||||
<div class="ul-header ">
|
||||
<div class="ul-header-main" style="max-width: 1000px;padding: 0 15px">
|
||||
|
||||
<div class="ul-header-left">
|
||||
<div class="">
|
||||
<img class="ul-header-logo" src="{:get_source_link(get_system_config('site_logo'))}" alt="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ul-header-right">
|
||||
{if $user.type == 'temp' }
|
||||
|
||||
<div class="ul-header-user">
|
||||
<div class="ul-header-user-avatar">
|
||||
|
||||
</div>
|
||||
<div class="ul-header-user-info">
|
||||
<div class="ul-header-user-name">
|
||||
临时账号
|
||||
</div>
|
||||
<a href="{$ulthon_login_url}" class="ul-header-user-options">
|
||||
<i class="ul-icon-exit"></i>
|
||||
<span>登陆</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{else /}
|
||||
<div class="ul-header-user">
|
||||
<div class="ul-header-user-avatar" style="background-image: url({$user.avatar});">
|
||||
</div>
|
||||
<div class="ul-header-user-info">
|
||||
<div class="ul-header-user-name">
|
||||
{$user.nickname}
|
||||
</div>
|
||||
<a href="{:url('logout')}" class="ul-header-user-options">
|
||||
<i class="ul-icon-exit"></i>
|
||||
<span>退出</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@@ -22,56 +22,17 @@
|
||||
.file-progress {
|
||||
margin-right: 15px;
|
||||
}
|
||||
|
||||
.files {
|
||||
border: 1px dashed #bbb;
|
||||
padding: 15px;
|
||||
}
|
||||
</style>
|
||||
<script src="/static/lib/webuploader/webuploader.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="ul-header ">
|
||||
<div class="ul-header-main" style="max-width: 1000px;padding: 0 15px">
|
||||
|
||||
<div class="ul-header-left">
|
||||
<div class="">
|
||||
<img class="ul-header-logo" src="{:get_source_link(get_system_config('site_logo'))}" alt="">
|
||||
</div>
|
||||
</div>
|
||||
<div class="ul-header-right">
|
||||
{if $user.type == 'temp' }
|
||||
|
||||
<div class="ul-header-user">
|
||||
<div class="ul-header-user-avatar">
|
||||
|
||||
</div>
|
||||
<div class="ul-header-user-info">
|
||||
<div class="ul-header-user-name">
|
||||
临时账号
|
||||
</div>
|
||||
<a href="{$ulthon_login_url}" class="ul-header-user-options">
|
||||
<i class="ul-icon-exit"></i>
|
||||
<span>登陆</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
{else /}
|
||||
<div class="ul-header-user">
|
||||
<div class="ul-header-user-avatar" style="background-image: url({$user.avatar});">
|
||||
</div>
|
||||
<div class="ul-header-user-info">
|
||||
<div class="ul-header-user-name">
|
||||
{$user.nickname}
|
||||
</div>
|
||||
<a href="{:url('logout')}" class="ul-header-user-options">
|
||||
<i class="ul-icon-exit"></i>
|
||||
<span>退出</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{include file='common/_header'/}
|
||||
<div class="layui-container" style="margin-top: 15px;;">
|
||||
<div class="layui-row">
|
||||
<div class="layui-card">
|
||||
@@ -128,7 +89,88 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-row" style="margin-top: 15px;">
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">分享记录</div>
|
||||
<div class="layui-card-body">
|
||||
{empty name='list_active_shares'}
|
||||
<div class="ul-padding-md layui-bg-gray">
|
||||
<div class="ul-info-tips">
|
||||
当前没有数据
|
||||
</div>
|
||||
</div>
|
||||
{else /}
|
||||
<table class="layui-table" lay-skin="line">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>分享信息</th>
|
||||
<th>访问统计</th>
|
||||
<th>密码</th>
|
||||
<th>剩余次数</th>
|
||||
<th>过期时间</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{volist name='list_active_shares' id='vo'}
|
||||
<tr>
|
||||
<td>
|
||||
<p>分享链接:
|
||||
<a href="{$vo.read_url}" target="_blank">{$vo.uid}</a>
|
||||
</p>
|
||||
<p>分享时间:{$vo.create_time}</p>
|
||||
<p>文件大小:{$vo.total_size_format}</p>
|
||||
<div>
|
||||
<span>文件列表:</span>
|
||||
<span class="layui-btn layui-btn-xs show-files">显示</span>
|
||||
<div class="files" style="display: none;">
|
||||
{volist name='vo.files' id='file'}
|
||||
<p>{$file.file_name}</p>
|
||||
{/volist}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<p>下载次数:{$vo.times_download}</p>
|
||||
<p>访问次数:{$vo.visit}</p>
|
||||
</td>
|
||||
<td>
|
||||
{empty name='vo.password'}
|
||||
无密码
|
||||
{else /}
|
||||
{$vo.password}
|
||||
{/empty}
|
||||
</td>
|
||||
<td>
|
||||
{empty name='vo.times'}
|
||||
无限制
|
||||
{else /}
|
||||
{$vo.times_last}/{$vo.times}
|
||||
{/empty}
|
||||
</td>
|
||||
<td>{$vo.expire_date}</td>
|
||||
<td>
|
||||
<div>
|
||||
<div class="layui-btn layui-btn-sm">立即下架</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{/volist}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
{/empty}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-row" style="margin-top: 15px;">
|
||||
<div class="footer">
|
||||
<span>{:get_system_config('site_copyright')}</span>
|
||||
<a href="http://www.beian.miit.gov.cn/">{:get_system_config('site_beian')}</a>
|
||||
<a href="{:get_system_config('site_safe_beian_url')}">{:get_system_config('site_safe_beian')}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: none;" class="tpl">
|
||||
@@ -272,6 +314,18 @@
|
||||
return false;
|
||||
})
|
||||
|
||||
$('.show-files').click(function () {
|
||||
var files = $(this).siblings('.files');
|
||||
|
||||
|
||||
if (files.is(':visible')) {
|
||||
files.hide()
|
||||
$(this).text('隐藏')
|
||||
} else {
|
||||
files.show()
|
||||
$(this).text('显示')
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
88
view/index/index/read.html
Normal file
88
view/index/index/read.html
Normal file
@@ -0,0 +1,88 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{:get_system_config('site_name')}</title>
|
||||
{include file='common/_require'/}
|
||||
|
||||
<!-- <link rel="stylesheet" href="/static/lib/webuploader/webuploader.css"> -->
|
||||
|
||||
<style>
|
||||
.webuploader-element-invisible {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.option-item {
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.file-progress {
|
||||
margin-right: 15px;
|
||||
}
|
||||
</style>
|
||||
<script src="/static/lib/webuploader/webuploader.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{include file='common/_header'/}
|
||||
<div class="layui-container" style="margin-top: 15px;;">
|
||||
<div class="layui-row">
|
||||
<div class="layui-col-md-offset3 layui-col-md6">
|
||||
|
||||
<div class="layui-card">
|
||||
<div class="layui-card-header">接收文件</div>
|
||||
<div class="layui-card-body">
|
||||
{notempty name='msg'}
|
||||
<blockquote class="layui-elem-quote layui-quote-nm">{$msg}</blockquote>
|
||||
{/notempty}
|
||||
<div class="file-list">
|
||||
{volist name='share_files' id='vo'}
|
||||
<div class="file-item">
|
||||
<div class="file-info">
|
||||
<span class="file-name">{$vo.file_name}</span>
|
||||
<span class="file-size">{$vo.file_size_format}</span>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
{/volist}
|
||||
</div>
|
||||
<div class="file-options" style="max-width: 300px;margin: 0 auto;">
|
||||
<form class="layui-form layui-form-pane" action="">
|
||||
<input type="hidden" name="do_download" value="1">
|
||||
{notempty name='$share.password'}
|
||||
<div class="layui-form-item">
|
||||
|
||||
<label class="layui-form-label">密码</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="password" value="" autocomplete="off" placeholder="请输入密码" class="layui-input">
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{/notempty}
|
||||
<div class="layui-form-item">
|
||||
<button class="layui-btn layui-btn-fluid submit" type="submit" lay-filter="submit" lay-submit>下载文件</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user