调整ad数据库的字段

This commit is contained in:
pengtao 2019-07-19 15:32:24 +08:00
parent 5923e503dc
commit cb5f8adab2

View File

@ -3,9 +3,9 @@ from __future__ import absolute_import
""" """
广告接口 广告接口
get 返回广告明细 paramsgameidlocalidoutputad_title,ad_body,ad_image,ad_url get 返回广告明细 paramsgameidlocalidoutputad_title,ad_body,ad_image,jump_param
post新增广告定义 paramsname,gameid,localid,start_time,end_time,ad_nums,ad_title,ad_body,ad_image,ad_url,ad_sort,status=unapproved, output1,0 post新增广告定义 paramsname,gameid,localid,start_time,end_time,ad_nums,ad_title,ad_body,ad_image,jump_param,ad_sort,status=unapproved, output1,0
put更新广告配置paramsname,gameid,localid,start_time,end_time,ad_nums,ad_title,ad_body,ad_image,ad_url,ad_sortoutput1,0 put更新广告配置paramsname,gameid,localid,start_time,end_time,ad_nums,ad_title,ad_body,ad_image,jump_param,ad_sortoutput1,0
delete删除定义的广告paramsoutput1,0 delete删除定义的广告paramsoutput1,0
""" """
@ -32,11 +32,11 @@ parser.add_argument('ad_num')
parser.add_argument('ad_title') parser.add_argument('ad_title')
parser.add_argument('ad_body') parser.add_argument('ad_body')
parser.add_argument('ad_image') parser.add_argument('ad_image')
parser.add_argument('ad_url') parser.add_argument('jump_status')
parser.add_argument('ad_sort') parser.add_argument('ad_sort')
parser.add_argument('status') parser.add_argument('status')
parser.add_argument('companyid') parser.add_argument('companyid')
parser.add_argument('jump_param')
class Ad(Resource): class Ad(Resource):
def __init__(self): def __init__(self):
@ -54,16 +54,16 @@ class Ad(Resource):
# now = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S") # now = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")
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,jump_param,ad_sort," \
f"status,companyid,locationid,gameid from ad where companyid={companyid};" f"status,companyid,locationid,gameid from ad where companyid={companyid};"
elif status or status == 0: elif status or status == 0:
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,jump_param,ad_sort," \
f"status,companyid,locationid,gameid from ad where status={status};" f"status,companyid,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,jump_param,ad_sort," \
f"status,companyid,locationid,gameid 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,jump_param,ad_sort," \
f"status,companyid,locationid,gameid from ad where id={id};" f"status,companyid,locationid,gameid from ad where id={id};"
data = self.mydb.query(sel_sql) data = self.mydb.query(sel_sql)
log.info(f"sql={sel_sql},data={data}") log.info(f"sql={sel_sql},data={data}")
@ -73,7 +73,7 @@ class Ad(Resource):
for line in data: for line in data:
ad_info = {} ad_info = {}
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['jump_param'], ad_info[
'ad_sort'], ad_info['status'], ad_info['companyid'], ad_info['locationid'], ad_info[ 'ad_sort'], ad_info['status'], ad_info['companyid'], ad_info['locationid'], ad_info[
'gameid'] = line 'gameid'] = line
all.append(ad_info) all.append(ad_info)
@ -97,13 +97,14 @@ class Ad(Resource):
ad['ad_title'] = self.args['ad_title'] ad['ad_title'] = self.args['ad_title']
ad['ad_body'] = self.args['ad_body'] ad['ad_body'] = self.args['ad_body']
ad['ad_image'] = self.args['ad_image'] ad['ad_image'] = self.args['ad_image']
ad['ad_url'] = self.args['ad_url'] ad['jump_param'] = self.args['jump_param']
ad['jump_status'] = self.args['jump_status']
ad['ad_sort'] = self.args['ad_sort'] or 0 ad['ad_sort'] = self.args['ad_sort'] or 0
ad['companyid'] = self.args['companyid'] ad['companyid'] = self.args['companyid']
# 检查必需有的字段 # 检查必需有的字段
if not ( if not (
ad['name'] and ad['gameid'] and ad['locationid'] and ad['ad_title'] and ad['ad_body'] and ad['ad_image'] and ad['name'] and ad['gameid'] and ad['locationid'] and ad['ad_title'] and ad['ad_body'] and ad['ad_image'] and
ad['ad_url'] and ad['companyid']): ad['jump_param'] and ad['companyid']):
return jsonify({'code': 500, 'message': '一些必填项未提供'}) return jsonify({'code': 500, 'message': '一些必填项未提供'})
# 检查该广告是否已存在 # 检查该广告是否已存在
@ -147,10 +148,11 @@ class Ad(Resource):
ad['ad_title'] = self.args['ad_title'] ad['ad_title'] = self.args['ad_title']
ad['ad_body'] = self.args['ad_body'] ad['ad_body'] = self.args['ad_body']
ad['ad_image'] = self.args['ad_image'] ad['ad_image'] = self.args['ad_image']
ad['ad_url'] = self.args['ad_url'] ad['jump_param'] = self.args['jump_param']
ad['ad_sort'] = self.args['ad_sort'] ad['ad_sort'] = self.args['ad_sort']
ad['status'] = self.args['status'] or 0 ad['status'] = self.args['status'] or 0
ad['companyid'] = self.args['companyid'] ad['companyid'] = self.args['companyid']
ad['jump_status'] = self.args['jump_status']
sel_sql = f"select name from ad where id={self.args['id']};" sel_sql = f"select name from ad where id={self.args['id']};"
data = self.mydb.query(sel_sql) data = self.mydb.query(sel_sql)