Example #1
0
def _bind_new_platform(request, platform_name, platform_openId, old_account, result):
    subarea = request.REQUEST.get("subarea", "1")
    fg = False
    msg = ''
    pid = md5.md5(platform_name + str(platform_openId)).hexdigest()
    #检查新账户是否已经被关联
    account_mapping_obj = AccountMapping.get(pid)
    if account_mapping_obj:
        msg = get_msg('login', 'already_bind')
        return fg, pid, msg
    #检查被绑定用户类型是否是oc
    old_user_obj = UserBase.get(old_account.get_subarea_uid(subarea))
    if old_user_obj.baseinfo['platform'] != 'oc':
        msg = get_msg('login', 'already_bind')
        return fg, pid, msg
    fg = True
    #创建新账户,将旧账户uid关联到新账户后,删除旧账户
    account_mapping_obj = AccountMapping.create(pid)
    account_mapping_obj.subarea_uids = old_account.subarea_uids
    account_mapping_obj.put()
    #删除oc账户
    old_account.delete()
    #给request安装用户
    request.rk_user = UserBase._install(pid, platform_name, subarea=subarea)
    request.rk_user.baseinfo['pid'] = pid
    request.rk_user.baseinfo['platform'] = platform_name
    request.rk_user.baseinfo['bind_time'] = int(time.time())
    request.rk_user.put()
    update_function = request.rk_user.update_platform_openid(platform_name, platform_openId)
    if update_function:
        update_function(result)
    return fg, pid, msg
Example #2
0
def auth_bind_for_qq(request,access_token,openid,bind_access_token,bind_openid):
    """论证qq开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    user_info_url = 'https://open.t.qq.com/api/user/info?format=json&oauth_consumer_key=%s&access_token=%s&openid=%s&oauth_version=2.a&scope=all' % (settings.QQ_APP_ID,access_token,openid)

    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login','invalid_bind')
        return fg,msg,pid
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(str(user_info_url), timeout=12)
        rc = url_request.code
        res  = url_request.read()
        res = res.strip()
        res = res.replace('false','False')
        res = res.replace('true','True')
        res = res.replace('null','None')
        if rc == 200:
            exec('result = %s' % res)
            if not result['ret']:
                get_openid = str(result['data']['openid'])
                if get_openid == openid:
                    fg, pid, msg = _bind_new_platform(request, 'qq', openid, account, result)
                    return fg, pid, msg
    else:
        msg = get_msg('login','invalid_bind')
    return fg,pid,msg
Example #3
0
def auth_token_for_oc(request,access_token,openid,uuid,mktid,version,client_type,macaddr,idfa,ios_ver):
    """论证无账号用户
    """
    print "debug_guochen access_token, openid", access_token, openid
    fg = False
    pid = ''
    msg = ''
    subarea = request.REQUEST.get("subarea", "1") or '1'
    #没有openid时,检查后控制自动分配id的开头是否开启,如果已经关闭,返回提示
    if not openid:
       if game_config.system_config.get('account_assign_switch'):
           fg = True
           pid = get_uuid()
           #验证成功,安装用户
           request.rk_user = UserBase._install(pid,'oc',uuid,mktid,version,client_type,macaddr,idfa,ios_ver, subarea=subarea)
           access_token = get_upwd()
           request.rk_user.account.update_info(pid, access_token)
       else:
           msg = get_msg('login','cannot_register')
           return fg,pid,msg
    if not check_openid(openid):
        msg = get_msg('login','cannot_register')
        return fg,pid,msg
    #有openid时,检查access_token是否正确
    account = AccountMapping.get(openid)
    if not account: 
        if game_config.system_config.get('account_assign_switch'):
            fg = True
            pid = openid
            #验证成功,安装用户
            request.rk_user = UserBase._install(pid,'oc',uuid,mktid,version,client_type,macaddr,idfa,ios_ver, subarea=subarea)
            # debug 模式下,将传入的access_token 作为新用户taken
            if settings.DEBUG is True:
                access_token = access_token or get_upwd()
            else:
                access_token = get_upwd()
            request.rk_user.account.update_info(pid, access_token)
            account = request.rk_user.account
            print "debug_guochen_new_token pid, access_token, openid", pid, access_token, openid
        else:
            msg = get_msg('login','cannot_register')
            return fg,pid,msg

    elif account.access_token == access_token:
        fg = True
        pid = openid
        #验证成功,安装用户
        request.rk_user = UserBase._install(pid, 'oc', subarea=subarea)
    else:
        print "debug_guochen_erro_token pid, access_token, openid", pid, access_token, openid
        msg = get_msg('login','session_overdue')
    return fg,pid,msg
Example #4
0
def __get_uid(platform, openid, pid, subarea):
    """取得uid

    根据平台、openid等信息取得对应的uid

    Returns:
        玩家uid, 若没有符合条件的uid则返回空字符串
    """

    if not pid:
        if platform == 'oc':
            pid = openid
        else:
            pid = md5.md5(platform + str(openid)).hexdigest()
    ac = AccountMapping.get(pid)
    return ac.get_subarea_uid(subarea) if ac else ''
Example #5
0
def auth_bind_for_sina(request,access_token,openid,bind_access_token,bind_openid):
    """论证sina开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    SINA_OPEN_URL = 'https://api.weibo.com/2/account/get_uid.json'
    request_url = '%s?access_token=%s' % (SINA_OPEN_URL, str(access_token))
    user_info_url = 'https://api.weibo.com/2/users/show.json?access_token=%s&uid=%s'

    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login','invalid_bind')
        return fg,msg,pid
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(request_url, timeout=12)
        rc = url_request.code
        res  = url_request.read()
        if rc == 200:
            res = res.strip()
            res = res.replace('false','False')
            res = res.replace('true','True')
            res = res.replace('null','None')
            exec('result = %s' % res)
            get_openid = str(result.get('uid'))
            if get_openid == openid:
                fg, pid, msg = _bind_new_platform(request, 'sina', openid, account, result)

                #调用平台的api,取得用户名等信息,并且更新
                user_info_url = user_info_url % (str(access_token),str(openid))
                #更新用户平台信息不影响绑定操作
                try:
                    res = urllib2.urlopen(str(user_info_url), timeout=12).read()
                    res = res.strip()
                    res = res.replace('false','False')
                    res = res.replace('true','True')
                    res = res.replace('null','None')
                    exec('result = %s' % res)
                    request.rk_user.update_user_from_sina(result)
                except:
                    pass
                return fg,pid,msg
    else:
        msg = get_msg('login','invalid_bind')
    return fg,pid,msg
