任务资格要求:最低信用分/要求勋章/要求认证(0061),can_accept 校验,发布端点接收

This commit is contained in:
Pine
2026-09-05 11:33:37 +08:00
parent e131bba599
commit 9b1df88bf0
5 changed files with 84 additions and 1 deletions
+41
View File
@@ -98,10 +98,28 @@ class TaskService:
return {}
full = (await self.db.users.get_by_id(uid)) or {}
credit = await self.db.credit_scores.get(uid)
# 勋章(active
badges: list[str] = []
try:
for ub in await self.db.user_badges.list_active(uid):
if ub.get("badge_code"):
badges.append(ub["badge_code"])
except Exception: # noqa: BLE001
badges = []
# 认证(approved/active
certs: list[str] = []
try:
for c in await self.db.certifications.list_by_user(uid):
if c.get("status") in ("approved", "active") and c.get("cert_type"):
certs.append(c["cert_type"])
except Exception: # noqa: BLE001
certs = []
return {
**full,
"credit_level": (credit or {}).get("level", "L1"),
"credit_score": (credit or {}).get("total_score", 0),
"badges": badges,
"certifications": certs,
}
async def can_accept(self, task: dict | None, actor: dict | None) -> dict:
@@ -169,6 +187,29 @@ class TaskService:
if cond.get("deposit") and int(cond["deposit"] or 0) > 0:
reasons.append("需缴纳接单保证金")
# ── 独立资格字段(0061):最低信用分 / 要求勋章 / 要求认证 ──
min_score = int(task.get("min_credit_score") or 0)
if min_score > 0 and int(full.get("credit_score") or 0) < min_score:
reasons.append(f"信用分需 ≥ {min_score}(当前 {full.get('credit_score', 0)}")
try:
req_badges = json.loads(task.get("required_badges") or "[]")
except Exception: # noqa: BLE001
req_badges = []
if isinstance(req_badges, list) and req_badges:
have_badges = set(full.get("badges") or [])
missing_b = [b for b in req_badges if b not in have_badges]
if missing_b:
reasons.append(f"需持有徽章:{''.join(missing_b)}")
try:
req_certs = json.loads(task.get("required_certifications") or "[]")
except Exception: # noqa: BLE001
req_certs = []
if isinstance(req_certs, list) and req_certs:
have_certs = set(full.get("certifications") or [])
missing_c = [c for c in req_certs if c not in have_certs]
if missing_c:
reasons.append(f"需完成认证:{''.join(missing_c)}")
# 软性提示(不阻断)
if cond.get("price_range") and isinstance(cond["price_range"], dict):
pr = cond["price_range"]