作者 刘锟

update

... ... @@ -58,7 +58,7 @@ class ProjectImport extends Command
$task->status = ImportTask::STATUS_COM;//导入完成
$task->save();
$this->send_mail($task->user_id, $task->created_at, 0, '文件编码格式错误,仅支持UTF-8和GBK编码格式');
$this->send_mail($task->user_id, $task->created_at, 0, 0, '文件编码格式错误,仅支持UTF-8和GBK编码格式');
return true;
} elseif ($file_code_type === 'GBK') {
$is_gbk = 1;
... ... @@ -78,12 +78,13 @@ class ProjectImport extends Command
$task->status = ImportTask::STATUS_COM;//导入完成
$task->save();
$this->send_mail($task->user_id, $task->created_at, 0, '读取文件数据失败');
$this->send_mail($task->user_id, $task->created_at, 0, 0, '读取文件数据失败');
return true;
}
$total_count = 0; //总条数
$success_count = 0; //成功导入条数
$repeat_count = 0; //过滤已存在条数
if (count($line_of_text) > 1) {
$task->status = ImportTask::STATUS_ING;//导入中
$task->save();
... ... @@ -105,14 +106,20 @@ class ProjectImport extends Command
if ($task->type == ImportTask::TYPE_NEWS) {
if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
} elseif ($task->type == ImportTask::TYPE_BLOG) {
if ((new BlogLogic())->importBlog($task->project_id, $task->user_id, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
} else {
if ((new ProductLogic())->importProduct($task->project_id, $task->user_id, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
}
} catch (\Exception $e) {
... ... @@ -130,7 +137,7 @@ class ProjectImport extends Command
$task->success_count += $success_count;
$task->save();
$this->send_mail($task->user_id, $task->created_at, $success_count, '');
$this->send_mail($task->user_id, $task->created_at, $success_count, $repeat_count, '');
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import end, total count: ' . $total_count . ', success count: ' . $success_count . PHP_EOL;
... ... @@ -152,11 +159,12 @@ class ProjectImport extends Command
}
//发生站内通知
protected function send_mail($user_list, $time, $success_count, $reason)
protected function send_mail($user_list, $time, $success_count, $repeat_count, $reason)
{
$title = '导入结果通知';
$content = '您于 ' . $time . ' 添加的导入任务已执行完成, 成功导入数据条数:' . $success_count . '。';
$reason && $content .= '原因:' . $reason;
$content = '您于 ' . $time . ' 添加的导入任务已执行完成, 成功导入数据:' . $success_count . ' 条';
$repeat_count && $content .= ',过滤已存在数据:' . $repeat_count . ' 条';
$reason && $content .= ',原因:' . $reason;
$mail_model = new Mail();
$mail_model->add([
... ...