def query_summary(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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') kvs = Context.Stat.get_day_data(gid, fmt) channel_info = {} for k, v in kvs.iteritems(): if (k.endswith('.new.device.count') or k.endswith('.new.user.count') or k.endswith('.login.user.count') or k.endswith('.new.pay.user.count') or k.endswith('.new.pay.user.pay_total') or k.endswith('.pay.user.count') or k.endswith('.pay.user.pay_total') or k.endswith('.user.pay.times')): channel, key = k.split('.', 1) if channel not in channel_info: channel_info[channel] = {} channel_info[channel][key] = int(v) mo.set_param(fmt, channel_info) start_day = Time.next_days(start_day) return mo
def query_pay_detail(self, gid, mi, request): conf = Context.Configure.get_game_item_json(gid, 'product.config') pids = [] for pid in conf.iterkeys(): pids.append('product_' + pid) 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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') timess = Context.Stat.get_day_data(gid, fmt, *pids) kvs = {'product_100646': 0, 'product_100710': 0} for k, v in zip(pids, timess): pid = k.replace('product_', '') if pid in ('100646', '100647', '100648', '100649', '100650', '100651', '100652', '100653', '100654', '100655'): kvs['product_100646'] += Tool.to_int(v, 0) elif pid in ('100710', '100711', '100712', '100713', '100714', '100715', '100716'): kvs['product_100710'] += Tool.to_int(v, 0) else: kvs[k] = Tool.to_int(v, 0) mo.set_param(fmt, kvs) start_day = Time.next_days(start_day) return mo
def query_diamond_produce(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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') kvs = Context.Stat.get_day_data(gid, fmt) _kvs = {} total, task_total, fall_total = 0, 0, 0 for k, v in kvs.iteritems(): if k.startswith('in.diamond.'): if k.startswith('in.diamond.task.reward.'): task_total += int(v) elif k.startswith('in.diamond.fish.fall.'): fall_total += int(v) else: _kvs[k] = int(v) total += int(v) _kvs['in.diamond.task.reward'] = task_total _kvs['in.diamond.fish.fall'] = fall_total _kvs['in.diamond.buy.product'] = int(kvs.get('in.diamond.buy.product', 0)) _kvs['total'] = total mo.set_param(fmt, _kvs) start_day = Time.next_days(start_day) return mo
def query_diamond_consume(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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') kvs = Context.Stat.get_day_data(gid, fmt) _kvs, total = {}, 0 for k, v in kvs.iteritems(): if k.startswith('out.diamond.'): if k.startswith('out.diamond.inner.buy.'): k = 'out.diamond.buy.' + k[-3:] elif k.startswith('out.diamond.table.buy.'): k = 'out.diamond.buy.' + k[-3:] if k in _kvs: _kvs[k] += int(v) else: _kvs[k] = int(v) total += int(v) _kvs['total'] = total mo.set_param(fmt, _kvs) start_day = Time.next_days(start_day) return mo
def query_chip_produce(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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') kvs = Context.Stat.get_day_data(gid, fmt) task_total, catch_total = 0, 0 _kvs = {} for k, v in kvs.iteritems(): if k.startswith('in.chip.'): if k.startswith('in.chip.task.reward.'): task_total += int(v) elif k.startswith('in.chip.catch.fish.'): catch_total += int(v) else: _kvs[k] = int(v) _kvs['in.chip.task.reward'] = task_total _kvs['in.chip.catch.fish'] = catch_total _kvs['in.chip.buy.product'] = int(kvs.get('in.chip.buy.product', 0)) mo.set_param(fmt, _kvs) start_day = Time.next_days(start_day) return mo
def query_chip_consume(self, gid, mi, request): room_types = (201, 202, 203) mini_games = (10002, 10003) fields = ['out.chip.attack'] for room_type in room_types: fields.append('out.chip.game.shot.bullet.%d' % room_type) for game in mini_games: fields.append('out.chip.game.%d' % game) 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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') chips = Context.Stat.get_day_data(gid, fmt, *fields) attack = Tool.to_int(chips[0], 0) info = [] for chip in chips[1:]: if chip: info.append(int(chip)) else: info.append(0) info[2] += attack mo.set_param(fmt, info) start_day = Time.next_days(start_day) return mo
def query_chip_pump(self, gid, mi, request): room_types = (201, 202, 203) fields = [] for room_type in room_types: fields.append('out.chip.pump.%d' % room_type) fields.append('out.chip.buff.pump.%d' % room_type) fields.append('out.chip.red.pump.%d' % room_type) 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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') chips = Context.Stat.get_day_data(gid, fmt, *fields) info = [] for i in range(0, len(chips), 3): total = 0 for j in range(3): if chips[i + j]: total += int(chips[i + j]) info.append(total) mo.set_param(fmt, info) start_day = Time.next_days(start_day) return mo
def query_user_info(self, gid, mi, request): uid = mi.get_param('userId') user_attrs = ['createTime', 'deviceId', 'nick', 'idType', 'userName', 'channel', 'platform'] kvs = Context.Data.get_attrs_dict(uid, user_attrs) game_attrs = ['pay_total', 'session_login', 'exp', 'barrel_level', 'chip', 'diamond', 'in_chip', 'out_chip'] _kvs = Context.Data.get_game_attrs_dict(uid, gid, game_attrs) kvs.update(_kvs) kvs['chip'] = int(kvs.get('chip', 0)) kvs['in_chip'] = int(kvs.get('in_chip', 0)) kvs['out_chip'] = int(kvs.get('out_chip', 0)) kvs['diamond'] = int(kvs.get('diamond', 0)) dt = Time.str_to_datetime(kvs['createTime'], '%Y-%m-%d %X.%f') kvs['createTime'] = Time.datetime_to_str(dt, '%Y-%m-%d %X') dt = Time.str_to_datetime(kvs['session_login'], '%Y-%m-%d %X.%f') kvs['session_login'] = Time.datetime_to_str(dt, '%Y-%m-%d %X') if int(kvs['idType']) == 13: kvs['phone'] = kvs['userName'] kvs['pay_total'] = int(kvs.get('pay_total', 0)) kvs['vip_level'] = FishAccount.get_vip_level(uid, gid, pay_total=int(kvs['pay_total'])) exp = int(kvs['exp']) kvs['level'], _ = FishAccount.get_exp_info(uid, gid, exp=exp) barrel_level = int(kvs['barrel_level']) kvs['barrel_multiple'] = FishAccount.trans_barrel_level(gid, barrel_level) l = (201, 202, 203, 204, 205, 211, 212, 213, 214, 215, 216, 217, 218, 219) _list = FishProps.get_props_list(uid, gid, l) props_map = dict(_list) props_list = [] for i in l: count = props_map.get(i, 0) props_list.append(count) kvs['props'] = props_list mo = MsgPack(0) mo.update_param(kvs) return mo
def query_carrying(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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') _login, _total = Context.Stat.get_day_data(gid, fmt, 'login.carrying.volume.chip', 'carrying.volume.chip') _login = Tool.to_int(_login, 0) _total = Tool.to_int(_total, 0) mo.set_param(fmt, {'carrying': _login, 'total': _total}) start_day = Time.next_days(start_day) return mo
def query_shot(self, gid, mi, request): room_types = (201, 202, 203) fields = [] for room_type in room_types: fields.append('shot.times.%d' % room_type) 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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') values = Context.Stat.get_day_data(gid, fmt, *fields) info = [] for v in values: if v: info.append(int(v)) else: info.append(0) mo.set_param(fmt, info) start_day = Time.next_days(start_day) return mo
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 __create_order(cls, uid, gid, channel, productId, **kwargs): all_product = Context.Configure.get_game_item_json( gid, 'product.config') if productId not in all_product: return cls.invalid_product, 'invalid productId' product = all_product[productId] dt = Time.datetime() order_id = cls.get_new_order_id(gid, dt) kvs = { 'userId': uid, 'gameId': gid, 'channel': channel, 'productId': productId, 'cost': product['price'], 'state': cls.state_create, 'createTime': Time.datetime_to_str(dt, '%Y-%m-%d %X.%f') } kvs.update(kwargs) Context.Log.report('order.create: [%d, %d, %s, %s]' % (uid, gid, order_id, kvs)) Context.RedisPay.hash_mset('order:' + order_id, **kvs) Context.RedisStat.list_rpush('order:%d:%d:user' % (gid, uid), order_id) Context.RedisStat.list_rpush( 'order:%d:%s:daily' % (gid, dt.strftime('%Y-%m-%d')), order_id) info = { 'orderId': order_id, 'productId': productId, 'title': product['name'], 'desc': '', 'cost': product['price'], 'price': product['price'], } return 0, info
def query_raffle(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') eggs = (211, 212, 213, 214) fileds = ['in.chip.bonus.raffle', 'in.diamond.bonus.raffle', 'in.coupon.bonus.raffle'] for egg in eggs: fileds.append('in.props.%d.bonus.raffle' % egg) mo = MsgPack(0) while start_day <= end_day: kvs = {} fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') values = Context.Stat.get_day_data(gid, fmt, *fileds) kvs['chip'] = Tool.to_int(values[0], 0) kvs['diamond'] = Tool.to_int(values[1], 0) kvs['coupon'] = Tool.to_int(values[2], 0) egg_list = [] for egg in values[3:]: egg_list.append(Tool.to_int(egg, 0)) kvs['egg'] = egg_list mo.set_param(fmt, kvs) start_day = Time.next_days(start_day) return mo
def query_egg_fall(self, gid, mi, request): room_types = (201, 202, 203) props_ids = (211, 212, 213) fields = [] for pid in props_ids: for room_type in room_types: fields.append('in.props.%d.fish.fall.%d' % (pid, room_type)) cnt_fields = [] for pid in props_ids: cnt_fields.append('user.count.get.props.%d' % pid) 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') mo = MsgPack(0) while start_day <= end_day: fmt = Time.datetime_to_str(start_day, '%Y-%m-%d') eggs = Context.Stat.get_day_data(gid, fmt, *fields) props_info = [] for i in range(0, len(eggs), len(room_types)): fall = 0 for j in range(len(room_types)): if eggs[i+j]: fall += int(eggs[i+j]) props_info.append(fall) gets = Context.Stat.get_day_data(gid, fmt, *cnt_fields) get_total = 0 for cnt in gets: if cnt: get_total += int(cnt) mo.set_param(fmt, {'fall': props_info, 'get': get_total}) start_day = Time.next_days(start_day) return mo