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,15 +50,22 @@ where enabled_date >= ${biz_date}$
return recs[0] return recs[0]
return None 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): 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}) 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()
@ -86,39 +93,36 @@ async def get_remote_pricing(sor, charge, data):
return d return d
async def pricing_program_charging(sor, pricing_program_id, data): async def pricing_program_charging(sor, pricing_program_id, data):
pp = PricingProgram(pricing_program_id, sor)
await pp.init()
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
pp_items = await sor_get_program_items(sor, pricing_program_id, data['biz_date']) debug(f'{pricing_program_id=}, {data=}')
charges = [] pp_items = await sor_get_program_items(sor, pricing_program_id, data['biz_date'])
for item in pp_items: charges = []
charge = item.copy() debug(f'{pp_items=}, {data["biz_date"]=}')
spec = await pp.get_spec_by_id(charge.psid) for item in pp_items:
d = data.get(spec.spec_name) charge = item.copy()
if d is None: spec = await get_specs(sor, charge.psid)
continue if spec.pricing_spec_mode == 'spec_name':
cnt = data.get(spec.count_name, 1) d = data.get(spec.spec_name)
if spec.pricing_spec_mode == 'spec_name': if d == item.spec_value:
if d == item.spec_value: change[spec.count_name] = cnt
change[spec.count_name] = cnt charge.amount = item.pricing_amount * cnt
charge.amount = item.pricing_amount * cnt charges.append(charge)
charges.append(charge) elif spec.pricing_spec_mode == 'spec_amount':
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: if charge.pricing_unit is None or charge.pricing_unit < 1:
charge.pricing_unit = 1 charge.pricing_unit = 1
charge.amount = d * charge.pricing_amount / charge.pricing_unit charge.amount = cnt * charge.pricing_amount / charge.pricing_unit
charge[spec.spec_name] = d charges.append(charge)
charges.append(charge) elif spec.pricing_spec_mode == 'remote_pricing':
elif spec.pricing_spec_mode == 'remote_pricing': charge.amount = await get_remote_pricing(sor, charge, params=d)
charge.amount = await get_remote_pricing(sor, charge, params=d) charges.append(charge)
charges.append(charge) elif spec.pricing_spec_mode == 'spec_subtype':
elif spec.pricing_spec_mode == 'spec_subtype': sub_charges = await pricing_program_chargeing(self.sor,
sub_charges = await pricing_program_chargeing(self.sor, charge.subppid, d)
charge.subppid, d) charges += sub_charges
charges += sub_charges
return charges
return charges