This repository has been archived on 2020-11-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
pingan/app/Admin/Imports/User.php
2020-08-06 16:37:53 +08:00

39 lines
826 B
PHP

<?php
namespace App\Admin\Imports;
use App\Models\User as UserModel;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
class User implements ToCollection
{
public function collection(Collection $rows)
{
$error = [];
foreach ($rows as $row) {
$user = UserModel::whereHas('info', function ($q) use ($row) {
$q->where('nickname', $row[1]);
})->where('type', 'pingan')->whereNull('PaOutletId')->first();
if ($user) {
$user->PaOutletId = $row[2];
$user->save();
} else {
$error[] = $row['1'];
}
}
if (count($error) > 0) {
dd($error);
return implode(' ,', $error);
}
return true;
}
}