Beispiel #1
0
def activity_top_videos(aid):
    """获取结束时获奖视频

    :uri: activity/<string:aid>/top/videos
    :param page: 页码
    :param nbr: 每页数量
    :returns: {'activity_videos': list, 'end_page': bool, 'activity_config': Object }
    """

    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_videos = list()
    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    avids = ActivityVideo.top_video_end(aid, page, pagesize, activity_config)
    activity_videos.extend([a.format() for a in ActivityVideo.get_list(avids)])
    return {
        'activity_videos': activity_videos,
        'end_page': len(avids) != pagesize,
        'activity_config': activity_config.format()
    }
Beispiel #2
0
def activity_top(aid):
    """获取结束时获奖视频(手动)

    :uri: activity/<string:aid>/manual/top
    :param page:
    :param nbr:
    :return: {'activity_videos': list, 'end_page': bool}
    """

    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_videos = list()
    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    avids = ActivityVideo.get_manual_top(aid, page, pagesize)
    activity_videos.extend([
        a.format() for a in ActivityVideo.get_list(avids, check_online=False)
    ])
    return {
        'activity_videos': activity_videos,
        'end_page': len(avids) != pagesize
    }
Beispiel #3
0
def unlike_video():
    """取消赞视频 (GET|POST&LOGIN)

    :uri: /user/opt/like-video
    :param video_id: 被赞视频id
    :returns: {}
    """
    user = request.authed_user
    vid = request.values.get('video_id', None)
    video = Video.get_one(vid)
    if not video:
        return error.VideoNotExist

    key = 'lock:unlike_video:%s:%s' % (str(user._id), vid)
    with util.Lockit(Redis, key) as locked:
        if locked:
            return error.LikeVideoFailed('取消赞失败')
        ulv = UserLikeVideo.get_by_ship(str(user._id), vid)
        ulv.delete_model() if ulv else None
        # 更新活动点赞数
        avideos = ActivityVideo.get_activity_video(vid=vid)
        for avideo in avideos:
            ts = time.time()
            aconfig = ActivityConfig.get_one(str(avideo['activity_id']),
                                             check_online=False)
            if aconfig and aconfig.status == const.ACTIVITY_BEGIN \
                    and (aconfig.begin_at < ts and aconfig.end_at > ts):
                avideo = ActivityVideo.get_one(avideo['_id'],
                                               check_online=False)
                avideo.update_model({'$inc': {'like_count': -1}})
    return {}
Beispiel #4
0
def delete_comment():
    """删除评论 (GET|POST&LOGIN)

    :uri: /user/opt/delete-comment
    :param comment_id: 评论id
    :returns: {}
    """
    user = request.authed_user
    params = request.values
    cid = params.get('comment_id', None)
    comment = Comment.get_one(cid)
    if not comment:
        return error.CommentNotExist
    if str(comment.author) != str(user._id):
        return error.AuthFailed
    comment.delete_model()
    # 更新活动评论数
    avideos = ActivityVideo.get_activity_video(vid=str(comment.video))
    for avideo in avideos:
        ts = time.time()
        aconfig = ActivityConfig.get_one(str(avideo['activity_id']), check_online=False)
        if aconfig and aconfig.status == const.ACTIVITY_BEGIN \
                and (aconfig.begin_at < ts and aconfig.end_at > ts):
            avideo = ActivityVideo.get_one(avideo['_id'], check_online=False)
            avideo.update_model({'$inc': {'comment_count': -1}})
    return {}
Beispiel #5
0
def activity_popular_videos(aid):
    """获取人气视频

    :uri: activity/<string:aid>/popular/videos
    :param page: 页码
    :param nbr: 每页数量
    :param device: 终端ID
    :returns: {'activity_videos': list, 'end_page': bool, 'activity_config': Object }
    """

    params = request.values
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_videos = list()
    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist
    sort = activity_config.sort

    avids = ActivityVideo.popular_video_ids(aid, sort, page, pagesize)
    activity_videos.extend([v.format() for v in ActivityVideo.get_list(avids)])
    return {
        'activity_videos': activity_videos,
        'end_page': len(avids) != pagesize,
        'activity_config': activity_config.format()
    }
