Example #1
0
    def get(self):
        user = self.current_user
        video_id = self.arg('video_id')
        video = PrivateVideo.objects.filter(id=video_id,
                                            delete_status=1).first()
        if not video:
            return self.write({"status": "fail", "error": _(u"视频已删除")})

        to_user_id = video.user_id
        to_user = User.objects.filter(id=to_user_id).first()

        account = Account.objects.filter(user=user).first()
        if account.diamond < video.price:
            return self.write({"status": "fail", "error": _(u"余额不足")})
        try:
            old_record = VideoPurchaseRecord.objects.filter(
                user_id=user.id, video_id=video_id).first()
            if old_record:
                return self.write({
                    "status": "success",
                    "msg": "Already purchased"
                })
            # 用户账号余额
            account.diamond_trade_out(
                price=video.price,
                desc=u"购买私房视频, 私房视频id=%s" % (str(video_id)),
                trade_type=TradeDiamondRecord.TradeTypePrivateVideo)

            user.update(
                inc__wealth_value=video.price / 10,
                inc__cost=video.price,
            )

            to_user.update(inc__charm_value=video.price / 10,
                           inc__ticket=video.price)

            # 2. 收礼人+经验, +粒子数
            # to_user.add_experience(10)
            ticket_account = TicketAccount.objects.get(user=to_user)
            ticket_account.add_ticket(
                trade_type=TradeTicketRecord.TradeTypePrivateVideo,
                ticket=video.price,
                desc=u"购买私房视频, 私房视频id=%s" % (str(video_id)))

            # 购买记录
            VideoPurchaseRecord.create_record(user.id, video_id)

            return self.write({"status": "success"})
        except Exception, e:
            return self.write({"status": "fail"})
Example #2
0
    def get(self):
        data = []
        page = self.arg_int('page')
        user_id = self.current_user_id
        page_count = self.arg_int('page_count')

        from app.customer.models.videodb import VideoShow
        show_list = VideoShow.objects.all().order_by("sort")[(page - 1) *
                                                             page_count:page *
                                                             page_count]

        for show in show_list:
            moment_id = show.moment_id
            moment = UserMoment.objects.filter(id=moment_id).first()
            if moment:
                dic = convert_user_moment(moment)
                if user_id:
                    like_user_list = moment.like_user_list
                    if int(user_id) in like_user_list:
                        is_liked = 1
                    else:
                        is_liked = 0
                    dic["is_liked"] = is_liked

                    if moment.type == 3:
                        buy_video_status = VideoPurchaseRecord.get_buy_status(
                            user_id, moment.video_id)
                        dic["buy_video_status"] = buy_video_status

                    data.append(dic)
                else:
                    dic["is_liked"] = 0
                    data.append(dic)

        return self.write({"status": "success", "data": data})
Example #3
0
    def get(self):
        user_id = self.current_user_id
        page = self.arg_int('page')
        page_count = self.arg_int('page_count')
        messages = AboutMeMessage.objects.filter(
            user_id=user_id).order_by("-create_time")[(page - 1) *
                                                      page_count:page *
                                                      page_count]
        data = []
        if messages:
            for message in messages:
                dict = convert_about_me_message(message)
                moment = UserMoment.objects.filter(
                    id=message.moment_id).first()
                buy_video_status = VideoPurchaseRecord.get_buy_status(
                    user_id, moment.video_id)
                dict["moment"]["buy_video_status"] = buy_video_status
                like_user_list = moment.like_user_list
                if int(user_id) in like_user_list:
                    is_liked = 1
                else:
                    is_liked = 0
                dict["moment"]["is_liked"] = is_liked
                data.append(dict)

        return self.write({"status": "success", "data": data})
