12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /*
- * This file is part of the Jiannei/lumen-api-starter.
- *
- * (c) Jiannei <longjian.huang@foxmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace App\Jobs;
- use App\Repositories\Models\User\Student;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Storage;
- use Illuminate\Support\Str;
- class ImportStudentJob extends Job
- {
- public $timeout = 1200;
- private $path = '';
- private $disk = '';
- /**
- * Create a new job instance.
- */
- public function __construct($disk, $path)
- {
- $this->disk = $disk;
- $this->path = $path;
- }
- /**
- * Execute the job.
- */
- public function handle()
- {
- $config = ['path' => ''];
- $excel = new \Vtiful\Kernel\Excel($config);
- $excel->openFile(Storage::disk($this->disk)->path($this->path))
- ->openSheet()
- ->setSkipRows(1);
- while (($row = $excel->nextRow()) !== NULL) {
- $sex = 0;
- switch ($row[3]) {
- case "男":
- case 'man':
- $sex = 1;
- break;
- case '女':
- case 'women':
- $sex = 2;
- break;
- }
- if (!empty($row[1])) {
- if (!Student::query()->where('account', $row[2])->exists()) {
- $data = [
- 'turename' => $row[1],
- 'account' => $row[2],
- 'faculty' => $row[6],
- 'class' => $row[7],
- 'mobile' => $row[4],
- 'period' => $row[5],
- 'password' => Str::random(6),
- 'sex' => $sex,
- ];
- Log::error(arr2str($data));
- Student::query()->create($data);
- }
- }
- }
- return true;
- }
- }
|