diff --git a/platformbiz/biz_order.py b/platformbiz/biz_order.py index 8ee00cf..8f18990 100644 --- a/platformbiz/biz_order.py +++ b/platformbiz/biz_order.py @@ -1,9 +1,11 @@ from time import time +from ahserver.serverenv import get_serverenv from sqlor.dbpools import DBPools -from platformbiz.businessdate import get_business_date from appPublic.dictObject import DictObject +from appPublic.log import debug from appPublic.uniqueID import getID from platformbiz.const import ORDER_INITIAL, RECHARGE_INITIAL + async def add_recharge_order(sor, customerid, userid, action, recharge_amt): """ arguments: @@ -18,6 +20,7 @@ async def add_recharge_order(sor, customerid, userid, action, recharge_amt): rec.id = getID() rec.customerid = customerid rec.userid = userid + get_business_date = get_serverenv('get_business_date') rec.order_date = await get_business_date() rec.business_op = action rec.amount = recharge_amt @@ -25,11 +28,12 @@ async def add_recharge_order(sor, customerid, userid, action, recharge_amt): await sor.C('biz_order', rec.copy()) return rec -async def get_paychanneli_by_name(sor, name): - sql = "select * from paychannel where name=${pcid}$" +async def get_paychannel_by_name(sor, name): + sql = "select * from paychannel where name=${name}$" recs = await sor.sqlExe(sql, {'name':name}) if len(recs) > 0: return recs[0] + debug(f'get paychannel error({name})') return None async def add_recharge_log(sor, customerid, userid, action, orderid, transdate, recharge_amt, name): @@ -39,13 +43,17 @@ async def add_recharge_log(sor, customerid, userid, action, orderid, transdate, rec.userid = userid rec.action = action rec.recharge_amt = recharge_amt - pc = await get_paychanneli_by_name(sor, name) - rec.fee_amt = recharge_amt * pc.feerate + pc = await get_paychannel_by_name(sor, name) + debug(f'{pc=}, {recharge_amt=}') + if pc is None: + raise Exception(f'paychannel({name}) pay channel not found') + rec.fee_amt = recharge_amt * pc.fee_rate + rec.fee_rate = pc.fee_rate rec.pcid = pc.id rec.biz_orderid = orderid rec.recharge_status = RECHARGE_INITIAL rec.transdate = transdate - await sor.C('recharge_log', rec.copy() + await sor.C('recharge_log', rec.copy()) return rec async def change_recharge_status(sor, rlid, status, tid): diff --git a/platformbiz/businessdate.py b/platformbiz/businessdate.py deleted file mode 100644 index 227d868..0000000 --- a/platformbiz/businessdate.py +++ /dev/null @@ -1,39 +0,0 @@ -from sqlor.dbpools import DBPools -from appPublic.timeUtils import strdate_add -from .excep import BusinessDateParamsError -from .const import * -async def get_business_date(sor=None): - async def _f(sor): - sql = "select * from params where params_name = 'business_date'" - recs = await sor.sqlExe(sql, {}) - if len(recs) > 0: - return recs[0]['params_value'] - raise BusinessDateParamsError - - if sor: - return await _f(sor) - db = DBPools() - async with db.sqlorContext(DBNAME()) as sor: - return await _f(sor) - -async def new_business_date(sor=None): - async def _f(sor): - dat = await get_business_date(sor) - new_dat = strdate_add(dat, days=1) - sql = "update params set params_value=${new_dat}$ where params_name='business_date'" - await sor.sqlExe(sql, {'new_dat':new_dat}) - - if sor: - return await _f(sor) - db = DBPools() - async with db.sqlorContext(DBNAME()) as sor: - return await _f(sor) - -async def previous_business_date(sor=None): - dat = await get_business_date(sor=sor) - return strdate_add(dat, days=-1) - -async def next_business_date(sor=None): - dat = await get_business_date(sor=sor) - return strdate_add(dat, days=1) - diff --git a/platformbiz/const.py b/platformbiz/const.py new file mode 100644 index 0000000..ad7bb01 --- /dev/null +++ b/platformbiz/const.py @@ -0,0 +1,2 @@ +ORDER_INITIAL = '0' +RECHARGE_INITIAL = '0' diff --git a/platformbiz/recharge.py b/platformbiz/recharge.py index d6e045b..989bc65 100644 --- a/platformbiz/recharge.py +++ b/platformbiz/recharge.py @@ -1,6 +1,9 @@ -from acccounting.accounting_config import Accounting -from platformbiz.biz_order import add_recharge_log, add_recharge_order +from accounting.accounting_config import Accounting +from appPublic.registerfunction import rfexe +from appPublic.log import exception, debug +from sqlor.dbpools import DBPools from pf_pay.ali_pay import Zhifubao_Pay +from platformbiz.biz_order import add_recharge_log, add_recharge_order class Recharge: def __init__(self, customerid, userid, recharge_amt, pc_name): @@ -20,15 +23,15 @@ class Recharge: async def start_recharge_action(self, action): db = DBPools() - dbname = rfexe('get_module_dbname', 'platformbiz') - async db.sqlorContext(dbname) as sor: + dbname = await rfexe('get_module_dbname', 'platformbiz') + async with db.sqlorContext(dbname) as sor: order = await add_recharge_order(sor, self.customerid, self.userid, action, self.recharge_amt) if order is None: return None - rl = await add_rechagre_log(sor, self.customerid, + rl = await add_recharge_log(sor, self.customerid, self.userid, action, order.id, @@ -40,6 +43,8 @@ class Recharge: url = await z.alipay_payment(rl.id, rl.recharge_amt, action) return url + exception(f'exception ...........{self.pc_name}') raise Exception(f'{self.pc_name} pay channel not implemented') - + exception('Exception happend ....') + diff --git a/requirements.txt b/requirements.txt index b709c05..a745bff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -git+https://git.kaiyuancloud.cn/yumoqing/rbac -git+https://git.kaiyuancloud.cn/yumoqing/accounting -git+https://git.kaiyuancloud.cn/yumoqing/pay +# git+https://git.kaiyuancloud.cn/yumoqing/rbac +# git+https://git.kaiyuancloud.cn/yumoqing/accounting +# git+https://git.kaiyuancloud.cn/yumoqing/pf_pay diff --git a/www/recharge.dspy b/www/recharge.dspy new file mode 100644 index 0000000..e50ad3f --- /dev/null +++ b/www/recharge.dspy @@ -0,0 +1,17 @@ +debug(f'{params_kw=}') +try: + userid = await get_user() + userorgid = await get_userorgid() + r = Recharge(userorgid, userid, float(params_kw.recharge_amt), params_kw.channel) + url = await r.start_recharge() + return { + "widgettype":"NewWindow", + "options":{ + "url":url + } + } +except Exception as e: + es = format_exc() + exception(f'{e=}, {es}') + return UiError(title='Error', message=f'Error:{e},trackback={es}') + diff --git a/www/recharge.ui b/www/recharge.ui new file mode 100644 index 0000000..0623ea3 --- /dev/null +++ b/www/recharge.ui @@ -0,0 +1,38 @@ +{ + "widgettype":"Form", + "options":{ + "fields":[ + { + "name":"recharge_amt", + "uitype":"float", + "required":true, + "label":"充值金额" + }, + { + "name":"channel", + "label":"选择充值方式", + "uitype":"checkbox", + "multicheck":false, + "required":true, + "value":"alipay", + "data":[ + { + "value":"alipay", + "text":"支付宝" + } + ] + } + ] + }, + "binds":[ + { + "wid":"self", + "event":"submit", + "actiontype":"urlwidget", + "target":"self", + "options":{ + "url":"{{entire_url('recharge.dspy')}}" + } + } + ] +}