1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace App\Imports;
- use App\Models\BoxBinding;
- use Illuminate\Support\Facades\Log;
- use Maatwebsite\Excel\Concerns\OnEachRow;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Row;
- class BoxBindingImport implements OnEachRow
- {
- // /**
- // * @param array $row
- // *
- // * @return \Illuminate\Database\Eloquent\Model|null 批量导入
- // */
- // public function model(array $row)
- // {
- // return new BoxBinding([
- // //
- // 'box_no' => $row[0]
- // ]);
- // }
- /**
- * 逐条插入
- * */
- public function onRow(Row $row)
- {
- $rowIndex = $row->getIndex();
- $row = $row->toArray();
- // Log::info($rowIndex);
- if ($rowIndex === 1) return false;
- if (!$row[1]) return false;
- return BoxBinding::updateOrCreate([
- 'box_no' => $row[1],
- ], [
- 'batch' => $row[0],
- 'box_no' => $row[1],
- 'device_xing' => $row[2],
- 'imei_no' => $row[3],
- 'sim_no' => $row[4],
- 'imsi_no' => $row[5],
- 'iccid_no' => $row[6],
- ]);
- }
- }
|