|
|
@ -29,35 +29,7 @@ class CarInfoHandle |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function import($data, $id) |
|
|
|
public function import($data, $id) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(pathinfo($data['filename'])['extension'] != 'csv'){ |
|
|
|
return $this->importExcel($data, $id); |
|
|
|
return '操作失败:上传文件必须为csv文件'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$filename = public_path('public/storage') . $data['filename']; |
|
|
|
|
|
|
|
$lines = FileSystem::getTxtFileLines($filename); |
|
|
|
|
|
|
|
echo '总计:' . $lines . PHP_EOL; |
|
|
|
|
|
|
|
cache('shell_process_' . $id, 0, 300); |
|
|
|
|
|
|
|
Db::execute('ALTER TABLE car_info_t DISABLE KEYS;'); |
|
|
|
|
|
|
|
for ($i = 2; $i < $lines; $i += 2000) { |
|
|
|
|
|
|
|
$insert_data = FileSystem::getFileBlockData($filename, $i, $i + 1999, function ($str) use ($id) { |
|
|
|
|
|
|
|
$keys = ['duty_no', 'register_date', 'car_man', 'car_number', 'car_phone', 'car_frame_no', 'car_no', 'engine_no', 'factory_model', 'purchase_price', 'source']; |
|
|
|
|
|
|
|
$keys_len = count($keys); |
|
|
|
|
|
|
|
$arr = explode(',', $str); |
|
|
|
|
|
|
|
array_walk($arr, function (&$value, $key) { |
|
|
|
|
|
|
|
$value = trim(trim($value, '"')); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
$values = array_slice($arr, 0, $keys_len); |
|
|
|
|
|
|
|
$values[$keys_len - 1] = $id; |
|
|
|
|
|
|
|
$data = array_combine($keys, $values); |
|
|
|
|
|
|
|
$data['register_date'] = date('Y-m-d', strtotime($data['register_date'])); |
|
|
|
|
|
|
|
return $data; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Db::name('car_info_t')->insertAll($insert_data); |
|
|
|
|
|
|
|
cache('shell_process_' . $id, round(($i + 2000) / $lines * 100, 3), 300); |
|
|
|
|
|
|
|
echo '当前进度:' . round(round(($i + 2000) / $lines * 100, 3)) . PHP_EOL; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Db::execute('ALTER TABLE car_info_t ENABLE KEYS;'); |
|
|
|
|
|
|
|
return '导入成功:' . ($lines - 1); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -336,26 +308,64 @@ class CarInfoHandle |
|
|
|
echo '总计:' . $count . PHP_EOL; |
|
|
|
echo '总计:' . $count . PHP_EOL; |
|
|
|
$current = 0; |
|
|
|
$current = 0; |
|
|
|
$faild_num = 0; |
|
|
|
$faild_num = 0; |
|
|
|
$map = []; |
|
|
|
|
|
|
|
if (isset($data['export_date1']) && $data['export_date1'] != '') { |
|
|
|
|
|
|
|
$map[] = ['register_date', '>=', $data['export_date1']]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (isset($data['export_date2']) && $data['export_date2'] != '') { |
|
|
|
|
|
|
|
$map[] = ['register_date', '<=', $data['export_date2']]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cache('shell_process_' . $id, 0, 300); |
|
|
|
cache('shell_process_' . $id, 0, 300); |
|
|
|
$query->chunk(1000, function ($infos) use (&$current, &$faild_num, $count, $id, $map) { |
|
|
|
$query->chunk(1000, function ($infos) use (&$current, &$faild_num, $count, $id) { |
|
|
|
foreach ($infos as $item) { |
|
|
|
foreach ($infos as $item) { |
|
|
|
if ($current % 10 == 0) { |
|
|
|
if ($current % 10 == 0) { |
|
|
|
cache('shell_process_' . $id, round($current / $count * 100, 3), 300); |
|
|
|
cache('shell_process_' . $id, round($current / $count * 100, 3), 300); |
|
|
|
echo '当前进度:' . round($current / $count * 100, 3) . PHP_EOL; |
|
|
|
echo '当前进度:' . round($current / $count * 100, 3) . PHP_EOL; |
|
|
|
} |
|
|
|
} |
|
|
|
$ids = CarInfoT::where(['car_frame_no' => $item->car_frame_no])->where($map)->order('car_phone desc, insurer1_date desc, car_no desc, id desc')->column('id'); |
|
|
|
$sources = CarInfoT::where(['car_frame_no' => $item->car_frame_no]) |
|
|
|
array_shift($ids); |
|
|
|
->order('car_phone desc, insurer1_date desc, car_no desc, id desc')->select(); |
|
|
|
|
|
|
|
if ($sources->isEmpty()) |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
$sources = $sources->toArray(); |
|
|
|
|
|
|
|
$source_a = null; |
|
|
|
|
|
|
|
foreach ($sources as $index => &$source) { |
|
|
|
|
|
|
|
$source['car_phone'] = trim($source['car_phone']); |
|
|
|
|
|
|
|
if (preg_match('/^1[3-9][0-9]{9}/', $source['car_phone'])) { |
|
|
|
|
|
|
|
$source_a = $source; |
|
|
|
|
|
|
|
array_splice($sources, $index, 1); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (empty($source_a)) { |
|
|
|
|
|
|
|
$source_a = $sources[0]; |
|
|
|
|
|
|
|
array_shift($sources); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Db::startTrans(); |
|
|
|
Db::startTrans(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
CarInfoT::destroy($ids); |
|
|
|
foreach ($sources as $index => $source) { |
|
|
|
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete(); |
|
|
|
if (empty(trim($source['car_phone']))) { |
|
|
|
|
|
|
|
$ids = array_column($sources, 'id'); |
|
|
|
|
|
|
|
CarInfoT::destroy($ids); |
|
|
|
|
|
|
|
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete(); |
|
|
|
|
|
|
|
$sources = []; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else if ($source_a['car_phone'] == $source['car_phone']) { |
|
|
|
|
|
|
|
foreach (['car_no', 'engine_no', 'insurer1_date'] as $key) { |
|
|
|
|
|
|
|
if ($source_a[$key] != $source[$key]) { |
|
|
|
|
|
|
|
if (trim($source_a[$key]) == '') { |
|
|
|
|
|
|
|
list($source_a, $source) = [$source, $source_a]; |
|
|
|
|
|
|
|
CarInfoT::destroy($source['id']); |
|
|
|
|
|
|
|
unset($sources[$index]); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else if (!preg_match('/^1[3-9][0-9]{9}/', $source['car_phone'])) { |
|
|
|
|
|
|
|
CarInfoT::destroy($source['id']); |
|
|
|
|
|
|
|
unset($sources[$index]); |
|
|
|
|
|
|
|
} else if (CarInfoT::where('car_phone', $source['car_phone'])->count() >= 6) { |
|
|
|
|
|
|
|
CarInfoT::destroy($source['id']); |
|
|
|
|
|
|
|
CarInfoT::where('car_phone', $source['car_phone'])->update(['car_phone' => '']); |
|
|
|
|
|
|
|
unset($sources[$index]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (empty($sources)) |
|
|
|
|
|
|
|
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete(); |
|
|
|
Db::commit(); |
|
|
|
Db::commit(); |
|
|
|
} catch (\Exception $e) { |
|
|
|
} catch (\Exception $e) { |
|
|
|
$faild_num++; |
|
|
|
$faild_num++; |
|
|
@ -487,16 +497,24 @@ class CarInfoHandle |
|
|
|
'engine_no' => $worksheet->getCellByColumnAndRow(8, $row)->getValue(), |
|
|
|
'engine_no' => $worksheet->getCellByColumnAndRow(8, $row)->getValue(), |
|
|
|
'factory_model' => $worksheet->getCellByColumnAndRow(9, $row)->getValue(), |
|
|
|
'factory_model' => $worksheet->getCellByColumnAndRow(9, $row)->getValue(), |
|
|
|
'purchase_price' => $worksheet->getCellByColumnAndRow(10, $row)->getValue(), |
|
|
|
'purchase_price' => $worksheet->getCellByColumnAndRow(10, $row)->getValue(), |
|
|
|
|
|
|
|
'insurer1_date' => $worksheet->getCellByColumnAndRow(11, $row)->getValue(), |
|
|
|
|
|
|
|
'insurer2_date' => $worksheet->getCellByColumnAndRow(12, $row)->getValue(), |
|
|
|
'create_timestamp' => $now, |
|
|
|
'create_timestamp' => $now, |
|
|
|
'update_timestamp' => $now |
|
|
|
'update_timestamp' => $now |
|
|
|
]; |
|
|
|
]; |
|
|
|
if ($row >= 1000) { |
|
|
|
if (count($row_array) > 1000) { |
|
|
|
Db::name('car_info_t')->insertAll($row_array); |
|
|
|
Db::name('car_info_t')->insertAll($row_array); |
|
|
|
cache('shell_process_' . $id, round(($row - 1) / $highestRow * 100, 3), 300); |
|
|
|
cache('shell_process_' . $id, round(($row - 1) / $highestRow * 100, 3), 300); |
|
|
|
echo '当前进度:' . round(round(($row - 1) / $highestRow * 100, 3)) . PHP_EOL; |
|
|
|
echo '当前进度:' . round(round(($row - 1) / $highestRow * 100, 3)) . PHP_EOL; |
|
|
|
$row_array = []; |
|
|
|
$row_array = []; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (count($row_array) > 0) { |
|
|
|
|
|
|
|
Db::name('car_info_t')->insertAll($row_array); |
|
|
|
|
|
|
|
cache('shell_process_' . $id, round(($row - 1) / $highestRow * 100, 3), 300); |
|
|
|
|
|
|
|
echo '当前进度:' . round(round(($row - 1) / $highestRow * 100, 3)) . PHP_EOL; |
|
|
|
|
|
|
|
$row_array = []; |
|
|
|
|
|
|
|
} |
|
|
|
Db::execute('ALTER TABLE car_info_t ENABLE KEYS;'); |
|
|
|
Db::execute('ALTER TABLE car_info_t ENABLE KEYS;'); |
|
|
|
$t2 = microtime(true); |
|
|
|
$t2 = microtime(true); |
|
|
|
echo '耗时' . round($t2 - $t1, 3) . '秒' . PHP_EOL; |
|
|
|
echo '耗时' . round($t2 - $t1, 3) . '秒' . PHP_EOL; |
|
|
|