feat: improve campus bike discovery and add independent live preview

This commit is contained in:
zzy
2026-11-04 16:42:47 +08:00
parent f986c8deae
commit b6b7b3dbe5
42 changed files with 5267 additions and 4313 deletions
+28 -7
View File
@@ -1157,9 +1157,23 @@ def user_orders():
if not user:
return jsonify({"rtn_code": 401, "message": "请先登录"})
try:
limit = max(1, min(500, int(request.args.get("limit", 80))))
except (TypeError, ValueError):
limit = 80
limit = max(1, min(100, int(request.args.get("limit", 20))))
offset = max(0, int(request.args.get("offset", 0)))
date_from, date_to = request.args.get("from", ""), request.args.get("to", "")
for value in (date_from, date_to):
if value:
dt.datetime.strptime(value, "%Y-%m-%d")
if date_from and date_to and date_from > date_to:
raise ValueError("开始日期不能晚于结束日期")
code = request.args.get("code", "").strip()
if code and (not code.isascii() or not code.isdigit() or len(code) > 8):
raise ValueError("车牌筛选只能输入最多8位数字")
source = request.args.get("source", "all")
if source not in ("all", "own", "shared"):
raise ValueError("无效的订单来源")
except (TypeError, ValueError) as exc:
return jsonify(rtn_code=400, message=str(exc) or "筛选参数无效"), 400
conn = get_db()
cursor = conn.cursor()
cursor.execute("""
@@ -1174,16 +1188,23 @@ def user_orders():
WHERE owner_user_id = r.user_id AND rider_user_id = r.rider_user_id)
WHERE (r.user_id = ? OR r.rider_user_id = ?)
AND COALESCE(r.source, '') != 'reminder'
ORDER BY r.id DESC LIMIT ?
""", (user["id"], user["id"], limit))
ORDER BY r.id DESC
""", (user["id"], user["id"]))
rows = [dict(r) for r in cursor.fetchall()]
conn.close()
chains = _merge_rental_chains(rows)
# 最近的在最前
chains.sort(key=lambda c: (c["rows"][-1].get("start_time") or "", c["rows"][-1]["id"]),
reverse=True)
return jsonify({"rtn_code": 0,
"data": [_chain_order_dict(c, user["id"]) for c in chains]})
records = [_chain_order_dict(c, user["id"]) for c in chains]
records = [item for item in records
if (not code or code in item["bike_code"])
and (not date_from or str(item.get("start_time") or "")[:10] >= date_from)
and (not date_to or str(item.get("start_time") or "")[:10] <= date_to)
and (source == "all" or bool(item["shared"]) == (source == "shared"))]
page = records[offset:offset + limit]
return jsonify(rtn_code=0, data=page, total=len(records), offset=offset,
has_more=offset + len(page) < len(records))
# ========== 开锁前预览(月卡余量 + 自动续租轮次预估) ==========