From c6eb41879265524543e495275cc3a8227134315d Mon Sep 17 00:00:00 2001 From: sa0ChunLuyu Date: Wed, 29 Jul 2026 23:01:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=A4=B4=E5=8F=B7=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Admin/YeWu/PlanListService.php | 66 ++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/Laravel/app/Services/Admin/YeWu/PlanListService.php b/Laravel/app/Services/Admin/YeWu/PlanListService.php index 1be69a4..49a7f6a 100644 --- a/Laravel/app/Services/Admin/YeWu/PlanListService.php +++ b/Laravel/app/Services/Admin/YeWu/PlanListService.php @@ -1786,8 +1786,70 @@ public function releaseSourceFromDetail($mainListId, $mainInfo = null) } // 没有可转移的共享项目:不修改 useDetailJson,正常释放逻辑释放全部 } else { - // currentCount <= remainingMax,按实际占用量正常释放全部 - // 不修改 useDetailJson,让正常释放逻辑处理 + // currentCount <= remainingMax,不释放,将占位合并到新持有者 + $newHolder = DB::table('s_list') + ->join('s_check_item', 's_list.entrust', '=', 's_check_item.item_name') + ->where('s_list.reg_num', $mainInfo->reg_num) + ->where('s_list.roster_id', $mainInfo->roster_id) + ->where('s_list.id', '!=', $mainListId) + ->where('s_list.list_status', 1) + ->where('s_check_item.is_share_slot', 1) + ->select('s_list.id') + ->first(); + + Log::info('[YuYueDebug] else 转移-新持有者查询', [ + 'mainListId' => $mainListId, + 'entrust' => $mainInfo->entrust, + 'newHolderId' => $newHolder ? $newHolder->id : 'null', + ]); + + if ($newHolder) { + // 读取新持有者当前 detail,合并当前项目的占位 + $newHolderJson = DB::table('s_list')->where('id', $newHolder->id)->value('appointment_use_plan_detail'); + $newHolderDetail = json_decode($newHolderJson, true) ?: []; + + Log::info('[YuYueDebug] else 转移-合并前', [ + 'newHolderId' => $newHolder->id, + 'newHolderDetail' => $newHolderDetail, + 'cancelDetail' => $useDetails, + ]); + + foreach ($useDetails as $d) { + $found = false; + foreach ($newHolderDetail as &$nd) { + if ($nd['roster_detail_count_id'] == $d['roster_detail_count_id']) { + $nd['count'] += (int)($d['count'] ?? 0); + $found = true; + break; + } + } + if (!$found) { + $newHolderDetail[] = [ + 'roster_detail_count_id' => $d['roster_detail_count_id'], + 'count' => (int)($d['count'] ?? 0) + ]; + } + } + + Log::info('[YuYueDebug] else 转移-合并后', [ + 'newHolderId' => $newHolder->id, + 'newHolderDetail' => $newHolderDetail, + ]); + + DB::table('s_list') + ->where('id', $newHolder->id) + ->update(['appointment_use_plan_detail' => json_encode($newHolderDetail)]); + + // 更新后读回确认 + $afterUpdate = DB::table('s_list')->where('id', $newHolder->id)->value('appointment_use_plan_detail'); + Log::info('[YuYueDebug] else 转移-更新后读回', [ + 'newHolderId' => $newHolder->id, + '写入值' => json_encode($newHolderDetail), + '读回值' => $afterUpdate, + ]); + } + // 不修改 useDetailJson,但返回 true 阻止正常释放逻辑 + return true; } } // remainingMax == 0:正常释放全部