feat(jituan): 集团多俱乐部改造 — club 隔离、财务/提现/分红/展示配置
This commit is contained in:
@@ -7,7 +7,9 @@ from django.db.models import F
|
||||
|
||||
from config.models import DailyIncomeStat, DailyPayoutStat
|
||||
from orders.models import Order, PlatformOrderExt, MerchantOrderExt, CommissionRate
|
||||
from jituan.services.club_config import get_commission_rate
|
||||
from products.models import Gsfenhong
|
||||
from jituan.services.club_penalty import resolve_gsfenhong_club_id
|
||||
from users.models import UserDashou, UserGuanshi
|
||||
|
||||
from backend.utils import update_guanshi_daily_by_action
|
||||
@@ -31,71 +33,66 @@ def get_order_user_id(order):
|
||||
return None
|
||||
|
||||
|
||||
def update_daily_income(amount):
|
||||
def update_daily_income(amount, club_id=None):
|
||||
"""
|
||||
原子更新当日收入统计(金额累加,笔数加1)。
|
||||
用于微信支付成功回调。
|
||||
|
||||
参数:
|
||||
amount: Decimal 本次收入金额
|
||||
"""
|
||||
from jituan.constants import CLUB_ID_DEFAULT
|
||||
cid = club_id or CLUB_ID_DEFAULT
|
||||
today = date.today()
|
||||
year, month, day = today.year, today.month, today.day
|
||||
|
||||
with transaction.atomic():
|
||||
stat, created = DailyIncomeStat.objects.select_for_update().get_or_create(
|
||||
date=today,
|
||||
club_id=cid,
|
||||
defaults={
|
||||
'year': year,
|
||||
'month': month,
|
||||
'day': day,
|
||||
'total_amount': amount,
|
||||
'total_count': 1
|
||||
}
|
||||
'total_count': 1,
|
||||
},
|
||||
)
|
||||
if not created:
|
||||
# 原子累加
|
||||
stat.total_amount = F('total_amount') + amount
|
||||
stat.total_count = F('total_count') + 1
|
||||
stat.save(update_fields=['total_amount', 'total_count'])
|
||||
|
||||
logger.info(
|
||||
f"每日收入更新: {today}, +{amount}元, 总金额={stat.total_amount if created else stat.total_amount + amount}, 总笔数={stat.total_count if created else stat.total_count + 1}")
|
||||
f"每日收入更新[{cid}]: {today}, +{amount}元"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def update_daily_payout(amount):
|
||||
def update_daily_payout(amount, club_id=None):
|
||||
"""
|
||||
原子更新当日出款统计(金额累加,笔数加1)。
|
||||
用于提现成功、结算打款等场景。
|
||||
|
||||
参数:
|
||||
amount: Decimal 本次出款金额
|
||||
"""
|
||||
from jituan.constants import CLUB_ID_DEFAULT
|
||||
cid = club_id or CLUB_ID_DEFAULT
|
||||
today = date.today()
|
||||
year, month, day = today.year, today.month, today.day
|
||||
|
||||
with transaction.atomic():
|
||||
stat, created = DailyPayoutStat.objects.select_for_update().get_or_create(
|
||||
date=today,
|
||||
club_id=cid,
|
||||
defaults={
|
||||
'year': year,
|
||||
'month': month,
|
||||
'day': day,
|
||||
'total_amount': amount,
|
||||
'total_count': 1
|
||||
}
|
||||
'total_count': 1,
|
||||
},
|
||||
)
|
||||
if not created:
|
||||
# 原子累加
|
||||
stat.total_amount = F('total_amount') + amount
|
||||
stat.total_count = F('total_count') + 1
|
||||
stat.save(update_fields=['total_amount', 'total_count'])
|
||||
|
||||
logger.info(f"每日出款更新: {today}, +{amount}元, 总金额={stat.total_amount if created else stat.total_amount + amount}, 总笔数={stat.total_count if created else stat.total_count + 1}")
|
||||
logger.info(f"每日出款更新[{cid}]: {today}, +{amount}元")
|
||||
|
||||
|
||||
|
||||
@@ -104,24 +101,19 @@ def update_daily_payout(amount):
|
||||
|
||||
|
||||
|
||||
def calc_shangjia_order_fencheng(jine):
|
||||
def calc_shangjia_order_fencheng(jine, club_id=None):
|
||||
"""
|
||||
商家发单时计算打手/管事分成。
|
||||
打手优先:打手+管事 > 订单金额时,管事分成为 0。
|
||||
"""
|
||||
from jituan.constants import CLUB_ID_DEFAULT
|
||||
jine = Decimal(str(jine))
|
||||
try:
|
||||
lilu_obj = CommissionRate.objects.get(Platform='3')
|
||||
rate_dashou = Decimal(str(lilu_obj.Rate)) if lilu_obj.Rate and lilu_obj.Rate > 0 else Decimal('1')
|
||||
except CommissionRate.DoesNotExist:
|
||||
cid = club_id or CLUB_ID_DEFAULT
|
||||
rate_dashou = get_commission_rate(cid, '3')
|
||||
if not rate_dashou or rate_dashou <= 0:
|
||||
rate_dashou = Decimal('1')
|
||||
|
||||
lilu_guanshi_obj = CommissionRate.objects.filter(Platform='13').first()
|
||||
rate_guanshi = (
|
||||
Decimal(str(lilu_guanshi_obj.Rate))
|
||||
if lilu_guanshi_obj and lilu_guanshi_obj.Rate is not None
|
||||
else Decimal('0')
|
||||
)
|
||||
rate_guanshi = get_commission_rate(cid, '13')
|
||||
|
||||
dashou_fencheng = (jine * rate_dashou).quantize(Decimal('0.01'))
|
||||
guanshi_raw = (jine * rate_guanshi).quantize(Decimal('0.01'))
|
||||
@@ -182,6 +174,7 @@ def settle_shangjia_order_guanshi_fenhong(order, dashou_id):
|
||||
avatar=user_main.Avatar if user_main else None,
|
||||
nicheng=dashou.nicheng or '未知打手',
|
||||
fenhong_leixing=3,
|
||||
club_id=resolve_gsfenhong_club_id(dingdan_id=order.OrderID, dashouid=dashou_id, order=order),
|
||||
)
|
||||
logger.info(
|
||||
f"商家订单管事分红成功: 订单{order.OrderID}, 管事{guanshi_id}, "
|
||||
|
||||
Reference in New Issue
Block a user