From 4f4d3d5c3b3251fcb062962d32b6c9383ff843a5 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 6 Feb 2025 18:50:10 +0800 Subject: [PATCH] bugfix --- platformbiz/pricing.py | 90 ++++++++++++++++++++++++++++++++++++++++++ platformbiz/sale.py | 70 -------------------------------- 2 files changed, 90 insertions(+), 70 deletions(-) create mode 100644 platformbiz/pricing.py delete mode 100644 platformbiz/sale.py diff --git a/platformbiz/pricing.py b/platformbiz/pricing.py new file mode 100644 index 0000000..aec8923 --- /dev/null +++ b/platformbiz/pricing.py @@ -0,0 +1,90 @@ + +from appPublic.log import debug, exception +from traceback import format_exc + +async def get_fact_price(sor, sellerid, buyerid, productid, fact_config): + pass +async def get_sell_price(sor, sellerid, buyerid, productid, list_price): + """ + 获得商品售价 + """ + +async def get_price(sor, sellerid, buyerid, productid, prod_config): + """ + 获得商品价格 + resellerid:商户id + productid:商品id + prod_config:商品配置 + 返回 + [ + {ownerid, list_price, price}, ... + ] + """ + cost_pricing_infos = [] + sql1 = """select a.*, +b.pricing_mode, +b.count_price, +b.pricingapiid +from product a left join prodpricing b on a.id=b.prodid +where a.id = ${productid}$ + and a.ownerid = ${sellerid}$""" + prods = await sor.sqlExe(sql1, {'productid':productid, 'sellerid':sellerid}) + if len(prods) < 1: + e = Exception(f'{resellerid=} {productid=} product not found') + exception(f'{e=}') + raise e + prod = prods[0] + if prod.agreeid is not None: + cost_pricing_infos = get_price(sor, prod.providerid, sellerid, prod.providerpid, prod_config) + + if prod.pricing_mode == '0' and prod.count_price: + # 按数量计费 + list_price = prod_config.get('count',1) * prod.count_price + sell_price = await get_sell_price(sor, sellerid, buyerid, productid, list_price) + pricing_info = { + 'sellerid': sellerid, + 'buyerid': buyerid, + 'productid': productid, + 'list_price': list_price, + 'sell_price': sell_price + } + elif prod.pricing_mode == '1': + # 按资源因子计费 + list_price = await get_fact_pricing(sor, productid, prod_config) + sell_price = await get_sell_price(sor, sellerid, buyerid, productid, list_price) + pricing_info = { + 'sellerid': sellerid, + 'buyerid': buyerid, + 'productid': productid, + 'list_price': list_price, + 'sell_price': sell_price + } + elif prod_pricing_mode == '2': + # 外部计费 + f = get_serverenv('pricing_api') + list_price = await f(sor, prod.pricingapiid, providerpid, prod_config) + sell_price = await get_sell_price(sor, sellerid, buyerid, productid, list_price) + pricing_info = { + 'sellerid': sellerid, + 'buyerid': buyerid, + 'productid': productid, + 'list_price': list_price, + 'sell_price': sell_price + } + else: + # 供应商计费 + if len(cost_pricing_info) < 1: + e = Exception(f'{sellerid=}, {buyerid=}, {productid=} has not resell agreement') + exception(e) + raise e + list_price = cost_pricing_info[-1]['list_price'] + sell_price = await get_sell_price(sor, sellerid, buyerid, productid, list_price) + pricing_info = { + 'sellerid': sellerid, + 'buyerid': buyerid, + 'productid': productid, + 'list_price': list_price, + 'sell_price': sell_price + } + cost_pricing_info.append(pricing_info) + return cost_pricing_info diff --git a/platformbiz/sale.py b/platformbiz/sale.py deleted file mode 100644 index 81dfd31..0000000 --- a/platformbiz/sale.py +++ /dev/null @@ -1,70 +0,0 @@ - -from appPublic.log import debug, exception -from traceback import format_exc - - -async def get_price(sor, sellerid, buyerid, productid, prod_config): - """ - 获得商品价格 - resellerid:商户id - productid:商品id - prod_config:商品配置 - 返回 - [ - {ownerid, list_price, price}, ... - ] - """ - sql1 = """select a.*, -b.pricing_mode, -b.count_price, -b.pricingapiid -from product a left join prodpricing b on a.id=b.prodid -where a.id = ${productid}$ - and a.ownerid = ${sellerid}$""" - prods = await sor.sqlExe(sql1, {'productid':productid, 'sellerid':sellerid}) - if len(prods) < 1: - e = Exception(f'{resellerid=} {productid=} product not found') - exception(f'{e=}') - raise e - prod = prods[0] - if prod.pricing_mode == '0' and prod.count_price: - # 按数量计费 - pricing_info = { - 'ownerid':resellerid, - 'buyerid':buyerid, - 'productid':productid, - 'list_price': prod_config.get('count',1) * prod.count_price, - 'price': - } - elif prod.pricing_mode == '2': - # 按资源因子计费 - pricing_info = await fact_pricing(sor, productid, prod_config) - elif prod_pricing_mode == '2': - # 外部计费 - f = get_serverenv('pricing_api') - pricing_info = await f(sor, prod.pricingapiid, providerpid, prod_config) - else: - pricing_info = { - } - - sql = """select a.*, -b.providerpid, -c.pricing_mode, -c.agreeid, -c.discount -from product a, agreeproduct b, agreedetail c -where a.id = b.resellerpid - and a.orgid = ${resellerid}$ - and id = ${productid}$ - and a.providerpid = b.providerpid - and b.agreedetailid = c.id -""" - ns = { - "resellerid":resellerid, - "productid":productid - } - recs = await sor.sqlExe(sql, ns.copy()) - if len(recs) < 1: - e = Exception( - return None - d =