diff --git a/README.MD b/README.MD index a50c85c..246f609 100644 --- a/README.MD +++ b/README.MD @@ -1,5 +1,15 @@ ### 推广系统接口文档 +TODO: + +广告添加 own字段 + +返回所有广告[status] +返回单条广告 +图片上传接口 + + + #### 1、获得公司列表 ##### 接口地址 @@ -287,7 +297,7 @@ http://192.168.100.20:8888/ad ##### 请求示范 -http://192.168.100.20:8888/ad?name=abc&gameid=1003&locationid=1&ad_title=hello&ad_body=hi world&ad_image=http://1&ad_url=http://2 +http://192.168.100.20:8888/ad?name=abc&gameid=1003&locationid=1&ad_title=hello&ad_body=hi world&ad_image=http://1&ad_url=http://2&companyid=2 ##### 请求参数说明 @@ -304,7 +314,8 @@ http://192.168.100.20:8888/ad?name=abc&gameid=1003&locationid=1&ad_title=hello&a | end_time | datetime | 否 | 结束时间,默认是3000-01-01 | | ad_num | int | 否 | 投放次数,默认是-1(无限) | | ad_sort | int | 否 | 优先级默认为0 | -| | int | 否 | 默认为0(未审批),1=审批通过,2=审批未通过,3=暂停 | +| status | int | 否 | 默认为0(未审批),1=审批通过,2=审批未通过,3=暂停 | +| companyid | int | 是 | 广告提交公司 | ##### 返回参数说明 @@ -330,7 +341,7 @@ http://192.168.100.20:8888/ad ##### 请求示范 -http://192.168.100.20:8888/ad?name=abc&gameid=1003&locationid=1&ad_title=hello&ad_body=hi world&ad_image=http://1&ad_url=http://2&begin_time=2019-06-01&end_time=2019-12-01&ad_num=300&ad_sort=1&status=1&id=1001 +http://192.168.100.20:8888/ad?name=abc&gameid=1003&locationid=1&ad_title=hello&ad_body=hi world&ad_image=http://1&ad_url=http://2&begin_time=2019-06-01&end_time=2019-12-01&ad_num=300&ad_sort=1&status=1&id=1001&companyid=2 ##### 请求参数说明 @@ -351,6 +362,7 @@ http://192.168.100.20:8888/ad?name=abc&gameid=1003&locationid=1&ad_title=hello&a | ad_num | int | 是 | 投放次数,默认是-1(无限) | | ad_sort | int | 是 | 优先级默认为0 | | status | int | 是 | 默认为0(未审批),1=审批通过,2=审批未通过,3=暂停 | +| companyid | int | 是 | 广告提交公司 | ##### 返回参数说明 @@ -396,7 +408,7 @@ http://192.168.100.20:8888/ad "code": 200 } -#### 11、返回需播放的广告 +#### 11、返回广告列表信息 ##### 接口地址 @@ -412,11 +424,9 @@ http://192.168.100.20:8888/ad?gameid=1003&locationid=1 ##### 请求参数说明 -| 名称 | 类型 | 必填 | 说明 | -| ---------- | ---- | ---- | --------------------------- | -| gameid | int | 是 | 游戏ID | -| locationid | int | 是 | 位置ID | -| status | int | 否 | 审批状态,默认为1(已审批) | +| 名称 | 类型 | 必填 | 说明 | +| ------ | ---- | ---- | --------------------------- | +| status | int | 否 | 审批状态,默认为1(已审批) | ##### 返回参数说明 diff --git a/handler/ad.py b/handler/ad.py index 923f624..08fd37b 100644 --- a/handler/ad.py +++ b/handler/ad.py @@ -35,6 +35,7 @@ parser.add_argument('ad_image') parser.add_argument('ad_url') parser.add_argument('ad_sort') parser.add_argument('status') +parser.add_argument('companyid') class Ad(Resource): @@ -42,23 +43,31 @@ class Ad(Resource): self.args = parser.parse_args() def get(self): - gameid = self.args['gameid'] - localid = self.args['locationid'] - status = self.args['status'] or 1 - if not gameid or not localid: - # log.error(f"请输入必须的游戏ID和位置ID字段,当前获得是{gameid},{localid}") - return jsonify({'code': 500, "message": f"请输入必须的游戏ID和位置ID字段,当前获得是{gameid},{localid},{status}"}) + status = self.args['status'] + id = self.args['id'] + # if not gameid or not localid: + # # log.error(f"请输入必须的游戏ID和位置ID字段,当前获得是{gameid},{localid}") + # return jsonify({'code': 500, "message": f"请输入必须的游戏ID和位置ID字段,当前获得是{gameid},{localid},{status}"}) now = datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S") - sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort from ad where gameid={gameid} and locationid={localid} and status={status};" + if not id: + if status: + sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort,status " \ + f"from ad where status={status};" + else: + sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \ + f"status from ad ;" + else: + sel_sql = f"select id,name,begin_time,end_time,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort," \ + f"status from ad where id={id};" data = mydb.query(sel_sql) log.info(f"sql={sel_sql},data={data}") ad_info = {} if data: try: 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_sort'] = \ - data[0] + 'ad_title'], ad_info['ad_body'], ad_info['ad_image'], ad_info['ad_url'], ad_info['ad_sort'], \ + ad_info['status'] = data[0] return jsonify({'code': 200, 'message': ad_info}) except Exception: log.error("split data from mysql failed!", exc_info=True) @@ -83,15 +92,23 @@ class Ad(Resource): ad['ad_image'] = self.args['ad_image'] ad['ad_url'] = self.args['ad_url'] ad['ad_sort'] = self.args['ad_sort'] or 0 + ad['companyid'] = self.args['companyid'] + # 检查必需有的字段 + if not ( + 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']): + return jsonify({'code': 500, 'message': '一些必填项未提供'}) + # 检查该广告是否已存在 try: - check_sql = f"select id from ad where name='{ad['name']}' and gameid={ad['gameid']} and locationid={ad['locationid']}" + check_sql = f"select id from ad where name='{ad['name']}' and gameid={ad['gameid']} and \ + locationid={ad['locationid']} and companyid=ad['companyid']" data = mydb.query(check_sql) if data: return jsonify({'code': 500, 'message': f"name={ad['name']} gameid={ad['gameid']} was in db!"}) except Exception: - log.error(f"check new id in db failed!",exc_info=True) - return jsonify({'code':500,'message':'check data in db failed!'}) + log.error(f"check new id in db failed!", exc_info=True) + return jsonify({'code': 500, 'message': 'check data in db failed!'}) try: mydb.insert('ad', ad) return jsonify({'code': 200}) @@ -126,6 +143,7 @@ class Ad(Resource): ad['ad_url'] = self.args['ad_url'] ad['ad_sort'] = self.args['ad_sort'] ad['status'] = self.args['status'] or 0 + ad['companyid'] = self.args['companyid'] sel_sql = f"select name from ad where id={self.args['id']};" data = mydb.query(sel_sql) @@ -150,3 +168,11 @@ class Ad(Resource): return jsonify({'code': 200, 'message': f'remove adid={id} success!'}) except Exception: log.error("remove id from ad failed!", exc_info=True) + + +class Adlist(Resource): + def __init__(self): + self.args = parser.parse_args() + + def get(self): + pass