kboss/b/news/news_article_update.dspy
2026-07-29 16:42:48 +08:00

49 lines
1.6 KiB
Plaintext

async def news_article_update(ns={}):
if not ns.get('id'):
return {
'status': False,
'msg': '请传递id'
}
ns_dic = {
'id': ns.get('id')
}
for field in [
'title_zh', 'title_en', 'article_type_zh', 'article_type_en',
'summary_zh', 'summary_en', 'content_zh', 'content_en'
]:
if field in ns:
ns_dic[field] = ns.get(field)
if 'cover_img' in ns:
ns_dic['cover_img'] = ns.get('cover_img')
if 'status' in ns:
if ns.get('status') not in ['0', '1']:
return {
'status': False,
'msg': '状态错误'
}
ns_dic['status'] = ns.get('status')
if 'publish_time' in ns:
ns_dic['publish_time'] = ns.get('publish_time')
db = DBPools()
async with db.sqlorContext('kboss') as sor:
try:
await sor.U('enterprise_news_article', ns_dic)
if ns.get('status') == '1' and not ns.get('publish_time'):
publish_sql = """update enterprise_news_article set publish_time = ifnull(publish_time, current_timestamp()) where id = '%s';""" % ns.get('id')
await sor.sqlExe(publish_sql, {})
return {
'status': True,
'msg': 'update news article success'
}
except Exception as e:
await sor.rollback()
return {
'status': False,
'msg': 'update news article failed, %s' % str(e)
}
ret = await news_article_update(params_kw)
return ret