feat(performance): 광고비 탭 [광고비 업데이트] 진행 창·자동 업데이트·업데이트 시각
- 채널별 [구글/메타 광고 불러오기] 버튼을 없애고 매출 탭과 같은 모양으로 마지막 업데이트 · 다음 업데이트까지(카운트다운) · [광고비 업데이트] - 진행 창 작업에 종류(sales/ads) 추가 — 광고 채널별 진행 막대(수집 → 저장 → 완료), 채널별 중지·전체 취소는 저장 직전까지, 진행 중이면 합류 - POST /api/ad-sync, GET /api/ad-sync/current - 자동 업데이트 회차에서 매출과 광고비를 동시에 각각 진행 창 작업으로 - 마지막 광고비 업데이트 = 광고 API 마지막 성공 가져오기 시각 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,10 @@ JSON API — 모듈 권한
|
||||
POST /performance/api/ad-spend/upload?channel= 광고비 파일 업로드(쿠팡 윙·로켓 광고 보고서 1열 날짜·19열 청구금액,
|
||||
네이버 광고 보고서 3열 기간·4열 총비용·12열 ROAS + 나머지 항목)
|
||||
GET /performance/api/ad-spend/{channel}/details?from=&to= 일자별 보고서 항목(네이버·구글·메타 머리글 클릭)
|
||||
POST /performance/api/ad-sources/{code}/sync 광고 API(구글·메타 광고) 가져오기 — 보는 기간(오늘까지), 92일 넘으면 관리자
|
||||
POST /performance/api/ad-sync [광고비 업데이트] — 설정된 광고 API 전부, 보는 기간(오늘까지), 진행 창 작업
|
||||
(jobs kind="ads", 진행·취소·중지는 /api/sync/jobs/… 그대로), 92일 넘으면 관리자
|
||||
GET /performance/api/ad-sync/current 진행 중인 광고비 업데이트(수동·자동) — 버튼이 진행 창을 다시 연다
|
||||
POST /performance/api/ad-sources/{code}/sync 광고 API 채널 하나 가져오기(예전 [구글/메타 광고 불러오기], 화면 버튼은 2026-10-20 삭제)
|
||||
JSON API — 관리자
|
||||
GET|PUT /performance/api/ad-sources/{code}/credentials 광고 API 인증정보(마이그레이션 007, 암호화 저장·비밀 원문 없음)
|
||||
POST /performance/api/ad-sources/{code}/test 광고 API 연결 테스트(저장값 또는 새 입력값)
|
||||
@@ -188,11 +191,21 @@ def ads_page(
|
||||
custom_from=_parse_date(from_), custom_to=_parse_date(to), holidays=_holidays(),
|
||||
sales_codes=[m["code"] for m in _sales_marketplaces(store)],
|
||||
)
|
||||
# [구글 광고 불러오기] — 관리자가 실적 설정에서 인증정보를 넣은 광고 연동만
|
||||
# [광고비 업데이트](2026-10-20) — 관리자가 실적 설정에서 인증정보를 넣은 광고 연동 전부를 진행 창으로.
|
||||
# 마지막 업데이트 = 광고 API 마지막 성공 가져오기, 다음 업데이트 = 매출 자동 업데이트와 같은 회차.
|
||||
from . import jobs # noqa: WPS433
|
||||
from .ad_sources.registry import get_source # noqa: WPS433
|
||||
from .ad_sync import last_ad_update_at # noqa: WPS433
|
||||
|
||||
_, ad_sync = _ad_services(store)
|
||||
ctx["ad_sync_sources"] = [{"code": c, "name": get_source(c).name} for c, ok in ad_sync.configured().items() if ok]
|
||||
try:
|
||||
configured = ad_sync.configured()
|
||||
except Exception: # noqa: BLE001 — 007 미적용 등: 버튼만 숨김
|
||||
configured = {}
|
||||
ctx["ad_sync_sources"] = [{"code": c, "name": get_source(c).name} for c, ok in configured.items() if ok]
|
||||
ctx["ad_last_update_at"] = last_ad_update_at(store)
|
||||
ctx["ad_running"] = jobs.running_job("ads") is not None
|
||||
ctx["auto_sync"] = _auto_sync_ctx()
|
||||
return render_template(request, "performance/ads.html",
|
||||
{**common.base_ctx(user, active_tab="ads", page_title="광고비"), **ctx})
|
||||
|
||||
@@ -641,18 +654,12 @@ def api_ad_source_test(request: Request, code: str, payload: dict[str, Any] = Bo
|
||||
return JSONResponse(ad_sync.test_connection(code, values=values or None, user=user["email"], cleared=cleared or None))
|
||||
|
||||
|
||||
@router.post("/api/ad-sources/{code}/sync")
|
||||
def api_ad_source_sync(request: Request, code: str, payload: dict[str, Any] = Body(default={})) -> JSONResponse:
|
||||
"""광고비 탭 [구글 광고 불러오기] — 기간(from·to, 없으면 최근 N일)을 가져와 저장. 오늘 뒤는 잘라낸다.
|
||||
모듈 권한자는 92일까지, 그보다 길면(최대 366일) 관리자만."""
|
||||
def _ad_sync_period(payload: dict[str, Any], user: dict[str, Any]) -> tuple[date, date]:
|
||||
"""광고 가져오기 기간 — from·to(없으면 최근 N일), 오늘 뒤는 자름. 모듈 권한자는 92일까지, 그보다 길면(최대 366일) 관리자만."""
|
||||
from app.store import is_admin # noqa: WPS433
|
||||
|
||||
from .ad_spend import AdMigrationNeeded # noqa: WPS433
|
||||
from .ad_sync import AdSyncBusy # noqa: WPS433
|
||||
from .auto_sync import sync_days # noqa: WPS433
|
||||
|
||||
store, user = common.require_store(request)
|
||||
src = _ad_source_or_404(code)
|
||||
today = today_kst()
|
||||
end = _parse_date(payload.get("to"), field="종료일") or today
|
||||
start = _parse_date(payload.get("from"), field="시작일") or (end - timedelta(days=sync_days() - 1))
|
||||
@@ -666,6 +673,51 @@ def api_ad_source_sync(request: Request, code: str, payload: dict[str, Any] = Bo
|
||||
raise HTTPException(status_code=400, detail=f"한 번에 {MAX_BACKFILL_DAYS}일까지 가져올 수 있습니다.")
|
||||
if days > MAX_USER_SYNC_DAYS and not is_admin(user):
|
||||
raise HTTPException(status_code=403, detail=f"{MAX_USER_SYNC_DAYS}일보다 긴 기간은 관리자만 가져올 수 있습니다.")
|
||||
return start, end
|
||||
|
||||
|
||||
@router.post("/api/ad-sync")
|
||||
def api_ad_sync(request: Request, payload: dict[str, Any] = Body(default={})) -> JSONResponse:
|
||||
"""[광고비 업데이트](2026-10-20) — 설정된 광고 API 전부를 백그라운드 진행 창 작업으로. 이미 돌고 있는 광고비 업데이트
|
||||
(다른 사람·자동 업데이트)가 있으면 새로 시작하지 않고 그 작업을 돌려준다(joined)."""
|
||||
import threading # noqa: WPS433
|
||||
|
||||
from . import jobs # noqa: WPS433
|
||||
from .ad_sync import run_ad_job # noqa: WPS433
|
||||
|
||||
store, user = common.require_store(request)
|
||||
live = jobs.running_job("ads")
|
||||
if live is not None:
|
||||
return JSONResponse({"job": live.snapshot(), "joined": True})
|
||||
start, end = _ad_sync_period(payload, user)
|
||||
_, ad_sync = _ad_services(store)
|
||||
if not any(ad_sync.configured().values()):
|
||||
raise HTTPException(status_code=400, detail="설정된 광고 API 가 없습니다. 관리자가 실적 설정 → 광고 API 연동에서 입력해야 합니다.")
|
||||
job = jobs.create_job(user=user["email"], start=start, end=end, kind="ads")
|
||||
threading.Thread(target=run_ad_job, args=(store, common.key_ring, job, start, end),
|
||||
kwargs={"user": user["email"]}, name=f"perf-ad-sync-{job.id}", daemon=True).start()
|
||||
return JSONResponse({"job": job.snapshot(), "joined": False})
|
||||
|
||||
|
||||
@router.get("/api/ad-sync/current")
|
||||
def api_ad_sync_current(request: Request) -> JSONResponse:
|
||||
common.require_store(request)
|
||||
from . import jobs # noqa: WPS433
|
||||
|
||||
job = jobs.running_job("ads")
|
||||
return JSONResponse({"job": job.snapshot() if job else None})
|
||||
|
||||
|
||||
@router.post("/api/ad-sources/{code}/sync")
|
||||
def api_ad_source_sync(request: Request, code: str, payload: dict[str, Any] = Body(default={})) -> JSONResponse:
|
||||
"""광고 API 채널 하나 가져오기(진행 창 없이) — 기간(from·to, 없으면 최근 N일). 오늘 뒤는 잘라낸다.
|
||||
모듈 권한자는 92일까지, 그보다 길면(최대 366일) 관리자만. 화면은 [광고비 업데이트](/api/ad-sync)를 쓴다."""
|
||||
from .ad_spend import AdMigrationNeeded # noqa: WPS433
|
||||
from .ad_sync import AdSyncBusy # noqa: WPS433
|
||||
|
||||
store, user = common.require_store(request)
|
||||
src = _ad_source_or_404(code)
|
||||
start, end = _ad_sync_period(payload, user)
|
||||
_, ad_sync = _ad_services(store)
|
||||
if not ad_sync.configured().get(code):
|
||||
raise HTTPException(status_code=400, detail=f"{src.name} API 가 설정되지 않았습니다. 관리자가 실적 설정 → 광고 API 연동에서 입력해야 합니다.")
|
||||
|
||||
Reference in New Issue
Block a user