Esempio n. 1
0
def pushredis(self):
    now_time = int(time.time())
    #pre_time = now_time - 120
    pre_time = now_time - 3600
    # heartbeats = UserHeartBeat.objects.filter(last_report_time__gte=pre_time)
    stuilabel = "598d7a2418ce423b1222d645"  #首推标签id
    usersss = User.objects.filter(is_video_auth=1,
                                  is_block__ne=1).order_by("is_vip")
    stuianchors = []
    for u in usersss:
        if stuilabel in u.label:
            stuianchors.append(u)
    hots = []
    users = []
    user_recommed_id = []
    user_recommed_id_all = []
    usermap = {}
    anchors = Anchor.objects.filter().order_by("seq")

    for anchor in anchors:
        user = User.objects.get(id=anchor.sid)
        user_heart = UserHeartBeat.objects.get(user=user)
        if user_heart.last_report_time > pre_time and user.disturb_mode != 1:
            hots.append(user)
    randomstui = []
    for stui in stuianchors:
        user_heart = UserHeartBeat.objects.get(user=stui)
        if user_heart.last_report_time > pre_time and stui.disturb_mode != 1:
            randomstui.append(stui)
    # hot 和 stulist
    # random.shuffle(hots)
    random.shuffle(randomstui)

    hots = hots + randomstui

    for user in hots:
        if user.id in users:
            continue
        users.append(user.id)
        personal_tags = UserTags.get_usertags(user_id=user.id)
        if not personal_tags:
            personal_tags = []

        user_vip = UserVip.objects.filter(user_id=user.id).first()

        # time = int(time.time())
        # pre_time = time - 120
        user_beat = UserHeartBeat.objects.filter(
            user=user, last_report_time__gte=pre_time).first()
        if user_beat:
            is_online = 1
            # else:
            #     is_online = 0
            user_recommed_id_all.append(user.id)
            roomrecord = AudioRoomRecord.objects.filter(
                user_id=user.id).order_by("-open_time").first()
            if not user_vip:
                dic = {
                    "user": {
                        "_uid": user.sid,
                        "logo_big": user.image,
                        "nickname": user.nickname,
                        "desc": user.desc
                    },
                    "personal_tags": personal_tags,
                    "is_online": is_online
                }
            else:
                vip = Vip.objects.filter(id=user_vip.vip_id).first()
                dic = {
                    "user": {
                        "_uid": user.sid,
                        "logo_big": user.image,
                        "nickname": user.nickname,
                        "desc": user.desc
                    },
                    "personal_tags": personal_tags,
                    "vip": {
                        "vip_type": vip.vip_type,
                        "icon_url": Vip.convert_http_to_https(vip.icon_url)
                    },
                    "is_online": is_online
                }

            show_video = RealVideoVerify.objects(
                user_id=user.id, status=1).order_by("-update_time").first()
            if show_video:
                dic["check_real_video"] = show_video.status
            else:
                real_video = RealVideoVerify.objects(
                    user_id=user.id,
                    status__ne=2).order_by("-update_time").first()
                if real_video:
                    dic["check_real_video"] = real_video.status
                else:
                    dic["check_real_video"] = 3

            self.append(user.id)
            usermap[str(user.id)] = json.dumps(dic)
            if not roomrecord or roomrecord.status == 1:
                user_recommed_id.append(user.id)
    deletetui()
    if user_recommed_id:
        UserRedis.add_user_recommed_id_v3(user_recommed_id)
        UserRedis.add_user_recommed_id_all(user_recommed_id_all)
        UserRedis.add_user_recommed_v3(usermap)
    push_index_anchor(self)
