revome gameid from localtion
This commit is contained in:
parent
a5cc75432d
commit
d290fcf4f5
@ -36,11 +36,12 @@ parser.add_argument('ad_url')
|
|||||||
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')
|
||||||
mydb = MysqlBase(**mysql_promotion_config)
|
|
||||||
|
|
||||||
class Ad(Resource):
|
class Ad(Resource):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.args = parser.parse_args()
|
self.args = parser.parse_args()
|
||||||
|
self.mydb = MysqlBase(**mysql_promotion_config)
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
status = self.args['status']
|
status = self.args['status']
|
||||||
@ -64,7 +65,7 @@ class Ad(Resource):
|
|||||||
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,locationid,gameid from ad where id={id};"
|
f"status,companyid,locationid,gameid from ad where id={id};"
|
||||||
data = 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}")
|
||||||
if data:
|
if data:
|
||||||
all = []
|
all = []
|
||||||
@ -109,14 +110,14 @@ class Ad(Resource):
|
|||||||
try:
|
try:
|
||||||
check_sql = f"select id from ad where name='{ad['name']}' and gameid={ad['gameid']} and \
|
check_sql = f"select id from ad where name='{ad['name']}' and gameid={ad['gameid']} and \
|
||||||
locationid={ad['locationid']} and companyid=ad['companyid']"
|
locationid={ad['locationid']} and companyid=ad['companyid']"
|
||||||
data = mydb.query(check_sql)
|
data = self.mydb.query(check_sql)
|
||||||
if data:
|
if data:
|
||||||
return jsonify({'code': 500, 'message': f"name={ad['name']} gameid={ad['gameid']} was in db!"})
|
return jsonify({'code': 500, 'message': f"name={ad['name']} gameid={ad['gameid']} was in db!"})
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error(f"check new id in db failed!", exc_info=True)
|
log.error(f"check new id in db failed!", exc_info=True)
|
||||||
return jsonify({'code': 500, 'message': 'check data in db failed!'})
|
return jsonify({'code': 500, 'message': 'check data in db failed!'})
|
||||||
try:
|
try:
|
||||||
mydb.insert('ad', ad)
|
self.mydb.insert('ad', ad)
|
||||||
return jsonify({'code': 200, 'message': 'add adid={id} success!'})
|
return jsonify({'code': 200, 'message': 'add adid={id} success!'})
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("Insert ad to mysql failed!", exc_info=True)
|
log.error("Insert ad to mysql failed!", exc_info=True)
|
||||||
@ -124,7 +125,7 @@ class Ad(Resource):
|
|||||||
|
|
||||||
def get_adid(self):
|
def get_adid(self):
|
||||||
max_id = f"select id from ad order by id desc limit 1"
|
max_id = f"select id from ad order by id desc limit 1"
|
||||||
data = mydb.query(max_id)
|
data = self.mydb.query(max_id)
|
||||||
try:
|
try:
|
||||||
max = int(data[0][0]) + 1
|
max = int(data[0][0]) + 1
|
||||||
log.info(f"max id was {max}!")
|
log.info(f"max id was {max}!")
|
||||||
@ -152,10 +153,10 @@ class Ad(Resource):
|
|||||||
ad['companyid'] = self.args['companyid']
|
ad['companyid'] = self.args['companyid']
|
||||||
|
|
||||||
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 = mydb.query(sel_sql)
|
data = self.mydb.query(sel_sql)
|
||||||
if data:
|
if data:
|
||||||
condition = f"id='{self.args['id']}'"
|
condition = f"id='{self.args['id']}'"
|
||||||
mydb.update("ad", ad, condition)
|
self.mydb.update("ad", ad, condition)
|
||||||
return jsonify({'code': 200, 'message': 'update adid={id} success!'})
|
return jsonify({'code': 200, 'message': 'update adid={id} success!'})
|
||||||
else:
|
else:
|
||||||
return jsonify({'code': 404, 'message': f"{self.args['id']} not found in mysql!"})
|
return jsonify({'code': 404, 'message': f"{self.args['id']} not found in mysql!"})
|
||||||
@ -170,7 +171,7 @@ class Ad(Resource):
|
|||||||
return jsonify({'code': 404, 'message': f'{id} not found!'})
|
return jsonify({'code': 404, 'message': f'{id} not found!'})
|
||||||
del_sql = f"delete from ad where id={id};"
|
del_sql = f"delete from ad where id={id};"
|
||||||
try:
|
try:
|
||||||
mydb.change(del_sql)
|
self.mydb.change(del_sql)
|
||||||
return jsonify({'code': 200, 'message': f'remove adid={id} success!'})
|
return jsonify({'code': 200, 'message': f'remove adid={id} success!'})
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("remove id from ad failed!", exc_info=True)
|
log.error("remove id from ad failed!", exc_info=True)
|
||||||
|
@ -20,12 +20,13 @@ parser.add_argument('appkey')
|
|||||||
parser.add_argument('status')
|
parser.add_argument('status')
|
||||||
parser.add_argument('tel')
|
parser.add_argument('tel')
|
||||||
parser.add_argument('user')
|
parser.add_argument('user')
|
||||||
mydb = MysqlBase(**mysql_promotion_config)
|
|
||||||
|
|
||||||
|
|
||||||
class Company(Resource):
|
class Company(Resource):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.args = parser.parse_args()
|
self.args = parser.parse_args()
|
||||||
|
self.mydb = MysqlBase(**mysql_promotion_config)
|
||||||
|
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
@ -42,7 +43,7 @@ class Company(Resource):
|
|||||||
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where user='{user}';"
|
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where user='{user}';"
|
||||||
else:
|
else:
|
||||||
sql = f"select id,name,contact,tel,appid,appkey,status,user from company ;"
|
sql = f"select id,name,contact,tel,appid,appkey,status,user from company ;"
|
||||||
data = mydb.query(sql)
|
data = self.mydb.query(sql)
|
||||||
|
|
||||||
log.info(f"get data from db was {data}")
|
log.info(f"get data from db was {data}")
|
||||||
if data:
|
if data:
|
||||||
@ -65,7 +66,7 @@ class Company(Resource):
|
|||||||
id = self.args['id']
|
id = self.args['id']
|
||||||
try:
|
try:
|
||||||
del_sql = f'delete from company where id={id};'
|
del_sql = f'delete from company where id={id};'
|
||||||
mydb.query(del_sql)
|
self.mydb.query(del_sql)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error(f"remove {id} failed!", exc_info=True)
|
log.error(f"remove {id} failed!", exc_info=True)
|
||||||
return jsonify({'code': 500})
|
return jsonify({'code': 500})
|
||||||
@ -80,14 +81,14 @@ class Company(Resource):
|
|||||||
appid = self.get_random()
|
appid = self.get_random()
|
||||||
# check appid not in db
|
# check appid not in db
|
||||||
check_appid = f"select appid from company where appid='{appid}'"
|
check_appid = f"select appid from company where appid='{appid}'"
|
||||||
data = mydb.query(check_appid)
|
data = self.mydb.query(check_appid)
|
||||||
if data:
|
if data:
|
||||||
self.get_appid()
|
self.get_appid()
|
||||||
return appid
|
return appid
|
||||||
|
|
||||||
def get_companyid(self):
|
def get_companyid(self):
|
||||||
max_id = f"select id from company order by id desc limit 1"
|
max_id = f"select id from company order by id desc limit 1"
|
||||||
data = mydb.query(max_id)
|
data = self.mydb.query(max_id)
|
||||||
log.info(f"1 {data}")
|
log.info(f"1 {data}")
|
||||||
try:
|
try:
|
||||||
max = int(data[0][0]) + 1
|
max = int(data[0][0]) + 1
|
||||||
@ -108,7 +109,7 @@ class Company(Resource):
|
|||||||
company['id'] = self.get_companyid()
|
company['id'] = self.get_companyid()
|
||||||
company['appid'] = self.get_appid()
|
company['appid'] = self.get_appid()
|
||||||
company['appkey'] = 'undefined'
|
company['appkey'] = 'undefined'
|
||||||
mydb.insert("company", company)
|
self.mydb.insert("company", company)
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("set values to company mysql failed!", exc_info=True)
|
log.error("set values to company mysql failed!", exc_info=True)
|
||||||
return jsonify({'code': 500})
|
return jsonify({'code': 500})
|
||||||
@ -128,10 +129,10 @@ class Company(Resource):
|
|||||||
company['appkey'] = self.args['appkey']
|
company['appkey'] = self.args['appkey']
|
||||||
|
|
||||||
sel_sql = f"select name from company where id={self.args['id']};"
|
sel_sql = f"select name from company where id={self.args['id']};"
|
||||||
data = mydb.query(sel_sql)
|
data = self.mydb.query(sel_sql)
|
||||||
if data:
|
if data:
|
||||||
condition = f"id='{self.args['id']}'"
|
condition = f"id='{self.args['id']}'"
|
||||||
mydb.update("company", company, condition)
|
self.mydb.update("company", company, condition)
|
||||||
return jsonify({'code': 200})
|
return jsonify({'code': 200})
|
||||||
else:
|
else:
|
||||||
return jsonify({'code': 404, 'message': f"{self.args['id']} not found in mysql!"})
|
return jsonify({'code': 404, 'message': f"{self.args['id']} not found in mysql!"})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user