fix some error
This commit is contained in:
parent
aa49059bb9
commit
8b4349b4cd
@ -91,6 +91,7 @@ http://192.168.100.20:8888/company?name=kings&contact=pt&tel=1234
|
||||
| name | string | 是 | 公司名称 |
|
||||
| contact | string | 是 | 联系人 |
|
||||
| tel | string | 是 | 联系电话 |
|
||||
| user | string | 是 | 登录账号 |
|
||||
|
||||
##### 返回参数说明
|
||||
|
||||
@ -117,7 +118,7 @@ http://192.168.100.20:8888/company
|
||||
|
||||
##### 请求示范
|
||||
|
||||
http://192.168.100.20:8888/company?appid=zpoHY37u&appkey=undefined&contact=miles&id=1006&name=kingsome&status=1&tel=17771
|
||||
http://192.168.100.20:8888/company?appid=zpoHY37u&appkey=undefined&contact=miles001&id=1006&name=kingsome&status=1&tel=17771&user=assd
|
||||
|
||||
##### 请求参数说明
|
||||
|
||||
@ -126,6 +127,7 @@ http://192.168.100.20:8888/company?appid=zpoHY37u&appkey=undefined&contact=miles
|
||||
| name | string | 是 | 公司名称 |
|
||||
| contact | string | 是 | 联系人 |
|
||||
| tel | string | 是 | 联系电话 |
|
||||
| user | string | 是 | 登录账号 |
|
||||
| id | int | 是 | 公司id(唯一值) |
|
||||
| appid | string | 是 | 公司标识 |
|
||||
| appkey | string | 是 | 认证用,暂无 |
|
||||
|
35
adlist.py
35
adlist.py
@ -5,15 +5,19 @@ from flask import Flask, jsonify
|
||||
from flask_restful import reqparse, abort, Api, Resource
|
||||
from log.mylog import define_logger
|
||||
import logging
|
||||
from mysql.mmysql import MysqlBase
|
||||
from config import mysql_promotion_config
|
||||
from myredis.myredis import my_redis, expire_time
|
||||
import datetime
|
||||
|
||||
define_logger("/data/logs/adlist.log")
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('id')
|
||||
parser.add_argument('gameid')
|
||||
parser.add_argument('name')
|
||||
parser.add_argument('locationid')
|
||||
parser.add_argument('num')
|
||||
|
||||
parser.add_argument('begin_time')
|
||||
parser.add_argument('end_time')
|
||||
parser.add_argument('ad_num')
|
||||
@ -24,15 +28,36 @@ parser.add_argument('ad_url')
|
||||
parser.add_argument('ad_sort')
|
||||
parser.add_argument('status')
|
||||
parser.add_argument('companyid')
|
||||
mydb = MysqlBase(**mysql_promotion_config)
|
||||
|
||||
|
||||
class Adlist(Resource):
|
||||
def __init__(self):
|
||||
self.args = parser.parse_args()
|
||||
self.limit = 20
|
||||
|
||||
def init_ad(self):
|
||||
# 初始化广告信息,将广告明细写入缓存Redis
|
||||
pass
|
||||
|
||||
|
||||
def get(self):
|
||||
pass
|
||||
gameid = self.args['gameid']
|
||||
locationid = self.args['locationid']
|
||||
num = self.args['num'] or self.limit
|
||||
if num > self.limit:
|
||||
num = self.limit
|
||||
|
||||
now = datetime.datetime.today().strftime('%Y-%m-%d')
|
||||
ad_list_per = my_redis.smembers(f"{gameid}#{locationid}#per")
|
||||
ad_list_int = []
|
||||
for i in range(num):
|
||||
ad_list_int.append(my_redis.spop(f"{gameid}#{locationid}#{now}"))
|
||||
ad_list = ad_list_int + ad_list_per
|
||||
|
||||
ad_info = []
|
||||
for item in ad_list:
|
||||
ad_info.append(my_redis.smembers[item])
|
||||
|
||||
return jsonify({'code': 200, 'message': {'total': len(ad_list), 'result': ad_info}})
|
||||
|
||||
def post(self):
|
||||
pass
|
||||
|
@ -31,12 +31,15 @@ class Company(Resource):
|
||||
def get(self):
|
||||
status = self.args['status']
|
||||
id = self.args['id']
|
||||
user = self.args['user']
|
||||
all_data = []
|
||||
try:
|
||||
if status:
|
||||
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where status={status};"
|
||||
elif id:
|
||||
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where id={id};"
|
||||
elif user:
|
||||
sql = f"select id,name,contact,tel,appid,appkey,status,user from company where user={user};"
|
||||
else:
|
||||
sql = f"select id,name,contact,tel,appid,appkey,status,user from company ;"
|
||||
data = mydb.query(sql)
|
||||
|
1
jobs/__init__.py
Normal file
1
jobs/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
46
jobs/init_ad.py
Normal file
46
jobs/init_ad.py
Normal file
@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from log.mylog import define_logger
|
||||
import logging
|
||||
from mysql.mmysql import MysqlBase
|
||||
from config import mysql_promotion_config
|
||||
from myredis.myredis import my_redis, expire_time
|
||||
import datetime
|
||||
|
||||
|
||||
log = logging.getLogger("/data/logs/init_ad_redis.log")
|
||||
|
||||
mydb = MysqlBase(**mysql_promotion_config)
|
||||
|
||||
|
||||
class Init_ad_redis():
|
||||
# 初始化广告信息,将广告明细写入缓存Redis
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def init_redis(self):
|
||||
now = datetime.datetime.today().strftime("%Y-%m-%d")
|
||||
ad_list = # get info from redis
|
||||
data = my_redis.hmget(key)
|
||||
if not data:
|
||||
getdata_sql = f"select id,name,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort,gameid,locationid from ad \
|
||||
where status=2 and ad_num=-1 and begin_time <'{now}' and end_time >'{now}' ;"
|
||||
data=mydb.query(getdata_sql)
|
||||
|
||||
|
||||
|
||||
|
||||
def check_expired(self):
|
||||
pass
|
||||
|
||||
|
||||
def check_play_num(self):
|
||||
|
||||
|
||||
# not found! get from mysql
|
||||
|
||||
# update 2 redis
|
||||
|
||||
|
||||
def post(self):
|
||||
pass
|
@ -9,5 +9,5 @@ log = logging.getLogger(__name__)
|
||||
pool = redis.ConnectionPool(host=redis_company_config['host'], port=redis_company_config['port'],
|
||||
db=redis_company_config['db'], decode_responses=True)
|
||||
|
||||
company_redis = redis.Redis(connection_pool=pool)
|
||||
my_redis = redis.Redis(connection_pool=pool)
|
||||
expire_time = expire_time
|
||||
|
Loading…
x
Reference in New Issue
Block a user