Esempio n. 2
0
    def normal_info(self):
        user_id = self.user_id
        user = User.objects.filter(id=user_id).first()

        head_image = user.image
        age = User.get_age(user.birth_date)
        create_time = UserMoment.get_time(self.create_time)
        date_time = self.create_time.strftime('%Y-%m-%d')
        imgs = self.img_list
        img_list = []
        if imgs:
            for img in imgs:
                if int(img["status"]) == 1:
                    img_list.append(img["url"])
        moment_look = UserMomentLook.objects.filter(
            user_moment_id=str(self.id)).first()
        look_count = 0
        if moment_look:
            look_user_ids = moment_look.user_id_list
            look_count = len(look_user_ids)

        price = self.price
        if not price:
            price = 0

        type = self.type
        if not type:
            type = 1

        show_video = RealVideoVerify.objects(
            user_id=user.id, status=1).order_by("-update_time").first()
        if show_video:
            real_video_auth = show_video.status
        else:
            real_video_auth = 3

        if user:
            data = {
                "moment_id": str(self.id),
                "user_id": user.id,
                "gender": user.gender_desc,
                "head_image": head_image,
                "nickname": user.nickname,
                "age": age,
                "create_time": create_time,
                "img_list": img_list,
                "comment_count": self.comment_count,
                "like_count": self.like_count,
                "type": type,
                "look_count": look_count,
                "content": self.content,
                "date_time": date_time,
                "video_id": self.video_id,
                "cover_url": self.cover_url,
                "video_url": self.video_url,
                "price": price,
                "real_video_auth": real_video_auth
            }
            user_vip = UserVip.objects.filter(user_id=user_id).first()
            if user_vip:
                vip = Vip.objects.filter(id=user_vip.vip_id).first()
                data["vip_icon"] = vip.icon_url

            return data
Esempio n. 3
0
def oldcommonlist():
    now_time = int(time.time())
    pre_time = now_time - 120
    heartbeats = UserHeartBeat.objects.filter(last_report_time__gte=pre_time)
    hots = []
    anchors = Anchor.objects.all()
    hot_ids = []
    hot_list = []
    for anchor in anchors:
        user = User.objects.get(id=anchor.sid)
        user_heart = UserHeartBeat.objects.get(user=user)
        if user_heart.last_report_time > pre_time and user.disturb_mode != 1:
            hots.append(user)
            hot_ids.append(user.id)

    for heartbeat in heartbeats:
        if heartbeat.user.charm_value > 3500 and heartbeat.user.disturb_mode != 1 \
                and heartbeat.user.id not in hot_ids and heartbeat.user.is_video_auth == 1:
            hots.append(heartbeat.user)

    if not hots:
        hots = User.objects.filter(
            is_video_auth=1).order_by("-charm_value")[0:4]

    for user in hots:
        room = AudioRoomRecord.objects.get(id=user.audio_room_id)
        personal_tags = UserTags.get_usertags(user_id=room.user_id)
        if not personal_tags:
            personal_tags = []

        user_vip = UserVip.objects.filter(user_id=user.id).first()

        # time = int(time.time())
        # pre_time = time - 120
        user_beat = UserHeartBeat.objects.filter(
            user=user, last_report_time__gte=pre_time).first()
        if user_beat:
            is_online = 1
        else:
            is_online = 0

        if not user_vip:
            dic = {
                "audioroom": convert_audioroom(room),
                "user": convert_user(user),
                "personal_tags": personal_tags,
                "time_stamp": int(time.time()),
                "is_online": is_online
            }
        else:
            vip = Vip.objects.filter(id=user_vip.vip_id).first()
            dic = {
                "audioroom": convert_audioroom(room),
                "user": convert_user(user),
                "personal_tags": personal_tags,
                "time_stamp": int(time.time()),
                "vip": convert_vip(vip),
                "is_online": is_online
            }

        show_video = RealVideoVerify.objects(
            user_id=user.id, status=1).order_by("-update_time").first()
        if show_video:
            dic["check_real_video"] = show_video.status
        else:
            real_video = RealVideoVerify.objects(
                user_id=user.id,
                status__ne=2).order_by("-update_time").first()
            if real_video:
                dic["check_real_video"] = real_video.status
            else:
                dic["check_real_video"] = 3
        hot_list.append(json.dumps(dic))
    return hot_list
