68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
from time import time
|
|
from ahserver.serverenv import get_serverenv
|
|
from sqlor.dbpools import DBPools
|
|
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:
|
|
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
|
|
get_business_date = get_serverenv('get_business_date')
|
|
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_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):
|
|
rec = DictObject()
|
|
rec.id = getID()
|
|
rec.customerid = customerid
|
|
rec.userid = userid
|
|
rec.action = action
|
|
rec.recharge_amt = recharge_amt
|
|
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())
|
|
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]
|
|
|