bugfix
This commit is contained in:
parent
a176289226
commit
4f4d3d5c3b
90
platformbiz/pricing.py
Normal file
90
platformbiz/pricing.py
Normal file
@ -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
|
@ -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 =
|
|
Loading…
Reference in New Issue
Block a user