1. 授信表单: accountid改为customer_name文本输入,后端先精确后模糊查找客户 2. 代客充值: load_path.py添加proxy_recharge.ui和proxy_recharge_submit.dspy路径
154 lines
4.3 KiB
Plaintext
154 lines
4.3 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
for k, v in ns.items():
|
|
if v == 'NaN' or v == 'null' or v == '':
|
|
ns[k] = None
|
|
|
|
customer_name = ns.get('customer_name', '').strip() if ns.get('customer_name') else ''
|
|
if not customer_name:
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "参数错误",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": "客户名称不能为空"
|
|
}
|
|
}
|
|
|
|
credit_limit_amount = float(ns.get('credit_limit', 0) or 0)
|
|
if credit_limit_amount <= 0:
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "参数错误",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": "授信额度必须大于0"
|
|
}
|
|
}
|
|
|
|
valid_from = ns.get('valid_from')
|
|
valid_to = ns.get('valid_to')
|
|
remark = ns.get('remark')
|
|
record_id = ns.get('id')
|
|
|
|
user_id = await get_user()
|
|
orgid = await get_userorgid()
|
|
|
|
db = DBPools()
|
|
dbname = get_module_dbname('accounting')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
# Look up customer by name
|
|
lookup_sql = """
|
|
select o.id as orgid, o.orgname, a.id as accountid
|
|
from organization o
|
|
left join account a on a.orgid = o.id COLLATE utf8mb4_unicode_ci
|
|
where o.orgname = ${customer_name}$
|
|
limit 1
|
|
"""
|
|
recs = await sor.sqlExe(lookup_sql, {'customer_name': customer_name})
|
|
if not recs or len(recs) == 0:
|
|
# Try fuzzy match
|
|
fuzzy_sql = """
|
|
select o.id as orgid, o.orgname, a.id as accountid
|
|
from organization o
|
|
left join account a on a.orgid = o.id COLLATE utf8mb4_unicode_ci
|
|
where o.orgname LIKE ${customer_name}$
|
|
limit 1
|
|
"""
|
|
recs = await sor.sqlExe(fuzzy_sql, {'customer_name': f'%{customer_name}%'})
|
|
|
|
if not recs or len(recs) == 0:
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "查找失败",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": f"未找到客户: {customer_name}"
|
|
}
|
|
}
|
|
|
|
customer = recs[0]
|
|
customer_orgid = customer.orgid
|
|
accountid = customer.accountid
|
|
|
|
if not accountid:
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "查找失败",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": f"客户 {customer.orgname} 尚未开设账户"
|
|
}
|
|
}
|
|
|
|
if record_id:
|
|
sql = """
|
|
UPDATE credit_limit
|
|
SET credit_limit = ${credit_limit}$,
|
|
available_credit = ${credit_limit}$ - used_credit,
|
|
valid_from = ${valid_from}$,
|
|
valid_to = ${valid_to}$,
|
|
remark = ${remark}$,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ${id}$ AND orgid = ${orgid}$
|
|
"""
|
|
await sor.sqlExe(sql, {
|
|
'credit_limit': credit_limit_amount,
|
|
'valid_from': valid_from,
|
|
'valid_to': valid_to,
|
|
'remark': remark,
|
|
'id': record_id,
|
|
'orgid': orgid
|
|
})
|
|
debug(f'Updated credit limit {record_id} to {credit_limit_amount}')
|
|
else:
|
|
new_id = uuid()
|
|
now = datetime.now()
|
|
data = {
|
|
'id': new_id,
|
|
'accountid': accountid,
|
|
'orgid': customer_orgid,
|
|
'credit_limit': credit_limit_amount,
|
|
'used_credit': 0,
|
|
'available_credit': credit_limit_amount,
|
|
'valid_from': valid_from,
|
|
'valid_to': valid_to,
|
|
'status': 'active',
|
|
'created_at': now,
|
|
'updated_at': now,
|
|
'created_by': user_id,
|
|
'remark': remark
|
|
}
|
|
await sor.C('credit_limit', data)
|
|
debug(f'Created credit limit for {customer.orgname}(orgid={customer_orgid}, accountid={accountid}): {credit_limit_amount}')
|
|
|
|
return {
|
|
"widgettype": "Message",
|
|
"options": {
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"title": "授信额度设置成功",
|
|
"timeout": 3,
|
|
"message": "ok"
|
|
}
|
|
}
|
|
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "设置失败",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": "failed"
|
|
}
|
|
}
|