You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
<?php
|
|
|
|
namespace App\AdminSupplier\Forms;
|
|
|
|
use App\Jobs\ImportProductFromExcel;
|
|
use Dcat\Admin\Widgets\Form;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class ExcelImport extends Form
|
|
{
|
|
/**
|
|
* Handle the form request.
|
|
*
|
|
* @param array $input
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle(array $input)
|
|
{
|
|
foreach ($input['zip_file'] as $zip_file) {
|
|
/*# 使用md5_file来重命名文件,保证唯一
|
|
$to_path = str_replace(basename($zip_file), '', $zip_file);
|
|
$to_path .= md5_file(Storage::disk('public')->path($zip_file)) . '.zip';
|
|
Storage::disk('public')->move($zip_file, $to_path);*/
|
|
ImportProductFromExcel::dispatch(\Admin::user()->id, Storage::disk('public')->path($zip_file));
|
|
}
|
|
|
|
return $this->response()->success('操作成功,导入产品可能需要几分钟,请勿重复导入,请耐心等待')->refresh();
|
|
}
|
|
|
|
/**
|
|
* Build a form here.
|
|
*/
|
|
public function form()
|
|
{
|
|
$this->multipleFile('zip_file', 'ZIP文件')
|
|
->help('注意:请上传zip文件,上传文件大小不能超过' . ini_get('upload_max_filesize') .
|
|
'。<a href="' . Storage::disk('public')->url('import.zip') . '" target="_blank">文件导入模板</a>')
|
|
->accept('zip')
|
|
->uniqueName()->autoUpload()->required();
|
|
}
|
|
|
|
/**
|
|
* The data of the form.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function default()
|
|
{
|
|
return [];
|
|
}
|
|
}
|