예제 #1
0
def set_server_state():
    channels = request.form.get("channels")
    state = int(request.form.get("state"))

    if state not in [SERVER_STATE_STOP, SERVER_STATE_PRE_PUBLIC, SERVER_STATE_PUBLIC]:
        return jsonify({})

    for channel in channels.split(","):
        if channel:
            payload = {
                "channels": channel,
                "state": state
            }
            channel_id = int(redis_conn.hget(CHANNEL_CONFIG_TABLE + channel, "id"))
            sql = 'select other_msg from channel where id = %d' % channel_id
            cfg = SqlOperate().select(sql)[0][0]
            conf = json.loads(cfg)
            conf["server_state"] = state

            sql = "update channel set other_msg = '%s' where id = %d" % (json.dumps(conf), channel_id)
            SqlOperate().update(sql)
            redis_conn.hset(CHANNEL_CONFIG_TABLE + channel, "server_state", state)
            redis_conn.hset(CHANNEL_CONFIG_TABLE + str(channel_id), "server_state", state)

    return jsonify({})
예제 #2
0
def add_annouce_game():
    title = request.form.get('title')
    content_image_url = request.form.get('content_image_url')
    push_times = request.form.get('push_times')
    priority = request.form.get('priority')
    date1 = request.form.get('date1')
    date2 = request.form.get('date2')
    channel_id = session['select_channel']

    # 校验并处理参数参数
    if not all([title, content_image_url, push_times, priority, date1, date2]):
        return jsonify(result=0, msg=u'请填入所有内容!')
    try:
        int(push_times)
        int(priority)
    except ValueError:
        return jsonify(result=0, msg=u'每日展示次数与优先级为整数纯数字!')
    date1 = time_util.formatTimestamp(date1)
    date2 = time_util.formatTimestamp(date2)
    if date1 > date2:
        return jsonify(result=0, msg=u'开始日期不能大于结束日期!')

    sql = "select ifnull(max(id), 1) + 1 from admin_announcement"
    notice_id = int(LogQry(channel_id).qry(sql)[0][0])

    channel = redis_conn.hget(CHANNEL_CONFIG_TABLE + str(channel_id), "name")
    payload = {
        "start_time": date1,
        "end_time": date2,
        "channel": channel,
        "notice_id": notice_id,
        "push_times": push_times,
        "priority": priority,
        "content_img": content_image_url
    }
    redis_conn.hset(NOTICE_TABLE + channel, notice_id, payload)

    create_sql = """
        INSERT INTO admin_announcement
            (id,channel,title,priority,content_image_url,
            push_times,start_date,end_date)
        VALUES (%d,%s,'%s',%s,'%s', 
                %s,%s,%s)
    """ % (notice_id, channel_id, title, priority, content_image_url,
           push_times, date1, date2)

    LogQry(channel_id).execute(create_sql)

    return jsonify(result=1, msg=u'新建公告成功!')
예제 #3
0
def sdk_bgp_conn():
    data = request.args

    if data.get("clear"):
        ## 删除链接
        return clear_bgp_conn()

    size = data.get("size")
    country = data.get("country")
    val = "%s_%s" % (size, country)

    for channel, key in data.items():
        if len(key.split("_")) == 2:
            redis_conn.hset(BGP_TABLE + channel, key, val)

    return jsonify()
예제 #4
0
def get_channel_data():
    rr = httpc_util.post(Config.ADMIN_WEB_SITE + "/api/channel_data", {})
    rr = rr.json()
    for dd in rr["data"]:
        channel = dd["name"]
        channel_id = dd["id"]
        redis_conn.hmset(CHANNEL_CONFIG_TABLE + channel, dd)
        redis_conn.hmset(CHANNEL_CONFIG_TABLE + str(channel_id), dd)
        try:
            redis_conn.hset(WX_CONFIG_TABLE, dd["wx_appid"], dd["wx_token"])
        except:
            pass
        try:
            redis_conn.hset(WX_CONFIG_TABLE, dd["h5_wx_appid"],
                            dd["h5_wx_token"])
        except:
            pass

    return jsonify()
예제 #5
0
def game_parameter_update():
    """游戏参数新建"""

    # 获取参数
    type_id = request.form.get('type')
    config = request.form.get('config')

    # 校验参数
    try:
        eval(config)
        redis_conn.hset(GAME_PARAMTER_TABLE, type_id, config)
    except ValueError:
        return jsonify(result='fail', msg=u'内容不合法')

    # 存进数据库
    update_sql = """replace into game_parameter (type, config) values (%s, '%s')""" % (
        type_id, config)
    SqlOperate().update(update_sql)

    # 返回应答
    return jsonify(result='ok', msg=u'新建成功!')
예제 #6
0
def sdk_reset_click_tj():
    if request.method == 'POST':
        data = request.form
    else:
        data = request.args

    channel = data.get("channel")

    ios = redis_conn.hget("download_count", "%s_ios" % channel)
    redis_conn.hset("download_count", "%s_ios" % channel, 0)
    android = redis_conn.hget("download_count", "%s_android" % channel)
    redis_conn.hset("download_count", "%s_android" % channel, 0)

    try:
        ios = int(ios)
    except:
        ios = 0

    try:
        android = int(android)
    except:
        android = 0

    return jsonify({"ios": ios, "android": android})
예제 #7
0
def load_game_paramter():
    sql = 'SELECT type, config FROM game_parameter'
    for stype, config in SqlOperate().select(sql):
        redis_conn.hset(GAME_PARAMTER_TABLE, stype, config)