ufutx.dma/app/Exports/NurtureShopsExport.php
2026-03-04 14:42:40 +08:00

47 lines
1.6 KiB
PHP

<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class NurtureShopsExport implements FromCollection, WithHeadings
{
protected $shops;
public function __construct($shops)
{
$this->shops = $shops;
}
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
$rows = [];
$shops = $this->shops;
foreach ($shops as $shop)
{
$sku_name ='';
$freight = '';
$price = '';
foreach ($shop['sku'] as $sku) {
$sku_name .= $sku['name'] . "/" . $sku["stock"] . ' | ';
if (isset($sku['ship_num'])) {
$ready_agent_price = $sku['ready_agent_price']??"";
$freight .= "{$sku['ship_num']}{$sku['ship_price']}元,每增加一件{$sku['ship_each_price']}元,最高{$sku['ship_max_price']}元 | ";
$price .= "{$sku["price"]}/{$ready_agent_price}/{$sku['agent_price']}/{$sku['staff_price']} | ";
}
}
$rows[] = ['id'=>$shop['id'], 'name'=>$shop['icon'], 'title'=>$shop['title'], 'sku_name'=>$sku_name, "price"=>$price, 'freight'=>$freight, 'is_show'=>$shop['shop_nurture']['is_show']?"上架":"下架"];
}
return collect($rows);
}
public function headings(): array
{
return [
['id','商品图片','商品名称', '规格名称/库存', "客户价/准批发商价/批发商价格/员工价", '邮费', "上架状态"]
];
}
}