派单统计时机:生成链接不计派单;客户填单成功才计;退款/结单在真正完成时统计。
客服日统计联动:update_shangjia_daily(..., order_id=...) 会同步更新对应派单客服的日统计。 客服 /me 接口:返回今日/累计派单、结单、退款等 stats。 角色权限修复:预置角色(总管/财务/派单员)每次访问时强制同步权限,换角色后权限才生效。 展示增强:订单详情带派单员头像;客服列表带金额字段;管理员同意退款补商家+客服统计。
This commit is contained in:
@@ -13,6 +13,16 @@ def seed_global_permissions():
|
||||
)
|
||||
|
||||
|
||||
def _sync_role_permissions(role, perm_codes):
|
||||
"""同步角色权限(系统预置角色与模板保持一致)。"""
|
||||
perm_codes = set(perm_codes or [])
|
||||
existing = set(role.role_permissions.values_list('perm_code', flat=True))
|
||||
for code in perm_codes - existing:
|
||||
MerchantStaffRolePermission.objects.get_or_create(role=role, perm_code=code)
|
||||
if role.is_system:
|
||||
role.role_permissions.exclude(perm_code__in=perm_codes).delete()
|
||||
|
||||
|
||||
def ensure_system_role_templates():
|
||||
seed_global_permissions()
|
||||
for tpl in SYSTEM_ROLE_TEMPLATES:
|
||||
@@ -27,18 +37,15 @@ def ensure_system_role_templates():
|
||||
'status': 1,
|
||||
},
|
||||
)
|
||||
for perm in tpl['permissions']:
|
||||
MerchantStaffRolePermission.objects.get_or_create(
|
||||
role=role, perm_code=perm,
|
||||
)
|
||||
_sync_role_permissions(role, tpl['permissions'])
|
||||
|
||||
|
||||
def ensure_merchant_roles(merchant_id):
|
||||
"""为商家复制系统角色模板(若尚未存在)。"""
|
||||
"""为商家复制系统角色模板,并同步预置角色权限。"""
|
||||
ensure_system_role_templates()
|
||||
templates = MerchantStaffRole.query.filter(merchant_id=None, status=1)
|
||||
for tpl in templates:
|
||||
role, created = MerchantStaffRole.objects.get_or_create(
|
||||
role, _ = MerchantStaffRole.objects.get_or_create(
|
||||
merchant_id=merchant_id,
|
||||
role_code=tpl.role_code,
|
||||
defaults={
|
||||
@@ -49,8 +56,5 @@ def ensure_merchant_roles(merchant_id):
|
||||
'status': 1,
|
||||
},
|
||||
)
|
||||
if created:
|
||||
for rp in tpl.role_permissions.all():
|
||||
MerchantStaffRolePermission.objects.get_or_create(
|
||||
role=role, perm_code=rp.perm_code,
|
||||
)
|
||||
tpl_perms = list(tpl.role_permissions.values_list('perm_code', flat=True))
|
||||
_sync_role_permissions(role, tpl_perms)
|
||||
|
||||
@@ -98,6 +98,40 @@ def update_merchant_and_staff_stats(merchant_id, staff_member, amount, action, o
|
||||
)
|
||||
|
||||
|
||||
def get_staff_stats_payload(member):
|
||||
"""子客服个人统计(今日 + 累计),供 /me 与首页展示。"""
|
||||
from django.db.models import Sum
|
||||
|
||||
today = date.today()
|
||||
today_stat = MerchantStaffDailyStats.objects.filter(
|
||||
member_id=member.id, stat_date=today,
|
||||
).first()
|
||||
total = MerchantStaffDailyStats.objects.filter(member_id=member.id).aggregate(
|
||||
dispatch_count=Sum('dispatch_count'),
|
||||
dispatch_amount=Sum('dispatch_amount'),
|
||||
settle_count=Sum('settle_count'),
|
||||
settle_amount=Sum('settle_amount'),
|
||||
refund_count=Sum('refund_count'),
|
||||
refund_amount=Sum('refund_amount'),
|
||||
)
|
||||
return {
|
||||
'today_dispatch_count': (
|
||||
today_stat.dispatch_count if today_stat else int(member.today_dispatch_count or 0)
|
||||
),
|
||||
'today_dispatch_amount': str(
|
||||
today_stat.dispatch_amount if today_stat else (member.today_dispatch_amount or '0.00')
|
||||
),
|
||||
'today_refund_count': today_stat.refund_count if today_stat else 0,
|
||||
'today_settle_count': today_stat.settle_count if today_stat else 0,
|
||||
'dispatch_count': total['dispatch_count'] or 0,
|
||||
'dispatch_amount': str(total['dispatch_amount'] or '0.00'),
|
||||
'settle_count': total['settle_count'] or 0,
|
||||
'settle_amount': str(total['settle_amount'] or '0.00'),
|
||||
'refund_count': total['refund_count'] or 0,
|
||||
'refund_amount': str(total['refund_amount'] or '0.00'),
|
||||
}
|
||||
|
||||
|
||||
def bump_cancel_count(merchant_id, staff_member):
|
||||
if not staff_member:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user