This commit is contained in:
2023-03-08 09:16:04 +08:00
commit e78454540f
1318 changed files with 210569 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Mall\Http\Exporter;
use Encore\Admin\Grid\Exporters\ExcelExporter;
use Maatwebsite\Excel\Facades\Excel;
class OrderExporter extends ExcelExporter
{
protected $fileName = '订单.xlsx';
protected $headings = [
'订单编号', '所属店铺', '下单用户', '商品金额', '运费', '发货数量', '订单金额', '订单状态', '订单类型',
'支付时间', '下单时间'
];
public function export()
{
$rows = [];
$rows[] = $this->headings;
$data = $this->getData();
if (count($data)) {
foreach ($data as $v) {
$rows[] = [
$v['order_no'],
$v['shop']['name'],
$v['user']['username'],
$v['amount'],
$v['freight'],
$v['items'][0]['qty'],
$v['total'],
$v['state'],
$v['type'],
$v['paid_at'],
$v['created_at'],
];
}
}
// 数据格式化
$export = new OrderFromArray($rows);
// 导出
return Excel::download($export, $this->fileName)->send();
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Modules\Mall\Http\Exporter;
use Maatwebsite\Excel\Concerns\FromArray;
/**
* Class OrderFromArray
* 不再使用 2.x 版本的导出工具。3.x 版本对 laravel-admin 的兼容有些问题,无法直接使用关联模型
* @package Modules\Mall\Http\Exporter
*/
class OrderFromArray implements FromArray
{
protected array $order;
public function __construct(array $order)
{
$this->order = $order;
}
public function array(): array
{
return $this->order;
}
}