コード例 #1
0
ファイル: backstage.py プロジェクト: DJune12138/django_demo
def backstage_edit(request):
    sync_id = int(request.GET.get('sync_id', '') or 0)

    edit_db = None
    #是否通过编辑按钮进入
    if sync_id:
        edit_db = get_backstage_data(bid=sync_id)

    is_post = True if request.POST else False  #是否提交了数据
    if is_post:
        conn = getConn()
        cursor = conn.cursor()

        backstage_name = request.POST.get('bs_name', '')
        backstage_url = request.POST.get('url', '')
        backstage_key = request.POST.get('key', '')

        if edit_db:
            sql = "UPDATE log_backstage SET f1='%s',f2='%s',f3='%s' WHERE id='%s'" % (
                backstage_name, backstage_url, backstage_key, sync_id)
        else:
            sql = filter_sql(
                "INSERT INTO log_backstage(log_user,log_type,f1,f2,f3,log_time) VALUES (1,1,'%s', '%s', '%s', NOW())"
                % (backstage_name, backstage_url, backstage_key))

        try:
            cursor.execute(sql)
            if not edit_db:
                sync_id = conn.insert_id()  #添加操作时,获取新增ID
        except MySQLdb.Warning, e:
            pass
        finally:
コード例 #2
0
def get_channel_id(player_id):
    channel_id = 0
    conn = getConn()
    try:
        query_sql = "select channel_id from player_all where player_id=%d" % (
            player_id)
        print(query_sql)
        cursor = conn.cursor()
        cursor.execute(query_sql)
        pay_user_record = cursor.fetchone()
        if pay_user_record != None:
            # pay_user = int(pay_user_record[0])
            channel_id = int(pay_user_record[0])
    except Exception, e:
        print('get player_channel_id has error', e)
コード例 #3
0
ファイル: backstage.py プロジェクト: DJune12138/django_demo
def backstage_remove(request):
    sync_id = int(request.GET.get("sync_id", 0))
    is_del = True if sync_id else False

    #删除操作
    if is_del:
        conn = getConn()
        cursor = conn.cursor()
        try:
            cursor.execute("DELETE FROM log_backstage WHERE id='%s'" % sync_id)
            conn.commit()
        except:
            err_msg = trace_msg()
        conn.close()
    return render_to_response('feedback.html', locals())
コード例 #4
0
def change_player_name(player_id, game_name):
    #_sid = get_server_id(player_id)
    _sid = int(player_id) >> 20
    _r = {'code': 1}
    try:
        conn = getConn(_sid)
        sql = "update player_%s set player_name='%s' where player_id=%d ;" % (
            _sid, game_name.encode('utf-8'), player_id)
        cur = conn.cursor()
        cur.execute(sql)
        _r['code'] = 0
        _r['msg'] = 'OK!'
    except Exception, e:
        err_msg = trace_msg()
        _r['msg'] = err_msg
コード例 #5
0
def player_block(request, server_id=0):
    '''封号
    '''
    player_ids = request.REQUEST.getlist('player_id')
    server_id = int(request.REQUEST.get('server_id', 0))
    _r = {"code": -1, "msg": ""}
    if request.method == 'POST' and player_ids:
        try:
            remark = request.REQUEST.get('remark', '')
            conn = getConn(server_id)
            cursor = conn.cursor()
            the_status = -1
            gmp = GMProtocol(server_id)
            if request.REQUEST.get('block_type', '') == '1':
                the_status = -1
                log_type = GMActionType.block_player
                result = gmp.block_player(player_ids)
                if result != 0:
                    return HttpResponse(json.dumps(_r))
            else:
                the_status = 0
                log_type = GMActionType.unblock_player
                result = gmp.unblock_player(player_ids)
                if result != 0:
                    return HttpResponse(json.dumps(_r))
            query_sql = 'update player_%d set status=%d where player_id in (%s)' % (
                server_id, the_status, ','.join(player_ids))
            cursor.execute(query_sql)
            cursor.close()
            for player_id in player_ids:
                write_gm_log(
                    request.admin.id,
                    log_type,
                    log_type,
                    server_id,
                    player_id,
                    '',
                    0,
                    '',
                    '',
                    remark1=remark,
                )
            _r["code"] = 0

        except Exception, e:
            err_msg = trace_msg()
            _r["msg"] = err_msg
