first
This commit is contained in:
49
modules/Mall/Http/Exporter/OrderExporter.php
Normal file
49
modules/Mall/Http/Exporter/OrderExporter.php
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
27
modules/Mall/Http/Exporter/OrderFromArray.php
Normal file
27
modules/Mall/Http/Exporter/OrderFromArray.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user