add:新增模型导出
This commit is contained in:
parent
9baadccfbb
commit
a62020650c
@ -1,12 +1,70 @@
|
||||
<?php
|
||||
namespace catcher;
|
||||
|
||||
use catcher\library\excel\CatchExcel;
|
||||
use catcher\library\excel\Excel;
|
||||
use catcher\library\excel\ExcelContract;
|
||||
use think\model\Collection;
|
||||
|
||||
class CatchModelCollection extends Collection
|
||||
{
|
||||
/**
|
||||
* tree 结构
|
||||
*
|
||||
* @time 2020年10月21日
|
||||
* @param int $pid
|
||||
* @param string $pidField
|
||||
* @param string $children
|
||||
* @return array
|
||||
*/
|
||||
public function toTree($pid = 0, $pidField = 'parent_id', $children = 'children')
|
||||
{
|
||||
return Tree::done($this->items, $pid, $pidField, $children);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
*
|
||||
* @time 2020年10月21日
|
||||
* @param $header
|
||||
* @param string $path
|
||||
* @param string $disk
|
||||
* @throws \PhpOffice\PhpSpreadsheet\Exception
|
||||
* @return mixed|string[]
|
||||
*/
|
||||
public function export($header, $path = '', $disk = 'local')
|
||||
{
|
||||
$excel = new Class($header, $this->items) implements ExcelContract
|
||||
{
|
||||
protected $headers;
|
||||
|
||||
protected $sheets;
|
||||
|
||||
public function __construct($headers, $sheets)
|
||||
{
|
||||
$this->headers = $headers;
|
||||
|
||||
$this->sheets = $sheets;
|
||||
}
|
||||
|
||||
public function headers(): array
|
||||
{
|
||||
// TODO: Implement headers() method.
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
public function sheets()
|
||||
{
|
||||
// TODO: Implement sheets() method.
|
||||
return $this->sheets;
|
||||
}
|
||||
};
|
||||
|
||||
if (!$path) {
|
||||
$path = Utils::publicPath('exports');
|
||||
}
|
||||
|
||||
return (new Excel)->save($excel, $path, $disk);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user