コード例 #6
0
def change_user_type(request):
    '''修改用户类型
    '''
    player_id = int(request.GET.get('player_id', '0'))
    if player_id:
        sid = player_id >> 20
        cursor = getConn(sid).cursor()
        if request.method == 'POST':
            user_type = request.POST.get('user_type', '')
            if user_type != '':
                update_sql = "update player_%s set user_type=%d where player_id=%d" % (
                    sid, int(user_type), player_id)
                cursor.execute(update_sql)
                return render_to_response('feedback.html')
        else:
            sql = 'select user_type from player_%d where player_id=%d;' % (
                sid, player_id)
            cursor.execute(sql)
            user_type = cursor.fetchone()[0]
    return render_to_response('game/change_user_type.html', locals())
コード例 #7
0
def role_transfer(request):
    '''角色转移
    '''
    _r = 'fail'
    oid = int(request.POST.get('oid', '0') or 0)
    nid = int(request.POST.get('nid', '0') or 0)

    if oid and nid:
        o_sid = int(oid) >> 20
        n_sid = int(nid) >> 20
        if o_sid == n_sid:
            try:
                conn = getConn(o_sid)
                query_sql = "select link_key,user_type from player_{0} where player_id in ({1},{2})".format(
                    o_sid, oid, nid)
                print '=====>:', query_sql
                cur = conn.cursor()
                cur.execute(query_sql)
                user_list = cur.fetchall()
                if len(user_list) > 1:
                    n_key = user_list[0][0]
                    n_user_type = int(user_list[0][1])
                    o_key = user_list[1][0]
                    o_user_type = int(user_list[1][1])

                    sql1 = "update player_%s set link_key='%s',user_type=%d where player_id=%d" % (
                        o_sid, n_key, n_user_type, oid)
                    sql2 = "update player_%s set link_key='%s',user_type=%d where player_id=%d" % (
                        o_sid, o_key, o_user_type, nid)
                    cur.execute(sql1)
                    cur.execute(sql2)
                    #print sql1,sql2
                    _r = 'OK!'

            except Exception, e:
                err_msg = trace_msg()
                _r = err_msg
コード例 #8
0
def player_info(request):
    g = lambda x, y: request.GET.get(x, request.POST.get(x, y))
    server_id = g('server_id', '')
    player_id = g('id', '')

    server_id = int(server_id)

    code = 1
    msg = ''
    item = {}
    try:
        conn = getConn(server_id)
        cur = conn.cursor()
        sql = 'select player_id,player_name,channel_id,user_type,link_key,login_num,mobile_key,last_time,create_time,status from player_%s WHERE player_id = %s '
        cur.execute(sql, (server_id, player_id))
        data_list = cur.fetchall()
        if 0 < data_list.__len__():
            tmp = data_list[0]
            s = item.setdefault
            s('player_id', tmp[0])
            s('player_name', tmp[1])
            s('channel_id', tmp[2])
            s('channel_name', center_cache.get_channel_by_id(str(tmp[2])).name)
            s('user_type', tmp[3])
            s('link_key', tmp[4])
            s('login_num', tmp[5])
            s('mobile_key', tmp[6])
            s('last_time', tmp[7].strftime('%Y-%m-%d %H:%M:%S'))
            s('create_time', tmp[8].strftime('%Y-%m-%d %H:%M:%S'))
            s('status', tmp[9])

            print item
            code = 0
    except Exception, ex:
        print 'player_info error:', ex
        msg = '查询出错'
        code = -1
