try: db = DBPools() post_id = params_kw.get('post_id', '') user_id = await get_user() async with db.sqlorContext('sage') as sor: # 获取作品详情 posts = await sor.R('showcase_posts', {"id": post_id}) if not posts: return json.dumps({"status": "error", "message": "作品不存在"}, ensure_ascii=False) post = dict(posts[0]) # 增加浏览计数 new_view = (post.get('view_count', 0) or 0) + 1 await sor.U('showcase_posts', {"id": post_id, "view_count": new_view}) post['view_count'] = new_view # 检查当前用户是否已点赞 liked = await sor.sqlExe( "SELECT id FROM showcase_likes WHERE post_id = ${post_id}$ AND user_id = ${user_id}$", {"post_id": post_id, "user_id": user_id} ) post['is_liked'] = len(liked) > 0 # 检查是否已购买(付费作品) if float(post.get('price', 0)) > 0: bought = await sor.sqlExe( "SELECT id FROM showcase_downloads WHERE post_id = ${post_id}$ AND user_id = ${user_id}$ AND payment_status = '1'", {"post_id": post_id, "user_id": user_id} ) post['is_purchased'] = len(bought) > 0 else: post['is_purchased'] = True # 移除敏感字段 post.pop('model_input', None) post.pop('model_output', None) return json.dumps({"status": "ok", "data": post}, ensure_ascii=False) except Exception as e: return json.dumps({"status": "error", "message": str(e)}, ensure_ascii=False)