feat: 小程序图标与频道配置 API(按俱乐部)

This commit is contained in:
XingQue
2026-06-26 04:03:52 +08:00
parent 141f17859a
commit 24949b1cb2
8 changed files with 540 additions and 1 deletions

View File

@@ -182,3 +182,6 @@ def copy_display_config(template_club_id, new_club_id):
text=img.text,
sort_order=img.sort_order,
)
from jituan.services.miniapp_assets import copy_miniapp_assets
copy_miniapp_assets(template_club_id, new_club_id)

View File

@@ -0,0 +1,139 @@
"""小程序频道与可配置图标(按俱乐部)。"""
from jituan.services.display_config import _display_club_id
ICON_FOLDER = 'beijing/tubiao/chengxutubiao'
# icon_key -> 后台展示名(文件名固定为 {icon_key}.png
MINIAPP_ICON_META = [
('merchant_gold_banner', '商家金牌横幅'),
('merchant_regular_dispatch', '常规派单'),
('merchant_custom_dispatch', '自定义派单'),
('merchant_pending_settle', '待清算'),
('merchant_kefu_key', '客服密钥'),
('merchant_kefu_list', '客服列表'),
('merchant_recharge_deposit', '充值保证金'),
('merchant_recharge_member', '充值会员'),
('merchant_link_dispatch', '链接派单'),
('merchant_punish', '处罚记录'),
('merchant_rank', '商家排行'),
('merchant_refresh', '商家刷新'),
('fighter_recharge_member', '打手充值会员'),
('fighter_recharge_deposit', '打手充值保证金'),
('mine_pindao', '频道入口'),
('icon_refresh', '通用刷新'),
]
MINIAPP_ICON_KEYS = [k for k, _ in MINIAPP_ICON_META]
MINIAPP_ICON_LABELS = dict(MINIAPP_ICON_META)
# 无 DB 记录时的默认相对路径(与种子脚本一致)
MINIAPP_ICON_DEFAULTS = {
key: f'{ICON_FOLDER}/{key}.png' for key in MINIAPP_ICON_KEYS
}
# 部分历史资源扩展名不同
MINIAPP_ICON_DEFAULTS['icon_refresh'] = 'beijing/guanshiduan/icon-refresh.png'
MINIAPP_ICON_DEFAULTS['merchant_refresh'] = 'beijing/guanshiduan/icon-refresh.png'
MINIAPP_ICON_DEFAULTS['fighter_recharge_member'] = 'beijing/dashouduan/dashoutubiaobeijing/icon-recharge.jpg'
MINIAPP_ICON_DEFAULTS['fighter_recharge_deposit'] = 'beijing/dashouduan/vip-card-bg.jpg'
MINIAPP_ICON_DEFAULTS['mine_pindao'] = 'beijing/tubiao/grzx_guanzhualong.jpg'
def default_icon_path(icon_key: str) -> str:
return MINIAPP_ICON_DEFAULTS.get(icon_key) or f'{ICON_FOLDER}/{icon_key}.png'
def get_miniapp_icons_dict(club_id: str) -> dict:
from config.models import ClubMiniappIcon
rows = ClubMiniappIcon.query.filter(club_id=club_id, is_active=True)
db_map = {r.icon_key: (r.image_path or '').strip() for r in rows if r.icon_key}
result = {}
for key in MINIAPP_ICON_KEYS:
path = db_map.get(key) or default_icon_path(key)
if path:
result[key] = path
return result
def get_pindao_payload(club_id: str) -> dict:
from config.models import ClubPindao, ClubPindaoImage
row = ClubPindao.query.filter(club_id=club_id, is_active=True).first()
if not row:
return {'channel_no': '', 'title': '频道', 'images': []}
images = [
img.image_path
for img in ClubPindaoImage.query.filter(club_id=club_id).order_by('sort_order', 'id')
if img.image_path
]
return {
'channel_no': row.channel_no or '',
'title': row.title or '频道',
'images': images,
}
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),
}
def seed_miniapp_icons_for_club(club_id: str, overwrite: bool = False) -> int:
from config.models import ClubMiniappIcon
created = 0
for key, label in MINIAPP_ICON_META:
path = default_icon_path(key)
row = ClubMiniappIcon.query.filter(club_id=club_id, icon_key=key).first()
if row:
if overwrite:
row.label = label
row.image_path = path
row.is_active = True
row.save(update_fields=['label', 'image_path', 'is_active', 'UpdateTime'])
continue
ClubMiniappIcon.query.create(
club_id=club_id,
icon_key=key,
label=label,
image_path=path,
is_active=True,
)
created += 1
return created
def copy_miniapp_assets(template_club_id: str, new_club_id: str):
from config.models import ClubMiniappIcon, ClubPindao, ClubPindaoImage
for row in ClubMiniappIcon.query.filter(club_id=template_club_id):
if ClubMiniappIcon.query.filter(club_id=new_club_id, icon_key=row.icon_key).exists():
continue
ClubMiniappIcon.query.create(
club_id=new_club_id,
icon_key=row.icon_key,
label=row.label,
image_path=row.image_path,
description=row.description,
is_active=row.is_active,
)
src_pindao = ClubPindao.query.filter(club_id=template_club_id).first()
if not src_pindao or ClubPindao.query.filter(club_id=new_club_id).exists():
return
new_pindao = ClubPindao.query.create(
club_id=new_club_id,
channel_no=src_pindao.channel_no,
title=src_pindao.title,
is_active=src_pindao.is_active,
)
for img in ClubPindaoImage.query.filter(club_id=template_club_id).order_by('sort_order', 'id'):
ClubPindaoImage.query.create(
club_id=new_club_id,
pindao=new_pindao,
image_path=img.image_path,
sort_order=img.sort_order,
)