コード例 #1
0
def check_excite_activity(activity_id, deleted=False):
    ''' 检查精彩活动中是否有定时活动并定时开启, 活动结束后定时把未领奖励发到领奖中心
    @param: deleted-True:清除旧数据, False:不清除
    '''
    global PAY_ACTIVITY_AWARD_TIME, CONSUME_ACTIVITY_AWARD_TIME, GROUP_BUY_AWARD_TIME

    _redis_key = None
    _award_center_type = AWARD_TYPE_UNKNOWN
    if activity_id == EXCITE_PAY_ACTIVITY:
        _redis_key = HASH_PAY_ACTIVITY
        _award_center_type = AWARD_TYPE_PAY_ACTIVITY
        PAY_ACTIVITY_AWARD_TIME = int(time())
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        _redis_key = HASH_CONSUME_ACTIVITY
        _award_center_type = AWARD_TYPE_CONSUME_ACTIVITY
        CONSUME_ACTIVITY_AWARD_TIME = int(time())
    elif activity_id == EXCITE_PAY_CREDITS_BACK:
        _redis_key = HASH_PAY_CREDITS_BACK

    elif activity_id == EXCITE_GROUP_BUY:
        _redis_key = DICT_GROUP_BUY_PERSON_INFO
        GROUP_BUY_AWARD_TIME = int(time())
        _award_center_type = AWARD_TYPE_GROUP_BUY

    if not _redis_key:
        defer.returnValue( None )

    _all_excite_conf = get_excite_activity_conf()
    for _excite_conf in _all_excite_conf.itervalues():
        if _excite_conf['ActivityID'] == activity_id:
            break
    else:
        yield redis.delete( _redis_key )
        defer.returnValue( None )

    # 每次OSS同步会删除旧的数据, 策划要求
    if deleted:
        yield redis.delete( _redis_key )

    # 定时发放奖励 针对活动结束时需要发放奖励的活动
    if activity_id == EXCITE_PAY_ACTIVITY:
        interval_seconds = datetime2time( _excite_conf['CloseTime'] )- PAY_ACTIVITY_AWARD_TIME
        log.warn('excite activity would award to award center after {0} seconds, activity_id: {1}.'.format( interval_seconds, activity_id ))
        if interval_seconds <= 0:
            defer.returnValue( None )
        reactor.callLater( interval_seconds, grant_excite_activity_award, activity_id, _redis_key, _award_center_type, PAY_ACTIVITY_AWARD_TIME )
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        interval_seconds = datetime2time( _excite_conf['CloseTime'] )- CONSUME_ACTIVITY_AWARD_TIME
        log.warn('excite activity would award to award center after {0} seconds, activity_id: {1}.'.format( interval_seconds, activity_id ))
        if interval_seconds <= 0:
            defer.returnValue( None )
        reactor.callLater( interval_seconds, grant_excite_activity_award, activity_id, _redis_key, _award_center_type, CONSUME_ACTIVITY_AWARD_TIME )

    elif activity_id == EXCITE_GROUP_BUY:
        interval_seconds = datetime2time( _excite_conf['CloseTime'] )- GROUP_BUY_AWARD_TIME
        log.warn('excite activity would award to award center after {0} seconds, activity_id: {1}.'.format( interval_seconds, activity_id ))
        if interval_seconds <= 0:
            defer.returnValue( None )
        reactor.callLater( interval_seconds, grant_group_buy_award, activity_id, _redis_key, _award_center_type, GROUP_BUY_AWARD_TIME )
    defer.returnValue( None )
コード例 #2
0
    def open_and_close_time(self, activity_type):
        _conf = get_excite_activity_conf()

        _begin_t, _end_t = 0, 0

        for _c in _conf.itervalues():
            if _c['ActivityID'] == activity_type:
                _begin_t, _end_t = datetime2time(_c['OpenTime']), datetime2time(_c['CloseTime'])
                break

        return _begin_t, _end_t
コード例 #3
0
    def open_and_close_time(self, activity_type):
        _conf = get_excite_activity_conf()

        _begin_t, _end_t = 0, 0

        for _c in _conf.itervalues():
            if _c['ActivityID'] == activity_type:
                _begin_t, _end_t = datetime2time(
                    _c['OpenTime']), datetime2time(_c['CloseTime'])
                break

        return _begin_t, _end_t
