示例#1
0
def __calculate_loopgap_dungeon_time(floor_conf):
    """
    计算循环战场还有多长时间开启
    """
    time_now = datetime.datetime.now()
    time_now_str = utils.datetime_toString(time_now)
    return_start_time = floor_conf["start_time"]
    return_end_time = floor_conf["end_time"]
    loop_gap = int(floor_conf["loop_gap"])
    if return_start_time[:10] > time_now_str[:10]:
        return_end_time = return_start_time[:10] + floor_conf["end_time"][10:]
    else:
        temp_today = utils.string_toDatetime(time_now_str[:10] + " 00:00:00")
        temp_start = utils.string_toDatetime(floor_conf["start_time"][:10] + " 00:00:00")
        # 小时数分钟数未到时间并且当天是循环开放时间,则给当天时间
        delta_days = (temp_today - temp_start).days
        if time_now_str[10:] < return_end_time[10:] and not delta_days % loop_gap:
            return_start_time = time_now_str[:10] + floor_conf["start_time"][10:]
            return_end_time = time_now_str[:10] + floor_conf["end_time"][10:]
        else:
            # 则计算后面开放时间
            _start_time = temp_today + datetime.timedelta(days=loop_gap - delta_days % loop_gap)
            _start_time = utils.datetime_toString(_start_time)
            return_start_time = _start_time[:10] + floor_conf["start_time"][10:]
            return_end_time = _start_time[:10] + floor_conf["end_time"][10:]
    next_start_time = utils.datetime_toString(
        utils.string_toDatetime(return_start_time) + datetime.timedelta(days=loop_gap)
    )
    next_end_time = utils.datetime_toString(
        utils.string_toDatetime(return_end_time) + datetime.timedelta(days=loop_gap)
    )
    return (return_start_time, return_end_time), (next_start_time, next_end_time)
示例#2
0
def _is_between_times(mail):
    # start 和end time 要符合 年月日 时分秒的格式 ,例如'2014-10-06 11:00:00'
    try:
        start_time = utils.string_toDatetime(mail['start_time'])
        end_time = utils.string_toDatetime(mail['end_time'])
    except ValueError:
        return False

    if start_time <= datetime.datetime.now() <= end_time:
        return True
    else:
        return False
示例#3
0
def _is_between_times(mail):
    # start 和end time 要符合 年月日 时分秒的格式 ,例如'2014-10-06 11:00:00'
    try:
        start_time = utils.string_toDatetime(mail['start_time'])
        end_time = utils.string_toDatetime(mail['end_time'])
    except ValueError:
        return False

    if start_time <= datetime.datetime.now() <= end_time:
        return True
    else:
        return False
示例#4
0
文件: mail.py 项目: wzgdavid/myCoding
def test_is_between_times():
    mail = {
        'mail_id': '2014-11-07-18',
        'title': unicode('18','utf-8'),   # 邮件标题
        'content': unicode('test2df','utf-8'),  # 正文
        'start_time': '2014-10-06  10:00:00',  #开始时间
        'end_time': '2014-12-15  15:00:00',   #结束时间
        'award': {},
    }
    try:
        start_time = utils.string_toDatetime(mail['start_time'])
        end_time = utils.string_toDatetime(mail['end_time'])
    except ValueError:
        print 'start or end time config error'
        return False
    now = datetime.datetime.now()
    if start_time <= now <= end_time:
        return True
    else:
        return False
示例#5
0
def cards_product_statistic(request):
    """元宝gacha武将产出统计
    """
    product_cards = []
    info = ""

    start_date = request.POST.get('start_date', '')
    end_date = request.POST.get('end_date', '')
    sort_by = request.POST.get('sort_by', 'star')

    if not (start_date and end_date):
        info = u"时间不能为空"
        return render_to_response('tool/cards_product_statistic.html', {'start_date': start_date, 'end_date': end_date, 'product_cards': product_cards , 'info': info, 'sort_by': sort_by}, RequestContext(request))
    
    table = app.secondary_log_mongo.mongo['cardproduct']

    start = utils.string_toDatetime(start_date, '%Y-%m-%d') 
    end = utils.string_toDatetime(end_date + ' 23:59:59') 

    # 判断时间间隔因该小于三天
    if -1 < (end - start).days < 3:
        match_query = {}
        match_query = {'date_time':{'$gte': start, '$lte': end},
                'where': {'$in': ['gacha_multi', 'gacha_charge']}
            }

        group_code = { "_id" : '$card_msg.cid', 'count':{"$sum" : 1}}

        product_cards = table.aggregate([{'$match': match_query}, {'$group': group_code}])['result']
        sum_count = sum([float(card['count']) for card in product_cards])
        product_cards = [{'name': game_config.card_config[card['_id']]['name'], 'cid': card['_id'], 'star': game_config.card_config[card['_id']]['star'], 'count': card['count'], 'rate': int(card['count']) * 100 / sum_count} for card in  product_cards]
        if sort_by:
            product_cards.sort(key=lambda card: card[sort_by], reverse=True)
    else:
        info = u"开始时间要不能大于结束时间, 间隔不能大于3天"

    return render_to_response('tool/cards_product_statistic.html', {'start_date': start_date, 'end_date': end_date, 'product_cards': product_cards , 'info': info, 'sort_by': sort_by}, RequestContext(request))
