29 lines
1.1 KiB
Plaintext
29 lines
1.1 KiB
Plaintext
# 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)}
|