From ecb4c770c488d860066358d9b5d68ea388c7affc Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 5 Jul 2026 13:51:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=A0=E9=99=A4pricing=5Fspec/discou?= =?UTF-8?q?nt=E5=AD=97=E6=AE=B5;=20=E6=96=B0=E5=A2=9Etiming=E6=8B=89?= =?UTF-8?q?=E9=93=BE=E9=80=BB=E8=BE=91(expired=5Fdate=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E7=AE=A1=E7=90=86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json/pricing_program.json | 12 +---- json/pricing_program_timing.json | 3 +- models/pricing_program.json | 12 ----- pricing/__init__.py | 1 + pricing/pricing.py | 51 ++++++++++----------- wwwroot/api/add_pricing_program_timing.dspy | 3 ++ 6 files changed, 32 insertions(+), 50 deletions(-) create mode 100644 wwwroot/api/add_pricing_program_timing.dspy diff --git a/json/pricing_program.json b/json/pricing_program.json index 329a8c8..4cb06fa 100644 --- a/json/pricing_program.json +++ b/json/pricing_program.json @@ -8,17 +8,7 @@ "sortby": "name", "logined_userorgid": "ownerid", "browserfields": { - "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"} - ] - } - } + "exclouded": ["id", "ownerid"] }, "data_filter": { "AND": [ diff --git a/json/pricing_program_timing.json b/json/pricing_program_timing.json index 6b4636c..f4304f8 100644 --- a/json/pricing_program_timing.json +++ b/json/pricing_program_timing.json @@ -3,7 +3,8 @@ "title": "定价项目时序", "params": { "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", "browserfields": { diff --git a/models/pricing_program.json b/models/pricing_program.json index bf48c2e..e46a9c9 100644 --- a/models/pricing_program.json +++ b/models/pricing_program.json @@ -40,22 +40,10 @@ "type": "str", "length": 32 }, - { - "name": "discount", - "title": "供应商折扣", - "type": "float", - "length": 18, - "dec": 2 - }, { "name": "description", "title": "描述", "type": "text" - }, - { - "name": "pricing_spec", - "title": "规格明细", - "type": "text" } ], "codes": [ diff --git a/pricing/__init__.py b/pricing/__init__.py index 70fa323..8aa9bbd 100644 --- a/pricing/__init__.py +++ b/pricing/__init__.py @@ -3,4 +3,5 @@ from pricing.pricing import ( test_pricing, generate_formula_from_factors, get_pricing_display, + add_pricing_program_timing, ) diff --git a/pricing/pricing.py b/pricing/pricing.py index a21fd29..50eda1c 100644 --- a/pricing/pricing.py +++ b/pricing/pricing.py @@ -224,7 +224,7 @@ class PricingProgram: e = f'pricing_program({pptid}) can not find pricing_program' exception(f) pp = pps[0] - pp_spec = yaml.safe_load(pp.pricing_spec) + pp_spec = {} # pricing_spec removed formula = None if pp_spec.get('fields'): fields = pp_spec.get('fields') @@ -266,7 +266,7 @@ class PricingProgram: if not recs: debug(f'id={ppid} pricing_program not found') r = recs[0] - x = DictObject(** yaml.safe_load(r.pricing_spec)) + x = DictObject() # pricing_spec removed fields = x if x.get('fields'): fields = x['fields'] @@ -292,24 +292,6 @@ class PricingProgram: fpath = write_pattern_xlsx(recs[0].name, fields, data=data) 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 def ppt_db2app(ppt): try: @@ -455,7 +437,7 @@ class PricingProgram: env = ServerEnv() async with get_sor_context(env, 'pricing') as sor: sql = """select a.name, a.ownerid, a.providerid, - pricing_belong, discount, b.pricing_data + pricing_belong, b.pricing_data from pricing_program a, pricing_program_timing b where a.id = b.ppid and a.id = ${ppid}$ @@ -489,9 +471,8 @@ class PricingProgram: prices = PricingProgram.get_pricing_from_ymalstr(data, r.pricing_data) 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: - p.cost = p.amount * discount + p.cost = p.amount # discount removed return prices async def charging(sor, ppid, data): @@ -506,7 +487,7 @@ class PricingProgram: env = ServerEnv() biz_date = await env.get_business_date(sor) sql = """select a.name, a.ownerid, a.providerid, -pricing_belong, discount, b.pricing_data +pricing_belong, b.pricing_data from pricing_program a, pricing_program_timing b where a.id = b.ppid and a.id = ${ppid}$ @@ -523,9 +504,8 @@ order by b.enabled_date desc""" r.pricing_data) debug(f'{r.prices=}') 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: - p.cost = p.amount * discount + p.cost = p.amount # discount removed return r.prices @staticmethod @@ -1030,3 +1010,22 @@ pricings: p = PricingProgram.get_pricing_from_ymalstr(config_data, yamlstr) 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 diff --git a/wwwroot/api/add_pricing_program_timing.dspy b/wwwroot/api/add_pricing_program_timing.dspy new file mode 100644 index 0000000..244a75c --- /dev/null +++ b/wwwroot/api/add_pricing_program_timing.dspy @@ -0,0 +1,3 @@ +# 新增定价项目时序,自动处理拉链逻辑 +await add_pricing_program_timing(request._run_ns, sor, params_kw) +return {'status': 'success'}