12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?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\Base\Admin;
- use App\Repositories\Models\Mentor\Teacher;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Storage;
- class ImportTeacherJob 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) {
- list(
- $account,
- $truename,
- $mobile,
- $sex_index,
- ) = $row;
- if (($account && $truename && $mobile)) {
- $sex = 0;
- switch ($sex_index) {
- case "男":
- case 'man':
- $sex = 1;
- break;
- case '女':
- case 'women':
- $sex = 2;
- break;
- }
- $data = [
- 'truename' => $truename,
- 'account' => $account,
- 'mobile' => $mobile,
- 'password' => $account,
- 'sex' => $sex,
- ];
- Log::warning($account);
- if (!Admin::query()->where('account', $account)->exists()) {
- Teacher::query()->create($data);
- }
- }
- }
- return true;
- }
- }
|