This commit is contained in:
yumoqing 2026-03-25 16:36:54 +08:00
parent 2f729cc384
commit 80aa8847e6

View File

@ -217,7 +217,7 @@ class PricingProgram:
return True
e = f'pricing_program_timing(id={pptid}) not found'
exception(e)
raise e
raise Exception(e)
e = f'pricing_program_timing(id={pptid}) read failed'
exception(e)
raise e
@ -299,36 +299,6 @@ order by b.enabled_date desc"""
p.cost = p.amount * r.discount
return r.prices
@staticmethod
async def pricing(ppid, data):
env = ServerEnv()
async with get_sor_context(env, 'pricing') as sor:
biz_date = await get_business_date(sor)
sql = """select a.name, a.ownerid, a.providerid,
pricing_belong, discount, b.pricing_data
from pricing_program a, pricing_program_timing b
where a.id = b.ppid
and a.id = ${ppid}$
and b.enabled_date <= ${biz_date}$
and b.expired_date > ${biz_date}$
order by b.enabled_date desc"""
recs = await sor.sqlExe(sql, {
'ppid': ppid,
'biz_date': biz_date
})
if recs:
r = recs[0]
r.prices = PricingProgram.get_pricing_from_ymalstr(data,
r.pricing_data)
debug(f'{r.prices=}')
amt = 0.0
for p in r.prices:
amt += p.amount
if r.pricing_belong == 'provider':
return amt, amt * r.discount # 售价, 成本
return amt, 0
return r
@staticmethod
def get_pricing_from_ymalstr(config_data, yamlstr):
"""
@ -353,8 +323,9 @@ where a.id = b.ppid
p_ok = True
times = 1
unit = 1
ns = DictObject()
for k,spec_value in p.items():
if k in ['price', 'formula']:
if k == 'formula':
continue
f = d.fields.get(k)
if not f:
@ -366,10 +337,8 @@ where a.id = b.ppid
e = f'数据({config_data})没有({k})数据'
exception(e)
raise Exception(e)
if f.type == 'unit':
unit = spec_value
elif f.type == 'times':
times = data_value
if f.type == 'factor':
ns[k] = float(data_value)
else:
f = check_value(f, spec_value, data_value)
if not f:
@ -377,23 +346,15 @@ where a.id = b.ppid
p_ok = False
break
if p_ok:
if not p.price:
e = f'{p} 没有价格属性'
exception(e)
raise Exception(e)
np = p.copy()
times = float(times)
unit = float(unit)
formula = p.formula or d.formula
if formula:
ns = {
'price': p.price,
'times': times,
'unit': unit
}
np.amount = eval(formula, ns)
else:
np.amount = p.price * float(times) / float(unit)
formula = p.formula
if not formula:
e = f'{p} not formula found'
exception(e)
raise Exception(e)
np.amount = eval(formula, ns)
ret_items.append(np)
if len(ret_items) == 0:
e = f'{config_data=}{yamlstr=}没有找到合适的定价'