Esempio n. 4
0
def push_index_anchor(self):
    users = []
    usermap = {}
    gaoyanzhi = "597ef92818ce420b6f46ce3f"
    xinggan = "597ef93418ce420b7d46ce17"
    yujie = "597ef86b18ce420b6f46ce3c"
    qingcun = "597ef85718ce420b7d46ce11"
    nodisllpay = "59956dfb18ce427fa83c9cec"

    randomvalist1 = []
    randomvalist2 = []
    randomvalist3 = []
    randomvalist4 = []
    randomvalist5 = []
    randomvalist6 = []
    index_id_all = []
    anchors = User.objects.filter(is_video_auth=1,
                                  is_block__ne=1).order_by("is_vip")
    for anchor in anchors:
        if gaoyanzhi in anchor.label and xinggan in anchor.label:
            randomvalist1.append(anchor)
        elif gaoyanzhi in anchor.label and qingcun in anchor.label:
            randomvalist2.append(anchor)
        else:
            if xinggan in anchor.label:
                randomvalist3.append(anchor)
            elif qingcun in anchor.label:
                randomvalist6.append(anchor)
            elif yujie in anchor.label:
                randomvalist4.append(anchor)
            elif not anchor.label:
                randomvalist5.append(anchor)

    random.shuffle(randomvalist1)
    random.shuffle(randomvalist2)
    random.shuffle(randomvalist3)
    random.shuffle(randomvalist4)
    random.shuffle(randomvalist5)
    random.shuffle(randomvalist6)

    valist1 = randomvalist1
    valist2 = randomvalist2
    valist3 = randomvalist3
    valist4 = randomvalist4
    valist5 = randomvalist5
    valist6 = randomvalist6

    index_id = []
    for gaoxing in valist1:
        if gaoxing not in users and gaoxing.disturb_mode == 0 and gaoxing.audio_room_id != "":
            users.append(gaoxing)
    for gaoqing in valist2:
        if gaoqing not in users and gaoqing.disturb_mode == 0 and gaoqing.audio_room_id != "":
            users.append(gaoqing)
    for xing in valist3:
        if xing not in users and xing.disturb_mode == 0 and xing.audio_room_id != "":
            users.append(xing)
    for qing in valist6:
        if qing not in users and qing.disturb_mode == 0 and qing.audio_room_id != "":
            users.append(qing)
    for yu in valist4:
        if yu not in users and yu.disturb_mode == 0 and yu.audio_room_id != "":
            users.append(yu)
    for wu in valist5:
        if wu not in users and wu.disturb_mode == 0 and wu.audio_room_id != "":
            users.append(wu)
    for user in users:
        #if not user.audio_room_id:
        #   continue
        if user.id == 1 or user.id == 2:
            continue
        try:
            if user.id not in self and nodisllpay not in user.label:
                personal_tags = UserTags.get_usertags(user_id=user.id)
                if not personal_tags:
                    personal_tags = []
                user_vip = UserVip.objects.filter(user_id=user.id).first()

                # 是否在线 查看心跳
                import time
                time = int(time.time())
                pre_time = time - 3600
                user_beat = UserHeartBeat.objects.filter(
                    user=user, last_report_time__gte=pre_time).first()
                roomrecord = AudioRoomRecord.objects.filter(
                    user_id=user.id).order_by("-open_time").first()
                if user_beat and user.disturb_mode != 1:
                    index_id_all.append(user.id)

                    is_online = 1
                    # 视频认证状态
                    real_video = RealVideoVerify.objects(
                        user_id=user.id,
                        status__ne=2).order_by("-update_time").first()
                    show_video = RealVideoVerify.objects(
                        user_id=user.id,
                        status=1).order_by("-update_time").first()

                    if user_vip:
                        vip = Vip.objects.filter(id=user_vip.vip_id).first()
                        dic = {
                            "user": {
                                "_uid": user.sid,
                                "logo_big": user.image,
                                "nickname": user.nickname,
                                "desc": user.desc
                            },
                            "personal_tags": personal_tags,
                            "vip": {
                                "vip_type": vip.vip_type,
                                "icon_url":
                                Vip.convert_http_to_https(vip.icon_url)
                            },
                            "is_online": is_online
                        }
                    else:
                        dic = {
                            "user": {
                                "_uid": user.sid,
                                "logo_big": user.image,
                                "nickname": user.nickname,
                                "desc": user.desc
                            },
                            "personal_tags": personal_tags,
                            "is_online": is_online
                        }

                    if show_video:
                        dic["check_real_video"] = show_video.status
                    else:
                        if real_video:
                            dic["check_real_video"] = real_video.status
                        else:
                            dic["check_real_video"] = 3

                    usermap[str(user.id)] = json.dumps(dic)
                    if not roomrecord or roomrecord.status == 1:
                        index_id.append(user.id)
        except Exception, e:
            print e
