This commit is contained in:
yumoqing 2025-01-10 18:37:11 +08:00
parent a27ad55227
commit 950faaab03
7 changed files with 85 additions and 54 deletions

View File

@ -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):

View File

@ -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)

2
platformbiz/const.py Normal file
View File

@ -0,0 +1,2 @@
ORDER_INITIAL = '0'
RECHARGE_INITIAL = '0'

View File

@ -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 ....')

View File

@ -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

17
www/recharge.dspy Normal file
View File

@ -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}')

38
www/recharge.ui Normal file
View File

@ -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')}}"
}
}
]
}