海南旅游SAAS
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.
 
 
 

57 lines
1.1 KiB

<?php
namespace App\Exports;
use App\Models\ProductSpec;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
class ProductSpecExport implements FromQuery, WithHeadings
{
private int $product_id;
public function __construct(int $product_id)
{
$this->product_id = $product_id;
}
/**
* @return Collection
*/
public function query()
{
return ProductSpec::where([
['product_id', '=', $this->product_id],
['date', '>=', date('Y-m-d')],
])->orderBy('name')->orderBy('date');
}
public function prepareRows($rows)
{
return $rows->transform(function ($row) {
return [
'规格名称' => $row['name'],
'日期' => $row['date'],
'库存' => $row['stock'],
'市场价' => $row['original_price'],
'销售价' => $row['price'],
'成本价' => $row['cost_price'],
];
});
}
public function headings(): array
{
return [
'规格名称', '日期', '库存', '市场价', '销售价', '成本价',
];
}
public function columnFormats(): array
{
return [
'B' => 'yyyy/m/d',
];
}
}