Example #6
0
def auth_bind_for_fb(request, access_token, openid, bind_access_token,
                     bind_openid):
    """论证fb开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    user_info_url = 'https://graph.facebook.com/me?access_token=%s' % str(
        access_token)

    #检查被绑定的oneclick账号是否合法
    url_request = urllib2.urlopen(str(user_info_url), timeout=12)
    rc, res = url_request.code, url_request.read()
    res = res.strip()
    res = res.replace('false', 'False')
    res = res.replace('true', 'True')
    res = res.replace('null', 'None')
    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login', 'invalid_bind')
        return fg, pid, msg
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(str(user_info_url), timeout=12)
        rc, res = url_request.code, url_request.read()
        if rc == 200:
            res = res.strip()
            res = res.replace('false', 'False')
            res = res.replace('true', 'True')
            res = res.replace('null', 'None')
            exec('result = %s' % res)
            get_openid = str(result.get('id'))
            if get_openid == openid:
                fg, pid, msg = _bind_new_platform(request, 'fb', openid,
                                                  account, result)
                return fg, pid, msg
    else:
        msg = get_msg('login', 'invalid_bind')
    return fg, pid, msg
Example #7
0
def auth_bind_for_fb(request,access_token,openid,bind_access_token,bind_openid):
    """论证fb开放平台账号绑定
    """
    fg = False
    pid = ''
    msg = ''
    user_info_url = 'https://graph.facebook.com/me?access_token=%s' % str(access_token)

    #检查被绑定的oneclick账号是否合法
    url_request = urllib2.urlopen(str(user_info_url), timeout=12)
    rc,res = url_request.code, url_request.read()
    res = res.strip()
    res = res.replace('false','False')
    res = res.replace('true','True')
    res = res.replace('null','None')
    #检查被绑定的oneclick账号是否合法
    if not check_openid(bind_openid):
        msg = get_msg('login','invalid_bind')
        return fg,pid,msg
    account = AccountMapping.get(bind_openid)
    if account and account.access_token == bind_access_token:
        url_request = urllib2.urlopen(str(user_info_url), timeout=12)
        rc,res = url_request.code, url_request.read()
        if rc == 200:
            res = res.strip()
            res = res.replace('false','False')
            res = res.replace('true','True')
            res = res.replace('null','None')
            exec('result = %s' % res)
            get_openid = str(result.get('id'))
            if get_openid == openid:
                fg, pid, msg = _bind_new_platform(request, 'fb', openid, account, result)
                return fg,pid,msg
    else:
        msg = get_msg('login','invalid_bind')
    return fg,pid,msg
Example #8
0
 def get_uid(cls, pid, platform, subarea):
     rk_uid = AccountMapping.get_user_id(pid, subarea)
     return rk_uid
Example #9
0
 def account(self):
     """用户账户信息
     """
     if not self._account:
         self._account = AccountMapping.get(self.pid)
     return self._account
Example #10
0
def view_user(request):
    """
     更新用户信息
    """

    uid = request.GET.get('uid', '').strip()
    if not uid:
        pid = request.GET.get('pid', '').strip()
        if not pid:
            username = request.GET.get('username', '')
            if not username:
                return HttpResponseRedirect('/admin/user/?status=1')
            try:
                uid = ocapp.mongo_store.mongo.db['username'].find(
                    {'name': username})[0]['uid']
            except:
                return HttpResponseRedirect('/admin/user/?status=1')
        else:
            account = AccountMapping.get(pid)
            if not account:
                return HttpResponseRedirect('/admin/user/?status=1')
            uid = account.uid

    user = UserBase.get(uid)
    if not user or not user.account:
        return HttpResponseRedirect('/admin/user/?status=1')

    ##### view raw db data
    check_raw_db_data = request.GET.get('check_raw_db_data', '').strip()
    db_data_name = request.GET.get('db_data_name', '').strip()

    #using exec/eval, need consider safety, or user could provide malicious
    #string, do bad behavior
    if db_data_name and db_data_name not in raw_db_data_list:
        return HttpResponse(
            'Wrong raw db data name, or not allowed to show yet')

    if check_raw_db_data in ('on', 'checked'):
        data = {'user': {}}
        data['user']['uid'] = uid
        data['user']['username'] = user.username
        module_name, data_class, db_data = db_data_name.split('.')

        #exec('from apps.models.' + module_name + ' import ' + data_class)
        exec 'from apps.models.' + module_name + ' import ' + data_class in globals(
        ), locals()

        if data_class == 'UserMail':
            raw_db_data = eval(data_class + '.hget("' + uid + '", "' + uid +
                               '").' + db_data)
        else:
            raw_db_data = eval(data_class + '.get(' + uid + ').' + db_data)

        data['db_data_name'] = db_data_name
        data['raw_db_data'] = pformat(raw_db_data)
        return render_to_response('user/view_raw.html', data,
                                  RequestContext(request))
    ###### end view raw db

    user_card_obj = UserCards.get(user.uid)
    user_equips_obj = UserEquips.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_pack_obj = UserPack.get_instance(uid)

    data = {
        'user_property_obj': user_property_obj,
        'user': user,
        'deck_cards': [],
        'other_cards': [],
        'add_time': timestamp_toString(user.add_time),
        'last_login_time': timestamp_toString(user.user_property.login_time),
        'login_record': UserLogin.get(uid).login_info['login_record'],
    }
    if not user.client_type:
        data['client_type'] = 'appstore_ios'
    else:
        data['client_type'] = user.client_type
    all_cards = []

    all_cids = game_config.card_config.keys()

    all_cids_cp = copy.deepcopy(game_config.card_config)
    for k, v in all_cids_cp.iteritems():
        all_cids_cp[k]['no'] = int(k.split('_')[0])
    all_cids.sort(key=lambda x: (all_cids_cp[x]['no']))
    for cid in all_cids:
        all_cards.append(Card.get(cid))
    data['all_cards'] = all_cards
    #用户当前战场信息
    user_dungeon_obj = UserDungeon.get_Ex(user.uid)
    #pvp_obj = UserPvp.getEx(user.uid)
    #pvp 排名
    top_model = pvp_redis.get_pvp_redis('1')
    rank = top_model.rank(uid)
    #pvp_obj.rank = rank+1 if rank != None else 0
    #data['pvp'] = pvp_obj
    data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current']
    #配置中的所有战场
    data['all_dungeon'] = []
    floor_ids = sorted(
        map(lambda x: int(x), game_config.normal_dungeon_config.keys()))
    for floor_id in floor_ids:
        for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)]
                              ['rooms'].keys()):
            data['all_dungeon'].append('%d-%s' % (floor_id, room_id))
    #用户已经达到最深层时
    if '%s-%s' % (data['current_dungeon']['floor_id'], data['current_dungeon']
                  ['room_id']) == data['all_dungeon'][-1]:
        data['max_dungeon'] = True
    else:
        data['max_dungeon'] = False
        now_index = data['all_dungeon'].index(
            '%s-%s' % (data['current_dungeon']['floor_id'],
                       data['current_dungeon']['room_id']))
        data['all_dungeon'] = data['all_dungeon'][now_index + 1:]

    deck_num = 0
    for card in user_card_obj.deck:
        if card:
            ucid = card['ucid']
            card_info = user_card_obj.cards[ucid]
            this_card = Card.get_from_dict(card_info)
            this_card.ucid = ucid
            this_card.is_leader = card.get('leader', 0)
            eid = ''
            if eid:
                this_card.equip = game_config.equip_config[eid]['name']
            else:
                this_card.equip = ''
            this_card.now_exp = card_info['exp']
            data['deck_cards'].append(this_card)
            deck_num += 1
        else:
            data['deck_cards'].append(None)

    data['deck_num'] = deck_num
    other_ucids = user_card_obj.cards.keys()
    for card in user_card_obj.deck:
        ucid = card.get('ucid')
        if ucid:
            other_ucids.remove(ucid)
    for ucid in other_ucids:
        card_info = user_card_obj.cards[ucid]
        this_card = Card.get_from_dict(card_info)
        this_card.ucid = ucid
        this_card.now_exp = card_info['exp']
        eid = ''
        if eid:
            this_card.equip = game_config.equip_config[eid]['name']
        else:
            this_card.equip = ''
        data['other_cards'].append(this_card)
    #重新整理 下编队
    user_card_obj.decks

    #装备
    equips = user_equips_obj.equips
    eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips]
    data['user_equips'] = [
        game_config.equip_config[eid_dict['eid']] for eid_dict in eqids_dict
    ]
    all_equips_tag = sorted(
        [int(i.split('_')[0]) for i in game_config.equip_config.keys()])
    data['all_equips'] = [(i, game_config.equip_config[str(i) + '_equip'])
                          for i in all_equips_tag]

    #mat
    data['user_materials'] = {
        mid: {
            'name': game_config.material_config[mid]['name'],
            'num': user_pack_obj.materials[mid]
        }
        for mid in user_pack_obj.materials
    }
    all_materials_tag = sorted(
        [int(i.split('_')[0]) for i in game_config.material_config.keys()])
    data['all_materials'] = [(i, game_config.material_config[str(i) + '_mat'])
                             for i in all_materials_tag]
    #
    data['charge_sum_money'] = user.user_property.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find(
        {'uid': uid})[-1] if ChargeRecord.find({'uid': uid}) else {}

    ######将魂系统##############

    data.update(soul.get_all(user, None)[1])
    for sid, soul_conf in data['normal_souls'].items():
        soul_conf['name'] = game_config.card_config[sid].get(
            'star', '') + u'星 ' + game_config.card_config[sid].get('name',
                                                                   '') + u' 将魂'
    #data["index_list"] = request.index_list
    return render_to_response('user/view.html', data, RequestContext(request))
Example #11
0
def edit_user(request):
    """
    编辑用户页
    """
    uid = request.GET.get('uid', '').strip()
    if not uid:
        pid = request.GET.get('pid', '').strip()
        if not pid:
            username = request.GET.get('username', '')
            if not username:
                return HttpResponseRedirect('/admin/user/?status=1')
            try:
                uid = ocapp.mongo_store.mongo.db['username'].find(
                    {'name': username})[0]['uid']
            except:
                return HttpResponseRedirect('/admin/user/?status=1')
        else:
            account = AccountMapping.get(pid)
            if not account:
                return HttpResponseRedirect('/admin/user/?status=1')
            uid = account.uid

    user = UserBase.get(uid)
    if not user or not user.account:
        return HttpResponseRedirect('/admin/user/?status=1')

    user_equips_obj = UserEquips.get_instance(uid)
    user_pack_obj = UserPack.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_card_obj = UserCards.get(user.uid)
    user_real_pvp_obj = user.user_real_pvp
    game_config.set_subarea(user.subarea)

    data = {
        'deck_cards': [],
        'other_cards': [],
    }
    if not user.client_type:
        data['client_type'] = 'appstore_ios'
    else:
        data['client_type'] = user.client_type
    all_cards = []

    all_cids = game_config.card_config.keys()

    all_cids_cp = copy.deepcopy(game_config.card_config)
    for k, v in all_cids_cp.iteritems():
        all_cids_cp[k]['no'] = int(k.split('_')[0])
    all_cids.sort(key=lambda x: (all_cids_cp[x]['no']))
    for cid in all_cids:
        all_cards.append(Card.get(cid))
    data['all_cards'] = all_cards
    #用户当前战场信息
    user_dungeon_obj = UserDungeon.get_instance(user.uid)

    #充值信息
    data['charge_sum_money'] = user_property_obj.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find(
        {'uid': uid})[-1] if ChargeRecord.find({'uid': uid}) else {}

    ######神秘商店   代码往前方 因为此操作会改变玩家武将,物品等信息##############
    #   刷新  物品列表
    if request.POST.get('refresh_mystery_store', ''):
        store_type = request.POST.get('store_type')
        params = {}
        mystery_store.refresh_store_by_self(user, params)
    #   购买  物品
    if request.POST.get('buy_mystery_store_goods', ''):
        store_type = request.POST.get('store_type')
        goods_index = int(request.POST.get('goods_index'))
        params = {
            'store_type': store_type,
            'goods_index': goods_index,
        }
        mystery_store.buy_store_goods(user, params)
######Pk商店   ##
#   刷新  物品列表
    if request.POST.get('refresh_pk_store', ''):
        pk_store.refresh_store_by_self(user, {})
    #   购买  物品
    if request.POST.get('buy_pk_store_goods', ''):
        goods_index = int(request.POST.get('goods_index'))
        params = {
            'goods_index': goods_index,
        }
        pk_store.buy_store_goods(user, params)


####################

    moderator = auth.get_moderator_by_request(request)
    qa_edit = 'qa edited by ' + str(moderator.username)

    #提交状态
    if request.method == "POST":
        state = int(request.POST.get("state", "0"))
        state = bool(state)
        #冻结
        if state != user.in_frozen:
            if state:
                user.froze()
            #解冻
            else:
                user.unfroze()
        #删除账号
        if request.POST.get('del_user', ''):
            if not user.account:
                return HttpResponseRedirect('/admin/user/?status=1')
            user.account.delete()
        if request.POST.get('add_gold', ''):
            add_gold = int(request.POST.get('add_gold'))
            if add_gold > 0:
                user_property_obj.add_gold(add_gold, where=qa_edit)
            else:
                user_property_obj.minus_gold(add_gold)
        #增加元宝
        if request.POST.get('add_coin', ''):
            add_coin = int(request.POST.get('add_coin'))
            if add_coin > 0:
                user_property_obj.add_coin(add_coin, where=qa_edit)
            else:
                user_property_obj.minus_coin(add_coin, where=qa_edit)
        #增加 经验点
        if request.POST.get('add_card_point', ''):
            add_card_point = int(request.POST.get('add_card_point'))
            if add_card_point > 0:
                user_property_obj.add_card_exp_point(add_card_point, qa_edit)
            else:
                user_property_obj.minus_card_exp_point(add_card_point, qa_edit)
        #增加经验
        if request.POST.get('add_exp', ''):
            add_exp = int(request.POST.get('add_exp'))
            user_property_obj.add_exp(add_exp, where=qa_edit)
        #更改等级
        if request.POST.get('modify_lv', ''):
            lv = request.POST.get('modify_lv')
            lv_exp = game_config.user_level_config[lv]['exp']
            now_exp = user_property_obj.property_info['exp']
            user_property_obj.add_exp(lv_exp - now_exp, where=qa_edit)
        # 增加pk 积分
        if request.POST.get('add_pk_pt', 0):
            pvp_pt = int(request.POST.get('add_pk_pt'))
            user_real_pvp_obj.add_pt(pvp_pt)
        # 加功勋
        if request.POST.get('add_honor', ''):
            honor = int(request.POST.get('add_honor'))
            urp = UserRealPvp.get(user.uid)
            urp.add_honor(honor, where=qa_edit)
        # 加战魂
        if request.POST.get('add_fight_soul', ''):
            fight_soul_num = int(request.POST.get('add_fight_soul'))
            user_property_obj.add_fight_soul(fight_soul_num, where=qa_edit)
        #发邮件
        if request.POST.get('mail_title') or request.POST.get('mail_goods'):
            from apps.models.user_mail import UserMail
            from apps.common import utils
            sid = 'system_%s' % (utils.create_gen_id())
            mail_title = request.POST.get('mail_title', '')
            mail_content = request.POST.get('mail_content', '')
            goods_str = request.POST.get('mail_goods', '').strip()
            award = {}
            for goods_info in goods_str.split(";"):
                goods_info = goods_info.strip()
                print "debug guochen email", goods_info
                if not goods_info:
                    continue

                goods_id, num = goods_info.strip().split(":")
                award.setdefault(goods_id, 0)
                award[goods_id] += int(num)

            mailtype = 'system_qa'
            user_mail_obj = UserMail.hget(uid, sid)
            user_mail_obj.set_mail(mailtype=mailtype,
                                   title=mail_title,
                                   content=mail_content,
                                   award=award)

        # 修改vip等级
        if request.POST.get('modify_vip_lv'):
            vip_lv = request.POST.get('modify_vip_lv')
            vip_conf = game_config.user_vip_config.get(str(vip_lv))
            if vip_conf:
                coin = vip_conf['coin']
                user_property_obj.property_info["charge_coins"] = coin
                user_property_obj.put()

        #补武将
        if request.POST.get("add_card_ex", ""):
            user_card_obj = UserCards.get(user.uid)
            strCardInfo = request.POST.get("add_card_ex")
            lstCardInfo = strCardInfo.strip().split(";")
            for strAddCard in lstCardInfo:
                cid = strAddCard.split(":")[0]
                cid = cid.strip() + '_card'
                num = int(strAddCard.split(":")[1])
                for i in range(num):
                    clv = 1
                    user_card_obj.add_card(cid, clv, where=qa_edit)
        #增加武将
        if request.POST.getlist('add_card'):
            add_cids = request.POST.getlist('add_card')
            user_card_obj = UserCards.get(user.uid)
            for add_cid in add_cids:
                if add_cid in game_config.card_config:
                    clv = 1
                    user_card_obj.add_card(add_cid, clv, where=qa_edit)
        #增加武将经验
        if request.POST.get('add_card_exp', ''):
            add_exp = int(request.POST.get('add_card_exp'))
            ucid = request.POST.get('ucid')
            user_card_obj.add_card_exp(ucid, add_exp)

        #增加武将技能级别
        if request.POST.get('add_card_sk_lv', ''):
            ucid = request.POST.get('ucid')
            user_card_obj.add_card_sk_lv(ucid)
        #卖掉卡片
        if request.POST.get('sell_card', ''):
            ucid = request.POST.get('ucid')
            #this_card = Card.get(user_card_obj.cards[ucid]['cid'],user_card_obj.cards[ucid]['lv'])
            user_card_obj.del_card_info([ucid])
            #user.user_property.add_gold(this_card.sell_gold,where=qa_edit)
        #踢出队伍
        if request.POST.get('kick_deck', ''):
            kick_index = int(request.POST.get('deck_index'))
            if user_card_obj.deck[kick_index].get(
                    'ucid', '') != user_card_obj.get_leader(
                        user_card_obj.cur_deck_index):
                user_card_obj.deck[kick_index] = {}
                user_card_obj.put()
        #设置主将
        if request.POST.get('set_deck_main', ''):
            ucid = request.POST.get('ucid')
            find_fg = False
            for card in user_card_obj.deck:
                if card.get('leader', 0):
                    card['ucid'] = ucid
                    user_card_obj.put()
                    find_fg = True
                    break
            if not find_fg:
                user_card_obj.deck[0] = {'ucid': ucid, 'leader': 1}
                user_card_obj.put()

        #设置副将
        if request.POST.get('set_deck_sub', ''):
            ucid = request.POST.get('ucid')
            for card in user_card_obj.deck:
                if not card:
                    card['ucid'] = ucid
                    user_card_obj.put()
                    break

        #一键送所有武将碎片
        if request.POST.get('give_all_card_soul', ''):
            for cid in game_config.card_config:
                user_card_obj.add_card(cid, 1, where=qa_edit)
            user_card_obj.put()

        #一键送所有武将
        if request.POST.get('give_all_card', ''):
            #一键送所有武将
            for cid in all_cids:
                ucid = user_card_obj.add_card(cid, 1, where=qa_edit)[2]
        # if request.POST.get('give_all_card',''):
        #     user_card_obj.cards = {}
        #     user_card_obj.cards_info = {
        #                     "decks":[[{}] * 5] * 10,
        #                     "cur_deck_index":0,
        #                 }
        #     for eid in user_equips_obj.equips:
        #         if user_equips_obj.equips[eid].get("used_by"):
        #             user_equips_obj.equips[eid]['used_by'] = ''
        #     user_equips_obj.put()
        #     card_index = 0
        #     for cid in all_cids:
        #         clv = 1
        #         ucid = user_card_obj.add_card(cid,clv,where=qa_edit)[2]
        #         if card_index < 5:
        #             user_card_obj.deck[card_index]['ucid'] = ucid
        #         card_index += 1

        #一键删除军队外的所有武将
        if request.POST.get('del_other_card', ''):
            decks = []
            for deck in user_card_obj.decks:
                decks.extend(
                    [card['ucid'] for card in deck if card.get('ucid', '')])
            del_cids = filter(lambda x: x not in decks,
                              user_card_obj.cards.keys())
            user_card_obj.del_card_info(del_cids)
            for eid in user_equips_obj.equips:
                if user_equips_obj.equips[eid].get("used_by"):
                    user_equips_obj.equips[eid]['used_by'] = ''
            user_equips_obj.put()
        #开放战场
        if request.POST.get('open_dungeon', ''):
            open_dungeon = request.POST.get('open_dungeon')
            floor_id = open_dungeon.split('-')[0]
            room_id = open_dungeon.split('-')[1]
            user_dungeon_obj.dungeon_info['normal_current'][
                'floor_id'] = floor_id
            user_dungeon_obj.dungeon_info['normal_current'][
                'room_id'] = room_id
            user_dungeon_obj.dungeon_info['normal_current']['status'] = 0
            user_dungeon_obj.put()
        #回复体力
        if request.POST.get('add_stamina', ''):
            add_stamina = int(request.POST.get('add_stamina'))
            user_property_obj.add_stamina(add_stamina)
        #equip
        if request.POST.get("add_equips", ""):
            user_equips_obj = UserEquips.get(uid)
            strEquipsInfo = request.POST.get("add_equips")
            lstEquipsInfo = strEquipsInfo.strip().split(";")
            for strAddEquip in lstEquipsInfo:
                eid = strAddEquip.split(":")[0]
                eid = eid.strip() + '_equip'
                num = int(strAddEquip.split(":")[1])
                for i in range(num):
                    user_equips_obj.add_equip(eid, where=qa_edit)
        #材料
        if request.POST.get("add_mats", ""):
            strItemsInfo = request.POST.get("add_mats")
            lstItemsInfo = strItemsInfo.strip().split(";")
            for strAddItem in lstItemsInfo:
                mid = strAddItem.split(":")[0]
                mid = mid.strip() + '_mat'
                num = int(strAddItem.split(":")[1])
                user_pack_obj.add_material(mid, num, where=qa_edit)

        #道具
        if request.POST.get("add_props", ""):
            strPropsInfo = request.POST.get("add_props")
            lstPropsInfo = strPropsInfo.strip().split(";")
            for strAddProps in lstPropsInfo:
                pid = strAddProps.split(":")[0]
                pid = pid.strip() + '_props'
                num = int(strAddProps.split(":")[1])
                user_pack_obj.add_props(pid, num, where=qa_edit)

        if request.POST.get("add_materials_num", 0):
            mid = request.POST.get("mid")
            user_pack_obj.add_material(
                mid,
                int(request.POST.get("add_materials_num", 0)),
                where=qa_edit)

        if request.POST.get("add_props_num", 0):
            pid = request.POST["prop"]
            user_pack_obj.add_props(pid,
                                    int(request.POST.get("add_props_num", 0)),
                                    where=qa_edit)

        if request.POST.get('give_all_props'):
            num = int(request.POST.get('all_props_num')) if request.POST.get(
                'all_props_num') else 99
            for iid in game_config.props_config:
                user_pack_obj.add_props(iid, num, where=qa_edit)

        if request.POST.get('del_all_props'):
            user_pack_obj.props = {}
            user_pack_obj.put()

        if request.POST.get('give_all_equips'):
            user_equips = UserEquips.get(uid)
            for eid in game_config.equip_config:
                user_equips.add_equip(eid, where=qa_edit)

        #一键送所有的装备碎片
        if request.POST.get('give_all_equip_soul'):
            user_souls_obj = UserSouls.get(uid)
            for eid in game_config.equip_config:
                if game_config.equip_config[eid].get('need_soul_types_num', 0):
                    parts = game_config.equip_config[eid].get(
                        'need_soul_types_num', 0)
                    for i in xrange(1, parts + 1):
                        user_souls_obj.add_equip_soul(eid + '_' + str(i),
                                                      100,
                                                      where=qa_edit)
                else:
                    user_souls_obj.add_equip_soul(eid, 1, where=qa_edit)

        #一键删除所有的装备碎片
        if request.POST.get('del_all_equip_soul'):
            user_souls_obj = UserSouls.get(uid)
            user_souls_obj.equip_souls_info = {}
            user_souls_obj.put()

        #添加单个装备碎片
        if request.POST.get('add_single_equip_soul'):
            sid = request.POST.get('sid')
            num = int(request.POST.get('add_single_equip_soul'))
            user_souls_obj = UserSouls.get_instance(uid)
            user_souls_obj.add_equip_soul(sid, num, where=qa_edit)
            user_souls_obj.put()

        if request.POST.get('del_other_equips'):
            user_equips = UserEquips.get(uid)
            ueids = [
                ueid for ueid in user_equips.equips
                if not user_equips.is_used(ueid)
            ]
            user_equips.delete_equip(ueids)
        if request.POST.get('give_all_materials'):
            num = int(request.POST.get('all_materials_num')
                      ) if request.POST.get('all_materials_num') else 99
            user_pack_obj = UserPack.get_instance(uid)
            for mid in game_config.material_config:
                user_pack_obj.add_material(mid, num, where=qa_edit)
        if request.POST.get('del_all_materials'):
            user_pack_obj = UserPack.get_instance(uid)
            user_pack_obj.materials = {}
            user_pack_obj.put()
        #一键过新手引导
        if request.POST.get('newbie_pass', '') and user.user_property.newbie:
            newbie_steps_num = int(
                user.game_config.system_config.get('newbie_steps', 6))
            user.user_property.property_info['newbie_steps'] = (
                1 << newbie_steps_num) - 1
            user.user_property.set_newbie()
            user.user_property.do_put()

        data['status'] = 1

    data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current']
    #配置中的所有战场
    data['all_dungeon'] = []
    floor_ids = sorted(
        map(lambda x: int(x), game_config.normal_dungeon_config.keys()))
    for floor_id in floor_ids:
        for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)]
                              ['rooms'].keys()):
            data['all_dungeon'].append('%d-%s' % (floor_id, room_id))
    #用户已经达到最深层时
    if '%s-%s' % (data['current_dungeon']['floor_id'], data['current_dungeon']
                  ['room_id']) == data['all_dungeon'][-1]:
        data['max_dungeon'] = True
    else:
        data['max_dungeon'] = False
        now_index = data['all_dungeon'].index(
            '%s-%s' % (data['current_dungeon']['floor_id'],
                       data['current_dungeon']['room_id']))
        data['all_dungeon'] = data['all_dungeon'][now_index + 1:]

    #装备
    equips = user_equips_obj.equips
    eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips]
    data['user_equips'] = [
        game_config.equip_config.get(eid_dict['eid'])
        for eid_dict in eqids_dict
    ]
    all_equips_tag = sorted(
        [int(i.split('_')[0]) for i in game_config.equip_config.keys()])
    data['all_equips'] = [(i, game_config.equip_config.get(str(i) + '_equip'))
                          for i in all_equips_tag]

    #mat
    data['user_materials'] = {
        mid: {
            'name': game_config.material_config.get(mid, {}).get('name', ''),
            'num': user_pack_obj.materials[mid]
        }
        for mid in user_pack_obj.materials
    }
    all_materials_tag = sorted(
        [int(i.split('_')[0]) for i in game_config.material_config.keys()])

    data['all_materials'] = [(i,
                              game_config.material_config.get(str(i) + '_mat'))
                             for i in all_materials_tag]

    #props
    data['user_props'] = {
        pid: {
            'name': game_config.props_config.get(pid, {}).get('name'),
            'num': user_pack_obj.props[pid]
        }
        for pid in user_pack_obj.props
    }
    all_props_tag = sorted(
        [int(i.split('_')[0]) for i in game_config.props_config.keys()])
    data['all_props'] = [(i, game_config.props_config.get(str(i) + '_props'))
                         for i in all_props_tag]

    ######将魂系统   代码要在其他逻辑偏后 以保证是最新的信息##############
    user_souls_obj = UserSouls.get_instance(uid)
    #   添加  普通将魂
    if request.POST.get('add_normal_soul', ''):
        add_normal_soul_num = int(request.POST.get('add_normal_soul'))
        sid = request.POST.get('sid')
        user_souls_obj.add_normal_soul(sid, add_normal_soul_num, where=qa_edit)
    #   批量添加  普通将魂
    if request.POST.get('dump_normal_soul'):
        dump_normal_soul_str = request.POST.get('dump_normal_soul').strip()
        for item in dump_normal_soul_str.split(';'):
            sid, num = item.split(':')
            user_souls_obj.add_normal_soul(sid + '_card',
                                           int(num),
                                           where=qa_edit)
    #   批量添加  装备碎片
    if request.POST.get('add_equip_soul'):
        add_equip_soul_str = request.POST.get('add_equip_soul').strip()
        for equip_info in add_equip_soul_str.split(';'):
            eid, num = equip_info.split(':')
            user_souls_obj.add_equip_soul(eid, int(num), where=qa_edit)

    #   添加  英雄将魂
    if request.POST.get('add_super_soul', ''):
        add_super_soul_num = int(request.POST.get('add_super_soul'))
        if add_super_soul_num >= 0:
            user_souls_obj.add_super_soul(add_super_soul_num, where=qa_edit)
        else:
            user_souls_obj.minus_card_soul('super_soul',
                                           -add_super_soul_num,
                                           where=qa_edit)

    # 武将碎片兑换武将
    if request.POST.get('soul_exchange_card'):
        sid = request.POST.get('sid')
        params = {'cid': sid}
        user['uid'] = uid
        soul.exchange_card(user, params)
    # 删除将魂
    if request.POST.get('delete_card_soul'):
        sid = request.POST.get('sid')
        num = int(request.POST.get('num'))
        user_souls_obj = UserSouls.get_instance(uid)
        user_souls_obj.minus_card_soul(sid, num, where=qa_edit)
        user_souls_obj.put()
    data.update(copy.deepcopy(soul.get_all(user, None)[1]))

    #武将碎片的显示
    for sid, soul_conf in data['normal_souls'].items():
        soul_conf['name'] = game_config.card_config[sid].get(
            'star', '') + u'星 ' + game_config.card_config[sid].get('name',
                                                                   '') + u' 碎片'
    #装备碎片的显示
    for sid, soul_conf in data['equip_souls_info'].items():
        all_parts = sid.split('_')
        if len(all_parts) == 2:
            soul_conf['name'] = str(game_config.equip_config[sid].get(
                'star', '')) + u'星 ' + game_config.equip_config[sid].get(
                    'name', '') + u' 碎片'
        else:
            sid = '%s_%s' % (all_parts[0], all_parts[1])
            soul_conf['name'] = str(game_config.equip_config[sid].get(
                'star', '')) + u'星 ' + game_config.equip_config[sid].get(
                    'name', '') + u' 碎片第%s部分' % all_parts[2]

    #  获取玩家武将信息  代码往后放 以保证是最新的信息
    deck_num = 0
    for card in user_card_obj.deck:
        if card:
            ucid = card['ucid']
            card_info = user_card_obj.cards[ucid]
            this_card = Card.get_from_dict(card_info)
            this_card.ucid = ucid
            this_card.is_leader = card.get('leader', 0)
            eid = ''  #user_card_obj.get_eid(ucid)
            if eid:
                this_card.equip = game_config.equip_config[eid]['name']
            else:
                this_card.equip = ''
            this_card.now_exp = card_info['exp']
            data['deck_cards'].append(this_card)
            deck_num += 1
        else:
            data['deck_cards'].append(None)
    data['deck_num'] = deck_num
    other_ucids = user_card_obj.cards.keys()
    for card in user_card_obj.deck:
        ucid = card.get('ucid')
        if ucid and ucid in other_ucids:
            other_ucids.remove(ucid)
    for ucid in other_ucids:
        card_info = user_card_obj.cards[ucid]
        this_card = Card.get_from_dict(card_info)
        this_card.ucid = ucid
        this_card.now_exp = card_info['exp']
        eid = ''  #user_card_obj.get_eid(ucid)
        if eid:
            this_card.equip = game_config.equip_config[eid]['name']
        else:
            this_card.equip = ''
        data['other_cards'].append(this_card)
    #重新整理 下编队
    user_card_obj.decks

    # 邮件
    show_mails = mails.show_mails(user, {})['show_mails']
    temp_mails = show_mails.values()

    # 整理awards内容,就显示good_id和num
    for mail in temp_mails:
        for award in mail['awards'][:]:
            if not 'good_id' in award.values()[0]:
                continue
            mail['awards'].append({
                award.values()[0]['good_id']:
                award.values()[0].get('num', 0)
            })
            mail['awards'].pop(0)

    data.update({
        'mails':
        sorted(temp_mails,
               key=operator.itemgetter('can_get', 'create_time'),
               reverse=True),
        'user_property_obj':
        user_property_obj,
        'user':
        user,
        'add_time':
        timestamp_toString(user.add_time),
        'last_login_time':
        timestamp_toString(user.user_property.login_time),
        'login_record':
        UserLogin.get(uid).login_info['login_record'],
        'user_real_pvp_obj':
        user_real_pvp_obj.pvp_detail,
        'mystery_store':
        mystery_store.get_store_info(user, {}),
        'pk_store':
        pk_store.get_store_info(user, {}),
    })

    return 'user/edit.html', data
Example #12
0
def customer_service(request):
    """客服工具
    """
    data = {'search_type': 'all'}
    uid = request.REQUEST.get('uid', '').strip()
    pid = request.REQUEST.get('pid', '').strip()
    uid_charge = request.REQUEST.get('uid_charge', '').strip()
    oid = request.REQUEST.get('oid', '').strip()
    start_date_charge = request.REQUEST.get('start_date_charge', '')
    end_date_charge = request.REQUEST.get('end_date_charge', '')
    for i in [
            "uid", "pid", "uid_charge", "start_date_charge", "oid",
            "end_date_charge"
    ]:
        data[i] = request.REQUEST.get(i, '')
    result_consume = []
    result_charge = []
    from apps.models.account_mapping import AccountMapping
    if not uid and pid:
        uid = AccountMapping.get(pid).uid
    if uid:
        search_type = request.REQUEST.get('search_type', 'all')
        start_date = request.REQUEST.get('start_date', '')
        data['start_date'] = start_date
        end_date = request.REQUEST.get('end_date', '')
        data['end_date'] = end_date
        data['uid'] = uid
        data['search_type'] = search_type
        if search_type == 'charge' or search_type == 'all':
            result_charge = _get_charge_record(uid, start_date, end_date)
        if search_type == 'consume' or search_type == 'all':
            result_consume = _get_consume_record(uid, start_date, end_date)
    all_result = result_consume + result_charge
    tmp = sorted([(i.createtime, i) for i in all_result], key=lambda x: x[0])
    sorted_result = [i[1] for i in tmp]
    data['result'] = sorted_result
    data["charge_log"] = {}
    match_query = {}
    if uid_charge or oid:
        shop_config = copy.deepcopy(game_config.shop_config)
        sale = shop_config['sale']
        sale.update(shop_config.get('google_sale', {}))
        sale.update(shop_config.get('new_sale', {}))
        sale.update(shop_config.get('mycard_sale', {}))
        if uid_charge:
            match_query['uid'] = uid_charge
        if oid:
            match_query['oid'] = oid
        if start_date_charge or end_date_charge:
            match_query['date_time'] = {}
            if start_date_charge:
                match_query['date_time']['$gte'] = string_toDatetime(
                    '%s 00:00:00' % start_date_charge)
            if end_date_charge:
                match_query['date_time']['$lte'] = string_toDatetime(
                    '%s 23:59:59' % end_date_charge)
        charge_log = data_log_model.get_log_model("ChargeResultLog").find(
            match_query)
        charge_log_list = []
        for c_log in charge_log:
            tmp = {}
            tmp['uid'] = c_log.uid
            tmp['oid'] = c_log.oid if hasattr(c_log, 'oid') else ''
            tmp['item_id'] = '%s元(%s元宝)' % (sale.get(c_log.item_id,{}).get('price','None'),sale.get(c_log.item_id,{}).get('num','None')) \
                              if hasattr(c_log,'item_id') else ''
            tmp['charge_way'] = c_log.charge_way
            tmp['result'] = c_log.result
            tmp['date_time'] = c_log.date_time
            charge_log_list.append(tmp)
        data['charge_log'] = charge_log_list
        data['sale'] = sale
    return 'tool/customer_service.html', data
Example #13
0
def view_user(request):
    """
     更新用户信息
    """

    uid = request.GET.get('uid','').strip()
    if not uid:
        pid = request.GET.get('pid','').strip()
        if not pid:
            username = request.GET.get('username','')
            if not username:
                return HttpResponseRedirect('/admin/user/?status=1')
            try:
                uid=ocapp.mongo_store.mongo.db['username'].find({'name':username})[0]['uid']
            except:
                return HttpResponseRedirect('/admin/user/?status=1')
        else:
            account = AccountMapping.get(pid)
            if not account:
                return HttpResponseRedirect('/admin/user/?status=1')
            uid = account.uid

    user = UserBase.get(uid)
    if not user or not user.account:
        return HttpResponseRedirect('/admin/user/?status=1')




    ##### view raw db data
    check_raw_db_data = request.GET.get('check_raw_db_data','').strip()
    db_data_name = request.GET.get('db_data_name','').strip()

    #using exec/eval, need consider safety, or user could provide malicious
    #string, do bad behavior
    if db_data_name and db_data_name not in raw_db_data_list:
        return HttpResponse('Wrong raw db data name, or not allowed to show yet')

    if check_raw_db_data in ('on', 'checked'):
        data={ 'user': {} }
        data['user']['uid'] = uid
        data['user']['username'] = user.username
        module_name, data_class, db_data = db_data_name.split('.')

        #exec('from apps.models.' + module_name + ' import ' + data_class)
        exec 'from apps.models.' + module_name + ' import ' + data_class in globals(), locals() 

        if data_class == 'UserMail':
            raw_db_data = eval(data_class + '.hget("' + uid + '", "' + uid + '").' + db_data )
        else:
            raw_db_data = eval(data_class + '.get(' + uid + ').' + db_data )

        data['db_data_name'] = db_data_name
        data['raw_db_data'] = pformat(raw_db_data)
        return render_to_response('user/view_raw.html', data, 
                    RequestContext(request))
    ###### end view raw db


    user_card_obj = UserCards.get(user.uid)
    user_equips_obj = UserEquips.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_pack_obj = UserPack.get_instance(uid)

    data = {
        'user_property_obj':user_property_obj,
        'user':user,
        'deck_cards':[],
        'other_cards':[],
        'add_time':timestamp_toString(user.add_time),
        'last_login_time':timestamp_toString(user.user_property.login_time),
        'login_record':UserLogin.get(uid).login_info['login_record'],
    }
    if not user.client_type:
        data['client_type'] = 'appstore_ios'
    else:
        data['client_type'] = user.client_type
    all_cards = []

    all_cids = game_config.card_config.keys()

    all_cids_cp = copy.deepcopy(game_config.card_config)
    for k,v in all_cids_cp.iteritems():
        all_cids_cp[k]['no'] = int(k.split('_')[0])
    all_cids.sort(key = lambda x :(all_cids_cp[x]['no']))
    for cid in all_cids:
        all_cards.append(Card.get(cid))
    data['all_cards'] = all_cards
    #用户当前战场信息
    user_dungeon_obj = UserDungeon.get_Ex(user.uid)
    #pvp_obj = UserPvp.getEx(user.uid)
    #pvp 排名
    top_model = pvp_redis.get_pvp_redis('1')
    rank = top_model.rank(uid)
    #pvp_obj.rank = rank+1 if rank != None else 0
    #data['pvp'] = pvp_obj
    data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current']
    #配置中的所有战场
    data['all_dungeon'] = []
    floor_ids = sorted(map(lambda x:int(x),game_config.normal_dungeon_config.keys()))
    for floor_id in floor_ids:
        for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)]['rooms'].keys()):
            data['all_dungeon'].append('%d-%s' % (floor_id,room_id))
    #用户已经达到最深层时
    if '%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id']) == data['all_dungeon'][-1]:
        data['max_dungeon'] = True
    else:
        data['max_dungeon'] = False
        now_index = data['all_dungeon'].index('%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id']))
        data['all_dungeon'] = data['all_dungeon'][now_index + 1:]

    deck_num = 0
    for card in user_card_obj.deck:
        if card:
            ucid = card['ucid']
            card_info = user_card_obj.cards[ucid]
            this_card = Card.get_from_dict(card_info)
            this_card.ucid = ucid
            this_card.is_leader = card.get('leader',0)
            eid = ''
            if eid:
                this_card.equip = game_config.equip_config[eid]['name']
            else:
                this_card.equip = ''
            this_card.now_exp = card_info['exp']
            data['deck_cards'].append(this_card)
            deck_num += 1
        else:
            data['deck_cards'].append(None)

    data['deck_num'] = deck_num
    other_ucids = user_card_obj.cards.keys()
    for card in user_card_obj.deck:
        ucid = card.get('ucid')
        if ucid:
            other_ucids.remove(ucid)
    for ucid in other_ucids:
        card_info = user_card_obj.cards[ucid]
        this_card = Card.get_from_dict(card_info)
        this_card.ucid = ucid
        this_card.now_exp = card_info['exp']
        eid = ''
        if eid:
            this_card.equip = game_config.equip_config[eid]['name']
        else:
            this_card.equip = ''
        data['other_cards'].append(this_card)
    #重新整理 下编队
    user_card_obj.decks

    #装备
    equips = user_equips_obj.equips
    eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips ]
    data['user_equips'] = [game_config.equip_config[eid_dict['eid']]  for eid_dict in eqids_dict]
    all_equips_tag = sorted([int(i.split('_')[0]) for i in game_config.equip_config.keys()])
    data['all_equips'] = [(i,game_config.equip_config[str(i)+'_equip']) for i in all_equips_tag]

    #mat
    data['user_materials'] = {mid :{'name':game_config.material_config[mid]['name'],'num':user_pack_obj.materials[mid]} for mid in user_pack_obj.materials }
    all_materials_tag = sorted([int(i.split('_')[0]) for i in game_config.material_config.keys()])
    data['all_materials'] = [(i,game_config.material_config[str(i)+'_mat']) for i in all_materials_tag]
    #
    data['charge_sum_money'] = user.user_property.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find({'uid':uid})[-1] if ChargeRecord.find({'uid':uid}) else {}


######将魂系统##############

    data.update(soul.get_all(user, None)[1])
    for sid, soul_conf in data['normal_souls'].items():
        soul_conf['name'] = game_config.card_config[sid].get('star','') + u'星 ' + game_config.card_config[sid].get('name','') + u' 将魂'
    #data["index_list"] = request.index_list
    return render_to_response('user/view.html',data,RequestContext(request))
Example #14
0
def edit_user(request):
    """
    编辑用户页
    """
    uid = request.GET.get('uid','').strip()
    if not uid:
        pid = request.GET.get('pid','').strip()
        if not pid:
            username = request.GET.get('username','')
            if not username:
                return HttpResponseRedirect('/admin/user/?status=1')
            try:
                uid=ocapp.mongo_store.mongo.db['username'].find({'name':username})[0]['uid']
            except:
                return HttpResponseRedirect('/admin/user/?status=1')
        else:
            account = AccountMapping.get(pid)
            if not account:
                return HttpResponseRedirect('/admin/user/?status=1')
            uid = account.uid


    user = UserBase.get(uid)
    if not user or not user.account:
        return HttpResponseRedirect('/admin/user/?status=1')

    user_equips_obj = UserEquips.get_instance(uid)
    user_pack_obj = UserPack.get_instance(uid)
    user_property_obj = UserProperty.get(uid)
    user_card_obj = UserCards.get(user.uid)
    user_real_pvp_obj = user.user_real_pvp
    game_config.set_subarea(user.subarea)

    data = {
        'deck_cards':[],
        'other_cards':[],
    }
    if not user.client_type:
        data['client_type'] = 'appstore_ios'
    else:
        data['client_type'] = user.client_type
    all_cards = []

    all_cids = game_config.card_config.keys()

    all_cids_cp = copy.deepcopy(game_config.card_config)
    for k,v in all_cids_cp.iteritems():
        all_cids_cp[k]['no'] = int(k.split('_')[0])
    all_cids.sort(key = lambda x :(all_cids_cp[x]['no']))
    for cid in all_cids:
        all_cards.append(Card.get(cid))
    data['all_cards'] = all_cards
    #用户当前战场信息
    user_dungeon_obj = UserDungeon.get_instance(user.uid)

    #充值信息
    data['charge_sum_money'] = user_property_obj.charge_sum_money
    data['last_charge_record'] = ChargeRecord.find({'uid':uid})[-1] if ChargeRecord.find({'uid':uid}) else {}

######神秘商店   代码往前方 因为此操作会改变玩家武将,物品等信息##############
    #   刷新  物品列表
    if request.POST.get('refresh_mystery_store',''):
        store_type = request.POST.get('store_type')
        params = {
        }
        mystery_store.refresh_store_by_self(user, params)
    #   购买  物品
    if request.POST.get('buy_mystery_store_goods',''):
        store_type = request.POST.get('store_type')
        goods_index = int(request.POST.get('goods_index'))
        params = {
            'store_type': store_type,
            'goods_index': goods_index,
        }
        mystery_store.buy_store_goods(user, params)
######Pk商店   ##
    #   刷新  物品列表
    if request.POST.get('refresh_pk_store', ''):
        pk_store.refresh_store_by_self(user, {})
    #   购买  物品
    if request.POST.get('buy_pk_store_goods',''):
        goods_index = int(request.POST.get('goods_index'))
        params = {
            'goods_index': goods_index,
        }
        pk_store.buy_store_goods(user, params)
####################

    moderator = auth.get_moderator_by_request(request)
    qa_edit = 'qa edited by '+str(moderator.username)

    #提交状态
    if request.method == "POST":
        state = int(request.POST.get("state","0"))
        state = bool(state)
        #冻结
        if state != user.in_frozen:
            if state:
                user.froze()
            #解冻
            else:
                user.unfroze()
        #删除账号
        if request.POST.get('del_user',''):
            if not user.account:
                return HttpResponseRedirect('/admin/user/?status=1')
            user.account.delete()
        if request.POST.get('add_gold',''):
            add_gold = int(request.POST.get('add_gold'))
            if add_gold>0:
                user_property_obj.add_gold(add_gold,where=qa_edit)
            else:
                user_property_obj.minus_gold(add_gold)
        #增加元宝
        if request.POST.get('add_coin',''):
            add_coin = int(request.POST.get('add_coin'))
            if add_coin>0:
                user_property_obj.add_coin(add_coin, where=qa_edit)
            else:
                user_property_obj.minus_coin(add_coin, where=qa_edit)
        #增加 经验点
        if request.POST.get('add_card_point',''):
            add_card_point = int(request.POST.get('add_card_point'))
            if add_card_point>0:
                user_property_obj.add_card_exp_point(add_card_point, qa_edit)
            else:
                user_property_obj.minus_card_exp_point(add_card_point, qa_edit)
        #增加经验
        if request.POST.get('add_exp',''):
            add_exp = int(request.POST.get('add_exp'))
            user_property_obj.add_exp(add_exp,where=qa_edit)
        #更改等级
        if request.POST.get('modify_lv',''):
            lv = request.POST.get('modify_lv')
            lv_exp = game_config.user_level_config[lv]['exp']
            now_exp = user_property_obj.property_info['exp']
            user_property_obj.add_exp(lv_exp-now_exp,where=qa_edit)
        # 增加pk 积分
        if request.POST.get('add_pk_pt', 0):
            pvp_pt = int(request.POST.get('add_pk_pt'))
            user_real_pvp_obj.add_pt(pvp_pt)
        # 加功勋
        if request.POST.get('add_honor',''):
            honor = int(request.POST.get('add_honor'))
            urp = UserRealPvp.get(user.uid)
            urp.add_honor(honor, where=qa_edit)
        # 加战魂
        if request.POST.get('add_fight_soul',''):
            fight_soul_num = int(request.POST.get('add_fight_soul'))
            user_property_obj.add_fight_soul(fight_soul_num, where=qa_edit)
        #发邮件
        if request.POST.get('mail_title') or request.POST.get('mail_goods'):
            from apps.models.user_mail import UserMail
            from apps.common import utils
            sid = 'system_%s' % (utils.create_gen_id())
            mail_title = request.POST.get('mail_title', '')
            mail_content = request.POST.get('mail_content', '')
            goods_str = request.POST.get('mail_goods', '').strip()
            award = {}
            for goods_info in goods_str.split(";"):
                goods_info = goods_info.strip()
                print "debug guochen email", goods_info
                if not goods_info:
                    continue

                goods_id, num = goods_info.strip().split(":")
                award.setdefault(goods_id, 0)
                award[goods_id] += int(num)

            mailtype = 'system_qa'
            user_mail_obj = UserMail.hget(uid, sid)
            user_mail_obj.set_mail(mailtype=mailtype, title=mail_title, content=mail_content, award=award)

        # 修改vip等级
        if request.POST.get('modify_vip_lv'):
            vip_lv = request.POST.get('modify_vip_lv')
            vip_conf = game_config.user_vip_config.get(str(vip_lv))
            if vip_conf:
                coin = vip_conf['coin']
                user_property_obj.property_info["charge_coins"] = coin
                user_property_obj.put()

        #补武将
        if request.POST.get("add_card_ex", ""):
            user_card_obj = UserCards.get(user.uid)
            strCardInfo = request.POST.get("add_card_ex")
            lstCardInfo = strCardInfo.strip().split(";")
            for strAddCard in lstCardInfo:
                cid = strAddCard.split(":")[0]
                cid = cid.strip() + '_card'
                num = int(strAddCard.split(":")[1])
                for i in range(num):
                    clv = 1
                    user_card_obj.add_card(cid,clv,where=qa_edit)
        #增加武将
        if request.POST.getlist('add_card'):
            add_cids = request.POST.getlist('add_card')
            user_card_obj = UserCards.get(user.uid)
            for add_cid in add_cids:
                if add_cid in game_config.card_config:
                    clv = 1
                    user_card_obj.add_card(add_cid,clv,where=qa_edit)
        #增加武将经验
        if request.POST.get('add_card_exp',''):
            add_exp = int(request.POST.get('add_card_exp'))
            ucid = request.POST.get('ucid')
            user_card_obj.add_card_exp(ucid,add_exp)

        #增加武将技能级别
        if request.POST.get('add_card_sk_lv',''):
            ucid = request.POST.get('ucid')
            user_card_obj.add_card_sk_lv(ucid)
        #卖掉卡片
        if request.POST.get('sell_card',''):
            ucid = request.POST.get('ucid')
            #this_card = Card.get(user_card_obj.cards[ucid]['cid'],user_card_obj.cards[ucid]['lv'])
            user_card_obj.del_card_info([ucid])
            #user.user_property.add_gold(this_card.sell_gold,where=qa_edit)
        #踢出队伍
        if request.POST.get('kick_deck',''):
            kick_index = int(request.POST.get('deck_index'))
            if user_card_obj.deck[kick_index].get('ucid','') != user_card_obj.get_leader(user_card_obj.cur_deck_index):
                user_card_obj.deck[kick_index] = {}
                user_card_obj.put()
        #设置主将
        if request.POST.get('set_deck_main',''):
            ucid = request.POST.get('ucid')
            find_fg = False
            for card in user_card_obj.deck:
                if card.get('leader',0):
                    card['ucid'] = ucid
                    user_card_obj.put()
                    find_fg = True
                    break
            if not find_fg:
                user_card_obj.deck[0] = {'ucid':ucid,'leader':1}
                user_card_obj.put()

        #设置副将
        if request.POST.get('set_deck_sub',''):
            ucid = request.POST.get('ucid')
            for card in user_card_obj.deck:
                if not card:
                    card['ucid'] = ucid
                    user_card_obj.put()
                    break

        #一键送所有武将碎片
        if request.POST.get('give_all_card_soul',''):
            for cid in game_config.card_config:
                user_card_obj.add_card(cid,1,where=qa_edit)
            user_card_obj.put()
            
        #一键送所有武将
        if request.POST.get('give_all_card',''):
            #一键送所有武将
            for cid in all_cids:
                ucid = user_card_obj.add_card(cid, 1, where=qa_edit)[2]
        # if request.POST.get('give_all_card',''):
        #     user_card_obj.cards = {}
        #     user_card_obj.cards_info = {
        #                     "decks":[[{}] * 5] * 10,
        #                     "cur_deck_index":0,
        #                 }
        #     for eid in user_equips_obj.equips:
        #         if user_equips_obj.equips[eid].get("used_by"):
        #             user_equips_obj.equips[eid]['used_by'] = ''
        #     user_equips_obj.put()     
        #     card_index = 0
        #     for cid in all_cids:
        #         clv = 1
        #         ucid = user_card_obj.add_card(cid,clv,where=qa_edit)[2]
        #         if card_index < 5:
        #             user_card_obj.deck[card_index]['ucid'] = ucid
        #         card_index += 1

        #一键删除军队外的所有武将
        if request.POST.get('del_other_card',''):
            decks = []
            for deck in user_card_obj.decks:
                decks.extend([card['ucid'] for card in deck if card.get('ucid','')])
            del_cids = filter(lambda x:x not in decks,user_card_obj.cards.keys())
            user_card_obj.del_card_info(del_cids)
            for eid in user_equips_obj.equips:
                if user_equips_obj.equips[eid].get("used_by"):
                    user_equips_obj.equips[eid]['used_by'] = ''
            user_equips_obj.put()
        #开放战场
        if request.POST.get('open_dungeon',''):
            open_dungeon = request.POST.get('open_dungeon')
            floor_id = open_dungeon.split('-')[0]
            room_id = open_dungeon.split('-')[1]
            user_dungeon_obj.dungeon_info['normal_current']['floor_id'] = floor_id
            user_dungeon_obj.dungeon_info['normal_current']['room_id'] = room_id
            user_dungeon_obj.dungeon_info['normal_current']['status'] = 0
            user_dungeon_obj.put()
        #回复体力
        if request.POST.get('add_stamina', ''):
            add_stamina = int(request.POST.get('add_stamina'))
            user_property_obj.add_stamina(add_stamina)
        #equip
        if request.POST.get("add_equips", ""):
            user_equips_obj = UserEquips.get(uid)
            strEquipsInfo = request.POST.get("add_equips")
            lstEquipsInfo = strEquipsInfo.strip().split(";")
            for strAddEquip in lstEquipsInfo:
                eid = strAddEquip.split(":")[0]
                eid = eid.strip() + '_equip'
                num = int(strAddEquip.split(":")[1])
                for i in range(num):
                    user_equips_obj.add_equip(eid,where=qa_edit)
        #材料
        if request.POST.get("add_mats", ""):
            strItemsInfo = request.POST.get("add_mats")
            lstItemsInfo = strItemsInfo.strip().split(";")
            for strAddItem in lstItemsInfo:
                mid = strAddItem.split(":")[0]
                mid = mid.strip() + '_mat'
                num = int(strAddItem.split(":")[1])
                user_pack_obj.add_material(mid,num,where=qa_edit)
                
        #道具
        if request.POST.get("add_props", ""):
            strPropsInfo = request.POST.get("add_props")
            lstPropsInfo = strPropsInfo.strip().split(";")
            for strAddProps in lstPropsInfo:
                pid = strAddProps.split(":")[0]
                pid = pid.strip() + '_props'
                num = int(strAddProps.split(":")[1])
                user_pack_obj.add_props(pid,num,where=qa_edit)

        if request.POST.get("add_materials_num", 0):
            mid = request.POST.get("mid")
            user_pack_obj.add_material(mid,int(request.POST.get("add_materials_num", 0)),where=qa_edit)


        if  request.POST.get("add_props_num", 0):
            pid = request.POST["prop"]
            user_pack_obj.add_props(pid, int(request.POST.get("add_props_num", 0)),where=qa_edit)

        if request.POST.get('give_all_props'):
            num = int(request.POST.get('all_props_num'))if request.POST.get('all_props_num') else 99
            for iid in game_config.props_config:
                user_pack_obj.add_props(iid,num,where=qa_edit)

        
        if request.POST.get('del_all_props'):
            user_pack_obj.props = {}
            user_pack_obj.put()


        if request.POST.get('give_all_equips'):
            user_equips = UserEquips.get(uid)
            for eid in game_config.equip_config:
                user_equips.add_equip(eid,where=qa_edit)

        #一键送所有的装备碎片
        if request.POST.get('give_all_equip_soul'):
            user_souls_obj = UserSouls.get(uid)
            for eid in game_config.equip_config:
                if game_config.equip_config[eid].get('need_soul_types_num',0):
                    parts = game_config.equip_config[eid].get('need_soul_types_num',0)
                    for i in xrange(1,parts+1):
                        user_souls_obj.add_equip_soul(eid+'_'+str(i),100,where=qa_edit)
                else:
                    user_souls_obj.add_equip_soul(eid,1,where=qa_edit)

        #一键删除所有的装备碎片
        if request.POST.get('del_all_equip_soul'):
            user_souls_obj = UserSouls.get(uid)
            user_souls_obj.equip_souls_info = {}
            user_souls_obj.put()

        #添加单个装备碎片
        if request.POST.get('add_single_equip_soul'):
            sid = request.POST.get('sid')
            num = int(request.POST.get('add_single_equip_soul'))
            user_souls_obj = UserSouls.get_instance(uid)
            user_souls_obj.add_equip_soul(sid, num,where=qa_edit)
            user_souls_obj.put()
        
        if request.POST.get('del_other_equips'):
            user_equips = UserEquips.get(uid)
            ueids = [ ueid for ueid in user_equips.equips if not user_equips.is_used(ueid)]
            user_equips.delete_equip(ueids)
        if request.POST.get('give_all_materials'):
            num = int(request.POST.get('all_materials_num'))if request.POST.get('all_materials_num') else 99
            user_pack_obj = UserPack.get_instance(uid)
            for mid in game_config.material_config:
                user_pack_obj.add_material(mid,num,where=qa_edit)
        if request.POST.get('del_all_materials'):
            user_pack_obj = UserPack.get_instance(uid)
            user_pack_obj.materials = {}
            user_pack_obj.put()
        #一键过新手引导
        if request.POST.get('newbie_pass','') and user.user_property.newbie:
            newbie_steps_num = int(user.game_config.system_config.get('newbie_steps', 6))
            user.user_property.property_info['newbie_steps'] = (1 << newbie_steps_num) - 1
            user.user_property.set_newbie()
            user.user_property.do_put()

        data['status'] = 1

    data['current_dungeon'] = user_dungeon_obj.dungeon_info['normal_current']
    #配置中的所有战场
    data['all_dungeon'] = []
    floor_ids = sorted(map(lambda x:int(x),game_config.normal_dungeon_config.keys()))
    for floor_id in floor_ids:
        for room_id in sorted(game_config.normal_dungeon_config[str(floor_id)]['rooms'].keys()):
            data['all_dungeon'].append('%d-%s' % (floor_id,room_id))
    #用户已经达到最深层时
    if '%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id']) == data['all_dungeon'][-1]:
        data['max_dungeon'] = True
    else:
        data['max_dungeon'] = False
        now_index = data['all_dungeon'].index('%s-%s' % (data['current_dungeon']['floor_id'],data['current_dungeon']['room_id']))
        data['all_dungeon'] = data['all_dungeon'][now_index + 1:]

    #装备
    equips = user_equips_obj.equips
    eqids_dict = [user_equips_obj.get_equip_dict(ueid) for ueid in equips ]
    data['user_equips'] = [game_config.equip_config.get(eid_dict['eid'])  for eid_dict in eqids_dict]
    all_equips_tag = sorted([int(i.split('_')[0]) for i in game_config.equip_config.keys()])
    data['all_equips'] = [(i,game_config.equip_config.get(str(i)+'_equip')) for i in all_equips_tag]

    #mat
    data['user_materials'] = {mid :{'name':game_config.material_config.get(mid, {}).get('name', ''),'num':user_pack_obj.materials[mid]} for mid in user_pack_obj.materials }
    all_materials_tag = sorted([int(i.split('_')[0]) for i in game_config.material_config.keys()])

    data['all_materials'] = [(i,game_config.material_config.get(str(i)+'_mat')) for i in all_materials_tag]

    #props
    data['user_props'] = {pid :{'name':game_config.props_config.get(pid, {}).get('name'),'num':user_pack_obj.props[pid]} for pid in user_pack_obj.props }
    all_props_tag = sorted([int(i.split('_')[0]) for i in game_config.props_config.keys()])
    data['all_props'] = [(i,game_config.props_config.get(str(i)+'_props')) for i in all_props_tag]

######将魂系统   代码要在其他逻辑偏后 以保证是最新的信息##############
    user_souls_obj = UserSouls.get_instance(uid)
    #   添加  普通将魂
    if request.POST.get('add_normal_soul',''):
        add_normal_soul_num = int(request.POST.get('add_normal_soul'))
        sid = request.POST.get('sid')
        user_souls_obj.add_normal_soul(sid, add_normal_soul_num, where=qa_edit)
    #   批量添加  普通将魂
    if request.POST.get('dump_normal_soul'):
        dump_normal_soul_str = request.POST.get('dump_normal_soul').strip()
        for item in dump_normal_soul_str.split(';'):
            sid, num = item.split(':')
            user_souls_obj.add_normal_soul(sid + '_card', int(num), where=qa_edit)
    #   批量添加  装备碎片
    if request.POST.get('add_equip_soul'):
        add_equip_soul_str = request.POST.get('add_equip_soul').strip()
        for equip_info in add_equip_soul_str.split(';'):
            eid, num = equip_info.split(':')
            user_souls_obj.add_equip_soul(eid, int(num), where=qa_edit)

    #   添加  英雄将魂
    if request.POST.get('add_super_soul',''):
        add_super_soul_num = int(request.POST.get('add_super_soul'))
        if add_super_soul_num >= 0:
            user_souls_obj.add_super_soul(add_super_soul_num, where=qa_edit)
        else:
            user_souls_obj.minus_card_soul('super_soul', -add_super_soul_num, where=qa_edit)

    # 武将碎片兑换武将
    if request.POST.get('soul_exchange_card'):
        sid = request.POST.get('sid')
        params = {'cid':sid}
        user['uid'] = uid
        soul.exchange_card(user, params)
    # 删除将魂
    if request.POST.get('delete_card_soul'):
        sid = request.POST.get('sid')
        num = int(request.POST.get('num'))
        user_souls_obj = UserSouls.get_instance(uid)
        user_souls_obj.minus_card_soul(sid, num,where=qa_edit)
        user_souls_obj.put()
    data.update(copy.deepcopy(soul.get_all(user, None)[1]))

    #武将碎片的显示
    for sid, soul_conf in data['normal_souls'].items():
        soul_conf['name'] = game_config.card_config[sid].get('star','') + u'星 ' + game_config.card_config[sid].get('name','') + u' 碎片'
    #装备碎片的显示
    for sid, soul_conf in data['equip_souls_info'].items():
        all_parts = sid.split('_')
        if len(all_parts) == 2:
            soul_conf['name'] = str(game_config.equip_config[sid].get('star','')) + u'星 ' + game_config.equip_config[sid].get('name','') + u' 碎片'
        else:
            sid = '%s_%s'%(all_parts[0],all_parts[1])
            soul_conf['name'] = str(game_config.equip_config[sid].get('star','')) + u'星 ' + game_config.equip_config[sid].get('name','') + u' 碎片第%s部分'%all_parts[2]

    #  获取玩家武将信息  代码往后放 以保证是最新的信息
    deck_num = 0
    for card in user_card_obj.deck:
        if card:
            ucid = card['ucid']
            card_info = user_card_obj.cards[ucid]
            this_card = Card.get_from_dict(card_info)
            this_card.ucid = ucid
            this_card.is_leader = card.get('leader',0)
            eid = ''#user_card_obj.get_eid(ucid)
            if eid:
                this_card.equip = game_config.equip_config[eid]['name']
            else:
                this_card.equip = ''
            this_card.now_exp = card_info['exp']
            data['deck_cards'].append(this_card)
            deck_num += 1
        else:
            data['deck_cards'].append(None)
    data['deck_num'] = deck_num
    other_ucids = user_card_obj.cards.keys()
    for card in user_card_obj.deck:
        ucid = card.get('ucid')
        if ucid and ucid in other_ucids:
            other_ucids.remove(ucid)
    for ucid in other_ucids:
        card_info = user_card_obj.cards[ucid]
        this_card = Card.get_from_dict(card_info)
        this_card.ucid = ucid
        this_card.now_exp = card_info['exp']
        eid = ''#user_card_obj.get_eid(ucid)
        if eid:
            this_card.equip = game_config.equip_config[eid]['name']
        else:
            this_card.equip = ''
        data['other_cards'].append(this_card)
    #重新整理 下编队
    user_card_obj.decks

    # 邮件
    show_mails = mails.show_mails(user, {})['show_mails']
    temp_mails =  show_mails.values()

    # 整理awards内容,就显示good_id和num
    for mail in temp_mails:
        for award in mail['awards'][:]:
            if not 'good_id' in award.values()[0]:
                continue
            mail['awards'].append({award.values()[0]['good_id']: award.values()[0].get('num', 0)})
            mail['awards'].pop(0)


    data.update({
        'mails': sorted(temp_mails, key=operator.itemgetter('can_get', 'create_time'), reverse=True),
        'user_property_obj':user_property_obj,
        'user':user,
        'add_time':timestamp_toString(user.add_time),
        'last_login_time':timestamp_toString(user.user_property.login_time),
        'login_record':UserLogin.get(uid).login_info['login_record'],
        'user_real_pvp_obj': user_real_pvp_obj.pvp_detail,
        'mystery_store': mystery_store.get_store_info(user, {}),
        'pk_store': pk_store.get_store_info(user, {}),
    })

    return 'user/edit.html', data
Example #15
0
def auth_token_for_oc(request, access_token, openid, uuid, mktid, version,
                      client_type, macaddr, idfa, ios_ver):
    """论证无账号用户
    """
    print "debug_guochen access_token, openid", access_token, openid
    fg = False
    pid = ''
    msg = ''
    subarea = request.REQUEST.get("subarea", "1") or '1'
    #没有openid时,检查后控制自动分配id的开头是否开启,如果已经关闭,返回提示
    if not openid:
        if game_config.system_config.get('account_assign_switch'):
            fg = True
            pid = get_uuid()
            #验证成功,安装用户
            request.rk_user = UserBase._install(pid,
                                                'oc',
                                                uuid,
                                                mktid,
                                                version,
                                                client_type,
                                                macaddr,
                                                idfa,
                                                ios_ver,
                                                subarea=subarea)
            access_token = get_upwd()
            request.rk_user.account.update_info(pid, access_token)
        else:
            msg = get_msg('login', 'cannot_register')
            return fg, pid, msg
    if not check_openid(openid):
        msg = get_msg('login', 'cannot_register')
        return fg, pid, msg
    #有openid时,检查access_token是否正确
    account = AccountMapping.get(openid)
    if not account:
        if game_config.system_config.get('account_assign_switch'):
            fg = True
            pid = openid
            #验证成功,安装用户
            request.rk_user = UserBase._install(pid,
                                                'oc',
                                                uuid,
                                                mktid,
                                                version,
                                                client_type,
                                                macaddr,
                                                idfa,
                                                ios_ver,
                                                subarea=subarea)
            # debug 模式下,将传入的access_token 作为新用户taken
            if settings.DEBUG is True:
                access_token = access_token or get_upwd()
            else:
                access_token = get_upwd()
            request.rk_user.account.update_info(pid, access_token)
            account = request.rk_user.account
            print "debug_guochen_new_token pid, access_token, openid", pid, access_token, openid
        else:
            msg = get_msg('login', 'cannot_register')
            return fg, pid, msg

    elif account.access_token == access_token:
        fg = True
        pid = openid
        #验证成功,安装用户
        request.rk_user = UserBase._install(pid, 'oc', subarea=subarea)
    else:
        print "debug_guochen_erro_token pid, access_token, openid", pid, access_token, openid
        msg = get_msg('login', 'session_overdue')
    return fg, pid, msg
Example #16
0
 def get_exist_user(cls, pid, subarea='1'):
     '''
     用已存在的PID  取得 userbase 实例
     '''
     account = AccountMapping.get(pid)
     return cls.get(account.get_subarea_uid(subarea)) if account else None
Example #17
0
def customer_service(request):
    """客服工具
    """
    data = {'search_type':'all'}
    uid = request.REQUEST.get('uid','').strip()
    pid = request.REQUEST.get('pid','').strip()
    uid_charge = request.REQUEST.get('uid_charge','').strip()
    oid = request.REQUEST.get('oid','').strip()
    start_date_charge = request.REQUEST.get('start_date_charge','')
    end_date_charge = request.REQUEST.get('end_date_charge','')
    for i in ["uid","pid","uid_charge","start_date_charge","oid","end_date_charge"]:
        data[i] = request.REQUEST.get(i,'')
    result_consume = []
    result_charge = []
    from apps.models.account_mapping import AccountMapping
    if not uid and pid:
        uid = AccountMapping.get(pid).uid
    if uid:
        search_type = request.REQUEST.get('search_type','all')
        start_date = request.REQUEST.get('start_date','')
        data['start_date'] = start_date
        end_date = request.REQUEST.get('end_date','')
        data['end_date'] = end_date
        data['uid'] = uid
        data['search_type'] = search_type
        if search_type == 'charge' or search_type == 'all':
            result_charge = _get_charge_record(uid,start_date,end_date)
        if search_type == 'consume' or search_type == 'all':
            result_consume = _get_consume_record(uid,start_date,end_date)
    all_result = result_consume + result_charge
    tmp = sorted([(i.createtime,i)for i in all_result],key=lambda x:x[0])
    sorted_result = [ i[1] for i in tmp]
    data['result'] = sorted_result
    data["charge_log"] = {}
    match_query = {}
    if uid_charge or oid:
        shop_config = copy.deepcopy(game_config.shop_config)
        sale = shop_config['sale']
        sale.update(shop_config.get('google_sale',{}))
        sale.update(shop_config.get('new_sale',{}))
        sale.update(shop_config.get('mycard_sale',{}))
        if uid_charge:
            match_query['uid'] = uid_charge
        if oid:
            match_query['oid'] = oid
        if start_date_charge or end_date_charge:
            match_query['date_time'] = {}
            if start_date_charge:
                match_query['date_time']['$gte'] = string_toDatetime('%s 00:00:00' % start_date_charge)
            if end_date_charge:
                match_query['date_time']['$lte'] = string_toDatetime('%s 23:59:59' % end_date_charge)
        charge_log = data_log_model.get_log_model("ChargeResultLog").find(match_query)
        charge_log_list = []
        for c_log in charge_log:
            tmp = {}
            tmp['uid'] = c_log.uid
            tmp['oid'] =  c_log.oid if hasattr(c_log,'oid') else ''
            tmp['item_id'] = '%s元(%s元宝)' % (sale.get(c_log.item_id,{}).get('price','None'),sale.get(c_log.item_id,{}).get('num','None')) \
                              if hasattr(c_log,'item_id') else ''
            tmp['charge_way'] = c_log.charge_way
            tmp['result'] = c_log.result
            tmp['date_time'] = c_log.date_time
            charge_log_list.append(tmp)
        data['charge_log'] = charge_log_list
        data['sale'] = sale
    return 'tool/customer_service.html', data
Example #18
0
def charge_result_91(request):
    """
    91获得玩家的充值行为后,用此api通知我们
    第一步  验证91 的请求参数
    第二步  给玩家充值
    """
    request_data = dict(
        AppId = request.REQUEST.get('AppId', None),
        Act = request.REQUEST.get('Act', None),
        ProductName = request.REQUEST.get('ProductName', None),
        ConsumeStreamId = request.REQUEST.get('ConsumeStreamId', None),
        CooOrderSerial = request.REQUEST.get('CooOrderSerial', None),
        Uin = request.REQUEST.get('Uin', None),
        GoodsId = request.REQUEST.get('GoodsId', None),
        GoodsInfo = request.REQUEST.get('GoodsInfo', None),
        GoodsCount = request.REQUEST.get('GoodsCount', None),
        OriginalMoney = request.REQUEST.get('OriginalMoney', None),
        OrderMoney = request.REQUEST.get('OrderMoney', None),
        Note = request.REQUEST.get('Note', None),
        PayStatus = request.REQUEST.get('PayStatus', None),
        CreateTime = request.REQUEST.get('CreateTime', None),
        Sign = request.REQUEST.get('Sign', None),
    )

    #### 验证91 的传参
    # ErrorCode 含义
    # 状态码,1 成功
    # 0 失败
    # 2 AppId无效
    # 3 Act无效
    # 4 参数无效 
    # 5 Sign错误
    errcode = {'ErrorCode': 1,'ErrorDesc':u'接收成功'}
    if None in request_data.values():
        errcode = {'ErrorCode': 4,'ErrorDesc':u'参数无效'}
        return HttpResponse(
                json.dumps(errcode, indent=1),
                content_type='application/x-javascript',
        ) 
    if request_data['AppId'] != settings.APP_ID_91:
        errcode['ErrorCode'] = 2
        errcode['ErrorDesc'] = u'AppId无效'
        return HttpResponse(
                json.dumps(errcode, indent=1),
                content_type='application/x-javascript',
        ) 
    if request_data['Act'] != '1':
        errcode['ErrorCode'] = 3
        errcode['ErrorDesc'] = u'Act无效'
        return HttpResponse(
                json.dumps(errcode, indent=1),
                content_type='application/x-javascript',
        ) 
    if request_data['PayStatus'] != '1':
        errcode['ErrorCode'] = 0
        errcode['ErrorDesc'] = u'接收失败'
        return HttpResponse(
                json.dumps(errcode, indent=1),
                content_type='application/x-javascript',
        )

    signature_params = u"{0}{1}{2}{3}{4}{5}{6}{7}{8}{9:.2f}{10:.2f}{11}{12}{13}{14}".format(\
                     request_data['AppId'],request_data['Act'],request_data['ProductName'],request_data['ConsumeStreamId'],\
                     request_data['CooOrderSerial'],request_data['Uin'],request_data['GoodsId'],request_data['GoodsInfo'],\
                     request_data['GoodsCount'],float(request_data['OriginalMoney']),float(request_data['OrderMoney']),\
                     request_data['Note'],request_data['PayStatus'],request_data['CreateTime'],settings.APP_KEY_91)
    signature = md5.new(signature_params.encode('utf-8')).hexdigest()
    if request_data['Sign'] != signature:
        errcode['ErrorCode'] = 5
        errcode['ErrorDesc'] = u'Sign无效'
        return HttpResponse(
            json.dumps(errcode, indent=1),
            content_type='application/x-javascript',
        ) 

    oid = request_data['CooOrderSerial']
    pid = md5.md5('91'+str(request_data['Uin'])).hexdigest()
    acc_obj = AccountMapping.get(pid)
    if not acc_obj:
        errcode['ErrorCode'] = 0
        errcode['ErrorDesc'] = u'接收失败'
        return HttpResponse(
                json.dumps(errcode, indent=1),
                content_type='application/x-javascript',
        )
    oc_uid = acc_obj.uid
    item_id = request_data['GoodsId']
    mi_record = OrderRecord.find({'oid':oid})
    if not mi_record:
        errcode['ErrorCode'] = 0
        errcode['ErrorDesc'] = u'接收失败'
        return HttpResponse(
                json.dumps(errcode, indent=1),
                content_type='application/x-javascript',
        )
    get_item_id = mi_record[0].item_id
    get_oc_uid = mi_record[0].uid
    if get_item_id != item_id or oc_uid != get_oc_uid:
        errcode['ErrorCode'] = 0
        errcode['ErrorDesc'] = u'接收失败'
        return HttpResponse(
                json.dumps(errcode, indent=1),
                content_type='application/x-javascript',
        )
    rk_user = UserBase.get(oc_uid)
    ###  给玩家充值
    OrderMoney = float(request_data['OrderMoney'])
    data = charge_api(rk_user, oid, item_id, platform = '91',res_dict={},request = request, charge_way='91',charge_money=OrderMoney)
    data_log_mod.set_log('ChargeResultLog', **{'uid':rk_user.uid,'charge_way':'91',\
                                              'result':data['result'],'oid':oid,'item_id':item_id,'subarea': rk_user.subarea,})
    if data['rc'] != 0:
        errcode['ErrorCode'] = 0
        errcode['ErrorDesc'] = u'接收失败'
    return HttpResponse(
        json.dumps(errcode, indent=1),
        content_type='application/x-javascript',
    )