修复生成卡密错误

This commit is contained in:
taiyi 2025-11-12 09:19:32 +08:00
parent f14b36e9b3
commit ecca300271
3 changed files with 18 additions and 2 deletions

View File

@ -151,7 +151,7 @@ def generate_licenses():
product_id = data.get('product_id')
count = data.get('count', 1)
license_type = data.get('type', 1) # 0=试用, 1=正式
valid_days = data.get('valid_days', 365)
valid_days = data.get('valid_days') # 不设置默认值保持None
prefix = data.get('prefix', '')
length = data.get('length', 32)
@ -182,6 +182,10 @@ def generate_licenses():
'message': '产品不存在'
}), 404
# 设置默认有效期
if valid_days is None:
valid_days = 365
# 试用卡密最大有效期限制
if license_type == 0 and valid_days > 90:
return jsonify({

View File

@ -124,11 +124,16 @@ function generateLicenses() {
product_id: document.getElementById('product_id').value,
type: parseInt(document.getElementById('license_type').value),
count: parseInt(document.getElementById('quantity').value),
valid_days: document.getElementById('expire_days').value ? parseInt(document.getElementById('expire_days').value) : 365,
valid_days: document.getElementById('expire_days').value ? parseInt(document.getElementById('expire_days').value) : null,
prefix: '',
length: 32
};
// 如果valid_days为null删除该属性
if (formData.valid_days === null) {
delete formData.valid_days;
}
// 基础验证
if (!formData.product_id) {
showNotification('请选择产品', 'warning');

View File

@ -41,6 +41,13 @@ def product_detail(product_id):
if not product:
flash('产品不存在', 'error')
return redirect(url_for('web.products'))
# 获取产品统计信息
stats = product.get_stats()
# 将统计信息添加到产品对象中
for key, value in stats.items():
setattr(product, key, value)
return render_template('product/detail.html', product=product)
@web_bp.route('/products/<product_id>/edit')