数据导入电话处理

master
zcstatham 2 years ago
parent bdb7d4c764
commit 61f96217ae
  1. 46
      extend/service/CarInfoHandle.php
  2. BIN
      public/static/tpl.xlsx

@ -548,7 +548,15 @@ class CarInfoHandle
$highestRow = $worksheet->getHighestRow(); // e.g. 10 $highestRow = $worksheet->getHighestRow(); // e.g. 10
echo '总计:' . $highestRow . PHP_EOL; echo '总计:' . $highestRow . PHP_EOL;
$now = date('Y-m-d H:i:s'); $now = date('Y-m-d H:i:s');
$update_keys = ['register_date', 'car_no', 'car_frame_no', 'engine_no', 'factory_model', 'car_year', 'displacement', 'car_man', 'car_number', 'car_phone', 'purchase_price', 'id_man', 'id_number', 'id_phone', 'insured_man', 'insured_number', 'insured_phone', 'company', 'insurer1_date', 'insurer2_date']; $update_keys = ['register_date', 'car_no', 'car_frame_no', 'engine_no', 'factory_model', 'car_year', 'displacement', 'car_man', 'car_number', 'purchase_price', 'id_man', 'id_number', 'insured_man', 'insured_number', 'company', 'insurer1_date', 'insurer2_date'];
$link_phone_keys = [
'car_phone' => 'car_man',
'id_phone' => 'id_man',
'insured_phone' => 'insured_man',
'link_phone_1' => 'link_man_1',
'link_phone_2' => 'link_man_2',
'link_phone_3' => 'link_man_3'
];
Db::execute('ALTER TABLE car_info_t DISABLE KEYS;'); Db::execute('ALTER TABLE car_info_t DISABLE KEYS;');
for ($row = 2; $row <= $highestRow; $row++) { for ($row = 2; $row <= $highestRow; $row++) {
$register_date = $worksheet->getCellByColumnAndRow(2, $row)->getValue(); $register_date = $worksheet->getCellByColumnAndRow(2, $row)->getValue();
@ -570,11 +578,14 @@ class CarInfoHandle
'purchase_price' => trim(trim($worksheet->getCellByColumnAndRow(10, $row)->getValue(), '"')), 'purchase_price' => trim(trim($worksheet->getCellByColumnAndRow(10, $row)->getValue(), '"')),
'insurer2_date' => trim(trim($worksheet->getCellByColumnAndRow(11, $row)->getValue(), '"')), 'insurer2_date' => trim(trim($worksheet->getCellByColumnAndRow(11, $row)->getValue(), '"')),
'insurer1_date' => trim(trim($worksheet->getCellByColumnAndRow(12, $row)->getValue(), '"')), 'insurer1_date' => trim(trim($worksheet->getCellByColumnAndRow(12, $row)->getValue(), '"')),
'link_man_1' => trim(trim($worksheet->getCellByColumnAndRow(13, $row)->getValue(), '"')), 'id_man' => trim(trim($worksheet->getCellByColumnAndRow(13, $row)->getValue(), '"')),
'link_phone_1' => trim(trim($worksheet->getCellByColumnAndRow(14, $row)->getValue(), '"')), 'id_number' => trim(trim($worksheet->getCellByColumnAndRow(14, $row)->getValue(), '"')),
'link_man_2' => trim(trim($worksheet->getCellByColumnAndRow(15, $row)->getValue(), '"')), 'id_phone' => trim(trim($worksheet->getCellByColumnAndRow(15, $row)->getValue(), '"')),
'link_phone_2' => trim(trim($worksheet->getCellByColumnAndRow(16, $row)->getValue(), '"')), 'link_man_1' => trim(trim($worksheet->getCellByColumnAndRow(16, $row)->getValue(), '"')),
'tag' => trim(trim($worksheet->getCellByColumnAndRow(17, $row)->getValue(), '"')), 'link_phone_1' => trim(trim($worksheet->getCellByColumnAndRow(17, $row)->getValue(), '"')),
'link_man_2' => trim(trim($worksheet->getCellByColumnAndRow(18, $row)->getValue(), '"')),
'link_phone_2' => trim(trim($worksheet->getCellByColumnAndRow(19, $row)->getValue(), '"')),
'tag' => trim(trim($worksheet->getCellByColumnAndRow(20, $row)->getValue(), '"')),
'source' => $id, 'source' => $id,
'create_timestamp' => $now, 'create_timestamp' => $now,
'update_timestamp' => $now 'update_timestamp' => $now
@ -585,6 +596,29 @@ class CarInfoHandle
if (empty($row_array[$key])) if (empty($row_array[$key]))
$row_array[$key] = $old[$key]; $row_array[$key] = $old[$key];
} }
$phones = [];
$phones_empty_keys = [];
// 新数据去重,并获得空电话位
foreach ($link_phone_keys as $phone_key => $man_key) {
if (in_array($row_array[$phone_key], $phones))
$row_array[$phone_key] = '';
if (!empty($row_array[$phone_key]))
$phones[] = $row_array[$phone_key];
else
$phones_empty_keys[] = $phone_key;
}
// 旧数据查重并依次补位
foreach ($link_phone_keys as $phone_key => $man_key) {
if (empty($phones_empty_keys)) break;
if (in_array($old[$phone_key], $phones)) continue;
if (!empty($old[$phone_key])) {
$key = array_shift($phones_empty_keys);
$row_array[$key] = $old[$phone_key];
$row_array[$link_phone_keys[$key]] = $old[$man_key];
}
}
$row_array['is_export_bhx'] = 0; $row_array['is_export_bhx'] = 0;
$row_array['is_update_bhx'] = 0; $row_array['is_update_bhx'] = 0;
$row_array['is_export_bmc'] = 0; $row_array['is_export_bmc'] = 0;

Binary file not shown.
Loading…
Cancel
Save