This commit is contained in:
yumoqing 2025-12-23 16:24:19 +08:00
parent 01d4612880
commit 3644f418a5
3 changed files with 44 additions and 40 deletions

Binary file not shown.

Binary file not shown.

View File

@ -50,6 +50,13 @@ where enabled_date >= ${biz_date}$
return recs[0]
return None
async def get_specs(sor, psid):
sql = """select a.* from pricing_spec a where a.id=${psid}$"""
recs = await sor.sqlExe(sql, {'psid': psid})
if len(recs)>0:
return recs[0]
return None
async def sor_get_program_items(sor, ppid, biz_date):
sql = """select b.* from pricing_program_timing a, pricing_item b
where b.pptid = a.id
@ -57,7 +64,7 @@ where b.pptid = a.id
and a.enabled_date <= ${biz_date}$
and a.expired_date > ${biz_date}$
"""
recs = await sor.sqlExe(sql, {'ppid': ppid})
recs = await sor.sqlExe(sql, {'ppid': ppid, 'biz_date': biz_date})
return recs
async def get_pricing_specs_by_pptid(pptid):
@ -86,31 +93,28 @@ async def get_remote_pricing(sor, charge, data):
return d
async def pricing_program_charging(sor, pricing_program_id, data):
pp = PricingProgram(pricing_program_id, sor)
await pp.init()
env = ServerEnv()
if not data.get('biz_date'):
biz_date = await env.get_business_date(self.sor)
data['biz_date'] = biz_date
debug(f'{pricing_program_id=}, {data=}')
pp_items = await sor_get_program_items(sor, pricing_program_id, data['biz_date'])
charges = []
debug(f'{pp_items=}, {data["biz_date"]=}')
for item in pp_items:
charge = item.copy()
spec = await pp.get_spec_by_id(charge.psid)
d = data.get(spec.spec_name)
if d is None:
continue
cnt = data.get(spec.count_name, 1)
spec = await get_specs(sor, charge.psid)
if spec.pricing_spec_mode == 'spec_name':
d = data.get(spec.spec_name)
if d == item.spec_value:
change[spec.count_name] = cnt
charge.amount = item.pricing_amount * cnt
charges.append(charge)
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 = d * charge.pricing_amount / charge.pricing_unit
charge[spec.spec_name] = d
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)