Compare commits
No commits in common. "7d41fd2aba002b74ae7779a695c670fa4a8296bc" and "5138ec338df3933421185c7aa1ff185dbf0913f1" have entirely different histories.
7d41fd2aba
...
5138ec338d
@ -8,7 +8,17 @@
|
|||||||
"sortby": "name",
|
"sortby": "name",
|
||||||
"logined_userorgid": "ownerid",
|
"logined_userorgid": "ownerid",
|
||||||
"browserfields": {
|
"browserfields": {
|
||||||
"exclouded": ["id", "ownerid"]
|
"exclouded": ["id", "ownerid", "pricing_spec" ],
|
||||||
|
"alters": {
|
||||||
|
"discount": {
|
||||||
|
"rules": [
|
||||||
|
{"type": "required", "message": "折扣不能为空"},
|
||||||
|
{"type": "number", "message": "折扣必须是数字"},
|
||||||
|
{"type": "min", "value": 0, "message": "折扣不能小于0"},
|
||||||
|
{"type": "max", "value": 1, "message": "折扣不能大于1"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"data_filter": {
|
"data_filter": {
|
||||||
"AND": [
|
"AND": [
|
||||||
|
|||||||
@ -3,8 +3,7 @@
|
|||||||
"title": "定价项目时序",
|
"title": "定价项目时序",
|
||||||
"params": {
|
"params": {
|
||||||
"editable": {
|
"editable": {
|
||||||
"get_data_url": "{{entire_url('get_pricing_program_timing.dspy')}}",
|
"get_data_url": "{{entire_url('get_pricing_program_timing.dspy')}}"
|
||||||
"new_data_url": "{{entire_url('../api/add_pricing_program_timing.dspy')}}"
|
|
||||||
},
|
},
|
||||||
"sortby": "enabled_date desc",
|
"sortby": "enabled_date desc",
|
||||||
"browserfields": {
|
"browserfields": {
|
||||||
|
|||||||
@ -40,10 +40,22 @@
|
|||||||
"type": "str",
|
"type": "str",
|
||||||
"length": 32
|
"length": 32
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "discount",
|
||||||
|
"title": "供应商折扣",
|
||||||
|
"type": "float",
|
||||||
|
"length": 18,
|
||||||
|
"dec": 2
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "description",
|
"name": "description",
|
||||||
"title": "描述",
|
"title": "描述",
|
||||||
"type": "text"
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pricing_spec",
|
||||||
|
"title": "规格明细",
|
||||||
|
"type": "text"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"codes": [
|
"codes": [
|
||||||
|
|||||||
@ -3,5 +3,4 @@ from pricing.pricing import (
|
|||||||
test_pricing,
|
test_pricing,
|
||||||
generate_formula_from_factors,
|
generate_formula_from_factors,
|
||||||
get_pricing_display,
|
get_pricing_display,
|
||||||
add_pricing_program_timing,
|
|
||||||
)
|
)
|
||||||
|
|||||||
@ -24,7 +24,7 @@ def _cache_enabled():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
采用yaml描述定价策略,
|
采用yaml描述定价策略,
|
||||||
在pricing_program_timing的pricing_data中定义定价的数据字段(YAML格式)
|
在pricing_program的pricing_spec表中定义定价的数据字段
|
||||||
遵循一下规格:
|
遵循一下规格:
|
||||||
字典结构,key是字段名,需定义字段的type(类型),label(标题),value_mode(值方式)(可选),options(可选项)(可选)
|
字典结构,key是字段名,需定义字段的type(类型),label(标题),value_mode(值方式)(可选),options(可选项)(可选)
|
||||||
必须要有一个price字段,其type: float
|
必须要有一个price字段,其type: float
|
||||||
@ -78,7 +78,7 @@ price:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
pricing_program_timing表中的pricing_data字段的数据是一个只有一个属性"pricings"的字典
|
pricing_program_timing表中的pricing_data字段的数据是一个只有一个属性"pricings"的字典
|
||||||
其值为定价条目列表,每个定价条目是个字典,key值为pricing_data中fields定义的字段,
|
其值为定价条目列表,每个定价条目是个字典,key值为pricing_spec字段定义的字段,
|
||||||
pricings:
|
pricings:
|
||||||
- resolution: 480p
|
- resolution: 480p
|
||||||
duration: 4
|
duration: 4
|
||||||
@ -224,7 +224,7 @@ class PricingProgram:
|
|||||||
e = f'pricing_program({pptid}) can not find pricing_program'
|
e = f'pricing_program({pptid}) can not find pricing_program'
|
||||||
exception(f)
|
exception(f)
|
||||||
pp = pps[0]
|
pp = pps[0]
|
||||||
pp_spec = {} # pricing_spec removed
|
pp_spec = yaml.safe_load(pp.pricing_spec)
|
||||||
formula = None
|
formula = None
|
||||||
if pp_spec.get('fields'):
|
if pp_spec.get('fields'):
|
||||||
fields = pp_spec.get('fields')
|
fields = pp_spec.get('fields')
|
||||||
@ -266,7 +266,7 @@ class PricingProgram:
|
|||||||
if not recs:
|
if not recs:
|
||||||
debug(f'id={ppid} pricing_program not found')
|
debug(f'id={ppid} pricing_program not found')
|
||||||
r = recs[0]
|
r = recs[0]
|
||||||
x = DictObject() # pricing_spec removed
|
x = DictObject(** yaml.safe_load(r.pricing_spec))
|
||||||
fields = x
|
fields = x
|
||||||
if x.get('fields'):
|
if x.get('fields'):
|
||||||
fields = x['fields']
|
fields = x['fields']
|
||||||
@ -292,6 +292,24 @@ class PricingProgram:
|
|||||||
fpath = write_pattern_xlsx(recs[0].name, fields, data=data)
|
fpath = write_pattern_xlsx(recs[0].name, fields, data=data)
|
||||||
return fpath
|
return fpath
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def pp_db2app(pp):
|
||||||
|
try:
|
||||||
|
pp.pricing_spec = yaml.safe_load(pp.pricing_spec)
|
||||||
|
except Exception as e:
|
||||||
|
e = f'{pp.pricing_spec}:yaml数据格式错误'
|
||||||
|
exception(e)
|
||||||
|
raise Exception(e)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def pp_app2db(pp):
|
||||||
|
try:
|
||||||
|
pp.pricing_spec = yaml.dump(pp.pricing_spec, allow_unicode=True)
|
||||||
|
except Exception as e:
|
||||||
|
e = f'{pp.pricing_spec}:导出到yaml失败'
|
||||||
|
exception(e)
|
||||||
|
raise Exception(e)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def ppt_db2app(ppt):
|
def ppt_db2app(ppt):
|
||||||
try:
|
try:
|
||||||
@ -437,7 +455,7 @@ class PricingProgram:
|
|||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
async with get_sor_context(env, 'pricing') as sor:
|
async with get_sor_context(env, 'pricing') as sor:
|
||||||
sql = """select a.name, a.ownerid, a.providerid,
|
sql = """select a.name, a.ownerid, a.providerid,
|
||||||
pricing_belong, b.pricing_data
|
pricing_belong, discount, b.pricing_data
|
||||||
from pricing_program a, pricing_program_timing b
|
from pricing_program a, pricing_program_timing b
|
||||||
where a.id = b.ppid
|
where a.id = b.ppid
|
||||||
and a.id = ${ppid}$
|
and a.id = ${ppid}$
|
||||||
@ -471,8 +489,9 @@ class PricingProgram:
|
|||||||
prices = PricingProgram.get_pricing_from_ymalstr(data,
|
prices = PricingProgram.get_pricing_from_ymalstr(data,
|
||||||
r.pricing_data)
|
r.pricing_data)
|
||||||
amt = 0.0
|
amt = 0.0
|
||||||
|
discount = max(0.0, min(1.0, r.discount)) if r.discount is not None else 1.0
|
||||||
for p in prices:
|
for p in prices:
|
||||||
p.cost = p.amount # discount removed
|
p.cost = p.amount * discount
|
||||||
return prices
|
return prices
|
||||||
|
|
||||||
async def charging(sor, ppid, data):
|
async def charging(sor, ppid, data):
|
||||||
@ -487,7 +506,7 @@ class PricingProgram:
|
|||||||
env = ServerEnv()
|
env = ServerEnv()
|
||||||
biz_date = await env.get_business_date(sor)
|
biz_date = await env.get_business_date(sor)
|
||||||
sql = """select a.name, a.ownerid, a.providerid,
|
sql = """select a.name, a.ownerid, a.providerid,
|
||||||
pricing_belong, b.pricing_data
|
pricing_belong, discount, b.pricing_data
|
||||||
from pricing_program a, pricing_program_timing b
|
from pricing_program a, pricing_program_timing b
|
||||||
where a.id = b.ppid
|
where a.id = b.ppid
|
||||||
and a.id = ${ppid}$
|
and a.id = ${ppid}$
|
||||||
@ -504,8 +523,9 @@ order by b.enabled_date desc"""
|
|||||||
r.pricing_data)
|
r.pricing_data)
|
||||||
debug(f'{r.prices=}')
|
debug(f'{r.prices=}')
|
||||||
amt = 0.0
|
amt = 0.0
|
||||||
|
discount = max(0.0, min(1.0, r.discount)) if r.discount is not None else 1.0
|
||||||
for p in r.prices:
|
for p in r.prices:
|
||||||
p.cost = p.amount # discount removed
|
p.cost = p.amount * discount
|
||||||
return r.prices
|
return r.prices
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -1010,22 +1030,3 @@ pricings:
|
|||||||
p = PricingProgram.get_pricing_from_ymalstr(config_data, yamlstr)
|
p = PricingProgram.get_pricing_from_ymalstr(config_data, yamlstr)
|
||||||
print(f'{p=}')
|
print(f'{p=}')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def add_pricing_program_timing(env, sor, ns):
|
|
||||||
"""拉链逻辑:新增定价时序时自动处理 expired_date"""
|
|
||||||
ppid = ns.get('ppid')
|
|
||||||
enabled_date = ns.get('enabled_date')
|
|
||||||
ns['expired_date'] = '9999-12-31'
|
|
||||||
if ppid and enabled_date:
|
|
||||||
prev = await sor.R('pricing_program_timing', {'ppid': ppid, 'expired_date': '9999-12-31'})
|
|
||||||
if prev:
|
|
||||||
await sor.U('pricing_program_timing', {'id': prev[0].id, 'expired_date': enabled_date})
|
|
||||||
|
|
||||||
|
|
||||||
def load_pricing():
|
|
||||||
from ahserver.serverenv import ServerEnv
|
|
||||||
env = ServerEnv()
|
|
||||||
env.add_pricing_program_timing = add_pricing_program_timing
|
|
||||||
env.get_pricing_program_timeing = get_pricing_program_timeing
|
|
||||||
env.test_pricing = test_pricing
|
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
# 新增定价项目时序,自动处理拉链逻辑
|
|
||||||
await add_pricing_program_timing(request._run_ns, sor, params_kw)
|
|
||||||
return {'status': 'success'}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user