Beispiel #6
0
def activity_video_config(vid):
    """获取app内视频的活动相关配置

    :uri: activity/video/config/<string:vid>
    :return:{"activity": Object, "is_voted": bool, "is_join": bool, "activity_status": bool}
    """
    user = request.authed_user
    params = request.values
    device = params.get('device', None)
    uid = user and str(user._id)

    activity = dict()
    is_join = False
    activity_status = False

    activity_video = ActivityVideo.get_activity_video_by_vid(vid)
    if activity_video:
        is_join = True
        aid = activity_video["activity_id"]
        activity_config = ActivityConfig.get_one(aid, check_online=False)
        if not activity_config.online:
            activity_status = False
        else:
            activity_status = True
        activity = activity_config.format()

    is_voted = True if VoteVideo.get_vote(uid, device, vid) else False
    return {
        "activity": activity,
        "is_voted": is_voted,
        "is_join": is_join,
        "activity_status": activity_status
    }
Beispiel #7
0
def create_comment():
    """创建评论 (GET|POST&LOGIN)

    :uri: /user/opt/submit-comment
    :param video_id: 被评论视频id
    :param content: 评论内容
    :returns: {'comment': object}
    """
    user = request.authed_user
    params = request.values
    vid = params.get('video_id', None)
    content = params.get('content', None)
    if not vid or not content:
        return error.InvalidArguments

    if not Video.get_one(vid):
        return error.VideoNotExist

    # 敏感词检查
    if Spam.filter_words(content, 'comment'):
        return error.InvalidContent
    comment = Comment.init()
    comment.author = ObjectId(str(user._id))
    comment.content = content
    comment.video = ObjectId(vid)
    cid = comment.create_model()
    if cid:
        # 发送评论消息
        Message.send_video_msg(str(user._id), str(vid), 'comment')

    # 任务检查
    if user:
        UserTask.check_user_tasks(str(user._id), COMMENT_VIDEO, 1)

        # 更新活动评论数
        avideos = ActivityVideo.get_activity_video(vid=vid)
        for avideo in avideos:
            ts = time.time()
            aconfig = ActivityConfig.get_one(str(avideo['activity_id']), check_online=False)
            if aconfig and aconfig.status == const.ACTIVITY_BEGIN \
                    and (aconfig.begin_at < ts and aconfig.end_at > ts):
                avideo = ActivityVideo.get_one(avideo['_id'], check_online=False)
                avideo.update_model({'$inc': {'comment_count': 1}})

    return Comment.get_one(str(cid)).format()
Beispiel #8
0
def activity_create_video(aid):
    """创建活动视频 (POST&LOGIN)

    :uri: activity/<string:aid>/new-video
    :param video_id: 原始视频id
    :returns: object
    """
    user = request.authed_user
    vid = request.values['video_id']
    video = Video.get_one(str(vid))
    if not video:
        return error.VideoNotExist

    if str(user._id) != str(video.author):
        return error.AuthFailed

    activity_video = ActivityVideo.get_activity_video_by_vid(vid)
    if activity_video:
        return error.ActivityVideoExist

    activity_video = ActivityVideo.init()
    activity_video.title = video.title
    activity_video.video_id = ObjectId(vid)
    activity_video.like_count = video.like
    activity_video.comment_count = video.comment_count
    activity_video.vv = video.vv
    activity_video.author = ObjectId(str(user._id))
    activity_video.activity_id = ObjectId(str(aid))
    activity_video.cover = video.cover
    activity_video.duration = video.duration
    activity_video.game = video.game

    avid = activity_video.create_model()
    video.update_model({'$set': {'activity_ids': [avid]}})

    # 任务检查
    if user:
        UserTask.check_user_tasks(str(user._id), JOIN_COLLECT, 1,
                                  str(video.game), str(aid))

    return ActivityVideo.get_one(avid, check_online=False).format()
Beispiel #9
0
def like_video():
    """赞视频 (GET|POST&LOGIN)

    :uri: /user/opt/like-video
    :param video_id: 被赞视频id
    :returns: {}
    """
    user = request.authed_user
    vid = request.values.get('video_id', None)
    video = Video.get_one(vid)
    if not video:
        return error.VideoNotExist

    ulv = UserLikeVideo.get_by_ship(str(user._id), vid)
    if not ulv:
        key = 'lock:like_video:%s:%s' % (str(user._id), vid)
        with util.Lockit(Redis, key) as locked:
            if locked:
                return error.LikeVideoFailed
            ulv = UserLikeVideo.init()
            ulv.source = ObjectId(str(user._id))
            ulv.target = ObjectId(vid)
            _id = ulv.create_model()
            if _id:
                # 发送点赞消息
                Message.send_video_msg(str(user._id), str(vid), 'like')
                # 更新活动点赞数
                avideos = ActivityVideo.get_activity_video(vid=vid)
                for avideo in avideos:
                    ts = time.time()
                    aconfig = ActivityConfig.get_one(str(
                        avideo['activity_id']),
                                                     check_online=False)
                    if aconfig and aconfig.status == const.ACTIVITY_BEGIN \
                            and (aconfig.begin_at < ts and aconfig.end_at > ts):
                        avideo = ActivityVideo.get_one(avideo['_id'],
                                                       check_online=False)
                        avideo.update_model({'$inc': {'like_count': 1}})

    return {}
