bugfix
This commit is contained in:
parent
2f729cc384
commit
80aa8847e6
@ -217,7 +217,7 @@ class PricingProgram:
|
|||||||
return True
|
return True
|
||||||
e = f'pricing_program_timing(id={pptid}) not found'
|
e = f'pricing_program_timing(id={pptid}) not found'
|
||||||
exception(e)
|
exception(e)
|
||||||
raise e
|
raise Exception(e)
|
||||||
e = f'pricing_program_timing(id={pptid}) read failed'
|
e = f'pricing_program_timing(id={pptid}) read failed'
|
||||||
exception(e)
|
exception(e)
|
||||||
raise e
|
raise e
|
||||||
@ -299,36 +299,6 @@ order by b.enabled_date desc"""
|
|||||||
p.cost = p.amount * r.discount
|
p.cost = p.amount * r.discount
|
||||||
return r.prices
|
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
|
@staticmethod
|
||||||
def get_pricing_from_ymalstr(config_data, yamlstr):
|
def get_pricing_from_ymalstr(config_data, yamlstr):
|
||||||
"""
|
"""
|
||||||
@ -353,8 +323,9 @@ where a.id = b.ppid
|
|||||||
p_ok = True
|
p_ok = True
|
||||||
times = 1
|
times = 1
|
||||||
unit = 1
|
unit = 1
|
||||||
|
ns = DictObject()
|
||||||
for k,spec_value in p.items():
|
for k,spec_value in p.items():
|
||||||
if k in ['price', 'formula']:
|
if k == 'formula':
|
||||||
continue
|
continue
|
||||||
f = d.fields.get(k)
|
f = d.fields.get(k)
|
||||||
if not f:
|
if not f:
|
||||||
@ -366,10 +337,8 @@ where a.id = b.ppid
|
|||||||
e = f'数据({config_data})没有({k})数据'
|
e = f'数据({config_data})没有({k})数据'
|
||||||
exception(e)
|
exception(e)
|
||||||
raise Exception(e)
|
raise Exception(e)
|
||||||
if f.type == 'unit':
|
if f.type == 'factor':
|
||||||
unit = spec_value
|
ns[k] = float(data_value)
|
||||||
elif f.type == 'times':
|
|
||||||
times = data_value
|
|
||||||
else:
|
else:
|
||||||
f = check_value(f, spec_value, data_value)
|
f = check_value(f, spec_value, data_value)
|
||||||
if not f:
|
if not f:
|
||||||
@ -377,23 +346,15 @@ where a.id = b.ppid
|
|||||||
p_ok = False
|
p_ok = False
|
||||||
break
|
break
|
||||||
if p_ok:
|
if p_ok:
|
||||||
if not p.price:
|
|
||||||
e = f'{p} 没有价格属性'
|
|
||||||
exception(e)
|
|
||||||
raise Exception(e)
|
|
||||||
np = p.copy()
|
np = p.copy()
|
||||||
times = float(times)
|
times = float(times)
|
||||||
unit = float(unit)
|
unit = float(unit)
|
||||||
formula = p.formula or d.formula
|
formula = p.formula
|
||||||
if formula:
|
if not formula:
|
||||||
ns = {
|
e = f'{p} not formula found'
|
||||||
'price': p.price,
|
exception(e)
|
||||||
'times': times,
|
raise Exception(e)
|
||||||
'unit': unit
|
np.amount = eval(formula, ns)
|
||||||
}
|
|
||||||
np.amount = eval(formula, ns)
|
|
||||||
else:
|
|
||||||
np.amount = p.price * float(times) / float(unit)
|
|
||||||
ret_items.append(np)
|
ret_items.append(np)
|
||||||
if len(ret_items) == 0:
|
if len(ret_items) == 0:
|
||||||
e = f'{config_data=}{yamlstr=}没有找到合适的定价'
|
e = f'{config_data=}{yamlstr=}没有找到合适的定价'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user