示例#1
0
def gift(request):
    data = {}
    data['status'] = '0'
    gift_keys = game_config.gift_config['gift_config']
    if request.method == "POST":
        if request.POST.get("add_num", "") and request.POST.get("gift_id", ""):
            add_num = min(int(request.POST.get("add_num")), 5000)
            gift_id = request.POST.get("gift_id")
            gift_code_obj = GiftCode.get_instance(gift_id)
            # if int(gift_id) < 10:
            #     gift_id = '0' + gift_id
            # if (len(gift_id) != 2 and int(gift_id) < 100) or (add_num < 1 or add_num >10000):
            #     data['status'] = '1'
            if gift_id not in gift_keys:
                data['status'] = '1'
            # elif len(gift_code_obj.codes) > 0:
            #     data['status'] = '2'
            else:
                new_gift_codes = random.sample(xrange(10000, 100000), add_num)
                new_gift_codes_dict = {
                    gift_id + str(gift_code): ''
                    for gift_code in new_gift_codes
                }
                gift_code_obj.give_codes(new_gift_codes_dict)
    gift_record = []
    for gift_id in gift_keys:
        temp = {}
        gift_code_obj = GiftCode.get(gift_id)
        if not gift_code_obj:
            continue
        temp["gift_id"] = gift_id
        temp['used_expand'] = False
        temp['not_used_expand'] = False
        gift_record.append(temp)
        used_code = [
            gift_code for gift_code in gift_code_obj.codes
            if gift_code_obj.codes[gift_code]
        ]
        not_used_code = [
            gift_code for gift_code in gift_code_obj.codes
            if not gift_code_obj.codes[gift_code]
        ]
        temp["used_code"] = ', '.join(used_code)
        temp["not_used_code"] = ', '.join(not_used_code)
    data["gift_record"] = gift_record
    return 'admin/gift.html', data
示例#2
0
def gift(request):
    data = {}
    data['status'] = '0'
    gift_keys = game_config.gift_config['gift_config']
    if request.method == "POST":
        if request.POST.get("add_num", "") and request.POST.get("gift_id", ""):
            add_num = min(int(request.POST.get("add_num")),5000)
            gift_id = request.POST.get("gift_id")
            gift_code_obj = GiftCode.get_instance(gift_id)
            # if int(gift_id) < 10:
            #     gift_id = '0' + gift_id
            # if (len(gift_id) != 2 and int(gift_id) < 100) or (add_num < 1 or add_num >10000):
            #     data['status'] = '1'
            if gift_id not in gift_keys:
                data['status'] = '1'
            # elif len(gift_code_obj.codes) > 0:
            #     data['status'] = '2'
            else:
                new_gift_codes = random.sample(xrange(10000,100000),add_num)                
                new_gift_codes_dict = {gift_id+str(gift_code):'' for gift_code in new_gift_codes}
                gift_code_obj.give_codes(new_gift_codes_dict)
    gift_record = []
    for gift_id in gift_keys:
        temp = {}
        gift_code_obj = GiftCode.get(gift_id)
        if not gift_code_obj:
            continue
        temp["gift_id"] = gift_id
        temp['used_expand'] = False
        temp['not_used_expand'] = False
        gift_record.append(temp)
        used_code = [gift_code for gift_code in gift_code_obj.codes if gift_code_obj.codes[gift_code]]
        not_used_code = [gift_code for gift_code in gift_code_obj.codes if not gift_code_obj.codes[gift_code]]
        temp["used_code"] = ', '.join(used_code)
        temp["not_used_code"] = ', '.join(not_used_code)
    data["gift_record"] = gift_record
    return 'admin/gift.html', data