Beispiel #10
0
def play_video(vid):
    """播放视频 (GET)

    :uri: /videos/<string:vid>/play
    :returns: redirect(real_url)
    """
    ut = request.values.get("ut", None)
    uid = User.uid_from_token(ut)

    start = int(time.time() * 1000)
    video = Video.get_one(vid)
    if not video:
        result = {
            'status': error.VideoNotExist.errno,
            'errmsg': error.VideoNotExist.errmsg,
            'data': {},
            'time': int(time.time() * 1000) - start,
        }
        return jsonify(result)
    video.update_model({'$inc': {'vv': 1}})
    # 如果是栏目视频,给对应频道增加播放量
    channel = ShowChannel.get_one(video.channel)
    channel and channel.update_model({'$inc': {'play_count': 1}})

    # 观看视频任务检查
    if uid:
        UserTask.check_user_tasks(uid, PLAY_VIDEO, 1)

    # 更新活动播放量
    avideos = ActivityVideo.get_activity_video(vid=vid)
    for avideo in avideos:
        ts = time.time()
        aconfig = ActivityConfig.get_one(str(avideo['activity_id']),
                                         check_online=False)
        if aconfig and aconfig.status == const.ACTIVITY_BEGIN \
                and (aconfig.begin_at < ts and aconfig.end_at > ts):
            avideo = ActivityVideo.get_one(avideo['_id'], check_online=False)
            avideo.update_model({'$inc': {'vv': 1}})

    return redirect(video.real_url())
