feat: 分俱乐部推广海报背景与二维码生成
This commit is contained in:
@@ -19,6 +19,8 @@ MINIAPP_ICON_META = [
|
||||
('fighter_recharge_deposit', '打手中心-保证金充值横幅(右侧)'),
|
||||
('mine_pindao', '频道入口'),
|
||||
('icon_refresh', '通用刷新'),
|
||||
('guanshi_poster_bg', '管事推广海报背景'),
|
||||
('zuzhang_poster_bg', '组长推广海报背景'),
|
||||
]
|
||||
|
||||
MINIAPP_ICON_KEYS = [k for k, _ in MINIAPP_ICON_META]
|
||||
@@ -35,6 +37,19 @@ MINIAPP_ICON_DEFAULTS['merchant_gold_banner'] = 'beijing/tubiao/chengxutubiao/me
|
||||
MINIAPP_ICON_DEFAULTS['fighter_recharge_member'] = f'{ICON_FOLDER}/fighter_recharge_member.png'
|
||||
MINIAPP_ICON_DEFAULTS['fighter_recharge_deposit'] = f'{ICON_FOLDER}/fighter_recharge_deposit.png'
|
||||
MINIAPP_ICON_DEFAULTS['mine_pindao'] = 'beijing/tubiao/grzx_guanzhualong.jpg'
|
||||
MINIAPP_ICON_DEFAULTS['guanshi_poster_bg'] = 'beijing/haibaobeijing.jpg'
|
||||
MINIAPP_ICON_DEFAULTS['zuzhang_poster_bg'] = 'beijing/zuzhangbeijing.jpg'
|
||||
|
||||
POSTER_BG_FIELDS = {
|
||||
'guanshi_bg': 'guanshi_poster_bg',
|
||||
'zuzhang_bg': 'zuzhang_poster_bg',
|
||||
}
|
||||
POSTER_BG_DEFAULTS = {
|
||||
'guanshi_bg': 'beijing/haibaobeijing.jpg',
|
||||
'zuzhang_bg': 'beijing/zuzhangbeijing.jpg',
|
||||
}
|
||||
POSTER_FOLDER = 'beijing/haibao'
|
||||
POSTER_ICON_KEYS = frozenset(POSTER_BG_FIELDS.values())
|
||||
|
||||
|
||||
def default_icon_path(icon_key: str) -> str:
|
||||
@@ -70,11 +85,31 @@ def get_pindao_payload(club_id: str) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def get_poster_payload(club_id: str) -> dict:
|
||||
"""各俱乐部推广海报背景相对路径(后台上传后覆盖默认)。"""
|
||||
from config.models import ClubMiniappIcon
|
||||
|
||||
rows = {
|
||||
r.icon_key: r
|
||||
for r in ClubMiniappIcon.query.filter(club_id=club_id, is_active=True)
|
||||
}
|
||||
result = {}
|
||||
for field, icon_key in POSTER_BG_FIELDS.items():
|
||||
default = POSTER_BG_DEFAULTS[field]
|
||||
row = rows.get(icon_key)
|
||||
if row and row.is_uploaded and (row.image_path or '').strip():
|
||||
result[field] = row.image_path.strip()
|
||||
else:
|
||||
result[field] = default
|
||||
return result
|
||||
|
||||
|
||||
def build_miniapp_assets_payload(request) -> dict:
|
||||
club_id = _display_club_id(request)
|
||||
return {
|
||||
'icons': get_miniapp_icons_dict(club_id),
|
||||
'pindao': get_pindao_payload(club_id),
|
||||
'poster': get_poster_payload(club_id),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -14,9 +14,12 @@ from jituan.services.miniapp_assets import (
|
||||
ICON_FOLDER,
|
||||
MINIAPP_ICON_LABELS,
|
||||
MINIAPP_ICON_META,
|
||||
POSTER_FOLDER,
|
||||
POSTER_ICON_KEYS,
|
||||
default_icon_path,
|
||||
get_miniapp_icons_dict,
|
||||
get_pindao_payload,
|
||||
get_poster_payload,
|
||||
)
|
||||
from products.views import delete_from_oss, upload_to_oss, validate_image
|
||||
|
||||
@@ -115,7 +118,10 @@ class ClubMiniappIconManageView(APIView):
|
||||
ext = os.path.splitext(file_obj.name)[1].lower() or '.png'
|
||||
if ext not in ('.png', '.jpg', '.jpeg', '.webp'):
|
||||
ext = '.png'
|
||||
oss_path = f'{ICON_FOLDER}/{icon_key}{ext}'
|
||||
if icon_key in POSTER_ICON_KEYS:
|
||||
oss_path = f'{POSTER_FOLDER}/{club_id}_{icon_key}{ext}'
|
||||
else:
|
||||
oss_path = f'{ICON_FOLDER}/{icon_key}{ext}'
|
||||
|
||||
row = ClubMiniappIcon.query.filter(club_id=club_id, icon_key=icon_key).first()
|
||||
if row and row.image_path and row.image_path != oss_path:
|
||||
|
||||
Reference in New Issue
Block a user