53 lines
1.7 KiB
Plaintext
53 lines
1.7 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',
|
|
'cover_img_zh', 'cover_img_en', 'publish_time_zh', 'publish_time_en'
|
|
]:
|
|
if field in ns:
|
|
if field in ['publish_time_zh', 'publish_time_en']:
|
|
ns_dic[field] = ns.get(field) or None
|
|
else:
|
|
ns_dic[field] = ns.get(field)
|
|
if 'status' in ns:
|
|
if ns.get('status') not in ['0', '1']:
|
|
return {
|
|
'status': False,
|
|
'msg': '状态错误'
|
|
}
|
|
ns_dic['status'] = ns.get('status')
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
try:
|
|
await sor.U('enterprise_news_article', ns_dic)
|
|
if ns.get('status') == '1':
|
|
publish_sql = """
|
|
update enterprise_news_article
|
|
set publish_time_zh = ifnull(publish_time_zh, current_date()),
|
|
publish_time_en = ifnull(publish_time_en, current_date())
|
|
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
|