Esempio n. 5
0
    def get(self):
        user_id = self.current_user_id
        is_old = True
        if user_id:
            is_target = (self.current_user.is_video_auth != 1 and UserRedis.is_target_user(user_id)) or \
                        (self.current_user.is_video_auth == 1 and not UserRedis.is_pure_anchor(user_id))

            if not is_target:
                is_old = False
        else:
            is_old = False
        column_type = self.arg_int('column_type')
        page = self.arg_int('page')
        page_count = self.arg_int('page_count')
        nodisplay = "59956dfb18ce427fa83c9cec"
        data = []

        if is_old:
            if column_type == 2:
                # 新人驾到
                anchor_list = NewAnchorRank.objects.all()
                if anchor_list:
                    anchor_list = anchor_list[(page - 1) * page_count:page *
                                              page_count]

                    for anchor in anchor_list:
                        user = User.objects.filter(id=anchor.user_id,
                                                   is_video_auth=1).first()
                        if not user:
                            continue
                        if user.disturb_mode != 1:
                            if nodisplay not in user.label:
                                if user.id == 1 or user.id == 2:
                                    continue
                                if not user.audio_room_id:
                                    continue
                                # 是否在线 查看心跳
                                import time
                                time = int(time.time())
                                pre_time = time - 3600
                                user_beat = UserHeartBeat.objects.filter(
                                    user=user,
                                    last_report_time__gte=pre_time).first()
                                if user_beat:
                                    is_online = 1
                                    if not user.audio_room_id:
                                        AudioRoomRecord.create_roomrecord(
                                            user.id, datetime.datetime.now())
                                    audioroom = AudioRoomRecord.objects.get(
                                        id=user.audio_room_id)
                                    personal_tags = UserTags.get_usertags(
                                        user_id=user.id)
                                    user_vip = UserVip.objects.filter(
                                        user_id=user.id).first()
                                    if user_vip:
                                        vip = Vip.objects.filter(
                                            id=user_vip.vip_id).first()
                                        dic = {
                                            "audioroom":
                                            convert_audioroom(audioroom),
                                            "user":
                                            convert_user(user),
                                            "personal_tags":
                                            personal_tags,
                                            "vip":
                                            convert_vip(vip),
                                            "is_online":
                                            is_online
                                        }
                                    else:
                                        dic = {
                                            "audioroom":
                                            convert_audioroom(audioroom),
                                            "user":
                                            convert_user(user),
                                            "is_online":
                                            is_online,
                                            "personal_tags":
                                            personal_tags
                                        }
                                    # 视频认证状态
                                    real_video = RealVideoVerify.objects(
                                        user_id=user.id,
                                        status__ne=2).order_by(
                                            "-update_time").first()
                                    show_video = RealVideoVerify.objects(
                                        user_id=user.id, status=1).order_by(
                                            "-update_time").first()
                                    if show_video:
                                        dic["check_real_video"] = show_video.status
                                    else:
                                        if real_video:
                                            dic["check_real_video"] = real_video.status
                                        else:
                                            dic["check_real_video"] = 3
                                    data.append(dic)
        else:
            recommed_list = UserRedis.get_recommed_list_pure()
            anchor_list = UserRedis.get_index_anchor_list_pure(0, -1)
            finaluser = recommed_list + anchor_list
            finaluser = finaluser[(page - 1) * page_count:page * page_count]
            if len(finaluser) > 0:
                for anchorid in finaluser:
                    user = User.objects.filter(id=int(anchorid)).first()
                    import time
                    time = int(time.time())
                    pre_time = time - 3600
                    user_beat = UserHeartBeat.objects.filter(
                        user=user, last_report_time__gte=pre_time).first()

                    if user_beat:
                        is_online = 1
                    else:
                        is_online = 0
                    if not user.audio_room_id:
                        AudioRoomRecord.create_roomrecord(
                            user.id, datetime.datetime.now())
                    audioroom = AudioRoomRecord.objects.get(
                        id=user.audio_room_id)
                    personal_tags = UserTags.get_usertags(user_id=user.id)
                    user_vip = UserVip.objects.filter(user_id=user.id).first()
                    if user_vip:
                        vip = Vip.objects.filter(id=user_vip.vip_id).first()
                        dic = {
                            "audioroom": convert_audioroom(audioroom),
                            "user": convert_user(user),
                            "personal_tags": personal_tags,
                            "vip": convert_vip(vip),
                            "is_online": is_online
                        }
                    else:
                        dic = {
                            "audioroom": convert_audioroom(audioroom),
                            "user": convert_user(user),
                            "is_online": is_online,
                            "personal_tags": personal_tags
                        }
                    # 视频认证状态
                    real_video = RealVideoVerify.objects(
                        user_id=user.id,
                        status__ne=2).order_by("-update_time").first()
                    show_video = RealVideoVerify.objects(
                        user_id=user.id,
                        status=1).order_by("-update_time").first()
                    if show_video:
                        dic["check_real_video"] = show_video.status
                    else:
                        if real_video:
                            dic["check_real_video"] = real_video.status
                        else:
                            dic["check_real_video"] = 3
                    data.append(dic)
        return self.write({
            "status": "success",
            "data": data,
        })
