This commit is contained in:
yumoqing 2026-03-19 16:50:44 +08:00
parent 4214f4e2de
commit d884132d77
4 changed files with 47 additions and 38 deletions

Binary file not shown.

View File

@ -1,15 +1,8 @@
from pricing.pricing import (
pricing_program_charging,
get_pricing_specs_by_pptid,
get_all_spec_fields_by_pptid,
sor_get_spec_fields,
get_spec_names_fields)
PricingProgram
)
from ahserver.serverenv import ServerEnv
def load_pricing():
env = ServerEnv()
env.pricing_program_charging = pricing_program_charging
env.get_pricing_specs_by_pptid = get_pricing_specs_by_pptid
env.get_spec_names_fields = get_spec_names_fields
env.get_all_spec_fields_by_pptid = get_all_spec_fields_by_pptid
env.sor_get_spec_fields = sor_get_spec_fields
env.calculate_prices = PricingProgram.pricing

View File

@ -139,26 +139,8 @@ def check_value(field, spec_value, data_value):
return x
class PricingProgram:
def parse_pricing_spec(self, yamlstr):
d = yaml.safe_load(yamlstr)
assert isinstance(d, list)
return d
async def add_pricing_program(self, sor,
name, ownerid,
description, pricing_spec, id=None):
env = ServerEnv()
if not id:
id = env.uuid()
yamlstr = yaml.dump(pricing_spec)
await sor.C('pricing_program', {
'id': id,
'name': name,
'ownerid': ownerid,
'description': description,
'pricing_spec': ymalstr
})
async def pp_db2app(self, pp):
@staticmethod
def pp_db2app(pp):
try:
pp.pricing_spec = yaml.safe_load(pp.pricing_spec)
except Exception as e:
@ -166,14 +148,17 @@ class PricingProgram:
exception(e)
raise Exception(e)
async def pp_app2db(self, pp):
@staticmethod
def pp_app2db(pp):
try:
pp.pricing_spec = yaml.dump(pp.pricing_spec)
except Exception as e:
e = f'{pp.pricing_spec}:导出到yaml失败'
exception(e)
raise Exception(e)
async def ppt_db2app(self, ppt):
@staticmethod
def ppt_db2app(ppt):
try:
ppt.pricing_data = yaml.safe_load(ppt.pricing_data)
except Exception as e:
@ -181,7 +166,8 @@ class PricingProgram:
exception(e)
raise Exception(e)
async def ppt_app2db(self, ppt):
@staticmethod
def ppt_app2db(ppt):
try:
ppt.pricing_data = yaml.dump(ppt.pricing_data)
except Exception as e:
@ -189,7 +175,37 @@ class PricingProgram:
exception(e)
raise Exception(e)
def pricing(self, config_data, yamlstr):
@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_date)
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):
"""
yamlstr是从
d = None

View File

@ -7,14 +7,14 @@
"items":[
{
"name": "pricing_type",
"icon": "{{entire_url('/pricing/imgs/pricing_type.svg')}}",
"label": "定价类型",
"url": "{{entire_url('/pricing/pricing_type')}}"
"icon": "{{entire_url('/pricing/imgs/pricing_program_timing.svg')}}",
"label": "项目定价",
"url": "{{entire_url('/pricing/pricing_program_timing')}}"
},
{
"name": "pricing_program",
"icon": "{{entire_url('/pricing/imgs/pricing_program.svg')}}",
"label": "定价项目",
"label": "定价项目管理",
"url": "{{entire_url('/pricing/pricing_program')}}"
}
]