discount/wwwroot/generate_qr.dspy
2026-02-24 17:32:46 +08:00

59 lines
1.2 KiB
Plaintext

params_kw.discount = float(params_kw.discount)
if params_kw.discount <= 0 or params_kw.discount >= 1:
e = Exception(f'discount({params_kw.discount}) invalid')
exception(f'{e}')
raise e
if params_kw.valid_term[-1] not in ['D', 'M', 'Y']:
e = Exception(f'valid_term must ends with "D", "M" or "Y"')
exception(f'{e}')
raise e
cnt = int(params_kw.valid_term[:-1])
if cnt < 0:
e = Exception(f'valid_term({params_kw.valid_term}) invalid')
exception(f'{e}')
raise e
if not params_kw.expired_date:
params_kw.expired_date = '9999-12-31'
x = await discount_qrcode(request, params_kw)
return {
"widgettype": "VBox",
"options": {
"width": "100%",
"height": "100%"
},
"subwidgets": [
{
"widgettype": "Image",
"options": {
"width": "auto",
"height": "auto",
"url": entire_url('/idfile') + f'?path={x.qr_webpath}'
}
}, {
"widgettype": "HBox",
"options": {
"width": "100%",
"cheight": 2
},
"subwidgets": [
{
"widgettype": "Text",
"options": {
"otext": "折扣:",
"i18n": True,
"cwidth": 3
}
},{
"widgettype": "Text",
"options":{
"text": x.discount
}
}
]
}
]
}