From 7d5ef3b89abf4e04e8e486bb194007fccac22534 Mon Sep 17 00:00:00 2001 From: sa0ChunLuyu Date: Mon, 3 Aug 2026 01:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AB=E6=AD=A3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../API/Admin/YeWu/PlanListController.php | 3 ++- .../app/Services/Admin/YeWu/PlanListService.php | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php index aeac964..d7ea1f7 100644 --- a/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php +++ b/Laravel/app/Http/Controllers/API/Admin/YeWu/PlanListController.php @@ -1248,7 +1248,8 @@ public function BatchChangeLocked(Request $request) public function CorrectUsedCountTest(Request $request, PlanListService $planListService) { $rosterId = request('roster_id'); - $result = $planListService->calculateUsedCount($rosterId); + $correct = request('correct', 0); + $result = $planListService->calculateUsedCount($rosterId, $correct); // calculateUsedCount 返回数组(成功)或 Yz::echoError1 的响应 if (is_array($result)) { diff --git a/Laravel/app/Services/Admin/YeWu/PlanListService.php b/Laravel/app/Services/Admin/YeWu/PlanListService.php index 5f47e19..6c1a65e 100644 --- a/Laravel/app/Services/Admin/YeWu/PlanListService.php +++ b/Laravel/app/Services/Admin/YeWu/PlanListService.php @@ -1932,7 +1932,7 @@ public function correctUsedCount($rosterId) * 测试校正号源:只读计算,不更新数据库 * 返回当前排班号源占用详情与校正后应占数的对比 */ - public function calculateUsedCount($rosterId) + public function calculateUsedCount($rosterId, $correct = 0) { if (!$rosterId) { return \Yz::echoError1('参数错误:roster_id 不能为空'); @@ -2085,6 +2085,17 @@ public function calculateUsedCount($rosterId) } } + // 校正模式:将计算结果写入数据库 + $corrected = false; + if ($correct == 1 && $hasDiff) { + foreach ($channelCalculated as $ch) { + DB::table('s_source_roster_detail_count') + ->where('id', $ch['id']) + ->update(['used_count' => $ch['calculated_used_count']]); + } + $corrected = true; + } + return [ 'roster_id' => (int)$rosterId, 'roster_info' => [ @@ -2101,6 +2112,7 @@ public function calculateUsedCount($rosterId) 'total_used' => $totalUsed, 'channels' => $channelCalculated, 'has_diff' => $hasDiff, + 'corrected' => $corrected, ]; }