示例#3
0
def get_giftCode_gift(rk_user, params):
    """兑换礼品码

    Args:
        gift_code:   礼品码
    """
    gift_keys = game_config.gift_config.get('gift_config', {})
    if rk_user.client_type in settings.ANDROID_CLIENT_TYPE and 'is_open' in game_config.android_config:
        is_open = game_config.android_config.get('is_open', True)
    else:
        is_open = game_config.gift_config.get('is_open', True)
    if not is_open:
        msg = utils.get_msg('gift', 'gift_not_open')
        return 11, {'msg': msg}
    # 校验礼品码
    gift_code = params['gift_code']
    gift_code = gift_code.strip()
    gift_id = gift_code[:-5]
    if gift_id not in gift_keys:
        msg = utils.get_msg('gift', 'gift_code_not_exist')
        return 11, {'msg': msg}
    gift_conf = game_config.gift_config['gift_config'][gift_id]
    start_time = utils.string_toDatetime(
        gift_conf.get('start_time', '2013-05-29 00:00:00'))
    end_time = utils.string_toDatetime(
        gift_conf.get('end_time', '2020-05-29 00:00:00'))
    now_time = datetime.datetime.now()
    if now_time < start_time or now_time > end_time:
        return 11, {'msg': utils.get_msg('gift', 'gift_not_in_right_time')}

    gift_code_obj = GiftCode.get(gift_id)
    user_gift_obj = UserGift.get_instance(rk_user.uid)

    # 平台限制判断
    gift_platform_list = gift_conf.get('platform_list', [])
    if gift_platform_list and rk_user.platform not in gift_platform_list:
        return 11, {'msg': utils.get_msg('gift', 'platform_not_allowed')}
    # 分区限制判断
    gift_subarea_list = gift_conf.get('subarea_list', [])
    if gift_subarea_list and rk_user.subarea not in gift_subarea_list:
        return 11, {'msg': utils.get_msg('gift', 'subarea_not_allowed')}

    if gift_id in user_gift_obj.gift_code_type:
        return 11, {'msg': utils.get_msg('gift', 'this_type_already_get')}
    if not gift_code_obj or gift_code not in gift_code_obj.codes:
        return 11, {'msg': utils.get_msg('gift', 'gift_code_not_exist')}
    # 是否允许不同uid领取相同礼品码
    recycling = gift_conf.get('recycling', False)
    if not recycling:
        if gift_code_obj.codes[gift_code]:
            return 11, {'msg': utils.get_msg('gift', 'gift_code_gived')}
    # 玩家是否已经领取了此礼品码
    if not user_gift_obj.add_has_got_gift_code(gift_code):
        return 11, {'msg': utils.get_msg('gift', 'gift_code_gived')}

    # 记录该礼品码被最后一次领取的uid
    gift_code_obj.codes[gift_code] = rk_user.uid
    gift_code_obj.put()
    # 记录玩家已领的礼品码
    user_gift_obj.gift_code_type.append(gift_id)
    # 发礼品
    all_get_things = tools.add_things(rk_user, [{
        '_id': thing_id,
        'num': num
    } for thing_id, num in gift_conf.get('gift', {}).items()],
                                      where=u"giftCode_award")
    #对于可以升级获得的奖励
    # if gift.get('lv_up_gift',{}):
    #     user_gift_obj.add_lv_up_giftcode(gift_id)
    #     user_gift_obj.get_giftcode_lv_up_award(gift_id)
    user_gift_obj.put()
    return {'get_info': all_get_things}
示例#4
0
def get_giftCode_gift(rk_user, params):
    """兑换礼品码

    Args:
        gift_code:   礼品码
    """
    gift_keys = game_config.gift_config.get("gift_config", {})
    if rk_user.client_type in settings.ANDROID_CLIENT_TYPE and "is_open" in game_config.android_config:
        is_open = game_config.android_config.get("is_open", True)
    else:
        is_open = game_config.gift_config.get("is_open", True)
    if not is_open:
        msg = utils.get_msg("gift", "gift_not_open")
        return 11, {"msg": msg}
    # 校验礼品码
    gift_code = params["gift_code"]
    gift_code = gift_code.strip()
    gift_id = gift_code[:-5]
    if gift_id not in gift_keys:
        msg = utils.get_msg("gift", "gift_code_not_exist")
        return 11, {"msg": msg}
    gift_conf = game_config.gift_config["gift_config"][gift_id]
    start_time = utils.string_toDatetime(gift_conf.get("start_time", "2013-05-29 00:00:00"))
    end_time = utils.string_toDatetime(gift_conf.get("end_time", "2020-05-29 00:00:00"))
    now_time = datetime.datetime.now()
    if now_time < start_time or now_time > end_time:
        return 11, {"msg": utils.get_msg("gift", "gift_not_in_right_time")}

    gift_code_obj = GiftCode.get(gift_id)
    user_gift_obj = UserGift.get_instance(rk_user.uid)

    # 平台限制判断
    gift_platform_list = gift_conf.get("platform_list", [])
    if gift_platform_list and rk_user.platform not in gift_platform_list:
        return 11, {"msg": utils.get_msg("gift", "platform_not_allowed")}
    # 分区限制判断
    gift_subarea_list = gift_conf.get("subarea_list", [])
    if gift_subarea_list and rk_user.subarea not in gift_subarea_list:
        return 11, {"msg": utils.get_msg("gift", "subarea_not_allowed")}

    if gift_id in user_gift_obj.gift_code_type:
        return 11, {"msg": utils.get_msg("gift", "this_type_already_get")}
    if not gift_code_obj or gift_code not in gift_code_obj.codes:
        return 11, {"msg": utils.get_msg("gift", "gift_code_not_exist")}
    # 是否允许不同uid领取相同礼品码
    recycling = gift_conf.get("recycling", False)
    if not recycling:
        if gift_code_obj.codes[gift_code]:
            return 11, {"msg": utils.get_msg("gift", "gift_code_gived")}
    # 玩家是否已经领取了此礼品码
    if not user_gift_obj.add_has_got_gift_code(gift_code):
        return 11, {"msg": utils.get_msg("gift", "gift_code_gived")}

    # 记录该礼品码被最后一次领取的uid
    gift_code_obj.codes[gift_code] = rk_user.uid
    gift_code_obj.put()
    # 记录玩家已领的礼品码
    user_gift_obj.gift_code_type.append(gift_id)
    # 发礼品
    all_get_things = tools.add_things(
        rk_user,
        [{"_id": thing_id, "num": num} for thing_id, num in gift_conf.get("gift", {}).items()],
        where=u"giftCode_award",
    )
    # 对于可以升级获得的奖励
    # if gift.get('lv_up_gift',{}):
    #     user_gift_obj.add_lv_up_giftcode(gift_id)
    #     user_gift_obj.get_giftcode_lv_up_award(gift_id)
    user_gift_obj.put()
    return {"get_info": all_get_things}