コード例 #9
0
ファイル: backstage.py プロジェクト: DJune12138/django_demo
def get_backstage_data(bid=0):
    conn = getConn()
    cursor = conn.cursor()
    where = "id=%s" % bid if bid else "1"

    cursor.execute(
        "SELECT id,f1,f2,f3,log_time FROM log_backstage where %s ORDER BY id ASC"
        % where)
    ret = cursor.fetchall()

    serv_list = []
    for r in ret:
        serv_list.append({
            "id": r[0],
            "name": r[1],
            "url": r[2],
            "key": r[3],
            "time": r[4].strftime("%Y-%m-%d %H:%M:%S")
        })

    cursor.close()
    conn.close()

    return serv_list[0] if bid else serv_list
コード例 #10
0
def update_pay_action_channel(request):

    sdate = request.GET.get('sdate', request.POST.get('sdate', ''))
    edate = request.GET.get('edate', request.POST.get('edate', ''))

    sid = int(request.GET.get('sid', request.POST.get('sid', 0)))
    eid = int(request.GET.get('eid', request.POST.get('eid', 0)))
    page_size = 100

    if eid - sid > page_size:
        eid = sid + page_size

    where_sql = ' (channel_id = 0 OR channel_id IS NULL) AND pay_status >= 4 AND pay_amount > 0 '

    if '' != sdate and '' != edate:
        sdate = datetime.datetime.strptime(sdate,
                                           '%Y-%m-%d').strftime('%Y-%m-%d')
        edate = datetime.datetime.strptime(edate,
                                           '%Y-%m-%d').strftime('%Y-%m-%d')
        where_sql = where_sql + " AND last_time BETWEEN '%s' AND '%s' " % (
            sdate, edate)

    center_con = connections['write']
    center_cur = center_con.cursor()
    pargs = {"status": 1}

    if 0 == sid or 0 == eid:
        count_sql = 'SELECT MIN(id), MAX(id) FROM pay_action  WHERE %s ' % where_sql
        center_cur.execute(count_sql)
        result_item = center_cur.fetchone()
        min_id = 0
        max_id = 0
        if None != result_item:
            if None != result_item[0] and None != result_item[0]:
                min_id, max_id = int(result_item[0]), int(result_item[1])
        pargs["min_id"] = min_id
        pargs["max_id"] = max_id
        pargs["page_size"] = page_size

        sid = min_id
        eid = sid + page_size

    sql = 'SELECT id,server_id,channel_key,pay_user FROM pay_action WHERE %s AND id BETWEEN %s AND %s ' % (
        where_sql, sid, eid)

    center_cur.execute(sql)
    list_data = center_cur.fetchall()

    channel_list = get_channel_list()
    for item in list_data:
        item_id = item[0]
        server_id = item[1]
        channel_key = item[2]
        pay_user = item[3]

        channel_id = 0

        if '' != channel_key and None != channel_key:

            for channel_item in channel_list:
                if channel_item.channel_key == channel_key:
                    channel_id = channel_item.id

        if 0 == channel_id:
            con = None
            cur = None
            try:
                con = getConn(server_id)
                cur = con.cursor()
                tmp_sql = 'SELECT channel_id FROM player_%s WHERE player_id=%s' % (
                    server_id, pay_user)
                cur.execute(tmp_sql)
                list_player_result = cur.fetchall()
                if 0 < list_player_result.__len__():
                    channel_id = list_player_result[0][0]
            except:
                continue
            finally:
                if None != cur:
                    cur.close()

                if None != con:
                    con.close()

        if 0 != channel_id:
            update_sql = 'UPDATE pay_action SET channel_id=%s WHERE id=%s '
            center_cur.execute(update_sql % (channel_id, item_id))

    sid = eid + 1
    eid = sid + page_size

    pargs["sid"] = sid
    pargs["eid"] = eid
    pargs["status"] = 0
    return HttpResponse(json.dumps(pargs))
