完成后台多俱乐部数据隔离:订单/会员/财务/板块,并添加星之界初始化命令
This commit is contained in:
226
backend/view.py
226
backend/view.py
@@ -2726,21 +2726,10 @@ class GetMemberListView(APIView):
|
||||
if '3300a' not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限查看会员列表'})
|
||||
|
||||
members = Huiyuan.query.all().order_by('-CreateTime')
|
||||
member_list = []
|
||||
for m in members:
|
||||
member_list.append({
|
||||
'huiyuan_id': m.huiyuan_id,
|
||||
'jieshao': m.jieshao,
|
||||
'jtjieshao': m.jtjieshao,
|
||||
'jiage': str(m.jiage),
|
||||
'guanshifc': str(m.guanshifc),
|
||||
'zuzhangfc': str(m.zuzhangfc),
|
||||
'goumai_cishu': m.goumai_cishu,
|
||||
'CreateTime': m.CreateTime.isoformat() if m.CreateTime else None,
|
||||
'UpdateTime': m.UpdateTime.isoformat() if m.UpdateTime else None,
|
||||
})
|
||||
return Response({'code': 0, 'data': {'list': member_list}})
|
||||
from jituan.services.club_member_admin import build_member_list_payload
|
||||
|
||||
payload = build_member_list_payload(request)
|
||||
return Response({'code': 0, 'data': {'list': payload['list']}, 'club_id': payload.get('club_id'), 'scope': payload.get('scope')})
|
||||
|
||||
|
||||
class UpdateMemberView(APIView):
|
||||
@@ -2790,19 +2779,13 @@ class UpdateMemberView(APIView):
|
||||
if '3300a' not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限修改会员'})
|
||||
|
||||
with transaction.atomic():
|
||||
try:
|
||||
member = Huiyuan.objects.select_for_update().get(huiyuan_id=huiyuan_id)
|
||||
except Huiyuan.DoesNotExist:
|
||||
return Response({'code': 404, 'msg': '会员不存在'})
|
||||
|
||||
member.jieshao = jieshao
|
||||
member.jiage = jiage
|
||||
member.guanshifc = guanshifc
|
||||
member.zuzhangfc = zuzhangfc
|
||||
member.jtjieshao = jtjieshao
|
||||
member.save()
|
||||
from jituan.services.club_member_admin import update_member_for_club
|
||||
|
||||
data, err = update_member_for_club(
|
||||
request, huiyuan_id, jieshao, jiage, guanshifc, zuzhangfc, jtjieshao,
|
||||
)
|
||||
if err:
|
||||
return Response({'code': 400, 'msg': err})
|
||||
return Response({'code': 0, 'msg': '修改成功'})
|
||||
|
||||
|
||||
@@ -2851,26 +2834,14 @@ class AddMemberView(APIView):
|
||||
if '3300a' not in permissions:
|
||||
return Response({'code': 403, 'msg': '无权限添加会员'})
|
||||
|
||||
# 生成唯一6位会员ID(数字+字母)
|
||||
def generate_huiyuan_id():
|
||||
while True:
|
||||
new_id = ''.join(random.choices(string.ascii_uppercase + string.digits, k=6))
|
||||
if not Huiyuan.query.filter(huiyuan_id=new_id).exists():
|
||||
return new_id
|
||||
from jituan.services.club_member_admin import add_member_for_club
|
||||
|
||||
with transaction.atomic():
|
||||
new_id = generate_huiyuan_id()
|
||||
member = Huiyuan.query.create(
|
||||
huiyuan_id=new_id,
|
||||
jieshao=jieshao,
|
||||
jiage=jiage,
|
||||
guanshifc=guanshifc,
|
||||
zuzhangfc=zuzhangfc,
|
||||
jtjieshao=jtjieshao,
|
||||
goumai_cishu=0
|
||||
)
|
||||
|
||||
return Response({'code': 0, 'msg': '添加成功', 'data': {'huiyuan_id': member.huiyuan_id}})
|
||||
data, err = add_member_for_club(
|
||||
request, jieshao, jiage, guanshifc, zuzhangfc, jtjieshao,
|
||||
)
|
||||
if err:
|
||||
return Response({'code': 400, 'msg': err})
|
||||
return Response({'code': 0, 'msg': '添加成功', 'data': data})
|
||||
|
||||
|
||||
|
||||
@@ -6755,14 +6726,34 @@ class HqbkxxView(APIView):
|
||||
'bankuai_id': sp.bankuai_id
|
||||
})
|
||||
|
||||
# 7. 查询所有会员
|
||||
# 7. 查询会员(附带当前俱乐部售价)
|
||||
from jituan.constants import CLUB_ID_DEFAULT, DATA_SCOPE_ALL
|
||||
from jituan.models import ClubHuiyuanPrice
|
||||
from jituan.services.club_context import resolve_club_id_from_request, resolve_club_scope
|
||||
|
||||
scope = resolve_club_scope(request)
|
||||
club_id = resolve_club_id_from_request(request)
|
||||
price_map = {}
|
||||
if scope != DATA_SCOPE_ALL:
|
||||
for row in ClubHuiyuanPrice.query.filter(club_id=club_id):
|
||||
price_map[row.huiyuan_id] = row
|
||||
|
||||
huiyuan_list = []
|
||||
for hy in Huiyuan.query.all():
|
||||
huiyuan_list.append({
|
||||
row = price_map.get(hy.huiyuan_id)
|
||||
if scope != DATA_SCOPE_ALL and club_id != CLUB_ID_DEFAULT and row is None:
|
||||
continue
|
||||
if row is not None and not row.is_enabled:
|
||||
continue
|
||||
item = {
|
||||
'huiyuan_id': hy.huiyuan_id,
|
||||
'jieshao': hy.jieshao,
|
||||
'bankuai_id': hy.bankuai_id
|
||||
})
|
||||
'bankuai_id': hy.bankuai_id,
|
||||
'jiage': str(row.jiage) if row else str(hy.jiage),
|
||||
'guanshifc': str(row.guanshifc) if row else str(hy.guanshifc),
|
||||
'zuzhangfc': str(row.zuzhangfc) if row else str(hy.zuzhangfc),
|
||||
}
|
||||
huiyuan_list.append(item)
|
||||
|
||||
return Response({
|
||||
'code': 0,
|
||||
@@ -6770,7 +6761,9 @@ class HqbkxxView(APIView):
|
||||
'data': {
|
||||
'bankuai': bankuai_list,
|
||||
'shangpin_leixing': shangpin_leixing_list,
|
||||
'huiyuan': huiyuan_list
|
||||
'huiyuan': huiyuan_list,
|
||||
'club_id': club_id,
|
||||
'scope': scope,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -6935,131 +6928,14 @@ class CaiwuView(APIView):
|
||||
if 'caiwu' not in permissions:
|
||||
return Response({'code': 403, 'msg': '无财务查看权限'}, status=403)
|
||||
|
||||
today = date.today()
|
||||
today_start = datetime.combine(today, datetime.min.time())
|
||||
today_end = today_start + timedelta(days=1)
|
||||
|
||||
from jituan.services.club_context import (
|
||||
filter_club_char_field,
|
||||
filter_queryset_by_club,
|
||||
resolve_club_id_from_request,
|
||||
resolve_club_scope,
|
||||
)
|
||||
from jituan.services.daily_finance_display import (
|
||||
cumulative_income_payout,
|
||||
daily_stats_for_request,
|
||||
sum_payout_stat_for_date,
|
||||
today_income_for_dashboard,
|
||||
)
|
||||
|
||||
order_qs = filter_queryset_by_club(Order.query.all(), request, club_field='ClubID')
|
||||
|
||||
# 四个板子:按 Header 俱乐部范围读 daily_income_stat / daily_payout_stat
|
||||
today_income_amount, today_income_count = today_income_for_dashboard(today, request)
|
||||
today_payout_amount, today_payout_count = sum_payout_stat_for_date(today, request)
|
||||
|
||||
# 今日订单(已付款及之后的状态)
|
||||
today_orders = order_qs.filter(
|
||||
CreateTime__gte=today_start,
|
||||
CreateTime__lt=today_end,
|
||||
Status__in=[1,2,3,4,5,6,7,8]
|
||||
)
|
||||
today_order_count = today_orders.count()
|
||||
today_order_amount = float(today_orders.aggregate(total=Sum('Amount'))['total'] or 0.00)
|
||||
|
||||
# 今日成交(Status=3)
|
||||
today_completed = Order.query.filter(
|
||||
CreateTime__gte=today_start,
|
||||
CreateTime__lt=today_end,
|
||||
Status=3
|
||||
)
|
||||
today_completed_count = today_completed.count()
|
||||
today_completed_amount = float(today_completed.aggregate(total=Sum('Amount'))['total'] or 0.00)
|
||||
|
||||
# 今日退款(Status=5)
|
||||
today_tuikuan = Order.query.filter(
|
||||
CreateTime__gte=today_start,
|
||||
CreateTime__lt=today_end,
|
||||
Status=5
|
||||
)
|
||||
today_tuikuan_count = today_tuikuan.count()
|
||||
today_tuikuan_amount = float(today_tuikuan.aggregate(total=Sum('Amount'))['total'] or 0.00)
|
||||
|
||||
# 今日充值(会员充值,leixing=1, zhuangtai=3)
|
||||
cz_qs = filter_club_char_field(Czjilu.query.all(), request, field='club_id')
|
||||
today_chongzhi = cz_qs.filter(
|
||||
CreateTime__gte=today_start,
|
||||
CreateTime__lt=today_end,
|
||||
leixing=1,
|
||||
zhuangtai=3
|
||||
)
|
||||
today_chongzhi_count = today_chongzhi.count()
|
||||
today_chongzhi_amount = float(today_chongzhi.aggregate(total=Sum('jine'))['total'] or 0.00)
|
||||
|
||||
# 今日新增会员
|
||||
hy_qs = filter_club_char_field(Huiyuangoumai.query.all(), request, field='club_id')
|
||||
new_huiyuan_user_ids = hy_qs.filter(
|
||||
CreateTime__gte=today_start,
|
||||
CreateTime__lt=today_end
|
||||
).values_list('yonghu_id', flat=True).distinct()
|
||||
today_new_huiyuan = len(new_huiyuan_user_ids)
|
||||
|
||||
# 新增会员充值总额(这些用户今天的会员充值金额)
|
||||
today_new_huiyuan_amount = 0.0
|
||||
if new_huiyuan_user_ids:
|
||||
amount_sum = cz_qs.filter(
|
||||
CreateTime__gte=today_start,
|
||||
CreateTime__lt=today_end,
|
||||
yonghuid__in=new_huiyuan_user_ids,
|
||||
leixing=1,
|
||||
zhuangtai=3
|
||||
).aggregate(total=Sum('jine'))
|
||||
today_new_huiyuan_amount = float(amount_sum['total'] or 0.0)
|
||||
|
||||
# 各角色可提现余额总和
|
||||
all_guanshi_yue = float(UserGuanshi.query.aggregate(total=Sum('yue'))['total'] or 0.00)
|
||||
all_dashou_yue = float(UserDashou.query.aggregate(total=Sum('yue'))['total'] or 0.00)
|
||||
all_zuzhang_yue = float(UserZuzhang.query.aggregate(total=Sum('ketixian_jine'))['total'] or 0.00)
|
||||
all_shangjia_yue = float(UserShangjia.query.aggregate(total=Sum('yue'))['total'] or 0.00)
|
||||
|
||||
# 累计收支 / 利润(当前俱乐部视图范围)
|
||||
total_income, total_payout, platform_profit = cumulative_income_payout(request)
|
||||
|
||||
daily_stats = daily_stats_for_request(request, days=30)
|
||||
|
||||
return Response({
|
||||
'code': 0,
|
||||
'msg': 'ok',
|
||||
'data': {
|
||||
'club_id': resolve_club_id_from_request(request),
|
||||
'scope': resolve_club_scope(request),
|
||||
'today_income': round(today_income_amount, 2),
|
||||
'today_income_count': today_income_count,
|
||||
'today_payout': round(today_payout_amount, 2),
|
||||
'today_payout_count': today_payout_count,
|
||||
'today_order_count': today_order_count,
|
||||
'today_order_amount': round(today_order_amount, 2),
|
||||
'today_completed_count': today_completed_count,
|
||||
'today_completed_amount': round(today_completed_amount, 2),
|
||||
'today_tuikuan_count': today_tuikuan_count,
|
||||
'today_tuikuan_amount': round(today_tuikuan_amount, 2),
|
||||
'today_chongzhi_count': today_chongzhi_count,
|
||||
'today_chongzhi_amount': round(today_chongzhi_amount, 2),
|
||||
'today_new_huiyuan': today_new_huiyuan,
|
||||
'today_new_huiyuan_amount': round(today_new_huiyuan_amount, 2),
|
||||
'all_guanshi_yue': round(all_guanshi_yue, 2),
|
||||
'all_dashou_yue': round(all_dashou_yue, 2),
|
||||
'all_zuzhang_yue': round(all_zuzhang_yue, 2),
|
||||
'all_shangjia_yue': round(all_shangjia_yue, 2),
|
||||
'total_income': round(total_income, 2),
|
||||
'total_payout': round(total_payout, 2),
|
||||
'platform_profit': platform_profit,
|
||||
'daily_stats': daily_stats
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
from jituan.services.caiwu_stats import build_caiwu_payload
|
||||
|
||||
try:
|
||||
data = build_caiwu_payload(request)
|
||||
return Response({'code': 0, 'msg': 'ok', 'data': data})
|
||||
except Exception:
|
||||
logger.exception('CaiwuView 异常')
|
||||
return Response({'code': 99, 'msg': '统计失败'}, status=500)
|
||||
|
||||
|
||||
class CwhybkhqView(APIView):
|
||||
|
||||
Reference in New Issue
Block a user