's'
This commit is contained in:
@@ -338,12 +338,55 @@ async def join_status(user_id: str = ""):
|
|||||||
existing = solan.get_list(1, 1, {"filter": f'user_id = "{user_id}"', "sort": "-created"})
|
existing = solan.get_list(1, 1, {"filter": f'user_id = "{user_id}"', "sort": "-created"})
|
||||||
has_record = len(existing.items) > 0
|
has_record = len(existing.items) > 0
|
||||||
rec = existing.items[0] if existing.items else None
|
rec = existing.items[0] if existing.items else None
|
||||||
is_complete = bool(rec and rec.get("order_id") and rec.get("amount", 0) > 0)
|
_get = lambda r, k, d=None: getattr(r, k, d) if r else d
|
||||||
|
is_complete = bool(rec and _get(rec, "order_id") and (_get(rec, "amount", 0) or 0) > 0)
|
||||||
return {"hasRecord": has_record, "isComplete": is_complete}
|
return {"hasRecord": has_record, "isComplete": is_complete}
|
||||||
except Exception:
|
except Exception:
|
||||||
return {"hasRecord": False, "isComplete": False}
|
return {"hasRecord": False, "isComplete": False}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/join/by-wechat")
|
||||||
|
async def join_by_wechat(wechat_id: str = ""):
|
||||||
|
"""按 wechatId 查询 solanRed 记录"""
|
||||||
|
if not wechat_id or not wechat_id.strip():
|
||||||
|
return {"hasRecord": False, "record": None, "isComplete": False, "isWechatFriend": False, "isApproved": False, "isRejected": False, "vip": False}
|
||||||
|
try:
|
||||||
|
from ..services import get_pb_client
|
||||||
|
pb_client = get_pb_client()
|
||||||
|
solan = pb_client.collection("solanRed")
|
||||||
|
w = wechat_id.strip().replace("\\", "\\\\").replace('"', '\\"')
|
||||||
|
existing = solan.get_list(1, 1, {"filter": f'wechatId = "{w}"', "sort": "-created"})
|
||||||
|
rec = existing.items[0] if existing.items else None
|
||||||
|
has_record = rec is not None
|
||||||
|
_get = lambda r, k, d=None: getattr(r, k, d) if r else d
|
||||||
|
amount = int(_get(rec, "amount", 0) or 0) if rec else 0
|
||||||
|
is_complete = has_record and bool(_get(rec, "order_id")) and amount > 0
|
||||||
|
is_wechat_friend = bool(_get(rec, "is_wechat_friend")) if rec else False
|
||||||
|
is_approved = bool(_get(rec, "is_approved")) if rec else False
|
||||||
|
is_rejected = bool(_get(rec, "is_rejected")) if rec else False
|
||||||
|
vip = bool(_get(rec, "vip")) if rec else False
|
||||||
|
record_dict = None
|
||||||
|
if rec:
|
||||||
|
record_dict = {
|
||||||
|
"user_id": _get(rec, "user_id"),
|
||||||
|
"amount": amount,
|
||||||
|
"order_id": _get(rec, "order_id"),
|
||||||
|
"vip": vip,
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"hasRecord": has_record,
|
||||||
|
"record": record_dict,
|
||||||
|
"isComplete": is_complete,
|
||||||
|
"isWechatFriend": is_wechat_friend,
|
||||||
|
"isApproved": is_approved,
|
||||||
|
"isRejected": is_rejected,
|
||||||
|
"vip": vip,
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
logging.warning(f"salon join by-wechat 查询失败: {e}")
|
||||||
|
return {"hasRecord": False, "record": None, "isComplete": False, "isWechatFriend": False, "isApproved": False, "isRejected": False, "vip": False}
|
||||||
|
|
||||||
|
|
||||||
class XiaohongshuProfileRequest(BaseModel):
|
class XiaohongshuProfileRequest(BaseModel):
|
||||||
url: str
|
url: str
|
||||||
|
|
||||||
@@ -1104,6 +1147,10 @@ async def submit_join(item: dict):
|
|||||||
from ..services import get_pb_client
|
from ..services import get_pb_client
|
||||||
pb_client = get_pb_client()
|
pb_client = get_pb_client()
|
||||||
solan = pb_client.collection("solanRed")
|
solan = pb_client.collection("solanRed")
|
||||||
|
raw_type = item.get("type", "")
|
||||||
|
# PocketBase type 仅接受 session-1/session-2 等,digital-nomad/volunteer 映射为空
|
||||||
|
pb_type = raw_type if raw_type in ("session-1", "session-2") else ""
|
||||||
|
|
||||||
pb_data = {
|
pb_data = {
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"nickname": item.get("nickname", ""),
|
"nickname": item.get("nickname", ""),
|
||||||
@@ -1113,14 +1160,21 @@ async def submit_join(item: dict):
|
|||||||
"gender": item.get("gender", ""),
|
"gender": item.get("gender", ""),
|
||||||
"education": item.get("education", ""),
|
"education": item.get("education", ""),
|
||||||
"gradYear": item.get("gradYear", ""),
|
"gradYear": item.get("gradYear", ""),
|
||||||
"phone": item.get("phone", ""),
|
|
||||||
"single": item.get("single", ""),
|
"single": item.get("single", ""),
|
||||||
"media": item.get("media", ""),
|
"media": item.get("media", ""),
|
||||||
"calculated_age": item.get("calculated_age", 0),
|
"calculated_age": item.get("calculated_age", 0),
|
||||||
"type": "",
|
"type": pb_type,
|
||||||
"order_id": "",
|
"order_id": item.get("order_id", ""),
|
||||||
"amount": 0,
|
"amount": item.get("amount", 0),
|
||||||
|
"xiaohongshu_url": item.get("xiaohongshu_url", ""),
|
||||||
|
"is_volunteer": bool(item.get("is_volunteer", False)),
|
||||||
|
"is_wechat_friend": bool(item.get("is_wechat_friend", False)),
|
||||||
|
"age_range": item.get("age_range", ""),
|
||||||
|
"first_time": item.get("first_time", ""),
|
||||||
}
|
}
|
||||||
|
phone_val = item.get("phone", "")
|
||||||
|
if phone_val and str(phone_val).strip():
|
||||||
|
pb_data["phone"] = str(phone_val).strip()
|
||||||
record = solan.create(pb_data)
|
record = solan.create(pb_data)
|
||||||
logging.info(f"salon 申请表单提交成功 - user_id: {user_id}, record_id: {record.id}")
|
logging.info(f"salon 申请表单提交成功 - user_id: {user_id}, record_id: {record.id}")
|
||||||
return {"ok": True, "user_id": user_id, "record_id": record.id}
|
return {"ok": True, "user_id": user_id, "record_id": record.id}
|
||||||
|
|||||||
Reference in New Issue
Block a user