コード例 #11
0
    ip = OperateLogManager.get_request_ipAddress(request)
    try:
        OperateLogManager.save_operate_log(
            the_user.id,
            '添加订单, pay_channel:%s server_id:%s player_id:%s  amount:%s' %
            (pay_channel, server_id, player_id, amount), '/pay/add', ip, 0)
    except Exception, ex:
        print ex
    finally:
        print 'add order, pay_channel:%s server_id:%s player_id:%s  amount:%s ' % (
            pay_channel, server_id, player_id, amount)

    channel_id = 0
    msg = ''
    try:
        conn = getConn(server_id)
        cur = conn.cursor()
        sql = 'SELECT channel_id FROM player_%s where player_id = %s' % (
            server_id, player_id)
        print sql
        cur.execute(sql)
        result_list = cur.fetchall()
        if 0 < result_list.__len__():
            channel_id = result_list[0][0]
        else:
            msg = '用户不存在'
    except Exception, ex:
        print ex
        msg = '用户不存在'

    the_pay_channel = PayChannel.objects.get(id=pay_channel)
コード例 #12
0
def user_convert(request, server_id=0):
    server_id = int(server_id)
    err_msg = ''
    if server_id > 0:
        try:
            conn = getConn(server_id)
        except:
            err_msg = '数据库链接出错!'
    else:
        conn = connection
    if err_msg != '':
        parg = {}
        parg["err_msg"] = err_msg
        return render_to_response('feedback.html', parg)
    cursor = conn.cursor()

    start_pos = int(request.GET.get('pos', 0))
    if start_pos == 0:
        query_sql = 'select id from log_create_role where log_user=(select max(player_id) from player_%d)' % (
            server_id, )
        cursor.execute(query_sql)
        last_player_id = cursor.fetchone()
        if last_player_id != None:
            start_pos = int(last_player_id[0])

    sql = 'select log_user,log_result,f1,log_time,id from log_create_role where id>%d order by id limit 100' % start_pos
    cursor.execute(sql)
    list_record = cursor.fetchall()
    for item in list_record:
        try:
            #先判断存在与否
            sql = 'select count(0) from player_%d where player_id=%d' % (
                server_id, item[0])
            cursor.execute(sql)
            count_list = cursor.fetchone()
            total_record = int(count_list[0])

            if total_record == 0:
                the_user = User.objects.using('read').get(id=item[1])
                if the_user.user_type == 0:
                    link_key = the_user.id
                else:
                    link_key = the_user.link_key
                channel_id = 0
                try:
                    the_channel = Channel.objects.using('read').get(
                        channel_key=the_user.channel_key)
                    channel_id = the_channel.id
                except:
                    pass
                try:
                    sql = '''insert into player_%d(player_id,player_name,user_type,link_key,channel_id,create_time,last_ip,last_time,login_num,status,mobile_key)
                            values(%s,"%s",%s,"%s",%s,"%s","%s","%s",0,0,"%s")''' % (
                        server_id, item[0], item[2].replace(
                            '\\', '\\\\'), the_user.user_type, link_key,
                        channel_id, item[3], the_user.last_ip,
                        the_user.last_time, the_user.mobile_key)
                    cursor.execute(sql)
                except Exception, e:
                    print('convert user has error', e, item[0])
        except Exception, e:
            print('convert user has error', e, item[0])
        start_pos = item[4]
コード例 #13
0
def _player_list(request, server_id=0):
    '''玩家列表
    '''
    page_size = 30
    page_num = int(request.GET.get("page_num", "1"))
    is_block = int(request.GET.get("block", 0))
    group_id = int(request.GET.get("group_id", 0))
    post_back = int(request.GET.get('post_back', '0'))

    list_group = center_cache.get_group_list()

    if (page_num < 1):
        page_num = 1

    the_user = request.admin

    list_channel = center_cache.get_channel_list()

    itemChannelList = {}
    for item in list_channel:
        itemChannelList[item.id] = item.name

    list_group_server = []
    if group_id != 0:
        list_group_server = center_cache.get_group_server_list(group_id)

    if request.admin.is_root:
        list_server = center_cache.get_server_list()
    else:
        list_server = center_cache.get_user_server_list(the_user)

    tmp_list_server = []
    if 0 != list_group_server.__len__():
        for item in list_group_server:
            if list_server.__contains__(item):
                tmp_list_server.append(item)
        list_server = tmp_list_server

    itemServerList = {}
    for item in list_server:
        itemServerList[item.id] = item.name

    player_key = request.GET.get('key', '')
    key_type = request.GET.get('key_type', '0')
    user_type = int(request.GET.get('user_type', '-1'))
    channel_id = int(request.session.get('channelId', '0'))

    server_id = int(request.GET.get("server_id", "0"))

    if server_id <= 0:
        server_id = int(request.session.get("serverId", "0"))
