[新增] first commit
This commit is contained in:
39
app/Admin/Imports/User.php
Normal file
39
app/Admin/Imports/User.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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]);
|
||||
})->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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user