示例#5
0
    'dungeon_info.normal_current.floor_id': max_fool,
    'dungeon_info.normal_current.room_id': max_room,
    'dungeon_info.normal_current.status': 2
})
#持之以恒
continue_login = db.userlogin.find({'total_login_num': {"$gt": 24}})

all_uids = [i['uid'] for i in all_users]
level_top_10_uids = [i['uid'] for i in level_top_10]
gold_top_5_uids = [i['uid'] for i in gold_top_5]
finish_dungeon_uids = [i['uid'] for i in finish_dungeon]
continue_login_uids = [i['uid'] for i in continue_login]

a = {
    'test_1':dict(zip(all_uids,\
        random.sample(GiftCode.get('test_1').codes,len(all_uids)))),
    'test_2':dict(zip(level_top_10_uids,\
        random.sample(GiftCode.get('test_2').codes,len(level_top_10_uids)))),
    'test_3':dict(zip(gold_top_5_uids,\
        random.sample(GiftCode.get('test_3').codes,len(gold_top_5_uids)))),
    'test_4':dict(zip(finish_dungeon_uids,\
        random.sample(GiftCode.get('test_4').codes,len(finish_dungeon_uids)))),
    'test_5':dict(zip(continue_login_uids,\
        random.sample(GiftCode.get('test_5').codes,len(continue_login_uids)))),
    }

# all_uids = set(reduce(lambda x,y:x+y,a.values()))

user_gift_record = {}
for uid in all_uids:
    user_gift_record[uid] = []
示例#6
0
max_fool = str(max([ int(i) for i in dungeon_config]))
max_room = str(max([ int(i) for i in dungeon_config[max_fool]['rooms']]))
# normal_current
finish_dungeon = db.userdungeon.find({'dungeon_info.normal_current.floor_id':max_fool,'dungeon_info.normal_current.room_id':max_room,'dungeon_info.normal_current.status':2})
#持之以恒
continue_login = db.userlogin.find({'total_login_num':{"$gt":24}})

all_uids = [i['uid']for i in all_users]
level_top_10_uids = [i['uid']for i in level_top_10]
gold_top_5_uids = [i['uid']for i in gold_top_5]
finish_dungeon_uids = [i['uid']for i in finish_dungeon]
continue_login_uids = [i['uid']for i in continue_login]

a = {
    'test_1':dict(zip(all_uids,\
        random.sample(GiftCode.get('test_1').codes,len(all_uids)))),
    'test_2':dict(zip(level_top_10_uids,\
        random.sample(GiftCode.get('test_2').codes,len(level_top_10_uids)))),
    'test_3':dict(zip(gold_top_5_uids,\
        random.sample(GiftCode.get('test_3').codes,len(gold_top_5_uids)))),
    'test_4':dict(zip(finish_dungeon_uids,\
        random.sample(GiftCode.get('test_4').codes,len(finish_dungeon_uids)))),
    'test_5':dict(zip(continue_login_uids,\
        random.sample(GiftCode.get('test_5').codes,len(continue_login_uids)))),
    }

# all_uids = set(reduce(lambda x,y:x+y,a.values()))

user_gift_record = {}
for uid in all_uids:
    user_gift_record[uid] = []