重复车架删除逻辑调整

master
zhaocheng 2 years ago
parent cf243297fc
commit d0a4023504
  1. 102
      extend/service/CarInfoHandle.php

@ -313,7 +313,7 @@ class CarInfoHandle
echo '当前进度:' . round($current / $count * 100, 3) . PHP_EOL; echo '当前进度:' . round($current / $count * 100, 3) . PHP_EOL;
} }
$sources = CarInfoT::where(['car_frame_no' => $item->car_frame_no]) $sources = CarInfoT::where(['car_frame_no' => $item->car_frame_no])
->order('car_phone desc, insurer1_date desc, car_no desc, id desc')->select(); ->order('car_phone desc, id desc')->select();
if ($sources->isEmpty()) if ($sources->isEmpty())
continue; continue;
$sources = $sources->toArray(); $sources = $sources->toArray();
@ -329,81 +329,14 @@ class CarInfoHandle
if (empty($source_a)) { if (empty($source_a)) {
$source_a = $sources[0]; $source_a = $sources[0];
array_shift($sources); array_shift($sources);
} } Db::startTrans();
Db::startTrans();
try { try {
$car_phone_a_valid = preg_match('/^1[3-9][0-9]{9}/', $source_a['car_phone']);
foreach ($sources as $index => $source) { foreach ($sources as $index => $source) {
if (empty(trim($source['car_phone']))) { $car_phone_valid = preg_match('/^1[3-9][0-9]{9}/', $source['car_phone']);
foreach ($sources as $source_data) { // 当不是标准有效对比无效的情况下,要进行数据对比替换
if (trim($source_a['insurer1_date']) != trim($source['insurer1_date']) && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) { if (!($car_phone_a_valid && !$car_phone_valid)) {
list($source_a, $source) = [$source, $source_a]; if ($car_phone_a_valid && $car_phone_valid) { // 都有效更新电话
} else if (trim($source_a['insurer2_date']) != trim($source['insurer2_date']) && (trim($source_a['insurer2_date']) == '' || $source_a['insurer2_date'] < $source['insurer2_date'])) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(mb_strlen($source_a['car_no']), [7,8]))) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['register_date'] != $source['register_date'] && (trim($source_a['register_date']) == '' || $source_a['register_date'] < $source['register_date'])) {
list($source_a, $source) = [$source, $source_a];
}
$this->repeatDataHandle($source_data, $id, 'frame');
$delete_num ++;
}
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete();
$sources = [];
break;
} else if ($source_a['car_phone'] == $source['car_phone']) {
if (trim($source_a['insurer1_date']) != trim($source['insurer1_date']) && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) {
list($source_a, $source) = [$source, $source_a];
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
} else if (trim($source_a['insurer2_date']) != trim($source['insurer2_date']) && (trim($source_a['insurer2_date']) == '' || $source_a['insurer2_date'] < $source['insurer2_date'])) {
list($source_a, $source) = [$source, $source_a];
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
} else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(mb_strlen($source_a['car_no']), [7,8]))) {
list($source_a, $source) = [$source, $source_a];
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
} else if ($source_a['register_date'] != $source['register_date'] && (trim($source_a['register_date']) == '' || $source_a['register_date'] < $source['register_date'])) {
list($source_a, $source) = [$source, $source_a];
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
}
if (isset($sources[$index])) {
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
}
} else if (!preg_match('/^1[3-9][0-9]{9}/', $source['car_phone'])) {
if (preg_match('/^1[3-9][0-9]{9}/', $source_a['car_phone'])) {
} else if (trim($source_a['insurer1_date']) != trim($source['insurer1_date']) && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) {
list($source_a, $source) = [$source, $source_a];
} else if (trim($source_a['insurer2_date']) != trim($source['insurer2_date']) && (trim($source_a['insurer2_date']) == '' || $source_a['insurer2_date'] < $source['insurer2_date'])) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(mb_strlen($source_a['car_no']), [7,8]))) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['register_date'] != $source['register_date'] && (trim($source_a['register_date']) == '' || $source_a['register_date'] < $source['register_date'])) {
list($source_a, $source) = [$source, $source_a];
}
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
} else {
if (trim($source_a['insurer1_date']) != trim($source['insurer1_date']) && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) {
list($source_a, $source) = [$source, $source_a];
} else if (trim($source_a['insurer2_date']) != trim($source['insurer2_date']) && (trim($source_a['insurer2_date']) == '' || $source_a['insurer2_date'] < $source['insurer2_date'])) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(mb_strlen($source_a['car_no']), [7,8]))) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['register_date'] != $source['register_date'] && (trim($source_a['register_date']) == '' || $source_a['register_date'] < $source['register_date'])) {
list($source_a, $source) = [$source, $source_a];
}
$phones = [$source['car_phone']]; $phones = [$source['car_phone']];
$phones_a = [$source_a['car_phone']]; $phones_a = [$source_a['car_phone']];
foreach (['id_phone', 'insured_phone', 'link_phone_1', 'link_phone_2', 'link_phone_3'] as $key) { foreach (['id_phone', 'insured_phone', 'link_phone_1', 'link_phone_2', 'link_phone_3'] as $key) {
@ -425,12 +358,29 @@ class CarInfoHandle
break; break;
} }
CarInfoT::where('id', $source_a['id'])->update($source_a); CarInfoT::where('id', $source_a['id'])->update($source_a);
}
} else if (!$car_phone_a_valid && $car_phone_valid) { // 标准无效,对比有效
list($source_a, $source) = [$source, $source_a];
} else if (trim($source_a['insurer1_date']) != trim($source['insurer1_date']) && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) {
list($source_a, $source) = [$source, $source_a];
} else if (trim($source_a['insurer2_date']) != trim($source['insurer2_date']) && (trim($source_a['insurer2_date']) == '' || $source_a['insurer2_date'] < $source['insurer2_date'])) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['is_export_bmc'] == 0 && $source['is_export_bmc'] > 0) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['is_update_bhx'] == 0 && $source['is_update_bhx'] > 0) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['is_export_bhx'] == 0 && $source['is_export_bhx'] > 0) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(mb_strlen($source_a['car_no']), [7,8]))) {
list($source_a, $source) = [$source, $source_a];
} else if ($source_a['register_date'] != $source['register_date'] && (trim($source_a['register_date']) == '' || $source_a['register_date'] < $source['register_date'])) {
list($source_a, $source) = [$source, $source_a];
}
}
$this->repeatDataHandle($source, $id, 'frame'); $this->repeatDataHandle($source, $id, 'frame');
$delete_num ++; $delete_num ++;
unset($sources[$index]); unset($sources[$index]);
} }
}
}
if (empty($sources)) if (empty($sources))
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete(); RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete();
Db::commit(); Db::commit();

Loading…
Cancel
Save