mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
fix: 修复无法导出的问题
This commit is contained in:
parent
8746caab06
commit
115b4aacb8
@ -3,10 +3,10 @@
|
|||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use Request;
|
use Request;
|
||||||
use Session;
|
|
||||||
use Response;
|
use Response;
|
||||||
use Madzipper;
|
use Madzipper;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Module\Down;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
use App\Module\Doo;
|
use App\Module\Doo;
|
||||||
@ -925,11 +925,10 @@ class ApproveController extends AbstractController
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (file_exists($zipPath)) {
|
if (file_exists($zipPath)) {
|
||||||
$base64 = base64_encode(Base::array2string([
|
$key = Down::cache_encode([
|
||||||
'file' => $zipFile,
|
'file' => $zipFile,
|
||||||
]));
|
]);
|
||||||
$fileUrl = Base::fillUrl('api/approve/down?key=' . urlencode($base64));
|
$fileUrl = Base::fillUrl('api/approve/down?key=' . $key);
|
||||||
Session::put('approve::export:userid', $user->userid);
|
|
||||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||||
'type' => 'file_download',
|
'type' => 'file_download',
|
||||||
'title' => '导出审批数据已完成',
|
'title' => '导出审批数据已完成',
|
||||||
@ -983,12 +982,7 @@ class ApproveController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
$userid = Session::get('approve::export:userid');
|
$array = Down::cache_decode();
|
||||||
if (empty($userid)) {
|
|
||||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
$array = Base::string2array(base64_decode(urldecode(Request::input('key'))));
|
|
||||||
$file = $array['file'];
|
$file = $array['file'];
|
||||||
if (empty($file) || !file_exists(storage_path($file))) {
|
if (empty($file) || !file_exists(storage_path($file))) {
|
||||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||||
|
|||||||
@ -12,10 +12,10 @@ use App\Models\FileLink;
|
|||||||
use App\Models\FileUser;
|
use App\Models\FileUser;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Module\Base;
|
use App\Module\Base;
|
||||||
|
use App\Module\Down;
|
||||||
use App\Module\Timer;
|
use App\Module\Timer;
|
||||||
use App\Module\Ihttp;
|
use App\Module\Ihttp;
|
||||||
use Response;
|
use Response;
|
||||||
use Session;
|
|
||||||
use Swoole\Coroutine;
|
use Swoole\Coroutine;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
@ -1016,14 +1016,8 @@ class FileController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function download__pack()
|
public function download__pack()
|
||||||
{
|
{
|
||||||
$key = Request::input('key');
|
if (Request::has('key')) {
|
||||||
if ($key) {
|
$array = Down::cache_decode();
|
||||||
$userid = Session::get('file::pack:userid');
|
|
||||||
if (empty($userid)) {
|
|
||||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
$array = Base::string2array(base64_decode(urldecode($key)));
|
|
||||||
$file = $array['file'];
|
$file = $array['file'];
|
||||||
if (empty($file) || !file_exists(storage_path($file))) {
|
if (empty($file) || !file_exists(storage_path($file))) {
|
||||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||||
@ -1091,11 +1085,10 @@ class FileController extends AbstractController
|
|||||||
return Base::retError('文件总大小已超过1GB,请分批下载');
|
return Base::retError('文件总大小已超过1GB,请分批下载');
|
||||||
}
|
}
|
||||||
|
|
||||||
$base64 = base64_encode(Base::array2string([
|
$key = Down::cache_encode([
|
||||||
'file' => $zipFile,
|
'file' => $zipFile,
|
||||||
]));
|
]);
|
||||||
$fileUrl = Base::fillUrl('api/file/download/pack?key=' . urlencode($base64));
|
$fileUrl = Base::fillUrl('api/file/download/pack?key=' . $key);
|
||||||
Session::put('file::pack:userid', $user->userid);
|
|
||||||
|
|
||||||
$zip = new \ZipArchive();
|
$zip = new \ZipArchive();
|
||||||
Base::makeDir(dirname($zipPath));
|
Base::makeDir(dirname($zipPath));
|
||||||
|
|||||||
@ -3,11 +3,11 @@
|
|||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use Request;
|
use Request;
|
||||||
use Session;
|
|
||||||
use Redirect;
|
use Redirect;
|
||||||
use Response;
|
use Response;
|
||||||
use Madzipper;
|
use Madzipper;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Module\Down;
|
||||||
use App\Module\Doo;
|
use App\Module\Doo;
|
||||||
use App\Models\File;
|
use App\Models\File;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@ -1292,7 +1292,7 @@ class ProjectController extends AbstractController
|
|||||||
->where('project_task_users.owner', 1)
|
->where('project_task_users.owner', 1)
|
||||||
->whereIn('project_task_users.userid', $userid)
|
->whereIn('project_task_users.userid', $userid)
|
||||||
->betweenTime(Carbon::parse($time[0])->startOfDay(), Carbon::parse($time[1])->endOfDay(), $type);
|
->betweenTime(Carbon::parse($time[0])->startOfDay(), Carbon::parse($time[1])->endOfDay(), $type);
|
||||||
$builder->orderByDesc('project_tasks.id')->chunk(100, function ($tasks) use (&$datas) {
|
$builder->orderByDesc('project_tasks.id')->chunk(100, function ($tasks) use ($doo, &$datas) {
|
||||||
/** @var ProjectTask $task */
|
/** @var ProjectTask $task */
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
$flowChanges = ProjectTaskFlowChange::whereTaskId($task->id)->get();
|
$flowChanges = ProjectTaskFlowChange::whereTaskId($task->id)->get();
|
||||||
@ -1446,11 +1446,10 @@ class ProjectController extends AbstractController
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (file_exists($zipPath)) {
|
if (file_exists($zipPath)) {
|
||||||
$base64 = base64_encode(Base::array2string([
|
$key = Down::cache_encode([
|
||||||
'file' => $zipFile,
|
'file' => $zipFile,
|
||||||
]));
|
]);
|
||||||
$fileUrl = Base::fillUrl('api/project/task/down?key=' . urlencode($base64));
|
$fileUrl = Base::fillUrl('api/project/task/down?key=' . $key);
|
||||||
Session::put('task::export:userid', $user->userid);
|
|
||||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||||
'type' => 'file_download',
|
'type' => 'file_download',
|
||||||
'title' => '导出任务统计已完成',
|
'title' => '导出任务统计已完成',
|
||||||
@ -1530,7 +1529,7 @@ class ProjectController extends AbstractController
|
|||||||
->whereNotNull('end_at')
|
->whereNotNull('end_at')
|
||||||
->where('end_at', '<=', Carbon::now())
|
->where('end_at', '<=', Carbon::now())
|
||||||
->orderBy('end_at')
|
->orderBy('end_at')
|
||||||
->chunk(100, function ($tasks) use (&$data) {
|
->chunk(100, function ($tasks) use ($doo, &$data) {
|
||||||
/** @var ProjectTask $task */
|
/** @var ProjectTask $task */
|
||||||
foreach ($tasks as $task) {
|
foreach ($tasks as $task) {
|
||||||
$taskStartTime = Carbon::parse($task->start_at ?: $task->created_at)->timestamp;
|
$taskStartTime = Carbon::parse($task->start_at ?: $task->created_at)->timestamp;
|
||||||
@ -1615,11 +1614,10 @@ class ProjectController extends AbstractController
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (file_exists($zipPath)) {
|
if (file_exists($zipPath)) {
|
||||||
$base64 = base64_encode(Base::array2string([
|
$key = Down::cache_encode([
|
||||||
'file' => $zipFile,
|
'file' => $zipFile,
|
||||||
]));
|
]);
|
||||||
$fileUrl = Base::fillUrl('api/project/task/down?key=' . urlencode($base64));
|
$fileUrl = Base::fillUrl('api/project/task/down?key=' . $key);
|
||||||
Session::put('task::export:userid', $user->userid);
|
|
||||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||||
'type' => 'file_download',
|
'type' => 'file_download',
|
||||||
'title' => '导出超期任务已完成',
|
'title' => '导出超期任务已完成',
|
||||||
@ -1661,12 +1659,7 @@ class ProjectController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function task__down()
|
public function task__down()
|
||||||
{
|
{
|
||||||
$userid = Session::get('task::export:userid');
|
$array = Down::cache_decode();
|
||||||
if (empty($userid)) {
|
|
||||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
$array = Base::string2array(base64_decode(urldecode(Request::input('key'))));
|
|
||||||
$file = $array['file'];
|
$file = $array['file'];
|
||||||
if (empty($file) || !file_exists(storage_path($file))) {
|
if (empty($file) || !file_exists(storage_path($file))) {
|
||||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||||
|
|||||||
@ -6,8 +6,8 @@ use App\Models\UserDevice;
|
|||||||
use App\Models\WebSocketDialog;
|
use App\Models\WebSocketDialog;
|
||||||
use App\Models\WebSocketDialogMsg;
|
use App\Models\WebSocketDialogMsg;
|
||||||
use App\Module\AI;
|
use App\Module\AI;
|
||||||
|
use App\Module\Down;
|
||||||
use Request;
|
use Request;
|
||||||
use Session;
|
|
||||||
use Response;
|
use Response;
|
||||||
use Madzipper;
|
use Madzipper;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
@ -1465,11 +1465,10 @@ class SystemController extends AbstractController
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (file_exists($zipPath)) {
|
if (file_exists($zipPath)) {
|
||||||
$base64 = base64_encode(Base::array2string([
|
$key = Down::cache_encode([
|
||||||
'file' => $zipFile,
|
'file' => $zipFile,
|
||||||
]));
|
]);
|
||||||
$fileUrl = Base::fillUrl('api/system/checkin/down?key=' . urlencode($base64));
|
$fileUrl = Base::fillUrl('api/system/checkin/down?key=' . $key);
|
||||||
Session::put('checkin::export:userid', $user->userid);
|
|
||||||
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
WebSocketDialogMsg::sendMsg(null, $dialog->id, 'template', [
|
||||||
'type' => 'file_download',
|
'type' => 'file_download',
|
||||||
'title' => '导出签到数据已完成',
|
'title' => '导出签到数据已完成',
|
||||||
@ -1511,12 +1510,7 @@ class SystemController extends AbstractController
|
|||||||
*/
|
*/
|
||||||
public function checkin__down()
|
public function checkin__down()
|
||||||
{
|
{
|
||||||
$userid = Session::get('checkin::export:userid');
|
$array = Down::cache_decode();
|
||||||
if (empty($userid)) {
|
|
||||||
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
$array = Base::string2array(base64_decode(urldecode(Request::input('key'))));
|
|
||||||
$file = $array['file'];
|
$file = $array['file'];
|
||||||
if (empty($file) || !file_exists(storage_path($file))) {
|
if (empty($file) || !file_exists(storage_path($file))) {
|
||||||
return Base::ajaxError("文件不存在!", [], 0, 403);
|
return Base::ajaxError("文件不存在!", [], 0, 403);
|
||||||
|
|||||||
@ -25,8 +25,11 @@ class Doo
|
|||||||
return RequestContext::get(self::DOO_INSTANCE);
|
return RequestContext::get(self::DOO_INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$token = $token ?: Base::token();
|
$request = request();
|
||||||
$language = $language ?: Base::headerOrInput('language');
|
if ($request && method_exists($request, 'header')) {
|
||||||
|
$token = $token ?: Base::token();
|
||||||
|
$language = $language ?: Base::headerOrInput('language');
|
||||||
|
}
|
||||||
$instance = new DooSo($token, $language);
|
$instance = new DooSo($token, $language);
|
||||||
|
|
||||||
RequestContext::set(self::DOO_INSTANCE, $instance);
|
RequestContext::set(self::DOO_INSTANCE, $instance);
|
||||||
|
|||||||
37
app/Module/Down.php
Normal file
37
app/Module/Down.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Module;
|
||||||
|
|
||||||
|
use Request;
|
||||||
|
use Cache;
|
||||||
|
|
||||||
|
class Down
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param $data
|
||||||
|
* @param null $ttl
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function cache_encode($data, $ttl = null): string
|
||||||
|
{
|
||||||
|
$base64 = base64_encode(Base::array2string($data));
|
||||||
|
$key = md5($base64);
|
||||||
|
Cache::put("down::{$key}", $base64, $ttl ?: now()->addHour());
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ?string $inputName
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function cache_decode(?string $inputName = 'key'): array
|
||||||
|
{
|
||||||
|
$key = Request::input($inputName);
|
||||||
|
$base64 = Cache::get("down::{$key}");
|
||||||
|
if (empty($base64)) {
|
||||||
|
return Base::ajaxError("请求已过期,请重新导出!", [], 0, 403);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
return Base::string2array(base64_decode($base64));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user