51 lines
1.5 KiB
PHP
51 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Imports;
|
|
|
|
use App\Models\Mobile as MobileModel;
|
|
use Illuminate\Support\Collection;
|
|
use Maatwebsite\Excel\Concerns\ToCollection;
|
|
use RuLong\Area\Models\Area;
|
|
|
|
class Mobile implements ToCollection
|
|
{
|
|
|
|
public function collection(Collection $rows)
|
|
{
|
|
$operators = [
|
|
'移动号码' => 'mobile',
|
|
'联通号码' => 'unicom',
|
|
'电信号码' => 'telecom',
|
|
];
|
|
unset($rows[0]);
|
|
$lists = [];
|
|
foreach ($rows as $row) {
|
|
$area = Area::where('name', $row['5'])->first();
|
|
$data = [
|
|
'number' => (string) $row[0] ?: '', //手机号
|
|
'begin' => substr($row[1], 0, 3), //号段
|
|
'type' => $row[2], //靓号类型
|
|
'charge' => $row[3] ?: 0, //服务费
|
|
'price' => $row[4] ?: 0, //低消
|
|
'province_sn' => $area->psn ?: null,
|
|
'city_sn' => $area->sn ?: null,
|
|
'operator' => $operators[$row[6]] ?: null, //运营商
|
|
'city_name' => $row[5],
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
];
|
|
|
|
$info = MobileModel::where('number', $data['number'])->first();
|
|
if ($info) {
|
|
$info->update($data);
|
|
} else {
|
|
$lists[] = $data;
|
|
}
|
|
}
|
|
if (count($lists) > 0) {
|
|
MobileModel::insert($lists);
|
|
}
|
|
}
|
|
|
|
}
|