54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
"""各俱乐部价格 / 利率覆盖(无覆盖时回落全局 huiyuan / lilubiao)。"""
|
||
from decimal import Decimal
|
||
|
||
from jituan.constants import CLUB_ID_DEFAULT
|
||
from jituan.models import ClubHuiyuanPrice, ClubLilubiao
|
||
from orders.models import CommissionRate
|
||
from products.models import Huiyuan
|
||
|
||
|
||
def get_huiyuan_price(club_id, huiyuan_id, huiyuan_obj=None):
|
||
club_id = club_id or CLUB_ID_DEFAULT
|
||
row = ClubHuiyuanPrice.query.filter(
|
||
club_id=club_id, huiyuan_id=huiyuan_id, is_enabled=True,
|
||
).first()
|
||
if row:
|
||
return Decimal(str(row.jiage))
|
||
obj = huiyuan_obj or Huiyuan.query.filter(huiyuan_id=huiyuan_id).first()
|
||
if obj:
|
||
return Decimal(str(obj.jiage))
|
||
return Decimal('0')
|
||
|
||
|
||
def get_huiyuan_fenchong(club_id, huiyuan_id, huiyuan_obj=None):
|
||
"""返回 (guanshifc, zuzhangfc)。"""
|
||
club_id = club_id or CLUB_ID_DEFAULT
|
||
row = ClubHuiyuanPrice.query.filter(club_id=club_id, huiyuan_id=huiyuan_id).first()
|
||
if row:
|
||
return Decimal(str(row.guanshifc)), Decimal(str(row.zuzhangfc))
|
||
obj = huiyuan_obj or Huiyuan.query.filter(huiyuan_id=huiyuan_id).first()
|
||
if obj:
|
||
return Decimal(str(obj.guanshifc)), Decimal(str(getattr(obj, 'zuzhangfc', 0) or 0))
|
||
return Decimal('0'), Decimal('0')
|
||
|
||
|
||
def get_commission_rate(club_id, platform_key):
|
||
"""
|
||
读取分成利率。platform_key 与 lilubiao.Platform 一致(如 '1','3','13')。
|
||
"""
|
||
club_id = club_id or CLUB_ID_DEFAULT
|
||
config_type = int(platform_key or 0)
|
||
row = ClubLilubiao.query.filter(club_id=club_id, config_type=config_type).first()
|
||
if row is not None:
|
||
return Decimal(str(row.lilv))
|
||
cr = CommissionRate.query.filter(Platform=str(platform_key)).first()
|
||
if cr and cr.Rate is not None:
|
||
return Decimal(str(cr.Rate))
|
||
return Decimal('0')
|
||
|
||
|
||
def get_commission_rate_object(club_id, platform_key):
|
||
"""兼容旧代码 CommissionRate.Rate 访问方式。"""
|
||
rate = get_commission_rate(club_id, platform_key)
|
||
return type('ClubRate', (), {'Rate': rate, 'Platform': str(platform_key)})()
|