コード例 #4
0
ファイル: character.py プロジェクト: hw233/python_3dkserver
def check_grant_items(cid, user):
    ''' 检查是否有全服发放的道具可领, 有时发放到领奖中心
    '''
    _register_ts    = datetime2time( user.base_att.register_time )
    _grant_keys_got = yield redis.smembers( SET_GOT_GRANT_KEYS%cid )

    _all_grants = yield redis.hgetall( HASH_GM_GRANT_ITEMS )
    if not _all_grants:
        defer.returnValue( NO_ERROR )

    for _grant_key, _grant_info in _all_grants.iteritems():
        _grant_key = int(_grant_key)
        # 判断注册时间点是否在发送道具时间点之后
        if _register_ts and _grant_key < _register_ts:
            continue
        if _grant_key in _grant_keys_got:
            continue
        # 检查时间是否过期, 14天
        if check_valid_time(_grant_key, hour=AWARD_VALID_HOURS):
            yield redis.hdel( HASH_GM_GRANT_ITEMS, _grant_key )
            continue
        # _grant_info=[玩家cid列表, 发放的道具, 过期时间戳]
        _grant_info = loads(_grant_info)
        if not _grant_info[0] or cid in _grant_info[0]:
            yield redis.sadd( SET_GOT_GRANT_KEYS%cid, _grant_key )
            yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_GM, [_grant_key, _grant_info[1]], flag=False )
 
    defer.returnValue( NO_ERROR )
コード例 #5
0
ファイル: package.py プロジェクト: hw233/python_3dkserver
def reward_to_center(cid, pay_date, package_id):
    ''' 将未领的豪华签到奖励发放到领奖中心 
    @param: pay_date-查询当天的充值记录
    @param: package_id-豪华签到的礼包ID
    '''
    conf = get_pay_login_package_conf(package_id)
    if not conf:
        defer.returnValue(NOT_FOUND_CONF)

    # had total cost
    _date = pay_date.strftime("%Y-%m-%d")
    _had_cost = yield get_daily_pay_record(cid, _date)

    if conf['NeedCost'] > _had_cost:
        defer.returnValue(REQUEST_LIMIT_ERROR)

    # timestamp-豪华签到奖励的时间点
    timestamp = datetime2time(pay_date)
    yield g_AwardCenterMgr.new_award(cid, AWARD_TYPE_PAY_LOGIN,
                                     [timestamp, package_id])
    # 更新豪华签到记录
    yield redis.hset(HASH_PAY_LOGIN_PACKAGE, cid,
                     dumps([timestamp, package_id, 1]))

    defer.returnValue(NO_ERROR)
コード例 #6
0
ファイル: entity.py プロジェクト: huangxiaohen2738/server3
async def load_m(manager, *args):
    with (await manager.rlock):
        if manager.dirty_state == DirtyState.NONE:
            foreign_ID = args[0]
            foreign_ID ='"{0}"'.format(foreign_ID) if isinstance(foreign_ID, str) else foreign_ID

            _sql = 'SELECT {0} FROM tb_{1} WHERE deleted=0 AND {2}={3};'.format(
                    ','.join(manager.fields),
                    manager.table_name,
                    manager.foreign_field,
                    foreign_ID
                )
            dataset = await fetchall(_sql)

            for row in dataset:
                _entity = manager.init()
                row = list(row)
                for idx, field_name in enumerate(manager.fields):
                    if field_name in manager.time_fields:
                        row[idx] = datetime2time(row[idx])
                row = tuple(row)
                _entity._replace(**dict(zip(manager.fields, row)))
                _entity.dirty_state = DirtyState.SYNCED
                _key = getattr(_entity, manager.primary_field)
                manager.cache[_key] = _entity

        manager.dirty_state = DirtyState.SYNCED