Example #4
0
    def get(self):
        user_id = self.current_user_id
        video_id = self.arg("video_id")
        now = datetime.datetime.now()
        create_time = now.strftime("%Y-%m-%d")
        count = VipWatchVideoRecord.objects.filter(
            user_id=user_id, create_time=create_time).count()
        super_vip_count = 6
        vip_count = 2
        user_vip = UserVip.objects.filter(user_id=user_id).first()
        can_watch = 2

        buy_video_status = VideoPurchaseRecord.get_buy_status(
            user_id, video_id)

        # 今天是否看过词视频
        looked_today = VipWatchVideoRecord.objects.filter(
            user_id=user_id, create_time=create_time,
            video_id=video_id).first()
        is_looked_today = 2
        if looked_today:
            is_looked_today = 1

        if user_vip:
            vip = Vip.objects.filter(id=user_vip.vip_id).first()
            if vip.vip_type == 1:
                # 高级
                if count < vip_count or looked_today:
                    can_watch = 1
                vip_total_count = vip_count

            if vip.vip_type == 2:
                # 超级
                if count < super_vip_count or looked_today:
                    can_watch = 1
                vip_total_count = super_vip_count

            looked_count = count

            if can_watch == 1:
                # 添加观看记录
                VipWatchVideoRecord.create_record(video_id, user_id)

            return self.write({
                "status": "success",
                "can_watch": can_watch,
                "looked_count": looked_count,
                "vip_total_count": vip_total_count,
                "buy_video_status": buy_video_status,
                "is_looked_today": is_looked_today
            })
        else:
            return self.write({
                "status": "success",
                "can_watch": can_watch,
                "looked_count": 0,
                "vip_total_count": 0,
                "buy_video_status": buy_video_status,
                "is_looked_today": is_looked_today
            })
Example #5
0
    def get(self):
        data = []
        user_id = self.current_user_id
        moment_id = self.arg('moment_id', "")
        moment = UserMoment.objects.filter(show_status__ne=2,
                                           id=moment_id).first()
        if moment:
            UserMomentLook.inc_look(user_id, str(moment.id))
            like_user_list = moment.like_user_list
            dic = convert_user_moment(moment)
            if int(user_id) in like_user_list:
                is_liked = 1
            else:
                is_liked = 0
            dic["is_liked"] = is_liked

            if moment.type == 3:
                buy_video_status = VideoPurchaseRecord.get_buy_status(
                    user_id, moment.video_id)
                dic["buy_video_status"] = buy_video_status
                user_vip = UserVip.objects.filter(user_id=user_id).first()
                if user_vip:
                    now = datetime.datetime.now()
                    create_time = now.strftime("%Y-%m-%d")
                    vip_watch_record = VipWatchVideoRecord.objects.filter(
                        user_id=user_id,
                        create_time=create_time,
                        video_id=moment.video_id).first()
                    vip_comment_status = 2
                    if vip_watch_record:
                        vip_comment_status = 1
                    dic["vip_comment_status"] = vip_comment_status

            dic["check_real_video"] = RealVideoVerify.get_status(
                moment.user_id)

            data.append(dic)
        else:
            return self.write({'status': "fail", 'error': _(u"该动态已经被删除")})
        return self.write({"status": "success", "data": data})
Example #6
0
    def get(self):
        data = []
        current_user_id = self.current_user_id
        user_id = self.arg("user_id")

        if int(user_id) == int(current_user_id):
            videos = PrivateVideo.objects.filter(
                show_status__ne=2, user_id=user_id,
                delete_status=1).order_by("-create_time")
        else:
            videos = PrivateVideo.objects.filter(
                show_status=1, user_id=user_id,
                delete_status=1).order_by("-create_time")

        if videos:
            for video in videos:
                moment = UserMoment.objects.filter(
                    video_id=str(video.id)).order_by("-create_time").first()
                if moment:
                    dic = convert_user_moment(moment)
                    buy_video_status = VideoPurchaseRecord.get_buy_status(
                        current_user_id, moment.video_id)
                    dic["buy_video_status"] = buy_video_status

                    if user_id:
                        like_user_list = moment.like_user_list
                        if int(user_id) in like_user_list:
                            is_liked = 1
                        else:
                            is_liked = 0
                        dic["is_liked"] = is_liked
                        data.append(dic)
                    else:
                        dic["is_liked"] = 0
                        data.append(dic)
                    dic["check_real_video"] = RealVideoVerify.get_status(
                        moment.user_id)

        self.write({"status": "success", "data": data})
