From a176289226d020fdf56c80c06eca44163d00000f Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 5 Feb 2025 18:55:35 +0800 Subject: [PATCH] bugfix --- platformbiz/init.py | 3 +- platformbiz/pb_acc.py | 14 ++++++++- platformbiz/sale.py | 70 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 platformbiz/sale.py diff --git a/platformbiz/init.py b/platformbiz/init.py index d5e78d3..69d243d 100644 --- a/platformbiz/init.py +++ b/platformbiz/init.py @@ -1,6 +1,6 @@ from ahserver.serverenv import ServerEnv, get_serverenv from platformbiz.recharge import Recharge -from platformbiz.pb_acc import PlatformBizAccRecharge, get_owner_orgid +from platformbiz.pb_acc import PlatformBizAccRecharge, get_owner_orgid, get_balance from platformbiz.biz_order import change_recharge_status def load_platformbiz(): @@ -9,4 +9,5 @@ def load_platformbiz(): g.PlatformBizAccRecharge = PlatformBizAccRecharge g.change_recharge_status = change_recharge_status g.get_owner_orgid = get_owner_orgid + g.get_balance = get_balance diff --git a/platformbiz/pb_acc.py b/platformbiz/pb_acc.py index df3e54e..dbbe647 100644 --- a/platformbiz/pb_acc.py +++ b/platformbiz/pb_acc.py @@ -1,12 +1,24 @@ import time from appPublic.timeUtils import timestampstr +from appPublic.registerfunction import rfexe +from sqlor.dbpools import DBPools from ahserver.serverenv import get_serverenv from accounting.accounting_config import Accounting + from accounting.bill import write_bill -def get_owner_orgid(sor, orgid): +async def get_owner_orgid(sor, orgid): return '0' +async def get_balance(orgid): + db = DBPools() + dbname = await rfexe('get_module_dbname', 'platformbiz') + async with db.sqlorContext(dbname) as sor: + f = get_serverenv('getCustomerBalance') + if f: + return await f(sor, orgid) + return None + class PlatformBizAcc: async def get_orgid_by_trans_role(self, sor, orgtype): if orgtype== 'customer': diff --git a/platformbiz/sale.py b/platformbiz/sale.py new file mode 100644 index 0000000..81dfd31 --- /dev/null +++ b/platformbiz/sale.py @@ -0,0 +1,70 @@ + +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 =