Merge branch 'main' of git.kaiyuancloud.cn:yumoqing/platformbiz

This commit is contained in:
yumoqing 2025-03-18 13:27:29 +08:00
commit 3bad604fcc
3 changed files with 105 additions and 0 deletions

View File

@ -5,6 +5,7 @@ from appPublic.dictObject import DictObject
from appPublic.log import debug
from appPublic.uniqueID import getID
from platformbiz.const import ORDER_INITIAL, RECHARGE_INITIAL
from platformbiz.pricing import get_biz_date
async def add_recharge_order(sor, customerid, userid, action, recharge_amt):
"""
@ -65,3 +66,50 @@ async def change_recharge_status(sor, rlid, status, tid):
await sor.U('recharge_log', recs[0].copy())
return recs[0]
async def add_pay_order(sor, sellerid,
customerid,
userid,
action,
order_details,
origin_orderid=None):
env = globals()
customerid1 = await env.get_userorgid()
userid1 = await env.get_user()
if customerid != customerid1:
e = Exception(f'{custmerid} is not logined orgid')
exception(f'{e}')
raise e
if userid != userid1:
e = Exception(f'{userid} is not logined userid')
exception(f'{e}')
raise e
id = getID()
amount = 0.0
for order_detail in order_details:
ns1 = {
"id": id,
"orderid":ns['id'],
"productid":order_detail.productid,
"product_cnt":order_detail.product_cnt,
"prod_config":order_detail.prod_config,
"list_amount":order_detail.list_amount,
"trans_amount":order_detail.trans_amount
}
await sor.C('biz_orderdetail', ns1)
amount += order_detail.trans_amount
ns = {
"id": id,
"customerid":customerid,
"userid":suerid,
"resellerid":sellerid,
"order_date":await get_biz_date(sor),
"order_status":"0",
"business_op":action,
"amount":pay_amount,
"ordertype":None,
"pay_date":None,
"origin_orderid":origin_orderid
}
await sor.C('biz_order', ns)

View File

@ -1,4 +1,5 @@
import time
import json
from appPublic.timeUtils import timestampstr
from appPublic.registerfunction import rfexe
from sqlor.dbpools import DBPools
@ -20,6 +21,45 @@ async def get_balance(orgid):
return None
class PlatformBizAcc:
"""
"""
async def accounting(self, sor, biz_orderid):
biz_order = await sor.R('biz_order', {'id':biz_orderid})
details = await sor.R('biz_orderdetail',{'orderid':biz_orderid})
self.customerid = biz_order.customerid
self.resellerid = biz_order.resellerid
self.orderid = biz_order.id
self.userid = biz_order.userid
self.business_op = biz_order.business_op
get_business_date = get_serverenv('get_business_date')
self.curdate = await get_business_date(sor)
transfee = await get_transfee(sor, self.resellerid, biz_order.amount, self.curdate)
self.variable = {
"交易金额":biz_order.amount,
"交易费用":transfee
}
bill = await write_bill(sor, self.customerid, self.userid,
self.orderid,
self.business_op,
biz_order.amount)
self.billid = bill.id
self.bill = bill
self.providerid = None
self.resellerid = None
self.action = self.recharge.action
self.productid = None
self.timestamp = timestampstr()
a = Accounting(self)
r = await a.do_accounting(sor)
for detail in details:
detail.prod_config = json.loads(detail.prod_config)
price_infos = await get_price_infos(sor, self.resellerid,
self.customerid,
detail.productid,
detail.prod_config)
async def get_orgid_by_trans_role(self, sor, orgtype):
if orgtype== 'customer':
return self.customerid
@ -68,3 +108,5 @@ class PlatformBizAccRecharge(PlatformBizAcc):
a = Accounting(self)
r = await a.do_accounting(sor)
async def PayAccounting(sor, *):
pass

View File

@ -256,3 +256,18 @@ where a.id = ${productid}$
pricing_info['cost_price'] = cost_pricing_infos[-1]['sell_price']
cost_pricing_infos.append(pricing_info)
return cost_pricing_infos
async def get_transfee(sor, resellerid, transamt, biz_date):
sql = """select * from reseller
where orgid=${resellerid}$
and enable_date<=${biz_date}$
and expire_date>${biz_date}$
"""
recs = sor.sqlExe(sql, {'resellerid':resellerid, 'biz_date':biz_date})
if len(recs) < 1:
e = Exception(f'reseller(id={resellerid}) not available at {biz_date=}')
exception(f'{e=}')
raise e
rate = recs[0].transrate
return transamt * rate