コード例 #7
0
ファイル: entity.py プロジェクト: huangxiaohen2738/server3
async def load_s(self, *args):
    with (await self.rlock):
        if self.dirty_state == DirtyState.NONE:
            ID = args[0]
            ID ='"{0}"'.format(ID) if isinstance(ID, str) else ID

            _sql = 'SELECT {0} FROM tb_{1} WHERE deleted=0 AND {2}={3};'.format(
                    ','.join(self.fields),
                    self.table_name,
                    self.primary_field,
                    ID
                )

            res = await fetchone(_sql)
            if res:
                for idx, field_name in enumerate(self.fields):
                    if field_name not in self.time_fields:
                        setattr(self, field_name, res[idx])
                    else:
                        setattr(self, field_name, datetime2time(res[idx]))
            else:
                raise Exception('No such row in table:{0}, ID:{1}, sql:{2}'.format(self.table_name, args[0], _sql))

            for attrib in self.__dict__.values():
                if is_entity_instance(attrib):
                    await attrib.load()

        self.dirty_state = DirtyState.SYNCED
コード例 #8
0
ファイル: gemsgpack.py プロジェクト: anson-tang/3dkserver
def _packb2(x):
    """
    Serialize a Python object into MessagePack bytes.

    Args:
        x: Python object

    Returns:
        A 'str' containing the serialized bytes.

    Raises:
        UnsupportedType(PackException):
            Object type not supported for packing.

    Example:
    >>> umsgpack.packb({u"compact": True, u"schema": 0})
    '\x82\xa7compact\xc3\xa6schema\x00'
    >>>
    """
    global compatibility

    if x is None:
        return _pack_nil(x)
    elif isinstance(x, bool):
        return _pack_boolean(x)
    elif isinstance(x, int) or isinstance(x, long):
        return _pack_integer(x)
    elif isinstance(x, float):
        return _pack_float(x)
    elif isinstance(x, decimal.Decimal):
        return _pack_float(float(x))
    elif isinstance(x, datetime.datetime):
        return _pack_integer(datetime2time(x))
    elif compatibility and isinstance(x, unicode):
        return _pack_oldspec_raw(bytes(x))
    elif compatibility and isinstance(x, bytes):
        return _pack_oldspec_raw(x)
    elif isinstance(x, unicode):
        return _pack_string(x)
    elif isinstance(x, str):
        return _pack_binary(x)
    elif isinstance(x, list) or isinstance(x, tuple):
        return _pack_array(x)
    elif isinstance(x, dict):
        return _pack_map(x)
    elif isinstance(x, Ext):
        return _pack_ext(x)
    else:
        raise UnsupportedTypeException("unsupported type: %s" % str(type(x)))
コード例 #9
0
ファイル: gemsgpack.py プロジェクト: cash2one/3dkserver
def _packb2(x):
    """
    Serialize a Python object into MessagePack bytes.

    Args:
        x: Python object

    Returns:
        A 'str' containing the serialized bytes.

    Raises:
        UnsupportedType(PackException):
            Object type not supported for packing.

    Example:
    >>> umsgpack.packb({u"compact": True, u"schema": 0})
    '\x82\xa7compact\xc3\xa6schema\x00'
    >>>
    """
    global compatibility

    if x is None:
        return _pack_nil(x)
    elif isinstance(x, bool):
        return _pack_boolean(x)
    elif isinstance(x, int) or isinstance(x, long):
        return _pack_integer(x)
    elif isinstance(x, float):
        return _pack_float(x)
    elif isinstance(x, decimal.Decimal):
        return _pack_float(float(x))
    elif isinstance(x, datetime.datetime):
        return _pack_integer(datetime2time(x))
    elif compatibility and isinstance(x, unicode):
        return _pack_oldspec_raw(bytes(x))
    elif compatibility and isinstance(x, bytes):
        return _pack_oldspec_raw(x)
    elif isinstance(x, unicode):
        return _pack_string(x)
    elif isinstance(x, str):
        return _pack_binary(x)
    elif isinstance(x, list) or isinstance(x, tuple):
        return _pack_array(x)
    elif isinstance(x, dict):
        return _pack_map(x)
    elif isinstance(x, Ext):
        return _pack_ext(x)
    else:
        raise UnsupportedTypeException("unsupported type: %s" % str(type(x)))