Esempio n. 6
0
def push_index_anchor(self):
    users = []
    usermap = {}
    qingcun = "597ef85718ce420b7d46ce11"

    randomvalist1 = []
    index_id_all = []
    anchors = User.objects.filter(is_video_auth=1,
                                  is_block__ne=1).order_by("is_vip")
    for anchor in anchors:
        if qingcun in anchor.label:
            randomvalist1.append(anchor)

    index_id = []
    for qingcun in randomvalist1:
        if qingcun not in users:
            users.append(qingcun)

    zaixianbururao = []
    zaixiancall = []
    zaixianwurao = []
    lixian = []
    for user in users:
        if user.id == 1 or user.id == 2:
            continue
        import time
        time = int(time.time())
        pre_time = time - 3600
        user_beat = UserHeartBeat.objects.filter(
            user=user, last_report_time__gte=pre_time).first()
        if user_beat:
            if user.audio_status == 2:
                if user.disturb_mode == 0:
                    zaixianbururao.append(user)
                else:
                    zaixianwurao.append(user)
            else:
                zaixiancall.append(user)
        else:
            lixian.append(user)
    finalusers = zaixianbururao + zaixiancall
    for user in finalusers:
        if user.id not in self:
            index_id_all.append(user.id)
            personal_tags = UserTags.get_usertags(user_id=user.id)
            if not personal_tags:
                personal_tags = []
            user_vip = UserVip.objects.filter(user_id=user.id).first()

            is_online = 1
            if user_vip:
                vip = Vip.objects.filter(id=user_vip.vip_id).first()
                dic = {
                    "user": {
                        "_uid": user.sid,
                        "logo_big": user.image,
                        "nickname": user.nickname,
                        "desc": user.desc
                    },
                    "personal_tags": personal_tags,
                    "vip": {
                        "vip_type": vip.vip_type,
                        "icon_url": Vip.convert_http_to_https(vip.icon_url)
                    },
                    "is_online": is_online
                }
                dic["check_real_video"] = 1
            else:
                dic = {
                    "user": {
                        "_uid": user.sid,
                        "logo_big": user.image,
                        "nickname": user.nickname,
                        "desc": user.desc
                    },
                    "personal_tags": personal_tags,
                    "is_online": is_online
                }
                dic["check_real_video"] = 1
            usermap[str(user.id)] = json.dumps(dic)
            index_id.append(user.id)
    lixian = zaixianwurao + lixian
    for user in lixian:
        if user.id not in self:
            index_id_all.append(user.id)
            personal_tags = UserTags.get_usertags(user_id=user.id)
            if not personal_tags:
                personal_tags = []
            user_vip = UserVip.objects.filter(user_id=user.id).first()

            is_online = 0
            # 视频认证状态
            real_video = RealVideoVerify.objects(
                user_id=user.id,
                status__ne=2).order_by("-update_time").first()
            show_video = RealVideoVerify.objects(
                user_id=user.id, status=1).order_by("-update_time").first()

            if user_vip:
                vip = Vip.objects.filter(id=user_vip.vip_id).first()
                dic = {
                    "user": {
                        "_uid": user.sid,
                        "logo_big": user.image,
                        "nickname": user.nickname,
                        "desc": user.desc
                    },
                    "personal_tags": personal_tags,
                    "vip": {
                        "vip_type": vip.vip_type,
                        "icon_url": Vip.convert_http_to_https(vip.icon_url)
                    },
                    "is_online": is_online
                }
                dic["check_real_video"] = 1
            else:
                dic = {
                    "user": {
                        "_uid": user.sid,
                        "logo_big": user.image,
                        "nickname": user.nickname,
                        "desc": user.desc
                    },
                    "personal_tags": personal_tags,
                    "is_online": is_online
                }
                dic["check_real_video"] = 1
            usermap[str(user.id)] = json.dumps(dic)
            index_id.append(user.id)
    deleteanchor()
    print "==================index_id", index_id
    UserRedis.add_index_id_pure(index_id)
    UserRedis.add_index_id_all_pure(index_id_all)
    UserRedis.add_index_anchor_pure(usermap)
    print "=============首页清纯数据入redis完毕"
