refactor(transfer): transfer_check scans ALL mails for all pending transfers
This commit is contained in:
parent
ba1e649814
commit
455d873167
@ -1,7 +1,6 @@
|
|||||||
"""手动检查转账邮件并完成入账"""
|
"""扫描所有转账邮件,完成全部待入账转账"""
|
||||||
tcode = str(params_kw.tcode)
|
|
||||||
env = request._run_ns
|
env = request._run_ns
|
||||||
debug(f'transfer_check.dspy: tcode={tcode}')
|
debug(f'transfer_check.dspy: checking all mails')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
provider = env.PROVIDERS.get('transfer')
|
provider = env.PROVIDERS.get('transfer')
|
||||||
@ -12,7 +11,11 @@ try:
|
|||||||
count, _ = ec.stat()
|
count, _ = ec.stat()
|
||||||
debug(f'transfer_check: got {count} mails')
|
debug(f'transfer_check: got {count} mails')
|
||||||
|
|
||||||
matched = None
|
db = DBPools()
|
||||||
|
dbname = get_module_dbname('unipay')
|
||||||
|
processed = []
|
||||||
|
skipped = []
|
||||||
|
|
||||||
for i in range(count, 0, -1):
|
for i in range(count, 0, -1):
|
||||||
try:
|
try:
|
||||||
mail = ec.get_mail(i)
|
mail = ec.get_mail(i)
|
||||||
@ -23,27 +26,24 @@ try:
|
|||||||
data = provider.get_transfer_data(mail)
|
data = provider.get_transfer_data(mail)
|
||||||
if data is None:
|
if data is None:
|
||||||
continue
|
continue
|
||||||
if str(data.code) == tcode:
|
|
||||||
matched = data
|
|
||||||
break
|
|
||||||
except Exception as e:
|
|
||||||
debug(f'transfer_check: skip mail {i}: {e}')
|
|
||||||
|
|
||||||
if matched is None:
|
code = str(data.code)
|
||||||
return {"widgettype": "Message", "options": {"timeout": 3, "title": "未匹配", "message": f"暂未找到转账码 {tcode} 的到账邮件,请确认已转账并稍后重试"}}
|
amount = data.amount
|
||||||
|
debug(f'transfer_check: mail[{i}] code={code} amount={amount}')
|
||||||
|
|
||||||
db = DBPools()
|
|
||||||
dbname = get_module_dbname('unipay')
|
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
recs = await sor.R('transfercode', {'tcode': tcode, 'status': '0'})
|
recs = await sor.R('transfercode', {'tcode': code, 'status': '0'})
|
||||||
if len(recs) < 1:
|
if len(recs) < 1:
|
||||||
return {"widgettype": "Message", "options": {"timeout": 3, "title": "已处理", "message": f"转账码 {tcode} 已处理或不存在"}}
|
skipped.append(f'转账码{code} (已处理/不存在)')
|
||||||
|
continue
|
||||||
|
|
||||||
tc = recs[0]
|
tc = recs[0]
|
||||||
diff = abs(float(matched.amount) - float(tc.amount))
|
diff = abs(float(amount) - float(tc.amount))
|
||||||
if diff > 0.01:
|
if diff > 0.01:
|
||||||
await sor.U('transfercode', {'id': tc.id, 'status': '9', 'remark': f'金额不匹配: 到账{matched.amount} 期望{tc.amount}'})
|
await sor.U('transfercode', {'id': tc.id, 'status': '9',
|
||||||
return {"widgettype": "Message", "options": {"timeout": 5, "title": "金额不匹配", "message": f"到账金额 {matched.amount} 与充值金额 {tc.amount} 不一致"}}
|
'remark': f'金额不匹配: 到账{amount} 期望{tc.amount}'})
|
||||||
|
skipped.append(f'转账码{code} (金额不匹配: {amount}≠{tc.amount})')
|
||||||
|
continue
|
||||||
|
|
||||||
biz_date = await env.get_business_date(sor)
|
biz_date = await env.get_business_date(sor)
|
||||||
await sor.U('transfercode', {'id': tc.id, 'status': '1'})
|
await sor.U('transfercode', {'id': tc.id, 'status': '1'})
|
||||||
@ -60,7 +60,18 @@ try:
|
|||||||
'payed_timestamp': timestampstr()
|
'payed_timestamp': timestampstr()
|
||||||
})
|
})
|
||||||
|
|
||||||
return {"widgettype": "Message", "options": {"timeout": 3, "title": "充值成功", "message": f"转账码 {tcode} 已确认到账 {matched.amount} 元"}}
|
processed.append(f'转账码{code} 到账{amount}元')
|
||||||
|
|
||||||
|
except Exception as e2:
|
||||||
|
debug(f'transfer_check: mail[{i}] error: {e2}')
|
||||||
|
|
||||||
|
msg = f'处理完成: {len(processed)} 笔入账'
|
||||||
|
if processed:
|
||||||
|
msg += '\n' + '\n'.join(processed)
|
||||||
|
if skipped:
|
||||||
|
msg += '\n跳过: ' + ', '.join(skipped)
|
||||||
|
|
||||||
|
return {"widgettype": "Message", "options": {"timeout": 5, "title": "转账检查结果", "message": msg}}
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exception(f'transfer_check.dspy error: {e}')
|
exception(f'transfer_check.dspy error: {e}')
|
||||||
|
|||||||
@ -43,17 +43,14 @@
|
|||||||
"event": "click",
|
"event": "click",
|
||||||
"actiontype": "urlwidget",
|
"actiontype": "urlwidget",
|
||||||
"options": {
|
"options": {
|
||||||
"url": "{{entire_url('transfer_check.dspy')}}",
|
"url": "{{entire_url('transfer_check.dspy')}}"
|
||||||
"params": {
|
|
||||||
"tcode": "{{params_kw.tcode}}"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"widgettype": "Text",
|
"widgettype": "Text",
|
||||||
"options": {
|
"options": {
|
||||||
"text": "转账完成后,系统将自动匹配转账码并完成充值。如有疑问请联系客服。"
|
"text": "点击上方按钮检查转账到账状态,系统将自动匹配转账码并完成充值。如有疑问请联系客服。"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user