コード例 #10
0
def activity_notice_info(p, req):
    ''' 获取活动公告的内容 '''
    cid, = req

    user = g_UserMgr.getUser(cid)
    if not user:
        log.error('Can not find user. cid: {0}.'.format( cid ))
        return CONNECTION_LOSE
 
    notice_data = []
    notice_conf = get_activity_notice_conf()
    for _c in notice_conf.itervalues():
        notice_data.append( [_c['ID'], _c['Title'], _c['Content'], datetime2time(_c['OpenTime']), datetime2time(_c['CloseTime'])] )

    return notice_data
コード例 #11
0
def check_limit_fellow(deleted=False):
    ''' 开服期间的限时神将活动
    @param: deleted-True:清除旧数据, False:不清除
    '''
    global ACTIVITY_AWARD_TIME

    _all_excite_conf = get_excite_activity_conf()
    for _excite_conf in _all_excite_conf.itervalues():
        if _excite_conf['ActivityID'] == EXCITE_LIMIT_FELLOW:
            break
    else:
        yield redis.delete(HASH_LIMIT_FELLOW_SHRINE,
                           SET_LIMIT_FELLOW_NAME_SCORE)
        defer.returnValue(None)
    # 限时神将 每次OSS同步会删除旧的数据
    if deleted:
        yield redis.delete(HASH_LIMIT_FELLOW_SHRINE,
                           SET_LIMIT_FELLOW_NAME_SCORE)

    # 限时神将中开启的活动配置
    _activity = get_limit_fellow_conf()
    if not _activity:
        yield redis.delete(HASH_LIMIT_FELLOW_SHRINE,
                           SET_LIMIT_FELLOW_NAME_SCORE)
        defer.returnValue(None)

    _activity_id = _activity['ActivityID']
    # 限时神将 活动的奖励
    _award_conf = get_limit_fellow_award_conf(_activity_id)
    if not _award_conf:
        yield redis.delete(HASH_LIMIT_FELLOW_SHRINE,
                           SET_LIMIT_FELLOW_NAME_SCORE)
        defer.returnValue(None)

    # 定时
    all_ranks = _award_conf.keys()
    ACTIVITY_AWARD_TIME = int(time())
    interval_seconds = datetime2time(
        _excite_conf['CloseTime']) - ACTIVITY_AWARD_TIME
    if interval_seconds <= 0:
        defer.returnValue(None)

    log.warn(
        'limit fellow would award to award center after {0} seconds, _activity_id: {1}, ACTIVITY_AWARD_TIME: {2}.'
        .format(interval_seconds, _activity_id, ACTIVITY_AWARD_TIME))
    reactor.callLater(interval_seconds, grant_limit_fellow_award, all_ranks,
                      _activity_id, ACTIVITY_AWARD_TIME)
    defer.returnValue(None)
コード例 #12
0
def check_limit_fellow(deleted=False):
    ''' 开服期间的限时神将活动
    @param: deleted-True:清除旧数据, False:不清除
    '''
    global ACTIVITY_AWARD_TIME

    _all_excite_conf = get_excite_activity_conf()
    for _excite_conf in _all_excite_conf.itervalues():
        if _excite_conf['ActivityID'] == EXCITE_LIMIT_FELLOW:
            break
    else:
        yield redis.delete( HASH_LIMIT_FELLOW_SHRINE, SET_LIMIT_FELLOW_NAME_SCORE )
        defer.returnValue( None )
    # 限时神将 每次OSS同步会删除旧的数据 
    if deleted:
        yield redis.delete( HASH_LIMIT_FELLOW_SHRINE, SET_LIMIT_FELLOW_NAME_SCORE )

    # 限时神将中开启的活动配置
    _activity = get_limit_fellow_conf()
    if not _activity:
        yield redis.delete( HASH_LIMIT_FELLOW_SHRINE, SET_LIMIT_FELLOW_NAME_SCORE )
        defer.returnValue( None )

    _activity_id = _activity['ActivityID']
    # 限时神将 活动的奖励
    _award_conf  = get_limit_fellow_award_conf( _activity_id )
    if not _award_conf:
        yield redis.delete( HASH_LIMIT_FELLOW_SHRINE, SET_LIMIT_FELLOW_NAME_SCORE )
        defer.returnValue( None )

    # 定时
    all_ranks = _award_conf.keys()
    ACTIVITY_AWARD_TIME = int(time())
    interval_seconds = datetime2time( _excite_conf['CloseTime'] ) - ACTIVITY_AWARD_TIME
    if interval_seconds <= 0:
        defer.returnValue( None )

    log.warn('limit fellow would award to award center after {0} seconds, _activity_id: {1}, ACTIVITY_AWARD_TIME: {2}.'.format( interval_seconds, _activity_id, ACTIVITY_AWARD_TIME ))
    reactor.callLater( interval_seconds, grant_limit_fellow_award, all_ranks, _activity_id, ACTIVITY_AWARD_TIME )
    defer.returnValue( None )