Beispiel #11
0
def latest_video(aid):
    """获取最新参赛视频

    :uri: activity/<string:aid>/video/current
    :param maxs: 最后时间, 0代表当前时间
    :param nbr: 每页数量
    :param device: 终端ID
    :returns: {'activity_videos': list, 'end_page': bool, 'activity_config': Object,
               'maxs': timestamp}
    """

    params = request.values
    maxs = params.get('maxs', None)
    maxs = time.time() if maxs is not None and int(
        float(maxs)) == 0 else maxs and float(maxs)
    pagesize = int(params.get('nbr', 10))

    activity_config = ActivityConfig.get_one(aid, check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    avideos = list()
    avids = list()
    while len(avideos) < pagesize:
        avids = ActivityVideo.latest_video_ids(aid, pagesize, maxs)
        avideos.extend([v.format() for v in ActivityVideo.get_list(avids)])
        # 如果按照maxs分页, 不足pagesize个记录则继续查询
        if maxs is not None:
            obj = ActivityVideo.get_one(avids[-1]) if avids else None
            maxs = obj.create_at if obj else 1000
            if len(avids) < pagesize:
                break
        else:
            break
    return {
        'activity_videos': avideos,
        'end_page': len(avids) != pagesize,
        'activity_config': activity_config.format(),
        'maxs': maxs
    }
Beispiel #12
0
def user_videos(aid):
    """获取我的参赛视频(GET&LOGIN)

    :uri: activity/<string:aid>/videos
    :param type: 活动结束时参数(type=end)
    :param device: 终端ID
    :return: {'activity_videos': list, 'activity_config': Object}
    """
    user = request.authed_user
    type = request.values.get('type', None)

    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist
    sort = activity_config.sort

    activity_videos = ActivityVideo.user_compete_video_ids(aid, user._id)
    if not type:
        top_compete_videos = ActivityVideo.top_video_ids(aid, sort)
    videos = list()

    for activity_video in activity_videos:
        avid = str(activity_video['_id'])
        activity_video = ActivityVideo.get_one(avid)
        activity_video = activity_video.format()
        if type:
            videos.append(activity_video)
            continue

        if avid in top_compete_videos:
            top = top_compete_videos.index(avid)
            activity_video['top'] = top + 1
            videos.append(activity_video)
        else:
            continue
    return {
        'activity_videos': videos,
        'activity_config': activity_config.format()
    }
Beispiel #13
0
def get_activity_video(vid):
    """获取参赛视频信息(GET&LOGIN)

    :uri: activity/video/<string:vid>
    :param device: 终端ID
    :return: {'activity_video': Object, 'activity_config': Object}
    """

    activity_video = ActivityVideo.get_activity_video_by_vid(vid)
    if not activity_video:
        return error.ActivityVideoNotExist
    activity_config = ActivityConfig.get_one(activity_video['activity_id'])
    top_compete_videos = ActivityVideo.top_video_ids(
        activity_video['activity_id'], activity_config.sort)

    top = top_compete_videos.index(str(activity_video['_id']))
    activity_video = activity_video.format()
    activity_video['top'] = top + 1

    return {
        'activity_video': activity_video,
        'activity_config': activity_config.format()
    }
Beispiel #14
0
def delete_videos(aid):
    """删除我的参赛视频(POST&LOGIN)

    :uri: activity/<string:aid>/delete/videos
    :param activity_video: 活动参赛视频id
    :return: {}
    """
    user = request.authed_user

    avid = request.values.get('activity_video', None)
    activity_video = ActivityVideo.get_one(avid)
    if not activity_video:
        return error.ActivityVideoNotExist
    if str(activity_video.author) != str(user._id):
        return error.AuthFailed

    activity_video.delete_model()
    return {}
Beispiel #15
0
def compete_videos(aid):
    """获取可参赛视频(GET&LOGIN)

    :uri: /activity/<string:aid>/compete_videos
    :param page: 页数
    :param nbr: 每页数量
    :return: {'videos': list, 'max_video': int, 'end_page': bool}
    """
    params = request.values
    user = request.authed_user
    page = int(params.get('page', 1))
    pagesize = int(params.get('nbr', 10))

    activity_config = ActivityConfig.get_one(str(aid), check_online=False)
    if not activity_config:
        return error.ActivityNotExist

    activity_videos = ActivityVideo.user_compete_video_ids(aid, str(user._id))
    avids = [a['video_id'] for a in activity_videos]

    videos = list()
    gids = GameActivity.game_activity_ids(aid)
    gids = [ObjectId(_gid) for _gid in gids]

    vids = Video.activity_video_ids(str(user._id), pagesize, page, gids,
                                    activity_config)
    vids = [vid for vid in vids]
    videos.extend([v.format() for v in Video.get_list(vids)])
    # 允许参赛最大视频数
    max_video = activity_config.max_video - len(avids)

    return {
        'videos': videos,
        'end_page': len(vids) != pagesize,
        'max_video': max_video
    }
Beispiel #16
0
def search():
    """搜索 (GET|POST)

    :uri: /search
    :param type: 搜索类型{'all':全部, 'user':用户, 'game':游戏, 'video':视频,
                           'activity_video':活动视频, 'live_number':直播间房号}
    :param keyword: 关键字
    :returns: {'user':list, 'game':list, 'video':list}
    """
    ua = request.headers.get('User-Agent')
    params = request.values
    stype = params.get('type', 'all')
    keyword = params.get('keyword', '')
    keyword = keyword.strip()
    platform = params.get('os')
    version_code = params.get('version_code', 0)

    if not stype or not keyword:
        return error.InvalidArguments

    users = games = videos = activity_videos = lives = list()

    if stype in ['user', 'all']:
        uids = User.search(keyword)
        users = [u.format() for u in User.get_list(uids)]
        users = sorted(users, key=lambda x: x['follower_count'])

    if stype in ['game', 'all']:
        ua_filter = None
        if ua and platform == 'android' and int(version_code) >= 64:
            ua_filter = ua
        gids = Game.search(keyword, ua_filter)
        games = [g.format() for g in Game.get_list(gids, check_online=False)]

    if stype in ['video', 'all']:
        vids = Video.search(keyword)
        videos = [v.format() for v in Video.get_list(vids)]

    if stype in ['activity_video']:
        activity_id = params.get('activity_id', None)
        uids = User.search(keyword)
        _ids = ActivityVideo.get_activity_video_by_authors(uids, activity_id)
        avids = ActivityVideo.search(keyword, activity_id)
        avids.extend(_ids)
        activity_videos = [
            v.format() for v in ActivityVideo.get_list(set(avids))
        ]

    if stype in ['live_number', 'all']:
        uids = User.search_live_number(keyword)
        livers = [u.format() for u in User.get_list(uids)]
        livers = sorted(livers, key=lambda x: x['follower_count'])
        lives_map = {}
        for live in Xlive.get_all_lives():
            lives_map.update({live['user_id']: live})
        lives = list()
        ex_fields = ['user__is_followed', 'game__subscribed']
        for uid in uids:
            uid = str(uid)
            if uid in lives_map:
                ulive = Xlive.format(lives_map[uid], exclude_fields=ex_fields)
                lives.append({'live': ulive, 'user': None})
                continue
            lives.append({'live': None, 'user': User.get_one(uid).format()})

    return {
        'users': users,
        'games': games,
        'videos': videos,
        'activity_videos': activity_videos,
        'lives': lives
    }
Beispiel #17
0
def send_gift():
    """赠送礼物 (GET|POST&LOGIN)

    :uri: /gifts/send_gift
    :param user_id: 主播ID
    :param gift_id: 礼物ID
    :param num: 礼物数量
    :param gift_from: 礼物来源(1:直播, 2:录播)
    :param from_id:来源ID(直播ID或者录播视频ID)
    :return: {'ret: bool}

    :if money need cs(充值来源),SDKVersion,dId 
    """
    user = request.authed_user
    gift_id = int(request.values.get('gift_id'))
    to_user_id = request.values.get('user_id')
    num = int(request.values.get('num', 1))
    gift_from = int(request.values.get('gift_from'))
    from_id = request.values.get('from_id')
    user_ip = request.remote_addr
    device = request.values.get('device', None)

    if not gift_id or not to_user_id or num < 1 or not gift_from:
        return error.InvalidArguments

    if to_user_id == str(user._id):
        return error.GiftError('不能给自己赠送礼物哦')

    to_user = User.get_one(to_user_id, check_online=False)
    if not to_user:
        return error.UserNotExist('该视频没有主播')

    available_num = _gift_num()
    if num not in available_num:
        return error.GiftError('礼物数量不符合规则')

    gift = Gift.get_gift(gift_id)
    if not gift:
        return error.GiftError('该礼物不能赠送')
    money_data = {}
    transactionId = ''
    if gift.credit_type == const.MONEY:
        # today_times = UserGiftLog.user_today_gift_id_times(user._id,gift_id,num)
        gift_data = gift.format()
        # max_times = gift_data['per_piece_limit'].get(num)
        # if max_times <= today_times:
        #     return error.GiftError('该档礼物今天的次数已用完')
        from wanx.platforms.migu import PayByMg
        consumeCode = gift_data['per_piece_id'].get(num)
        cs = 6
        SDKVersion = request.values.get('SDKVersion')
        dId = request.values.get('dId', 'null')
        goodsname = gift_data['product_name'] + '_' + str(num)

        pay_mg_data = PayByMg.get_payurl(user,
                                         cs,
                                         SDKVersion,
                                         dId,
                                         consumeCode,
                                         1,
                                         goodsname=goodsname)

        if isinstance(pay_mg_data, error.ApiError):
            return pay_mg_data
        # 创建订单
        pay_order_obj = PayOrder.init()
        # [set(pay_order_obj,attr,value) for attr,value in pay_mg_data.items()]
        pay_order_obj.pay_mg_data = pay_mg_data
        transactionId = pay_mg_data['resultData']['transactionId']
        pay_order_obj.transactionId = transactionId
        pay_order_obj.phone = user.phone
        pay_order_obj.nickname = user.nickname
        pay_order_obj.credit_value = gift.credit_value
        pay_order_obj.total_value = gift.credit_value * num
        pay_order_obj.gift_num = num
        pay_order_obj.finished = 0
        pay_order_obj.product_name = gift_data['product_name']
        pay_order_obj.check_pay_data = {}
        pay_order_obj.pay_info = {"from_user_id": user._id, 'to_user_id': to_user_id, "num": num,
                                  'gift_id': gift_id, \
                                  'gift_from': gift_from, "from_id": from_id}
        pay_order_obj.create_model()
        money_data = {
            'is_money': True,
            "pay_data": pay_mg_data.get("resultData", {})
        }

    ret = False
    key = 'lock:send_gift:%s' % (str(user._id))
    with util.Lockit(Redis, key) as locked:
        if locked:
            return error.GiftError('赠送礼物失败')

        ret = gift.send_to_user(str(user._id),
                                to_user_id,
                                num,
                                gift_from,
                                from_id,
                                transactionId=transactionId)

    if isinstance(ret, error.ApiError):
        return ret

    if money_data:
        return money_data
    # 录播发送消息到中心消息
    if ret and gift_from == const.FROM_RECORD:
        video = Video.get_one(from_id, check_online=False)
        if video:
            Message.send_gift_msg(str(user._id), from_id, 'gift')
            video.update_model({'$inc': {'gift_count': 1, 'gift_num': num}})

    # 直播发送广播信息
    if ret and gift_from == const.FROM_LIVE:
        total = Xlive.get_user_send_gift_count(from_id, str(user._id), gift_id,
                                               num)
        data = dict(user_id=str(user._id),
                    username=user.nickname or user.name,
                    userphoto=user.get_photo(),
                    gift_name=gift.format()['product_name'],
                    gift_image=gift.format()['product_image'],
                    gift_num=num,
                    event_id=from_id,
                    total=total)
        Xlive.send_live_msg(data)

    # 营销数据入库经分  打赏活动
    from wanx.models.activity import ActivityConfig, ActivityVideo
    from wanx.platforms.migu import Marketing
    activity_config = None
    if gift_from == const.FROM_RECORD:
        activity_video = ActivityVideo.get_activity_video_by_vid(from_id)
        if activity_video:
            activity_config = ActivityConfig.get_one(
                activity_video['activity_id'])
    else:
        aids = ActivityConfig.get_by_type(const.FROM_LIVE)
        for a in ActivityConfig.get_list(aids):
            activity_config = a
            break
    if activity_config:
        data_dict = dict(cmd="deliver_gift",
                         opt="{0}/{1}".format(gift.gold_price, to_user_id),
                         deviceid=request.values.get('device', ''),
                         mobile=user.phone,
                         source=request.values.get('source', 'activity'),
                         activityid=str(activity_config['_id']),
                         activityname=activity_config['name'])
        Marketing.jf_report(data_dict)
    # 1118 task1
    # Marketing.trigger_report(user.partner_migu['id'], user.phone, 'send_gift')
    return {'ret': ret}
Beispiel #18
0
def activity_vote():
    """活动投票

    :uri: activity/vote
    :param source: 投票来源(app_play, activity, activity_share, video_share)
    :param device: 设备唯一ID
    :param video_id: 视频ID
    :param ut: 用户ut
    :return: {'vote_count': int}
    """
    user = request.authed_user
    params = request.values.to_dict()

    if not Guard.verify_sig(params):
        return error.InvalidRequest

    vid = params.get('video_id', None)
    source = params.get('source', None)
    device = params.get('device', None)
    uid = user and str(user._id)

    if not vid or not source or not device:
        return error.InvalidArguments

    # 增加ip限制,每个ip每天限制20次
    user_ip = request.remote_addr
    ip_key = 'ip_limit:%s:%s:%s' % (user_ip, vid, str(datetime.date.today()))
    ip_limit = Redis.incr(ip_key)
    if ip_limit == 1:  # 第一次设置key过期时间
        Redis.expire(ip_key, 86400)

    if ip_limit > 20:
        return error.ActivityVideoNotExist("超出IP限制")

    video = Video.get_one(vid)
    if not video:
        return error.VideoNotExist

    activity_video = ActivityVideo.get_activity_video_by_vid(vid)
    if not activity_video:
        return error.ActivityVideoNotExist("该视频未参赛")

    vote_count = activity_video['vote']
    activity_id = activity_video['activity_id']

    activity_config = ActivityConfig.get_one(activity_id)
    if not activity_config or not activity_config.online:
        return error.ActivityEnd

    is_voted = True if VoteVideo.get_vote(uid, device, vid) else False
    if is_voted:
        return error.VoteVideoLimited

    vote = VoteVideo.get_vote(uid=uid, device=device, vid=vid)
    if not vote:
        key = 'lock:vote_video:%s:%s' % (device, vid)
        with util.Lockit(Redis, key) as locked:
            if locked:
                return error.VoteVideoFailed
            vote = VoteVideo.init()
            vote.device = device
            vote.source = source
            vote.author = ObjectId(uid)
            vote.target = ObjectId(vid)
            vote.activity = ObjectId(activity_id)
            vote.create_model()
            # 票数加1
            vote_count = vote_count + 1

    # 营销数据入库经分  投票活动
    from wanx.platforms.migu import Marketing
    data_dict = dict(cmd="vote",
                     opt=vid,
                     deviceid=params.get('device', ''),
                     mobile=user.phone,
                     source=params.get('source', 'activity'),
                     activityid=str(activity_video['activity_id']),
                     activityname=activity_config['name'])
    Marketing.jf_report(data_dict)

    return {'vote_count': vote_count}