feat: 项目创建/分配代理商时发送消息通知给代理商
品牌方创建项目分配代理商、或后续追加代理商时, 被分配的代理商用户会收到"新项目分配"消息通知。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4c9b2f1263
commit
4ca743e7b6
@ -123,6 +123,24 @@ async def create_project(
|
|||||||
related_project_id=project.id,
|
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)
|
return await _project_to_response(project, db)
|
||||||
|
|
||||||
|
|
||||||
@ -306,6 +324,7 @@ async def assign_agencies(
|
|||||||
if project.brand_id != brand.id:
|
if project.brand_id != brand.id:
|
||||||
raise HTTPException(status_code=403, detail="无权操作此项目")
|
raise HTTPException(status_code=403, detail="无权操作此项目")
|
||||||
|
|
||||||
|
newly_assigned = []
|
||||||
for agency_id in request.agency_ids:
|
for agency_id in request.agency_ids:
|
||||||
agency_result = await db.execute(
|
agency_result = await db.execute(
|
||||||
select(Agency).where(Agency.id == agency_id)
|
select(Agency).where(Agency.id == agency_id)
|
||||||
@ -313,10 +332,28 @@ async def assign_agencies(
|
|||||||
agency = agency_result.scalar_one_or_none()
|
agency = agency_result.scalar_one_or_none()
|
||||||
if agency and agency not in project.agencies:
|
if agency and agency not in project.agencies:
|
||||||
project.agencies.append(agency)
|
project.agencies.append(agency)
|
||||||
|
newly_assigned.append(agency)
|
||||||
|
|
||||||
await db.flush()
|
await db.flush()
|
||||||
await db.refresh(project)
|
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)
|
return await _project_to_response(project, db)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user