v1.0.29: 碎片处理按dp方案2修订 - 完整度改三层独立判定(核心100%/重要60%/非必要40%,任一不达标即碎片)+字段分层调整(persons email升核心,companies核心扩5字段)+指标卡5张(新增累计处理,本月/累计=硬+软合计)+软碎片列表加各层完整度列+硬碎片完整度改已填/总可填
This commit is contained in:
@@ -1,8 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* 碎片处理中心 - 顶部指标卡接口 GET /api/fragment/stats_overview.php
|
||||
* 返回:{ hard_total 硬碎片总数, soft_total 软碎片总数, month_new 本月新增,
|
||||
* month_processed 本月处理, pending 待处理碎片 }
|
||||
* 碎片处理中心 - 顶部概览接口 GET /api/fragment/stats_overview.php
|
||||
* 指标:
|
||||
* - hard_total 硬碎片待处理数(preliminary_data 未终结)
|
||||
* - soft_total 软碎片待处理数(四主表 is_incomplete=1)
|
||||
* - month_new 本月新增(硬碎片本月新增 + 软碎片本月新增)
|
||||
* - month_processed 本月处理(本月已转换硬碎片 + 本月已补全软碎片)
|
||||
* - cumulative 累计处理(历史已转换硬碎片 + 历史已补全软碎片)
|
||||
* - pending 待处理碎片(硬待处理 + 软待处理)
|
||||
*/
|
||||
require_once __DIR__ . '/../common/db.php';
|
||||
require_once __DIR__ . '/../common/response.php';
|
||||
@@ -11,39 +16,63 @@ require_once __DIR__ . '/../common/auth.php';
|
||||
checkPermission('preliminary');
|
||||
|
||||
$pdo = DB::getInstance()->getPdo();
|
||||
$monthStart = "DATE_FORMAT(CURDATE(), '%Y-%m-01')";
|
||||
|
||||
// 硬碎片:preliminary_data 中未终结(未转换/未废弃)的记录
|
||||
// 硬碎片待处理数
|
||||
$hardTotal = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status NOT IN ('已转换','已废弃')"
|
||||
)->fetchColumn();
|
||||
|
||||
// 软碎片:四张主表 is_incomplete=1 之和
|
||||
// 软碎片待处理数(四主表 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')"
|
||||
// 本月新增硬碎片(created_at 在本月)
|
||||
$hardMonthNew = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND created_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
|
||||
// 本月处理(已转换/已废弃且 processed_at 在本月)
|
||||
$monthProcessed = (int)$pdo->query(
|
||||
// 本月新增软碎片(is_incomplete=1 且本月创建;media 的创建时间取关联 social_accounts)
|
||||
$softMonthNew = 0;
|
||||
foreach (['companies', 'persons', 'social_accounts'] as $t) {
|
||||
$softMonthNew += (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM `$t` WHERE is_incomplete = 1 AND created_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
}
|
||||
$softMonthNew += (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM media_commercial_attributes m
|
||||
WHERE m.is_incomplete = 1
|
||||
AND EXISTS (SELECT 1 FROM social_accounts sa WHERE sa.id = m.social_account_id AND sa.created_at >= $monthStart)"
|
||||
)->fetchColumn();
|
||||
|
||||
// 本月已转换硬碎片
|
||||
$hardConvertedMonth = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data
|
||||
WHERE is_active = 1 AND status IN ('已转换','已废弃')
|
||||
AND processed_at >= DATE_FORMAT(CURDATE(), '%Y-%m-01')"
|
||||
WHERE is_active = 1 AND status = '已转换' AND processed_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
|
||||
// 待处理碎片
|
||||
$pending = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status = '待处理'"
|
||||
// 本月已补全软碎片(fragment 模块 complete 日志)
|
||||
$softCompletedMonth = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM system_logs WHERE action = 'complete' AND module = 'fragment' AND created_at >= $monthStart"
|
||||
)->fetchColumn();
|
||||
|
||||
// 历史累计已转换硬碎片
|
||||
$hardConvertedTotal = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM preliminary_data WHERE is_active = 1 AND status = '已转换'"
|
||||
)->fetchColumn();
|
||||
|
||||
// 历史累计已补全软碎片
|
||||
$softCompletedTotal = (int)$pdo->query(
|
||||
"SELECT COUNT(*) FROM system_logs WHERE action = 'complete' AND module = 'fragment'"
|
||||
)->fetchColumn();
|
||||
|
||||
Response::success([
|
||||
'hard_total' => $hardTotal,
|
||||
'soft_total' => $softTotal,
|
||||
'month_new' => $monthNew,
|
||||
'month_processed' => $monthProcessed,
|
||||
'pending' => $pending,
|
||||
'hard_total' => $hardTotal,
|
||||
'soft_total' => $softTotal,
|
||||
'month_new' => $hardMonthNew + $softMonthNew,
|
||||
'month_processed' => $hardConvertedMonth + $softCompletedMonth,
|
||||
'cumulative' => $hardConvertedTotal + $softCompletedTotal,
|
||||
'pending' => $hardTotal + $softTotal,
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user