This commit is contained in:
yumoqing 2025-12-23 17:16:53 +08:00
parent d386373abb
commit d407b312cf

View File

@ -1,3 +1,4 @@
import json
from ahserver.serverenv import ServerEnv from ahserver.serverenv import ServerEnv
from sqlor.dbpools import DBPools from sqlor.dbpools import DBPools
from appPublic.log import debug, exception from appPublic.log import debug, exception
@ -51,21 +52,21 @@ where enabled_date >= ${biz_date}$
return None return None
async def get_specs(sor, psid): async def get_specs(sor, psid):
sql = """select a.* from pricing_spec a where a.id=${psid}$""" sql = """select a.* from pricing_spec a where a.id=${psid}$"""
recs = await sor.sqlExe(sql, {'psid': psid}) recs = await sor.sqlExe(sql, {'psid': psid})
if len(recs)>0: if len(recs)>0:
return recs[0] return recs[0]
return None return None
async def sor_get_program_items(sor, ppid, biz_date): async def sor_get_program_items(sor, ppid, biz_date):
sql = """select b.* from pricing_program_timing a, pricing_item b sql = """select b.* from pricing_program_timing a, pricing_item b
where b.pptid = a.id where b.pptid = a.id
and a.ppid = ${ppid}$ and a.ppid = ${ppid}$
and a.enabled_date <= ${biz_date}$ and a.enabled_date <= ${biz_date}$
and a.expired_date > ${biz_date}$ and a.expired_date > ${biz_date}$
""" """
recs = await sor.sqlExe(sql, {'ppid': ppid, 'biz_date': biz_date}) recs = await sor.sqlExe(sql, {'ppid': ppid, 'biz_date': biz_date})
return recs return recs
async def get_pricing_specs_by_pptid(pptid): async def get_pricing_specs_by_pptid(pptid):
env = ServerEnv() env = ServerEnv()
@ -94,35 +95,35 @@ async def get_remote_pricing(sor, charge, data):
async def pricing_program_charging(sor, pricing_program_id, data): async def pricing_program_charging(sor, pricing_program_id, data):
env = ServerEnv() env = ServerEnv()
if not data.get('biz_date'): if not data.get('biz_date'):
biz_date = await env.get_business_date(self.sor) biz_date = await env.get_business_date(self.sor)
data['biz_date'] = biz_date data['biz_date'] = biz_date
debug(f'{pricing_program_id=}, {data=}') debug(f'{pricing_program_id=}, {data=}')
pp_items = await sor_get_program_items(sor, pricing_program_id, data['biz_date']) pp_items = await sor_get_program_items(sor, pricing_program_id, data['biz_date'])
charges = [] charges = []
debug(f'{pp_items=}, {data["biz_date"]=}') debug(f'{pp_items=}, {data["biz_date"]=}')
for item in pp_items: for item in pp_items:
charge = item.copy() charge = item.copy()
spec = await get_specs(sor, charge.psid) spec = await get_specs(sor, charge.psid)
if spec.pricing_spec_mode == 'spec_name': if spec.pricing_spec_mode == 'spec_amount':
d = data.get(spec.spec_name) if item.spec_value:
if d == item.spec_value: d = json.loads(item.spec_value)
change[spec.count_name] = cnt for k,v in d.items():
charge.amount = item.pricing_amount * cnt if v != item['k']:
charges.append(charge) continue
elif spec.pricing_spec_mode == 'spec_amount':
cnt = data.get(spec.count_name, 1)
if charge.pricing_unit is None or charge.pricing_unit < 1:
charge.pricing_unit = 1
charge.amount = cnt * charge.pricing_amount / charge.pricing_unit
charges.append(charge)
elif spec.pricing_spec_mode == 'remote_pricing':
charge.amount = await get_remote_pricing(sor, charge, params=d)
charges.append(charge)
elif spec.pricing_spec_mode == 'spec_subtype':
sub_charges = await pricing_program_chargeing(self.sor,
charge.subppid, d)
charges += sub_charges
return charges cnt = data.get(spec.count_name, 1)
if charge.pricing_unit is None or charge.pricing_unit < 1:
charge.pricing_unit = 1
charge.amount = cnt * charge.pricing_amount / charge.pricing_unit
charges.append(charge)
elif spec.pricing_spec_mode == 'remote_pricing':
charge.amount = await get_remote_pricing(sor, charge, params=d)
charges.append(charge)
elif spec.pricing_spec_mode == 'spec_subtype':
sub_charges = await pricing_program_chargeing(self.sor,
charge.subppid, d)
charges += sub_charges
return charges