voucher/wwwroot/api/v1/available.dspy

29 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# v1/available.dspy — 客户自助查询可用券HTTP API登录态按机构隔离
customer_id = await get_userorgid()
if not customer_id:
return {'status': 'error', 'message': 'not logged in', 'data': [], 'total': 0}
context = {}
if params_kw.get('product_type'):
context['product_type'] = params_kw.get('product_type')
if params_kw.get('product_name'):
context['product_name'] = params_kw.get('product_name')
if params_kw.get('request_amount'):
try:
context['request_amount'] = float(params_kw.get('request_amount'))
except (ValueError, TypeError):
pass
result = await get_available_vouchers_api(customer_id, context if context else None)
vouchers = []
for v in (result.get('data') or []):
vouchers.append({
'id': v.get('id'),
'code': v.get('code'),
'face_value': float(v.get('face_value') or 0),
'valid_from': str(v.get('valid_from') or ''),
'valid_to': str(v.get('valid_to') or ''),
'template_name': v.get('template_name') or '',
})
return {'status': 'success', 'data': vouchers, 'total': len(vouchers)}