This commit is contained in:
yumoqing 2025-03-03 16:38:09 +08:00
parent f33aff94df
commit 82c6bcba02
3 changed files with 38 additions and 41 deletions

View File

@ -2,7 +2,8 @@ from ahserver.serverenv import ServerEnv, get_serverenv
from platformbiz.recharge import Recharge
from platformbiz.pb_acc import PlatformBizAccRecharge, get_owner_orgid, get_balance
from platformbiz.biz_order import change_recharge_status
from platformbiz.pricing import calc_spec_price, get_sell_price
from platformbiz.pricing import calc_prod_price, get_sell_price, get_price_infos
from platformbiz.product import agree_product_clone
def load_platformbiz():
g = ServerEnv()
@ -11,4 +12,7 @@ def load_platformbiz():
g.change_recharge_status = change_recharge_status
g.get_owner_orgid = get_owner_orgid
g.get_balance = get_balance
g.calc_prod_price = calc_prod_price
g.get_sell_price = get_sell_price
g.get_price_infos = get_price_infos
g.agree_product_clone = agree_product_clone

View File

@ -3,7 +3,7 @@ from appPublic.log import debug, exception
from ahserver.serverenv import get_serverenv
from traceback import format_exc
def get_date_between(use_date, step_type):
def get_step_dates(use_date, step_type):
if step_type == '0':
# 总金额
return '1000-01-01', '9999-12-31'
@ -56,7 +56,10 @@ where adid = ${adid}
return rec.discount
async def get_sale_amount(sor, step_type, sellerid, buyerid):
"""
统计销售收入根据step_type分别统计总销售额本年销售累计
本季度销售累计本月销售累计和本周销售累计等
"""
subjectname = '供应商分销收入'
f = get_serverenv('getAccountByName')
if f is None:
@ -84,23 +87,23 @@ c.step_type
from product as a, agreement as b, agreedetail as c
where a.agreeid = b.id
and ( a.prodtypeid = c.prodtypeid or c.prodtypeid is NULL)
and b.agreeid = a.id
and a.ownerid = b.providerid
and b.start_date <= ${biz_date}$
and b.end_date > ${biz_date}$
and a.ownerid = ${sellerid}$
and a.agreeid = b.id
and a.orgid = b.providerid
and b.enable_date <= ${biz_date}$
and b.expire_date > ${biz_date}$
and a.orgid = ${sellerid}$
and b.resellerid = ${buyerid}$
and a.id = ${productid}$
"""
recs = await sor.sqlExe(sql, {'sellerid':selllerid,
recs = await sor.sqlExe(sql, {'sellerid':sellerid,
'buyerid':buyerid,
'biz_date':biz_date,
'productid':productid
})
if len(recs) == 0:
e = Exception(f'there is no agreement for {sellerid=} and {buyerid=}, {productid=} at {biz_date=} ')
exception(f'{e=}')
raise e
e = f'there is no agreement for {sellerid=} and {buyerid=}, {productid=} at {biz_date=} '
debug(f'{e=}')
return None
rec = None
for r in recs:
if r.prodtypeid == r.agree_prodtypeid:
@ -174,14 +177,16 @@ async def get_sell_price(sor, sellerid, buyerid, productid, list_price):
"""
biz_date = await get_biz_date(sor)
rec = get_product_agreement(sor, sellerid, buyerid, productid, biz_date)
if rec.discount:
return list_price * rec.discount
# amount = await get_sale_amount(sor, rec.step_type, sellerid, buyerid)
discount = await get_step_discount(sor, rec.agreedetailid, rec.step_type, selllerid, buyerid)
agree = await get_product_agreement(sor, sellerid, buyerid, productid, biz_date)
if agree is None:
return list_price
if agree.discount:
return list_price * agree.discount
discount = await get_step_discount(sor, agree.agreedetailid, agree.step_type, selllerid, buyerid)
return discount * list_price
async def get_price(sor, sellerid, buyerid, productid, prod_config):
async def get_price_infos(sor, sellerid, buyerid, productid, prod_config):
"""
获得商品价格
resellerid:商户id
@ -194,12 +199,11 @@ async def get_price(sor, sellerid, buyerid, productid, prod_config):
"""
cost_pricing_infos = []
sql1 = """select a.*,
b.pricing_mode,
b.count_price,
b.pricingapiid
b.pricing_method,
b.apiid
from product a left join prodpricing b on a.id=b.prodid
where a.id = ${productid}$
and a.ownerid = ${sellerid}$"""
and a.orgid = ${sellerid}$"""
prods = await sor.sqlExe(sql1, {'productid':productid, 'sellerid':sellerid})
if len(prods) < 1:
e = Exception(f'{resellerid=} {productid=} product not found')
@ -207,20 +211,9 @@ where a.id = ${productid}$
raise e
prod = prods[0]
if prod.agreeid is not None:
cost_pricing_infos = get_price(sor, prod.providerid, sellerid, prod.providerpid, prod_config)
cost_pricing_infos = get_price_infos(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':
if prod.pricing_method == '0':
# 按资源因子计费
list_price = await calc_prod_price(sor, productid, prod_config)
sell_price = await get_sell_price(sor, sellerid, buyerid, productid, list_price)
@ -231,10 +224,10 @@ where a.id = ${productid}$
'list_price': list_price,
'sell_price': sell_price
}
elif prod_pricing_mode == '2':
elif prod_pricing_method == '1':
# 外部计费
f = get_serverenv('pricing_api')
list_price = await f(sor, prod.pricingapiid, providerpid, prod_config)
list_price = await f(sor, prod.apiid, providerpid, prod_config)
sell_price = await get_sell_price(sor, sellerid, buyerid, productid, list_price)
pricing_info = {
'sellerid': sellerid,
@ -258,5 +251,5 @@ where a.id = ${productid}$
'list_price': list_price,
'sell_price': sell_price
}
cost_pricing_info.append(pricing_info)
return cost_pricing_info
cost_pricing_infos.append(pricing_info)
return cost_pricing_infos

View File

@ -2,6 +2,6 @@ debug(f'{params_kw=}')
db = DBPools()
dbname = await get_module_dbname('platformbiz')
async with db.sqlorContext(dbname) as sor:
await agreedetail_products_clone(params_kw.agreedetailid)
await agreedetail_products_clone(sor, params_kw.agreedetailid)
return UiMessage(title='clone product', message='OK')
return UiError(title='Product clone', message='Product clone error')