50 lines
1.8 KiB
PHP
50 lines
1.8 KiB
PHP
<?php
|
||
/**
|
||
* 碎片处理中心 - 顶部指标卡接口 GET /api/fragment/stats_overview.php
|
||
* 返回:{ hard_total 硬碎片总数, soft_total 软碎片总数, month_new 本月新增,
|
||
* month_processed 本月处理, pending 待处理碎片 }
|
||
*/
|
||
require_once __DIR__ . '/../common/db.php';
|
||
require_once __DIR__ . '/../common/response.php';
|
||
require_once __DIR__ . '/../common/auth.php';
|
||
|
||
checkPermission('preliminary');
|
||
|
||
$pdo = DB::getInstance()->getPdo();
|
||
|
||
// 硬碎片:preliminary_data 中未终结(未转换/未废弃)的记录
|
||
$hardTotal = (int)$pdo->query(
|
||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status NOT IN ('已转换','已废弃')"
|
||
)->fetchColumn();
|
||
|
||
// 软碎片:四张主表 is_incomplete=1 之和
|
||
$softTotal = 0;
|
||
foreach (['companies', 'persons', 'social_accounts', 'media_commercial_attributes'] as $t) {
|
||
$softTotal += (int)$pdo->query("SELECT COUNT(*) FROM `$t` WHERE is_incomplete = 1")->fetchColumn();
|
||
}
|
||
|
||
// 本月新增(硬碎片按 created_at)
|
||
$monthNew = (int)$pdo->query(
|
||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND created_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')"
|
||
)->fetchColumn();
|
||
|
||
// 本月处理(已转换/已废弃且 processed_at 在本月)
|
||
$monthProcessed = (int)$pdo->query(
|
||
"SELECT COUNT(*) FROM preliminary_data
|
||
WHERE is_active = 1 AND status IN ('已转换','已废弃')
|
||
AND processed_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')"
|
||
)->fetchColumn();
|
||
|
||
// 待处理碎片
|
||
$pending = (int)$pdo->query(
|
||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status = '待处理'"
|
||
)->fetchColumn();
|
||
|
||
Response::success([
|
||
'hard_total' => $hardTotal,
|
||
'soft_total' => $softTotal,
|
||
'month_new' => $monthNew,
|
||
'month_processed' => $monthProcessed,
|
||
'pending' => $pending,
|
||
]);
|