- 5个CRUD JSON从自定义格式重写为规范格式(tblname/alias/params) - 13个新CRUD dspy文件(create/update/delete + noop) - product_resource_delete含级联删除product_resource_supplier - product_subscription CRUD含完整校验 - product_usage_log只读(noop dspy) - load_path.py注册所有新增API和CRUD路径
45 lines
1.7 KiB
Plaintext
45 lines
1.7 KiB
Plaintext
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid', 'type': 'error'}}
|
|
|
|
try:
|
|
dbname = get_module_dbname('product_management')
|
|
data = dict(params_kw)
|
|
data['id'] = getID()
|
|
data['created_at'] = timestampstr()
|
|
data['updated_at'] = timestampstr()
|
|
if 'status' not in data:
|
|
data['status'] = '1'
|
|
if 'quota_total' not in data:
|
|
data['quota_total'] = '0'
|
|
if 'quota_used' not in data:
|
|
data['quota_used'] = '0'
|
|
if 'overflow_rate' not in data:
|
|
data['overflow_rate'] = '0'
|
|
if 'purchase_price' not in data:
|
|
data['purchase_price'] = '0'
|
|
if 'purchase_currency' not in data:
|
|
data['purchase_currency'] = 'CNY'
|
|
if 'overflow_mode' not in data:
|
|
data['overflow_mode'] = '1'
|
|
|
|
if not data.get('product_id'):
|
|
raise ValueError('产品ID不能为空')
|
|
if not data.get('user_id'):
|
|
raise ValueError('用户ID不能为空')
|
|
if not data.get('user_org_id'):
|
|
raise ValueError('用户机构ID不能为空')
|
|
if not data.get('subscription_type'):
|
|
raise ValueError('订购类型不能为空')
|
|
if not data.get('start_date'):
|
|
raise ValueError('生效日期不能为空')
|
|
if not data.get('end_date'):
|
|
raise ValueError('到期日期不能为空')
|
|
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
await sor.C('product_subscription', data)
|
|
|
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': '订购创建成功', 'type': 'success'}}
|
|
except Exception as e:
|
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
|
|
|
return json.dumps(result, ensure_ascii=False)
|