This commit is contained in:
yumoqing 2025-01-06 18:28:27 +08:00
parent be64ca5941
commit 2e2b1e5edc
4 changed files with 157 additions and 0 deletions

59
platformbiz/biz_order.py Normal file
View File

@ -0,0 +1,59 @@
from time import time
from sqlor.dbpools import DBPools
from platformbiz.businessdate import get_business_date
from appPublic.dictObject import DictObject
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:
customerid: organization who recharge
userid: user who do the recharge action
recharge_amt: recharge amount
action: business action name
return:
order record
"""
rec = DictObject()
rec.id = getID()
rec.customerid = customerid
rec.userid = userid
rec.order_date = await get_business_date()
rec.business_op = action
rec.amount = recharge_amt
rec.order_status = ORDER_INITIAL
await sor.C('biz_order', rec.copy())
return rec
async def get_paychanneli_by_name(sor, name):
sql = "select * from paychannel where name=${pcid}$"
recs = await sor.sqlExe(sql, {'name':name})
if len(recs) > 0:
return recs[0]
return None
async def add_recharge_log(sor, customerid, userid, action, orderid, transdate, recharge_amt, name):
rec = DictObject()
rec.id = getID()
rec.customerid = customerid
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
rec.pcid = pc.id
rec.biz_orderid = orderid
rec.recharge_status = RECHARGE_INITIAL
rec.transdate = transdate
await sor.C('recharge_log', rec.copy()
return rec
async def change_recharge_status(sor, rlid, status, tid):
recs = await sor.R('recharge_log', {'id':rlid})
if len(recs) < 1:
return None
recs[0].recharge_status = status
recs[0].channel_tid = tid
await sor.U('recharge_log', recs[0].copy())
return recs[0]

45
platformbiz/recharge.py Normal file
View File

@ -0,0 +1,45 @@
from acccounting.accounting_config import Accounting
from platformbiz.biz_order import add_recharge_log, add_recharge_order
from pf_pay.ali_pay import Zhifubao_Pay
class Recharge:
def __init__(self, customerid, userid, recharge_amt, pc_name):
self.customerid = customerid
self.userid = userid
self.recharge_amt = recharge_amt
self.pc_name = pc_name
if pc_name not in ['alipay']:
raise Exception(f'{pc_name} pay channel not implemented')
async def start_recharge(self):
return await self.start_recharge_action('RECHARGE')
async def start_recharge_reverse(self):
return await self.start_recharge_action('RECHARGE_REVERSE')
async def start_recharge_action(self, action):
db = DBPools()
dbname = rfexe('get_module_dbname', 'platformbiz')
async 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,
self.userid,
action,
order.id,
order.order_date,
self.recharge_amt,
self.pc_name)
if self.pc_name == 'alipay':
z = Zhifubao_Pay()
url = await z.alipay_payment(rl.id, rl.recharge_amt, action)
return url
raise Exception(f'{self.pc_name} pay channel not implemented')

1
platformbiz/version.py Normal file
View File

@ -0,0 +1 @@
__version__ = '0.0.1'

52
setup.py Executable file
View File

@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
from platformbiz.version import __version__
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
required = []
with open('requirements.txt', 'r') as f:
ls = f.read()
required = ls.split('\n')
with open('platformbiz/version.py', 'r') as f:
x = f.read()
y = x[x.index("'")+1:]
z = y[:y.index("'")]
version = z
with open("README.md", "r") as fh:
long_description = fh.read()
name = "platformbiz"
description = "platformbiz"
author = "yumoqing"
email = "yumoqing@gmail.com"
package_data = {}
setup(
name="platformbiz",
version=version,
# uncomment the following lines if you fill them out in release.py
description=description,
author=author,
author_email=email,
platforms='any',
install_requires=required ,
packages=[
"platformbiz"
],
package_data=package_data,
keywords = [
],
url="https://github.com/yumoqing/platformbiz",
long_description=long_description,
long_description_content_type="text/markdown",
classifiers = [
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
],
)