def __merge_reward(self, prev, later): if not prev: return Context.copy_json_obj(later) if not later: return Context.copy_json_obj(prev) rewards = {} # merge金币 if 'chip' in prev or 'chip' in later: rewards['chip'] = prev.get('chip', 0) + later.get('chip', 0) # merge钻石 if 'diamond' in prev or 'diamond' in later: rewards['diamond'] = prev.get('diamond', 0) + later.get('diamond', 0) # merge兑换券 if 'coupon' in prev or 'coupon' in later: rewards['coupon'] = prev.get('coupon', 0) + later.get('coupon', 0) # merge道具 props = {} for tmp in [prev, later]: if 'props' in tmp: for prop in tmp['props']: if prop['id'] not in props: props[prop['id']] = prop else: props[prop['id']]['count'] += prop['count'] if props: rewards['props'] = props.values() return rewards
def __merge_reward_result(self, detail, prev, later): if not prev: return Context.copy_json_obj(later) if not later: return Context.copy_json_obj(prev) ret = {} # 合并最终的字段 if 'chip' in later: ret['chip'] = later['chip'] elif 'chip' in prev: ret['chip'] = prev['chip'] if 'diamond' in later: ret['diamond'] = later['diamond'] elif 'diamond' in prev: ret['diamond'] = prev['diamond'] _props = {} for tmp in [prev, later]: if 'props' in tmp: for prop in tmp['props']: _props[prop['id']] = prop if _props: ret['props'] = _props.values() if detail: # 合并奖励字段 prev_reward, later_reward = prev['reward'], later['reward'] rewards = {} # merge金币 if 'chip' in prev_reward or 'chip' in later_reward: rewards['chip'] = prev_reward.get('chip', 0) + later_reward.get('chip', 0) # merge fake 金币 if 'fake_chip' in prev_reward or 'fake_chip' in later_reward: rewards['fake_chip'] = prev_reward.get('fake_chip', 0) + later_reward.get('fake_chip', 0) # merge钻石 if 'diamond' in prev_reward or 'diamond' in later_reward: rewards['diamond'] = prev_reward.get('diamond', 0) + later_reward.get('diamond', 0) # merge兑换券 if 'coupon' in prev_reward or 'coupon' in later_reward: rewards['coupon'] = prev_reward.get('coupon', 0) + later_reward.get('coupon', 0) # merge道具 props = {} for tmp in [prev_reward, later_reward]: if 'props' in tmp: for prop in tmp['props']: if prop['id'] not in props: props[prop['id']] = prop else: props[prop['id']]['count'] += prop['count'] if props: rewards['props'] = props.values() if rewards: ret['reward'] = rewards return ret
def on_use_props(self, uid, gid, mi): _id = mi.get_param('id') _count = mi.get_param('count') mo = MsgPack(Message.MSG_SYS_USE_PROPS | Message.ID_ACK) if _id not in [ FishProps.PROP_EGG_BRONZE, FishProps.PROP_EGG_SILVER, FishProps.PROP_EGG_GOLD, FishProps.PROP_EGG_COLOR ]: return mo.set_error(1, 'can not use') if not isinstance(_count, int) or _count <= 0: return mo.set_error(2, 'count error') conf = FishProps.get_config_by_id(gid, _id) if not conf: Context.Log.error('not found props:', uid, gid, _id, _count) return mo.set_error(4, 'not found props') real, final = FishProps.incr_props(uid, gid, _id, -_count, 'entity.use') if real != -_count: return mo.set_error(3, 'not enough') if _count == 1: reward = conf['content'] else: reward = FishProps.merge_reward(*[conf['content']] * _count) reward = Context.copy_json_obj(reward) reward = self.deal_reward(reward) reward = FishProps.issue_rewards(uid, gid, reward, 'entity.use') reward = FishProps.convert_reward(reward) mo.update_param(reward) return mo
def incrby(cls, uid, gid, rank_name, score, cache=None, field='score'): key = 'rank:%d:%s' % (gid, rank_name) score = Context.RedisMix.zset_incrby(key, uid, score) if cache: cache[field] = score Context.RedisMix.hash_set(key + ':cache', uid, Context.json_dumps(cache)) return int(score)
def on_exchange(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_EXCHANGE | Message.ID_ACK) _id = mi.get_param('id') if not isinstance(_id, int): return mo.set_error(1, 'error param') conf = Context.Configure.get_game_item_json(gid, 'exchange.config') if _id >= len(conf): return mo.set_error(1, 'error id') info = conf[_id] to_type = info['type'] if to_type not in ('diamond', 'props', 'phone'): raise Exception( str(to_type) + '<----error type, please check config') real, final = Context.UserAttr.incr_coupon(uid, gid, -info['cost'], 'exchange.' + to_type) if real != -info['cost']: return mo.set_error(2, 'not enough') mo.set_param('coupon', final) record = { 'uid': uid, 'type': 'exchange', 'ts': Time.current_ts(), 'from': 'coupon', 'to': to_type, 'cost': info['cost'], 'count': info['count'], 'desc': info['desc'] } if info['type'] == 'diamond': # 兑换钻石 real, final = Context.UserAttr.incr_diamond( uid, gid, info['count'], 'exchange.diamond') mo.set_param('diamond', final) state = 1 elif info['type'] == 'props': # 兑换道具 real, final = FishProps.incr_props(uid, gid, info['id'], info['count'], 'exchange.props') mo.set_param('id', info['id']) mo.set_param('count', final) state = 1 record['id'] = info['id'] elif info['type'] == 'phone': state = 0 record['phone'] = mi.get_param('phone') else: raise Exception('something error, please check config') seq_num = Context.RedisMix.hash_incrby('game.%d.info.hash' % gid, 'exchange.history.seq', 1) Context.RedisCluster.hash_set(uid, 'history:%d:%d' % (gid, uid), seq_num, state) record = Context.json_dumps(record) Context.RedisMix.hash_mset('game.%d.exchange.record' % gid, seq_num, record) fmt = Time.current_time('%Y-%m-%d') Context.RedisStat.hash_set('history:%d:%s' % (gid, fmt), seq_num, uid) return mo
def __add_config_item(cls, key, attr, value): if key not in cls._ALL_CONFIG: cls._ALL_CONFIG[key] = {} cls._ALL_CONFIG[key][attr] = value if isinstance(value, (tuple, list, dict)): value = Context.json_dumps(value) cls._ALL_CMD.append(['HSET', key, attr, value])
def on_join_table(self, gid, msg): ack = MsgPack(Message.MSG_SYS_JOIN_TABLE | Message.ID_ACK) tid = msg.get_param('tableId') self._info('player req to join table', tid) self.offline = False if self.tid > 0 and self.tid != tid: self.offline = True return ack.set_error(Enum.join_table_failed_multi) registry = Context.get_module(gid, 'registry') table = registry.create_table(gid, tid) if not table: self.offline = True return ack.set_error(Enum.join_table_failed_id) result = table.join_table(self.uid) if result != 0: self.offline = True return ack.set_error(result) self.table = table self.online_ts = Time.current_ts() sid = msg.get_param('seatId') if sid is not None: return self.on_sit_down(msg) return result
def get_total_degree(self, uid, gid): task_list = Context.Daily.get_daily_data(uid, gid, 'task.list') if not task_list: return 0 task_list = Context.json_loads(task_list) degree = 0 for task in task_list: if task['type'] == 1: count = Context.Daily.get_daily_data(uid, gid, 'fish.' + str(task['fish_type'])) task['count'] = Tool.to_int(count, 0) elif task['type'] == 2: count = Context.Daily.get_daily_data(uid, gid, 'class.boss') task['count'] = Tool.to_int(count, 0) elif task['type'] == 3: count = Context.Daily.get_daily_data(uid, gid, 'class.bonus') task['count'] = Tool.to_int(count, 0) elif task['type'] == 11: count = Context.Daily.get_daily_data(uid, gid, 'win.chip') task['count'] = Tool.to_int(count, 0) elif task['type'] == 21: degree += task['degree'] if 'count' in task and task['count'] >= task['total']: task['done'] = 1 degree += task['degree'] return degree
def onLed(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_LED | Message.ID_ACK) action = mi.get_param('action', 'get') if action == 'get': last_ts = mi.get_param('last_ts', 0) led_list = Context.RedisCache.list_range('global.led.list', 0, 9) _list, ts = [], 0 for led in led_list: led = Context.json_loads(led) if led['ts'] > last_ts: _list.append(led['led']) ts = led['ts'] if _list: mo.set_param('global', {'ts': ts, 'list': _list}) led_list = Context.RedisCache.list_range('game.%d.led.list' % gid, 0, 9) _list, ts = [], 0 for led in led_list: led = Context.json_loads(led) if led['ts'] > last_ts: _list.append(led['led']) ts = led['ts'] if _list: mo.set_param('game', {'ts': ts, 'list': _list}) elif action == 'put': conf = Context.Configure.get_game_item_json(gid, 'led.config') if not conf or not conf.get('enable'): mo.set_error(101, 'led not available') else: msg = mi.get_param('msg') cost = conf['cost'] real, final = Context.UserAttr.incr_diamond( uid, gid, -cost, 'led.put') if real != -cost: mo.set_error(102, 'no enough diamond') else: led = Context.json_dumps({ 'led': msg, 'ts': Time.current_ts() }) Context.RedisCache.list_lpush('game.%d.led.list' % gid, led) return Context.GData.send_to_connect(uid, mo)
def gm_push_led(self, gid, mi, request): msg = mi.get_param('msg') if not msg: # 清除led Context.RedisCache.delete('game.%d.led.list' % gid) else: led = Context.json_dumps({'led': msg, 'ts': Time.current_ts()}) Context.RedisCache.list_lpush('game.%d.led.list' % gid, led) return MsgPack(0)
def on_room_list(self, uid, gid, mi): room_config = Context.Configure.get_room_config(gid) if not room_config: Context.Log.error(uid, 'req room list, but no config fetch') return False conf = Context.copy_json_obj(room_config) mo = MsgPack(Message.MSG_SYS_ROOM_LIST | Message.ID_ACK) mo.set_param('room_list', conf) return Context.GData.send_to_connect(uid, mo)
def onMessage(self, cmd, uid, gid, mi): if cmd == Message.MSG_INNER_TIMER: tid = mi.get_param('tableId') if tid: registry = Context.get_module(gid, 'registry') table = registry.get_table(tid) if table: with Context.GData.table_locker[tid]: table.onTimer(cmd, gid, mi) else: Context.Log.info(tid, 'table not exist', mi) else: Context.Log.info('miss table id', mi) else: registry = Context.get_module(gid, 'registry') player = registry.create_player(uid) if player: player.on_message(cmd, gid, mi) else: Context.Log.debug('no player found', mi)
def save_config(cls, fdir, fname): cls.add_global_config('game.list', cls._ROOM_MAP.keys()) for gameId, item in cls._ROOM_MAP.iteritems(): cls.add_game_config(gameId, 'room.map', item) roomtype = item.keys() cls.add_game_config(gameId, 'room.type', sorted(roomtype)) gamelist = set() for _, servers in item.iteritems(): gamelist.update(servers) data = Context.json_dumps(cls._ALL_CMD) File.write_file(fdir, fname, data)
def getLoginInfo(cls, request, cmd, uid, gid, param, userInfo, freshAccessToken, openid=None, open_token=None): session = Algorithm.md5_encode(Time.asctime() + request.getClientIP() + userInfo['userName']) Account.setUserToken(uid, gid, session) conn_server = Context.json_loads( Context.RedisCache.get('connect.server')) internet = conn_server[uid % len(conn_server)] dictInfo = { "session": session, "userId": uid, "sex": int(userInfo['sex']), "nick": userInfo['nick'], "avatar": userInfo['avatar'], "host": internet["domain"], "port": internet["port"], } if openid: dictInfo['openid'] = openid if open_token: dictInfo['open_token'] = open_token if freshAccessToken: data = '{"uid":%d,"ct":%d}' % (uid, Time.current_ts()) accessToken = Entity.encrypt(data) Account.updateUserInfo(uid, accessToken=accessToken) dictInfo['accessToken'] = accessToken kvs = { 'session_platform': param['platform'] or 'android', 'session_channel': param['channel'] or 'jiyu', 'session_ver': param['releaseVer'] or '1.0.1' } Context.Data.set_game_attrs_dict(uid, gid, kvs) Context.Log.report('user.login:', [uid, gid, kvs]) # 登录成功设置session值 session = request.getSession() session.setLogined(uid) return MsgPack(cmd, dictInfo)
def onInnerMessage(self, cmd, mi, *args, **kwargs): uid = mi.get_uid() gid = mi.get_gid() raw = mi.get_message() mi = MsgPack.unpack(cmd, raw) gid = mi.get_param('gameId', gid) quick = Context.get_module(gid, 'quick') with Context.GData.server_locker: if quick: quick.onMessage(cmd, uid, gid, mi) else: Context.Log.warn('error msg', cmd, mi)
def onInnerMessage(self, cmd, mi, *args, **kwargs): uid = mi.get_uid() gid = mi.get_gid() raw = mi.get_message() mi = MsgPack.unpack(cmd, raw) gid = mi.get_param('gameId', gid) game = Context.get_module(gid, 'game') with Context.GData.user_locker[uid]: if game: game.onMessage(cmd, uid, gid, mi) else: Context.Log.warn('no game found', mi)
def loginByAccessToken(self, mi, request): param = self.getParam(mi, 'accessToken') if len(param['accessToken']) <= 1: return MsgPack.Error(0, self.error_invalid_access_token, self.desc_invalid_access_token) try: decrptData = Entity.decrypt(param['accessToken']) decoded = Context.json_loads(decrptData) except Exception, e: return MsgPack.Error(0, self.error_invalid_access_token, self.desc_invalid_access_token)
def __rebate_reward(self, gid, pay_total, reward, channel): reward = Context.copy_json_obj(reward) if 'chip' in reward: vip_config = Context.Configure.get_game_item_json( gid, 'vip.config') if vip_config: for item in reversed(vip_config): if pay_total > item['pay'] and 'rebate' in item: rebate = item['rebate'] reward['chip'] += int(reward['chip'] * rebate) break return reward
def get_common_game_info(cls, uid, gid): chip = Context.UserAttr.get_chip(uid, gid) if chip is None: kvs = Context.copy_json_obj(cls.game_attrs) Context.Data.set_game_attrs_dict(uid, gid, kvs) chip_startup = Context.Configure.get_game_item_int( gid, 'game.startup') Context.UserAttr.incr_chip(uid, gid, chip_startup, 'game.startup') kvs['chip'] = chip_startup is_new = True else: attrs = cls.game_attrs.keys() kvs = Context.copy_json_obj(cls.game_attrs) kvs.update(Context.Data.get_game_attrs_dict(uid, gid, attrs)) for k, v in kvs.iteritems(): kvs[k] = int(kvs[k]) kvs['chip'] = chip is_new = False diamond = Context.UserAttr.get_diamond(uid, gid, 0) kvs['diamond'] = diamond coupon = Context.UserAttr.get_coupon(uid, gid, 0) kvs['coupon'] = coupon return is_new, kvs
def on_raffle(self, uid, gid, mi): _id = mi.get_param('i') _button = mi.get_param('bt') mo = MsgPack(Message.MSG_SYS_RAFFLE | Message.ID_ACK) raffle_config = Context.Configure.get_game_item_json( gid, 'raffle.config') raffle_config = Context.copy_json_obj(raffle_config) loop_config = raffle_config['loop'] raffle_config = raffle_config['config'] class_pool, loop_times = Context.Daily.get_daily_data( uid, gid, 'fake.bonus.count', 'bonus.loop.times') class_pool = Tool.to_int(class_pool, 0) loop_times = Tool.to_int(loop_times, 0) if loop_times > len(loop_config) - 1: this_count = loop_config[-1] else: this_count = loop_config[loop_times] if class_pool < this_count: return mo.set_error(1, 'lack fish') for item in raffle_config: if item['id'] == _id: bonus_pool = Context.Data.get_game_attr_int( uid, gid, 'bonus_pool', 0) if bonus_pool < item['limit']: return mo.set_error(2, 'lack chip') # 发放奖励 index, which = Algorithm.choice_by_ratio(item['reward'], 10000, func=lambda l: l[0]) reward = FishProps.issue_rewards(uid, gid, which[1], 'bonus.raffle') mo.set_param('bt', _button) mo.set_param('i', index + 1) rw = FishProps.convert_reward(reward) mo.update_param(rw) # 重置数据 pipe_args = [ 'fake.bonus.count', -class_pool, 'bonus.loop.times', 1 ] Context.Daily.mincr_daily_data(uid, gid, *pipe_args) Context.Data.hincr_game(uid, gid, 'bonus_pool', -bonus_pool) self.__pub_raffle_led(uid, gid, item['name'], reward) return mo return mo.set_error(3, 'error id')
def onGameInfo(self, uid, gid, mi): gid = mi.get_param('gameId') mo = MsgPack(Message.MSG_SYS_GAME_INFO | Message.ID_ACK) account = Context.get_module(gid, 'account', Account) is_new, data = account.get_game_info(uid, gid) if not data: mo.set_error(-1, 'no game info') else: mo.update_param(data) if is_new: mo.set_param('new', 1) info = Context.RedisCache.hash_mget('global.notice', 'led', 'start', 'end') led = info[0] if led: now_ts = Time.current_ts() start = int(info[1]) end = int(info[2]) if start < now_ts < end: mo.set_param('global_notice', { 'list': [led], 'end': end, 'now_ts': now_ts }) Context.GData.send_to_connect(uid, mo) if is_new: account.on_create_user(uid, gid) if account.auto_issue_benefit: benefit_config = Context.Configure.get_game_item_json( gid, 'benefit.config') if benefit_config and benefit_config['limit'] > data['chip']: benefit = Context.Daily.issue_benefit(uid, gid) mo = MsgPack(Message.MSG_SYS_BENEFIT | Message.ID_NTF) if not benefit: benefit = { 'which': 0, 'total': 0, 'reward': 0, 'chip': data['chip'], } mo.update_param(benefit) Context.GData.send_to_connect(uid, mo)
def on_consume_task(self, uid, gid, mi): _id = mi.get_param('id') mo = MsgPack(Message.MSG_SYS_CONSUME_TASK | Message.ID_ACK) task_list = Context.Daily.get_daily_data(uid, gid, 'task.list') if not task_list: return mo.set_error(1, 'no task') task_list = Context.json_loads(task_list) degree = 0 for task in task_list: if task['type'] == 1: count = Context.Daily.get_daily_data(uid, gid, 'fish.' + str(task['fish_type'])) task['count'] = Tool.to_int(count, 0) elif task['type'] == 2: count = Context.Daily.get_daily_data(uid, gid, 'class.boss') task['count'] = Tool.to_int(count, 0) elif task['type'] == 3: count = Context.Daily.get_daily_data(uid, gid, 'class.bonus') task['count'] = Tool.to_int(count, 0) elif task['type'] == 11: count = Context.Daily.get_daily_data(uid, gid, 'win.chip') task['count'] = Tool.to_int(count, 0) elif task['type'] == 21: degree += task['degree'] if 'count' in task and task['count'] >= task['total']: task['done'] = 1 degree += task['degree'] conf = Context.Configure.get_game_item_json(gid, 'task.config') for i, reward in enumerate(conf['reward']): if i == _id: if degree < reward['degree']: return mo.set_error(2, 'not done') state = Context.Daily.incr_daily_data(uid, gid, 'task.reward.%d' % _id, 1) if state > 1: return mo.set_error(3, 'received') reward = FishProps.issue_rewards(uid, gid, reward['reward'], 'task.reward.%d' % _id) _reward = FishProps.convert_reward(reward) mo.update_param(_reward) break else: mo.set_error(4, 'error id') return mo
def kick_off_user(self, reason, kicked_uid, kicker_uid=None): evt = [{ 'type': Enum.table_event_kick_off, 'userId': kicked_uid, 'reason': reason, }] if kicker_uid and kicker_uid > 0: evt[0]['kicker'] = kicker_uid self.notify_event(evt) registry = Context.get_module(self.gid, 'registry') player = registry.get_player(kicked_uid) if player: player.leave_table() return 0
def __get_history_exchange_list(self, uid, gid): _list = [] all_history = Context.RedisCluster.hash_getall(uid, 'history:%d:%d' % (gid, uid)) if all_history: keys = all_history.keys() values = Context.RedisMix.hash_mget('game.%d.exchange.record' % gid, *keys) for k, v in zip(keys, values): v = Context.json_loads(v) if v and v['type'] == 'exchange': _r = { 'ts': v['ts'], 'desc': v['desc'], 'cost': v['cost'], 'state': int(all_history[k]) } if 'phone' in v: _r['phone'] = v['phone'] _list.append(_r) return _list
def load_config(cls, gid): for roomtype in (201, 202, 203): conf = Context.Configure.get_game_item_json( gid, 'timeline.%d.config' % roomtype) conf = Context.copy_json_obj(conf) for k in ('boss', 'tide', 'bounty'): conf[k] = [int(t * 10) for t in conf[k]] cls.timeline_map[roomtype] = conf conf = Context.Configure.get_game_item_json( gid, 'fish.%d.config' % roomtype) kvs = {} for k in ('common', 'boss', 'bonus'): types = [item['type'] for item in conf[k]] kvs[k] = types kvs['little'] = kvs['common'][:9] kvs['middle'] = kvs['common'][9:] kvs['bonus'] = kvs['bonus'][:-1] # 红龙任务中红龙奖金鱼去掉 kvs['boss'] = kvs['boss'][:-1] # 红龙任务中红龙去掉 cls.fish_info_map[roomtype] = kvs
def onUserInfo(self, uid, gid, mi): mo = MsgPack(Message.MSG_SYS_USER_INFO | Message.ID_ACK) account = Context.get_module(gid, 'account', Account) data = account.get_user_info(uid, gid) if not data: mo.set_error(-1, 'no user info') else: mo.update_param(data) login = mi.get_param('login') if login: account.on_user_login(uid, gid) result, loc = Online.get_location(uid, gid) if result and loc: loc = { 'roomType': loc['room_type'], 'tableId': loc['table_id'], 'seatId': loc['seat_id'] } mo.set_param('loc', loc) return Context.GData.send_to_connect(uid, mo)
def onInnerMessage(self, cmd, mi, *args, **kwargs): uid = mi.get_uid() gid = mi.get_gid() raw = mi.get_message() mi = MsgPack.unpack(cmd, raw) gid = mi.get_param('gameId', gid) with Context.GData.user_locker[uid]: if cmd == Message.MSG_SYS_USER_INFO | Message.ID_REQ: self.onUserInfo(uid, gid, mi) elif cmd == Message.MSG_SYS_GAME_INFO | Message.ID_REQ: self.onGameInfo(uid, gid, mi) elif cmd == Message.MSG_SYS_SERVER_INFO | Message.ID_REQ: self.onServerInfo(uid, gid, mi) elif cmd == Message.MSG_SYS_LED | Message.ID_REQ: self.onLed(uid, gid, mi) else: entity = Context.get_module(gid, 'entity') if entity: entity.onMessage(cmd, uid, gid, mi) else: Context.Log.warn('error msg', cmd, mi)
def get_shop_config(self, uid, gid): product_config = Context.Configure.get_game_item_json( gid, 'product.config') shop_config = Context.Configure.get_game_item_json(gid, 'shop.config') if not shop_config or not product_config: return {} product_config = Context.copy_json_obj(product_config) attrs = list(shop_config['chip']) attrs.extend(shop_config['first']) fileds = [] for attr in attrs: fileds.append('product_%s' % attr) fileds.append('reset_%s' % attr) counts = Context.Data.get_game_attrs(uid, gid, fileds) kvs = Tool.make_dict(attrs, counts[::2]) reset_kvs = Tool.make_dict(attrs, counts[1::2]) info = {} for k, pids in shop_config.iteritems(): group = [] for pid in pids: product = product_config[pid] del product['name'] if k in ('chip', 'diamond'): del product['content'] if 'first' in product: del product['first'] if k == 'first' and kvs[pid] is None: product['first'] = 1 elif k == 'chip' and (kvs[pid] is None or reset_kvs[pid]): product['first'] = 1 product['id'] = pid group.append(product) info[k] = group info['card'] = info['card'][0] # 只要一个 if not counts[-2]: info['first'] = info['first'][1] # 只要一个 return info
def query_history_phone(self, gid, mi, request): start = mi.get_param('start') end = mi.get_param('end') start_day = Time.str_to_datetime(start, '%Y-%m-%d') end_day = Time.str_to_datetime(end, '%Y-%m-%d') uid_seq_map, all_seq_list = {}, [] while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') records = Context.RedisStat.hash_getall('history:%d:%s' % (gid, fmt)) for seq, uid in records.iteritems(): if uid not in uid_seq_map: uid_seq_map[uid] = [] uid_seq_map[uid].append(int(seq)) all_seq_list.append(int(seq)) start_day = Time.next_days(start_day) _list = [] if all_seq_list: seq_record_map = Context.RedisMix.hash_mget_as_dict('game.%d.exchange.record' % gid, *all_seq_list) for uid, seq_list in uid_seq_map.iteritems(): states = Context.RedisCluster.hash_mget(uid, 'history:%d:%s' % (gid, uid), *seq_list) for seq, state in zip(seq_list, states): if state is not None and seq in seq_record_map: record = Context.json_loads(seq_record_map[seq]) if record['type'] == 'exchange' and record['to'] == 'phone': record = { 'uid': int(uid), 'ts': record['ts'], 'count': record['count'], 'phone': record['phone'], 'state': int(state), 'seq': seq, } _list.append(record) mo = MsgPack(0) mo.set_param('exchange', _list) return mo
def get_raffle_config(self, uid, gid): raffle_config = Context.Configure.get_game_item_json( gid, 'raffle.config') raffle_config = Context.copy_json_obj(raffle_config) loop_config = raffle_config['loop'] raffle_config = raffle_config['config'] for item in raffle_config: for i, reward in enumerate(item['reward']): item['reward'][i] = reward[1] class_pool, loop_times = Context.Daily.get_daily_data( uid, gid, 'fake.bonus.count', 'bonus.loop.times') class_pool = Tool.to_int(class_pool, 0) loop_times = Tool.to_int(loop_times, 0) if loop_times > len(loop_config) - 1: this_count = loop_config[-1] else: this_count = loop_config[loop_times] info = {'config': raffle_config} bonus_pool = Context.Data.get_game_attr_int(uid, gid, 'bonus_pool', 0) info['pool'] = bonus_pool info['progress'] = [class_pool, this_count] return info