コード例 #1
0
def activity_config(aid):
    """获取活动配置接口(GET)

    :uri: /activity/<string:aid>/config
    :return: {"activity_games": list, "status": string, "buttons": list, "activity_config": Object}
    """

    activity_games = GameActivity.get_by_aid(aid)
    activity_games = [game.format() for game in activity_games]

    status = ActivityConfig.activity_status(aid)

    activity_config = ActivityConfig.get_one(aid)

    if activity_config:
        activity_config = activity_config.format()

    return {
        "activity_games": activity_games,
        "status": status,
        "buttons": [],
        'activity_config': activity_config
    }
コード例 #2
0
ファイル: traffic.py プロジェクト: leepood/migu_community
def traffic_send():
    """发放流量 (GET|POST&LOGIN)

    :uri: /traffic/send
    :param traffic_type: (first_login, video_share)
    :returns: {'message': str}
    """
    user = request.authed_user
    traffic_type = request.values.get('traffic_type', None)
    device = request.values.get('device', None)

    status = ActivityConfig.activity_status()
    if const.ACTIVITY_PAUSE == status:
        print_log('app_traffic',
                  '[%s][%s]: activity is pause' % (traffic_type, user.phone))
        return error.TrafficSendFail(u'小伙伴们太热情了,稍后再来吧!')
    elif const.ACTIVITY_END == status:
        print_log('app_traffic',
                  '[%s][%s]: activity is end' % (traffic_type, user.phone))
        return error.UserTrafficZero(u'亲,我们的奖品已经送完啦,下次要早点来哦!')

    utl = UserTrafficLog.get_traffic_by_type(str(user._id), traffic_type)
    if not utl and traffic_type == 'video_share':
        print_log('app_traffic',
                  '[video_share][%s]: UserTrafficExists' % user.phone)
        return error.UserTrafficExists(u'亲,你还没有分享自己的作品哦,赶快去分享你的游戏视频,再来领取吧!')
    elif utl and utl.status in [
            const.TRAFFIC_SUCCESS, const.TRAFFIC_RECEIVED_SUCCESS,
            const.TRAFFIC_RECEIVED_PROCESS
    ]:
        print_log('app_traffic',
                  '[%s][%s]: TrafficExists' % (traffic_type, user.phone))
        return error.TrafficExists

    utl_device = UserTrafficLog.get_traffic_by_device(device, traffic_type)
    if utl_device:
        print_log(
            'app_traffic',
            '[%s][%s][%s]: device repeat' % (traffic_type, user.phone, device))
        return error.UserTrafficInvalid(u'亲,同一部终端只能领取一次流量哦!')

    utl_count = UserTrafficLog.traffic_count_by_type(traffic_type)
    if utl_count and utl_count > const.TRAFFIC_CATEGORY_NUM.get(
            traffic_type, None):
        print_log('app_traffic',
                  '[%s][%s]: UserTrafficZero' % (traffic_type, user.phone))
        return error.UserTrafficZero(u'亲,我们的奖品已经送完啦,下次要早点来哦!')

    key = 'lock:traffic:%s:%s' % (user.phone, utl.order_id)
    with util.Lockit(Redis, key) as locked:
        if locked:
            return error.TrafficSendFail
        # 移动接口返回
        if Traffic.send_traffic(utl.order_id, user.phone):
            utl.update_model(
                {'$set': {
                    'status': const.TRAFFIC_SUCCESS,
                    'device': device
                }})
        else:
            utl.update_model({'$set': {'status': const.TRAFFIC_FAIL}})
            return error.TrafficSendFail(u'小伙伴们太热情了,稍后再来吧!')
    return {"message": "你已经成功分享视频, 恭喜你获得免费流量150M, 礼物将以光速飞到你的碗里去哦, 请注意查收!"}