1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Imports;
- use App\Models\AdminMerchant;
- use App\Models\AdminUserArea;
- use App\Models\Area;
- use App\Models\Bike;
- use App\Utils\Admin;
- use Illuminate\Support\Facades\Log;
- use Maatwebsite\Excel\Concerns\OnEachRow;
- use Maatwebsite\Excel\Concerns\ToModel;
- use Maatwebsite\Excel\Row;
- class BikesImport implements OnEachRow
- {
- /**
- * @param array $row
- *
- * @return
- */
- public function onRow(Row $row)
- {
- if ($row->getIndex() === 1) return true;
- $admin_id = Admin::user()->id;
- // $area = Area::query()->where('admin_id', $admin_id)->first();
- // 投放区域id 在导入excle时 默认为改该管理员第一个创建得区域id
- $put_area_id = 0;
- // if (!Admin::user()->isRole('administrator')) {
- // if (!empty($area)) {
- // $put_area_id = $area->id;
- // } else {
- // // 如果是普通管理员 则显示其自己管理的区域id
- //
- // $area_id = AdminUserArea::query()->where('admin_id', $admin_id)->first('area_id');
- // $put_area_id = $area_id->area_id ?? 0;
- //
- // }
- // }
- $row = $row->toArray();
- if (empty($row[0])) return false;
- return Bike::firstOrCreate([
- 'bike_no' => $row[0],//车辆编号
- ], [
- 'bike_no' => $row[0],//车辆编号
- // 'box_no' => $row[1],//控制设备
- 'put_area_id' => $put_area_id,
- 'merchant_id' => $row[1] ?? AdminMerchant::getMchId(),
- 'code_url' => $row[2] ? $row[2] . $row[0] : ''
- ]);
- }
- }
|