From 2e2b1e5edc9a7109a5c78e28615c98e33cc8ec91 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 6 Jan 2025 18:28:27 +0800 Subject: [PATCH] bugfix --- platformbiz/biz_order.py | 59 ++++++++++++++++++++++++++++++++++++++++ platformbiz/recharge.py | 45 ++++++++++++++++++++++++++++++ platformbiz/version.py | 1 + setup.py | 52 +++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 platformbiz/biz_order.py create mode 100644 platformbiz/recharge.py create mode 100644 platformbiz/version.py create mode 100755 setup.py diff --git a/platformbiz/biz_order.py b/platformbiz/biz_order.py new file mode 100644 index 0000000..8ee00cf --- /dev/null +++ b/platformbiz/biz_order.py @@ -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] + diff --git a/platformbiz/recharge.py b/platformbiz/recharge.py new file mode 100644 index 0000000..d6e045b --- /dev/null +++ b/platformbiz/recharge.py @@ -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') + + diff --git a/platformbiz/version.py b/platformbiz/version.py new file mode 100644 index 0000000..b8023d8 --- /dev/null +++ b/platformbiz/version.py @@ -0,0 +1 @@ +__version__ = '0.0.1' diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..9a4d22c --- /dev/null +++ b/setup.py @@ -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', + ], +)