重复车架处理后保存源信息2

master
zhaocheng 2 years ago
parent dff5827e4c
commit 98e2e8f962
  1. 0
      app/model/ExportLogT.php.bak
  2. 35
      extend/service/CarInfoHandle.php

@ -260,21 +260,14 @@ 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_phone', $item->phone)->where($map)->column('id'); $ids = CarInfoT::where('car_phone', $item->phone)->column('id');
Db::startTrans(); Db::startTrans();
try { try {
CarInfoT::where('id', 'in', $ids) CarInfoT::where('id', 'in', $ids)
@ -329,31 +322,32 @@ class CarInfoHandle
try { try {
foreach ($sources as $index => $source) { foreach ($sources as $index => $source) {
if (empty(trim($source['car_phone']))) { if (empty(trim($source['car_phone']))) {
$ids = array_column($sources, 'id'); foreach ($sources as $source_data) {
CarInfoT::destroy($ids); $this->repeatDataHandle($source_data, $id, 'frame');
}
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete(); RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete();
$sources = []; $sources = [];
break; break;
} else if ($source_a['car_phone'] == $source['car_phone']) { } else if ($source_a['car_phone'] == $source['car_phone']) {
if ($source_a['insurer1_date'] != $source['insurer1_date'] && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) { if ($source_a['insurer1_date'] != $source['insurer1_date'] && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) {
list($source_a, $source) = [$source, $source_a]; list($source_a, $source) = [$source, $source_a];
CarInfoT::destroy($source['id']); $this->repeatDataHandle($source, $id, 'frame');
unset($sources[$index]); unset($sources[$index]);
} else if ($source_a['insurer2_date'] != $source['insurer2_date'] && (trim($source_a['insurer2_date']) == '' || $source_a['insurer2_date'] < $source['insurer2_date'])) { } else if ($source_a['insurer2_date'] != $source['insurer2_date'] && (trim($source_a['insurer2_date']) == '' || $source_a['insurer2_date'] < $source['insurer2_date'])) {
list($source_a, $source) = [$source, $source_a]; list($source_a, $source) = [$source, $source_a];
CarInfoT::destroy($source['id']); $this->repeatDataHandle($source, $id, 'frame');
unset($sources[$index]); unset($sources[$index]);
} else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(strlen($source_a['car_no']), [7,8]))) { } else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(strlen($source_a['car_no']), [7,8]))) {
list($source_a, $source) = [$source, $source_a]; list($source_a, $source) = [$source, $source_a];
CarInfoT::destroy($source['id']); $this->repeatDataHandle($source, $id, 'frame');
unset($sources[$index]); unset($sources[$index]);
} }
if (isset($sources[$index])) { if (isset($sources[$index])) {
CarInfoT::destroy($source['id']); $this->repeatDataHandle($source, $id, 'frame');
unset($sources[$index]); unset($sources[$index]);
} }
} else if (!preg_match('/^1[3-9][0-9]{9}/', $source['car_phone'])) { } else if (!preg_match('/^1[3-9][0-9]{9}/', $source['car_phone'])) {
CarInfoT::destroy($source['id']); $this->repeatDataHandle($source, $id, 'frame');
unset($sources[$index]); unset($sources[$index]);
} else { } else {
$phones = [$source['car_phone']]; $phones = [$source['car_phone']];
@ -375,6 +369,7 @@ class CarInfoHandle
break; break;
} }
CarInfoT::where('id', $source_a['id'])->update($source_a); CarInfoT::where('id', $source_a['id'])->update($source_a);
$this->repeatDataHandle($source, $id, 'frame');
CarInfoT::destroy($source['id']); CarInfoT::destroy($source['id']);
unset($sources[$index]); unset($sources[$index]);
} }
@ -491,6 +486,14 @@ class CarInfoHandle
跳过数据列:" . implode(',', $statistical_information['total_skip_arr']); 跳过数据列:" . implode(',', $statistical_information['total_skip_arr']);
} }
private function repeatDataHandle($data, $id, $type)
{
if ($type == 'frame') {
CarInfoT::destroy($data['id']);
}
}
private function importExcel($data, $id) private function importExcel($data, $id)
{ {
$filename = public_path('public/storage') . $data['filename']; $filename = public_path('public/storage') . $data['filename'];

Loading…
Cancel
Save