添加按companyid返回广告列表的方法

This commit is contained in:
pengtao 2019-07-11 10:59:57 +08:00
parent 71df5f75ee
commit 94b3ef043e

View File

@ -54,16 +54,16 @@ class Ad(Resource):
if not id: if not id:
if companyid: if companyid:
sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \ sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \
f"status,companyid from ad where companyid={companyid};" f"status,companyid,locationid,gameid from ad where companyid={companyid};"
elif status: elif status:
sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \ sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \
f"statuscompanyid from ad where status={status};" f"statuscompanyid,locationid,gameid from ad where status={status};"
else: else:
sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \ sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \
f"status,companyid from ad ;" f"status,companyid,locationid,gameid from ad ;"
else: else:
sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \ sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \
f"status,companyid from ad where id={id};" f"status,companyid,locationid,gameid from ad where id={id};"
data = mydb.query(sel_sql) data = mydb.query(sel_sql)
log.info(f"sql={sel_sql},data={data}") log.info(f"sql={sel_sql},data={data}")
if data: if data:
@ -72,15 +72,15 @@ class Ad(Resource):
try: try:
for line in data: for line in data:
ad_info['id'], ad_info['name'], ad_info['begin_time'], ad_info['end_time'], ad_info['ad_num'], \ ad_info['id'], ad_info['name'], ad_info['begin_time'], ad_info['end_time'], ad_info['ad_num'], \
ad_info['ad_title'], ad_info['ad_body'], ad_info['ad_image'], ad_info['ad_url'], ad_info[ ad_info['ad_title'], ad_info['ad_body'], ad_info['ad_image'], ad_info['ad_url'], ad_info['ad_sort'], \
'ad_sort'], ad_info['status'], ad_info['companyid'] = line ad_info['status'], ad_info['companyid'], ad_info['locationid'], ad_info['gameid'] = line
all.append(ad_info) all.append(ad_info)
return jsonify({'code': 200, 'message': all}) return jsonify({'code': 200, 'message': all})
except Exception: except Exception:
log.error("split data from mysql failed!", exc_info=True) log.error("split data from mysql failed!", exc_info=True)
else: else:
return jsonify({ return jsonify({
'code': 404, 'message': f'ad not found with id={id},status={status}!' 'code': 404, 'message': f'ad not found with id={id},status={status},companyid={companyid}!'
}) })