Esempio n. 7
0
def pushredis(self):
    now_time = int(time.time())
    # pre_time = now_time - 120
    pre_time = now_time - 3600
    # heartbeats = UserHeartBeat.objects.filter(last_report_time__gte=pre_time)
    stuilabel = "598d7a2418ce423b1222d645"
    usersss = User.objects.filter(is_video_auth=1,
                                  is_block__ne=1).order_by("is_vip")
    stuianchors = []
    for u in usersss:
        if stuilabel in u.label:
            stuianchors.append(u)
    hots = []
    users = []
    user_recommed_id = []
    usermap = {}
    anchors = Anchor.objects.filter().order_by("seq")

    for anchor in anchors:
        user = User.objects.get(id=anchor.sid)
        user_heart = UserHeartBeat.objects.get(user=user)
        if user_heart.last_report_time > pre_time and user.disturb_mode != 1:
            hots.append(user)
            print "===================在线的热门主播", user.id
    stuilist = []
    for stui in stuianchors:
        user_heart = UserHeartBeat.objects.get(user=stui)
        if user_heart.last_report_time > pre_time and stui.disturb_mode != 1:
            show_video = RealVideoVerify.objects(
                user_id=stui.id, status=1).order_by("-update_time").first()
            if show_video:
                stuilist.insert(0, stui)
            else:
                stuilist.append(stui)

    hots = hots + stuilist

    # for heartbeat in heartbeats:
    #     if heartbeat.user.charm_value > 3500 and heartbeat.user.disturb_mode != 1 \
    #             and heartbeat.user.id not in hot_ids and heartbeat.user.is_video_auth == 1:
    #         hots.append(heartbeat.user)

    # if not hots:
    #     hots = User.objects.filter(is_video_auth=1).order_by("-charm_value")[0:4]
    for h in hots:
        roomrecord = AudioRoomRecord.objects.filter(
            user_id=h.id).order_by("-open_time").first()
        if h not in users:
            if not roomrecord or roomrecord.status == 1:
                users.append(h)

    for user in users:
        personal_tags = UserTags.get_usertags(user_id=user.id)
        if not personal_tags:
            personal_tags = []

        user_vip = UserVip.objects.filter(user_id=user.id).first()

        # time = int(time.time())
        # pre_time = time - 120
        user_beat = UserHeartBeat.objects.filter(
            user=user, last_report_time__gte=pre_time).first()
        if user_beat:
            is_online = 1
        else:
            is_online = 0

        if not user_vip:
            dic = {
                "user": convert_user(user),
                "personal_tags": personal_tags,
                "time_stamp": int(time.time()),
                "is_online": is_online
            }
        else:
            vip = Vip.objects.filter(id=user_vip.vip_id).first()
            dic = {
                "user": convert_user(user),
                "personal_tags": personal_tags,
                "time_stamp": int(time.time()),
                "vip": convert_vip(vip),
                "is_online": is_online
            }

        show_video = RealVideoVerify.objects(
            user_id=user.id, status=1).order_by("-update_time").first()
        if show_video:
            dic["check_real_video"] = show_video.status
        else:
            real_video = RealVideoVerify.objects(
                user_id=user.id,
                status__ne=2).order_by("-update_time").first()
            if real_video:
                dic["check_real_video"] = real_video.status
            else:
                dic["check_real_video"] = 3
        user_recommed_id.append(user.id)
        self.append(user.id)
        usermap[str(user.id)] = json.dumps(dic)
    deletetui()
    if user_recommed_id:
        UserRedis.add_user_recommed_id(user_recommed_id)
        UserRedis.add_user_recommed(usermap)
    push_index_anchor(self)
