63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
from models import SystemDict, SystemNotification, db
|
|
from flask import jsonify
|
|
|
|
def get_system_config_data():
|
|
"""获取系统配置数据的业务逻辑"""
|
|
dicts = SystemDict.query.filter_by(is_active=True).order_by(SystemDict.sort_order.desc()).all()
|
|
|
|
config = {
|
|
"models": [],
|
|
"ratios": [],
|
|
"prompts": [],
|
|
"sizes": [],
|
|
"video_models": [],
|
|
"video_prompts": []
|
|
}
|
|
|
|
for d in dicts:
|
|
item = {"label": d.label, "value": d.value}
|
|
if d.dict_type == 'ai_model':
|
|
item["cost"] = d.cost
|
|
config["models"].append(item)
|
|
elif d.dict_type == 'aspect_ratio':
|
|
config["ratios"].append(item)
|
|
elif d.dict_type == 'prompt_tpl':
|
|
config["prompts"].append(item)
|
|
elif d.dict_type == 'ai_image_size':
|
|
config["sizes"].append(item)
|
|
elif d.dict_type == 'video_model':
|
|
item["cost"] = d.cost
|
|
config["video_models"].append(item)
|
|
elif d.dict_type == 'video_prompt':
|
|
config["video_prompts"].append(item)
|
|
|
|
return config
|
|
|
|
def get_user_latest_notification(user_id):
|
|
"""获取用户最近一条未读通知"""
|
|
latest = SystemNotification.query.filter_by(is_active=True)\
|
|
.filter(~SystemNotification.read_by_users.any(id=user_id))\
|
|
.order_by(SystemNotification.created_at.desc()).first()
|
|
|
|
if latest:
|
|
return {
|
|
"id": latest.id,
|
|
"title": latest.title,
|
|
"content": latest.content,
|
|
"time": latest.created_at_bj.strftime('%Y-%m-%d %H:%M')
|
|
}
|
|
return {"id": None}
|
|
|
|
def mark_notification_as_read(user_id, notif_id):
|
|
"""标记通知已读"""
|
|
from models import User
|
|
|
|
notif = db.session.get(SystemNotification, notif_id)
|
|
user = db.session.get(User, user_id)
|
|
|
|
if notif and user:
|
|
if user not in notif.read_by_users:
|
|
notif.read_by_users.append(user)
|
|
db.session.commit()
|
|
return True
|