def getGmList(redis, session, searchId, pageSize, pageNumber): """ 获取gm的列表 """ gmAccounts = redis.smembers('GMAccount:set') if searchId: account = redis.hget(FORMAT_USER_TABLE % (searchId), 'account') gmAccounts = [account] gm_list_len = len(gmAccounts) else: gm_list_len = len(gmAccounts) gmAccounts = ServerPagination(gmAccounts, pageSize, pageNumber) gm_info_lists = [] for gmAccount in gmAccounts: account2user_table = FORMAT_ACCOUNT2USER_TABLE % (gmAccount ) #从账号获得账号信息,和旧系统一样 table = redis.get(account2user_table) if not table: aId = '账号未建' continue else: aId = table.split(':')[1] name, parentAg = redis.hmget(table, ('nickname', 'parentAg')) gmInfo = {} gmInfo['id'] = aId gmInfo['name'] = name gmInfo['parentAg'] = parentAg gmInfo['account'] = gmAccount gmInfo['op'] = GM_OP_LIST gm_info_lists.append(gmInfo) return {'total': gm_list_len, 'result': gm_info_lists}
def getGoldListInfos(redis, search, page_size, page_num): """ 获取金币场用户数据 """ prredis = getPrivateRedisInst(redis, MASTER_GAMEID) ''' # 如果缓存存在则直接去缓存中取数据 if not search and redis.exists('gold:data:cache'): data = redis.get('gold:data:cache') data_list = json.loads(data) count = len(data_list) return {'total': count, 'result': data_list} ''' # 微信集合 weixin_sets = prredis.smembers(GOLD_ACCOUNT_SET_TOTAL) weixin_sets = weixin_sets | redis.smembers(ACCOUNT4WEIXIN_SET) data_list = [] if search: if search not in weixin_sets: return {'total': 0, 'result': []} gold_dic = get_user_field(redis, prredis, search) if gold_dic: data_list.append(gold_dic) return {'total': len(gold_dic), 'result': data_list} total_count = len(weixin_sets) weixin_sets = ServerPagination(weixin_sets, page_size, page_num) # 遍历微信集合,从对应表中取出数据字典放入data列表中 for account in weixin_sets: gold_dic = get_user_field(redis, prredis, account) data_list.append(gold_dic) ''' # 如果大于10000条数据做一个金币用户表data缓存 if count >= LIST_CACHE_MAXNUM: data_cache = json.dumps(data_list) redis.set('gold:data:cache', data_cache) # 缓存5分钟 redis.expire('gold:data:cache', LIST_CACHE_TTL) ''' return {'total': total_count, 'result': data_list}
def get_bet_list(redis,startDate,endDate,room_id,user_id,page_info,sort_info,userId=None,groupId=None): """ 获取捕鱼投注明细数据 params: reids,condition(查询条件列表) """ try: startDate = datetime.strptime(startDate,'%Y-%m-%d') endDate = datetime.strptime(endDate,'%Y-%m-%d') except: weekDelTime = timedelta(7) weekBefore = datetime.now()-weekDelTime startDate = weekBefore endDate = datetime.now() deltaTime = timedelta(1) bet_table = ALL_FISH_BET_DATA_DETAIL sum_table = ALL_FISH_BET_DATA4DAY if user_id:#根据玩家ID搜索 bet_table = PLAYER_FISH_BET_DATA_DETAIL4DAY%(user_id,'%s') sum_table= PLAYER_FISH_BET_DATA4DAY%(user_id,'%s') elif room_id:#根据房间号查询 bet_table = FISH_BET_DATA_DETAIL4ROOM%(room_id,'%s') sum_table = FISH_BET_DATA4DAY4ROOM%(room_id,'%s') res,totalBetMoney,totalWinLostMoney,winLostRate,totalTickets = [],0,0,0,0 total_datas = [] now_time = datetime.now() log_debug('[try get_bet_list] startDate->[%s]'%(datetime.now())) while endDate >= startDate: if endDate > now_time:#不查没有数据的时间 endDate-=deltaTime continue dateStr = endDate.strftime('%Y-%m-%d') bet_records = redis.lrange(bet_table%(dateStr),0,-1) #记录总投注额 betMoney,winLostMoney,ticket_total = redis.hmget(sum_table%(dateStr),('bet','profit','ticket')) betMoney = convert_util.to_float(betMoney) winLostMoney = convert_util.to_float(winLostMoney) ticket_total = convert_util.to_float(ticket_total) totalBetMoney+=betMoney totalWinLostMoney+=winLostMoney totalTickets+=ticket_total #索引出所有数据 total_datas.extend(bet_records) endDate -= deltaTime total = len(total_datas) for bet_record in total_datas: bet_record = eval(bet_record) bet_keys = bet_record.keys() betInfo = {} betInfo['win'] = bet_record['win'] betInfo['bet_id'] = bet_record['bet_id'] betInfo['room_id'] = bet_record['room_id'] betInfo['bet'] = bet_record['bet'] betInfo['uid'] = bet_record['uid'] betInfo['datetime'] = bet_record['datetime'] betInfo['init_coin'] = int(bet_record['init_coin']) if 'init_coin' in bet_keys else 0 betInfo['add_coin'] = bet_record['add_coin'] if 'add_coin' in bet_keys else 0 betInfo['login_time'] = bet_record['login_time'] if 'login_time' in bet_keys else '未知' betInfo['add_ticket'] = bet_record['add_ticket'] if 'add_ticket' in bet_keys else 0 betInfo['op'] = [] betInfo['op'].append(BET_OP_LIST) res.append(betInfo) if totalWinLostMoney: winLostRate = round(((totalBetMoney-totalWinLostMoney)/totalBetMoney)*100,2) if winLostRate > 0.00: winLostRate=-winLostRate else: winLostRate=abs(winLostRate) if sort_info['sort_name']: #如果排序 res = sorted(res, key=itemgetter(sort_info['sort_name']),reverse=FONT_CONFIG['STR_2_SORT'][sort_info['sort_method']]) #分页处理,客户端每次只渲染15条 res = ServerPagination(res,page_info['page_size'],page_info['page_number']) log_util.debug('[try get_bet_list] endDtime->[%s]'%(datetime.now())) return {'result':res,'count':total,'betTotal':totalBetMoney,'ticketTotal':totalTickets,'winLostTotal':totalWinLostMoney,'winLostRate':winLostRate}
def get_fish_member_list(redis, session, selfUid, searchId, lang, pageSize, pageNumber, sort_name, sort_method): """ 获取捕鱼会员列表 :params redis redis链接实例 :params session 会话信息句柄 :params searchId 搜索的用户ID :params lang 语言包实例 :params pageNumber 分页数 :params sort_name 排序名称 :params sort_method 排序方法 #捕鱼玩家信息列表 MEMBER_FISH_LIST_FIELDS = ( 'name', 'parentAg', 'coin', 'nickname', 'headImgUrl', 'last_login_date', 'last_logout_date', 'valid', 'recharge_coin_total', 'exchange_ticket' ) """ adminTable = AGENT_TABLE % (selfUid) aType, aId = redis.hmget(adminTable, ('type', 'id')) type2getMemberIds = {0: getSystemMemberIds, 1: getAgentAllMemberIds} if searchId and redis.exists(FORMAT_USER_TABLE % (searchId)): #如果搜索的话 memberIds = [searchId] else: #管理员或者1及代理 memberIds = getSystemMemberIds(redis, selfUid, 'fish') total_records = len(memberIds) membersList, user_info_list = [], [] selfAccesses = eval(session['access']) log_debug('=================startTime[%s]' % (datetime.now())) memberInfos = [] if not searchId and redis.exists("agent:%s:fish:members:cache" % (selfUid)): #直接从缓存读取 user_info_list = eval( redis.get("agent:%s:fish:members:cache" % (selfUid))) else: for memberId in memberIds: #获取所有用户信息 table = FORMAT_USER_TABLE % (memberId) #从账号获得账号信息,和旧系统一样 memberInfos = redis.hmget(table, MEMBER_FISH_LIST_FIELDS) memberInfos.insert(0, memberId) try: memberInfos[3] = int(memberInfos[3]) except: memberInfos[3] = 0 user_info_list.append(memberInfos) if total_records >= LIST_CACHE_MAXNUM: #总记录数大于阈值的才需要缓存 redis.set("agent:%s:fish:members:cache" % (selfUid), user_info_list) redis.expire("agent:%s:fish:members:cache" % (selfUid), LIST_CACHE_TTL) if sort_name: #如果排序 log_util.debug('sorOrder[%s] sortName[%s]' % (sort_name, sort_method)) user_info_list = sorted(user_info_list, key=itemgetter(SORT_2_INDEX[sort_name]), reverse=FONT_CONFIG['STR_2_SORT'][sort_method]) #分页渲染 user_info_list = ServerPagination(user_info_list, pageSize, pageNumber) for user_info in user_info_list: #MEMBER_LIST_FIELDS = ('name','parentAg','roomCard','nickname','headImgUrl','last_login_date','last_logout_date','valid','open_auth') memberInfo = {} memberInfo['name'] = user_info[1] memberInfo['id'] = user_info[0] memberInfo['nickname'] = user_info[4] memberInfo['headImgUrl'] = user_info[5] memberInfo[ 'last_login_date'] = user_info[6] if user_info[6] else '从未登录' memberInfo[ 'last_logout_date'] = user_info[7] if user_info[7] else '从未登录' memberInfo['valid'] = user_info[8] memberInfo['recharge_coin_total'] = user_info[9] memberInfo['exchange_ticket'] = user_info[10] if user_info[10] else 0 memberInfo['coin'] = int(user_info[3]) if user_info[3] else 0 memberInfo['parentAg'] = user_info[2] #memberInfo['rechargeTotal']= user_info[10] memberInfo['op'] = [] for access in access_module.ACCESS_MEMBER_LIST: if access.url[-4:] == 'kick' and int(aType) == 0: continue elif access.url[-6:] == 'freeze': memberInfo['op'].append({'url':access.url+"/fish",'txt':'冻结' \ if user_info[8] == '1' else '解冻','method':access.method}) elif access.url[-10:] == 'removeCard': memberInfo['op'].append({ 'url': access.url, 'method': access.method, 'txt': '移除金币' }) elif access.url[-7:] == 'addCard': memberInfo['op'].append({ 'url': access.url, 'method': access.method, 'txt': '补充金币' }) else: memberInfo['op'].append({ 'url': access.url, 'method': access.method, 'txt': access.getTxt(lang) }) membersList.append(memberInfo) return { 'total': total_records, 'result': membersList, 'pageNumber': pageNumber }
def getMemberList(redis, session, selfUid, searchId, lang, pageSize, pageNumber, sort_name, sort_method): """ 获取代理的会员列表 """ adminTable = AGENT_TABLE % (selfUid) aType, aId = redis.hmget(adminTable, ('type', 'id')) type2getMemberIds = {0: getSystemMemberIds, 1: getAgentAllMemberIds} if searchId and redis.exists(FORMAT_USER_TABLE % (searchId)): #如果搜索的话 memberIds = [searchId] elif int(aType) in type2getMemberIds.keys(): #管理员或者1及代理 memberIds = type2getMemberIds[int(aType)](redis, selfUid) else: #二级,三级代理 memberTable = FORMAT_ADMIN_ACCOUNT_MEMBER_TABLE % (selfUid) memberIds = redis.smembers(memberTable) # 修改 只有一层代理关系 memberTable = FORMAT_ADMIN_ACCOUNT_MEMBER_TABLE % (selfUid) memberIds = redis.smembers(memberTable) total_records = len(memberIds) membersList, user_info_list = [], [] selfAccesses = eval(session['access']) log_debug('=================startTime[%s]' % (datetime.now())) memberInfos = [] if not searchId and redis.exists("agent:%s:members:cache" % (selfUid)): #直接从缓存读取 user_info_list = eval(redis.get("agent:%s:members:cache" % (selfUid))) else: for memberId in memberIds: #获取所有用户信息 table = FORMAT_USER_TABLE % (memberId) #从账号获得账号信息,和旧系统一样 memberInfos = redis.hmget(table, MEMBER_LIST_FIELDS) memberInfos.insert(0, memberId) try: memberInfos[3] = int( redis.get(USER4AGENT_CARD % (memberInfos[2], memberInfos[0]))) except: memberInfos[3] = 0 try: memberInfos.insert( 10, int( get_sum_rechargeInGroup(redis, memberInfos[2], memberInfos[0]))) except: memberInfos.insert(10, 0) user_info_list.append(memberInfos) if total_records >= LIST_CACHE_MAXNUM: #总记录数大于阈值的才需要缓存 redis.set("agent:%s:members:cache" % (selfUid), user_info_list) redis.expire("agent:%s:members:cache" % (selfUid), LIST_CACHE_TTL) if sort_name: #如果排序 log_debug('sorOrder[%s] sortName[%s]' % (sort_name, sort_method)) user_info_list = sorted(user_info_list, key=itemgetter(SORT_2_INDEX[sort_name]), reverse=FONT_CONFIG['STR_2_SORT'][sort_method]) #分页渲染 user_info_list = ServerPagination(user_info_list, pageSize, pageNumber) for user_info in user_info_list: #MEMBER_LIST_FIELDS = ('name','parentAg','roomCard','nickname','headImgUrl','last_login_date','last_logout_date','valid','open_auth') memberInfo = {} memberInfo['name'] = redis.hget('users:%s' % user_info[0], 'account') memberInfo['coin'] = redis.hget('users:%s' % user_info[0], 'coin') memberInfo['id'] = user_info[0] memberInfo['nickname'] = user_info[4] memberInfo['headImgUrl'] = user_info[5] memberInfo[ 'last_login_date'] = user_info[6] if user_info[6] else '从未登录' memberInfo[ 'last_logout_date'] = user_info[7] if user_info[7] else '从未登录' memberInfo['valid'] = user_info[8] memberInfo['open_auth'] = user_info[9] if user_info[9] else '0' #默认不开启 if not user_info[2]: memberInfo['roomcard'] = 0 memberInfo['rechargeTotal'] = 0 memberInfo['parentAg'] = '无' else: roomCard = user_info[3] memberInfo['roomcard'] = int(roomCard) if roomCard else 0 memberInfo['parentAg'] = user_info[2] memberInfo['rechargeTotal'] = user_info[10] memberInfo['op'] = [] for access in access_module.ACCESS_MEMBER_LIST: if access.url in selfAccesses: if access.url[-4:] == 'kick' and int(aType) == 0: continue elif access.url[-6:] == 'freeze': memberInfo['op'].append({'url':access.url+"/hall",'txt':'冻结' \ if user_info[8] == '1' else '解冻','method':access.method}) elif access.url[-9:] == 'open_auth': memberInfo['op'].append({'url':access.url,'txt':'关闭代开权限' \ if user_info[9] == '1' else '打开代开权限','method':access.method}) else: memberInfo['op'].append({ 'url': access.url, 'method': access.method, 'txt': access.getTxt(lang) }) membersList.append(memberInfo) return { 'total': total_records, 'result': membersList, 'pageNumber': pageNumber }
def getMemberList(redis, session, selfUid, searchId, lang, pageSize, pageNumber, sort_name, sort_method): """ 获取代理的会员列表 """ adminTable = AGENT_TABLE % (selfUid) aType, aId = redis.hmget(adminTable, ('type', 'id')) type2getMemberIds = {0: getSystemMemberIds, 1: getAgentAllMemberIds} # if searchId: #and redis.exists(FORMAT_USER_TABLE%(searchId)):#如果搜索的话 if searchId and redis.hexists("users:relate:number:hset", searchId): #如果搜索的话 memberIds = [redis.hget("users:relate:number:hset", searchId)] elif int(aType) in type2getMemberIds.keys(): #管理员或者1及代理 memberIds = type2getMemberIds[int(1)](redis, selfUid) else: #二级,三级代理 memberTable = FORMAT_ADMIN_ACCOUNT_MEMBER_TABLE % (selfUid) memberIds = redis.smembers(memberTable) total_records = len(memberIds) membersList, user_info_list = [], [] selfAccesses = eval(session['access']) log_debug('=================startTime[%s]' % (datetime.now())) memberInfos = [] if not searchId and redis.exists("agent:%s:members:cache" % (selfUid)): #直接从缓存读取 user_info_list = eval(redis.get("agent:%s:members:cache" % (selfUid))) else: for memberId in memberIds: #获取所有用户信息 table = FORMAT_USER_TABLE % (memberId) #从账号获得账号信息,和旧系统一样 memberInfos = redis.hmget(table, MEMBER_LIST_FIELDS) memberInfos.insert(0, memberId) try: memberInfos[3] = int( redis.get(USER4AGENT_CARD % (memberInfos[2], memberInfos[0]))) except: memberInfos[3] = 0 try: memberInfos.insert( 10, int( get_sum_rechargeInGroup(redis, memberInfos[2], memberInfos[0]))) except: memberInfos.insert(10, 0) user_info_list.append(memberInfos) if total_records >= LIST_CACHE_MAXNUM: #总记录数大于阈值的才需要缓存 redis.set("agent:%s:members:cache" % (selfUid), user_info_list) redis.expire("agent:%s:members:cache" % (selfUid), LIST_CACHE_TTL) if sort_name: #如果排序 log_debug('sorOrder[%s] sortName[%s]' % (sort_name, sort_method)) user_info_list = sorted(user_info_list, key=itemgetter(SORT_2_INDEX[sort_name]), reverse=FONT_CONFIG['STR_2_SORT'][sort_method]) if searchId: member_return, qty = get_member_by_id(redis, searchId, user_info_list) return {'total': qty, 'result': member_return, 'pageNumber': 1} #分页渲染 user_info_list = ServerPagination(user_info_list, pageSize, pageNumber) for user_info in user_info_list: #MEMBER_LIST_FIELDS = ('name','parentAg','roomCard','nickname','headImgUrl','last_login_date','last_logout_date','valid','open_auth') memberInfo = {} memberInfo['name'] = user_info[1] memberInfo['id'] = user_info[0] memberInfo['nickname'] = user_info[4] memberInfo['headImgUrl'] = user_info[5] memberInfo[ 'last_login_date'] = user_info[6] if user_info[6] else '从未登录' memberInfo[ 'last_logout_date'] = user_info[7] if user_info[7] else '从未登录' memberInfo['valid'] = user_info[8] memberInfo['open_auth'] = user_info[9] if user_info[9] else '0' #默认不开启 relate = redis.smembers("users:relate:%s:set" % memberInfo['id']) if not relate: relate = [] memberInfo["relate"] = list(relate) if not user_info[2]: memberInfo['roomcard'] = 0 memberInfo['rechargeTotal'] = 0 memberInfo['parentAg'] = '无' else: roomCard = user_info[3] memberInfo['roomcard'] = int(roomCard) if roomCard else 0 memberInfo['parentAg'] = user_info[2] memberInfo['rechargeTotal'] = user_info[10] user_id = memberInfo['id'] parentAg = user_info[2] topAgent = agentModel.getTopAgentId(redis, parentAg) print(u"顶级公会ID:%s, 当前公会%s" % (topAgent, parentAg)) topManager = redis.smembers("agent:%s:manager:member:set" % topAgent) parentManager = redis.smembers("agent:%s:manager:member:set" % parentAg) if user_id in topManager: level = 1 elif user_id in parentManager: level = 2 else: level = 3 memberInfo["topAgent"] = topAgent gid = redis.hget("agents:id:%s" % topAgent, 'parent_id') memberInfo['gid'] = gid memberInfo["level"] = level memberInfo['op'] = [] membersList.append(memberInfo) return { 'total': total_records, 'result': membersList, 'pageNumber': pageNumber }