车架去重处理返回结果增加删除数量

master
zcstatham 2 years ago
parent 95c1f456c3
commit 784d3fd8b1
  1. 14
      extend/service/CarInfoHandle.php

@ -290,9 +290,10 @@ class CarInfoHandle
$count = $query->count();
echo '总计:' . $count . PHP_EOL;
$current = 0;
$delete_num = 0;
$faild_num = 0;
cache('shell_process_' . $id, 0, 300);
$query->chunk(1000, function ($infos) use (&$current, &$faild_num, $count, $id) {
$query->chunk(1000, function ($infos) use (&$current, &$delete_num, &$faild_num, $count, $id) {
foreach ($infos as $item) {
if ($current % 10 == 0) {
cache('shell_process_' . $id, round($current / $count * 100, 3), 300);
@ -315,15 +316,14 @@ class CarInfoHandle
if (empty($source_a)) {
$source_a = $sources[0];
array_shift($sources);
}
Db::startTrans();
try {
foreach ($sources as $index => $source) {
if (empty(trim($source['car_phone']))) {
foreach ($sources as $source_data) {
$this->repeatDataHandle($source_data, $id, 'frame');
$delete_num ++;
}
RepeatFrameT::where('car_frame_no', $item->car_frame_no)->delete();
$sources = [];
@ -332,22 +332,27 @@ class CarInfoHandle
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];
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
} 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];
$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(strlen($source_a['car_no']), [7,8]))) {
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'])) {
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
unset($sources[$index]);
} else {
$phones = [$source['car_phone']];
@ -370,6 +375,7 @@ class CarInfoHandle
}
CarInfoT::where('id', $source_a['id'])->update($source_a);
$this->repeatDataHandle($source, $id, 'frame');
$delete_num ++;
CarInfoT::destroy($source['id']);
unset($sources[$index]);
}
@ -385,7 +391,7 @@ class CarInfoHandle
$current++;
}
}, 'car_frame_no');
return '处理总数:' . $count . ', 失败总数:' . $faild_num;
return '处理总数:' . $count . ', 删除总数:' . $delete_num . ', 失败总数:' . $faild_num;
}
public function carInfoUpdate($data, $id)

Loading…
Cancel
Save