From 4ca743e7b67830882488ebd678e99783834eb86a Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 10 Feb 2026 19:02:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A1=B9=E7=9B=AE=E5=88=9B=E5=BB=BA/?= =?UTF-8?q?=E5=88=86=E9=85=8D=E4=BB=A3=E7=90=86=E5=95=86=E6=97=B6=E5=8F=91?= =?UTF-8?q?=E9=80=81=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E7=BB=99=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E5=95=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 品牌方创建项目分配代理商、或后续追加代理商时, 被分配的代理商用户会收到"新项目分配"消息通知。 Co-Authored-By: Claude Opus 4.6 --- backend/app/api/projects.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/backend/app/api/projects.py b/backend/app/api/projects.py index 858c3bf..306b44f 100644 --- a/backend/app/api/projects.py +++ b/backend/app/api/projects.py @@ -123,6 +123,24 @@ async def create_project( related_project_id=project.id, ) + # 给被分配的代理商发送新项目通知 + if project.agencies: + for agency in project.agencies: + agency_user_result = await db.execute( + select(User).where(User.id == agency.user_id) + ) + agency_user = agency_user_result.scalar_one_or_none() + if agency_user: + await create_message( + db=db, + user_id=agency_user.id, + type="new_task", + title="新项目分配", + content=f"品牌方「{brand.name}」将您加入了项目「{project.name}」", + related_project_id=project.id, + sender_name=brand.name, + ) + return await _project_to_response(project, db) @@ -306,6 +324,7 @@ async def assign_agencies( if project.brand_id != brand.id: raise HTTPException(status_code=403, detail="无权操作此项目") + newly_assigned = [] for agency_id in request.agency_ids: agency_result = await db.execute( select(Agency).where(Agency.id == agency_id) @@ -313,10 +332,28 @@ async def assign_agencies( agency = agency_result.scalar_one_or_none() if agency and agency not in project.agencies: project.agencies.append(agency) + newly_assigned.append(agency) await db.flush() await db.refresh(project) + # 给新分配的代理商发送通知 + for agency in newly_assigned: + agency_user_result = await db.execute( + select(User).where(User.id == agency.user_id) + ) + agency_user = agency_user_result.scalar_one_or_none() + if agency_user: + await create_message( + db=db, + user_id=agency_user.id, + type="new_task", + title="新项目分配", + content=f"品牌方「{brand.name}」将您加入了项目「{project.name}」", + related_project_id=project.id, + sender_name=brand.name, + ) + return await _project_to_response(project, db)