fix: 会员余额购按俱乐部分天数履约,后台展示俱乐部销量
This commit is contained in:
@@ -71,6 +71,20 @@ def _format_member(m, price_row=None):
|
||||
return item
|
||||
|
||||
|
||||
def count_club_member_sales(club_id, huiyuan_id, formal_only=True):
|
||||
"""本俱乐部已支付会员单数(用于后台展示,非全局 goumai_cishu)。"""
|
||||
from products.models import Czjilu
|
||||
qs = Czjilu.query.filter(
|
||||
club_id=club_id,
|
||||
huiyuan_id=huiyuan_id,
|
||||
leixing=1,
|
||||
zhuangtai=3,
|
||||
)
|
||||
if formal_only:
|
||||
qs = qs.filter(is_trial=False)
|
||||
return qs.count()
|
||||
|
||||
|
||||
def build_member_list_payload(request):
|
||||
scope = resolve_club_scope(request)
|
||||
club_id = resolve_club_id_from_request(request)
|
||||
@@ -94,7 +108,9 @@ def build_member_list_payload(request):
|
||||
continue
|
||||
if row is not None and not row.is_enabled:
|
||||
continue
|
||||
member_list.append(_format_member(m, row))
|
||||
item = _format_member(m, row)
|
||||
item['goumai_cishu'] = count_club_member_sales(club_id, m.huiyuan_id)
|
||||
member_list.append(item)
|
||||
|
||||
return {
|
||||
'list': member_list,
|
||||
|
||||
@@ -156,6 +156,56 @@ def resolve_member_purchase_cishu(yonghuid, huiyuan_id, current_dingdan_id, club
|
||||
return resolve_formal_purchase_cishu(yonghuid, huiyuan_id, current_dingdan_id, club_id)
|
||||
|
||||
|
||||
def fulfill_member_balance_purchase(czjilu, huiyuan, club_id=None):
|
||||
"""余额抵扣购买会员:按俱乐部配置天数履约,并计入购买次数/分红。"""
|
||||
club_id = club_id or getattr(czjilu, 'club_id', None) or CLUB_ID_DEFAULT
|
||||
is_trial = bool(getattr(czjilu, 'is_trial', False))
|
||||
purchase_days = int(getattr(czjilu, 'purchase_days', None) or 0)
|
||||
if purchase_days <= 0:
|
||||
_, _, purchase_days = club_huiyuan_sellable(club_id, czjilu.huiyuan_id, is_trial=is_trial)
|
||||
|
||||
formal_cishu = None
|
||||
trial_guanshi_fc = Decimal('0')
|
||||
trial_zuzhangfc = Decimal('0')
|
||||
if is_trial:
|
||||
row = get_club_huiyuan_row(club_id, czjilu.huiyuan_id)
|
||||
if row:
|
||||
trial_guanshi_fc = Decimal(str(row.trial_guanshifc or 0))
|
||||
trial_zuzhangfc = Decimal(str(row.trial_zuzhangfc or 0))
|
||||
else:
|
||||
formal_cishu = resolve_formal_purchase_cishu(
|
||||
czjilu.yonghuid, czjilu.huiyuan_id, czjilu.dingdan_id, club_id,
|
||||
)
|
||||
|
||||
goumai_record, is_first_buy_any = _apply_huiyuan_entitlement(
|
||||
czjilu.yonghuid, czjilu.huiyuan_id, huiyuan, club_id, is_trial, purchase_days,
|
||||
)
|
||||
if is_first_buy_any:
|
||||
_add_first_buy_jifen(czjilu.yonghuid)
|
||||
|
||||
czjilu.zhuangtai = MEMBER_PAID_STATUS
|
||||
if not czjilu.purchase_days:
|
||||
czjilu.purchase_days = purchase_days
|
||||
czjilu.save(update_fields=['zhuangtai', 'purchase_days'])
|
||||
|
||||
huiyuan.goumai_cishu = (huiyuan.goumai_cishu or 0) + 1
|
||||
huiyuan.save(update_fields=['goumai_cishu'])
|
||||
|
||||
try:
|
||||
_apply_member_fenhong(
|
||||
czjilu, huiyuan,
|
||||
formal_cishu=formal_cishu,
|
||||
trial_guanshi_fc=trial_guanshi_fc,
|
||||
trial_zuzhangfc=trial_zuzhangfc,
|
||||
)
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
'余额购会员分红失败 dingdan=%s: %s', czjilu.dingdan_id, exc, exc_info=True,
|
||||
)
|
||||
|
||||
return goumai_record, is_first_buy_any
|
||||
|
||||
|
||||
def _lookup_duoci_fenhong(club_id, huiyuan_id, beneficiary_id, cishu, field):
|
||||
try:
|
||||
row = DuociFenhong.query.get(
|
||||
|
||||
Reference in New Issue
Block a user