This commit is contained in:
yumoqing 2025-12-15 14:09:12 +08:00
parent 856a8d89dc
commit f1e00e02c3
3 changed files with 21 additions and 14 deletions

View File

@ -56,9 +56,9 @@ async def create_payment(request, params_kw=None):
payment_name = data.payment_name or "充值", payment_name = data.payment_name or "充值",
amount = data.amount amount = data.amount
currency = data.currency currency = data.currency
id = await pl.new_log(userid, orgid, payment_name, amount, fee, client_ip, currency=currency) plog = await pl.new_log(userid, orgid, payment_name, amount, fee, client_ip, currency=currency)
if id: if plog:
data.out_trade_no = id data.out_trade_no = plog.id
res = await PROVIDERS[provider].create_payment(data) res = await PROVIDERS[provider].create_payment(data)
return res return res
raise Exception('write payment_log error') raise Exception('write payment_log error')
@ -120,7 +120,7 @@ async def payment_notify(request, callback, params_kw=None):
# 返回厂商要求的固定成功响应 # 返回厂商要求的固定成功响应
logid = data['out_trade_no'] logid = data['out_trade_no']
pl = PaymentLog(request._run_ns) pl = PaymentLog(request._run_ns)
await pl.payed_log(logid) plog = await pl.payed_log(logid)
await callback(request, data) await callback(request, data)
if provider == "wechat": if provider == "wechat":
return {"code":"SUCCESS", "message":"OK"} return {"code":"SUCCESS", "message":"OK"}
@ -143,5 +143,6 @@ def load_unipay():
env.refund_payment = refund_payment env.refund_payment = refund_payment
env.get_pay_fee = get_pay_fee env.get_pay_fee = get_pay_fee
env.sor_get_pay_fee = sor_get_pay_fee env.sor_get_pay_fee = sor_get_pay_fee
env.PaymentLog = PaymentLog

View File

@ -24,9 +24,9 @@ class PaymentLog:
"init_timestamp": timestampstr(), "init_timestamp": timestampstr(),
"userid": userid "userid": userid
} }
await sor.C('payment_log', ns) await sor.C('payment_log', ns.copy())
return True return ns
return False return None
async def cancel_log(self, logid): async def cancel_log(self, logid):
dbname = await self.env.get_module_dbname('unipay') dbname = await self.env.get_module_dbname('unipay')
@ -36,8 +36,11 @@ class PaymentLog:
"cancel_timestamp": timestampstr() "cancel_timestamp": timestampstr()
} }
await sor.U('payment_log', ns) await sor.U('payment_log', ns)
return True recs = await sor.R('payment_log', {"id": logid})
return False if len(recs) > 0:
return recs[0]
return None
return None
async def payed_log(self, logid): async def payed_log(self, logid):
dbname = await self.env.get_module_dbname('unipay') dbname = await self.env.get_module_dbname('unipay')
@ -47,7 +50,10 @@ class PaymentLog:
"payed_timestamp": timestampstr() "payed_timestamp": timestampstr()
} }
await sor.U('payment_log', ns) await sor.U('payment_log', ns)
return True recs = await sor.R('payment_log', {"id": logid})
return False if len(recs) > 0:
return recs[0]
return None
return None

View File

@ -18,18 +18,18 @@ async with db.sqlorContext(dbname) as sor:
message=f"客户机构不存在{params_kw.customerid}") message=f"客户机构不存在{params_kw.customerid}")
pl = PaymentLog(request._run_ns) pl = PaymentLog(request._run_ns)
plid = await pl.new_log(serid, params_kw.customerid, 'manual', plog = await pl.new_log(serid, params_kw.customerid, 'manual',
'手工充值', params_kw.amount, 0.0, '手工充值', params_kw.amount, 0.0,
request['client_ip'], currency='CNY') request['client_ip'], currency='CNY')
async with db.sqlorContext(dbname) as sor: async with db.sqlorContext(dbname) as sor:
biz_date = await get_business_date(sor) biz_date = await get_business_date(sor)
await recharge_accounting(sor, params_kw.customerid, 'RECHARGE', await recharge_accounting(sor, params_kw.customerid, 'RECHARGE',
plid, plog.id,
biz_date, biz_date,
params_kw.amount, params_kw.amount,
0.00) 0.00)
pl.payed_log(plid) pl.payed_log(plog.id)
return UiMessage(title="手工充值",message=f"充值{params_kw.amount} 成功") return UiMessage(title="手工充值",message=f"充值{params_kw.amount} 成功")
exception(f'Exception:{db.e_except}') exception(f'Exception:{db.e_except}')
return UiError(title="手工充值", return UiError(title="手工充值",