Example #7
0
    def get(self):
        data = []
        page = self.arg_int('page')
        user_id = self.current_user_id

        page_count = self.arg_int('page_count')

        # moments = UserMoment.objects.filter(show_status__in=[1, 3, 4], delete_status=1, is_public=1).order_by("-create_time")[(page - 1) * page_count:page * page_count]
        moments = UserMoment.get_index_moments(page, page_count,
                                               self.current_user)
        if moments:
            for moment in moments:
                if moment:
                    dic = convert_user_moment(moment)
                    if user_id:
                        like_user_list = moment.like_user_list
                        if int(user_id) in like_user_list:
                            is_liked = 1
                        else:
                            is_liked = 0
                        dic["is_liked"] = is_liked

                        if moment.type == 3:
                            buy_video_status = VideoPurchaseRecord.get_buy_status(
                                user_id, moment.video_id)
                            dic["buy_video_status"] = buy_video_status

                        dic["check_real_video"] = RealVideoVerify.get_status(
                            moment.user_id)

                        data.append(dic)
                    else:
                        dic["is_liked"] = 0
                        data.append(dic)

        self.write({"status": "success", "data": data})
Example #8
0
    def get(self):
        user = self.current_user
        user_id = self.current_user_id
        if not user_id:
            return self.write({"status": "success", "data": []})
        list_type = self.arg_int("list_type")
        show_user_id = self.arg_int("show_user_id", 0)
        page = self.arg_int('page')
        page_count = self.arg_int('page_count')
        data = []

        if list_type == 1:
            # 我的动态
            moments = UserMoment.objects.filter(
                user_id=user.id,
                show_status__ne=2,
                delete_status=1,
                is_public=1).order_by("-create_time")[(page - 1) *
                                                      page_count:page *
                                                      page_count]
        elif list_type == 2:
            # 我的关注动态
            follow_users = FollowUser.objects.filter(from_id=user.id)
            friend_users = FriendUser.objects.filter(from_id=user.id)
            user_ids = []
            if follow_users:
                for follow_user in follow_users:
                    fo_uid = follow_user.to_id
                    if fo_uid not in user_ids:
                        user_ids.append(fo_uid)
            if friend_users:
                for friend_user in friend_users:
                    fr_uid = friend_user.to_id
                    if fr_uid not in user_ids:
                        user_ids.append(fr_uid)
            is_spec = False
            if self.current_user.is_video_auth != 1 and not UserRedis.is_target_user(
                    user_id):
                is_pure = 1
                is_spec = True
            elif self.current_user.is_video_auth == 1 and not UserRedis.is_pure_anchor(
                    user_id):
                is_pure = 2
                is_spec = True
            if not is_spec:
                moments = UserMoment.objects.filter(
                    user_id__in=user_ids,
                    show_status__in=[1, 3, 4],
                    delete_status=1,
                    is_public=1).order_by("-create_time")[(page - 1) *
                                                          page_count:page *
                                                          page_count]
            else:
                moments = UserMoment.objects.filter(
                    user_id__in=user_ids,
                    show_status__in=[1, 3, 4],
                    delete_status=1,
                    is_public=1,
                    is_pure=is_pure).order_by("-create_time")[(page - 1) *
                                                              page_count:page *
                                                              page_count]
        elif list_type == 3:
            # 临时加一个 判断我的. 稍后客户端把lsit_type修复
            if show_user_id == int(user_id):
                moments = UserMoment.objects.filter(
                    user_id=user.id,
                    show_status__ne=2,
                    delete_status=1,
                    is_public=1).order_by("-create_time")[(page - 1) *
                                                          page_count:page *
                                                          page_count]
            else:
                # 其他用户动态
                moments = UserMoment.objects.filter(
                    user_id=show_user_id,
                    show_status__in=[1, 3, 4],
                    delete_status=1,
                    is_public=1).order_by("-create_time")[(page - 1) *
                                                          page_count:page *
                                                          page_count]

        if moments:
            for moment in moments:
                like_user_list = moment.like_user_list
                dic = convert_user_moment(moment)
                if int(user_id) in like_user_list:
                    is_liked = 1
                else:
                    is_liked = 0
                dic["is_liked"] = is_liked
                if moment.type == 3:
                    buy_video_status = VideoPurchaseRecord.get_buy_status(
                        user_id, moment.video_id)
                    dic["buy_video_status"] = buy_video_status

                dic["check_real_video"] = RealVideoVerify.get_status(
                    moment.user_id)
                data.append(dic)

        return self.write({"status": "success", "data": data})