def group_edit(request, model_id=0): model_id = int(model_id) if model_id == 0: model_id = int(request.GET.get('model_id', '0')) model = None if model_id > 0: model = Group.objects.using('read').get(id=model_id) if model == None: model = Group() model.id = 0 list_server = get_server_list() if model.id > 0: list_server_selected = model.server.all() server_selected = {} for item in list_server_selected: server_selected[item.id] = 1 for item in list_server: item.is_show = server_selected.get(item.id, 0) list_notice = Notice.objects.using('read').filter(notice_type=3) parg = {} parg["model"] = model parg["list_server"] = list_server parg["list_notice"] = list_notice return render_to_response('server/group_edit.html', parg)
def pay_user_rank(request): server_id = int(request.GET.get('server_id', '0')) page_num = int(request.GET.get('page_num', '1')) sdate = request.GET.get('sdate', '') edate = request.GET.get('edate', '') err_msg = '' page_size = 30 list_server = get_server_list() if server_id < 1 and len(list_server) > 0: server_id = list_server[0].id query_date = '' try: if sdate != '': sdate = datetime.datetime.strptime( sdate, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') #%H:%M:%S query_date = ' a.last_time>=\'%s\'' % sdate if edate != '': if query_date != '': query_date += ' and ' edate = datetime.datetime.strptime( edate, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') query_date += ' a.last_time<\'%s\'' % edate except Exception, e: print('menu error:', e) sdate = '' edate = ''
def notice_list(request, notice_type=0): server_id = int(request.GET.get('server_id', 0)) usm = UserStateManager(request) the_user = usm.get_the_user() if the_user.id == 0: server_list = get_server_list() else: server_list = the_user.server.all() if server_list.__len__() == 0: server_list = get_server_list() else: if server_id <= 0: server_id = server_list[0].id if server_list.__len__() == 0: return HttpResponse("没有服务器可管理") if server_id > 0: if notice_type > 0: list_record = Notice.objects.using('read').filter( server=server_id, notice_type=notice_type) else: list_record = Notice.objects.using('read').filter(server=server_id) else: if notice_type > 0: list_record = Notice.objects.using('read').filter( notice_type=notice_type) else: list_record = Notice.objects.using('read').all() template_path = 'server/notice_list.html' if notice_type == 4: template_path = 'server/push_list.html' parg = {} parg["server_list"] = server_list parg["server_id"] = server_id parg["list_record"] = list_record parg["usm"] = usm return render_to_response(template_path, parg)
def log_server(request, log_id=0): if log_id > 0: log_def = LogDefine.objects.get(id=log_id) list_server = get_server_list() parg = {} parg["list_server"] = list_server parg["log_def"] = log_def return render_to_response('log/log_server.html', parg)
def statistic_list(request, log_type=0): list_model = [] log_type = int(log_type) if log_type == 0: log_type = int(request.GET.get('log_type', '0')) if log_type == 0: list_model = Statistic.objects.all() else: list_model = Statistic.objects.filter(log_type=log_type) server_id = int(request.GET.get('server_id', '0')) list_server = get_server_list() list_log = LogDefine.objects.using('read').all() logDefine_list = LogDefine.objects.using('read').all() logDefineIdName = {} ResultTimes = {} not_center_log_id_list = [] for logDefineItem in logDefine_list: logDefineIdName[logDefineItem.id] = logDefineItem.key if logDefineItem.status != ENUM_LOG_STATUS.SAVE_CENTER: not_center_log_id_list.append(logDefineItem.id) if server_id > 0: result_list = Result.objects.raw( 'select max(id) id,statistic_id,max(result_time) result_time from result where server_id=%d group by statistic_id' % server_id) else: result_list = Result.objects.raw( 'select max(id) id,statistic_id,max(result_time) result_time from result group by statistic_id' ) for item in result_list: ResultTimes[item.statistic_id] = item.result_time for item in list_model: item.log_typeName = logDefineIdName.get(item.log_type, 0) item.last_exec_time = ResultTimes.get(item.id, item.last_exec_time) #raise Exception, not_center_log_id_list.__contains__(item.log_type) if not_center_log_id_list.__contains__(item.log_type): item.is_center_log = False else: item.is_center_log = True parg = {} parg["log_type"] = log_type parg["list_server"] = list_server parg["list_log"] = list_log parg["list_model"] = list_model parg["server_id"] = server_id return render_to_response('log/statistic_list.html', parg)
def table_info(request): usm = UserStateManager(request) if not usm.current_userRole_is_root(): return HttpResponse('权限不足') log_id = int(request.GET.get('log_id', '0')) server_id = int(request.GET.get('server_id', '0')) if 0 == server_id: server_id = int(request.POST.get('server_id', '0')) log_list = [] if 0 == server_id: log_list = LogDefine.objects.filter( status=ENUM_LOG_STATUS.SAVE_CENTER).all() else: log_list = LogDefine.objects.filter( status=ENUM_LOG_STATUS.NORMAL).all() server_list = get_server_list() parg = {} if 0 != log_id and -1 != server_id: if 0 == LogDefine.objects.filter(id=log_id).count(): return HttpResponse('请选择日志表') log_def = None for item in log_list: if item.id == log_id: log_def = item if None == log_def: return HttpResponse('请选择日志表') query_sql = 'show index from log_%s' % log_def.key conn = conn_switch(server_id) cursor = conn.cursor() cursor.execute(query_sql) list_data = cursor.fetchall() #raise Exception, query_sql conn.close() parg['log_def'] = log_def parg['list_data'] = list_data parg['log_id'] = log_id parg['log_list'] = log_list parg['server_list'] = server_list parg['server_id'] = server_id return render_to_response('log/table_info.html', parg)
def group_ajax(request): group = int(request.POST.get('group', '0')) option_str = [] option_str.append('<option value="0">服务器</option>') if 0 != group: list_server = Group.objects.get(id=group).server.all() else: list_server = get_server_list() if len(list_server) != 0: for item in list_server: option_str.append('<option value="%s">%s</option>' % (item.id, item.name)) return HttpResponse(''.join(option_str))
def batch_statistic(request): statistic_id = int(request.GET.get('statistic_id')) if 0 == statistic_id: return HttpResponse('没有选择统计项') statistic = Statistic.objects.get(id=statistic_id) list_server = get_server_list() parg = {} parg['statistic'] = statistic parg['list_server'] = list_server return render_to_response('log/batch_statistic.html', parg)
def admin_edit(request, admin_id=0): admin_id = int(admin_id) if 0 == admin_id: admin_id = int( request.GET.get('admin_id', request.POST.get('admin_id', 0))) if admin_id > 0: model = Admin.objects.using('read').get(id=admin_id) model.password = '' else: model = Admin() model.id = admin_id roles = Role.objects.using('read').all() list_server = get_server_list() list_channel = center_cache.get_channel_list() item = [] if model.id > 0: #******设置服务器状态是否选中 *********** list_server_selected = model.server.all() server_selected = {} for item in list_server_selected: server_selected[item.id] = 1 for item in list_server: item.is_show = server_selected.get(item.id, 0) #******** 设置服务器状态 END ***************** #*******设置渠道 状态是否选中 *********** list_channel_selected = model.channel.all() channel_selected = {} for item in list_channel_selected: channel_selected[item.id] = 1 for item in list_channel: item.is_show = channel_selected.get(item.id, 0) #******** 设置渠道状态END *********** parg = {} parg["item"] = item parg["roles"] = roles parg["list_server"] = list_server parg["list_channel"] = list_channel parg["model"] = model return render_to_response('system/admin_edit.html', parg)
def kingarena_info(request): list_infos = [] list_server = get_server_list() is_search = request.GET.get('is_search', False) server_id = int(request.GET.get('server_id', '0')) err_msg = None if is_search: req_params = 'req_type=505&server_id=%d' % server_id result = '' try: result = http_post(game_server_url.GM_SERVER_URL, req_params, timeout_param=10) result = json.loads(result) except: err_msg = '获取失败!' if result != '' and result != None and err_msg == None: if result['code'] == '0' or result['code'] == 0: country_json = result.get("content")[0] position_param = get_kingarena_position_param(); player_dic = get_kingarena_player_param(); for country in country_json: position_array = [] for p_key in position_param: cname = position_param.get(p_key) value = u"没有数据" player_json = country.get(p_key) if player_json != None and player_json != '': player_attribute = get_king_player_attribute(player_json, player_dic) value = ','.join(player_attribute) tmp = "%s: %s" % (cname, value) position_array.append(tmp) list_infos.append(position_array) parg = {} parg["list_infos"] = list_infos parg["list_server"] = list_server parg["server_id"] = server_id parg["err_msg"] = err_msg return render_to_response('game/kingarena_info.html', parg)
def batch_list(request): #usm = UserStateManager(request) #list_group = [] #if usm.current_userRole_is_root(): list_group = Group.objects.all() query = ['1=1'] status = int(request.GET.get('status', '1')) query.append(' and status = %d ' % status) page_size = 15 page_num = int(request.GET.get('page_num', '1')) if page_num < 1: page_num = 1 search_card = int(request.GET.get('search_card', '0')) search_card_val = request.GET.get('search_card_val', '') server_id = int(request.GET.get('server_id', '0')) group = int(request.GET.get('group', '0')) if 0 != group: try: list_server = Group.objects.get(id=group).server.all() except: list_server = None pass else: list_server = get_server_list() card_batch = None if status == 1: query.append(" and end_time >= '%s'" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) elif status == 0: query.append(" or end_time < '%s'" % (datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) if search_card != 0 and search_card_val != '': if search_card == 1: query.append(" and `key` = '%s'" % search_card_val) elif search_card == 2: query.append(" and `name` like '%s%s%s'" % ('%%', search_card_val, '%%')) if server_id != 0: query.append(" and `server` REGEXP '^%d$|,%d|%d,' " % (server_id, server_id, server_id)) elif group != 0: query_server_id = [] for item in list_server: query_server_id.append("`server` REGEXP '^%d$|,%d|%d,' " % (item.id, item.id, item.id)) if len(query_server_id) != 0: query.append(" and (%s) " % (' or '.join(query_server_id))) else: query.append(" and 0 ") #return HttpResponse(''.join(query)) total_record = CardBatch.objects.using('card').extra( where=[''.join(query)]).count() if total_record: card_batch = CardBatch.objects.using('card').extra( where=[''.join(query)])[(page_num - 1) * page_size:page_num * page_size] for item in card_batch: item.prize_content = item.get_prize_content() item.server_content = item.get_server_content() item.channel_content = item.get_channel_content() item.expire = 0 if item.end_time < datetime.datetime.now(): item.expire = 1 if item.used_count == item.total_count: item.rate = 100 else: item.rate = round( float(item.used_count) * 100 / item.total_count, 2) parg = {} parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record parg["batch"] = card_batch parg['status'] = status parg['list_server'] = list_server parg['server_id'] = server_id parg['search_card'] = search_card parg['search_card_val'] = search_card_val parg['list_group'] = list_group parg['group'] = group return render_to_response('card/batch_list.html', parg)
def batch_edit(request): tmp_group_id = request.GET.get('group_id', 0) model_id = request.GET.get('id', 0) group_id = 0 try: group_id = int(tmp_group_id) except: pass usm = UserStateManager(request) the_user = usm.get_the_user() if usm.current_userRole_is_root(): list_channel = Channel.objects.using('read').all().order_by("-logins") else: list_channel = the_user.channel.all().order_by("-logins") # # for item1 in list_channel: # if query_channel.__len__() > 0: # if str(item1.id) in query_channel: # item1.is_show = 1 # else: # item1.is_show = 1 list_group = [] if usm.current_userRole_is_root(): list_group = Group.objects.all() if 0 != group_id: list_server = Group.objects.get(id=group_id).server.all() else: list_server = get_server_list() else: list_server = the_user.server.all().order_by("id") # query_server = request.GET.getlist('s')#server_id # query_channel = request.GET.getlist('c')#server_id # # for serverItem in list_server: # if len(query_server) > 0: # if str(serverItem.id) in query_server: # serverItem.is_show = 1 # else: # serverItem.is_show = 1 ## ## for channelItem in list_channel: ## if len(query_channel) > 0: ## if str(channelItem.id) in query_channel: ## channelItem.is_show = 1 ## else: ## channelItem.is_show = 1 query_server = [] query_channel = [] model_id = int(model_id) prize = '[[1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [6, 0], [7, 0], [8, 0], [9, 0]]' the_key = '' if model_id > 0: model = CardBatch.objects.using('card').get(id=model_id) query_server = model.server.split(',') query_channel = model.channels.split(',') prize = model.prize else: try: conn = connections['card'] cursor = conn.cursor() sql = "SELECT SUBSTR(`table_name`,6) + 1 FROM INFORMATION_SCHEMA.`TABLES` WHERE `table_schema` = 'card' AND `table_name` NOT LIKE 'card_9%%' AND `table_name` REGEXP 'card_[[:digit:]]{4}$' ORDER BY `table_name` DESC LIMIT 1" cursor.execute(sql) count = cursor.fetchone() the_key = int(count[0]) except: pass now = datetime.datetime.now() model = CardBatch() model.id = model_id model.limit_count = 1 if not the_key: model.key = 1000 elif the_key < 9999 and the_key > 1000: model.key = the_key model.start_time = now.strftime("%Y-%m-%d 00:00:00") model.end_time = ( now + datetime.timedelta(days=90)).strftime("%Y-%m-%d 00:00:00") prize_help = {} for item in re.findall("\[(\d+,\s*\d+)\]", prize): prize_help[item.split(',')[0].strip(' ')] = item.split(',')[1].strip( ' ') for serverItem in list_server: if len(query_server) > 0: if str(serverItem.id) in query_server: serverItem.is_show = 1 else: serverItem.is_show = 1 for channelItem in list_channel: if len(query_channel) > 0: if str(channelItem.key) in query_channel: channelItem.is_show = 1 else: channelItem.is_show = 1 parg = {} parg["usm"] = usm parg["model"] = model parg["list_server"] = list_server parg["list_channel"] = list_channel parg["prize"] = prize parg["prize_help"] = prize_help parg["list_group"] = list_group parg["group_id"] = group_id parg["the_key"] = the_key return render_to_response('card/batch_edit.html', parg)
def result_analyse(request, query_id=0, show_type='list'): query_id = int(query_id) base_group_id = int(request.GET.get('base_group_id', 0)) op_group_id = int(request.GET.get('op_group_id', 0)) query_statistic_item = request.GET.getlist('f') query_item = request.GET.get('query_item', 0) select_op = request.GET.get("select_op","") query_channel = request.GET.getlist('c')#channel_id usm = UserStateManager(request) the_user = usm.get_the_user() query_channel_1 = '' query_channel_2 = '' channel_1 = int(request.GET.get('channel_1', 0)) channel_2 = int(request.GET.get('channel_2', 0)) if channel_1: query_channel_1 = ' and channel_id = %d ' % channel_1 if channel_2: query_channel_2 = ' and channel_id = %d ' % channel_2 if usm.current_userRole_is_root(): list_channel = center_cache.get_channel_list() else: list_channel = center_cache.get_user_channel_list(the_user) for item1 in list_channel: if query_channel.__len__() > 0: if str(item1.id) in query_channel: item1.is_show = 1 else: item1.is_show = 1 query_server1 = request.GET.getlist('s1')#server_id query_server2 = request.GET.getlist('s2')#server_id base_server = request.GET.get('base_server','') op_server = request.GET.get('op_server','') if not base_server: if query_server1.__len__() > 0: base_server = ','.join(query_server1) elif not query_server1: query_server1 = base_server.split(',') elif query_server1: base_server = ','.join(query_server1) if not op_server: if query_server2.__len__() > 0: op_server = ','.join(query_server2) elif not query_server2: query_server2 = op_server.split(',') elif query_server2: op_server = ','.join(query_server2) the_query = QueryResult.objects.get(id=query_id) list_statistic = the_query.statistic.all() list_statistic_sort = get_statistic_in_query(query_id)#获取根据关联表ip排序的数据 join_results = [] list_statistic_name = [] exec_interval = 0 statistic_results = [] canSelectServer = True item_results = [] for item in list_statistic_sort: statistic_results.append(str(item[0])) join_results.append([str(item[0]),item[1]])#id item_results.append(int(item[0])) for item3 in join_results: if query_statistic_item.__len__() > 0: query_item = ','.join(query_statistic_item) if str(item3[0]) in query_statistic_item: item3.append(1) list_statistic_name.append(item3[1]) else: if query_item: query_statistic_item = query_item.split(',') item3.append(1) list_statistic_name.append(item3[1]) list_group = [] if usm.current_userRole_is_root(): list_group = Group.objects.all() if 0 != base_group_id: list_server_base = Group.objects.get(id = base_group_id).server.all() else: list_server_base = get_server_list() if 0 != op_group_id: list_server_op = Group.objects.get(id = op_group_id).server.all() else: list_server_op = get_server_list() else: list_server_base = the_user.server.all().order_by("id") list_server_op = the_user.server.all().order_by("id") #if canSelectServer: for serverItem in list_server_base: if len(query_server1) > 0: if str(serverItem.id) in query_server1: serverItem.is_show = 1 else: serverItem.is_show = 1 for serverItem in list_server_op: if len(query_server2) > 0: if str(serverItem.id) in query_server2: serverItem.is_show = 1 else: serverItem.is_show = 1 the_date = datetime.datetime.now() sdate = request.GET.get('sdate', the_date.strftime('%Y-%m-1')) edate = request.GET.get('edate', the_date.strftime('%Y-%m-%d')) # print(sdate,edate) query_date = '' try: if sdate != '': sdate = datetime.datetime.strptime(sdate, '%Y-%m-%d').strftime('%Y-%m-%d')# %H:%M:%S query_date = ' and result_time>=\'%s\'' % sdate if edate != '': if query_date != '': query_date += ' and ' edate = datetime.datetime.strptime(edate, '%Y-%m-%d').strftime('%Y-%m-%d') query_date += ' result_time<=\'%s\'' % edate except: sdate = '' edate = '' if query_channel.__len__() == 0 and not usm.current_userRole_is_root(): query_channel = [] for item in list_channel: query_channel.append(str(item.id)) if query_server1.__len__() == 0 and not usm.current_userRole_is_root(): query_server1 = [] for item in list_server_base: query_server1.append(str(item.id)) if query_server2.__len__() == 0 and not usm.current_userRole_is_root(): query_server2 = [] for item in list_server_op: query_server2.append(str(item.id)) # query_channel_str = '' # if query_channel.__len__() > 0 : # query_channel_str = ' and channel_id in (%s)' % (','.join(query_channel)) # query_server_str1 = '' query_server_str2 = '' if query_server1.__len__() > 0 : query_server_str1 = ' and server_id in (%s)' % (','.join(query_server1)) if query_server2.__len__() > 0 : query_server_str2 = ' and server_id in (%s)' % (','.join(query_server2)) page_size = int(request.GET.get('page_size',15)) page_num = int(request.GET.get('page_num', '1')) if page_num < 1: page_num = 1 spos = (page_num - 1) * page_size if query_statistic_item.__len__() == 1: count_statistic = ''.join(query_statistic_item) elif query_statistic_item.__len__() > 1: count_statistic = ','.join(query_statistic_item) else: count_statistic = ','.join(statistic_results) date_format = '%%Y-%%m-%%d' chart_format = '%Y-%m-%d' def_date = request.GET.get("def_date","") minTickSize = [1,"day"] if def_date == 'day': pass elif def_date == 'month': date_format = '%%Y-%%m' chart_format = '%Y-%m' minTickSize = [1,"month"] elif def_date == 'year': date_format = '%%Y' chart_format = '%Y' minTickSize = [1,"year"] cursor = connection.cursor() select_str1 = 'DATE_FORMAT(result_time,"%s") AS `date`'% date_format select_str2 = 'DATE_FORMAT(result_time,"%s") AS `date`'% date_format select_str12 = 'a.`date`' for item in query_statistic_item: select_str1 += ',sum(case when `statistic_id`=%s then result else 0 end) item%s' % (item, item) select_str2 += ',sum(case when `statistic_id`=%s then result else 0 end) item%s' % (item, item) select_str12 += ',(a.`item%s`-b.`item%s`) item%s' % (item,item,item) if select_op == '0': query_sql1 = 'select %s from result where statistic_id in(%s)%s%s group by `date` ORDER BY `date` DESC ' % (select_str1, count_statistic, query_server_str1, query_date) query_sql2 = 'select %s from result where statistic_id in(%s)%s%s group by `date` ORDER BY `date` DESC ' % (select_str2, count_statistic, query_server_str2, query_date) else: query_sql1 = 'select %s from result where statistic_id in(%s)%s%s group by `date` ORDER BY `date` DESC ' % (select_str1, count_statistic, query_channel_1, query_date) query_sql2 = 'select %s from result where statistic_id in(%s)%s%s group by `date` ORDER BY `date` DESC ' % (select_str2, count_statistic, query_channel_2, query_date) query_sql = 'SELECT %s from (%s) a join (%s) b ON a.`date` = b.`date`'%(select_str12,query_sql1,query_sql2) count_sql = 'select count(*) result from (%s) newTable WHERE 1 %s' % (query_sql, '') cursor.execute(count_sql) total_record = int(cursor.fetchone()[0]) list_record = [] if total_record > 0: query_sql = query_sql + ' ' + 'LIMIT %s,%s'%(spos,page_size) cursor.execute(query_sql) list_record = cursor.fetchall() #cursor.close() # print(total_record,query_sql) if show_type == 'list': template = 'log/result_analyse.html' else: template = 'log/result_query_chart.html' list_record_arr = {} i = 1 tmp_item = [] for item_result in join_results: if item_result[0] in query_statistic_item: tmp_item = [] for item in list_record: item = list(item) item[0] = int(time.mktime(datetime.datetime.strptime(str(item[0]),"%s"%chart_format).timetuple())) * 1000; tmp_item.append([item[0],int(item[i])]) list_record_arr[item_result[1]] = tmp_item i = i+1 for key,val in list_record_arr.items(): list_record_arr[key] = sorted(val) list_record_arr = str(list_record_arr).replace('(', '[').replace(')', ']').replace('L', '') list_record_arr = str(list_record_arr).replace('u\'', '\'') time_slot = 86400000 if def_date == 'day': d1 = datetime.datetime(int(sdate.split("-")[0]),int(sdate.split("-")[1]),int(sdate.split("-")[2])) d2 = datetime.datetime(int(edate.split("-")[0]),int(edate.split("-")[1]),int(edate.split("-")[2])) days = ( d2 - d1).days +1 time_slot = Result().cmp_time(days) elif def_date == 'month': time_slot = 86400000 * 30 elif def_date == 'year': time_slot = 86400000 * 30 * 12 #处理 导出文件 exprot = int(request.GET.get('exprot', '0')) close_export = int(request.GET.get('close_export', '0')) clear_export_old_file = int(request.GET.get('clear_export_old_file', '0')) if 0< exprot: query_exprot = QueryExprot() file_name = ''.join(query_statistic_item) file_name = file_name+'___'+sdate.replace('-','').replace(':','')+'___'+edate.replace('-','').replace(':','') #session ID session_id = request.COOKIES.get('sessionid') return query_exprot.gene_file(list_record, [u'时间']+list_statistic_name, file_name, page_num, page_size, total_record, exprot, close_export, clear_export_old_file, session_id) parg = {} parg["usm"] = usm parg["query_id"] = query_id parg["list_statistic"] = list_statistic parg["list_group"] = list_group parg["base_group_id"] = base_group_id parg["op_group_id"] = op_group_id parg["list_server_base"] = list_server_base parg["list_server_op"] = list_server_op parg["list_channel"] = list_channel parg["base_server"] = base_server parg["op_server"] = op_server parg["sdate"] = sdate parg["edate"] = edate parg["list_statistic_sort"] = list_statistic_sort parg["list_record"] = list_record parg["exec_interval"] = exec_interval parg["list_record_arr"] = list_record_arr parg["list_statistic_name"] = list_statistic_name parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record parg["select_op"] = select_op parg["canSelectServer"] = canSelectServer parg["channel_1"] = channel_1 parg["channel_2"] = channel_2 parg["def_date"] = def_date parg["minTickSize"] = minTickSize parg["join_results"] = join_results parg["time_slot"] = time_slot parg["chart_format"] = chart_format parg["query_item"] = query_item return render_to_response(template, parg)
def result_query(request, query_id=0, show_type='list'): query_id = int(query_id) tmp_group_id = request.GET.get('group_id', 0) group_id = 0 try: group_id = int(tmp_group_id) except: pass query_channel = request.GET.getlist('c')#channel_id usm = UserStateManager(request) the_user = usm.get_the_user() if usm.current_userRole_is_root(): list_channel = center_cache.get_channel_list() else: list_channel = center_cache.get_user_channel_list(the_user) for item1 in list_channel: if query_channel.__len__() > 0: if str(item1.id) in query_channel: item1.is_show = 1 else: item1.is_show = 1 query_server = request.GET.getlist('s')#server_id the_query = QueryResult.objects.get(id=query_id) list_statistic = the_query.statistic.all() list_statistic_sort = get_statistic_in_query(query_id)#获取根据关联表ip排序的数据 join_results = [] list_statistic_name = [] exec_interval = 0 item_results = [] for item in list_statistic_sort: exec_interval = item[2]#exec_interval join_results.append(str(item[0]))#id item_results.append([item[0], item[1]]) #处理统计数据 list_group = [] if usm.current_userRole_is_root(): list_group = Group.objects.all() if 0 != group_id: list_server = Group.objects.get(id = group_id).server.all() else: list_server = get_server_list() else: list_server = the_user.server.all().order_by("id") #if canSelectServer: for serverItem in list_server: if len(query_server) > 0: if str(serverItem.id) in query_server: serverItem.is_show = 1 else: serverItem.is_show = 1 sdate = request.GET.get('sdate', '') edate = request.GET.get('edate', '') # print(sdate,edate) if query_channel.__len__() == 0 and not usm.current_userRole_is_root(): query_channel = [] for item in list_channel: query_channel.append(str(item.id)) if query_server.__len__() == 0 and not usm.current_userRole_is_root(): query_server = [] for item in list_server: query_server.append(str(item.id)) query_channel_str = '' if query_channel.__len__() > 0 : query_channel_str = ' and channel_id in (%s)' % (','.join(query_channel)) query_server_str = '' if query_server.__len__() > 0 : query_server_str = ' and server_id in (%s)' % (','.join(query_server)) page_size = 20 page_num = int(request.GET.get('page_num', '1')) if page_num < 1: page_num = 1 spos = (page_num - 1) * page_size date_format = '%%Y-%%m-%%d' chart_format = '%Y-%m-%d' time_slot = 86400000 charts_type = 'spline' def_date = request.GET.get("def_date","") now = datetime.datetime.now() if sdate and edate: d1 = datetime.datetime(int(sdate.split("-")[0]),int(sdate.split("-")[1]),int(sdate.split("-")[2])) d2 = datetime.datetime(int(edate.split("-")[0]),int(edate.split("-")[1]),int(edate.split("-")[2])) days = ( d2 - d1).days + 1 if days == 1: charts_type = 'column' time_slot = Result().cmp_time(days) else: sdate = now.strftime('%Y-%m-01') edate = now.strftime('%Y-%m-%d') if def_date == 'day': pass elif def_date == 'month': date_format = '%%Y-%%m' chart_format = '%Y-%m' time_slot = 30 * 86400000 elif def_date == 'year': date_format = '%%Y' chart_format = '%Y' time_slot = 12 * 30 * 86400000 edate = datetime.datetime.strptime(edate, '%Y-%m-%d') edate = edate + datetime.timedelta(days=1) sdate = datetime.datetime.strptime(sdate, '%Y-%m-%d') query_date = ' AND `result_time` >= \'%s\' AND `result_time` < \'%s\''%(sdate, edate) cursor = connection.cursor() count_sql = 'select count(distinct DATE_FORMAT(result_time,"%s")) result from result where statistic_id in(%s)%s%s%s' % (date_format,','.join(join_results), query_server_str, query_channel_str, query_date) cursor.execute(count_sql) total_record = int(cursor.fetchone()[0]) list_record = [] if total_record > 0: select_str = 'DATE_FORMAT(result_time,"%s") AS `date`'% date_format for item in join_results: select_str += ',sum(case when `statistic_id`=%s then result else 0 end) item%s' % (item, item) query_sql = 'select %s from result where statistic_id in(%s)%s%s%s group by `date` order by `date` DESC limit %d,%d' % (select_str, ','.join(join_results), query_server_str, query_channel_str, query_date, spos, page_size) print(query_sql) cursor.execute(query_sql) list_record = cursor.fetchall() #cursor.close() #print total_record #print '------------------' #print query_sql if show_type == 'list': template = 'log/result_query.html' else: template = 'log/result_query_chart.html' list_record_arr = {} i = 1 tmp_item = [] for item_result in item_results: tmp_item = [] for item in list_record: item = list(item) item[0] = int(time.mktime(datetime.datetime.strptime(str(item[0]),"%s"%chart_format).timetuple())) * 1000; tmp_item.append([item[0],int(item[i])]) list_record_arr[item_result[1]] = tmp_item i = i+1 for key,val in list_record_arr.items(): list_record_arr[key] = sorted(val) list_record_arr = str(list_record_arr).replace('(', '[').replace(')', ']').replace('L', '') list_record_arr = str(list_record_arr).replace('u\'', '\'') list_statistic_name = str(list_statistic_name).replace('u\'', '\'') parg = {} parg["usm"] = usm parg["query_id"] = query_id parg["list_statistic"] = list_statistic parg["list_group"] = list_group parg["group_id"] = group_id parg["list_server"] = list_server parg["list_channel"] = list_channel parg["sdate"] = sdate.strftime('%Y-%m-%d') edate = edate - datetime.timedelta(days = - 1) parg["edate"] = edate.strftime('%Y-%m-%d') parg["list_statistic_sort"] = list_statistic_sort parg["list_record"] = list_record parg["exec_interval"] = exec_interval parg["list_record_arr"] = list_record_arr parg["list_statistic_name"] = list_statistic_name if query_channel.__len__() == 1: parg["channel_id"] = int(query_channel[0]) parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record parg["def_date"] = def_date parg["time_slot"] = time_slot parg["charts_type"] = charts_type parg["chart_format"] = chart_format return render_to_response(template, parg)
def result_list(request, statistic_id=0, show_type='list'): statistic_id = int(statistic_id) if 0 == statistic_id: statistic_id = int(request.GET.get('id', request.POST.get('id', 0))) statistic_type = 0#int(statistic_type) the_date = datetime.datetime.now() sdate = request.GET.get('sdate', the_date.strftime('%Y-%m-1')) edate = request.GET.get('edate', the_date.strftime('%Y-%m-%d')) query_channel = request.GET.getlist('c')#channel_id query_server = request.GET.getlist('s')#server_id list_record = [] usm = UserStateManager(request) the_user = usm.get_the_user() statistic = None if statistic_id > 0: statistic = Statistic.objects.get(id=statistic_id) log_def = LogDefine.objects.get(id = statistic.log_type) if statistic == None or log_def == None: return HttpResponseRedirect('/statistic/list') canSelectServer = True #if the_log_in_center(log_def): #check_user #canSelectServer = False if usm.current_userRole_is_root(): list_server = get_server_list() else: list_server = the_user.server.all().order_by("id") if canSelectServer: for serverItem in list_server: if len(query_server) > 0: if str(serverItem.id) in query_server: serverItem.is_show = 1 else: serverItem.is_show = 1 if usm.current_userRole_is_root(): list_channel = center_cache.get_channel_list() else: list_channel = center_cache.get_user_channel_list(the_user) #新增激活特殊处理, 因为新增激活没有服务器id if statistic_id != 1: if query_server.__len__() <= 0: query_server = [] for item in list_server: query_server.append(str(item.id)) channel_condition = True if query_channel.__len__() == 0: query_channel = [] for item in list_channel: query_channel.append(str(item.id)) for item1 in list_channel: if len(query_channel) > 0: if str(item1.id) in query_channel: item1.is_show = 1 else: item1.is_show = 0#取消默认全选 -zhenwei 2012-10-24 query_date = '' try: if sdate != '': sdate = datetime.datetime.strptime(sdate, '%Y-%m-%d').strftime('%Y-%m-%d') query_date = ' and result_time>=\'%s\'' % sdate if edate != '': if query_date != '': query_date += ' and ' edate = datetime.datetime.strptime(edate, '%Y-%m-%d').strftime('%Y-%m-%d')# %H:%M:%S query_date += ' result_time<=\'%s\'' % edate except: sdate = '' edate = '' query_channel_str = '' server_condition = True if (usm.user_server_count() == 0 or usm.is_Administrator(the_user)) and (list_server.__len__() == query_server.__len__()): server_condition = False if statistic_id == 1:#新增激活特殊处理,不筛选服务器 server_condition = False if (usm.user_channel_count() == 0 or usm.is_Administrator(the_user)) and (list_channel.__len__() == query_channel.__len__()): channel_condition = False if channel_condition: query_channel_str = ' and channel_id in (%s)' % (','.join(query_channel)) query_server_str = '' if server_condition: query_server_str = ' and server_id in (%s)' % (','.join(query_server)) page_size = 20 page_num = int(request.GET.get('page_num', '1')) if page_num < 1: page_num = 1 spos = (page_num - 1) * page_size statistic_types = [{'id':0, 'name':'默认统计', 'key':''}, {'id':1, 'name':'按小时', 'key':'hour'}, {'id':2, 'name':'按星期', 'key':'week'}, {'id':3, 'name':'按日数', 'key':'day'}, {'id':4, 'name':'按月数', 'key':'month'}, {'id':5, 'name':'按季度', 'key':'quarter'}]#{'id':5,'name':'按年份','key':'year'} statistic_type_str = statistic_types[statistic_type]['key'] list_statistic = Statistic.objects.using('read').filter(log_type=statistic.log_type) cursor = connection.cursor() count_sql = 'select count(distinct result_time) as result from result where statistic_id=%s%s%s%s' % (statistic_id, query_server_str, query_channel_str, query_date) cursor.execute(count_sql) total_record = int(cursor.fetchone()[0]) #raise Exception, count_sql #cursor.close() list_record_arr = {} if total_record > 0 : list_record = Result.objects.raw('select id,statistic_id,result_time,sum(result) result from result where statistic_id=%s%s%s%s group by result_time ORDER BY result_time DESC limit %d,%d' % (statistic_id, query_server_str, query_channel_str, query_date, spos, page_size)) tmp_item = [] temp = 0 for item in list_record: temp = int(time.mktime(datetime.datetime.strptime(str(item.result_time),"%s"%'%Y-%m-%d %H:%M:%S').timetuple())) * 1000; tmp_item.append([temp,int(item.result)]) list_record_arr[statistic.name] = tmp_item for key,val in list_record_arr.items(): list_record_arr[key] = sorted(val) list_record_arr = str(list_record_arr).replace('(', '[').replace(')', ']').replace('L', '') list_record_arr = str(list_record_arr).replace('u\'', '\'') if show_type == 'list': template = 'log/result_list.html' else: template = 'log/result_chart.html' parg = {} parg["statistic"] = statistic parg["usm"] = usm parg["statistic_id"] = statistic_id parg["list_statistic"] = list_statistic parg["canSelectServer"] = canSelectServer parg["list_server"] = list_server parg["list_channel"] = list_channel parg["sdate"] = sdate parg["edate"] = edate parg["statistic_type"] = statistic_type parg["list_record"] = list_record parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record parg["list_record_arr"] = list_record_arr if query_channel.__len__() == 1: parg["channel_id"] = int(query_channel[0]) return render_to_response(template, parg)
def card_log_list(request): exprot = int(request.GET.get('exprot', '0')) close_export = int(request.GET.get('close_export', '0')) clear_export_old_file = int(request.GET.get('clear_export_old_file', '0')) msg = '' batch_id = int(request.GET.get('batch_id', '0')) page_num = int(request.GET.get('page_num', '1')) if page_num < 1: page_num = 1 page_size = 15 if exprot > 0: page_size = 500 list_data = [] search_type = int(request.GET.get('search_type', '0')) search_val = request.GET.get('search_val', '') status = request.GET.get('status', '') now = datetime.datetime.now() sdate = request.GET.get('start_date', now.strftime("%Y-%m-01 00:00:00")) edate = request.GET.get('end_date', now.strftime("%Y-%m-%d %H:%M:%S")) query = ['1=1'] total_record = 0 group = int(request.GET.get('group', '0')) list_group = Group.objects.all() if 0 != group: try: list_server = Group.objects.get(id=group).server.all() except: list_server = None pass else: list_server = get_server_list() server_id = int(request.GET.get('server_id', '0')) if batch_id > 0: query.append(" and card_key = '%s'" % batch_id) try: if search_type != 0 and search_val != '': if search_type == 1: query.append(" and `number` = '%s'" % search_val) elif search_type == 2: query.append(" and `player_id` = '%s'" % search_val) elif search_type == 3: query.append(" and `card_key` = '%s'" % search_val) elif search_type == 4: query.append(" and `id` = %d " % int(search_val)) elif search_type == 5: query.append(" and `card_name` like '%s%s%s'" % ('%%', search_val, '%%')) # elif search_type == 3: # query.append(" and password = '******'"%search_val) if status != '': query.append(" and `status` = %d " % int(status)) if sdate != '' and edate != '': query.append( " AND `create_time` >= '%s' AND `create_time` <= '%s'" % (sdate, edate)) if server_id != 0: query.append(" and server_id = %d " % server_id) elif group != 0: query_server_id = [] for server_item in list_server: query_server_id.append(int(server_item.id)) if len(query_server_id) != 0: query_server_id = tuple(query_server_id) query.append(" and `server_id` in %s " % str(query_server_id)) else: query.append(" and 0 ") total_record = CardLog.objects.using('card').extra( where=[''.join(query)]).count() if total_record > 0: list_data = CardLog.objects.using('card').extra( where=[''.join(query)]).order_by('-id')[(page_num - 1) * page_size:page_num * page_size] for item in list_data: item.server = '' if item.server_id: the_server = Server.objects.get(id=item.server_id) if the_server: item.server = the_server.name #处理 导出文件 if 0 < exprot: export_data = [] fields = [ u'礼包ID', u'礼包卡名', u'礼包卡号', u'礼包卡标识', u'使用时间', u'奖励内容', u'角色ID', u'服务器', u'奖励状态' ] try: for item in list_data: export_data.append([ item.id, item.card_name, item.number, item.card_key, item.create_time_str(), item.get_prize_content(), item.player_id, item.server_name(), item.get_status_name() ]) except Exception, e: print 'error', e query_exprot = QueryExprot() #session ID session_id = request.COOKIES.get('sessionid') pre_file_name = '' if search_val != '': pre_file_name = '%s%s_' % (pre_file_name, search_val) if group != 0: try: pre_file_name = '%s%s_' % ( pre_file_name, Group.objects.get(id=group).name) except: pass if server_id != 0: try: pre_file_name = '%s%s_' % ( pre_file_name, Server.objects.get(id=server_id).name) except: pass file_name = '%s%s_%s___%s' % (pre_file_name, sdate.replace( "-", "").replace(":", "").replace( " ", ""), edate.replace("-", "").replace(":", "").replace( " ", ""), session_id) return query_exprot.gene_file(export_data, fields, file_name, page_num, page_size, total_record, exprot, close_export, clear_export_old_file, session_id) except Exception, e: print('search CardLog error:', e) msg = '%s' % e
def notice_edit(request, model_id=0, notice_type=0): model_id = int(model_id) if model_id == 0: model_id = int(request.GET.get('notice_id', '0')) model = None if model_id > 0: model = Notice.objects.using('write').get(id=model_id) notice_type = model.notice_type if model == None: model = Notice() model.id = 0 if model.size == None: model.size = '' # channel_list = Channel.objects.all() # if model.id>0: # for item in channel_list: # if len(model.channel.filter(id=item.id))>0: # item.is_show=1 # else: # item.is_show=0 the_user_id = int(request.session.get('userid', '0')) the_user = Admin.objects.using('write').get(id=the_user_id) list_server = [] list_group = [] list_channel = [] if notice_type == 4: list_group = Group.objects.using('write').all() if model.id > 0: list_group_selected = model.group.all() group_selected = {} for item in list_group_selected: group_selected[item.id] = 1 for item in list_group: item.is_show = group_selected.get(item.id, 0) else: if the_user == 0: list_server = get_server_list() else: list_server = the_user.server.all() if list_server.__len__() == 0: list_server = get_server_list() if model.id > 0: list_server_selected = model.server.all() server_selected = {} for item in list_server_selected: server_selected[item.id] = 1 for item in list_server: item.is_show = server_selected.get(item.id, 0) list_channel = center_cache.get_channel_list() list_channel_selected = model.channel.all() channel_selected = {} for item in list_channel_selected: channel_selected[item.id] = 1 for item in list_channel: item.is_show = channel_selected.get(item.id, 0) template_path = 'server/notice_edit.html' if notice_type == 4: template_path = 'server/push_edit.html' parg = {} parg["notice_type"] = notice_type parg["model"] = model parg["list_server"] = list_server parg["list_group"] = list_group parg["list_channel"] = list_channel return render_to_response(template_path, parg)
def pay_server_paychannel(request): query_server = request.POST.getlist('s') #server_id query_paychannel = request.POST.getlist('c') page_num = int(request.GET.get("page_num", "1")) sdate = request.POST.get('sdate', '') edate = request.POST.get('edate', '') page_size = 50 query_where = " and a.pay_status=4" try: if sdate != "": sdate = datetime.datetime.strptime( sdate, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S") query_where += " and a.last_time>='%s'" % sdate if edate != "": edate = datetime.datetime.strptime( edate, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S") query_where += " and a.last_time<='%s'" % edate except: sdate = "" edate = "" list_server = get_server_list() for serverItem in list_server: if len(query_server) > 0: if str(serverItem.id) in query_server: serverItem.is_show = 1 else: serverItem.is_show = 1 list_paychannel = PayChannel.objects.all().order_by("id") for pcItem in list_paychannel: if len(query_paychannel) > 0: if str(pcItem.id) in query_paychannel: pcItem.is_show = 1 else: pcItem.is_show = 0 else: pcItem.is_show = 1 if len(query_server) > 0 and len(query_server) != len(list_server): query_where += " and a.server_id in (%s)" % (','.join(query_server)) if len(query_paychannel) > 0 and len(query_paychannel) != len( list_paychannel): query_where += " and a.pay_type in (%s)" % (','.join(query_paychannel)) query_sql = "SELECT (SELECT `name` FROM servers WHERE `id`=a.server_id),\ `name`,DATE(a.last_time),COUNT(DISTINCT pay_user),COUNT(pay_user),\ SUM(pay_amount),SUM(pay_gold),SUM(pay_amount)/COUNT(DISTINCT pay_user)\ FROM pay_action a,pay_channel b WHERE a.pay_type=b.id %s\ GROUP BY a.server_id,a.pay_type,DATE(a.last_time)\ ORDER BY a.server_id,a.pay_type,DATE(a.last_time)" % query_where query_count = "select count(*) from (%s) newTable" % query_sql query_limit = " limit %d,%d" % ((page_num - 1) * page_size, page_size) query_sql += query_limit print "pay_server_paychannel" print query_count print query_sql cursor = connection.cursor() cursor.execute(query_count) total_record = int(cursor.fetchone()[0]) list_pay = [] if total_record > 0: cursor.execute(query_sql) list_pay = cursor.fetchall() parg = {} parg["list_server"] = list_server parg["list_paychannel"] = list_paychannel parg["sdate"] = sdate parg["edate"] = edate parg["list_pay"] = list_pay parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record return render_to_response("pay/pay_server_paychannel.html", parg)
def pay_result_list(request, table_name=''): page_size = 50 page_num = int(request.GET.get('page_num', '1')) key = request.GET.get('key', '') pay_type = int(request.GET.get('pay_type', '0')) server_id = int(request.GET.get('server_id', '0')) key_type = int(request.GET.get('key_type', '0')) #**支付通道列表 *** payChannel_record = {} payChannel_list = PayChannel.objects.all() for payChannel in payChannel_list: payChannel_record[payChannel.id] = payChannel.name #***支付通道列表 END list_record = [] pay_status = int(request.GET.get('status', '0')) query = Q() if server_id > 0: query = query & Q(server_id=server_id) if pay_type > 0: query = query & Q(pay_type=pay_type) if pay_status != 0 and pay_status != -4: query = query & Q(pay_status=pay_status) if pay_status == -4: query = query & Q(pay_status__lt=2) if key != '': if key_type == 0: query = query & Q(query_id=key) elif key_type == 1: query = query & Q(pay_user=key) elif key_type == 2: query = query & Q(order_id=key) elif key_type == 3: query = query & Q(card_no=key) elif key_type == 4: query = query & Q(remark__contains=key) if 'old' == table_name: PayAction._meta.db_table = 'pay_action_old' else: PayAction._meta.db_table = 'pay_action' total_record = PayAction.objects.filter(query).count() list_server = [] if total_record > 0: list_record = PayAction.objects.filter(query)[(page_num - 1) * page_size:page_num * page_size] list_server = get_server_list() itemServerList = {} for item in list_server: itemServerList[item.id] = item.name for item in list_record: item.playerName = '' item.pay_type_name = payChannel_record.get(item.pay_type, '') item.server_name = itemServerList.get(item.server_id, '--') parg = {} parg["list_server"] = list_server parg["payChannel_list"] = payChannel_list parg["pay_type"] = pay_type parg["key_type"] = key_type parg["list_record"] = list_record parg["key"] = key parg["status"] = pay_status parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record parg["table_name"] = table_name return render_to_response('pay/pay_list.html', parg)
def user_pay(request): query_channel = request.POST.getlist('c') #channel_id user_id = request.POST.get("user_id", '') user_name = request.POST.get("user_name", "") sdate = request.POST.get("sdate", "") edate = request.POST.get("edate", "") query_server = request.POST.getlist('s') #server_id page_num = int(request.GET.get("page_num", "1")) if user_id == "": user_id = "0" user_id = int(user_id) page_size = 50 list_channel = center_cache.get_channel_list() for item1 in list_channel: if query_channel.__len__() > 0: if str(item1.id) in query_channel: item1.is_show = 1 else: item1.is_show = 1 list_server = get_server_list() for serverItem in list_server: if len(query_server) > 0: if str(serverItem.id) in query_server: serverItem.is_show = 1 else: serverItem.is_show = 1 query_where = " a.pay_status=4" try: if sdate != "": sdate = datetime.datetime.strptime( sdate, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') query_where += " and a.last_time>='%s'" % sdate if edate != "": edate = datetime.datetime.strptime( edate, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M:%S') query_where += " and a.last_time<='%s'" % edate except: sdate = "" edate = "" if query_channel.__len__() > 0 and query_channel.__len__( ) != list_channel.__len__(): query_where += ' and c.id in(%s)' % (','.join(query_channel)) if query_server.__len__() > 0 and query_server.__len__( ) != list_server.__len__(): query_where += " and a.server_id in (%s)" % (','.join(query_server)) if user_id > 0: query_where += " and a.pay_user=%s" % user_id user_name = user_name.strip() if user_name != "": query_where += " and b.username='******'" % user_name # query_user_list=User.objects.filter(username=username,channel_key=channel.0key) # if len(query_user_list)>0: # query_where+=" and pay_user=%s"%query_user_list[0].id query_pagesize = " limit %s,%s" % ( (page_num - 1) * page_size, page_num * page_size) query_sql = "select a.pay_user,b.username,sum(a.pay_amount) total_amount from pay_action a,users b,channel c where a.pay_user=b.id and a.channel_id=c.id and %s group by pay_user order by total_amount desc %s" % ( query_where, query_pagesize) query_count = "select count(distinct a.pay_user) from pay_action a,users b,channel c where a.pay_user=b.id and a.channel_id=c.id and %s" % query_where print "channel_pay_rank_list:" print query_count print query_sql cursor = connection.cursor() cursor.execute(query_count) total_record = int(cursor.fetchone()[0]) list_record = [] if total_record > 0: cursor.execute(query_sql) list_record = cursor.fetchall() #cursor.close() if user_id <= 0: user_id = "" parg = {} parg["list_server"] = list_server parg["list_channel"] = list_channel parg["user_id"] = user_id parg["user_name"] = user_name parg["sdate"] = sdate parg["edate"] = edate parg["list_record"] = list_record parg["page_num"] = page_num parg["page_size"] = page_size parg["total_record"] = total_record return render_to_response('pay/user_pay.html', parg)
def send_msg(request, server_id=0): server_id = int(server_id) player_id = int(request.GET.get('player_id', '0')) if player_id == 0: player_id = int(request.POST.get('player_id', '0')) if server_id == 0: server_id = int(request.GET.get('server_id', '0')) if server_id == 0: server_id = int(request.POST.get('server_id', '0')) usm = UserStateManager(request) server_list = [] if server_id == 0: if usm.current_userRole_is_root(): server_list = get_server_list() else: server_list = usm.get_the_user().server.all() err_msg = '' if request.method == 'POST': result_msgs = {-1: '未知错误', 0: '成功'} result_code = -1 if not usm.current_userRole_is_root(): the_user = usm.get_the_user() user_server_list = [] for server in the_user.server.all(): user_server_list.append(server.id) if not user_server_list.__contains__(server_id): return HttpResponse(u'没有权限') server_id = center_cache.get_server_config(server_id, 'master_server_id', server_id) msg_content = request.POST.get('content', '').encode('utf-8') try: if player_id > 0: if request.POST.get('msg_type', '0') == '0': req_type = 612 else: req_type = 616 req_params = 'req_type=%d&server_id=%d&reciver_id=%s&msg_content=%s' % ( req_type, server_id, player_id, msg_content) else: req_type = 611 net_id = request.GET.get('net_id', '-1') req_params = 'req_type=%d&server_id=%d&net_id=%s&msg_content=%s' % ( req_type, server_id, net_id, msg_content) result = http_post(game_server_url.GM_SERVER_URL, req_params, timeout_param=10) result = json.loads(result) print(game_server_url.GM_SERVER_URL, req_params, result) if result['code'] == 0: result_code = result['content'][0] write_gm_log( request, [req_type, server_id, player_id, result_code, msg_content]) except Exception, e: err_msg = '发生错误%s' % e #print(u'发生错误:%s' % e) result_msg = result_msgs.get(result_code, '') parg = {} parg["err_msg"] = err_msg parg["result_msg"] = result_msg return render_to_response('game/feedback.html', locals())
def server_make(request): list_group = Group.objects.using('read').all() rootPath = os.path.dirname(__file__) if True: # try: folderPath = os.path.abspath( os.path.join(rootPath, '../../../static/server/')) if not os.path.exists(folderPath): os.mkdir(folderPath) #clear old file for file_item in os.listdir(folderPath): try: itemsrc = os.path.join(folderPath, file_item) if os.path.isfile(itemsrc): os.remove(itemsrc) except: pass list_server = get_server_list() serverList = [] for item in list_server: mongo_port = 27017 #f item.json_data.find('master_server_id')!=-1: #continue #子服不需要生成 db_address = '' mongo_port = 27017 if item.log_db_config != '': try: db_config = json.loads(item.log_db_config) except: continue mongo_port = db_config.get('mongo_port', 27017) db_address = db_config.get('db_addr', item.game_addr) if None != item.report_url and '' != item.report_url: item.report_url = item.report_url.replace('http://', '') item.report_url = item.report_url.replace('/', '') serverList.append( u'{"id":%d,"name":"%s","address":"%s","db_address": "%s","gate_port":%d,"db_port":%d,"status":%d,"battle_report_url":"%s"}' % (item.id, item.name, item.game_addr, db_address, item.game_port, mongo_port, item.status, item.report_url)) #生成GM LIST filePath = os.path.join(folderPath, 'GM.json') fileContent = '[%s]' % ','.join(serverList) file_handler = open(filePath, "w") file_handler.write(fileContent.encode('utf-8')) file_handler.close() for item_group in list_group: serverList = [] noticeContent = '' list_server = item_group.server.filter( Q(status__gt=0, group__id=item_group.id)) for item in list_server: if item.json_data == None: item.json_data = '' serverList.append( u'{"id":%d,"name":"%s","address":"%s", "port":%d,"state":%d,"brUrl":"%s","rqVer":%d,"commend":%d,"limitVer":[%s],"other":{%s},"order":%d}' % (item.id, item.name, item.game_addr, item.game_port, item.status, item.report_url, item.require_ver, item.commend, item.client_ver, item.json_data, item.order)) #当前分区公告 notices = Notice.objects.using('read').filter( id=item_group.notice_select) if len(notices) > 0: the_notice = notices[0] size_str = '0.7,0.8' if None != the_notice.size and '' != the_notice.size: size_str = the_notice.size noticeContent = u",\"notice\":{\"beginDate\":\"%s\",\"endDate\":\"%s\",\"title\":\"%s\",\"size\":[%s],\"positioin\":[-1,-1],\"url\":\"%s\"}" % ( the_notice.begin_time, the_notice.end_time, the_notice.title, size_str, the_notice.link_url) fileContent = u'{"serverList":[%s],"payUrl":"%s","customUrl":"%s","noticeUrl":"%s","upgradeUrl":"%s"%s}' % ( ','.join(serverList), item_group.pay_url, item_group.custom_url, item_group.notice_url, item_group.upgrade_url, noticeContent) filePath = os.path.join(folderPath, '%s.json' % item_group.key) file_handler = open(filePath, "w") file_handler.write(fileContent.encode('utf-8')) file_handler.close() # except Exception, e: # print('write server list has error:%s' % e) return render_to_response('feedback.html')
def card_list(request): msg = '' batch_id = int(request.GET.get('batch_id', '0')) page_num = int(request.GET.get('page_num', '1')) if page_num < 1: page_num = 1 page_num = int(request.GET.get('page_num', '1')) page_size = 15 list_data = [] search_type = int(request.GET.get('search_type', '0')) status = request.GET.get('status', '') sdate = request.GET.get('start_date', '') edate = request.GET.get('end_date', '') search_val = request.GET.get('search_val', '') query = ['1=1'] total_record = 0 card_batch = None list_server = get_server_list() server_id = int(request.GET.get('server_id', '0')) if batch_id > 0: query.append(" and batch_id = '%s'" % batch_id) try: card_batch = CardBatch.objects.using('card').get(id=batch_id) key = card_batch.key Card._meta.db_table = 'card_%s' % key if search_type != 0 and search_val != '': if search_type == 1: query.append(" and number = '%s'" % search_val) elif search_type == 2: query.append(" and player_id = '%s'" % search_val) # elif search_type == 3: # query.append(" and password = '******'"%search_val) if server_id != 0: query.append(" and server_id = %d " % server_id) if status != '': try: status = int(status) query.append(" and status = %d " % status) except: pass if sdate != '' and edate != '': query.append( " AND DATE(`use_time`) >= '%s' AND DATE(`use_time`) <= '%s'" % (sdate, edate)) total_record = Card.objects.using('card').extra( where=[''.join(query)]).count() if total_record > 0: list_data = Card.objects.using('card').extra( where=[''.join(query)]).order_by( '-id')[(page_num - 1) * page_size:page_num * page_size] for item in list_data: item.server = '' if item.server_id: the_server = Server.objects.get(id=item.server_id) if the_server: item.server = the_server.name except Exception, e: print('create card number error:', e) msg = '%s' % e