Esempio n. 8
0
def push_index_anchor(self):
    users = []
    usermap = {}
    gaoyanzhi = "597ef92818ce420b6f46ce3f"
    xinggan = "597ef93418ce420b7d46ce17"
    yujie = "597ef86b18ce420b6f46ce3c"
    qingcun = "597ef85718ce420b7d46ce11"
    nodisllpay = "59956dfb18ce427fa83c9cec"
    valist1 = []
    valist2 = []
    valist3 = []
    valist4 = []
    valist5 = []
    index_id = []
    anchors = User.objects.filter(is_video_auth=1,
                                  is_block__ne=1).order_by("is_vip")
    for anchor in anchors:
        if gaoyanzhi in anchor.label and xinggan in anchor.label:
            if anchor not in users:
                show_video = RealVideoVerify.objects(
                    user_id=anchor.id,
                    status=1).order_by("-update_time").first()
                if show_video:
                    valist1.insert(0, anchor)
                else:
                    valist1.append(anchor)
        elif gaoyanzhi in anchor.label and qingcun in anchor.label:
            if anchor not in users:
                show_video = RealVideoVerify.objects(
                    user_id=anchor.id,
                    status=1).order_by("-update_time").first()
                if show_video:
                    valist2.insert(0, anchor)
                else:
                    valist2.append(anchor)
        else:
            if xinggan in anchor.label:
                if anchor not in users:
                    show_video = RealVideoVerify.objects(
                        user_id=anchor.id,
                        status=1).order_by("-update_time").first()
                    if show_video:
                        valist3.insert(0, anchor)
                    else:
                        valist3.append(anchor)
            elif yujie in anchor.label:
                if anchor not in users:
                    show_video = RealVideoVerify.objects(
                        user_id=anchor.id,
                        status=1).order_by("-update_time").first()
                    if show_video:
                        valist4.insert(0, anchor)
                    else:
                        valist4.append(anchor)
            elif not anchor.label:
                show_video = RealVideoVerify.objects(
                    user_id=anchor.id,
                    status=1).order_by("-update_time").first()
                if show_video:
                    valist5.insert(0, anchor)
                else:
                    valist5.append(anchor)
    for gaoxing in valist1:
        if gaoxing not in users and gaoxing.disturb_mode == 0 and gaoxing.audio_room_id != "":
            users.append(gaoxing)
    for gaoqing in valist2:
        if gaoqing not in users and gaoqing.disturb_mode == 0 and gaoqing.audio_room_id != "":
            users.append(gaoqing)
    for xing in valist3:
        if xing not in users and xing.disturb_mode == 0 and xing.audio_room_id != "":
            users.append(xing)
    for yu in valist4:
        if yu not in users and yu.disturb_mode == 0 and yu.audio_room_id != "":
            users.append(yu)
    for wu in valist5:
        if wu not in users and wu.disturb_mode == 0 and wu.audio_room_id != "":
            users.append(wu)
    for user in users:
        #if not user.audio_room_id:
        #   continue
        if user.id == 1 or user.id == 2:
            continue
        try:
            if user.id not in self and nodisllpay not in user.label:
                audioroom = AudioRoomRecord.objects.get(id=user.audio_room_id)
                personal_tags = UserTags.get_usertags(user_id=user.id)
                if not personal_tags:
                    personal_tags = []
                user_vip = UserVip.objects.filter(user_id=user.id).first()

                # 是否在线 查看心跳
                import time
                time = int(time.time())
                pre_time = time - 3600
                user_beat = UserHeartBeat.objects.filter(
                    user=user, last_report_time__gte=pre_time).first()
                roomrecord = AudioRoomRecord.objects.filter(
                    user_id=user.id).order_by("-open_time").first()
                if user_beat and user.disturb_mode != 1:
                    if not roomrecord or roomrecord.status == 1:
                        is_online = 1
                        # 视频认证状态
                        real_video = RealVideoVerify.objects(
                            user_id=user.id,
                            status__ne=2).order_by("-update_time").first()
                        show_video = RealVideoVerify.objects(
                            user_id=user.id,
                            status=1).order_by("-update_time").first()

                        if user_vip:
                            vip = Vip.objects.filter(
                                id=user_vip.vip_id).first()
                            dic = {
                                "audioroom":
                                convert_audioroom(audioroom),
                                "user":
                                convert_user(user),
                                "personal_tags":
                                personal_tags,
                                "time_stamp":
                                datetime_to_timestamp(audioroom.open_time),
                                "vip":
                                convert_vip(vip),
                                "is_online":
                                is_online
                            }
                        else:
                            dic = {
                                "audioroom":
                                convert_audioroom(audioroom),
                                "user":
                                convert_user(user),
                                "personal_tags":
                                personal_tags,
                                "time_stamp":
                                datetime_to_timestamp(audioroom.open_time),
                                "is_online":
                                is_online
                            }

                        if show_video:
                            dic["check_real_video"] = show_video.status
                        else:
                            if real_video:
                                dic["check_real_video"] = real_video.status
                            else:
                                dic["check_real_video"] = 3
                        index_id.append(user.id)
                        usermap[str(user.id)] = json.dumps(dic)
        except Exception, e:
            print e