コード例 #13
0
ファイル: package.py プロジェクト: anson-tang/3dkserver
def reward_to_center(cid, pay_date, package_id):
    ''' 将未领的豪华签到奖励发放到领奖中心 
    @param: pay_date-查询当天的充值记录
    @param: package_id-豪华签到的礼包ID
    '''
    conf = get_pay_login_package_conf( package_id )
    if not conf:
        defer.returnValue( NOT_FOUND_CONF )

    # had total cost
    _date = pay_date.strftime("%Y-%m-%d")
    _had_cost = yield get_daily_pay_record(cid, _date)

    if conf['NeedCost'] > _had_cost:
        defer.returnValue( REQUEST_LIMIT_ERROR )

    # timestamp-豪华签到奖励的时间点
    timestamp = datetime2time( pay_date )
    yield g_AwardCenterMgr.new_award( cid, AWARD_TYPE_PAY_LOGIN, [timestamp, package_id] )
    # 更新豪华签到记录
    yield redis.hset(HASH_PAY_LOGIN_PACKAGE, cid, dumps([timestamp, package_id, 1]))

    defer.returnValue( NO_ERROR )
コード例 #14
0
 def activity_info(self):
     _data   = []
     _dt_now = datetime.now()
     _conf   = get_excite_activity_conf()
     for _c in _conf.itervalues():
         _status = []
         if _c['OpenTime'] > _dt_now or _c['CloseTime'] <= _dt_now:
             continue
         if _c['ActivityID'] == EXCITE_FIRSTPAY:
             # 已完成首充
             if self.user.base_att.firstpay > 0:
                 continue
         elif _c['ActivityID'] == EXCITE_EAT_PEACH:
             _s , _, _, _ = yield self.user.check_eat_peach_status( _dt_now )
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_MYSTICALSHOP:
             _status = yield self.mystical_shop_mgr.mystical_status()
         elif _c['ActivityID'] == EXCITE_MONTHLY_CARD:
             _status = yield self.user.new_check_monthly_card_status(MONTHLY_CARD_NORMAL)
             _dual_status = yield self.user.new_check_monthly_card_status(MONTHLY_CARD_DUAL)
             _status.extend(_dual_status)
         elif _c['ActivityID'] == EXCITE_GROWTH_PLAN:
             _s = yield self.user.check_growth_plan_status()
             # 奖励已领完
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_EXCHANGE_LIMITED:
             _s = yield self.exchange_limited_mgr.exchange_refresh_times()
             _status = [ 1 if _s > 0 else 0]
         #elif _c['ActivityID'] == EXCITE_VIP_WELFARE:
         #    _s = yield self.user.check_vip_welfare_status()
             # 当前等级没有VIP福利
         #    if _s == 2:
         #        continue
         #    _status = [_s]
         elif _c['ActivityID'] == EXCITE_LIMIT_FELLOW:
             _s, _ = yield self.limit_fellow_mgr.status()
             if _s < 0:
                 continue
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_PAY_ACTIVITY:
             _s, _total_pay = yield self.user.check_pay_activity_status()
             _status = [_total_pay, _s]
         elif _c['ActivityID'] == EXCITE_CONSUME_ACTIVITY:
             _s, _total_consume = yield self.user.check_consume_activity_status()
             _status = [_total_consume, _s]
         elif _c['ActivityID'] == EXCITE_NEWYEAR_PACKAGE:
             _recved = yield newYearPackage.received_today(self.user.cid)
             _s = 0 if _recved else 1
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_LOVER_KISS:
             _m = yield LoverKissMgr.get(self.user)
             if _m:
                 _s = 0 if _m.check_activity() else 1
                 _status = [_s]
         elif _c['ActivityID'] == EXCITE_HAPPY_NEW_YEAR:
             _s = 0 if self.check_happy_new_year() == 0 else 1
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_PAY_CREDITS_BACK:
             _had_back = yield self.user.pay_credits_back_status()
             _status   = [_had_back]
         elif _c['ActivityID'] == EXCITE_DIG_TREASURE:
             _s = yield self.get_dig_treasure_info()
             _status = [_s, self.free_dig_count, self.dig_total_count]
         elif _c['ActivityID'] == EXCITE_TIME_LIMIT_SHOP:
             #_can_buy = yield timeLimitedShop.can_buy(self.user)
             #_status = [_can_buy]
             _status = [1]
         _data.append( [_c['ID'], _c['ActivityID'], _c['ActivityType'], _c['ActivityName'], _c['ActivityIcon'], datetime2time(_c['OpenTime']), datetime2time(_c['CloseTime']), _status] )
     defer.returnValue( _data )
