56 lines
1.8 KiB
Plaintext
56 lines
1.8 KiB
Plaintext
async def news_article_update(ns={}):
|
|
if not ns.get('id'):
|
|
return {
|
|
'status': False,
|
|
'msg': '请传递id'
|
|
}
|
|
|
|
ns_dic = {
|
|
'id': ns.get('id')
|
|
}
|
|
if 'title' in ns:
|
|
ns_dic['title'] = ns.get('title')
|
|
if 'article_type' in ns:
|
|
# if ns.get('article_type') not in ['企业动态', '产品动态', '行业洞察', '活动资讯']:
|
|
# return {
|
|
# 'status': False,
|
|
# 'msg': '文章类型错误'
|
|
# }
|
|
ns_dic['article_type'] = ns.get('article_type')
|
|
if 'summary' in ns:
|
|
ns_dic['summary'] = ns.get('summary')
|
|
if 'cover_img' in ns:
|
|
ns_dic['cover_img'] = ns.get('cover_img')
|
|
if 'content' in ns:
|
|
ns_dic['content'] = ns.get('content')
|
|
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
|