Esempio n. 9
0
    def send_activity_tools(cls, user_id):
        from app.customer.models.real_video_verify import RealVideoVerify
        now = datetime.datetime.now()
        now_str = now.strftime('%Y-%m-%d 23:59:59')
        hm = cls.get_hm(now)
        activity_id = ""
        user = User.objects.filter(id=user_id).first()
        receive_data = {}

        if user.is_video_auth == 1:
            #  主播
            verify = RealVideoVerify.objects(
                user_id=user.id, status=1).order_by("-update_time").first()
            if not verify:
                return
            if not verify.update_time:
                return
            verify_time = verify.update_time
            temp_end_time = verify_time + datetime.timedelta(days=7)
            endtime = temp_end_time.strftime('%Y-%m-%d 23:59:59')

            # 6-22 之前认证的都属于老主播
            compare_time = datetime.datetime(2017, 6, 21)

            if verify_time < compare_time or datetime.datetime.strptime(
                    endtime, "%Y-%m-%d %H:%M:%S") < now:
                # 老主播
                status, activity = cls.check_receive(2, now, user_id)
                if status == 3:
                    receive_data = eval(activity.tools_data)
                    activity_id = str(activity.id)
            else:
                # 新主播
                status, activity = cls.check_receive(1, now, user_id)
                if status == 3:
                    receive_data = eval(activity.tools_data)
                    activity_id = str(activity.id)
        else:
            #  非主播
            if int(user.gender) == 1:
                status, activity = cls.check_receive(3, now, user_id)
                if status == 3:
                    receive_data = eval(activity.tools_data)
                    activity_id = str(activity.id)

        if receive_data:
            for key, value in receive_data.items():
                tools = Tools.objects.filter(tools_type=int(key)).first()  # 道具
                user_tools = UserTools()
                user_tools.user_id = user_id
                user_tools.tools_id = str(tools.id)
                user_tools.tools_count = int(value)
                user_tools.time_type = 0
                user_tools.get_type = 4
                invalid_time = now + datetime.timedelta(days=1)
                user_tools.invalid_time = invalid_time
                user_tools.save()

                tools_record = UserToolsRecord()
                tools_record.user_id = user_id
                tools_record.tools_id = str(tools.id)
                tools_record.tools_count = 1
                tools_record.time_type = 0
                tools_record.oper_type = 4
                tools_record.create_time = now
                tools_record.save()

            activity_record = ToolsActivityRecord()
            activity_record.user_id = user_id
            activity_record.date_time = datetime.datetime(
                now.year, now.month, now.day)
            activity_record.tools_activity_id = activity_id
            activity_record.save()

            desc = u"<html><p>" + _(
                u'您的活动奖励已发送至您的账户,在"我的道具"中,请注意查收,希望您在我们平台玩得开心~'
            ) + u"</p></html>"
            MessageSender.send_system_message(user.sid, desc)