重复车架删除逻辑调整

master
zhaocheng 2 years ago
parent cf243297fc
commit d0a4023504
  1. 120
      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,107 +329,57 @@ 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'])) { $phones = [$source['car_phone']];
list($source_a, $source) = [$source, $source_a]; $phones_a = [$source_a['car_phone']];
} else if ($source_a['car_no'] != $source['car_no'] && (trim($source_a['car_no']) == '' || !in_array(mb_strlen($source_a['car_no']), [7,8]))) { foreach (['id_phone', 'insured_phone', 'link_phone_1', 'link_phone_2', 'link_phone_3'] as $key) {
list($source_a, $source) = [$source, $source_a]; if (preg_match('/^1[3-9][0-9]{9}/', $source_a[$key]) && !in_array($source_a[$key], $phones_a))
} else if ($source_a['register_date'] != $source['register_date'] && (trim($source_a['register_date']) == '' || $source_a['register_date'] < $source['register_date'])) { $phones_a[] = $source_a[$key];
list($source_a, $source) = [$source, $source_a]; if (preg_match('/^1[3-9][0-9]{9}/', $source[$key]) && !in_array($source[$key], $phones))
$phones[] = $source[$key];
} }
$this->repeatDataHandle($source_data, $id, 'frame'); $phones = array_unique(array_merge($phones_a, $phones));
$delete_num ++; // 可用电话大于6个时跳过
} if (count($phones) <= 6) {
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete(); array_shift($phones);
$sources = []; foreach (['id_phone', 'insured_phone', 'link_phone_1', 'link_phone_2', 'link_phone_3'] as $key) {
break; if (in_array($source_a[$key], $phones))
} else if ($source_a['car_phone'] == $source['car_phone']) { array_shift($phones);
if (trim($source_a['insurer1_date']) != trim($source['insurer1_date']) && (trim($source_a['insurer1_date']) == '' || $source_a['insurer1_date'] < $source['insurer1_date'])) { else
list($source_a, $source) = [$source, $source_a]; $source_a[$key] = array_shift($phones);
$this->repeatDataHandle($source, $id, 'frame'); if (empty($source_a[$key]) || empty($phones))
$delete_num ++; break;
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'])) { CarInfoT::where('id', $source_a['id'])->update($source_a);
list($source_a, $source) = [$source, $source_a]; }
$this->repeatDataHandle($source, $id, 'frame'); } else if (!$car_phone_a_valid && $car_phone_valid) { // 标准无效,对比有效
$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]; 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'])) { } 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]; 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'])) { } 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]; 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]))) { } else if ($source_a['is_export_bmc'] == 0 && $source['is_export_bmc'] > 0) {
list($source_a, $source) = [$source, $source_a]; 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'])) { } else if ($source_a['is_update_bhx'] == 0 && $source['is_update_bhx'] > 0) {
list($source_a, $source) = [$source, $source_a]; list($source_a, $source) = [$source, $source_a];
} } else if ($source_a['is_export_bhx'] == 0 && $source['is_export_bhx'] > 0) {
$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]; 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]))) { } 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]; 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'])) { } 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]; list($source_a, $source) = [$source, $source_a];
} }
$phones = [$source['car_phone']];
$phones_a = [$source_a['car_phone']];
foreach (['id_phone', 'insured_phone', 'link_phone_1', 'link_phone_2', 'link_phone_3'] as $key) {
if (preg_match('/^1[3-9][0-9]{9}/', $source_a[$key]) && !in_array($source_a[$key], $phones_a))
$phones_a[] = $source_a[$key];
if (preg_match('/^1[3-9][0-9]{9}/', $source[$key]) && !in_array($source[$key], $phones))
$phones[] = $source[$key];
}
$phones = array_unique(array_merge($phones_a, $phones));
// 可用电话大于6个时跳过
if (count($phones) <= 6) {
array_shift($phones);
foreach (['id_phone', 'insured_phone', 'link_phone_1', 'link_phone_2', 'link_phone_3'] as $key) {
if (in_array($source_a[$key], $phones))
array_shift($phones);
else
$source_a[$key] = array_shift($phones);
if (empty($source_a[$key]) || empty($phones))
break;
}
CarInfoT::where('id', $source_a['id'])->update($source_a);
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
}
} }
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
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();

Loading…
Cancel
Save