コード例 #15
0
 def activity_info(self):
     _data = []
     _dt_now = datetime.now()
     _conf = get_excite_activity_conf()
     for _c in _conf.itervalues():
         _status = []
         if _c['OpenTime'] > _dt_now or _c['CloseTime'] <= _dt_now:
             continue
         if _c['ActivityID'] == EXCITE_FIRSTPAY:
             # 已完成首充
             if self.user.base_att.firstpay > 0:
                 continue
         elif _c['ActivityID'] == EXCITE_EAT_PEACH:
             _s, _, _, _ = yield self.user.check_eat_peach_status(_dt_now)
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_MYSTICALSHOP:
             _status = yield self.mystical_shop_mgr.mystical_status()
         elif _c['ActivityID'] == EXCITE_MONTHLY_CARD:
             _status = yield self.user.new_check_monthly_card_status(
                 MONTHLY_CARD_NORMAL)
             _dual_status = yield self.user.new_check_monthly_card_status(
                 MONTHLY_CARD_DUAL)
             _status.extend(_dual_status)
         elif _c['ActivityID'] == EXCITE_GROWTH_PLAN:
             _s = yield self.user.check_growth_plan_status()
             # 奖励已领完
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_EXCHANGE_LIMITED:
             _s = yield self.exchange_limited_mgr.exchange_refresh_times()
             _status = [1 if _s > 0 else 0]
         #elif _c['ActivityID'] == EXCITE_VIP_WELFARE:
         #    _s = yield self.user.check_vip_welfare_status()
         # 当前等级没有VIP福利
         #    if _s == 2:
         #        continue
         #    _status = [_s]
         elif _c['ActivityID'] == EXCITE_LIMIT_FELLOW:
             _s, _ = yield self.limit_fellow_mgr.status()
             if _s < 0:
                 continue
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_PAY_ACTIVITY:
             _s, _total_pay = yield self.user.check_pay_activity_status()
             _status = [_total_pay, _s]
         elif _c['ActivityID'] == EXCITE_CONSUME_ACTIVITY:
             _s, _total_consume = yield self.user.check_consume_activity_status(
             )
             _status = [_total_consume, _s]
         elif _c['ActivityID'] == EXCITE_NEWYEAR_PACKAGE:
             _recved = yield newYearPackage.received_today(self.user.cid)
             _s = 0 if _recved else 1
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_LOVER_KISS:
             _m = yield LoverKissMgr.get(self.user)
             if _m:
                 _s = 0 if _m.check_activity() else 1
                 _status = [_s]
         elif _c['ActivityID'] == EXCITE_HAPPY_NEW_YEAR:
             _s = 0 if self.check_happy_new_year() == 0 else 1
             _status = [_s]
         elif _c['ActivityID'] == EXCITE_PAY_CREDITS_BACK:
             _had_back = yield self.user.pay_credits_back_status()
             _status = [_had_back]
         elif _c['ActivityID'] == EXCITE_DIG_TREASURE:
             _s = yield self.get_dig_treasure_info()
             _status = [_s, self.free_dig_count, self.dig_total_count]
         elif _c['ActivityID'] == EXCITE_TIME_LIMIT_SHOP:
             #_can_buy = yield timeLimitedShop.can_buy(self.user)
             #_status = [_can_buy]
             _status = [1]
         _data.append([
             _c['ID'], _c['ActivityID'], _c['ActivityType'],
             _c['ActivityName'], _c['ActivityIcon'],
             datetime2time(_c['OpenTime']),
             datetime2time(_c['CloseTime']), _status
         ])
     defer.returnValue(_data)
