51 lines
2.4 KiB
PHP
51 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Support\DropshipFreight;
|
|
|
|
use App\Support\CourierBills\StreamingWorkbook;
|
|
|
|
/** 导出各厂家汇总,数据直接复用页面汇总结果,不导出逐单明细。 */
|
|
final class DropshipOverviewExporter
|
|
{
|
|
public static function headers(): array
|
|
{
|
|
return ['厂家', ...array_values(DropshipFees::COLUMNS), '合计运费', '备注', '代发仓', '关键字',
|
|
'厂家开运费单数', '厂家运费', '结算运费', '差额', '运费有差·厂家多开', '运费有差·厂家少开',
|
|
'厂家未提供(不付)', '其他要看的', '厂家确认'];
|
|
}
|
|
|
|
/** @param resource $output */
|
|
public function write(array $data, $output): void
|
|
{
|
|
$book = new StreamingWorkbook();
|
|
$book->row('各厂家汇总', self::headers(), true);
|
|
foreach ($data['dfRows'] as $row) {
|
|
$fee = $data['dfFees'][$row['factory_id']];
|
|
$amounts = [];
|
|
foreach (array_keys(DropshipFees::COLUMNS) as $key) {
|
|
$value = (float) $fee['values'][$key];
|
|
$amounts[] = $value == 0 ? null : ($key === 'booking' ? -$value : $value);
|
|
}
|
|
$notes = $fee['note'];
|
|
if ($fee['other'] !== []) {
|
|
$other = [];
|
|
foreach ($fee['other'] as $type => $amount) $other[] = $type . ' ' . number_format($amount, 2);
|
|
$notes .= ($notes !== '' ? "\n" : '') . '未归类附加费(不计入合计):' . implode('、', $other);
|
|
}
|
|
$book->row('各厂家汇总', [$row['factory'], ...$amounts, $fee['total'], $notes, $row['warehouse'], $row['keywords'],
|
|
$row['billed'], $row['bill'], $row['settle'], $row['diff'], $row['over'], $row['under'],
|
|
$row['counts']['unprovided'], $row['attention'] - $row['counts']['diff'],
|
|
DropshipConfirmation::label($data['dfStates'][$row['factory_id']] ?? null)]);
|
|
}
|
|
if ($data['dfRows'] !== []) {
|
|
$totals = [];
|
|
foreach (array_keys(DropshipFees::COLUMNS) as $key) {
|
|
$value = (float) ($data['dfFeeTotals'][$key] ?? 0);
|
|
$totals[] = $value == 0 ? null : ($key === 'booking' ? -$value : $value);
|
|
}
|
|
$book->row('各厂家汇总', ['合计', ...$totals, $data['dfFeeTotals']['total'], ...array_fill(0, 12, null)], true);
|
|
}
|
|
$book->writeTo($output);
|
|
}
|
|
}
|