- 新增 credit_limit 表定义和DDL - 修改 accounting_config.py 支持信用额度透支检查 - 新增 creditlimit.py 信用额度管理模块 - 新增信用额度管理界面和CRUD API - 支持设置/查询/更新客户信用额度
129 lines
2.9 KiB
Plaintext
129 lines
2.9 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
debug(f'get_credit_limit.dspy:{ns=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
ns['sort'] = 'created_at desc'
|
|
|
|
|
|
sql = '''select a.*, b.accountid_text, c.orgid_text, d.status_text
|
|
from (select * from credit_limit where 1=1 [[filterstr]]) a
|
|
left join (select id as accountid, id as accountid_text from account where 1 = 1) b on a.accountid = b.accountid
|
|
left join (select id as orgid, orgname as orgid_text from organization where 1 = 1) c on a.orgid = c.orgid
|
|
left join (select k as status, v as status_text from appcodes_kv where parentid='credit_status') d on a.status = d.status'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
fields_str=r'''[
|
|
{
|
|
"name": "id",
|
|
"title": "id",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "accountid",
|
|
"title": "账户ID",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "orgid",
|
|
"title": "机构ID",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "credit_limit",
|
|
"title": "信用额度",
|
|
"type": "float",
|
|
"length": 18,
|
|
"dec": 2
|
|
},
|
|
{
|
|
"name": "used_credit",
|
|
"title": "已用额度",
|
|
"type": "float",
|
|
"length": 18,
|
|
"dec": 2
|
|
},
|
|
{
|
|
"name": "available_credit",
|
|
"title": "可用额度",
|
|
"type": "float",
|
|
"length": 18,
|
|
"dec": 2
|
|
},
|
|
{
|
|
"name": "valid_from",
|
|
"title": "生效日期",
|
|
"type": "date"
|
|
},
|
|
{
|
|
"name": "valid_to",
|
|
"title": "失效日期",
|
|
"type": "date"
|
|
},
|
|
{
|
|
"name": "status",
|
|
"title": "状态",
|
|
"type": "str",
|
|
"length": 10
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"title": "创建时间",
|
|
"type": "timestamp"
|
|
},
|
|
{
|
|
"name": "updated_at",
|
|
"title": "更新时间",
|
|
"type": "timestamp"
|
|
},
|
|
{
|
|
"name": "created_by",
|
|
"title": "创建人",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "remark",
|
|
"title": "备注",
|
|
"type": "str",
|
|
"length": 500
|
|
}
|
|
]'''
|
|
ori_fields = json.loads(fields_str)
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in ori_fields ]
|
|
filterjson = default_filterjson(fields, ns)
|
|
filterdic = ns.copy()
|
|
filterdic['filterstr'] = ''
|
|
filterdic['userorgid'] = '${userorgid}$'
|
|
filterdic['userid'] = '${userid}$'
|
|
if filterjson:
|
|
dbf = DBFilter(filterjson)
|
|
conds = dbf.gen(ns)
|
|
if conds:
|
|
ns.update(dbf.consts)
|
|
conds = f' and {conds}'
|
|
filterdic['filterstr'] = conds
|
|
ac = ArgsConvert('[[', ']]')
|
|
vars = ac.findAllVariables(sql)
|
|
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
|
|
filterdic.update(NameSpace)
|
|
sql = ac.convert(sql, filterdic)
|
|
|
|
debug(f'{sql=}')
|
|
db = DBPools()
|
|
dbname = get_module_dbname('accounting')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
}
|