示例#6
0
def __calculate_loopgap_dungeon_time(floor_conf):
    """
    计算循环战场还有多长时间开启
    """
    time_now = datetime.datetime.now()
    time_now_str = utils.datetime_toString(time_now)
    return_start_time = floor_conf['start_time']
    return_end_time = floor_conf['end_time']
    loop_gap = int(floor_conf['loop_gap'])
    if return_start_time[:10] > time_now_str[:10]:
        return_end_time = return_start_time[:10] + floor_conf['end_time'][10:]
    else:
        temp_today = utils.string_toDatetime(time_now_str[:10] + ' 00:00:00')
        temp_start = utils.string_toDatetime(floor_conf['start_time'][:10] +
                                             ' 00:00:00')
        #小时数分钟数未到时间并且当天是循环开放时间,则给当天时间
        delta_days = (temp_today - temp_start).days
        if time_now_str[10:] < return_end_time[10:] and\
        not delta_days % loop_gap:
            return_start_time = time_now_str[:10] + floor_conf['start_time'][
                10:]
            return_end_time = time_now_str[:10] + floor_conf['end_time'][10:]
        else:
            #则计算后面开放时间
            _start_time = temp_today + datetime.timedelta(
                days=loop_gap - delta_days % loop_gap)
            _start_time = utils.datetime_toString(_start_time)
            return_start_time = _start_time[:10] + floor_conf['start_time'][10:]
            return_end_time = _start_time[:10] + floor_conf['end_time'][10:]
    next_start_time = utils.datetime_toString(
        utils.string_toDatetime(return_start_time) +
        datetime.timedelta(days=loop_gap))
    next_end_time = utils.datetime_toString(
        utils.string_toDatetime(return_end_time) +
        datetime.timedelta(days=loop_gap))
    return (return_start_time, return_end_time), (next_start_time,
                                                  next_end_time)
示例#7
0
def __record_month_item(rk_user,item_id,item_info):
    """
    记录月卡信息        
    """
    today = datetime.date.today()
    product_id = item_id.split('.')[-1]
    today_str = datetime_toString(today,'%Y-%m-%d')
    month_item_info = rk_user.user_property.month_item_info
    should_end_time = datetime_toString(today + datetime.timedelta(days=29),'%Y-%m-%d')
    if product_id not in month_item_info:
        month_item_info[product_id] = {
                                        'can_buy':False,#可以购买
                                        'charge_date':[today_str],#购买日期
                                        'can_get_today': False,#领奖开始时间
                                        'start_time':today_str,#领奖开始时间
                                        'end_time':should_end_time,#领奖结束时间
                                       }
    else:
        month_item_info[product_id]['charge_date'].insert(0,today_str)
        month_item_info[product_id]['charge_date'] = month_item_info[product_id]['charge_date'][:5]
        month_item_info[product_id]['can_buy'] = False
        #第一次买或者领奖期限已过
        if not month_item_info[product_id]['end_time'] or today_str >= month_item_info[product_id]['end_time']:
            month_item_info[product_id]['start_time'] = today_str
            month_item_info[product_id]['end_time'] = should_end_time
        else:
            end_time_date = string_toDatetime(month_item_info[product_id]['end_time'],'%Y-%m-%d')
            month_item_info[product_id]['end_time'] = datetime_toString(end_time_date + datetime.timedelta(days=30),'%Y-%m-%d')
    #发首日奖励
    first_day_bonus = item_info.get('first_day_bonus',{})
    if first_day_bonus:
        month_card_award = get_msg('operat', 'month_card_award')
        if month_card_award and product_id in month_card_award:
            content = month_card_award[product_id].get('month_today_award','')
        else:
            content = ''
        rk_user.user_gift.add_gift(first_day_bonus,content)
    rk_user.user_property.put()
示例#8
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
示例#9
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}
示例#10
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}
示例#11
0
def cards_product_statistic(request):
    """元宝gacha武将产出统计
    """
    product_cards = []
    info = ""

    start_date = request.POST.get('start_date', '')
    end_date = request.POST.get('end_date', '')
    sort_by = request.POST.get('sort_by', 'star')

    if not (start_date and end_date):
        info = u"时间不能为空"
        return render_to_response(
            'tool/cards_product_statistic.html', {
                'start_date': start_date,
                'end_date': end_date,
                'product_cards': product_cards,
                'info': info,
                'sort_by': sort_by
            }, RequestContext(request))

    table = app.secondary_log_mongo.mongo['cardproduct']

    start = utils.string_toDatetime(start_date, '%Y-%m-%d')
    end = utils.string_toDatetime(end_date + ' 23:59:59')

    # 判断时间间隔因该小于三天
    if -1 < (end - start).days < 3:
        match_query = {}
        match_query = {
            'date_time': {
                '$gte': start,
                '$lte': end
            },
            'where': {
                '$in': ['gacha_multi', 'gacha_charge']
            }
        }

        group_code = {"_id": '$card_msg.cid', 'count': {"$sum": 1}}

        product_cards = table.aggregate([{
            '$match': match_query
        }, {
            '$group': group_code
        }])['result']
        sum_count = sum([float(card['count']) for card in product_cards])
        product_cards = [{
            'name': game_config.card_config[card['_id']]['name'],
            'cid': card['_id'],
            'star': game_config.card_config[card['_id']]['star'],
            'count': card['count'],
            'rate': int(card['count']) * 100 / sum_count
        } for card in product_cards]
        if sort_by:
            product_cards.sort(key=lambda card: card[sort_by], reverse=True)
    else:
        info = u"开始时间要不能大于结束时间, 间隔不能大于3天"

    return render_to_response(
        'tool/cards_product_statistic.html', {
            'start_date': start_date,
            'end_date': end_date,
            'product_cards': product_cards,
            'info': info,
            'sort_by': sort_by
        }, RequestContext(request))
示例#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