CaiWuXiTong/app/Imports/Sales/Customers.php
WuYongJie 9595267ee7
Some checks failed
Tests / PHP 8.1 (push) Has been cancelled
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
chore: 导入 Akaunting 初始源码与团队协作规则
2026-07-20 18:20:25 +08:00

50 lines
1.2 KiB
PHP

<?php
namespace App\Imports\Sales;
use App\Abstracts\Import;
use App\Http\Requests\Common\Contact as Request;
use App\Models\Common\Contact as Model;
class Customers extends Import
{
public $request_class = Request::class;
public $model = Model::class;
public $columns = [
'type',
'name',
'email',
];
public function model(array $row)
{
if (self::hasRow($row)) {
return;
}
return new Model($row);
}
public function map($row): array
{
$row = parent::map($row);
// Uploaded file may not include a country column.
$country = ! empty($row['country']) ? array_search($row['country'], trans('countries')) : false;
$row['type'] = 'customer';
$row['country'] = !empty($country) ? $country : null;
$row['category_id'] = $this->getCategoryId($row, 'income');
$row['currency_code'] = $this->getCurrencyCode($row);
$row['user_id'] = null;
if (isset($row['can_login']) && isset($row['email'])) {
$row['user_id'] = user_model_class()::where('email', $row['email'])->first()?->id ?? null;
}
return $row;
}
}