重复车架删除逻辑调整

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;
}
$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())
continue;
$sources = $sources->toArray();
@ -329,107 +329,57 @@ class CarInfoHandle
if (empty($source_a)) {
$source_a = $sources[0];
array_shift($sources);
}
Db::startTrans();
} Db::startTrans();
try {
$car_phone_a_valid = preg_match('/^1[3-9][0-9]{9}/', $source_a['car_phone']);
foreach ($sources as $index => $source) {
if (empty(trim($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'])) {
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];
$car_phone_valid = preg_match('/^1[3-9][0-9]{9}/', $source['car_phone']);
// 当不是标准有效对比无效的情况下,要进行数据对比替换
if (!($car_phone_a_valid && !$car_phone_valid)) {
if ($car_phone_a_valid && $car_phone_valid) { // 都有效更新电话
$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];
}
$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'])) {
$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);
}
} else if (!$car_phone_a_valid && $car_phone_valid) { // 标准无效,对比有效
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]))) {
} else if ($source_a['is_export_bmc'] == 0 && $source['is_export_bmc'] > 0) {
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];
}
$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'])) {
} 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];
}
$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))
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete();

Loading…
Cancel
Save