voucher/wwwroot/api/apply_voucher.dspy

22 lines
912 B
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.

# apply_voucher.dspy — 核销代金券(一次性,不找零;并发安全条件 UPDATE
customer_id = (params_kw.get('customer_id') or '').strip()
if not customer_id:
customer_id = await get_userorgid() or ''
order_id = (params_kw.get('order_id') or '').strip()
voucher_ids = params_kw.get('voucher_ids') or []
if isinstance(voucher_ids, str):
try:
voucher_ids = json.loads(voucher_ids)
except (ValueError, TypeError):
voucher_ids = [s.strip() for s in voucher_ids.split(',') if s.strip()]
context = {}
for k in ('product_type', 'product_name'):
if params_kw.get(k):
context[k] = params_kw.get(k)
try:
context['request_amount'] = float(params_kw.get('request_amount') or 0)
except (ValueError, TypeError):
context['request_amount'] = 0
context['used_by'] = await get_user() or ''
return await apply_voucher_api(customer_id, order_id, voucher_ids, context)