コード例 #16
0
def check_excite_activity(activity_id, deleted=False):
    ''' 检查精彩活动中是否有定时活动并定时开启, 活动结束后定时把未领奖励发到领奖中心
    @param: deleted-True:清除旧数据, False:不清除
    '''
    global PAY_ACTIVITY_AWARD_TIME, CONSUME_ACTIVITY_AWARD_TIME, GROUP_BUY_AWARD_TIME

    _redis_key = None
    _award_center_type = AWARD_TYPE_UNKNOWN
    if activity_id == EXCITE_PAY_ACTIVITY:
        _redis_key = HASH_PAY_ACTIVITY
        _award_center_type = AWARD_TYPE_PAY_ACTIVITY
        PAY_ACTIVITY_AWARD_TIME = int(time())
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        _redis_key = HASH_CONSUME_ACTIVITY
        _award_center_type = AWARD_TYPE_CONSUME_ACTIVITY
        CONSUME_ACTIVITY_AWARD_TIME = int(time())
    elif activity_id == EXCITE_PAY_CREDITS_BACK:
        _redis_key = HASH_PAY_CREDITS_BACK

    elif activity_id == EXCITE_GROUP_BUY:
        _redis_key = DICT_GROUP_BUY_PERSON_INFO
        GROUP_BUY_AWARD_TIME = int(time())
        _award_center_type = AWARD_TYPE_GROUP_BUY

    if not _redis_key:
        defer.returnValue(None)

    _all_excite_conf = get_excite_activity_conf()
    for _excite_conf in _all_excite_conf.itervalues():
        if _excite_conf['ActivityID'] == activity_id:
            break
    else:
        yield redis.delete(_redis_key)
        defer.returnValue(None)

    # 每次OSS同步会删除旧的数据, 策划要求
    if deleted:
        yield redis.delete(_redis_key)

    # 定时发放奖励 针对活动结束时需要发放奖励的活动
    if activity_id == EXCITE_PAY_ACTIVITY:
        interval_seconds = datetime2time(
            _excite_conf['CloseTime']) - PAY_ACTIVITY_AWARD_TIME
        log.warn(
            'excite activity would award to award center after {0} seconds, activity_id: {1}.'
            .format(interval_seconds, activity_id))
        if interval_seconds <= 0:
            defer.returnValue(None)
        reactor.callLater(interval_seconds, grant_excite_activity_award,
                          activity_id, _redis_key, _award_center_type,
                          PAY_ACTIVITY_AWARD_TIME)
    elif activity_id == EXCITE_CONSUME_ACTIVITY:
        interval_seconds = datetime2time(
            _excite_conf['CloseTime']) - CONSUME_ACTIVITY_AWARD_TIME
        log.warn(
            'excite activity would award to award center after {0} seconds, activity_id: {1}.'
            .format(interval_seconds, activity_id))
        if interval_seconds <= 0:
            defer.returnValue(None)
        reactor.callLater(interval_seconds, grant_excite_activity_award,
                          activity_id, _redis_key, _award_center_type,
                          CONSUME_ACTIVITY_AWARD_TIME)

    elif activity_id == EXCITE_GROUP_BUY:
        interval_seconds = datetime2time(
            _excite_conf['CloseTime']) - GROUP_BUY_AWARD_TIME
        log.warn(
            'excite activity would award to award center after {0} seconds, activity_id: {1}.'
            .format(interval_seconds, activity_id))
        if interval_seconds <= 0:
            defer.returnValue(None)
        reactor.callLater(interval_seconds, grant_group_buy_award, activity_id,
                          _redis_key, _award_center_type, GROUP_BUY_AWARD_TIME)
    defer.returnValue(None)