#    if server_id<=0 and len(list_server)>0:
#        server_id=list_server[0].id
    player_keys = [player_key]

    if key_type == '0' and player_key:
        if ',' in player_key:
            player_keys = [x.strip() for x in player_key.split(',') if x]
        if server_id <= 0:
            server_id = int(player_keys[0]) >> 20

    #账号状态
    status_condition = 0
    if is_block == 1:
        status_condition = -1

    total_record = 0
    player_list = []
    player_list1 = []

    if 0 != post_back and server_id > 0:
        conn = getConn(server_id)
        cursor = conn.cursor()

        query = []
        query.append("status=%d" % status_condition)
        if channel_id > 0:
            query.append('channel_id=%d' % channel_id)

        if player_key != "":
            if key_type == '0':
                query.append('player_id in (%s)' % ','.join(player_keys))
            elif key_type == '1':
                query.append('player_name like \'%s%%\'' %
                             player_key.encode('utf-8'))
            elif key_type == '2':
                query.append('link_key=\'%s\'' % player_key)
            elif key_type == '3':
                query.append('mobile_key=\'%s\'' % player_key)
        if user_type > -1:
            query.append('user_type=%d' % player_key)

        if not request.admin.is_root:
            channel_count = request.admin.get_resource('channel').count()
            if request > 0:
                channel_list = request.admin.get_resource('channel')
                channel_id_list_query = ' channel_id in (%s) ' % ','.join(
                    [str(item.id) for item in channel_list])
                query.append(channel_id_list_query)

        if len(query) > 0:
            sql1 = 'select count(1) from player_%d where %s' % (
                server_id, ' and '.join(query))
            sql2 = 'select player_id,player_name,channel_id,user_type,link_key,login_num,mobile_key,last_time,create_time,status from player_%d where %s order by id desc limit %d,%d' % (
                server_id, ' and '.join(query),
                (page_num - 1) * page_size, page_size)
        else:
            sql1 = 'select count(1) from player_%d' % server_id
            sql2 = 'select player_id,player_name,channel_id,user_type,link_key,login_num,mobile_key,last_time,create_time,status from player_%d order by id desc limit %d,%d' % (
                server_id, (page_num - 1) * page_size, page_size)

        print(sql1, sql2)
        cursor.execute(sql1)
        count_list = cursor.fetchone()
        total_record = int(count_list[0])
        if total_record > 0:
            cursor.execute(sql2)
            player_list1 = cursor.fetchall()
        user_type_name = {
            0: '游爱',
            1: '当乐',
            2: 'UC',
            3: '91',
            4: '云游',
            5: '飞流',
            6: '乐逗',
            8: '小虎',
            9: '4399',
            10: 'facebook',
            11: 'qq'
        }
        for item in player_list1:
            item = list(item)
            item[2] = itemChannelList.get(int(item[2]), item[2])

            item[3] = user_type_name.get(int(item[3]), item[3])

            player_list.append(item)
        cursor.close()
    parg = {}
    parg["server_id"] = server_id
    parg["list_group"] = list_group
    parg["list_server"] = list_server
    parg["player_key"] = player_key
    parg["player_list"] = player_list
    parg["is_block"] = is_block
    parg['key_type'] = key_type
    parg["page_num"] = page_num
    parg["page_size"] = page_size
    parg["total_record"] = total_record
    group_servers_dict = get_group_servers_dict(request)
    agent_channels_dict = get_agent_channels_dict(request)
    return render_to_response('player/player_list.html', locals())